1 /* $NetBSD: sti_sgc.c,v 1.1 2014/02/24 07:23:43 skrll Exp $ */ 2 3 /* $OpenBSD: sti_sgc.c,v 1.38 2009/02/06 22:51:04 miod Exp $ */ 4 5 /* 6 * Copyright (c) 2000-2003 Michael Shalayeff 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 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 WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES 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 MIND, 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 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 * THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 /* 31 * These cards has to be known to work so far: 32 * - HPA1991AGrayscale rev 0.02 (705/35) (byte-wide) 33 * - HPA1991AC19 rev 0.02 (715/33) (byte-wide) 34 * - HPA208LC1280 rev 8.04 (712/80) just works 35 */ 36 37 #include <sys/cdefs.h> 38 __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.1 2014/02/24 07:23:43 skrll Exp $"); 39 40 #include "opt_cputype.h" 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/device.h> 45 46 #include <uvm/uvm.h> 47 48 #include <sys/bus.h> 49 #include <machine/cpu.h> 50 #include <machine/iomod.h> 51 #include <machine/autoconf.h> 52 53 #include <dev/wscons/wsdisplayvar.h> 54 #include <dev/wscons/wsconsio.h> 55 56 #include <dev/ic/stireg.h> 57 #include <dev/ic/stivar.h> 58 59 #include <hppa/dev/cpudevs.h> 60 #include <hppa/hppa/machdep.h> 61 62 #ifdef STIDEBUG 63 #define DPRINTF(s) do { \ 64 if (stidebug) \ 65 printf s; \ 66 } while(0) 67 68 extern int stidebug; 69 #else 70 #define DPRINTF(s) /* */ 71 #endif 72 73 #define STI_ROMSIZE (sizeof(struct sti_dd) * 4) 74 #define STI_ID_FDDI 0x280b31af /* Medusa FDDI ROM id */ 75 76 /* gecko optional graphics */ 77 #define STI_GOPT1_REV 0x17 78 #define STI_GOPT2_REV 0x70 79 #define STI_GOPT3_REV 0xd0 80 #define STI_GOPT4_REV 0x00 81 #define STI_GOPT5_REV 0x20 82 #define STI_GOPT6_REV 0x40 83 #define STI_GOPT7_REV 0x30 84 85 const char sti_sgc_opt[] = { 86 STI_GOPT1_REV, 87 STI_GOPT2_REV, 88 STI_GOPT3_REV, 89 STI_GOPT4_REV, 90 STI_GOPT5_REV, 91 STI_GOPT6_REV, 92 STI_GOPT7_REV 93 }; 94 95 int sti_sgc_probe(device_t, cfdata_t, void *); 96 void sti_sgc_attach(device_t, device_t, void *); 97 98 void sti_sgc_end_attach(device_t); 99 100 extern struct cfdriver sti_cd; 101 102 CFATTACH_DECL_NEW(sti_gedoens, sizeof(struct sti_softc), sti_sgc_probe, 103 sti_sgc_attach, NULL, NULL); 104 105 paddr_t sti_sgc_getrom(struct confargs *); 106 107 /* 108 * Locate STI ROM. 109 * On some machines it may not be part of the HPA space. 110 */ 111 paddr_t 112 sti_sgc_getrom(struct confargs *ca) 113 { 114 paddr_t rom; 115 int pagezero_cookie; 116 117 pagezero_cookie = hppa_pagezero_map(); 118 rom = PAGE0->pd_resv2[1]; 119 hppa_pagezero_unmap(pagezero_cookie); 120 121 if (ca->ca_type.iodc_sv_model == HPPA_FIO_GSGC) { 122 int i; 123 for (i = sizeof(sti_sgc_opt); i--; ) 124 if (sti_sgc_opt[i] == ca->ca_type.iodc_revision) 125 break; 126 if (i < 0) 127 rom = 0; 128 } 129 130 if (rom < HPPA_IOBEGIN) { 131 if (ca->ca_naddrs > 0) 132 rom = ca->ca_addrs[0].addr; 133 else 134 rom = ca->ca_hpa; 135 } 136 137 return rom; 138 } 139 140 int 141 sti_sgc_probe(device_t parent, cfdata_t cf, void *aux) 142 { 143 struct confargs *ca = aux; 144 bus_space_handle_t romh; 145 paddr_t rom; 146 uint32_t id; 147 u_char devtype; 148 int rv = 0, romunmapped = 0; 149 150 /* due to the graphic nature of this program do probe only one */ 151 if (cf->cf_unit > sti_cd.cd_ndevs) 152 return 0; 153 154 if (ca->ca_type.iodc_type != HPPA_TYPE_FIO) 155 return 0; 156 157 /* these need further checking for the graphics id */ 158 if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC && 159 ca->ca_type.iodc_sv_model != HPPA_FIO_SGC) 160 return 0; 161 162 rom = sti_sgc_getrom(ca); 163 DPRINTF(("%s: hpa=%x, rom=%x\n", __func__, (uint)ca->ca_hpa, 164 (uint)rom)); 165 166 /* if it does not map, probably part of the lasi space */ 167 if ((rv = bus_space_map(ca->ca_iot, rom, STI_ROMSIZE, 0, &romh))) { 168 DPRINTF(("%s: can't map rom space (%d)\n", __func__, rv)); 169 170 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) { 171 romh = rom; 172 romunmapped++; 173 } else { 174 /* in this case nobody has no freaking idea */ 175 return 0; 176 } 177 } 178 179 devtype = bus_space_read_1(ca->ca_iot, romh, 3); 180 181 DPRINTF(("%s: devtype=%d\n", __func__, devtype)); 182 rv = 1; 183 switch (devtype) { 184 case STI_DEVTYPE4: 185 id = bus_space_read_4(ca->ca_iot, romh, STI_DEV4_DD_GRID); 186 break; 187 case STI_DEVTYPE1: 188 id = (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID 189 + 3) << 24) | 190 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID 191 + 7) << 16) | 192 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID 193 + 11) << 8) | 194 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID 195 + 15)); 196 break; 197 default: 198 DPRINTF(("%s: unknown type (%x)\n", __func__, devtype)); 199 rv = 0; 200 } 201 202 if (rv && 203 ca->ca_type.iodc_sv_model == HPPA_FIO_SGC && id == STI_ID_FDDI) { 204 DPRINTF(("%s: not a graphics device\n", __func__)); 205 rv = 0; 206 } 207 208 if (ca->ca_naddrs >= sizeof(ca->ca_addrs) / sizeof(ca->ca_addrs[0])) { 209 printf("sti: address list overflow\n"); 210 return 0; 211 } 212 213 ca->ca_addrs[ca->ca_naddrs].addr = rom; 214 ca->ca_addrs[ca->ca_naddrs].size = sti_rom_size(ca->ca_iot, romh); 215 ca->ca_naddrs++; 216 217 if (!romunmapped) 218 bus_space_unmap(ca->ca_iot, romh, STI_ROMSIZE); 219 return rv; 220 } 221 222 void 223 sti_sgc_attach(device_t parent, device_t self, void *aux) 224 { 225 struct sti_softc *sc = device_private(self); 226 struct confargs *ca = aux; 227 bus_space_handle_t romh; 228 hppa_hpa_t consaddr; 229 int pagezero_cookie; 230 paddr_t rom; 231 uint32_t romlen; 232 int rv; 233 int i; 234 235 pagezero_cookie = hppa_pagezero_map(); 236 consaddr = (hppa_hpa_t)PAGE0->mem_cons.pz_hpa; 237 hppa_pagezero_unmap(pagezero_cookie); 238 239 sc->sc_dev = self; 240 sc->sc_enable_rom = NULL; 241 sc->sc_disable_rom = NULL; 242 243 /* we stashed rom addr/len into the last slot during probe */ 244 rom = ca->ca_addrs[ca->ca_naddrs - 1].addr; 245 romlen = ca->ca_addrs[ca->ca_naddrs - 1].size; 246 247 if ((rv = bus_space_map(ca->ca_iot, rom, romlen, 0, &romh))) { 248 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) 249 romh = rom; 250 else { 251 aprint_error(": can't map rom space (%d)\n", rv); 252 return; 253 } 254 } 255 256 sc->bases[0] = romh; 257 for (i = 1; i < STI_REGION_MAX; i++) 258 sc->bases[i] = ca->ca_hpa; 259 260 #ifdef HP7300LC_CPU 261 /* 262 * PCXL2: enable accel I/O for this space, see PCX-L2 ERS "ACCEL_IO". 263 * "pcxl2_ers.{ps,pdf}", (section / chapter . rel. page / abs. page) 264 * 8.7.4 / 8-12 / 92, 11.3.14 / 11-14 / 122 and 14.8 / 14-5 / 203. 265 */ 266 if (hppa_cpu_info->hci_cputype == hpcxl2 267 && ca->ca_hpa >= PCXL2_ACCEL_IO_START 268 && ca->ca_hpa <= PCXL2_ACCEL_IO_END) 269 eaio_l2(PCXL2_ACCEL_IO_ADDR2MASK(ca->ca_hpa)); 270 #endif /* HP7300LC_CPU */ 271 272 if (ca->ca_hpa == consaddr) 273 sc->sc_flags |= STI_CONSOLE; 274 if (sti_attach_common(sc, ca->ca_iot, ca->ca_iot, romh, 275 STI_CODEBASE_PA) == 0) 276 config_interrupts(self, sti_sgc_end_attach); 277 } 278 279 void 280 sti_sgc_end_attach(device_t dev) 281 { 282 struct sti_softc *sc = device_private(dev); 283 284 sti_end_attach(sc); 285 } 286