agpvar.h revision 1.2.2.3 1 /* $NetBSD: agpvar.h,v 1.2.2.3 2002/01/10 19:56:25 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2000 Doug Rabson
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD: src/sys/pci/agppriv.h,v 1.3 2000/07/12 10:13:04 dfr Exp $
29 */
30
31 #ifndef _PCI_AGPVAR_H_
32 #define _PCI_AGPVAR_H_
33
34 #include <sys/lock.h>
35
36 struct agpbus_attach_args {
37 char *apa_busname;
38 struct pci_attach_args apa_pci_args;
39 };
40
41 /*
42 * The AGP chipset can be acquired by user or kernel code. If the
43 * chipset has already been acquired, it cannot be acquired by another
44 * user until the previous user has released it.
45 */
46 enum agp_acquire_state {
47 AGP_ACQUIRE_FREE,
48 AGP_ACQUIRE_USER,
49 AGP_ACQUIRE_KERNEL
50 };
51
52 /*
53 * This structure is used to query the state of the AGP system.
54 */
55 struct agp_info {
56 u_int32_t ai_mode;
57 bus_addr_t ai_aperture_base;
58 bus_size_t ai_aperture_size;
59 vsize_t ai_memory_allowed;
60 vsize_t ai_memory_used;
61 u_int32_t ai_devid;
62 };
63
64 struct agp_memory_info {
65 vsize_t ami_size; /* size in bytes */
66 bus_addr_t ami_physical; /* bogus hack for i810 */
67 off_t ami_offset; /* page offset if bound */
68 int ami_is_bound; /* non-zero if bound */
69 };
70
71 #define AGP_DEBUGxx
72
73 #ifdef AGP_DEBUG
74 #define AGP_DPF(x...) do { \
75 printf("agp: "); \
76 printf(##x); \
77 } while (0)
78 #else
79 #define AGP_DPF(x...) do {} while (0)
80 #endif
81
82 #define AGPUNIT(x) minor(x)
83
84 /*
85 * Data structure to describe an AGP memory allocation.
86 */
87 TAILQ_HEAD(agp_memory_list, agp_memory);
88 struct agp_memory {
89 TAILQ_ENTRY(agp_memory) am_link; /* wiring for the tailq */
90 int am_id; /* unique id for block */
91 vsize_t am_size; /* number of bytes allocated */
92 int am_type; /* chipset specific type */
93 off_t am_offset; /* page offset if bound */
94 int am_is_bound; /* non-zero if bound */
95 bus_addr_t am_physical;
96 caddr_t am_virtual;
97 bus_dmamap_t am_dmamap;
98 bus_dma_segment_t *am_dmaseg;
99 int am_nseg;
100 };
101
102 struct agp_softc;
103
104 struct agp_methods {
105 u_int32_t (*get_aperture)(struct agp_softc *);
106 int (*set_aperture)(struct agp_softc *, u_int32_t);
107 int (*bind_page)(struct agp_softc *, off_t, bus_addr_t);
108 int (*unbind_page)(struct agp_softc *, off_t);
109 void (*flush_tlb)(struct agp_softc *);
110 int (*enable)(struct agp_softc *, u_int32_t mode);
111 struct agp_memory *(*alloc_memory)(struct agp_softc *, int, vsize_t);
112 int (*free_memory)(struct agp_softc *, struct agp_memory *);
113 int (*bind_memory)(struct agp_softc *, struct agp_memory *, off_t);
114 int (*unbind_memory)(struct agp_softc *, struct agp_memory *);
115 };
116
117 #define AGP_GET_APERTURE(sc) ((sc)->as_methods->get_aperture(sc))
118 #define AGP_SET_APERTURE(sc,a) ((sc)->as_methods->set_aperture((sc),(a)))
119 #define AGP_BIND_PAGE(sc,o,p) ((sc)->as_methods->bind_page((sc),(o),(p)))
120 #define AGP_UNBIND_PAGE(sc,o) ((sc)->as_methods->unbind_page((sc), (o)))
121 #define AGP_FLUSH_TLB(sc) ((sc)->as_methods->flush_tlb(sc))
122 #define AGP_ENABLE(sc,m) ((sc)->as_methods->enable((sc),(m)))
123 #define AGP_ALLOC_MEMORY(sc,t,s) ((sc)->as_methods->alloc_memory((sc),(t),(s)))
124 #define AGP_FREE_MEMORY(sc,m) ((sc)->as_methods->free_memory((sc),(m)))
125 #define AGP_BIND_MEMORY(sc,m,o) ((sc)->as_methods->bind_memory((sc),(m),(o)))
126 #define AGP_UNBIND_MEMORY(sc,m) ((sc)->as_methods->unbind_memory((sc),(m)))
127
128 /*
129 * All chipset drivers must have this at the start of their softc.
130 */
131 struct agp_softc {
132 struct device as_dev;
133 bus_space_tag_t as_apt;
134 int as_capoff;
135 bus_addr_t as_apaddr;
136 bus_size_t as_apsize;
137 int as_apflags;
138 bus_dma_tag_t as_dmat;
139 u_int32_t as_maxmem; /* allocation upper bound */
140 u_int32_t as_allocated; /* amount allocated */
141 enum agp_acquire_state as_state;
142 struct agp_memory_list as_memory; /* list of allocated memory */
143 int as_nextid; /* next memory block id */
144 int as_isopen; /* user device is open */
145 #if 0
146 dev_t as_devnode; /* from make_dev */
147 #endif
148 struct lock as_lock; /* lock for access to GATT */
149 struct agp_methods *as_methods; /* chipset-dependent API */
150 void *as_chipc; /* chipset-dependent state */
151 pci_chipset_tag_t as_pc;
152 pcitag_t as_tag;
153 pcireg_t as_id;
154 };
155
156 struct agp_gatt {
157 u_int32_t ag_entries;
158 u_int32_t *ag_virtual;
159 bus_addr_t ag_physical;
160 bus_dmamap_t ag_dmamap;
161 bus_dma_segment_t ag_dmaseg;
162 size_t ag_size;
163 };
164
165 /*
166 * Functions private to the AGP code.
167 */
168 void agp_flush_cache(void);
169 int agp_find_caps(pci_chipset_tag_t pct, pcitag_t pt);
170 int agp_map_aperture(struct pci_attach_args *pa, struct agp_softc *sc);
171 struct agp_gatt *agp_alloc_gatt(struct agp_softc *sc);
172 void agp_free_gatt(struct agp_softc *sc, struct agp_gatt *gatt);
173 int agp_generic_attach(struct agp_softc *sc);
174 int agp_generic_detach(struct agp_softc *sc);
175 int agp_generic_enable(struct agp_softc *sc, u_int32_t mode);
176 struct agp_memory *agp_generic_alloc_memory(struct agp_softc *sc, int type,
177 vsize_t size);
178 int agp_generic_free_memory(struct agp_softc *sc, struct agp_memory *mem);
179 int agp_generic_bind_memory(struct agp_softc *sc, struct agp_memory *mem,
180 off_t offset);
181 int agp_generic_unbind_memory(struct agp_softc *sc, struct agp_memory *mem);
182
183 /* The vendor has already been matched when these functions are called */
184 int agp_amd_match(const struct pci_attach_args *);
185
186 int agp_ali_attach(struct device *parent, struct device *self, void *aux);
187 int agp_amd_attach(struct device *parent, struct device *self, void *aux);
188 int agp_i810_attach(struct device *parent, struct device *self, void *aux);
189 int agp_intel_attach(struct device *parent, struct device *self, void *aux);
190 int agp_via_attach(struct device *parent, struct device *self, void *aux);
191 int agp_sis_attach(struct device *parent, struct device *self, void *aux);
192
193 int agp_alloc_dmamem(bus_dma_tag_t, size_t, int, bus_dmamap_t *, caddr_t *,
194 bus_addr_t *, bus_dma_segment_t *, int, int *);
195 void agp_free_dmamem(bus_dma_tag_t tag, size_t size, bus_dmamap_t map,
196 caddr_t vaddr, bus_dma_segment_t *seg, int nseg) ;
197
198 /*
199 * Kernel API
200 */
201 /*
202 * Find the AGP device and return it.
203 */
204 void *agp_find_device(int);
205
206 /*
207 * Return the current owner of the AGP chipset.
208 */
209 enum agp_acquire_state agp_state(void *devcookie);
210
211 /*
212 * Query the state of the AGP system.
213 */
214 void agp_get_info(void *devhandle, struct agp_info *info);
215
216 /*
217 * Acquire the AGP chipset for use by the kernel. Returns EBUSY if the
218 * AGP chipset is already acquired by another user.
219 */
220 int agp_acquire(void *devhandle);
221
222 /*
223 * Release the AGP chipset.
224 */
225 int agp_release(void *devhandle);
226
227 /*
228 * Enable the agp hardware with the relavent mode. The mode bits are
229 * defined in <dev/pci/agpreg.h>
230 */
231 int agp_enable(void *devhandle, u_int32_t mode);
232
233 /*
234 * Allocate physical memory suitable for mapping into the AGP
235 * aperture. The value returned is an opaque handle which can be
236 * passed to agp_bind(), agp_unbind() or agp_deallocate().
237 */
238 void *agp_alloc_memory(void *devhandle, int type, vsize_t bytes);
239
240 /*
241 * Free memory which was allocated with agp_allocate().
242 */
243 void agp_free_memory(void *devhandle, void *handle);
244
245 /*
246 * Bind memory allocated with agp_allocate() at a given offset within
247 * the AGP aperture. Returns EINVAL if the memory is already bound or
248 * the offset is not at an AGP page boundary.
249 */
250 int agp_bind_memory(void *devhandle, void *handle, off_t offset);
251
252 /*
253 * Unbind memory from the AGP aperture. Returns EINVAL if the memory
254 * is not bound.
255 */
256 int agp_unbind_memory(void *devhandle, void *handle);
257
258 /*
259 * Retrieve information about a memory block allocated with
260 * agp_alloc_memory().
261 */
262 void agp_memory_info(void *devhandle, void *handle, struct agp_memory_info *mi);
263
264 #endif /* !_PCI_AGPPRIV_H_ */
265