Advertisement
peetaur

xen winxp pciback script for radeon 6770 passthrough

Aug 15th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. peter:~/xen # cat startwindows.bash
  2. #!/bin/bash
  3. # License: GPLv2
  4. # Author: Peter Maloney
  5. . bind_lib.bash
  6.  
  7. xm sched-credit -d Domain-0 -w 5120
  8.  
  9. modprobe xen-pciback
  10.  
  11. bindallback
  12.  
  13. /etc/init.d/xencommons start
  14. /etc/init.d/xendomains start
  15. /etc/init.d/xend start
  16.  
  17. xm create /etc/xen/vm/windowsxp2
  18.  
  19. peter:~/xen # cat bind_lib.bash
  20. #!/bin/bash
  21. # License: GPLv2
  22. # Author: Peter Maloney
  23. # Script to bind devices to pciback (or pci-stub)
  24.  
  25. find_new_id() {
  26. device="$1"
  27. len=${#device}
  28. if [ "$len" -eq 12 ]; then
  29. device="${device:5:12}"
  30. fi
  31. lspci -n | grep "${device}" | cut -d' ' -f3 | sed -r "s/:/ /"
  32. }
  33.  
  34. bindstub() {
  35. device="$1"
  36. echo "binddevice $device"
  37.  
  38. if [ ! -e "/sys/bus/pci/devices/$device" ]; then
  39. echo " ERROR: Device does not exist... cancelling"
  40. return
  41. fi
  42.  
  43. # with pci-stub, you do new_id, then unbind, then bind
  44.  
  45. echo "create new_id"
  46. chmod +w /sys/bus/pci/drivers/pci-stub/new_id
  47. new_id="$(find_new_id "$device")"
  48. echo " echo \"$new_id\" > /sys/bus/pci/drivers/pci-stub/new_id"
  49. echo "$new_id" > /sys/bus/pci/drivers/pci-stub/new_id
  50.  
  51. echo "unbind"
  52. if [ ! -e "/sys/bus/pci/devices/$device/driver" ]; then
  53. echo " no driver to unbind"
  54. else
  55. chmod +w "/sys/bus/pci/devices/${device}/driver/unbind"
  56. echo " echo -n \"$device\" > \"/sys/bus/pci/devices/$device/driver/unbind\""
  57. echo -n "$device" > "/sys/bus/pci/devices/$device/driver/unbind"
  58. fi
  59.  
  60. echo "bind"
  61. chmod +w /sys/bus/pci/drivers/pci-stub/bind
  62. echo " echo -n \"$device\" > /sys/bus/pci/drivers/pci-stub/bind"
  63. echo -n "$device" > /sys/bus/pci/drivers/pci-stub/bind
  64.  
  65. echo
  66. }
  67.  
  68. bindback() {
  69. device="$1"
  70. echo "binddevice $device"
  71.  
  72. if [ ! -e "/sys/bus/pci/devices/$device" ]; then
  73. echo "ERROR: Device does not exist... cancelling"
  74. return
  75. fi
  76.  
  77. # with pci-stub, you do unbind, then new_slot, then bind
  78.  
  79. echo "unbind"
  80. if [ ! -e "/sys/bus/pci/devices/$device/driver" ]; then
  81. echo " no driver to unbind"
  82. else
  83. chmod +w "/sys/bus/pci/devices/${device}/driver/unbind"
  84. echo " echo -n \"$device\" > \"/sys/bus/pci/devices/$device/driver/unbind\""
  85. echo -n "$device" > "/sys/bus/pci/devices/$device/driver/unbind"
  86. fi
  87.  
  88. echo "create new_slot"
  89. chmod +w /sys/bus/pci/drivers/pciback/new_slot
  90. echo " echo -n \"$device\" > /sys/bus/pci/drivers/pciback/new_slot"
  91. echo -n "$device" > /sys/bus/pci/drivers/pciback/new_slot
  92.  
  93. echo "bind"
  94. chmod +w /sys/bus/pci/drivers/pciback/bind
  95. echo " echo -n \"$device\" > /sys/bus/pci/drivers/pci-stub/bind"
  96. echo -n "$device" > /sys/bus/pci/drivers/pciback/bind
  97.  
  98. echo
  99. }
  100.  
  101. checkdevice() {
  102. device="$1"
  103. ls -l /sys/bus/pci/devices/0000:${device}/driver
  104. }
  105.  
  106. bindallstub() {
  107. # vga2
  108. bindstub "0000:04:00.0"
  109.  
  110. # vga2 audio
  111. bindstub "0000:04:00.1"
  112.  
  113. # usb2
  114. bindstub "0000:00:12.0"
  115. bindstub "0000:00:12.2"
  116.  
  117. # usb3
  118. bindstub "0000:02:00.0"
  119.  
  120.  
  121. ls -l /sys/bus/pci/devices/{0000:01:00.0,0000:01:00.1,0000:04:00.0,0000:04:00.1,0000:00:12.0,0000:00:12.2,0000:02:00.0}/driver
  122.  
  123. xm pci-list-assignable-devices || xl pci-list-assignable-devices
  124. }
  125.  
  126. bindallback() {
  127. # vga2
  128. bindback "0000:04:00.0"
  129.  
  130. # vga2 audio
  131. bindback "0000:04:00.1"
  132.  
  133. # usb2
  134. bindback "0000:00:12.0"
  135. bindback "0000:00:12.2"
  136.  
  137. # usb3
  138. bindback "0000:02:00.0"
  139.  
  140.  
  141. ls -l /sys/bus/pci/devices/{0000:01:00.0,0000:01:00.1,0000:04:00.0,0000:04:00.1,0000:00:12.0,0000:00:12.2,0000:02:00.0}/driver
  142.  
  143. xm pci-list-assignable-devices || xl pci-list-assignable-devices
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement