1 /* $OpenBSD: agpvar.h,v 1.15 2008/11/09 15:11:19 oga Exp $ */ 2 /* $NetBSD: agpvar.h,v 1.4 2001/10/01 21:54:48 fvdl Exp $ */ 3 4 /*- 5 * Copyright (c) 2000 Doug Rabson 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD: src/sys/pci/agppriv.h,v 1.3 2000/07/12 10:13:04 dfr Exp $ 30 */ 31 32 #ifndef _PCI_AGPVAR_H_ 33 #define _PCI_AGPVAR_H_ 34 35 #include <sys/rwlock.h> 36 37 /* #define AGP_DEBUG */ 38 #ifdef AGP_DEBUG 39 #define AGP_DPF(fmt, arg...) do { printf("agp: " fmt ,##arg); } while (0) 40 #else 41 #define AGP_DPF(fmt, arg...) do {} while (0) 42 #endif 43 44 #define AGPUNIT(x) minor(x) 45 46 struct agp_attach_args { 47 char *aa_busname; 48 struct pci_attach_args *aa_pa; 49 }; 50 51 struct agpbus_attach_args { 52 char *aa_busname; /*so pci doesn't conflict*/ 53 struct pci_attach_args *aa_pa; 54 const struct agp_methods *aa_methods; 55 int aa_bar; 56 pcireg_t aa_type; 57 }; 58 59 enum agp_acquire_state { 60 AGP_ACQUIRE_FREE, 61 AGP_ACQUIRE_USER, 62 AGP_ACQUIRE_KERNEL 63 }; 64 65 /* 66 * Data structure to describe an AGP memory allocation. 67 */ 68 TAILQ_HEAD(agp_memory_list, agp_memory); 69 struct agp_memory { 70 TAILQ_ENTRY(agp_memory) am_link; /* wiring for the tailq */ 71 int am_id; /* unique id for block */ 72 vsize_t am_size; /* number of bytes allocated */ 73 int am_type; /* chipset specific type */ 74 off_t am_offset; /* page offset if bound */ 75 int am_is_bound; /* non-zero if bound */ 76 bus_addr_t am_physical; 77 caddr_t am_virtual; 78 bus_dmamap_t am_dmamap; 79 int am_nseg; 80 bus_dma_segment_t *am_dmaseg; 81 }; 82 83 /* 84 * This structure is used to query the state of the AGP system. 85 */ 86 struct agp_info { 87 u_int32_t ai_mode; 88 bus_addr_t ai_aperture_base; 89 bus_size_t ai_aperture_size; 90 vsize_t ai_memory_allowed; 91 vsize_t ai_memory_used; 92 u_int32_t ai_devid; 93 }; 94 95 struct agp_memory_info { 96 vsize_t ami_size; /* size in bytes */ 97 bus_addr_t ami_physical; /* bogus hack for i810 */ 98 off_t ami_offset; /* page offset if bound */ 99 int ami_is_bound; /* non-zero if bound */ 100 }; 101 102 struct agp_methods { 103 bus_size_t (*get_aperture)(void *); 104 int (*bind_page)(void *, off_t, bus_addr_t); 105 int (*unbind_page)(void *, off_t); 106 void (*flush_tlb)(void *); 107 int (*enable)(void *, u_int32_t mode); 108 struct agp_memory * 109 (*alloc_memory)(void *, int, vsize_t); 110 int (*free_memory)(void *, struct agp_memory *); 111 int (*bind_memory)(void *, struct agp_memory *, off_t); 112 int (*unbind_memory)(void *, struct agp_memory *); 113 }; 114 115 /* 116 * All chipset drivers must have this at the start of their softc. 117 */ 118 struct agp_softc { 119 struct device sc_dev; 120 121 struct agp_memory_list sc_memory; /* mem blocks */ 122 struct rwlock sc_lock; /* GATT access lock */ 123 const struct agp_methods *sc_methods; /* callbacks */ 124 void *sc_chipc; /* chipset softc */ 125 126 bus_dma_tag_t sc_dmat; 127 bus_addr_t sc_apaddr; 128 pci_chipset_tag_t sc_pc; 129 pcitag_t sc_pcitag; 130 pcireg_t sc_id; 131 132 int sc_opened; 133 int sc_capoff; 134 int sc_nextid; /* next mem block id */ 135 enum agp_acquire_state sc_state; 136 137 u_int32_t sc_maxmem; /* mem upper bound */ 138 u_int32_t sc_allocated; /* amount allocated */ 139 }; 140 141 struct agp_gatt { 142 u_int32_t ag_entries; 143 u_int32_t *ag_virtual; 144 bus_addr_t ag_physical; 145 bus_dmamap_t ag_dmamap; 146 bus_dma_segment_t ag_dmaseg; 147 size_t ag_size; 148 }; 149 150 /* 151 * Functions private to the AGP code. 152 */ 153 struct device *agp_attach_bus(struct pci_attach_args *, 154 const struct agp_methods *, int, pcireg_t, 155 struct device *); 156 int agp_map_aperture(struct pci_attach_args *, 157 struct agp_softc *, u_int32_t, u_int32_t); 158 struct agp_gatt * 159 agp_alloc_gatt(bus_dma_tag_t, u_int32_t); 160 void agp_free_gatt(bus_dma_tag_t, struct agp_gatt *); 161 void agp_flush_cache(void); 162 int agp_generic_bind_memory(struct agp_softc *, struct agp_memory *, off_t); 163 int agp_generic_unbind_memory(struct agp_softc *, struct agp_memory *); 164 165 int agp_alloc_dmamem(bus_dma_tag_t, size_t, int, bus_dmamap_t *, 166 caddr_t *, bus_addr_t *, bus_dma_segment_t *, int, int *); 167 void agp_free_dmamem(bus_dma_tag_t, size_t, bus_dmamap_t, 168 caddr_t, bus_dma_segment_t *, int nseg) ; 169 int agpdev_print(void *, const char *); 170 int agpbus_probe(struct agp_attach_args *aa); 171 172 173 /* 174 * Kernel API 175 */ 176 /* 177 * Find the AGP device and return it. 178 */ 179 void *agp_find_device(int); 180 181 /* 182 * Return the current owner of the AGP chipset. 183 */ 184 enum agp_acquire_state agp_state(void *); 185 186 /* 187 * Query the state of the AGP system. 188 */ 189 void agp_get_info(void *, struct agp_info *); 190 191 /* 192 * Acquire the AGP chipset for use by the kernel. Returns EBUSY if the 193 * AGP chipset is already acquired by another user. 194 */ 195 int agp_acquire(void *); 196 197 /* 198 * Release the AGP chipset. 199 */ 200 int agp_release(void *); 201 202 /* 203 * Enable the agp hardware with the relavent mode. The mode bits are 204 * defined in <dev/pci/agpreg.h> 205 */ 206 int agp_enable(void *, u_int32_t); 207 208 /* 209 * Allocate physical memory suitable for mapping into the AGP 210 * aperture. The value returned is an opaque handle which can be 211 * passed to agp_bind(), agp_unbind() or agp_deallocate(). 212 */ 213 void *agp_alloc_memory(void *, int, vsize_t); 214 215 /* 216 * Free memory which was allocated with agp_allocate(). 217 */ 218 void agp_free_memory(void *, void *); 219 220 /* 221 * Bind memory allocated with agp_allocate() at a given offset within 222 * the AGP aperture. Returns EINVAL if the memory is already bound or 223 * the offset is not at an AGP page boundary. 224 */ 225 int agp_bind_memory(void *, void *, off_t); 226 227 /* 228 * Unbind memory from the AGP aperture. Returns EINVAL if the memory 229 * is not bound. 230 */ 231 int agp_unbind_memory(void *, void *); 232 233 /* 234 * Retrieve information about a memory block allocated with 235 * agp_alloc_memory(). 236 */ 237 void agp_memory_info(void *, void *, struct agp_memory_info *); 238 239 #endif /* !_PCI_AGPVAR_H_ */ 240