bwtwo.c revision 1.13
1/* $OpenBSD: bwtwo.c,v 1.13 2005/03/01 21:23:36 miod Exp $ */ 2 3/* 4 * Copyright (c) 2002 Jason L. Wright (jason@thought.net) 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 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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 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 IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Effort sponsored in part by the Defense Advanced Research Projects 29 * Agency (DARPA) and Air Force Research Laboratory, Air Force 30 * Materiel Command, USAF, under agreement number F30602-01-2-0537. 31 * 32 */ 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/kernel.h> 37#include <sys/errno.h> 38#include <sys/device.h> 39#include <sys/ioctl.h> 40#include <sys/malloc.h> 41 42#include <machine/bus.h> 43#include <machine/intr.h> 44#include <machine/autoconf.h> 45#include <machine/openfirm.h> 46 47#include <dev/sbus/sbusvar.h> 48#include <dev/wscons/wsconsio.h> 49#include <dev/wscons/wsdisplayvar.h> 50#include <dev/wscons/wscons_raster.h> 51#include <dev/rasops/rasops.h> 52#include <machine/fbvar.h> 53 54#define BWTWO_CTRL_OFFSET 0x400000 55#define BWTWO_CTRL_SIZE (sizeof(u_int32_t) * 8) 56#define BWTWO_VID_OFFSET 0x800000 57#define BWTWO_VID_SIZE (1024 * 1024) 58 59#define FBC_CTRL 0x10 /* control */ 60#define FBC_STAT 0x11 /* status */ 61#define FBC_START 0x12 /* cursor start */ 62#define FBC_END 0x13 /* cursor end */ 63#define FBC_VCTRL 0x14 /* 12 bytes of timing goo */ 64 65#define FBC_CTRL_IENAB 0x80 /* interrupt enable */ 66#define FBC_CTRL_VENAB 0x40 /* video enable */ 67#define FBC_CTRL_TIME 0x20 /* timing enable */ 68#define FBC_CTRL_CURS 0x10 /* cursor compare enable */ 69#define FBC_CTRL_XTAL 0x0c /* xtal select (0,1,2,test): */ 70#define FBC_CTRL_XTAL_0 0x00 /* 0 */ 71#define FBC_CTRL_XTAL_1 0x04 /* 0 */ 72#define FBC_CTRL_XTAL_2 0x08 /* 0 */ 73#define FBC_CTRL_XTAL_TEST 0x0c /* 0 */ 74#define FBC_CTRL_DIV 0x03 /* divisor (1,2,3,4): */ 75#define FBC_CTRL_DIV_1 0x00 /* / 1 */ 76#define FBC_CTRL_DIV_2 0x01 /* / 2 */ 77#define FBC_CTRL_DIV_3 0x02 /* / 3 */ 78#define FBC_CTRL_DIV_4 0x03 /* / 4 */ 79 80#define FBC_STAT_INTR 0x80 /* interrupt pending */ 81#define FBC_STAT_RES 0x70 /* monitor sense: */ 82#define FBC_STAT_RES_1024 0x10 /* 1024x768 */ 83#define FBC_STAT_RES_1280 0x40 /* 1280x1024 */ 84#define FBC_STAT_RES_1152 0x30 /* 1152x900 */ 85#define FBC_STAT_RES_1152A 0x40 /* 1152x900x76, A */ 86#define FBC_STAT_RES_1600 0x50 /* 1600x1200 */ 87#define FBC_STAT_RES_1152B 0x60 /* 1152x900x86, B */ 88#define FBC_STAT_ID 0x0f /* id mask: */ 89#define FBC_STAT_ID_COLOR 0x01 /* color */ 90#define FBC_STAT_ID_MONO 0x02 /* monochrome */ 91#define FBC_STAT_ID_MONOECL 0x03 /* monochrome, ecl */ 92 93#define FBC_READ(sc, reg) \ 94 bus_space_read_1((sc)->sc_bustag, (sc)->sc_ctrl_regs, (reg)) 95#define FBC_WRITE(sc, reg, val) \ 96 bus_space_write_1((sc)->sc_bustag, (sc)->sc_ctrl_regs, (reg), (val)) 97 98struct bwtwo_softc { 99 struct sunfb sc_sunfb; 100 struct sbusdev sc_sd; 101 bus_space_tag_t sc_bustag; 102 bus_addr_t sc_paddr; 103 bus_space_handle_t sc_ctrl_regs; 104 bus_space_handle_t sc_vid_regs; 105 int sc_nscreens; 106}; 107 108int bwtwo_ioctl(void *, u_long, caddr_t, int, struct proc *); 109int bwtwo_alloc_screen(void *, const struct wsscreen_descr *, void **, 110 int *, int *, long *); 111void bwtwo_free_screen(void *, void *); 112int bwtwo_show_screen(void *, void *, int, void (*cb)(void *, int, int), 113 void *); 114paddr_t bwtwo_mmap(void *, off_t, int); 115int bwtwo_is_console(int); 116void bwtwo_burner(void *, u_int, u_int); 117void bwtwo_updatecursor(struct rasops_info *); 118 119struct wsdisplay_accessops bwtwo_accessops = { 120 bwtwo_ioctl, 121 bwtwo_mmap, 122 bwtwo_alloc_screen, 123 bwtwo_free_screen, 124 bwtwo_show_screen, 125 NULL, /* load_font */ 126 NULL, /* scrollback */ 127 NULL, /* getchar */ 128 bwtwo_burner, 129}; 130 131int bwtwomatch(struct device *, void *, void *); 132void bwtwoattach(struct device *, struct device *, void *); 133 134struct cfattach bwtwo_ca = { 135 sizeof (struct bwtwo_softc), bwtwomatch, bwtwoattach 136}; 137 138struct cfdriver bwtwo_cd = { 139 NULL, "bwtwo", DV_DULL 140}; 141 142int 143bwtwomatch(parent, vcf, aux) 144 struct device *parent; 145 void *vcf, *aux; 146{ 147 struct cfdata *cf = vcf; 148 struct sbus_attach_args *sa = aux; 149 150 return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0); 151} 152 153void 154bwtwoattach(parent, self, aux) 155 struct device *parent, *self; 156 void *aux; 157{ 158 struct bwtwo_softc *sc = (struct bwtwo_softc *)self; 159 struct sbus_attach_args *sa = aux; 160 int node, console; 161 const char *nam; 162 163 node = sa->sa_node; 164 sc->sc_bustag = sa->sa_bustag; 165 sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset); 166 167 fb_setsize(&sc->sc_sunfb, 1, 1152, 900, node, 0); 168 169 if (sa->sa_nreg != 1) { 170 printf(": expected %d registers, got %d\n", 1, sa->sa_nreg); 171 goto fail; 172 } 173 174 /* 175 * Map just CTRL and video RAM. 176 */ 177 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot, 178 sa->sa_reg[0].sbr_offset + BWTWO_CTRL_OFFSET, 179 BWTWO_CTRL_SIZE, 0, 0, &sc->sc_ctrl_regs) != 0) { 180 printf(": cannot map ctrl registers\n"); 181 goto fail_ctrl; 182 } 183 184 if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot, 185 sa->sa_reg[0].sbr_offset + BWTWO_VID_OFFSET, 186 sc->sc_sunfb.sf_fbsize, BUS_SPACE_MAP_LINEAR, 187 0, &sc->sc_vid_regs) != 0) { 188 printf(": cannot map vid registers\n"); 189 goto fail_vid; 190 } 191 192 nam = getpropstring(node, "model"); 193 if (*nam == '\0') 194 nam = sa->sa_name; 195 printf(": %s", nam); 196 197 console = bwtwo_is_console(node); 198 199 sbus_establish(&sc->sc_sd, &sc->sc_sunfb.sf_dev); 200 201 bwtwo_burner(sc, 1, 0); 202 203 printf(", %dx%d\n", sc->sc_sunfb.sf_width, sc->sc_sunfb.sf_height); 204 205 sc->sc_sunfb.sf_ro.ri_bits = (void *)bus_space_vaddr(sc->sc_bustag, 206 sc->sc_vid_regs); 207 sc->sc_sunfb.sf_ro.ri_hw = sc; 208 fbwscons_init(&sc->sc_sunfb, console ? 0 : RI_CLEAR); 209 210 if (console) { 211 sc->sc_sunfb.sf_ro.ri_updatecursor = bwtwo_updatecursor; 212 fbwscons_console_init(&sc->sc_sunfb, -1, bwtwo_burner); 213 } 214 215 fbwscons_attach(&sc->sc_sunfb, &bwtwo_accessops, console); 216 217 return; 218 219fail_vid: 220 bus_space_unmap(sa->sa_bustag, sc->sc_ctrl_regs, BWTWO_CTRL_SIZE); 221fail_ctrl: 222fail: 223; 224} 225 226int 227bwtwo_ioctl(v, cmd, data, flags, p) 228 void *v; 229 u_long cmd; 230 caddr_t data; 231 int flags; 232 struct proc *p; 233{ 234 struct bwtwo_softc *sc = v; 235 struct wsdisplay_fbinfo *wdf; 236 237 switch (cmd) { 238 case WSDISPLAYIO_GTYPE: 239 *(u_int *)data = WSDISPLAY_TYPE_SUNBW; 240 break; 241 case WSDISPLAYIO_GINFO: 242 wdf = (void *)data; 243 wdf->height = sc->sc_sunfb.sf_height; 244 wdf->width = sc->sc_sunfb.sf_width; 245 wdf->depth = sc->sc_sunfb.sf_depth; 246 wdf->cmsize = 0; 247 break; 248 case WSDISPLAYIO_LINEBYTES: 249 *(u_int *)data = sc->sc_sunfb.sf_linebytes; 250 break; 251 252 case WSDISPLAYIO_GETCMAP: 253 case WSDISPLAYIO_PUTCMAP: 254 break; 255 256 case WSDISPLAYIO_SVIDEO: 257 case WSDISPLAYIO_GVIDEO: 258 break; 259 260 case WSDISPLAYIO_GCURPOS: 261 case WSDISPLAYIO_SCURPOS: 262 case WSDISPLAYIO_GCURMAX: 263 case WSDISPLAYIO_GCURSOR: 264 case WSDISPLAYIO_SCURSOR: 265 default: 266 return -1; /* not supported yet */ 267 } 268 269 return (0); 270} 271 272int 273bwtwo_alloc_screen(v, type, cookiep, curxp, curyp, attrp) 274 void *v; 275 const struct wsscreen_descr *type; 276 void **cookiep; 277 int *curxp, *curyp; 278 long *attrp; 279{ 280 struct bwtwo_softc *sc = v; 281 282 if (sc->sc_nscreens > 0) 283 return (ENOMEM); 284 285 *cookiep = &sc->sc_sunfb.sf_ro; 286 *curyp = 0; 287 *curxp = 0; 288 sc->sc_sunfb.sf_ro.ri_ops.alloc_attr(&sc->sc_sunfb.sf_ro, 289 0, 0, 0, attrp); 290 sc->sc_nscreens++; 291 return (0); 292} 293 294void 295bwtwo_free_screen(v, cookie) 296 void *v; 297 void *cookie; 298{ 299 struct bwtwo_softc *sc = v; 300 301 sc->sc_nscreens--; 302} 303 304int 305bwtwo_show_screen(v, cookie, waitok, cb, cbarg) 306 void *v; 307 void *cookie; 308 int waitok; 309 void (*cb)(void *, int, int); 310 void *cbarg; 311{ 312 return (0); 313} 314 315#define START (128 * 1024 + 128 * 1024) 316#define NOOVERLAY (0x04000000) 317 318paddr_t 319bwtwo_mmap(v, offset, prot) 320 void *v; 321 off_t offset; 322 int prot; 323{ 324 struct bwtwo_softc *sc = v; 325 326 if (offset & PGOFSET) 327 return (-1); 328 329 if (offset >= 0 && offset < sc->sc_sunfb.sf_fbsize) 330 return (bus_space_mmap(sc->sc_bustag, sc->sc_paddr, 331 BWTWO_VID_OFFSET + offset, prot, BUS_SPACE_MAP_LINEAR)); 332 333 return (-1); 334} 335 336int 337bwtwo_is_console(node) 338 int node; 339{ 340 extern int fbnode; 341 342 return (fbnode == node); 343} 344 345void 346bwtwo_burner(vsc, on, flags) 347 void *vsc; 348 u_int on, flags; 349{ 350 struct bwtwo_softc *sc = vsc; 351 int s; 352 u_int8_t fbc; 353 354 s = splhigh(); 355 fbc = FBC_READ(sc, FBC_CTRL); 356 if (on) 357 fbc |= FBC_CTRL_VENAB | FBC_CTRL_TIME; 358 else { 359 fbc &= ~FBC_CTRL_VENAB; 360 if (flags & WSDISPLAY_BURN_VBLANK) 361 fbc &= ~FBC_CTRL_TIME; 362 } 363 FBC_WRITE(sc, FBC_CTRL, fbc); 364 splx(s); 365} 366 367void 368bwtwo_updatecursor(ri) 369 struct rasops_info *ri; 370{ 371 struct bwtwo_softc *sc = ri->ri_hw; 372 373 if (sc->sc_sunfb.sf_crowp != NULL) 374 *sc->sc_sunfb.sf_crowp = ri->ri_crow; 375 if (sc->sc_sunfb.sf_ccolp != NULL) 376 *sc->sc_sunfb.sf_ccolp = ri->ri_ccol; 377} 378