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