drm_agp_netbsd.h revision 1.7 1 /* $NetBSD: drm_agp_netbsd.h,v 1.7 2018/08/27 13:55:24 riastradh Exp $ */
2
3 /*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _DRM_DRM_AGP_NETBSD_H_
33 #define _DRM_DRM_AGP_NETBSD_H_
34
35 /*
36 * XXX XXX XXX BEWARE! This file is full of abstraction violations
37 * that are ruthlessly exploited for their value as happy accidents!
38 * You have been warned!
39 */
40
41 #include <sys/agpio.h>
42
43 #include <dev/pci/pcivar.h> /* XXX include order botch */
44 #include <dev/pci/agpreg.h>
45 #include <dev/pci/agpvar.h>
46
47 #include <linux/kernel.h>
48 #include <linux/pci.h>
49
50 #define PCI_AGP_COMMAND_FW AGPCMD_FWEN
51
52 #if defined(__i386__) || defined(__x86_64__)
53 #if defined(_KERNEL_OPT)
54 #include "agp.h"
55 #else
56 #define NAGP 1
57 #endif
58 #if NAGP > 0
59 #define CONFIG_AGP 1
60 #endif
61 __CTASSERT(PAGE_SIZE == AGP_PAGE_SIZE);
62 __CTASSERT(PAGE_SHIFT == AGP_PAGE_SHIFT);
63 #endif
64
65 struct agp_kern_info {
66 struct agp_info aki_info;
67 };
68
69 struct agp_bridge_data {
70 struct agp_softc abd_sc; /* XXX Abstraction violation! */
71 };
72
73 /*
74 * We already have a struct agp_memory, but fortunately it looks like
75 * it may accidentally work out.
76 */
77
78 #if 0
79 struct agp_memory {
80 void *am_cookie;
81 };
82 #endif
83
84 static inline struct agp_bridge_data *
85 agp_find_bridge(struct pci_dev *pdev __unused)
86 {
87 /*
88 * XXX How do we find the agp bridge attached to this
89 * particular PCI device?
90 */
91 return container_of((struct agp_softc *)agp_find_device(0),
92 struct agp_bridge_data, abd_sc);
93 }
94
95 static inline struct agp_bridge_data *
96 agp_backend_acquire(struct pci_dev *pdev)
97 {
98 struct agp_bridge_data *const bridge = agp_find_bridge(pdev);
99
100 if (bridge == NULL)
101 return NULL;
102
103 /* XXX We lose the error code here. */
104 if (agp_acquire(&bridge->abd_sc) != 0)
105 return NULL;
106
107 return bridge;
108 }
109
110 static inline void
111 agp_backend_release(struct agp_bridge_data *bridge)
112 {
113
114 /* XXX We lose the error code here. */
115 (void)agp_release(&bridge->abd_sc);
116 }
117
118 /*
119 * Happily, agp_enable will accidentally DTRT as is in NetBSD in spite
120 * of the name collision, thanks to a curious `void *' argument in its
121 * declaration...
122 */
123
124 #if 0
125 static inline void
126 agp_enable(struct agp_bridge_data *bridge)
127 {
128 ...
129 }
130 #endif
131
132 static inline struct agp_memory *
133 agp_allocate_memory(struct agp_bridge_data *bridge, size_t npages,
134 uint32_t type)
135 {
136 return agp_alloc_memory(&bridge->abd_sc, (npages << AGP_PAGE_SHIFT),
137 type);
138 }
139
140 /*
141 * Once again, a happy accident makes agp_free_memory work out.
142 */
143
144 #if 0
145 static inline void
146 agp_free_memory(struct agp_bridge_data *bridge, struct agp_memory *mem)
147 {
148 ...
149 }
150 #endif
151
152 /*
153 * Unfortunately, Linux's agp_bind_memory doesn't require the agp
154 * device as an argument. So we'll have to kludge that up as we go.
155 */
156 #if 0
157 static inline void
158 agp_bind_memory(struct agp_memory *mem, size_t npages)
159 {
160 agp_bind_memory(???, mem, (npages << AGP_PAGE_SHIFT));
161 }
162 #endif
163
164 static inline void
165 agp_copy_info(struct agp_bridge_data *bridge, struct agp_kern_info *info)
166 {
167 agp_get_info(bridge, &info->aki_info);
168 }
169
170 static inline int
171 drm_bind_agp(struct agp_bridge_data *bridge, struct agp_memory *mem,
172 unsigned npages)
173 {
174 return agp_bind_memory(&bridge->abd_sc, mem,
175 ((size_t)npages << AGP_PAGE_SHIFT));
176 }
177
178 static inline int
179 drm_unbind_agp(struct agp_bridge_data *bridge, struct agp_memory *mem)
180 {
181 return agp_unbind_memory(&bridge->abd_sc, mem);
182 }
183
184 static inline void
185 drm_free_agp(struct agp_bridge_data *bridge, struct agp_memory *mem,
186 int npages __unused)
187 {
188 agp_free_memory(&bridge->abd_sc, mem);
189 }
190
191 #endif /* _DRM_DRM_AGP_NETBSD_H_ */
192