drm_agpsupport.h revision 1.9 1 /* $NetBSD: drm_agpsupport.h,v 1.9 2021/12/18 23:45:45 riastradh Exp $ */
2
3 /* SPDX-License-Identifier: GPL-2.0 */
4 #ifndef _DRM_AGPSUPPORT_H_
5 #define _DRM_AGPSUPPORT_H_
6
7 #include <linux/agp_backend.h>
8 #include <linux/kernel.h>
9 #include <linux/list.h>
10 #include <linux/mm.h>
11 #include <linux/mutex.h>
12 #include <linux/types.h>
13 #include <uapi/drm/drm.h>
14
15 #ifdef __NetBSD__
16 #include <drm/drm_agp_netbsd.h>
17 #endif
18
19 struct drm_device;
20 struct drm_file;
21
22 struct drm_agp_hooks {
23 void __pci_iomem *
24 (*agph_borrow)(struct drm_device *, unsigned, bus_size_t);
25 void (*agph_flush)(void);
26
27 struct drm_agp_head *
28 (*agph_init)(struct drm_device *);
29 void (*agph_clear)(struct drm_device *);
30 int (*agph_acquire)(struct drm_device *);
31 int (*agph_release)(struct drm_device *);
32 int (*agph_enable)(struct drm_device *, struct drm_agp_mode);
33 int (*agph_info)(struct drm_device *, struct drm_agp_info *);
34 int (*agph_alloc)(struct drm_device *, struct drm_agp_buffer *);
35 int (*agph_free)(struct drm_device *, struct drm_agp_buffer *);
36 int (*agph_bind)(struct drm_device *, struct drm_agp_binding *);
37 int (*agph_unbind)(struct drm_device *, struct drm_agp_binding *);
38
39 int (*agph_acquire_ioctl)(struct drm_device *, void *,
40 struct drm_file *);
41 int (*agph_release_ioctl)(struct drm_device *, void *,
42 struct drm_file *);
43 int (*agph_enable_ioctl)(struct drm_device *, void *,
44 struct drm_file *);
45 int (*agph_info_ioctl)(struct drm_device *, void *,
46 struct drm_file *);
47 int (*agph_alloc_ioctl)(struct drm_device *, void *,
48 struct drm_file *);
49 int (*agph_free_ioctl)(struct drm_device *, void *,
50 struct drm_file *);
51 int (*agph_bind_ioctl)(struct drm_device *, void *,
52 struct drm_file *);
53 int (*agph_unbind_ioctl)(struct drm_device *, void *,
54 struct drm_file *);
55 };
56
57 struct drm_agp_head {
58 const struct drm_agp_hooks *hooks;
59 struct agp_kern_info agp_info;
60 struct list_head memory;
61 unsigned long mode;
62 struct agp_bridge_data *bridge;
63 int enabled;
64 int acquired;
65 unsigned long base;
66 int agp_mtrr;
67 int cant_use_aperture;
68 unsigned long page_mask;
69 };
70
71 #if IS_ENABLED(CONFIG_AGP)
72
73 #ifdef __NetBSD__
74 static inline void drm_free_agp(struct agp_bridge_data *, struct agp_memory *, int);
75 static inline int drm_bind_agp(struct agp_bridge_data *, struct agp_memory *, unsigned);
76 static inline int drm_unbind_agp(struct agp_bridge_data *, struct agp_memory *);
77 #else
78 void drm_free_agp(struct agp_memory * handle, int pages);
79 int drm_bind_agp(struct agp_memory * handle, unsigned int start);
80 int drm_unbind_agp(struct agp_memory * handle);
81 #endif
82
83 struct drm_agp_head *drm_agp_init(struct drm_device *dev);
84 void drm_legacy_agp_clear(struct drm_device *dev);
85 int drm_agp_acquire(struct drm_device *dev);
86 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
87 struct drm_file *file_priv);
88 int drm_agp_release(struct drm_device *dev);
89 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
90 struct drm_file *file_priv);
91 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
92 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
93 struct drm_file *file_priv);
94 int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
95 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
96 struct drm_file *file_priv);
97 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
98 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
99 struct drm_file *file_priv);
100 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
101 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
102 struct drm_file *file_priv);
103 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
104 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
105 struct drm_file *file_priv);
106 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
107 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
108 struct drm_file *file_priv);
109
110 #ifdef __NetBSD__
111 void __pci_iomem *drm_agp_borrow(struct drm_device *, unsigned, bus_size_t);
112 void drm_agp_flush(void);
113 void drm_agp_fini(struct drm_device *);
114 int drm_agp_register(const struct drm_agp_hooks *);
115 int drm_agp_deregister(const struct drm_agp_hooks *);
116 void drm_agp_hooks_init(void);
117 void drm_agp_hooks_fini(void);
118 int drmkms_agp_guarantee_initialized(void);
119 #endif
120
121 #else /* CONFIG_AGP */
122
123 #if !defined(__NetBSD__)
124
125 static inline void drm_free_agp(struct agp_memory * handle, int pages)
126 {
127 }
128
129 static inline int drm_bind_agp(struct agp_memory * handle, unsigned int start)
130 {
131 return -ENODEV;
132 }
133
134 static inline int drm_unbind_agp(struct agp_memory * handle)
135 {
136 return -ENODEV;
137 }
138 #endif
139
140 static inline struct drm_agp_head *drm_agp_init(struct drm_device *dev)
141 {
142 return NULL;
143 }
144
145 static inline void drm_legacy_agp_clear(struct drm_device *dev)
146 {
147 }
148
149 static inline int drm_agp_acquire(struct drm_device *dev)
150 {
151 return -ENODEV;
152 }
153
154 static inline int drm_agp_release(struct drm_device *dev)
155 {
156 return -ENODEV;
157 }
158
159 static inline int drm_agp_enable(struct drm_device *dev,
160 struct drm_agp_mode mode)
161 {
162 return -ENODEV;
163 }
164
165 static inline int drm_agp_info(struct drm_device *dev,
166 struct drm_agp_info *info)
167 {
168 return -ENODEV;
169 }
170
171 static inline int drm_agp_alloc(struct drm_device *dev,
172 struct drm_agp_buffer *request)
173 {
174 return -ENODEV;
175 }
176
177 static inline int drm_agp_free(struct drm_device *dev,
178 struct drm_agp_buffer *request)
179 {
180 return -ENODEV;
181 }
182
183 static inline int drm_agp_unbind(struct drm_device *dev,
184 struct drm_agp_binding *request)
185 {
186 return -ENODEV;
187 }
188
189 static inline int drm_agp_bind(struct drm_device *dev,
190 struct drm_agp_binding *request)
191 {
192 return -ENODEV;
193 }
194
195 #endif /* CONFIG_AGP */
196
197 #endif /* _DRM_AGPSUPPORT_H_ */
198