Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vgaarbiter: rst-ifiy and polish kerneldoc

Move the documentation into Documentation/gpu, link it up and pull in
the kernel doc.

No actual text changes except that I did polish the kerneldoc a bit,
especially for vga_client_register().

v2: Remove some rst from vga-switcheroo.rst that I don't understand,
but which seems to be the reason why the new vgaarbiter.rst sometimes
drops out of the sidebar index.

v3: Drop one level of headings and clarify the vgaarb one a bit.

v4: Fix some typos (Sean).

Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-doc@vger.kernel.org
Cc: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1471034937-651-20-git-send-email-daniel.vetter@ffwll.ch

+196 -188
+1
Documentation/gpu/index.rst
··· 12 12 drm-uapi 13 13 i915 14 14 vga-switcheroo 15 + vgaarbiter
-2
Documentation/gpu/vga-switcheroo.rst
··· 1 - .. _vga_switcheroo: 2 - 3 1 ============== 4 2 VGA Switcheroo 5 3 ==============
+71 -72
Documentation/vgaarbiter.txt Documentation/gpu/vgaarbiter.rst
··· 1 - 1 + =========== 2 2 VGA Arbiter 3 3 =========== 4 4 ··· 19 19 is needed to control the sharing of these resources. This document introduces 20 20 the operation of the VGA arbiter implemented for the Linux kernel. 21 21 22 - ---------------------------------------------------------------------------- 23 - 24 - I. Details and Theory of Operation 25 - I.1 vgaarb 26 - I.2 libpciaccess 27 - I.3 xf86VGAArbiter (X server implementation) 28 - II. Credits 29 - III.References 30 - 31 - 32 - I. Details and Theory of Operation 33 - ================================== 34 - 35 - I.1 vgaarb 36 - ---------- 22 + vgaarb kernel/userspace ABI 23 + --------------------------- 37 24 38 25 The vgaarb is a module of the Linux Kernel. When it is initially loaded, it 39 26 scans all PCI devices and adds the VGA ones inside the arbitration. The ··· 31 44 The kernel exports a char device interface (/dev/vga_arbiter) to the clients, 32 45 which has the following semantics: 33 46 34 - open : open user instance of the arbiter. By default, it's attached to 35 - the default VGA device of the system. 47 + open 48 + Opens a user instance of the arbiter. By default, it's attached to the 49 + default VGA device of the system. 36 50 37 - close : close user instance. Release locks made by the user 51 + close 52 + Close a user instance. Release locks made by the user 38 53 39 - read : return a string indicating the status of the target like: 54 + read 55 + Return a string indicating the status of the target like: 40 56 41 - "<card_ID>,decodes=<io_state>,owns=<io_state>,locks=<io_state> (ic,mc)" 57 + "<card_ID>,decodes=<io_state>,owns=<io_state>,locks=<io_state> (ic,mc)" 42 58 43 - An IO state string is of the form {io,mem,io+mem,none}, mc and 44 - ic are respectively mem and io lock counts (for debugging/ 45 - diagnostic only). "decodes" indicate what the card currently 46 - decodes, "owns" indicates what is currently enabled on it, and 47 - "locks" indicates what is locked by this card. If the card is 48 - unplugged, we get "invalid" then for card_ID and an -ENODEV 49 - error is returned for any command until a new card is targeted. 59 + An IO state string is of the form {io,mem,io+mem,none}, mc and 60 + ic are respectively mem and io lock counts (for debugging/ 61 + diagnostic only). "decodes" indicate what the card currently 62 + decodes, "owns" indicates what is currently enabled on it, and 63 + "locks" indicates what is locked by this card. If the card is 64 + unplugged, we get "invalid" then for card_ID and an -ENODEV 65 + error is returned for any command until a new card is targeted. 50 66 51 67 52 - write : write a command to the arbiter. List of commands: 68 + write 69 + Write a command to the arbiter. List of commands: 53 70 54 - target <card_ID> : switch target to card <card_ID> (see below) 55 - lock <io_state> : acquires locks on target ("none" is an invalid io_state) 56 - trylock <io_state> : non-blocking acquire locks on target (returns EBUSY if 57 - unsuccessful) 58 - unlock <io_state> : release locks on target 59 - unlock all : release all locks on target held by this user (not 60 - implemented yet) 61 - decodes <io_state> : set the legacy decoding attributes for the card 71 + target <card_ID> 72 + switch target to card <card_ID> (see below) 73 + lock <io_state> 74 + acquires locks on target ("none" is an invalid io_state) 75 + trylock <io_state> 76 + non-blocking acquire locks on target (returns EBUSY if 77 + unsuccessful) 78 + unlock <io_state> 79 + release locks on target 80 + unlock all 81 + release all locks on target held by this user (not implemented 82 + yet) 83 + decodes <io_state> 84 + set the legacy decoding attributes for the card 62 85 63 - poll : event if something changes on any card (not just the 64 - target) 86 + poll 87 + event if something changes on any card (not just the target) 65 88 66 - card_ID is of the form "PCI:domain:bus:dev.fn". It can be set to "default" 67 - to go back to the system default card (TODO: not implemented yet). Currently, 68 - only PCI is supported as a prefix, but the userland API may support other bus 69 - types in the future, even if the current kernel implementation doesn't. 89 + card_ID is of the form "PCI:domain:bus:dev.fn". It can be set to "default" 90 + to go back to the system default card (TODO: not implemented yet). Currently, 91 + only PCI is supported as a prefix, but the userland API may support other bus 92 + types in the future, even if the current kernel implementation doesn't. 70 93 71 94 Note about locks: 72 95 ··· 94 97 There is also an in-kernel API of the arbiter in case DRM, vgacon, or other 95 98 drivers want to use it. 96 99 100 + In-kernel interface 101 + ------------------- 97 102 98 - I.2 libpciaccess 99 - ---------------- 103 + .. kernel-doc:: include/linux/vgaarb.h 104 + :internal: 105 + 106 + .. kernel-doc:: drivers/gpu/vga/vgaarb.c 107 + :export: 108 + 109 + libpciaccess 110 + ------------ 100 111 101 112 To use the vga arbiter char device it was implemented an API inside the 102 113 libpciaccess library. One field was added to struct pci_device (each device 103 - on the system): 114 + on the system):: 104 115 105 116 /* the type of resource decoded by the device */ 106 117 int vgaarb_rsrc; 107 118 108 - Besides it, in pci_system were added: 119 + Besides it, in pci_system were added:: 109 120 110 121 int vgaarb_fd; 111 122 int vga_count; 112 123 struct pci_device *vga_target; 113 124 struct pci_device *vga_default_dev; 114 125 115 - 116 126 The vga_count is used to track how many cards are being arbitrated, so for 117 127 instance, if there is only one card, then it can completely escape arbitration. 118 - 119 128 120 129 These functions below acquire VGA resources for the given card and mark those 121 130 resources as locked. If the resources requested are "normal" (and not legacy) ··· 139 136 succeeds. vga_arb_trylock() will return (-EBUSY) instead of blocking. Nested 140 137 calls are supported (a per-resource counter is maintained). 141 138 139 + Set the target device of this client. :: 142 140 143 - Set the target device of this client. 144 141 int pci_device_vgaarb_set_target (struct pci_device *dev); 145 - 146 142 147 143 For instance, in x86 if two devices on the same bus want to lock different 148 144 resources, both will succeed (lock). If devices are in different buses and 149 - trying to lock different resources, only the first who tried succeeds. 145 + trying to lock different resources, only the first who tried succeeds. :: 146 + 150 147 int pci_device_vgaarb_lock (void); 151 148 int pci_device_vgaarb_trylock (void); 152 149 153 - Unlock resources of device. 150 + Unlock resources of device. :: 151 + 154 152 int pci_device_vgaarb_unlock (void); 155 153 156 154 Indicates to the arbiter if the card decodes legacy VGA IOs, legacy VGA 157 155 Memory, both, or none. All cards default to both, the card driver (fbdev for 158 156 example) should tell the arbiter if it has disabled legacy decoding, so the 159 157 card can be left out of the arbitration process (and can be safe to take 160 - interrupts at any time. 158 + interrupts at any time. :: 159 + 161 160 int pci_device_vgaarb_decodes (int new_vgaarb_rsrc); 162 161 163 - Connects to the arbiter device, allocates the struct 162 + Connects to the arbiter device, allocates the struct :: 163 + 164 164 int pci_device_vgaarb_init (void); 165 165 166 - Close the connection 166 + Close the connection :: 167 + 167 168 void pci_device_vgaarb_fini (void); 168 169 169 - 170 - I.3 xf86VGAArbiter (X server implementation) 171 - -------------------------------------------- 172 - 173 - (TODO) 170 + xf86VGAArbiter (X server implementation) 171 + ---------------------------------------- 174 172 175 173 X server basically wraps all the functions that touch VGA registers somehow. 176 174 177 - 178 - II. Credits 179 - =========== 175 + References 176 + ---------- 180 177 181 178 Benjamin Herrenschmidt (IBM?) started this work when he discussed such design 182 179 with the Xorg community in 2005 [1, 2]. In the end of 2007, Paulo Zanoni and ··· 185 182 implementation of the user space side [3]. Now (2009) Tiago Vignatti and Dave 186 183 Airlie finally put this work in shape and queued to Jesse Barnes' PCI tree. 187 184 188 - 189 - III. References 190 - ============== 191 - 192 - [0] http://cgit.freedesktop.org/xorg/xserver/commit/?id=4b42448a2388d40f257774fbffdccaea87bd0347 193 - [1] http://lists.freedesktop.org/archives/xorg/2005-March/006663.html 194 - [2] http://lists.freedesktop.org/archives/xorg/2005-March/006745.html 195 - [3] http://lists.freedesktop.org/archives/xorg/2007-October/029507.html 185 + 0) http://cgit.freedesktop.org/xorg/xserver/commit/?id=4b42448a2388d40f257774fbffdccaea87bd0347 186 + 1) http://lists.freedesktop.org/archives/xorg/2005-March/006663.html 187 + 2) http://lists.freedesktop.org/archives/xorg/2005-March/006745.html 188 + 3) http://lists.freedesktop.org/archives/xorg/2007-October/029507.html
+108 -2
drivers/gpu/vga/vgaarb.c
··· 131 131 return NULL; 132 132 } 133 133 134 - /* Returns the default VGA device (vgacon's babe) */ 134 + /** 135 + * vga_default_device - return the default VGA device, for vgacon 136 + * 137 + * This can be defined by the platform. The default implementation 138 + * is rather dumb and will probably only work properly on single 139 + * vga card setups and/or x86 platforms. 140 + * 141 + * If your VGA default device is not PCI, you'll have to return 142 + * NULL here. In this case, I assume it will not conflict with 143 + * any PCI card. If this is not true, I'll have to define two archs 144 + * hooks for enabling/disabling the VGA default device if that is 145 + * possible. This may be a problem with real _ISA_ VGA cards, in 146 + * addition to a PCI one. I don't know at this point how to deal 147 + * with that card. Can theirs IOs be disabled at all ? If not, then 148 + * I suppose it's a matter of having the proper arch hook telling 149 + * us about it, so we basically never allow anybody to succeed a 150 + * vga_get()... 151 + */ 135 152 struct pci_dev *vga_default_device(void) 136 153 { 137 154 return vga_default; ··· 373 356 wake_up_all(&vga_wait_queue); 374 357 } 375 358 359 + /** 360 + * vga_get - acquire & locks VGA resources 361 + * @pdev: pci device of the VGA card or NULL for the system default 362 + * @rsrc: bit mask of resources to acquire and lock 363 + * @interruptible: blocking should be interruptible by signals ? 364 + * 365 + * This function acquires VGA resources for the given card and mark those 366 + * resources locked. If the resource requested are "normal" (and not legacy) 367 + * resources, the arbiter will first check whether the card is doing legacy 368 + * decoding for that type of resource. If yes, the lock is "converted" into a 369 + * legacy resource lock. 370 + * 371 + * The arbiter will first look for all VGA cards that might conflict and disable 372 + * their IOs and/or Memory access, including VGA forwarding on P2P bridges if 373 + * necessary, so that the requested resources can be used. Then, the card is 374 + * marked as locking these resources and the IO and/or Memory accesses are 375 + * enabled on the card (including VGA forwarding on parent P2P bridges if any). 376 + * 377 + * This function will block if some conflicting card is already locking one of 378 + * the required resources (or any resource on a different bus segment, since P2P 379 + * bridges don't differentiate VGA memory and IO afaik). You can indicate 380 + * whether this blocking should be interruptible by a signal (for userland 381 + * interface) or not. 382 + * 383 + * Must not be called at interrupt time or in atomic context. If the card 384 + * already owns the resources, the function succeeds. Nested calls are 385 + * supported (a per-resource counter is maintained) 386 + * 387 + * On success, release the VGA resource again with vga_put(). 388 + * 389 + * Returns: 390 + * 391 + * 0 on success, negative error code on failure. 392 + */ 376 393 int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible) 377 394 { 378 395 struct vga_device *vgadev, *conflict; ··· 459 408 } 460 409 EXPORT_SYMBOL(vga_get); 461 410 411 + /** 412 + * vga_tryget - try to acquire & lock legacy VGA resources 413 + * @pdev: pci devivce of VGA card or NULL for system default 414 + * @rsrc: bit mask of resources to acquire and lock 415 + * 416 + * This function performs the same operation as vga_get(), but will return an 417 + * error (-EBUSY) instead of blocking if the resources are already locked by 418 + * another card. It can be called in any context 419 + * 420 + * On success, release the VGA resource again with vga_put(). 421 + * 422 + * Returns: 423 + * 424 + * 0 on success, negative error code on failure. 425 + */ 462 426 int vga_tryget(struct pci_dev *pdev, unsigned int rsrc) 463 427 { 464 428 struct vga_device *vgadev; ··· 501 435 } 502 436 EXPORT_SYMBOL(vga_tryget); 503 437 438 + /** 439 + * vga_put - release lock on legacy VGA resources 440 + * @pdev: pci device of VGA card or NULL for system default 441 + * @rsrc: but mask of resource to release 442 + * 443 + * This fuction releases resources previously locked by vga_get() or 444 + * vga_tryget(). The resources aren't disabled right away, so that a subsequence 445 + * vga_get() on the same card will succeed immediately. Resources have a 446 + * counter, so locks are only released if the counter reaches 0. 447 + */ 504 448 void vga_put(struct pci_dev *pdev, unsigned int rsrc) 505 449 { 506 450 struct vga_device *vgadev; ··· 792 716 } 793 717 EXPORT_SYMBOL(vga_set_legacy_decoding); 794 718 795 - /* call with NULL to unregister */ 719 + /** 720 + * vga_client_register - register or unregister a VGA arbitration client 721 + * @pdev: pci device of the VGA client 722 + * @cookie: client cookie to be used in callbacks 723 + * @irq_set_state: irq state change callback 724 + * @set_vga_decode: vga decode change callback 725 + * 726 + * Clients have two callback mechanisms they can use. 727 + * 728 + * @irq_set_state callback: If a client can't disable its GPUs VGA 729 + * resources, then we need to be able to ask it to turn off its irqs when we 730 + * turn off its mem and io decoding. 731 + * 732 + * @set_vga_decode callback: If a client can disable its GPU VGA resource, it 733 + * will get a callback from this to set the encode/decode state. 734 + * 735 + * Rationale: we cannot disable VGA decode resources unconditionally some single 736 + * GPU laptops seem to require ACPI or BIOS access to the VGA registers to 737 + * control things like backlights etc. Hopefully newer multi-GPU laptops do 738 + * something saner, and desktops won't have any special ACPI for this. The 739 + * driver will get a callback when VGA arbitration is first used by userspace 740 + * since some older X servers have issues. 741 + * 742 + * This function does not check whether a client for @pdev has been registered 743 + * already. 744 + * 745 + * To unregister just call this function with @irq_set_state and @set_vga_decode 746 + * both set to NULL for the same @pdev as originally used to register them. 747 + * 748 + * Returns: 0 on success, -1 on failure 749 + */ 796 750 int vga_client_register(struct pci_dev *pdev, void *cookie, 797 751 void (*irq_set_state)(void *cookie, bool state), 798 752 unsigned int (*set_vga_decode)(void *cookie,
+16 -112
include/linux/vgaarb.h
··· 73 73 unsigned int decodes) { }; 74 74 #endif 75 75 76 - /** 77 - * vga_get - acquire & locks VGA resources 78 - * 79 - * @pdev: pci device of the VGA card or NULL for the system default 80 - * @rsrc: bit mask of resources to acquire and lock 81 - * @interruptible: blocking should be interruptible by signals ? 82 - * 83 - * This function acquires VGA resources for the given 84 - * card and mark those resources locked. If the resource requested 85 - * are "normal" (and not legacy) resources, the arbiter will first check 86 - * whether the card is doing legacy decoding for that type of resource. If 87 - * yes, the lock is "converted" into a legacy resource lock. 88 - * The arbiter will first look for all VGA cards that might conflict 89 - * and disable their IOs and/or Memory access, including VGA forwarding 90 - * on P2P bridges if necessary, so that the requested resources can 91 - * be used. Then, the card is marked as locking these resources and 92 - * the IO and/or Memory accesse are enabled on the card (including 93 - * VGA forwarding on parent P2P bridges if any). 94 - * This function will block if some conflicting card is already locking 95 - * one of the required resources (or any resource on a different bus 96 - * segment, since P2P bridges don't differenciate VGA memory and IO 97 - * afaik). You can indicate whether this blocking should be interruptible 98 - * by a signal (for userland interface) or not. 99 - * Must not be called at interrupt time or in atomic context. 100 - * If the card already owns the resources, the function succeeds. 101 - * Nested calls are supported (a per-resource counter is maintained) 102 - */ 103 - 104 76 #if defined(CONFIG_VGA_ARB) 105 77 extern int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible); 106 78 #else ··· 80 108 #endif 81 109 82 110 /** 83 - * vga_get_interruptible 111 + * vga_get_interruptible 112 + * @pdev: pci device of the VGA card or NULL for the system default 113 + * @rsrc: bit mask of resources to acquire and lock 84 114 * 85 - * Shortcut to vga_get 115 + * Shortcut to vga_get with interruptible set to true. 116 + * 117 + * On success, release the VGA resource again with vga_put(). 86 118 */ 87 - 88 119 static inline int vga_get_interruptible(struct pci_dev *pdev, 89 120 unsigned int rsrc) 90 121 { ··· 95 120 } 96 121 97 122 /** 98 - * vga_get_uninterruptible 123 + * vga_get_uninterruptible - shortcut to vga_get() 124 + * @pdev: pci device of the VGA card or NULL for the system default 125 + * @rsrc: bit mask of resources to acquire and lock 99 126 * 100 - * Shortcut to vga_get 127 + * Shortcut to vga_get with interruptible set to false. 128 + * 129 + * On success, release the VGA resource again with vga_put(). 101 130 */ 102 - 103 131 static inline int vga_get_uninterruptible(struct pci_dev *pdev, 104 132 unsigned int rsrc) 105 133 { 106 134 return vga_get(pdev, rsrc, 0); 107 135 } 108 - 109 - /** 110 - * vga_tryget - try to acquire & lock legacy VGA resources 111 - * 112 - * @pdev: pci devivce of VGA card or NULL for system default 113 - * @rsrc: bit mask of resources to acquire and lock 114 - * 115 - * This function performs the same operation as vga_get(), but 116 - * will return an error (-EBUSY) instead of blocking if the resources 117 - * are already locked by another card. It can be called in any context 118 - */ 119 136 120 137 #if defined(CONFIG_VGA_ARB) 121 138 extern int vga_tryget(struct pci_dev *pdev, unsigned int rsrc); ··· 115 148 static inline int vga_tryget(struct pci_dev *pdev, unsigned int rsrc) { return 0; } 116 149 #endif 117 150 118 - /** 119 - * vga_put - release lock on legacy VGA resources 120 - * 121 - * @pdev: pci device of VGA card or NULL for system default 122 - * @rsrc: but mask of resource to release 123 - * 124 - * This function releases resources previously locked by vga_get() 125 - * or vga_tryget(). The resources aren't disabled right away, so 126 - * that a subsequence vga_get() on the same card will succeed 127 - * immediately. Resources have a counter, so locks are only 128 - * released if the counter reaches 0. 129 - */ 130 - 131 151 #if defined(CONFIG_VGA_ARB) 132 152 extern void vga_put(struct pci_dev *pdev, unsigned int rsrc); 133 153 #else 134 154 #define vga_put(pdev, rsrc) 135 155 #endif 136 156 137 - 138 - /** 139 - * vga_default_device 140 - * 141 - * This can be defined by the platform. The default implementation 142 - * is rather dumb and will probably only work properly on single 143 - * vga card setups and/or x86 platforms. 144 - * 145 - * If your VGA default device is not PCI, you'll have to return 146 - * NULL here. In this case, I assume it will not conflict with 147 - * any PCI card. If this is not true, I'll have to define two archs 148 - * hooks for enabling/disabling the VGA default device if that is 149 - * possible. This may be a problem with real _ISA_ VGA cards, in 150 - * addition to a PCI one. I don't know at this point how to deal 151 - * with that card. Can theirs IOs be disabled at all ? If not, then 152 - * I suppose it's a matter of having the proper arch hook telling 153 - * us about it, so we basically never allow anybody to succeed a 154 - * vga_get()... 155 - */ 156 157 157 158 #ifdef CONFIG_VGA_ARB 158 159 extern struct pci_dev *vga_default_device(void); ··· 130 195 static inline void vga_set_default_device(struct pci_dev *pdev) { }; 131 196 #endif 132 197 133 - /** 134 - * vga_conflicts 135 - * 136 - * Architectures should define this if they have several 137 - * independent PCI domains that can afford concurrent VGA 138 - * decoding 198 + /* 199 + * Architectures should define this if they have several 200 + * independent PCI domains that can afford concurrent VGA 201 + * decoding 139 202 */ 140 - 141 203 #ifndef __ARCH_HAS_VGA_CONFLICT 142 204 static inline int vga_conflicts(struct pci_dev *p1, struct pci_dev *p2) 143 205 { ··· 142 210 } 143 211 #endif 144 212 145 - /** 146 - * vga_client_register 147 - * 148 - * @pdev: pci device of the VGA client 149 - * @cookie: client cookie to be used in callbacks 150 - * @irq_set_state: irq state change callback 151 - * @set_vga_decode: vga decode change callback 152 - * 153 - * return value: 0 on success, -1 on failure 154 - * Register a client with the VGA arbitration logic 155 - * 156 - * Clients have two callback mechanisms they can use. 157 - * irq enable/disable callback - 158 - * If a client can't disable its GPUs VGA resources, then we 159 - * need to be able to ask it to turn off its irqs when we 160 - * turn off its mem and io decoding. 161 - * set_vga_decode 162 - * If a client can disable its GPU VGA resource, it will 163 - * get a callback from this to set the encode/decode state 164 - * 165 - * Rationale: we cannot disable VGA decode resources unconditionally 166 - * some single GPU laptops seem to require ACPI or BIOS access to the 167 - * VGA registers to control things like backlights etc. 168 - * Hopefully newer multi-GPU laptops do something saner, and desktops 169 - * won't have any special ACPI for this. 170 - * They driver will get a callback when VGA arbitration is first used 171 - * by userspace since we some older X servers have issues. 172 - */ 173 213 #if defined(CONFIG_VGA_ARB) 174 214 int vga_client_register(struct pci_dev *pdev, void *cookie, 175 215 void (*irq_set_state)(void *cookie, bool state),