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