static void awin_fb_attach(device_t parent, device_t self, void *aux) { struct awin_fb_softc *sc = device_private(self); struct awinfb_attach_args * const afb = aux; prop_dictionary_t cfg = device_properties(self); struct genfb_ops ops; if (awin_fb_consoledev == NULL) awin_fb_consoledev = self; sc->sc_gen.sc_dev = self; sc->sc_debedev = parent; sc->sc_dmat = afb->afb_dmat; sc->sc_dmasegs = afb->afb_dmasegs; sc->sc_ndmasegs = afb->afb_ndmasegs; sc->sc_mpdev = device_find_by_driver_unit("awinmp", 0); prop_dictionary_set_uint32(cfg, "width", afb->afb_width); prop_dictionary_set_uint32(cfg, "height", afb->afb_height); prop_dictionary_set_uint8(cfg, "depth", 32); prop_dictionary_set_uint16(cfg, "linebytes", afb->afb_width * 4); prop_dictionary_set_uint32(cfg, "address", 0); prop_dictionary_set_uint32(cfg, "virtual_address", (uintptr_t)afb->afb_fb); genfb_init(&sc->sc_gen); if (sc->sc_gen.sc_width == 0 || sc->sc_gen.sc_fbsize == 0) { aprint_normal(": disabled\n"); return; } pmf_device_register1(self, NULL, NULL, awin_fb_shutdown); memset(&ops, 0, sizeof(ops)); ops.genfb_ioctl = awin_fb_ioctl; ops.genfb_mmap = awin_fb_mmap; aprint_naive("\n"); bool is_console = false; prop_dictionary_get_bool(cfg, "is_console", &is_console); if (is_console) aprint_normal(": switching to framebuffer console\n"); else aprint_normal("\n"); genfb_attach(&sc->sc_gen, &ops); }
static void tegra_genfb_attach(device_t parent, device_t self, void *aux) { struct tegra_genfb_softc * const sc = device_private(self); struct tegrafb_attach_args * const tfb = aux; prop_dictionary_t prop = device_properties(self); const bool is_console = tfb->tfb_console; struct genfb_ops ops; sc->sc_gen.sc_dev = self; sc->sc_dmat = tfb->tfb_dmat; sc->sc_dmamap = tfb->tfb_dmamap; prop_dictionary_set_bool(prop, "is_console", is_console); prop_dictionary_set_uint32(prop, "width", tfb->tfb_width); prop_dictionary_set_uint32(prop, "height", tfb->tfb_height); prop_dictionary_set_uint8(prop, "depth", tfb->tfb_depth); prop_dictionary_set_uint32(prop, "linebytes", tfb->tfb_stride); prop_dictionary_set_uint64(prop, "address", 0); prop_dictionary_set_uint64(prop, "virtual_address", (uintptr_t)tfb->tfb_dmap); genfb_init(&sc->sc_gen); if (sc->sc_gen.sc_width == 0 || sc->sc_gen.sc_fbsize == 0) { aprint_error(": disabled\n"); return; } pmf_device_register1(self, NULL, NULL, tegra_genfb_shutdown); aprint_naive("\n"); if (is_console) { aprint_normal(": switching to framebuffer console\n"); } else { aprint_normal("\n"); } memset(&ops, 0, sizeof(ops)); ops.genfb_ioctl = tegra_genfb_ioctl; ops.genfb_mmap = tegra_genfb_mmap; genfb_attach(&sc->sc_gen, &ops); #if defined(DDB) if (is_console) { tegra_genfb_consoledev = self; db_trap_callback = tegra_genfb_ddb_trap_callback; } #endif }
/* * Attach a display. We need to notice if it is the console, too. */ static void genfb_attach_sbus(device_t parent, device_t self, void *args) { struct genfb_sbus_softc *sc = device_private(self); struct sbus_attach_args *sa = args; static const struct genfb_ops zero_ops; struct genfb_ops ops = zero_ops; prop_dictionary_t dict; bus_space_handle_t bh; paddr_t fbpa; vaddr_t fbva; int node = sa->sa_node; int isconsole; aprint_normal("\n"); sc->sc_gen.sc_dev = self; /* Remember cookies for genfb_mmap_sbus() */ sc->sc_tag = sa->sa_bustag; sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset); /* read geometry information from the device tree */ sc->sc_gen.sc_width = prom_getpropint(sa->sa_node, "width", 1152); sc->sc_gen.sc_height = prom_getpropint(sa->sa_node, "height", 900); sc->sc_gen.sc_depth = prom_getpropint(sa->sa_node, "depth", 8); sc->sc_gen.sc_stride = prom_getpropint(sa->sa_node, "linebytes", (sc->sc_gen.sc_width * sc->sc_gen.sc_depth + 7) >> 3 ); sc->sc_gen.sc_fbsize = sc->sc_gen.sc_height * sc->sc_gen.sc_stride; fbva = (uint32_t)prom_getpropint(sa->sa_node, "address", 0); if (fbva == 0) panic("this fb has no address property\n"); aprint_normal_dev(self, "%d x %d at %d bit\n", sc->sc_gen.sc_width, sc->sc_gen.sc_height, sc->sc_gen.sc_depth); pmap_extract(pmap_kernel(), fbva, &fbpa); sc->sc_gen.sc_fboffset = (fbpa & 0x01ffffff) - (sc->sc_paddr & 0x01ffffff); aprint_normal_dev(self, "framebuffer at offset 0x%x\n", (uint32_t)sc->sc_gen.sc_fboffset); #if notyet if (sc->sc_gen.sc_depth <= 8) { /* setup some ANSIish colour map */ char boo[256]; snprintf(boo, 256, "\" pal!\" %x %x %x %x %x call", sa->sa_node, 0, 0xa0, 0xa0, 0); prom_interpret(boo); } #endif isconsole = fb_is_console(node); dict = device_properties(self); prop_dictionary_set_bool(dict, "is_console", isconsole); if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, sa->sa_offset + sc->sc_gen.sc_fboffset, sc->sc_gen.sc_fbsize, BUS_SPACE_MAP_LINEAR, &bh) != 0) { aprint_error_dev(self, "cannot map framebuffer\n"); return; } sc->sc_gen.sc_fbaddr = (void *)bus_space_vaddr(sa->sa_bustag, bh); ops.genfb_ioctl = genfb_ioctl_sbus; ops.genfb_mmap = genfb_mmap_sbus; genfb_attach(&sc->sc_gen, &ops); }
int drmfb_attach(struct drmfb_softc *sc, const struct drmfb_attach_args *da) { const struct drm_fb_helper_surface_size *const sizes = da->da_fb_sizes; const prop_dictionary_t dict = device_properties(da->da_dev); #if NVGA > 0 struct drm_device *const dev = da->da_fb_helper->dev; #endif static const struct genfb_ops zero_genfb_ops; struct genfb_ops genfb_ops = zero_genfb_ops; enum { CONS_VGA, CONS_GENFB, CONS_NONE } what_was_cons; int error; /* genfb requires this. */ KASSERTMSG((void *)&sc->sc_genfb == device_private(da->da_dev), "drmfb_softc must be first member of device softc"); sc->sc_da = *da; prop_dictionary_set_uint32(dict, "width", sizes->surface_width); prop_dictionary_set_uint32(dict, "height", sizes->surface_height); prop_dictionary_set_uint8(dict, "depth", sizes->surface_bpp); prop_dictionary_set_uint16(dict, "linebytes", roundup2((sizes->surface_width * howmany(sizes->surface_bpp, 8)), 64)); prop_dictionary_set_uint32(dict, "address", 0); /* XXX >32-bit */ CTASSERT(sizeof(uintptr_t) <= sizeof(uint64_t)); prop_dictionary_set_uint64(dict, "virtual_address", (uint64_t)(uintptr_t)da->da_fb_vaddr); prop_dictionary_set_uint64(dict, "mode_callback", (uint64_t)(uintptr_t)&drmfb_genfb_mode_callback); /* XXX Whattakludge! */ #if NVGA > 0 if ((da->da_params->dp_is_vga_console != NULL) && (*da->da_params->dp_is_vga_console)(dev)) { what_was_cons = CONS_VGA; prop_dictionary_set_bool(dict, "is_console", true); vga_cndetach(); if (da->da_params->dp_disable_vga) (*da->da_params->dp_disable_vga)(dev); } else #endif if (genfb_is_console() && genfb_is_enabled()) { what_was_cons = CONS_GENFB; prop_dictionary_set_bool(dict, "is_console", true); } else { what_was_cons = CONS_NONE; prop_dictionary_set_bool(dict, "is_console", false); } sc->sc_genfb.sc_dev = sc->sc_da.da_dev; genfb_init(&sc->sc_genfb); genfb_ops.genfb_ioctl = drmfb_genfb_ioctl; genfb_ops.genfb_mmap = drmfb_genfb_mmap; genfb_ops.genfb_enable_polling = drmfb_genfb_enable_polling; genfb_ops.genfb_disable_polling = drmfb_genfb_disable_polling; error = genfb_attach(&sc->sc_genfb, &genfb_ops); if (error) { aprint_error_dev(sc->sc_da.da_dev, "failed to attach genfb: %d\n", error); goto fail0; } /* Success! */ return 0; fail0: KASSERT(error); /* XXX Restore console... */ switch (what_was_cons) { case CONS_VGA: break; case CONS_GENFB: break; case CONS_NONE: break; default: break; } return error; }