Linux 6.10-rc4
[linux-block.git] / include / linux / vgaarb.h
CommitLineData
02158453
SJ
1/* SPDX-License-Identifier: MIT */
2
deb2d2ec 3/*
e2d4304b
JB
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.
deb2d2ec
BH
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
a6a1a095 13#define LINUX_VGA_H
deb2d2ec 14
1a39b310 15#include <video/vga.h>
deb2d2ec 16
6609176f
CH
17struct pci_dev;
18
deb2d2ec
BH
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
6609176f
CH
28#ifdef CONFIG_VGA_ARB
29void vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes);
30int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible);
31void vga_put(struct pci_dev *pdev, unsigned int rsrc);
32struct pci_dev *vga_default_device(void);
33void vga_set_default_device(struct pci_dev *pdev);
34int vga_remove_vgacon(struct pci_dev *pdev);
bf44e8ce
CH
35int vga_client_register(struct pci_dev *pdev,
36 unsigned int (*set_decode)(struct pci_dev *pdev, bool state));
6609176f 37#else /* CONFIG_VGA_ARB */
0ea18b40 38static inline void vga_set_legacy_decoding(struct pci_dev *pdev,
6609176f
CH
39 unsigned int decodes)
40{
41};
42static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc,
43 int interruptible)
44{
45 return 0;
46}
47static inline void vga_put(struct pci_dev *pdev, unsigned int rsrc)
48{
49}
50static inline struct pci_dev *vga_default_device(void)
51{
52 return NULL;
53}
54static inline void vga_set_default_device(struct pci_dev *pdev)
55{
56}
57static inline int vga_remove_vgacon(struct pci_dev *pdev)
58{
59 return 0;
60}
bf44e8ce
CH
61static inline int vga_client_register(struct pci_dev *pdev,
62 unsigned int (*set_decode)(struct pci_dev *pdev, bool state))
6609176f
CH
63{
64 return 0;
65}
66#endif /* CONFIG_VGA_ARB */
deb2d2ec
BH
67
68/**
b754b35b
DV
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
deb2d2ec 72 *
b754b35b
DV
73 * Shortcut to vga_get with interruptible set to true.
74 *
75 * On success, release the VGA resource again with vga_put().
deb2d2ec 76 */
deb2d2ec 77static inline int vga_get_interruptible(struct pci_dev *pdev,
6ac3bd52 78 unsigned int rsrc)
deb2d2ec 79{
cc64ca4b 80 return vga_get(pdev, rsrc, 1);
deb2d2ec
BH
81}
82
83/**
b754b35b
DV
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
deb2d2ec 87 *
b754b35b
DV
88 * Shortcut to vga_get with interruptible set to false.
89 *
90 * On success, release the VGA resource again with vga_put().
deb2d2ec 91 */
deb2d2ec 92static inline int vga_get_uninterruptible(struct pci_dev *pdev,
6ac3bd52 93 unsigned int rsrc)
deb2d2ec 94{
cc64ca4b 95 return vga_get(pdev, rsrc, 0);
deb2d2ec
BH
96}
97
b8779475
CH
98static inline void vga_client_unregister(struct pci_dev *pdev)
99{
bf44e8ce 100 vga_client_register(pdev, NULL);
b8779475
CH
101}
102
deb2d2ec 103#endif /* LINUX_VGA_H */