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