1 /* $OpenBSD: gfb.c,v 1.1 2009/03/09 22:36:43 kettenis Exp $ */ 2 3 /* 4 * Copyright (c) 2009 Mark Kettenis. 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/param.h> 20 #include <sys/device.h> 21 #include <sys/systm.h> 22 23 #include <machine/bus.h> 24 #include <machine/autoconf.h> 25 26 #include <dev/wscons/wsconsio.h> 27 #include <dev/wscons/wsdisplayvar.h> 28 #include <dev/rasops/rasops.h> 29 #include <machine/fbvar.h> 30 31 struct gfb_softc { 32 struct sunfb sc_sunfb; 33 bus_space_tag_t sc_bt; 34 bus_space_handle_t sc_pixel_h; 35 int sc_console; 36 int sc_node; 37 u_int sc_mode; 38 }; 39 40 int gfb_match(struct device *, void *, void *); 41 void gfb_attach(struct device *, struct device *, void *); 42 43 int gfb_ioctl(void *, u_long, caddr_t, int, struct proc *); 44 45 struct wsdisplay_accessops gfb_accessops = { 46 gfb_ioctl, 47 NULL, /* mmap */ 48 NULL, /* alloc_screen */ 49 NULL, /* free_screen */ 50 NULL, /* show_screen */ 51 NULL, /* load_font */ 52 NULL, /* scrollback */ 53 NULL, /* getchar */ 54 NULL, /* burner */ 55 }; 56 57 struct cfdriver gfb_cd = { 58 NULL, "gfb", DV_DULL 59 }; 60 61 struct cfattach gfb_ca = { 62 sizeof(struct gfb_softc), gfb_match, gfb_attach 63 }; 64 65 int 66 gfb_match(struct device *parent, void *match, void *aux) 67 { 68 struct mainbus_attach_args *ma = aux; 69 70 if (strcmp(ma->ma_name, "SUNW,gfb") == 0) 71 return (1); 72 return (0); 73 } 74 75 void 76 gfb_attach(struct device *parent, struct device *self, void *aux) 77 { 78 struct gfb_softc *sc = (struct gfb_softc *)self; 79 struct mainbus_attach_args *ma = aux; 80 extern int fbnode; 81 82 sc->sc_bt = ma->ma_bustag; 83 84 printf("\n"); 85 86 if (bus_space_map(ma->ma_bustag, ma->ma_reg[6].ur_paddr, 87 ma->ma_reg[6].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_pixel_h)) 88 return; 89 90 sc->sc_console = (fbnode == ma->ma_node); 91 sc->sc_node = ma->ma_node; 92 93 fb_setsize(&sc->sc_sunfb, 32, 1152, 900, sc->sc_node, 0); 94 /* linesize has a fixed value, compensate */ 95 sc->sc_sunfb.sf_linebytes = 16384; 96 sc->sc_sunfb.sf_fbsize = sc->sc_sunfb.sf_height * 16384; 97 98 sc->sc_sunfb.sf_ro.ri_bits = (void *)bus_space_vaddr(sc->sc_bt, 99 sc->sc_pixel_h); 100 sc->sc_sunfb.sf_ro.ri_hw = sc; 101 fbwscons_init(&sc->sc_sunfb, 0, sc->sc_console); 102 103 if (sc->sc_console) 104 fbwscons_console_init(&sc->sc_sunfb, -1); 105 106 fbwscons_attach(&sc->sc_sunfb, &gfb_accessops, sc->sc_console); 107 return; 108 } 109 110 int 111 gfb_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p) 112 { 113 struct gfb_softc *sc = v; 114 struct wsdisplay_fbinfo *wdf; 115 116 switch (cmd) { 117 case WSDISPLAYIO_GTYPE: 118 *(u_int *)data = WSDISPLAY_TYPE_UNKNOWN; 119 break; 120 case WSDISPLAYIO_SMODE: 121 sc->sc_mode = *(u_int *)data; 122 break; 123 case WSDISPLAYIO_GINFO: 124 wdf = (void *)data; 125 wdf->height = sc->sc_sunfb.sf_height; 126 wdf->width = sc->sc_sunfb.sf_width; 127 wdf->depth = sc->sc_sunfb.sf_depth; 128 wdf->cmsize = 256; 129 break; 130 case WSDISPLAYIO_LINEBYTES: 131 *(u_int *)data = sc->sc_sunfb.sf_linebytes; 132 break; 133 134 #if 0 135 case WSDISPLAYIO_GETCMAP: 136 return gfb_getcmap(sc, (struct wsdisplay_cmap *)data); 137 case WSDISPLAYIO_PUTCMAP: 138 return gfb_putcmap(sc, (struct wsdisplay_cmap *)data); 139 #endif 140 141 case WSDISPLAYIO_SVIDEO: 142 case WSDISPLAYIO_GVIDEO: 143 break; 144 145 case WSDISPLAYIO_GCURPOS: 146 case WSDISPLAYIO_SCURPOS: 147 case WSDISPLAYIO_GCURMAX: 148 case WSDISPLAYIO_GCURSOR: 149 case WSDISPLAYIO_SCURSOR: 150 default: 151 return -1; /* not supported yet */ 152 } 153 154 return (0); 155 } 156