1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2000,2001 Jonathan Chen All rights reserved. 5 * Copyright (c) 2003-2004 M. Warner Losh <imp@FreeBSD.org> 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 29 /* 30 * Structure definitions for the Cardbus Bridge driver 31 */ 32 33 struct cbb_intrhand { 34 driver_filter_t *filt; 35 driver_intr_t *intr; 36 void *arg; 37 struct cbb_softc *sc; 38 void *cookie; 39 }; 40 41 struct cbb_reslist { 42 SLIST_ENTRY(cbb_reslist) link; 43 struct resource *res; 44 int type; 45 int rid; 46 /* note: unlike the regular resource list, there can be 47 * duplicate rid's in the same list. However, the 48 * combination of rid and res->r_dev should be unique. 49 */ 50 bus_addr_t cardaddr; /* for 16-bit pccard memory */ 51 }; 52 53 #define CBB_AUTO_OPEN_SMALLHOLE 0x100 54 55 struct cbb_softc { 56 device_t dev; 57 struct exca_softc exca; 58 struct resource *base_res; 59 struct resource *irq_res; 60 void *intrhand; 61 bus_space_tag_t bst; 62 bus_space_handle_t bsh; 63 uint32_t domain; 64 unsigned int pribus; 65 struct pcib_secbus bus; 66 struct mtx mtx; 67 int cardok; 68 u_int32_t flags; 69 #define CBB_16BIT_CARD 0x20000000 70 #define CBB_KTHREAD_RUNNING 0x40000000 71 #define CBB_KTHREAD_DONE 0x80000000 72 int chipset; /* chipset id */ 73 #define CB_UNKNOWN 0 /* NOT Cardbus-PCI bridge */ 74 #define CB_TI113X 1 /* TI PCI1130/1131 */ 75 #define CB_TI12XX 2 /* TI PCI12xx/14xx/44xx/15xx/45xx */ 76 #define CB_TI125X 3 /* TI PCI1250/1251(B)/1450 */ 77 #define CB_RF5C47X 4 /* RICOH RF5C475/476/477 */ 78 #define CB_RF5C46X 5 /* RICOH RF5C465/466/467 */ 79 #define CB_CIRRUS 6 /* Cirrus Logic CLPD683x */ 80 #define CB_TOPIC95 7 /* Toshiba ToPIC95 */ 81 #define CB_TOPIC97 8 /* Toshiba ToPIC97/100 */ 82 #define CB_O2MICRO 9 /* O2Micro chips */ 83 SLIST_HEAD(, cbb_reslist) rl; 84 device_t cbdev; 85 struct proc *event_thread; 86 void (*chipinit)(struct cbb_softc *); 87 int powerintr; 88 struct root_hold_token *sc_root_token; 89 }; 90 91 /* result of detect_card */ 92 #define CARD_UKN_CARD 0x00 93 #define CARD_5V_CARD 0x01 94 #define CARD_3V_CARD 0x02 95 #define CARD_XV_CARD 0x04 96 #define CARD_YV_CARD 0x08 97 98 /* for power_socket */ 99 #define CARD_VCC(X) (X) 100 #define CARD_VPP_VCC 0xf0 101 #define CARD_VCCMASK 0xf 102 #define CARD_VCCSHIFT 0 103 #define XV 2 104 #define YV 1 105 106 #define CARD_OFF (CARD_VCC(0)) 107 108 extern int cbb_debug; 109 110 int cbb_activate_resource(device_t brdev, device_t child, 111 int type, int rid, struct resource *r); 112 struct resource *cbb_alloc_resource(device_t brdev, device_t child, 113 int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, 114 u_int flags); 115 void cbb_child_detached(device_t brdev, device_t child); 116 int cbb_child_present(device_t parent, device_t child); 117 int cbb_deactivate_resource(device_t brdev, device_t child, 118 int type, int rid, struct resource *r); 119 int cbb_detach(device_t brdev); 120 void cbb_disable_func_intr(struct cbb_softc *sc); 121 void cbb_driver_added(device_t brdev, driver_t *driver); 122 void cbb_event_thread(void *arg); 123 int cbb_pcic_set_memory_offset(device_t brdev, device_t child, int rid, 124 uint32_t cardaddr, uint32_t *deltap); 125 int cbb_pcic_set_res_flags(device_t brdev, device_t child, int type, 126 int rid, u_long flags); 127 int cbb_power(device_t brdev, int volts); 128 int cbb_power_enable_socket(device_t brdev, device_t child); 129 int cbb_power_disable_socket(device_t brdev, device_t child); 130 int cbb_read_ivar(device_t brdev, device_t child, int which, 131 uintptr_t *result); 132 int cbb_release_resource(device_t brdev, device_t child, 133 int type, int rid, struct resource *r); 134 int cbb_setup_intr(device_t dev, device_t child, struct resource *irq, 135 int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg, 136 void **cookiep); 137 int cbb_teardown_intr(device_t dev, device_t child, struct resource *irq, 138 void *cookie); 139 int cbb_write_ivar(device_t brdev, device_t child, int which, 140 uintptr_t value); 141 142 /* 143 */ 144 static __inline void 145 cbb_set(struct cbb_softc *sc, uint32_t reg, uint32_t val) 146 { 147 bus_space_write_4(sc->bst, sc->bsh, reg, val); 148 } 149 150 static __inline uint32_t 151 cbb_get(struct cbb_softc *sc, uint32_t reg) 152 { 153 return (bus_space_read_4(sc->bst, sc->bsh, reg)); 154 } 155 156 static __inline void 157 cbb_setb(struct cbb_softc *sc, uint32_t reg, uint32_t bits) 158 { 159 cbb_set(sc, reg, cbb_get(sc, reg) | bits); 160 } 161 162 static __inline void 163 cbb_clrb(struct cbb_softc *sc, uint32_t reg, uint32_t bits) 164 { 165 cbb_set(sc, reg, cbb_get(sc, reg) & ~bits); 166 } 167