Module Name: src Committed By: dyoung Date: Tue Oct 18 23:43:36 UTC 2011
Modified Files: src/sys/arch/x86/isa: isa_machdep.c src/sys/arch/x86/pci: pci_machdep.c src/sys/arch/x86/x86: x86_autoconf.c Log Message: Factor device_isa_register() and device_pci_register() out of device_register() and stick the new routines into isa_machdep.c and pci_machdep.c, respectively. To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/isa/isa_machdep.c cvs rdiff -u -r1.51 -r1.52 src/sys/arch/x86/pci/pci_machdep.c cvs rdiff -u -r1.61 -r1.62 src/sys/arch/x86/x86/x86_autoconf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/x86/isa/isa_machdep.c diff -u src/sys/arch/x86/isa/isa_machdep.c:1.30 src/sys/arch/x86/isa/isa_machdep.c:1.31 --- src/sys/arch/x86/isa/isa_machdep.c:1.30 Thu Sep 1 15:10:31 2011 +++ src/sys/arch/x86/isa/isa_machdep.c Tue Oct 18 23:43:36 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: isa_machdep.c,v 1.30 2011/09/01 15:10:31 christos Exp $ */ +/* $NetBSD: isa_machdep.c,v 1.31 2011/10/18 23:43:36 dyoung Exp $ */ /*- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. @@ -65,7 +65,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.30 2011/09/01 15:10:31 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.31 2011/10/18 23:43:36 dyoung Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -80,12 +80,16 @@ __KERNEL_RCSID(0, "$NetBSD: isa_machdep. #include <machine/bus_private.h> #include <machine/pio.h> #include <machine/cpufunc.h> +#include <machine/autoconf.h> +#include <machine/bootinfo.h> #include <dev/isa/isareg.h> #include <dev/isa/isavar.h> #include <uvm/uvm_extern.h> +#include "acpica.h" +#include "opt_acpi.h" #include "ioapic.h" #if NIOAPIC > 0 @@ -335,3 +339,48 @@ _isa_dma_may_bounce(bus_dma_tag_t t, bus *cookieflagsp |= X86_DMA_MIGHT_NEED_BOUNCE; return 0; } + +device_t +device_isa_register(device_t dev, void *aux) +{ + + /* + * Handle network interfaces here, the attachment information is + * not available driver-independently later. + * + * For disks, there is nothing useful available at attach time. + */ + if (device_class(dev) == DV_IFNET) { + struct btinfo_netif *bin = lookup_bootinfo(BTINFO_NETIF); + if (bin == NULL) + return NULL; + + /* + * We don't check the driver name against the device name + * passed by the boot ROM. The ROM should stay usable if + * the driver becomes obsolete. The physical attachment + * information (checked below) must be sufficient to + * idenfity the device. + */ + if (bin->bus == BI_BUS_ISA && + device_is_a(device_parent(dev), "isa")) { + struct isa_attach_args *iaa = aux; + + /* Compare IO base address */ + /* XXXJRT What about multiple IO addrs? */ + if (iaa->ia_nio > 0 && + bin->addr.iobase == iaa->ia_io[0].ir_addr) + return dev; + } + } +#if NACPICA > 0 +#if notyet + if (device_is_a(dev, "isa") && acpi_active) { + if (!(AcpiGbl_FADT.BootFlags & ACPI_FADT_LEGACY_DEVICES)) + prop_dictionary_set_bool(device_properties(dev), + "no-legacy-devices", true); + } +#endif +#endif /* NACPICA > 0 */ + return NULL; +} Index: src/sys/arch/x86/pci/pci_machdep.c diff -u src/sys/arch/x86/pci/pci_machdep.c:1.51 src/sys/arch/x86/pci/pci_machdep.c:1.52 --- src/sys/arch/x86/pci/pci_machdep.c:1.51 Tue Sep 13 17:58:42 2011 +++ src/sys/arch/x86/pci/pci_machdep.c Tue Oct 18 23:43:36 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_machdep.c,v 1.51 2011/09/13 17:58:42 dyoung Exp $ */ +/* $NetBSD: pci_machdep.c,v 1.52 2011/10/18 23:43:36 dyoung Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -73,7 +73,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.51 2011/09/13 17:58:42 dyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.52 2011/10/18 23:43:36 dyoung Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -98,10 +98,34 @@ __KERNEL_RCSID(0, "$NetBSD: pci_machdep. #include <dev/pci/pcireg.h> #include <dev/pci/pccbbreg.h> #include <dev/pci/pcidevs.h> +#include <dev/pci/genfb_pcivar.h> + +#include <dev/wsfb/genfbvar.h> +#include <arch/x86/include/genfb_machdep.h> +#include <dev/ic/vgareg.h> #include "acpica.h" -#include "opt_mpbios.h" +#include "genfb.h" +#include "isa.h" #include "opt_acpi.h" +#include "opt_ddb.h" +#include "opt_mpbios.h" +#include "opt_vga.h" +#include "pci.h" +#include "wsdisplay.h" + +#ifdef DDB +#include <machine/db_machdep.h> +#include <ddb/db_sym.h> +#include <ddb/db_extern.h> +#endif + +#ifdef VGA_POST +#include <x86/vga_post.h> +#endif + +#include <machine/autoconf.h> +#include <machine/bootinfo.h> #ifdef MPBIOS #include <machine/mpbiosvar.h> @@ -221,6 +245,18 @@ static struct pci_conf_lock cl0 = { static struct pci_conf_lock * const cl = &cl0; +#if NGENFB > 0 && NACPICA > 0 && defined(VGA_POST) +extern int acpi_md_vbios_reset; +extern int acpi_md_vesa_modenum; +#endif + +static struct genfb_colormap_callback gfb_cb; +static struct genfb_pmf_callback pmf_cb; +static struct genfb_mode_callback mode_cb; +#ifdef VGA_POST +static struct vga_post *vga_posth = NULL; +#endif + static void pci_conf_lock(struct pci_conf_lock *ocl, uint32_t sel) { @@ -801,3 +837,201 @@ einval: kmem_free(pc, sizeof(struct pci_chipset_tag)); return EINVAL; } + +static void +x86_genfb_set_mapreg(void *opaque, int index, int r, int g, int b) +{ + outb(0x3c0 + VGA_DAC_ADDRW, index); + outb(0x3c0 + VGA_DAC_PALETTE, (uint8_t)r >> 2); + outb(0x3c0 + VGA_DAC_PALETTE, (uint8_t)g >> 2); + outb(0x3c0 + VGA_DAC_PALETTE, (uint8_t)b >> 2); +} + +static bool +x86_genfb_setmode(struct genfb_softc *sc, int newmode) +{ +#if NGENFB > 0 + static int curmode = WSDISPLAYIO_MODE_EMUL; + + switch (newmode) { + case WSDISPLAYIO_MODE_EMUL: + x86_genfb_mtrr_init(sc->sc_fboffset, + sc->sc_height * sc->sc_stride); +#if NACPICA > 0 && defined(VGA_POST) + if (curmode != newmode) { + if (vga_posth != NULL && acpi_md_vesa_modenum != 0) { + vga_post_set_vbe(vga_posth, + acpi_md_vesa_modenum); + } + } +#endif + break; + } + + curmode = newmode; +#endif + return true; +} + +static bool +x86_genfb_suspend(device_t dev, const pmf_qual_t *qual) +{ + return true; +} + +static bool +x86_genfb_resume(device_t dev, const pmf_qual_t *qual) +{ +#if NGENFB > 0 + struct pci_genfb_softc *psc = device_private(dev); + +#if NACPICA > 0 && defined(VGA_POST) + if (vga_posth != NULL && acpi_md_vbios_reset == 2) { + vga_post_call(vga_posth); + if (acpi_md_vesa_modenum != 0) + vga_post_set_vbe(vga_posth, acpi_md_vesa_modenum); + } +#endif + genfb_restore_palette(&psc->sc_gen); +#endif + + return true; +} + +device_t +device_pci_register(device_t dev, void *aux) +{ + static bool found_console = false; + + device_pci_props_register(dev, aux); + + /* + * Handle network interfaces here, the attachment information is + * not available driver-independently later. + * + * For disks, there is nothing useful available at attach time. + */ + if (device_class(dev) == DV_IFNET) { + struct btinfo_netif *bin = lookup_bootinfo(BTINFO_NETIF); + if (bin == NULL) + return NULL; + + /* + * We don't check the driver name against the device name + * passed by the boot ROM. The ROM should stay usable if + * the driver becomes obsolete. The physical attachment + * information (checked below) must be sufficient to + * idenfity the device. + */ + if (bin->bus == BI_BUS_PCI && + device_is_a(device_parent(dev), "pci")) { + struct pci_attach_args *paa = aux; + int b, d, f; + + /* + * Calculate BIOS representation of: + * + * <bus,device,function> + * + * and compare. + */ + pci_decompose_tag(paa->pa_pc, paa->pa_tag, &b, &d, &f); + if (bin->addr.tag == ((b << 8) | (d << 3) | f)) + return dev; + } + } + if (device_parent(dev) && device_is_a(device_parent(dev), "pci") && + found_console == false) { + struct btinfo_framebuffer *fbinfo; + struct pci_attach_args *pa = aux; + prop_dictionary_t dict; + + if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY) { +#if NWSDISPLAY > 0 && NGENFB > 0 + extern struct vcons_screen x86_genfb_console_screen; + struct rasops_info *ri; + + ri = &x86_genfb_console_screen.scr_ri; +#endif + + fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER); + dict = device_properties(dev); + /* + * framebuffer drivers other than genfb can work + * without the address property + */ + if (fbinfo != NULL) { + if (fbinfo->physaddr != 0) { + prop_dictionary_set_uint32(dict, "width", + fbinfo->width); + prop_dictionary_set_uint32(dict, "height", + fbinfo->height); + prop_dictionary_set_uint8(dict, "depth", + fbinfo->depth); + prop_dictionary_set_uint16(dict, "linebytes", + fbinfo->stride); + + prop_dictionary_set_uint64(dict, "address", + fbinfo->physaddr); +#if NWSDISPLAY > 0 && NGENFB > 0 + if (ri->ri_bits != NULL) { + prop_dictionary_set_uint64(dict, + "virtual_address", + (vaddr_t)ri->ri_bits); + } +#endif + } +#if notyet + prop_dictionary_set_bool(dict, "splash", + fbinfo->flags & BI_FB_SPLASH ? + true : false); +#endif + if (fbinfo->depth == 8) { + gfb_cb.gcc_cookie = NULL; + gfb_cb.gcc_set_mapreg = + x86_genfb_set_mapreg; + prop_dictionary_set_uint64(dict, + "cmap_callback", + (uint64_t)(uintptr_t)&gfb_cb); + } + if (fbinfo->physaddr != 0) { + mode_cb.gmc_setmode = x86_genfb_setmode; + prop_dictionary_set_uint64(dict, + "mode_callback", + (uint64_t)(uintptr_t)&mode_cb); + } + +#if NWSDISPLAY > 0 && NGENFB > 0 + if (device_is_a(dev, "genfb")) { + x86_genfb_set_console_dev(dev); +#ifdef DDB + db_trap_callback = + x86_genfb_ddb_trap_callback; +#endif + } +#endif + } + prop_dictionary_set_bool(dict, "is_console", true); + prop_dictionary_set_bool(dict, "clear-screen", false); +#if NWSDISPLAY > 0 && NGENFB > 0 + prop_dictionary_set_uint16(dict, "cursor-row", + x86_genfb_console_screen.scr_ri.ri_crow); +#endif +#if notyet + prop_dictionary_set_bool(dict, "splash", + fbinfo->flags & BI_FB_SPLASH ? true : false); +#endif + pmf_cb.gpc_suspend = x86_genfb_suspend; + pmf_cb.gpc_resume = x86_genfb_resume; + prop_dictionary_set_uint64(dict, + "pmf_callback", (uint64_t)(uintptr_t)&pmf_cb); +#ifdef VGA_POST + vga_posth = vga_post_init(pa->pa_bus, pa->pa_device, + pa->pa_function); +#endif + found_console = true; + return NULL; + } + } + return NULL; +} Index: src/sys/arch/x86/x86/x86_autoconf.c diff -u src/sys/arch/x86/x86/x86_autoconf.c:1.61 src/sys/arch/x86/x86/x86_autoconf.c:1.62 --- src/sys/arch/x86/x86/x86_autoconf.c:1.61 Mon Sep 19 10:03:32 2011 +++ src/sys/arch/x86/x86/x86_autoconf.c Tue Oct 18 23:43:36 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_autoconf.c,v 1.61 2011/09/19 10:03:32 gsutre Exp $ */ +/* $NetBSD: x86_autoconf.c,v 1.62 2011/10/18 23:43:36 dyoung Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.61 2011/09/19 10:03:32 gsutre Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.62 2011/10/18 23:43:36 dyoung Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -50,119 +50,20 @@ __KERNEL_RCSID(0, "$NetBSD: x86_autoconf #include <sys/md5.h> #include <sys/kauth.h> +#include <machine/autoconf.h> #include <machine/bootinfo.h> #include <machine/pio.h> #include "acpica.h" -#include "pci.h" -#include "isa.h" -#include "genfb.h" #include "wsdisplay.h" -#include "opt_vga.h" -#include "opt_ddb.h" - -#ifdef DDB -#include <machine/db_machdep.h> -#include <ddb/db_sym.h> -#include <ddb/db_extern.h> -#endif #if NACPICA > 0 #include <dev/acpi/acpivar.h> #endif -#ifdef VGA_POST -#include <x86/vga_post.h> -#endif -#include <dev/isa/isavar.h> -#if NPCI > 0 -#include <dev/pci/pcivar.h> -#endif -#include <dev/wsfb/genfbvar.h> -#include <arch/x86/include/genfb_machdep.h> -#if NPCI > 0 -#include <dev/pci/genfb_pcivar.h> -#endif -#include <dev/ic/vgareg.h> - -#if NPCI > 0 -static struct genfb_colormap_callback gfb_cb; -static struct genfb_pmf_callback pmf_cb; -static struct genfb_mode_callback mode_cb; -#ifdef VGA_POST -static struct vga_post *vga_posth = NULL; -#endif -#endif -#if NGENFB > 0 && NACPICA > 0 && defined(VGA_POST) -extern int acpi_md_vbios_reset; -extern int acpi_md_vesa_modenum; -#endif - struct disklist *x86_alldisks; int x86_ndisks; -#if NPCI > 0 -static void -x86_genfb_set_mapreg(void *opaque, int index, int r, int g, int b) -{ - outb(0x3c0 + VGA_DAC_ADDRW, index); - outb(0x3c0 + VGA_DAC_PALETTE, (uint8_t)r >> 2); - outb(0x3c0 + VGA_DAC_PALETTE, (uint8_t)g >> 2); - outb(0x3c0 + VGA_DAC_PALETTE, (uint8_t)b >> 2); -} - -static bool -x86_genfb_setmode(struct genfb_softc *sc, int newmode) -{ -#if NGENFB > 0 - static int curmode = WSDISPLAYIO_MODE_EMUL; - - switch (newmode) { - case WSDISPLAYIO_MODE_EMUL: - x86_genfb_mtrr_init(sc->sc_fboffset, - sc->sc_height * sc->sc_stride); -#if NACPICA > 0 && defined(VGA_POST) - if (curmode != newmode) { - if (vga_posth != NULL && acpi_md_vesa_modenum != 0) { - vga_post_set_vbe(vga_posth, - acpi_md_vesa_modenum); - } - } -#endif - break; - } - - curmode = newmode; -#endif - return true; -} - -static bool -x86_genfb_suspend(device_t dev, const pmf_qual_t *qual) -{ - return true; -} - -static bool -x86_genfb_resume(device_t dev, const pmf_qual_t *qual) -{ -#if NGENFB > 0 - struct pci_genfb_softc *psc = device_private(dev); - -#if NACPICA > 0 && defined(VGA_POST) - if (vga_posth != NULL && acpi_md_vbios_reset == 2) { - vga_post_call(vga_posth); - if (acpi_md_vesa_modenum != 0) - vga_post_set_vbe(vga_posth, acpi_md_vesa_modenum); - } -#endif - genfb_restore_palette(&psc->sc_gen); -#endif - - return true; -} -#endif - static void handle_wedges(device_t dv, int par) { @@ -606,169 +507,18 @@ cpu_rootconf(void) void device_register(device_t dev, void *aux) { -#if NPCI > 0 - static bool found_console = false; -#endif - - /* - * Handle network interfaces here, the attachment information is - * not available driver-independently later. - * - * For disks, there is nothing useful available at attach time. - */ - if (device_class(dev) == DV_IFNET) { - struct btinfo_netif *bin = lookup_bootinfo(BTINFO_NETIF); - if (bin == NULL) - return; - - /* - * We don't check the driver name against the device name - * passed by the boot ROM. The ROM should stay usable if - * the driver becomes obsolete. The physical attachment - * information (checked below) must be sufficient to - * idenfity the device. - */ - if (bin->bus == BI_BUS_ISA && - device_is_a(device_parent(dev), "isa")) { - struct isa_attach_args *iaa = aux; - - /* Compare IO base address */ - /* XXXJRT What about multiple IO addrs? */ - if (iaa->ia_nio > 0 && - bin->addr.iobase == iaa->ia_io[0].ir_addr) - goto found; - } -#if NPCI > 0 - if (bin->bus == BI_BUS_PCI && - device_is_a(device_parent(dev), "pci")) { - struct pci_attach_args *paa = aux; - int b, d, f; + device_t isaboot, pciboot; - /* - * Calculate BIOS representation of: - * - * <bus,device,function> - * - * and compare. - */ - pci_decompose_tag(paa->pa_pc, paa->pa_tag, &b, &d, &f); - if (bin->addr.tag == ((b << 8) | (d << 3) | f)) - goto found; - } -#endif /* NPCI > 0 */ - } -#if NISA > 0 && NACPICA > 0 -#if notyet - if (device_is_a(dev, "isa") && acpi_active) { - if (!(AcpiGbl_FADT.BootFlags & ACPI_FADT_LEGACY_DEVICES)) - prop_dictionary_set_bool(device_properties(dev), - "no-legacy-devices", true); - } -#endif -#endif /* NISA > 0 && NACPICA > 0 */ -#if NPCI > 0 - if (device_parent(dev) && device_is_a(device_parent(dev), "pci") && - found_console == false) { - struct btinfo_framebuffer *fbinfo; - struct pci_attach_args *pa = aux; - prop_dictionary_t dict; - - if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY) { -#if NWSDISPLAY > 0 && NGENFB > 0 - extern struct vcons_screen x86_genfb_console_screen; - struct rasops_info *ri; - - ri = &x86_genfb_console_screen.scr_ri; -#endif - - fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER); - dict = device_properties(dev); - /* - * framebuffer drivers other than genfb can work - * without the address property - */ - if (fbinfo != NULL) { - if (fbinfo->physaddr != 0) { - prop_dictionary_set_uint32(dict, "width", - fbinfo->width); - prop_dictionary_set_uint32(dict, "height", - fbinfo->height); - prop_dictionary_set_uint8(dict, "depth", - fbinfo->depth); - prop_dictionary_set_uint16(dict, "linebytes", - fbinfo->stride); - - prop_dictionary_set_uint64(dict, "address", - fbinfo->physaddr); -#if NWSDISPLAY > 0 && NGENFB > 0 - if (ri->ri_bits != NULL) { - prop_dictionary_set_uint64(dict, - "virtual_address", - (vaddr_t)ri->ri_bits); - } -#endif - } -#if notyet - prop_dictionary_set_bool(dict, "splash", - fbinfo->flags & BI_FB_SPLASH ? - true : false); -#endif - if (fbinfo->depth == 8) { - gfb_cb.gcc_cookie = NULL; - gfb_cb.gcc_set_mapreg = - x86_genfb_set_mapreg; - prop_dictionary_set_uint64(dict, - "cmap_callback", - (uint64_t)(uintptr_t)&gfb_cb); - } - if (fbinfo->physaddr != 0) { - mode_cb.gmc_setmode = x86_genfb_setmode; - prop_dictionary_set_uint64(dict, - "mode_callback", - (uint64_t)(uintptr_t)&mode_cb); - } + isaboot = device_isa_register(dev, aux); + pciboot = device_pci_register(dev, aux); -#if NWSDISPLAY > 0 && NGENFB > 0 - if (device_is_a(dev, "genfb")) { - x86_genfb_set_console_dev(dev); -#ifdef DDB - db_trap_callback = - x86_genfb_ddb_trap_callback; -#endif - } -#endif - } - prop_dictionary_set_bool(dict, "is_console", true); - prop_dictionary_set_bool(dict, "clear-screen", false); -#if NWSDISPLAY > 0 && NGENFB > 0 - prop_dictionary_set_uint16(dict, "cursor-row", - x86_genfb_console_screen.scr_ri.ri_crow); -#endif -#if notyet - prop_dictionary_set_bool(dict, "splash", - fbinfo->flags & BI_FB_SPLASH ? true : false); -#endif - pmf_cb.gpc_suspend = x86_genfb_suspend; - pmf_cb.gpc_resume = x86_genfb_resume; - prop_dictionary_set_uint64(dict, - "pmf_callback", (uint64_t)(uintptr_t)&pmf_cb); -#ifdef VGA_POST - vga_posth = vga_post_init(pa->pa_bus, pa->pa_device, - pa->pa_function); -#endif - found_console = true; - return; - } - } -#endif - return; + if (isaboot == NULL && pciboot == NULL) + return; - found: - if (booted_device) { + if (booted_device != NULL) { /* XXX should be a panic() */ printf("WARNING: double match for boot device (%s, %s)\n", device_xname(booted_device), device_xname(dev)); - return; - } - booted_device = dev; + } else + booted_device = (isaboot != NULL) ? isaboot : pciboot; }