1 /* $OpenBSD: agpvar.h,v 1.30 2014/03/26 14:41:41 mpi 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 /* #define AGP_DEBUG */ 36 #ifdef AGP_DEBUG 37 #define AGP_DPF(fmt, arg...) do { printf("agp: " fmt ,##arg); } while (0) 38 #else 39 #define AGP_DPF(fmt, arg...) do {} while (0) 40 #endif 41 42 #define AGPUNIT(x) minor(x) 43 44 /* we can't use the BUS_DMA_NOCACHE here or it won't get mapped via the gtt */ 45 #define BUS_DMA_GTT_NOCACHE (1 << 30) 46 #define BUS_DMA_GTT_CACHE_LLC (1 << 29) 47 #define BUS_DMA_GTT_CACHE_LLC_MLC (1 << 28) 48 #define BUS_DMA_GTT_WRAPAROUND (1 << 27) 49 50 struct agp_attach_args { 51 char *aa_busname; 52 struct pci_attach_args *aa_pa; 53 }; 54 55 struct agpbus_attach_args { 56 char *aa_busname; /*so pci doesn't conflict*/ 57 struct pci_attach_args *aa_pa; 58 const struct agp_methods *aa_methods; 59 bus_addr_t aa_apaddr; 60 bus_size_t aa_apsize; 61 }; 62 63 enum agp_acquire_state { 64 AGP_ACQUIRE_FREE, 65 AGP_ACQUIRE_USER, 66 AGP_ACQUIRE_KERNEL 67 }; 68 69 /* 70 * Data structure to describe an AGP memory allocation. 71 */ 72 TAILQ_HEAD(agp_memory_list, agp_memory); 73 struct agp_memory { 74 TAILQ_ENTRY(agp_memory) am_link; /* wiring for the tailq */ 75 bus_dmamap_t am_dmamap; 76 bus_dma_segment_t *am_dmaseg; 77 bus_size_t am_size; /* number of bytes allocated */ 78 bus_size_t am_offset; /* page offset if bound */ 79 paddr_t am_physical; 80 caddr_t am_kva; /* kva if mapped */ 81 u_int32_t am_mapref; /* mapping reference count */ 82 int am_id; /* unique id for block */ 83 int am_is_bound; /* non-zero if bound */ 84 int am_nseg; 85 int am_type; /* chipset specific type */ 86 }; 87 88 /* 89 * This structure is used to query the state of the AGP system. 90 */ 91 struct agp_info { 92 u_int32_t ai_mode; 93 bus_addr_t ai_aperture_base; 94 bus_size_t ai_aperture_size; 95 vsize_t ai_memory_allowed; 96 vsize_t ai_memory_used; 97 u_int32_t ai_devid; 98 }; 99 100 struct agp_memory_info { 101 vsize_t ami_size; /* size in bytes */ 102 bus_addr_t ami_physical; /* bogus hack for i810 */ 103 off_t ami_offset; /* page offset if bound */ 104 int ami_is_bound; /* non-zero if bound */ 105 }; 106 107 struct agp_methods { 108 void (*bind_page)(void *, bus_addr_t, paddr_t, int); 109 void (*unbind_page)(void *, bus_addr_t); 110 void (*flush_tlb)(void *); 111 int (*enable)(void *, u_int32_t mode); 112 struct agp_memory * 113 (*alloc_memory)(void *, int, vsize_t); 114 int (*free_memory)(void *, struct agp_memory *); 115 int (*bind_memory)(void *, struct agp_memory *, bus_size_t); 116 int (*unbind_memory)(void *, struct agp_memory *); 117 }; 118 119 /* 120 * All chipset drivers must have this at the start of their softc. 121 */ 122 struct agp_softc { 123 struct device sc_dev; 124 125 struct agp_memory_list sc_memory; /* mem blocks */ 126 struct rwlock sc_lock; /* GATT access lock */ 127 const struct agp_methods *sc_methods; /* callbacks */ 128 void *sc_chipc; /* chipset softc */ 129 130 bus_dma_tag_t sc_dmat; 131 bus_space_tag_t sc_memt; 132 pci_chipset_tag_t sc_pc; 133 pcitag_t sc_pcitag; 134 bus_addr_t sc_apaddr; 135 bus_size_t sc_apsize; 136 uint32_t sc_stolen_entries; 137 pcireg_t sc_id; 138 139 int sc_opened; 140 int sc_capoff; 141 int sc_nextid; /* next mem block id */ 142 enum agp_acquire_state sc_state; 143 144 u_int32_t sc_maxmem; /* mem upper bound */ 145 u_int32_t sc_allocated; /* amount allocated */ 146 }; 147 148 struct agp_gatt { 149 u_int32_t ag_entries; 150 u_int32_t *ag_virtual; 151 bus_addr_t ag_physical; 152 bus_dmamap_t ag_dmamap; 153 bus_dma_segment_t ag_dmaseg; 154 size_t ag_size; 155 }; 156 157 struct agp_map; 158 159 /* 160 * Functions private to the AGP code. 161 */ 162 struct device *agp_attach_bus(struct pci_attach_args *, 163 const struct agp_methods *, bus_addr_t, bus_size_t, 164 struct device *); 165 struct agp_gatt * 166 agp_alloc_gatt(bus_dma_tag_t, u_int32_t); 167 void agp_free_gatt(bus_dma_tag_t, struct agp_gatt *); 168 void agp_flush_cache(void); 169 void agp_flush_cache_range(vaddr_t, vsize_t); 170 int agp_generic_bind_memory(struct agp_softc *, struct agp_memory *, 171 bus_size_t); 172 int agp_generic_unbind_memory(struct agp_softc *, struct agp_memory *); 173 int agp_init_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, struct 174 agp_map **); 175 void agp_destroy_map(struct agp_map *); 176 int agp_map_subregion(struct agp_map *, bus_size_t, bus_size_t, 177 bus_space_handle_t *); 178 void agp_unmap_subregion(struct agp_map *, bus_space_handle_t, 179 bus_size_t); 180 181 int agp_alloc_dmamem(bus_dma_tag_t, size_t, bus_dmamap_t *, 182 bus_addr_t *, bus_dma_segment_t *); 183 void agp_free_dmamem(bus_dma_tag_t, size_t, bus_dmamap_t, 184 bus_dma_segment_t *); 185 int agpdev_print(void *, const char *); 186 int agpbus_probe(struct agp_attach_args *aa); 187 188 void *agp_map(struct agp_softc *, bus_addr_t, bus_size_t, 189 bus_space_handle_t *); 190 void agp_unmap(struct agp_softc *, void *, size_t, bus_space_handle_t); 191 paddr_t agp_mmap(struct agp_softc *, off_t, int); 192 193 /* 194 * Kernel API 195 */ 196 /* 197 * Find the AGP device and return it. 198 */ 199 void *agp_find_device(int); 200 201 /* 202 * Return the current owner of the AGP chipset. 203 */ 204 enum agp_acquire_state agp_state(void *); 205 206 /* 207 * Query the state of the AGP system. 208 */ 209 void agp_get_info(void *, struct agp_info *); 210 211 /* 212 * Acquire the AGP chipset for use by the kernel. Returns EBUSY if the 213 * AGP chipset is already acquired by another user. 214 */ 215 int agp_acquire(void *); 216 217 /* 218 * Release the AGP chipset. 219 */ 220 int agp_release(void *); 221 222 /* 223 * Enable the agp hardware with the relavent mode. The mode bits are 224 * defined in <dev/pci/agpreg.h> 225 */ 226 int agp_enable(void *, u_int32_t); 227 228 /* 229 * Allocate physical memory suitable for mapping into the AGP 230 * aperture. The value returned is an opaque handle which can be 231 * passed to agp_bind(), agp_unbind() or agp_deallocate(). 232 */ 233 void *agp_alloc_memory(void *, int, vsize_t); 234 235 /* 236 * Free memory which was allocated with agp_allocate(). 237 */ 238 void agp_free_memory(void *, void *); 239 240 /* 241 * Bind memory allocated with agp_allocate() at a given offset within 242 * the AGP aperture. Returns EINVAL if the memory is already bound or 243 * the offset is not at an AGP page boundary. 244 */ 245 int agp_bind_memory(void *, void *, off_t); 246 247 /* 248 * Unbind memory from the AGP aperture. Returns EINVAL if the memory 249 * is not bound. 250 */ 251 int agp_unbind_memory(void *, void *); 252 253 /* 254 * Retrieve information about a memory block allocated with 255 * agp_alloc_memory(). 256 */ 257 void agp_memory_info(void *, void *, struct agp_memory_info *); 258 259 #endif /* !_PCI_AGPVAR_H_ */ 260