1 /* SPDX-License-Identifier: MIT */
2 
3 /*
4  * The VGA aribiter manages VGA space routing and VGA resource decode to
5  * allow multiple VGA devices to be used in a system in a safe way.
6  *
7  * (C) Copyright 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org>
8  * (C) Copyright 2007 Paulo R. Zanoni <przanoni@gmail.com>
9  * (C) Copyright 2007, 2009 Tiago Vignatti <vignatti@freedesktop.org>
10  */
11 
12 #ifndef LINUX_VGA_H
13 #define LINUX_VGA_H
14 
15 #include <video/vga.h>
16 
17 struct pci_dev;
18 
19 /* Legacy VGA regions */
20 #define VGA_RSRC_NONE	       0x00
21 #define VGA_RSRC_LEGACY_IO     0x01
22 #define VGA_RSRC_LEGACY_MEM    0x02
23 #define VGA_RSRC_LEGACY_MASK   (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
24 /* Non-legacy access */
25 #define VGA_RSRC_NORMAL_IO     0x04
26 #define VGA_RSRC_NORMAL_MEM    0x08
27 
28 #ifdef CONFIG_VGA_ARB
29 void vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes);
30 int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible);
31 void vga_put(struct pci_dev *pdev, unsigned int rsrc);
32 struct pci_dev *vga_default_device(void);
33 void vga_set_default_device(struct pci_dev *pdev);
34 int vga_remove_vgacon(struct pci_dev *pdev);
35 int vga_client_register(struct pci_dev *pdev,
36 		unsigned int (*set_decode)(struct pci_dev *pdev, bool state));
37 #else /* CONFIG_VGA_ARB */
vga_set_legacy_decoding(struct pci_dev * pdev,unsigned int decodes)38 static inline void vga_set_legacy_decoding(struct pci_dev *pdev,
39 		unsigned int decodes)
40 {
41 };
vga_get(struct pci_dev * pdev,unsigned int rsrc,int interruptible)42 static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc,
43 		int interruptible)
44 {
45 	return 0;
46 }
vga_put(struct pci_dev * pdev,unsigned int rsrc)47 static inline void vga_put(struct pci_dev *pdev, unsigned int rsrc)
48 {
49 }
vga_default_device(void)50 static inline struct pci_dev *vga_default_device(void)
51 {
52 	return NULL;
53 }
vga_set_default_device(struct pci_dev * pdev)54 static inline void vga_set_default_device(struct pci_dev *pdev)
55 {
56 }
vga_remove_vgacon(struct pci_dev * pdev)57 static inline int vga_remove_vgacon(struct pci_dev *pdev)
58 {
59 	return 0;
60 }
vga_client_register(struct pci_dev * pdev,unsigned int (* set_decode)(struct pci_dev * pdev,bool state))61 static inline int vga_client_register(struct pci_dev *pdev,
62 		unsigned int (*set_decode)(struct pci_dev *pdev, bool state))
63 {
64 	return 0;
65 }
66 #endif /* CONFIG_VGA_ARB */
67 
68 /**
69  * vga_get_interruptible
70  * @pdev: pci device of the VGA card or NULL for the system default
71  * @rsrc: bit mask of resources to acquire and lock
72  *
73  * Shortcut to vga_get with interruptible set to true.
74  *
75  * On success, release the VGA resource again with vga_put().
76  */
vga_get_interruptible(struct pci_dev * pdev,unsigned int rsrc)77 static inline int vga_get_interruptible(struct pci_dev *pdev,
78 					unsigned int rsrc)
79 {
80 	return vga_get(pdev, rsrc, 1);
81 }
82 
83 /**
84  * vga_get_uninterruptible - shortcut to vga_get()
85  * @pdev: pci device of the VGA card or NULL for the system default
86  * @rsrc: bit mask of resources to acquire and lock
87  *
88  * Shortcut to vga_get with interruptible set to false.
89  *
90  * On success, release the VGA resource again with vga_put().
91  */
vga_get_uninterruptible(struct pci_dev * pdev,unsigned int rsrc)92 static inline int vga_get_uninterruptible(struct pci_dev *pdev,
93 					  unsigned int rsrc)
94 {
95 	return vga_get(pdev, rsrc, 0);
96 }
97 
vga_client_unregister(struct pci_dev * pdev)98 static inline void vga_client_unregister(struct pci_dev *pdev)
99 {
100 	vga_client_register(pdev, NULL);
101 }
102 
103 #endif /* LINUX_VGA_H */
104