vgaarb.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. /*
  2. * vgaarb.c: Implements the VGA arbitration. For details refer to
  3. * Documentation/vgaarbiter.txt
  4. *
  5. *
  6. * (C) Copyright 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org>
  7. * (C) Copyright 2007 Paulo R. Zanoni <przanoni@gmail.com>
  8. * (C) Copyright 2007, 2009 Tiago Vignatti <vignatti@freedesktop.org>
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a
  11. * copy of this software and associated documentation files (the "Software"),
  12. * to deal in the Software without restriction, including without limitation
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14. * and/or sell copies of the Software, and to permit persons to whom the
  15. * Software is furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice (including the next
  18. * paragraph) shall be included in all copies or substantial portions of the
  19. * Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  24. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  26. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  27. * DEALINGS
  28. * IN THE SOFTWARE.
  29. *
  30. */
  31. #include <linux/module.h>
  32. #include <linux/kernel.h>
  33. #include <linux/pci.h>
  34. #include <linux/errno.h>
  35. #include <linux/init.h>
  36. #include <linux/list.h>
  37. #include <linux/sched.h>
  38. #include <linux/wait.h>
  39. #include <linux/spinlock.h>
  40. #include <linux/poll.h>
  41. #include <linux/miscdevice.h>
  42. #include <linux/slab.h>
  43. #include <linux/uaccess.h>
  44. #include <linux/vgaarb.h>
  45. static void vga_arbiter_notify_clients(void);
  46. /*
  47. * We keep a list of all vga devices in the system to speed
  48. * up the various operations of the arbiter
  49. */
  50. struct vga_device {
  51. struct list_head list;
  52. struct pci_dev *pdev;
  53. unsigned int decodes; /* what does it decodes */
  54. unsigned int owns; /* what does it owns */
  55. unsigned int locks; /* what does it locks */
  56. unsigned int io_lock_cnt; /* legacy IO lock count */
  57. unsigned int mem_lock_cnt; /* legacy MEM lock count */
  58. unsigned int io_norm_cnt; /* normal IO count */
  59. unsigned int mem_norm_cnt; /* normal MEM count */
  60. /* allow IRQ enable/disable hook */
  61. void *cookie;
  62. void (*irq_set_state)(void *cookie, bool enable);
  63. unsigned int (*set_vga_decode)(void *cookie, bool decode);
  64. };
  65. static LIST_HEAD(vga_list);
  66. static int vga_count, vga_decode_count;
  67. static bool vga_arbiter_used;
  68. static DEFINE_SPINLOCK(vga_lock);
  69. static DECLARE_WAIT_QUEUE_HEAD(vga_wait_queue);
  70. static const char *vga_iostate_to_str(unsigned int iostate)
  71. {
  72. /* Ignore VGA_RSRC_IO and VGA_RSRC_MEM */
  73. iostate &= VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM;
  74. switch (iostate) {
  75. case VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM:
  76. return "io+mem";
  77. case VGA_RSRC_LEGACY_IO:
  78. return "io";
  79. case VGA_RSRC_LEGACY_MEM:
  80. return "mem";
  81. }
  82. return "none";
  83. }
  84. static int vga_str_to_iostate(char *buf, int str_size, int *io_state)
  85. {
  86. /* we could in theory hand out locks on IO and mem
  87. * separately to userspace but it can cause deadlocks */
  88. if (strncmp(buf, "none", 4) == 0) {
  89. *io_state = VGA_RSRC_NONE;
  90. return 1;
  91. }
  92. /* XXX We're not chekcing the str_size! */
  93. if (strncmp(buf, "io+mem", 6) == 0)
  94. goto both;
  95. else if (strncmp(buf, "io", 2) == 0)
  96. goto both;
  97. else if (strncmp(buf, "mem", 3) == 0)
  98. goto both;
  99. return 0;
  100. both:
  101. *io_state = VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM;
  102. return 1;
  103. }
  104. #ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
  105. /* this is only used a cookie - it should not be dereferenced */
  106. static struct pci_dev *vga_default;
  107. #endif
  108. static void vga_arb_device_card_gone(struct pci_dev *pdev);
  109. /* Find somebody in our list */
  110. static struct vga_device *vgadev_find(struct pci_dev *pdev)
  111. {
  112. struct vga_device *vgadev;
  113. list_for_each_entry(vgadev, &vga_list, list)
  114. if (pdev == vgadev->pdev)
  115. return vgadev;
  116. return NULL;
  117. }
  118. /* Returns the default VGA device (vgacon's babe) */
  119. #ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
  120. struct pci_dev *vga_default_device(void)
  121. {
  122. return vga_default;
  123. }
  124. #endif
  125. static inline void vga_irq_set_state(struct vga_device *vgadev, bool state)
  126. {
  127. if (vgadev->irq_set_state)
  128. vgadev->irq_set_state(vgadev->cookie, state);
  129. }
  130. /* If we don't ever use VGA arb we should avoid
  131. turning off anything anywhere due to old X servers getting
  132. confused about the boot device not being VGA */
  133. static void vga_check_first_use(void)
  134. {
  135. /* we should inform all GPUs in the system that
  136. * VGA arb has occured and to try and disable resources
  137. * if they can */
  138. if (!vga_arbiter_used) {
  139. vga_arbiter_used = true;
  140. vga_arbiter_notify_clients();
  141. }
  142. }
  143. static struct vga_device *__vga_tryget(struct vga_device *vgadev,
  144. unsigned int rsrc)
  145. {
  146. unsigned int wants, legacy_wants, match;
  147. struct vga_device *conflict;
  148. unsigned int pci_bits;
  149. /* Account for "normal" resources to lock. If we decode the legacy,
  150. * counterpart, we need to request it as well
  151. */
  152. if ((rsrc & VGA_RSRC_NORMAL_IO) &&
  153. (vgadev->decodes & VGA_RSRC_LEGACY_IO))
  154. rsrc |= VGA_RSRC_LEGACY_IO;
  155. if ((rsrc & VGA_RSRC_NORMAL_MEM) &&
  156. (vgadev->decodes & VGA_RSRC_LEGACY_MEM))
  157. rsrc |= VGA_RSRC_LEGACY_MEM;
  158. pr_debug("%s: %d\n", __func__, rsrc);
  159. pr_debug("%s: owns: %d\n", __func__, vgadev->owns);
  160. /* Check what resources we need to acquire */
  161. wants = rsrc & ~vgadev->owns;
  162. /* We already own everything, just mark locked & bye bye */
  163. if (wants == 0)
  164. goto lock_them;
  165. /* We don't need to request a legacy resource, we just enable
  166. * appropriate decoding and go
  167. */
  168. legacy_wants = wants & VGA_RSRC_LEGACY_MASK;
  169. if (legacy_wants == 0)
  170. goto enable_them;
  171. /* Ok, we don't, let's find out how we need to kick off */
  172. list_for_each_entry(conflict, &vga_list, list) {
  173. unsigned int lwants = legacy_wants;
  174. unsigned int change_bridge = 0;
  175. /* Don't conflict with myself */
  176. if (vgadev == conflict)
  177. continue;
  178. /* Check if the architecture allows a conflict between those
  179. * 2 devices or if they are on separate domains
  180. */
  181. if (!vga_conflicts(vgadev->pdev, conflict->pdev))
  182. continue;
  183. /* We have a possible conflict. before we go further, we must
  184. * check if we sit on the same bus as the conflicting device.
  185. * if we don't, then we must tie both IO and MEM resources
  186. * together since there is only a single bit controlling
  187. * VGA forwarding on P2P bridges
  188. */
  189. if (vgadev->pdev->bus != conflict->pdev->bus) {
  190. change_bridge = 1;
  191. lwants = VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM;
  192. }
  193. /* Check if the guy has a lock on the resource. If he does,
  194. * return the conflicting entry
  195. */
  196. if (conflict->locks & lwants)
  197. return conflict;
  198. /* Ok, now check if he owns the resource we want. We don't need
  199. * to check "decodes" since it should be impossible to own
  200. * own legacy resources you don't decode unless I have a bug
  201. * in this code...
  202. */
  203. WARN_ON(conflict->owns & ~conflict->decodes);
  204. match = lwants & conflict->owns;
  205. if (!match)
  206. continue;
  207. /* looks like he doesn't have a lock, we can steal
  208. * them from him
  209. */
  210. vga_irq_set_state(conflict, false);
  211. pci_bits = 0;
  212. if (lwants & (VGA_RSRC_LEGACY_MEM|VGA_RSRC_NORMAL_MEM))
  213. pci_bits |= PCI_COMMAND_MEMORY;
  214. if (lwants & (VGA_RSRC_LEGACY_IO|VGA_RSRC_NORMAL_IO))
  215. pci_bits |= PCI_COMMAND_IO;
  216. pci_set_vga_state(conflict->pdev, false, pci_bits,
  217. change_bridge);
  218. conflict->owns &= ~lwants;
  219. /* If he also owned non-legacy, that is no longer the case */
  220. if (lwants & VGA_RSRC_LEGACY_MEM)
  221. conflict->owns &= ~VGA_RSRC_NORMAL_MEM;
  222. if (lwants & VGA_RSRC_LEGACY_IO)
  223. conflict->owns &= ~VGA_RSRC_NORMAL_IO;
  224. }
  225. enable_them:
  226. /* ok dude, we got it, everybody conflicting has been disabled, let's
  227. * enable us. Make sure we don't mark a bit in "owns" that we don't
  228. * also have in "decodes". We can lock resources we don't decode but
  229. * not own them.
  230. */
  231. pci_bits = 0;
  232. if (wants & (VGA_RSRC_LEGACY_MEM|VGA_RSRC_NORMAL_MEM))
  233. pci_bits |= PCI_COMMAND_MEMORY;
  234. if (wants & (VGA_RSRC_LEGACY_IO|VGA_RSRC_NORMAL_IO))
  235. pci_bits |= PCI_COMMAND_IO;
  236. pci_set_vga_state(vgadev->pdev, true, pci_bits, !!(wants & VGA_RSRC_LEGACY_MASK));
  237. vga_irq_set_state(vgadev, true);
  238. vgadev->owns |= (wants & vgadev->decodes);
  239. lock_them:
  240. vgadev->locks |= (rsrc & VGA_RSRC_LEGACY_MASK);
  241. if (rsrc & VGA_RSRC_LEGACY_IO)
  242. vgadev->io_lock_cnt++;
  243. if (rsrc & VGA_RSRC_LEGACY_MEM)
  244. vgadev->mem_lock_cnt++;
  245. if (rsrc & VGA_RSRC_NORMAL_IO)
  246. vgadev->io_norm_cnt++;
  247. if (rsrc & VGA_RSRC_NORMAL_MEM)
  248. vgadev->mem_norm_cnt++;
  249. return NULL;
  250. }
  251. static void __vga_put(struct vga_device *vgadev, unsigned int rsrc)
  252. {
  253. unsigned int old_locks = vgadev->locks;
  254. pr_debug("%s\n", __func__);
  255. /* Update our counters, and account for equivalent legacy resources
  256. * if we decode them
  257. */
  258. if ((rsrc & VGA_RSRC_NORMAL_IO) && vgadev->io_norm_cnt > 0) {
  259. vgadev->io_norm_cnt--;
  260. if (vgadev->decodes & VGA_RSRC_LEGACY_IO)
  261. rsrc |= VGA_RSRC_LEGACY_IO;
  262. }
  263. if ((rsrc & VGA_RSRC_NORMAL_MEM) && vgadev->mem_norm_cnt > 0) {
  264. vgadev->mem_norm_cnt--;
  265. if (vgadev->decodes & VGA_RSRC_LEGACY_MEM)
  266. rsrc |= VGA_RSRC_LEGACY_MEM;
  267. }
  268. if ((rsrc & VGA_RSRC_LEGACY_IO) && vgadev->io_lock_cnt > 0)
  269. vgadev->io_lock_cnt--;
  270. if ((rsrc & VGA_RSRC_LEGACY_MEM) && vgadev->mem_lock_cnt > 0)
  271. vgadev->mem_lock_cnt--;
  272. /* Just clear lock bits, we do lazy operations so we don't really
  273. * have to bother about anything else at this point
  274. */
  275. if (vgadev->io_lock_cnt == 0)
  276. vgadev->locks &= ~VGA_RSRC_LEGACY_IO;
  277. if (vgadev->mem_lock_cnt == 0)
  278. vgadev->locks &= ~VGA_RSRC_LEGACY_MEM;
  279. /* Kick the wait queue in case somebody was waiting if we actually
  280. * released something
  281. */
  282. if (old_locks != vgadev->locks)
  283. wake_up_all(&vga_wait_queue);
  284. }
  285. int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible)
  286. {
  287. struct vga_device *vgadev, *conflict;
  288. unsigned long flags;
  289. wait_queue_t wait;
  290. int rc = 0;
  291. vga_check_first_use();
  292. /* The one who calls us should check for this, but lets be sure... */
  293. if (pdev == NULL)
  294. pdev = vga_default_device();
  295. if (pdev == NULL)
  296. return 0;
  297. for (;;) {
  298. spin_lock_irqsave(&vga_lock, flags);
  299. vgadev = vgadev_find(pdev);
  300. if (vgadev == NULL) {
  301. spin_unlock_irqrestore(&vga_lock, flags);
  302. rc = -ENODEV;
  303. break;
  304. }
  305. conflict = __vga_tryget(vgadev, rsrc);
  306. spin_unlock_irqrestore(&vga_lock, flags);
  307. if (conflict == NULL)
  308. break;
  309. /* We have a conflict, we wait until somebody kicks the
  310. * work queue. Currently we have one work queue that we
  311. * kick each time some resources are released, but it would
  312. * be fairly easy to have a per device one so that we only
  313. * need to attach to the conflicting device
  314. */
  315. init_waitqueue_entry(&wait, current);
  316. add_wait_queue(&vga_wait_queue, &wait);
  317. set_current_state(interruptible ?
  318. TASK_INTERRUPTIBLE :
  319. TASK_UNINTERRUPTIBLE);
  320. if (signal_pending(current)) {
  321. rc = -EINTR;
  322. break;
  323. }
  324. schedule();
  325. remove_wait_queue(&vga_wait_queue, &wait);
  326. set_current_state(TASK_RUNNING);
  327. }
  328. return rc;
  329. }
  330. EXPORT_SYMBOL(vga_get);
  331. int vga_tryget(struct pci_dev *pdev, unsigned int rsrc)
  332. {
  333. struct vga_device *vgadev;
  334. unsigned long flags;
  335. int rc = 0;
  336. vga_check_first_use();
  337. /* The one who calls us should check for this, but lets be sure... */
  338. if (pdev == NULL)
  339. pdev = vga_default_device();
  340. if (pdev == NULL)
  341. return 0;
  342. spin_lock_irqsave(&vga_lock, flags);
  343. vgadev = vgadev_find(pdev);
  344. if (vgadev == NULL) {
  345. rc = -ENODEV;
  346. goto bail;
  347. }
  348. if (__vga_tryget(vgadev, rsrc))
  349. rc = -EBUSY;
  350. bail:
  351. spin_unlock_irqrestore(&vga_lock, flags);
  352. return rc;
  353. }
  354. EXPORT_SYMBOL(vga_tryget);
  355. void vga_put(struct pci_dev *pdev, unsigned int rsrc)
  356. {
  357. struct vga_device *vgadev;
  358. unsigned long flags;
  359. /* The one who calls us should check for this, but lets be sure... */
  360. if (pdev == NULL)
  361. pdev = vga_default_device();
  362. if (pdev == NULL)
  363. return;
  364. spin_lock_irqsave(&vga_lock, flags);
  365. vgadev = vgadev_find(pdev);
  366. if (vgadev == NULL)
  367. goto bail;
  368. __vga_put(vgadev, rsrc);
  369. bail:
  370. spin_unlock_irqrestore(&vga_lock, flags);
  371. }
  372. EXPORT_SYMBOL(vga_put);
  373. /*
  374. * Currently, we assume that the "initial" setup of the system is
  375. * not sane, that is we come up with conflicting devices and let
  376. * the arbiter's client decides if devices decodes or not legacy
  377. * things.
  378. */
  379. static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)
  380. {
  381. struct vga_device *vgadev;
  382. unsigned long flags;
  383. struct pci_bus *bus;
  384. struct pci_dev *bridge;
  385. u16 cmd;
  386. /* Only deal with VGA class devices */
  387. if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
  388. return false;
  389. /* Allocate structure */
  390. vgadev = kmalloc(sizeof(struct vga_device), GFP_KERNEL);
  391. if (vgadev == NULL) {
  392. pr_err("vgaarb: failed to allocate pci device\n");
  393. /* What to do on allocation failure ? For now, let's
  394. * just do nothing, I'm not sure there is anything saner
  395. * to be done
  396. */
  397. return false;
  398. }
  399. memset(vgadev, 0, sizeof(*vgadev));
  400. /* Take lock & check for duplicates */
  401. spin_lock_irqsave(&vga_lock, flags);
  402. if (vgadev_find(pdev) != NULL) {
  403. BUG_ON(1);
  404. goto fail;
  405. }
  406. vgadev->pdev = pdev;
  407. /* By default, assume we decode everything */
  408. vgadev->decodes = VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
  409. VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  410. /* by default mark it as decoding */
  411. vga_decode_count++;
  412. /* Mark that we "own" resources based on our enables, we will
  413. * clear that below if the bridge isn't forwarding
  414. */
  415. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  416. if (cmd & PCI_COMMAND_IO)
  417. vgadev->owns |= VGA_RSRC_LEGACY_IO;
  418. if (cmd & PCI_COMMAND_MEMORY)
  419. vgadev->owns |= VGA_RSRC_LEGACY_MEM;
  420. /* Check if VGA cycles can get down to us */
  421. bus = pdev->bus;
  422. while (bus) {
  423. bridge = bus->self;
  424. if (bridge) {
  425. u16 l;
  426. pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
  427. &l);
  428. if (!(l & PCI_BRIDGE_CTL_VGA)) {
  429. vgadev->owns = 0;
  430. break;
  431. }
  432. }
  433. bus = bus->parent;
  434. }
  435. /* Deal with VGA default device. Use first enabled one
  436. * by default if arch doesn't have it's own hook
  437. */
  438. #ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
  439. if (vga_default == NULL &&
  440. ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK))
  441. vga_default = pci_dev_get(pdev);
  442. #endif
  443. /* Add to the list */
  444. list_add(&vgadev->list, &vga_list);
  445. vga_count++;
  446. pr_info("vgaarb: device added: PCI:%s,decodes=%s,owns=%s,locks=%s\n",
  447. pci_name(pdev),
  448. vga_iostate_to_str(vgadev->decodes),
  449. vga_iostate_to_str(vgadev->owns),
  450. vga_iostate_to_str(vgadev->locks));
  451. spin_unlock_irqrestore(&vga_lock, flags);
  452. return true;
  453. fail:
  454. spin_unlock_irqrestore(&vga_lock, flags);
  455. kfree(vgadev);
  456. return false;
  457. }
  458. static bool vga_arbiter_del_pci_device(struct pci_dev *pdev)
  459. {
  460. struct vga_device *vgadev;
  461. unsigned long flags;
  462. bool ret = true;
  463. spin_lock_irqsave(&vga_lock, flags);
  464. vgadev = vgadev_find(pdev);
  465. if (vgadev == NULL) {
  466. ret = false;
  467. goto bail;
  468. }
  469. if (vga_default == pdev) {
  470. pci_dev_put(vga_default);
  471. vga_default = NULL;
  472. }
  473. if (vgadev->decodes & (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM))
  474. vga_decode_count--;
  475. /* Remove entry from list */
  476. list_del(&vgadev->list);
  477. vga_count--;
  478. /* Notify userland driver that the device is gone so it discards
  479. * it's copies of the pci_dev pointer
  480. */
  481. vga_arb_device_card_gone(pdev);
  482. /* Wake up all possible waiters */
  483. wake_up_all(&vga_wait_queue);
  484. bail:
  485. spin_unlock_irqrestore(&vga_lock, flags);
  486. kfree(vgadev);
  487. return ret;
  488. }
  489. /* this is called with the lock */
  490. static inline void vga_update_device_decodes(struct vga_device *vgadev,
  491. int new_decodes)
  492. {
  493. int old_decodes;
  494. struct vga_device *new_vgadev, *conflict;
  495. old_decodes = vgadev->decodes;
  496. vgadev->decodes = new_decodes;
  497. pr_info("vgaarb: device changed decodes: PCI:%s,olddecodes=%s,decodes=%s:owns=%s\n",
  498. pci_name(vgadev->pdev),
  499. vga_iostate_to_str(old_decodes),
  500. vga_iostate_to_str(vgadev->decodes),
  501. vga_iostate_to_str(vgadev->owns));
  502. /* if we own the decodes we should move them along to
  503. another card */
  504. if ((vgadev->owns & old_decodes) && (vga_count > 1)) {
  505. /* set us to own nothing */
  506. vgadev->owns &= ~old_decodes;
  507. list_for_each_entry(new_vgadev, &vga_list, list) {
  508. if ((new_vgadev != vgadev) &&
  509. (new_vgadev->decodes & VGA_RSRC_LEGACY_MASK)) {
  510. pr_info("vgaarb: transferring owner from PCI:%s to PCI:%s\n", pci_name(vgadev->pdev), pci_name(new_vgadev->pdev));
  511. conflict = __vga_tryget(new_vgadev, VGA_RSRC_LEGACY_MASK);
  512. if (!conflict)
  513. __vga_put(new_vgadev, VGA_RSRC_LEGACY_MASK);
  514. break;
  515. }
  516. }
  517. }
  518. /* change decodes counter */
  519. if (old_decodes != new_decodes) {
  520. if (new_decodes & (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM))
  521. vga_decode_count++;
  522. else
  523. vga_decode_count--;
  524. }
  525. pr_debug("vgaarb: decoding count now is: %d\n", vga_decode_count);
  526. }
  527. static void __vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes, bool userspace)
  528. {
  529. struct vga_device *vgadev;
  530. unsigned long flags;
  531. decodes &= VGA_RSRC_LEGACY_MASK;
  532. spin_lock_irqsave(&vga_lock, flags);
  533. vgadev = vgadev_find(pdev);
  534. if (vgadev == NULL)
  535. goto bail;
  536. /* don't let userspace futz with kernel driver decodes */
  537. if (userspace && vgadev->set_vga_decode)
  538. goto bail;
  539. /* update the device decodes + counter */
  540. vga_update_device_decodes(vgadev, decodes);
  541. /* XXX if somebody is going from "doesn't decode" to "decodes" state
  542. * here, additional care must be taken as we may have pending owner
  543. * ship of non-legacy region ...
  544. */
  545. bail:
  546. spin_unlock_irqrestore(&vga_lock, flags);
  547. }
  548. void vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes)
  549. {
  550. __vga_set_legacy_decoding(pdev, decodes, false);
  551. }
  552. EXPORT_SYMBOL(vga_set_legacy_decoding);
  553. /* call with NULL to unregister */
  554. int vga_client_register(struct pci_dev *pdev, void *cookie,
  555. void (*irq_set_state)(void *cookie, bool state),
  556. unsigned int (*set_vga_decode)(void *cookie, bool decode))
  557. {
  558. int ret = -1;
  559. struct vga_device *vgadev;
  560. unsigned long flags;
  561. spin_lock_irqsave(&vga_lock, flags);
  562. vgadev = vgadev_find(pdev);
  563. if (!vgadev)
  564. goto bail;
  565. vgadev->irq_set_state = irq_set_state;
  566. vgadev->set_vga_decode = set_vga_decode;
  567. vgadev->cookie = cookie;
  568. ret = 0;
  569. bail:
  570. spin_unlock_irqrestore(&vga_lock, flags);
  571. return ret;
  572. }
  573. EXPORT_SYMBOL(vga_client_register);
  574. /*
  575. * Char driver implementation
  576. *
  577. * Semantics is:
  578. *
  579. * open : open user instance of the arbitrer. by default, it's
  580. * attached to the default VGA device of the system.
  581. *
  582. * close : close user instance, release locks
  583. *
  584. * read : return a string indicating the status of the target.
  585. * an IO state string is of the form {io,mem,io+mem,none},
  586. * mc and ic are respectively mem and io lock counts (for
  587. * debugging/diagnostic only). "decodes" indicate what the
  588. * card currently decodes, "owns" indicates what is currently
  589. * enabled on it, and "locks" indicates what is locked by this
  590. * card. If the card is unplugged, we get "invalid" then for
  591. * card_ID and an -ENODEV error is returned for any command
  592. * until a new card is targeted
  593. *
  594. * "<card_ID>,decodes=<io_state>,owns=<io_state>,locks=<io_state> (ic,mc)"
  595. *
  596. * write : write a command to the arbiter. List of commands is:
  597. *
  598. * target <card_ID> : switch target to card <card_ID> (see below)
  599. * lock <io_state> : acquires locks on target ("none" is invalid io_state)
  600. * trylock <io_state> : non-blocking acquire locks on target
  601. * unlock <io_state> : release locks on target
  602. * unlock all : release all locks on target held by this user
  603. * decodes <io_state> : set the legacy decoding attributes for the card
  604. *
  605. * poll : event if something change on any card (not just the target)
  606. *
  607. * card_ID is of the form "PCI:domain:bus:dev.fn". It can be set to "default"
  608. * to go back to the system default card (TODO: not implemented yet).
  609. * Currently, only PCI is supported as a prefix, but the userland API may
  610. * support other bus types in the future, even if the current kernel
  611. * implementation doesn't.
  612. *
  613. * Note about locks:
  614. *
  615. * The driver keeps track of which user has what locks on which card. It
  616. * supports stacking, like the kernel one. This complexifies the implementation
  617. * a bit, but makes the arbiter more tolerant to userspace problems and able
  618. * to properly cleanup in all cases when a process dies.
  619. * Currently, a max of 16 cards simultaneously can have locks issued from
  620. * userspace for a given user (file descriptor instance) of the arbiter.
  621. *
  622. * If the device is hot-unplugged, there is a hook inside the module to notify
  623. * they being added/removed in the system and automatically added/removed in
  624. * the arbiter.
  625. */
  626. #define MAX_USER_CARDS CONFIG_VGA_ARB_MAX_GPUS
  627. #define PCI_INVALID_CARD ((struct pci_dev *)-1UL)
  628. /*
  629. * Each user has an array of these, tracking which cards have locks
  630. */
  631. struct vga_arb_user_card {
  632. struct pci_dev *pdev;
  633. unsigned int mem_cnt;
  634. unsigned int io_cnt;
  635. };
  636. struct vga_arb_private {
  637. struct list_head list;
  638. struct pci_dev *target;
  639. struct vga_arb_user_card cards[MAX_USER_CARDS];
  640. spinlock_t lock;
  641. };
  642. static LIST_HEAD(vga_user_list);
  643. static DEFINE_SPINLOCK(vga_user_lock);
  644. /*
  645. * This function gets a string in the format: "PCI:domain:bus:dev.fn" and
  646. * returns the respective values. If the string is not in this format,
  647. * it returns 0.
  648. */
  649. static int vga_pci_str_to_vars(char *buf, int count, unsigned int *domain,
  650. unsigned int *bus, unsigned int *devfn)
  651. {
  652. int n;
  653. unsigned int slot, func;
  654. n = sscanf(buf, "PCI:%x:%x:%x.%x", domain, bus, &slot, &func);
  655. if (n != 4)
  656. return 0;
  657. *devfn = PCI_DEVFN(slot, func);
  658. return 1;
  659. }
  660. static ssize_t vga_arb_read(struct file *file, char __user * buf,
  661. size_t count, loff_t *ppos)
  662. {
  663. struct vga_arb_private *priv = file->private_data;
  664. struct vga_device *vgadev;
  665. struct pci_dev *pdev;
  666. unsigned long flags;
  667. size_t len;
  668. int rc;
  669. char *lbuf;
  670. lbuf = kmalloc(1024, GFP_KERNEL);
  671. if (lbuf == NULL)
  672. return -ENOMEM;
  673. /* Shields against vga_arb_device_card_gone (pci_dev going
  674. * away), and allows access to vga list
  675. */
  676. spin_lock_irqsave(&vga_lock, flags);
  677. /* If we are targetting the default, use it */
  678. pdev = priv->target;
  679. if (pdev == NULL || pdev == PCI_INVALID_CARD) {
  680. spin_unlock_irqrestore(&vga_lock, flags);
  681. len = sprintf(lbuf, "invalid");
  682. goto done;
  683. }
  684. /* Find card vgadev structure */
  685. vgadev = vgadev_find(pdev);
  686. if (vgadev == NULL) {
  687. /* Wow, it's not in the list, that shouldn't happen,
  688. * let's fix us up and return invalid card
  689. */
  690. if (pdev == priv->target)
  691. vga_arb_device_card_gone(pdev);
  692. spin_unlock_irqrestore(&vga_lock, flags);
  693. len = sprintf(lbuf, "invalid");
  694. goto done;
  695. }
  696. /* Fill the buffer with infos */
  697. len = snprintf(lbuf, 1024,
  698. "count:%d,PCI:%s,decodes=%s,owns=%s,locks=%s(%d:%d)\n",
  699. vga_decode_count, pci_name(pdev),
  700. vga_iostate_to_str(vgadev->decodes),
  701. vga_iostate_to_str(vgadev->owns),
  702. vga_iostate_to_str(vgadev->locks),
  703. vgadev->io_lock_cnt, vgadev->mem_lock_cnt);
  704. spin_unlock_irqrestore(&vga_lock, flags);
  705. done:
  706. /* Copy that to user */
  707. if (len > count)
  708. len = count;
  709. rc = copy_to_user(buf, lbuf, len);
  710. kfree(lbuf);
  711. if (rc)
  712. return -EFAULT;
  713. return len;
  714. }
  715. /*
  716. * TODO: To avoid parsing inside kernel and to improve the speed we may
  717. * consider use ioctl here
  718. */
  719. static ssize_t vga_arb_write(struct file *file, const char __user * buf,
  720. size_t count, loff_t *ppos)
  721. {
  722. struct vga_arb_private *priv = file->private_data;
  723. struct vga_arb_user_card *uc = NULL;
  724. struct pci_dev *pdev;
  725. unsigned int io_state;
  726. char *kbuf, *curr_pos;
  727. size_t remaining = count;
  728. int ret_val;
  729. int i;
  730. kbuf = kmalloc(count + 1, GFP_KERNEL);
  731. if (!kbuf)
  732. return -ENOMEM;
  733. if (copy_from_user(kbuf, buf, count)) {
  734. kfree(kbuf);
  735. return -EFAULT;
  736. }
  737. curr_pos = kbuf;
  738. kbuf[count] = '\0'; /* Just to make sure... */
  739. if (strncmp(curr_pos, "lock ", 5) == 0) {
  740. curr_pos += 5;
  741. remaining -= 5;
  742. pr_debug("client 0x%p called 'lock'\n", priv);
  743. if (!vga_str_to_iostate(curr_pos, remaining, &io_state)) {
  744. ret_val = -EPROTO;
  745. goto done;
  746. }
  747. if (io_state == VGA_RSRC_NONE) {
  748. ret_val = -EPROTO;
  749. goto done;
  750. }
  751. pdev = priv->target;
  752. if (priv->target == NULL) {
  753. ret_val = -ENODEV;
  754. goto done;
  755. }
  756. vga_get_uninterruptible(pdev, io_state);
  757. /* Update the client's locks lists... */
  758. for (i = 0; i < MAX_USER_CARDS; i++) {
  759. if (priv->cards[i].pdev == pdev) {
  760. if (io_state & VGA_RSRC_LEGACY_IO)
  761. priv->cards[i].io_cnt++;
  762. if (io_state & VGA_RSRC_LEGACY_MEM)
  763. priv->cards[i].mem_cnt++;
  764. break;
  765. }
  766. }
  767. ret_val = count;
  768. goto done;
  769. } else if (strncmp(curr_pos, "unlock ", 7) == 0) {
  770. curr_pos += 7;
  771. remaining -= 7;
  772. pr_debug("client 0x%p called 'unlock'\n", priv);
  773. if (strncmp(curr_pos, "all", 3) == 0)
  774. io_state = VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM;
  775. else {
  776. if (!vga_str_to_iostate
  777. (curr_pos, remaining, &io_state)) {
  778. ret_val = -EPROTO;
  779. goto done;
  780. }
  781. /* TODO: Add this?
  782. if (io_state == VGA_RSRC_NONE) {
  783. ret_val = -EPROTO;
  784. goto done;
  785. }
  786. */
  787. }
  788. pdev = priv->target;
  789. if (priv->target == NULL) {
  790. ret_val = -ENODEV;
  791. goto done;
  792. }
  793. for (i = 0; i < MAX_USER_CARDS; i++) {
  794. if (priv->cards[i].pdev == pdev)
  795. uc = &priv->cards[i];
  796. }
  797. if (!uc)
  798. return -EINVAL;
  799. if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0)
  800. return -EINVAL;
  801. if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0)
  802. return -EINVAL;
  803. vga_put(pdev, io_state);
  804. if (io_state & VGA_RSRC_LEGACY_IO)
  805. uc->io_cnt--;
  806. if (io_state & VGA_RSRC_LEGACY_MEM)
  807. uc->mem_cnt--;
  808. ret_val = count;
  809. goto done;
  810. } else if (strncmp(curr_pos, "trylock ", 8) == 0) {
  811. curr_pos += 8;
  812. remaining -= 8;
  813. pr_debug("client 0x%p called 'trylock'\n", priv);
  814. if (!vga_str_to_iostate(curr_pos, remaining, &io_state)) {
  815. ret_val = -EPROTO;
  816. goto done;
  817. }
  818. /* TODO: Add this?
  819. if (io_state == VGA_RSRC_NONE) {
  820. ret_val = -EPROTO;
  821. goto done;
  822. }
  823. */
  824. pdev = priv->target;
  825. if (priv->target == NULL) {
  826. ret_val = -ENODEV;
  827. goto done;
  828. }
  829. if (vga_tryget(pdev, io_state)) {
  830. /* Update the client's locks lists... */
  831. for (i = 0; i < MAX_USER_CARDS; i++) {
  832. if (priv->cards[i].pdev == pdev) {
  833. if (io_state & VGA_RSRC_LEGACY_IO)
  834. priv->cards[i].io_cnt++;
  835. if (io_state & VGA_RSRC_LEGACY_MEM)
  836. priv->cards[i].mem_cnt++;
  837. break;
  838. }
  839. }
  840. ret_val = count;
  841. goto done;
  842. } else {
  843. ret_val = -EBUSY;
  844. goto done;
  845. }
  846. } else if (strncmp(curr_pos, "target ", 7) == 0) {
  847. struct pci_bus *pbus;
  848. unsigned int domain, bus, devfn;
  849. struct vga_device *vgadev;
  850. curr_pos += 7;
  851. remaining -= 7;
  852. pr_debug("client 0x%p called 'target'\n", priv);
  853. /* if target is default */
  854. if (!strncmp(curr_pos, "default", 7))
  855. pdev = pci_dev_get(vga_default_device());
  856. else {
  857. if (!vga_pci_str_to_vars(curr_pos, remaining,
  858. &domain, &bus, &devfn)) {
  859. ret_val = -EPROTO;
  860. goto done;
  861. }
  862. pr_debug("vgaarb: %s ==> %x:%x:%x.%x\n", curr_pos,
  863. domain, bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
  864. pbus = pci_find_bus(domain, bus);
  865. pr_debug("vgaarb: pbus %p\n", pbus);
  866. if (pbus == NULL) {
  867. pr_err("vgaarb: invalid PCI domain and/or bus address %x:%x\n",
  868. domain, bus);
  869. ret_val = -ENODEV;
  870. goto done;
  871. }
  872. pdev = pci_get_slot(pbus, devfn);
  873. pr_debug("vgaarb: pdev %p\n", pdev);
  874. if (!pdev) {
  875. pr_err("vgaarb: invalid PCI address %x:%x\n",
  876. bus, devfn);
  877. ret_val = -ENODEV;
  878. goto done;
  879. }
  880. }
  881. vgadev = vgadev_find(pdev);
  882. pr_debug("vgaarb: vgadev %p\n", vgadev);
  883. if (vgadev == NULL) {
  884. pr_err("vgaarb: this pci device is not a vga device\n");
  885. pci_dev_put(pdev);
  886. ret_val = -ENODEV;
  887. goto done;
  888. }
  889. priv->target = pdev;
  890. for (i = 0; i < MAX_USER_CARDS; i++) {
  891. if (priv->cards[i].pdev == pdev)
  892. break;
  893. if (priv->cards[i].pdev == NULL) {
  894. priv->cards[i].pdev = pdev;
  895. priv->cards[i].io_cnt = 0;
  896. priv->cards[i].mem_cnt = 0;
  897. break;
  898. }
  899. }
  900. if (i == MAX_USER_CARDS) {
  901. pr_err("vgaarb: maximum user cards (%d) number reached!\n",
  902. MAX_USER_CARDS);
  903. pci_dev_put(pdev);
  904. /* XXX: which value to return? */
  905. ret_val = -ENOMEM;
  906. goto done;
  907. }
  908. ret_val = count;
  909. pci_dev_put(pdev);
  910. goto done;
  911. } else if (strncmp(curr_pos, "decodes ", 8) == 0) {
  912. curr_pos += 8;
  913. remaining -= 8;
  914. pr_debug("vgaarb: client 0x%p called 'decodes'\n", priv);
  915. if (!vga_str_to_iostate(curr_pos, remaining, &io_state)) {
  916. ret_val = -EPROTO;
  917. goto done;
  918. }
  919. pdev = priv->target;
  920. if (priv->target == NULL) {
  921. ret_val = -ENODEV;
  922. goto done;
  923. }
  924. __vga_set_legacy_decoding(pdev, io_state, true);
  925. ret_val = count;
  926. goto done;
  927. }
  928. /* If we got here, the message written is not part of the protocol! */
  929. kfree(kbuf);
  930. return -EPROTO;
  931. done:
  932. kfree(kbuf);
  933. return ret_val;
  934. }
  935. static unsigned int vga_arb_fpoll(struct file *file, poll_table * wait)
  936. {
  937. struct vga_arb_private *priv = file->private_data;
  938. pr_debug("%s\n", __func__);
  939. if (priv == NULL)
  940. return -ENODEV;
  941. poll_wait(file, &vga_wait_queue, wait);
  942. return POLLIN;
  943. }
  944. static int vga_arb_open(struct inode *inode, struct file *file)
  945. {
  946. struct vga_arb_private *priv;
  947. unsigned long flags;
  948. pr_debug("%s\n", __func__);
  949. priv = kmalloc(sizeof(struct vga_arb_private), GFP_KERNEL);
  950. if (priv == NULL)
  951. return -ENOMEM;
  952. memset(priv, 0, sizeof(*priv));
  953. spin_lock_init(&priv->lock);
  954. file->private_data = priv;
  955. spin_lock_irqsave(&vga_user_lock, flags);
  956. list_add(&priv->list, &vga_user_list);
  957. spin_unlock_irqrestore(&vga_user_lock, flags);
  958. /* Set the client' lists of locks */
  959. priv->target = vga_default_device(); /* Maybe this is still null! */
  960. priv->cards[0].pdev = priv->target;
  961. priv->cards[0].io_cnt = 0;
  962. priv->cards[0].mem_cnt = 0;
  963. return 0;
  964. }
  965. static int vga_arb_release(struct inode *inode, struct file *file)
  966. {
  967. struct vga_arb_private *priv = file->private_data;
  968. struct vga_arb_user_card *uc;
  969. unsigned long flags;
  970. int i;
  971. pr_debug("%s\n", __func__);
  972. if (priv == NULL)
  973. return -ENODEV;
  974. spin_lock_irqsave(&vga_user_lock, flags);
  975. list_del(&priv->list);
  976. for (i = 0; i < MAX_USER_CARDS; i++) {
  977. uc = &priv->cards[i];
  978. if (uc->pdev == NULL)
  979. continue;
  980. pr_debug("uc->io_cnt == %d, uc->mem_cnt == %d\n",
  981. uc->io_cnt, uc->mem_cnt);
  982. while (uc->io_cnt--)
  983. vga_put(uc->pdev, VGA_RSRC_LEGACY_IO);
  984. while (uc->mem_cnt--)
  985. vga_put(uc->pdev, VGA_RSRC_LEGACY_MEM);
  986. }
  987. spin_unlock_irqrestore(&vga_user_lock, flags);
  988. kfree(priv);
  989. return 0;
  990. }
  991. static void vga_arb_device_card_gone(struct pci_dev *pdev)
  992. {
  993. }
  994. /*
  995. * callback any registered clients to let them know we have a
  996. * change in VGA cards
  997. */
  998. static void vga_arbiter_notify_clients(void)
  999. {
  1000. struct vga_device *vgadev;
  1001. unsigned long flags;
  1002. uint32_t new_decodes;
  1003. bool new_state;
  1004. if (!vga_arbiter_used)
  1005. return;
  1006. spin_lock_irqsave(&vga_lock, flags);
  1007. list_for_each_entry(vgadev, &vga_list, list) {
  1008. if (vga_count > 1)
  1009. new_state = false;
  1010. else
  1011. new_state = true;
  1012. if (vgadev->set_vga_decode) {
  1013. new_decodes = vgadev->set_vga_decode(vgadev->cookie, new_state);
  1014. vga_update_device_decodes(vgadev, new_decodes);
  1015. }
  1016. }
  1017. spin_unlock_irqrestore(&vga_lock, flags);
  1018. }
  1019. static int pci_notify(struct notifier_block *nb, unsigned long action,
  1020. void *data)
  1021. {
  1022. struct device *dev = data;
  1023. struct pci_dev *pdev = to_pci_dev(dev);
  1024. bool notify = false;
  1025. pr_debug("%s\n", __func__);
  1026. /* For now we're only intereted in devices added and removed. I didn't
  1027. * test this thing here, so someone needs to double check for the
  1028. * cases of hotplugable vga cards. */
  1029. if (action == BUS_NOTIFY_ADD_DEVICE)
  1030. notify = vga_arbiter_add_pci_device(pdev);
  1031. else if (action == BUS_NOTIFY_DEL_DEVICE)
  1032. notify = vga_arbiter_del_pci_device(pdev);
  1033. if (notify)
  1034. vga_arbiter_notify_clients();
  1035. return 0;
  1036. }
  1037. static struct notifier_block pci_notifier = {
  1038. .notifier_call = pci_notify,
  1039. };
  1040. static const struct file_operations vga_arb_device_fops = {
  1041. .read = vga_arb_read,
  1042. .write = vga_arb_write,
  1043. .poll = vga_arb_fpoll,
  1044. .open = vga_arb_open,
  1045. .release = vga_arb_release,
  1046. .llseek = noop_llseek,
  1047. };
  1048. static struct miscdevice vga_arb_device = {
  1049. MISC_DYNAMIC_MINOR, "vga_arbiter", &vga_arb_device_fops
  1050. };
  1051. static int __init vga_arb_device_init(void)
  1052. {
  1053. int rc;
  1054. struct pci_dev *pdev;
  1055. rc = misc_register(&vga_arb_device);
  1056. if (rc < 0)
  1057. pr_err("vgaarb: error %d registering device\n", rc);
  1058. bus_register_notifier(&pci_bus_type, &pci_notifier);
  1059. /* We add all pci devices satisfying vga class in the arbiter by
  1060. * default */
  1061. pdev = NULL;
  1062. while ((pdev =
  1063. pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  1064. PCI_ANY_ID, pdev)) != NULL)
  1065. vga_arbiter_add_pci_device(pdev);
  1066. pr_info("vgaarb: loaded\n");
  1067. return rc;
  1068. }
  1069. subsys_initcall(vga_arb_device_init);