xref: /netbsd-src/sys/external/bsd/drm2/include/drm/drm_agp_netbsd.h (revision 80d9064ac03cbb6a4174695f0d5b237c8766d3d0)
1 /*	$NetBSD: drm_agp_netbsd.h,v 1.4 2014/08/23 08:03:33 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	__OS_HAS_AGP	1
51 
52 #define	PCI_AGP_COMMAND_FW	AGPCMD_FWEN
53 
54 __CTASSERT(PAGE_SIZE == AGP_PAGE_SIZE);
55 __CTASSERT(PAGE_SHIFT == AGP_PAGE_SHIFT);
56 
57 struct agp_kern_info {
58 	struct agp_info aki_info;
59 };
60 
61 struct agp_bridge_data {
62 	struct agp_softc abd_sc; /* XXX Abstraction violation! */
63 };
64 
65 /*
66  * We already have a struct agp_memory, but fortunately it looks like
67  * it may accidentally work out.
68  */
69 
70 #if 0
71 struct agp_memory {
72 	void *am_cookie;
73 };
74 #endif
75 
76 static inline struct agp_bridge_data *
77 agp_find_bridge(struct pci_dev *pdev __unused)
78 {
79 	/*
80 	 * XXX How do we find the agp bridge attached to this
81 	 * particular PCI device?
82 	 */
83 	return container_of((struct agp_softc *)agp_find_device(0),
84 	    struct agp_bridge_data, abd_sc);
85 }
86 
87 static inline struct agp_bridge_data *
88 agp_backend_acquire(struct pci_dev *pdev)
89 {
90 	struct agp_bridge_data *const bridge = agp_find_bridge(pdev);
91 
92 	if (bridge == NULL)
93 		return NULL;
94 
95 	/* XXX We lose the error code here.  */
96 	if (agp_acquire(&bridge->abd_sc) != 0)
97 		return NULL;
98 
99 	return bridge;
100 }
101 
102 static inline void
103 agp_backend_release(struct agp_bridge_data *bridge)
104 {
105 
106 	/* XXX We lose the error code here.  */
107 	(void)agp_release(&bridge->abd_sc);
108 }
109 
110 /*
111  * Happily, agp_enable will accidentally DTRT as is in NetBSD in spite
112  * of the name collision, thanks to a curious `void *' argument in its
113  * declaration...
114  */
115 
116 #if 0
117 static inline void
118 agp_enable(struct agp_bridge_data *bridge)
119 {
120 	...
121 }
122 #endif
123 
124 static inline struct agp_memory *
125 agp_allocate_memory(struct agp_bridge_data *bridge, size_t npages,
126     uint32_t type)
127 {
128 	return agp_alloc_memory(&bridge->abd_sc, (npages << AGP_PAGE_SHIFT),
129 	    type);
130 }
131 
132 /*
133  * Once again, a happy accident makes agp_free_memory work out.
134  */
135 
136 #if 0
137 static inline void
138 agp_free_memory(struct agp_bridge_data *bridge, struct agp_memory *mem)
139 {
140 	...
141 }
142 #endif
143 
144 /*
145  * Unfortunately, Linux's agp_bind_memory doesn't require the agp
146  * device as an argument.  So we'll have to kludge that up as we go.
147  */
148 #if 0
149 static inline void
150 agp_bind_memory(struct agp_memory *mem, size_t npages)
151 {
152 	agp_bind_memory(???, mem, (npages << AGP_PAGE_SHIFT));
153 }
154 #endif
155 
156 static inline void
157 agp_copy_info(struct agp_bridge_data *bridge, struct agp_kern_info *info)
158 {
159 	agp_get_info(bridge, &info->aki_info);
160 }
161 
162 static inline int
163 drm_bind_agp(struct agp_bridge_data *bridge, struct agp_memory *mem,
164     unsigned npages)
165 {
166 	return agp_bind_memory(&bridge->abd_sc, mem,
167 	    ((size_t)npages << AGP_PAGE_SHIFT));
168 }
169 
170 static inline int
171 drm_unbind_agp(struct agp_bridge_data *bridge, struct agp_memory *mem)
172 {
173 	return agp_unbind_memory(&bridge->abd_sc, mem);
174 }
175 
176 static inline void
177 drm_free_agp(struct agp_bridge_data *bridge, struct agp_memory *mem,
178     int npages __unused)
179 {
180 	agp_free_memory(&bridge->abd_sc, mem);
181 }
182 
183 #endif  /* _DRM_DRM_AGP_NETBSD_H_ */
184