1 /* $OpenBSD: sti_sgc.c,v 1.38 2009/02/06 22:51:04 miod Exp $ */ 2 3 /* 4 * Copyright (c) 2000-2003 Michael Shalayeff 5 * All rights reserved. 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 ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 * THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 /* 29 * These cards has to be known to work so far: 30 * - HPA1991AGrayscale rev 0.02 (705/35) (byte-wide) 31 * - HPA1991AC19 rev 0.02 (715/33) (byte-wide) 32 * - HPA208LC1280 rev 8.04 (712/80) just works 33 */ 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/device.h> 38 39 #include <uvm/uvm.h> 40 41 #include <machine/bus.h> 42 #include <machine/cpu.h> 43 #include <machine/iomod.h> 44 #include <machine/autoconf.h> 45 46 #include <dev/wscons/wsdisplayvar.h> 47 #include <dev/wscons/wsconsio.h> 48 49 #include <dev/ic/stireg.h> 50 #include <dev/ic/stivar.h> 51 52 #include <hppa/dev/cpudevs.h> 53 54 #define STI_ROMSIZE (sizeof(struct sti_dd) * 4) 55 #define STI_ID_FDDI 0x280b31af /* Medusa FDDI ROM id */ 56 57 /* gecko optional graphics (these share the onboard's prom) */ 58 const char sti_sgc_opt[] = { 0x17, 0x20, 0x30, 0x40, 0x70, 0xc0, 0xd0 }; 59 60 extern struct cfdriver sti_cd; 61 62 int sti_sgc_probe(struct device *, void *, void *); 63 void sti_sgc_attach(struct device *, struct device *, void *); 64 paddr_t sti_sgc_getrom(int, struct confargs *); 65 66 struct cfattach sti_gedoens_ca = { 67 sizeof(struct sti_softc), sti_sgc_probe, sti_sgc_attach 68 }; 69 70 /* 71 * Locate STI ROM. 72 * On some machines it may not be part of the HPA space. 73 */ 74 paddr_t 75 sti_sgc_getrom(int unit, struct confargs *ca) 76 { 77 paddr_t rom = PAGE0->pd_resv2[1]; 78 int i; 79 80 if (unit) { 81 i = -1; 82 if (ca->ca_type.iodc_sv_model == HPPA_FIO_GSGC) 83 for (i = sizeof(sti_sgc_opt); i-- && 84 sti_sgc_opt[i] != ca->ca_type.iodc_revision; ) 85 ; 86 if (i < 0) 87 rom = 0; 88 } 89 90 if (rom < HPPA_IOBEGIN) { 91 if (ca->ca_naddrs > 0) 92 rom = ca->ca_addrs[0].addr; 93 else 94 rom = ca->ca_hpa; 95 } 96 97 return (rom); 98 } 99 100 int 101 sti_sgc_probe(struct device *parent, void *match, void *aux) 102 { 103 struct cfdata *cf = match; 104 struct confargs *ca = aux; 105 bus_space_handle_t romh; 106 paddr_t rom; 107 u_int32_t id; 108 u_char devtype; 109 int rv = 0, romunmapped = 0; 110 111 /* due to the graphic nature of this program do probe only one */ 112 if (cf->cf_unit > sti_cd.cd_ndevs) 113 return (0); 114 115 if (ca->ca_type.iodc_type != HPPA_TYPE_FIO) 116 return (0); 117 118 /* these need further checking for the graphics id */ 119 if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC && 120 ca->ca_type.iodc_sv_model != HPPA_FIO_SGC) 121 return 0; 122 123 rom = sti_sgc_getrom(cf->cf_unit, ca); 124 #ifdef STIDEBUG 125 printf ("sti: hpa=%x, rom=%x\n", ca->ca_hpa, rom); 126 #endif 127 128 /* if it does not map, probably part of the lasi space */ 129 if ((rv = bus_space_map(ca->ca_iot, rom, STI_ROMSIZE, 0, &romh))) { 130 #ifdef STIDEBUG 131 printf ("sti: cannot map rom space (%d)\n", rv); 132 #endif 133 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) { 134 romh = rom; 135 romunmapped++; 136 } else { 137 /* in this case nobody has no freaking idea */ 138 return 0; 139 } 140 } 141 142 devtype = bus_space_read_1(ca->ca_iot, romh, 3); 143 144 #ifdef STIDEBUG 145 printf("sti: devtype=%d\n", devtype); 146 #endif 147 rv = 1; 148 switch (devtype) { 149 case STI_DEVTYPE4: 150 id = bus_space_read_4(ca->ca_iot, romh, 0x8); 151 break; 152 case STI_DEVTYPE1: 153 id = (bus_space_read_1(ca->ca_iot, romh, 0x10 + 3) << 24) | 154 (bus_space_read_1(ca->ca_iot, romh, 0x10 + 7) << 16) | 155 (bus_space_read_1(ca->ca_iot, romh, 0x10 + 11) << 8) | 156 (bus_space_read_1(ca->ca_iot, romh, 0x10 + 15)); 157 break; 158 default: 159 #ifdef STIDEBUG 160 printf("sti: unknown type (%x)\n", devtype); 161 #endif 162 rv = 0; 163 } 164 165 if (rv && 166 ca->ca_type.iodc_sv_model == HPPA_FIO_SGC && id == STI_ID_FDDI) { 167 #ifdef STIDEBUG 168 printf("sti: not a graphics device\n"); 169 #endif 170 rv = 0; 171 } 172 173 if (ca->ca_naddrs >= sizeof(ca->ca_addrs)/sizeof(ca->ca_addrs[0])) { 174 printf("sti: address list overflow\n"); 175 return (0); 176 } 177 178 ca->ca_addrs[ca->ca_naddrs].addr = rom; 179 ca->ca_addrs[ca->ca_naddrs].size = sti_rom_size(ca->ca_iot, romh); 180 ca->ca_naddrs++; 181 182 if (!romunmapped) 183 bus_space_unmap(ca->ca_iot, romh, STI_ROMSIZE); 184 return (rv); 185 } 186 187 void 188 sti_sgc_attach(struct device *parent, struct device *self, void *aux) 189 { 190 struct sti_softc *sc = (void *)self; 191 struct confargs *ca = aux; 192 bus_space_handle_t romh; 193 paddr_t rom; 194 u_int32_t romlen; 195 int rv; 196 int i; 197 198 /* we stashed rom addr/len into the last slot during probe */ 199 rom = ca->ca_addrs[ca->ca_naddrs - 1].addr; 200 romlen = ca->ca_addrs[ca->ca_naddrs - 1].size; 201 if ((rv = bus_space_map(ca->ca_iot, rom, romlen, 0, &romh))) { 202 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) 203 romh = rom; 204 else { 205 printf (": cannot map rom space (%d)\n", rv); 206 return; 207 } 208 } 209 210 sc->bases[0] = romh; 211 for (i = 1; i < STI_REGION_MAX; i++) 212 sc->bases[i] = ca->ca_hpa; 213 214 #ifdef HP7300LC_CPU 215 /* PCXL2: enable accel i/o for this space */ 216 if (cpu_type == hpcxl2) 217 eaio_l2(0x8 >> (((ca->ca_hpa >> 25) & 3) - 2)); 218 #endif 219 220 if (ca->ca_hpa == (hppa_hpa_t)PAGE0->mem_cons.pz_hpa) 221 sc->sc_flags |= STI_CONSOLE; 222 if (sti_attach_common(sc, ca->ca_iot, ca->ca_iot, romh, 223 STI_CODEBASE_PA) == 0) 224 startuphook_establish(sti_end_attach, sc); 225 } 226