1 /* $OpenBSD: cardbusvar.h,v 1.20 2014/12/18 10:51:35 mpi Exp $ */ 2 /* $NetBSD: cardbusvar.h,v 1.17 2000/04/02 19:11:37 mycroft Exp $ */ 3 4 /* 5 * Copyright (c) 1998, 1999 and 2000 6 * HAYAKAWA Koichi. 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 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef _DEV_CARDBUS_CARDBUSVAR_H_ 32 #define _DEV_CARDBUS_CARDBUSVAR_H_ 33 34 #include <dev/pci/pcivar.h> /* for pcitag_t */ 35 #include <dev/cardbus/rbus.h> 36 37 typedef void *cardbus_chipset_tag_t; 38 typedef int cardbus_intr_handle_t; 39 40 /* Base Registers */ 41 #define CARDBUS_BASE0_REG 0x10 42 #define CARDBUS_BASE1_REG 0x14 43 #define CARDBUS_BASE2_REG 0x18 44 #define CARDBUS_BASE3_REG 0x1C 45 #define CARDBUS_BASE4_REG 0x20 46 #define CARDBUS_BASE5_REG 0x24 47 #define CARDBUS_CIS_REG 0x28 48 #define CARDBUS_ROM_REG 0x30 49 # define CARDBUS_CIS_ASIMASK 0x07 50 # define CARDBUS_CIS_ASI(x) (CARDBUS_CIS_ASIMASK & (x)) 51 # define CARDBUS_CIS_ASI_TUPLE 0x00 52 # define CARDBUS_CIS_ASI_BAR0 0x01 53 # define CARDBUS_CIS_ASI_BAR1 0x02 54 # define CARDBUS_CIS_ASI_BAR2 0x03 55 # define CARDBUS_CIS_ASI_BAR3 0x04 56 # define CARDBUS_CIS_ASI_BAR4 0x05 57 # define CARDBUS_CIS_ASI_BAR5 0x06 58 # define CARDBUS_CIS_ASI_ROM 0x07 59 # define CARDBUS_CIS_ADDRMASK 0x0ffffff8 60 # define CARDBUS_CIS_ADDR(x) (CARDBUS_CIS_ADDRMASK & (x)) 61 # define CARDBUS_CIS_ASI_BAR(x) (((CARDBUS_CIS_ASIMASK & (x))-1)*4+0x10) 62 # define CARDBUS_CIS_ASI_ROM_IMAGE(x) (((x) >> 28) & 0xf) 63 64 /* XXX end */ 65 66 typedef struct cardbus_functions { 67 int (*cardbus_space_alloc)(cardbus_chipset_tag_t, rbus_tag_t, 68 bus_addr_t, bus_size_t, bus_addr_t, bus_size_t, int, bus_addr_t *, 69 bus_space_handle_t *); 70 int (*cardbus_space_free)(cardbus_chipset_tag_t, rbus_tag_t, 71 bus_space_handle_t, bus_size_t); 72 void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int, int, 73 int (*)(void *), void *, const char *); 74 void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t, void *); 75 int (*cardbus_ctrl)(cardbus_chipset_tag_t, int); 76 int (*cardbus_power)(cardbus_chipset_tag_t, int); 77 } cardbus_function_t, *cardbus_function_tag_t; 78 79 /* 80 * struct cbslot_attach_args is the attach argument for cardbus card. 81 */ 82 struct cbslot_attach_args { 83 char *cba_busname; 84 bus_space_tag_t cba_iot; /* cardbus i/o space tag */ 85 bus_space_tag_t cba_memt; /* cardbus mem space tag */ 86 bus_dma_tag_t cba_dmat; /* DMA tag */ 87 88 int cba_bus; /* cardbus bus number */ 89 90 cardbus_chipset_tag_t cba_cc; /* cardbus chipset */ 91 pci_chipset_tag_t cba_pc; /* pci chipset */ 92 cardbus_function_tag_t cba_cf; /* cardbus functions */ 93 int cba_intrline; /* interrupt line */ 94 95 rbus_tag_t cba_rbus_iot; /* CardBus i/o rbus tag */ 96 rbus_tag_t cba_rbus_memt; /* CardBus mem rbus tag */ 97 98 int cba_cacheline; /* cache line size */ 99 int cba_lattimer; /* latency timer */ 100 }; 101 102 103 #define cbslotcf_dev cf_loc[0] 104 #define cbslotcf_func cf_loc[1] 105 #define CBSLOT_UNK_DEV -1 106 #define CBSLOT_UNK_FUNC -1 107 108 109 struct cardbus_devfunc; 110 111 /* 112 * struct cardbus_softc is the softc for cardbus card. 113 */ 114 struct cardbus_softc { 115 struct device sc_dev; /* fundamental device structure */ 116 117 int sc_bus; /* cardbus bus number */ 118 int sc_device; /* cardbus device number */ 119 int sc_intrline; /* CardBus intrline */ 120 121 bus_space_tag_t sc_iot; /* CardBus I/O space tag */ 122 bus_space_tag_t sc_memt; /* CardBus MEM space tag */ 123 bus_dma_tag_t sc_dmat; /* DMA tag */ 124 125 cardbus_chipset_tag_t sc_cc; /* CardBus chipset */ 126 pci_chipset_tag_t sc_pc; /* PCI chipset */ 127 cardbus_function_tag_t sc_cf; /* CardBus function */ 128 129 rbus_tag_t sc_rbus_iot; /* CardBus i/o rbus tag */ 130 rbus_tag_t sc_rbus_memt; /* CardBus mem rbus tag */ 131 132 int sc_cacheline; /* cache line size */ 133 int sc_lattimer; /* latency timer */ 134 int sc_volt; /* applied Vcc voltage */ 135 #define PCCARD_33V 0x02 136 #define PCCARD_XXV 0x04 137 #define PCCARD_YYV 0x08 138 int sc_poweron_func; 139 struct cardbus_devfunc *sc_funcs[8]; /* cardbus device functions */ 140 }; 141 142 143 /* 144 * struct cardbus_devfunc: 145 * 146 * This is the data deposit for each function of a CardBus device. 147 * This structure is used for memory or i/o space allocation and 148 * disallocation. 149 */ 150 typedef struct cardbus_devfunc { 151 cardbus_chipset_tag_t ct_cc; 152 cardbus_function_tag_t ct_cf; 153 struct cardbus_softc *ct_sc; /* pointer to the parent */ 154 int ct_bus; /* bus number */ 155 int ct_dev; /* device number */ 156 int ct_func; /* function number */ 157 158 rbus_tag_t ct_rbus_iot; /* CardBus i/o rbus tag */ 159 rbus_tag_t ct_rbus_memt; /* CardBus mem rbus tag */ 160 161 u_int32_t ct_lc; /* Latency timer and cache line size */ 162 /* u_int32_t ct_cisreg; */ /* CIS reg: is it needed??? */ 163 164 struct device *ct_device; /* pointer to the device */ 165 166 struct cardbus_devfunc *ct_next; 167 168 /* some data structure needed for tuple??? */ 169 } *cardbus_devfunc_t; 170 171 172 /* XXX various things extracted from CIS */ 173 struct cardbus_cis_info { 174 int32_t manufacturer; 175 int32_t product; 176 char cis1_info_buf[256]; 177 char *cis1_info[4]; 178 struct cb_bar_info { 179 unsigned int flags; 180 unsigned int size; 181 } bar[7]; 182 unsigned int funcid; 183 union { 184 struct { 185 int uart_type; 186 int uart_present; 187 } serial; 188 struct { 189 char netid[6]; 190 char netid_present; 191 char __filler; 192 } network; 193 } funce; 194 }; 195 196 struct cardbus_attach_args { 197 int ca_unit; 198 cardbus_devfunc_t ca_ct; 199 pci_chipset_tag_t ca_pc; /* PCI chipset */ 200 201 bus_space_tag_t ca_iot; /* CardBus I/O space tag */ 202 bus_space_tag_t ca_memt; /* CardBus MEM space tag */ 203 bus_dma_tag_t ca_dmat; /* DMA tag */ 204 205 u_int ca_bus; 206 u_int ca_device; 207 u_int ca_function; 208 pcitag_t ca_tag; 209 pcireg_t ca_id; 210 pcireg_t ca_class; 211 212 /* Interrupt information */ 213 pci_intr_line_t ca_intrline; 214 215 rbus_tag_t ca_rbus_iot; /* CardBus i/o rbus tag */ 216 rbus_tag_t ca_rbus_memt; /* CardBus mem rbus tag */ 217 218 struct cardbus_cis_info ca_cis; 219 }; 220 221 222 #define CARDBUS_ENABLE 1 /* enable the channel */ 223 #define CARDBUS_DISABLE 2 /* disable the channel */ 224 #define CARDBUS_RESET 4 225 #define CARDBUS_CD 7 226 # define CARDBUS_NOCARD 0 227 # define CARDBUS_5V_CARD 0x01 /* XXX: It must not exist */ 228 # define CARDBUS_3V_CARD 0x02 229 # define CARDBUS_XV_CARD 0x04 230 # define CARDBUS_YV_CARD 0x08 231 #define CARDBUS_IO_ENABLE 100 232 #define CARDBUS_IO_DISABLE 101 233 #define CARDBUS_MEM_ENABLE 102 234 #define CARDBUS_MEM_DISABLE 103 235 #define CARDBUS_BM_ENABLE 104 /* bus master */ 236 #define CARDBUS_BM_DISABLE 105 237 238 #define CARDBUS_VCC_UC 0x0000 239 #define CARDBUS_VCC_3V 0x0001 240 #define CARDBUS_VCC_XV 0x0002 241 #define CARDBUS_VCC_YV 0x0003 242 #define CARDBUS_VCC_0V 0x0004 243 #define CARDBUS_VCC_5V 0x0005 /* ??? */ 244 #define CARDBUS_VCCMASK 0x000f 245 #define CARDBUS_VPP_UC 0x0000 246 #define CARDBUS_VPP_VCC 0x0010 247 #define CARDBUS_VPP_12V 0x0030 248 #define CARDBUS_VPP_0V 0x0040 249 #define CARDBUS_VPPMASK 0x00f0 250 251 #define CARDBUSCF_DEV 0 252 #define CARDBUSCF_DEV_DEFAULT -1 253 #define CARDBUSCF_FUNCTION 1 254 #define CARDBUSCF_FUNCTION_DEFAULT -1 255 256 /* 257 * Locators devies that attach to 'cardbus', as specified to config. 258 */ 259 #define cardbuscf_dev cf_loc[CARDBUSCF_DEV] 260 #define CARDBUS_UNK_DEV CARDBUSCF_DEV_DEFAULT 261 262 #define cardbuscf_function cf_loc[CARDBUSCF_FUNCTION] 263 #define CARDBUS_UNK_FUNCTION CARDBUSCF_FUNCTION_DEFAULT 264 265 int cardbus_attach_card(struct cardbus_softc *); 266 void cardbus_detach_card(struct cardbus_softc *); 267 void *cardbus_intr_establish(cardbus_chipset_tag_t, cardbus_function_tag_t, 268 cardbus_intr_handle_t irq, int level, int (*func) (void *), 269 void *arg, const char *); 270 void cardbus_intr_disestablish(cardbus_chipset_tag_t, 271 cardbus_function_tag_t, void *handler); 272 273 int cardbus_mapreg_map(struct cardbus_softc *, int, int, pcireg_t, 274 int, bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *, 275 bus_size_t *); 276 int cardbus_mapreg_unmap(struct cardbus_softc *, int, int, 277 bus_space_tag_t, bus_space_handle_t, bus_size_t); 278 279 int cardbus_function_enable(struct cardbus_softc *, int function); 280 int cardbus_function_disable(struct cardbus_softc *, int function); 281 282 int cardbus_matchbyid(struct cardbus_attach_args *, 283 const struct pci_matchid *, int); 284 285 #define Cardbus_function_enable(ct) \ 286 cardbus_function_enable((ct)->ct_sc, (ct)->ct_func) 287 #define Cardbus_function_disable(ct) \ 288 cardbus_function_disable((ct)->ct_sc, (ct)->ct_func) 289 290 #define Cardbus_mapreg_map(ct, reg, type, busflags, tagp, handlep, basep, sizep) \ 291 cardbus_mapreg_map((ct)->ct_sc, (ct->ct_func), \ 292 (reg), (type), (busflags), (tagp), (handlep), (basep), (sizep)) 293 #define Cardbus_mapreg_unmap(ct, reg, tag, handle, size)\ 294 cardbus_mapreg_unmap((ct)->ct_sc, (ct->ct_func), \ 295 (reg), (tag), (handle), (size)) 296 297 #endif /* !_DEV_CARDBUS_CARDBUSVAR_H_ */ 298