From owner-svn-src-all@FreeBSD.ORG Wed May 14 14:08:48 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 336895E0; Wed, 14 May 2014 14:08:48 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1DE5B237A; Wed, 14 May 2014 14:08:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4EE8mAl056070; Wed, 14 May 2014 14:08:48 GMT (envelope-from ian@svn.freebsd.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4EE8joX056047; Wed, 14 May 2014 14:08:45 GMT (envelope-from ian@svn.freebsd.org) Message-Id: <201405141408.s4EE8joX056047@svn.freebsd.org> From: Ian Lepore Date: Wed, 14 May 2014 14:08:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r266019 - in stable/10/sys/powerpc: aim booke ofw powermac pseries X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 May 2014 14:08:48 -0000 Author: ian Date: Wed May 14 14:08:45 2014 New Revision: 266019 URL: http://svnweb.freebsd.org/changeset/base/266019 Log: MFC r258268, r258271, r258272, r258274, r258275, r258427, r258694, r258696, r258697, r258757 Do not assume a value for #address-cells when parsing the OF translations map. This allows the kernel to get farther with OpenBIOS on 64-bit CPUs. Actually look up #address-cells instead of assuming it is correlated with the Uninorth version number. #interrupt-cells belongs to the iparent, not the device parent. Add a sysctl to allow disabling resetting the OF syscons. For PCI<->PCI bridges, #address-cells may be 3. Make RTAS calls, which call setfault() to recover from machine checks, preserve any existing fault buffer. badaddr() is used only in the grackle PCI driver, so move its definition there. Clean up a spurious setfault() declaration as well. This [phyp_console] driver doesn't need the /options node, so don't check for it. Use the Open Firmware-based CPU frequency determination as a generic fallback if we can't measure CPU frequency. This is also useful on a variety of embedded systems using FDT. Modified: stable/10/sys/powerpc/aim/machdep.c stable/10/sys/powerpc/aim/mmu_oea64.c stable/10/sys/powerpc/aim/trap.c stable/10/sys/powerpc/booke/trap.c stable/10/sys/powerpc/ofw/ofw_syscons.c stable/10/sys/powerpc/powermac/grackle.c stable/10/sys/powerpc/powermac/macio.c stable/10/sys/powerpc/powermac/uninorth.c stable/10/sys/powerpc/powermac/uninorthpci.c stable/10/sys/powerpc/powermac/uninorthvar.h stable/10/sys/powerpc/pseries/phyp_console.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/powerpc/aim/machdep.c ============================================================================== --- stable/10/sys/powerpc/aim/machdep.c Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/aim/machdep.c Wed May 14 14:08:45 2014 (r266019) @@ -159,8 +159,6 @@ SYSCTL_INT(_machdep, CPU_CACHELINE, cach uintptr_t powerpc_init(vm_offset_t, vm_offset_t, vm_offset_t, void *); -int setfault(faultbuf); /* defined in locore.S */ - long Maxmem = 0; long realmem = 0; Modified: stable/10/sys/powerpc/aim/mmu_oea64.c ============================================================================== --- stable/10/sys/powerpc/aim/mmu_oea64.c Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/aim/mmu_oea64.c Wed May 14 14:08:45 2014 (r266019) @@ -180,8 +180,7 @@ uintptr_t moea64_get_unique_vsid(void); struct ofw_map { cell_t om_va; cell_t om_len; - cell_t om_pa_hi; - cell_t om_pa_lo; + uint64_t om_pa; cell_t om_mode; }; @@ -471,13 +470,9 @@ om_cmp(const void *a, const void *b) mapa = a; mapb = b; - if (mapa->om_pa_hi < mapb->om_pa_hi) + if (mapa->om_pa < mapb->om_pa) return (-1); - else if (mapa->om_pa_hi > mapb->om_pa_hi) - return (1); - else if (mapa->om_pa_lo < mapb->om_pa_lo) - return (-1); - else if (mapa->om_pa_lo > mapb->om_pa_lo) + else if (mapa->om_pa > mapb->om_pa) return (1); else return (0); @@ -486,26 +481,41 @@ om_cmp(const void *a, const void *b) static void moea64_add_ofw_mappings(mmu_t mmup, phandle_t mmu, size_t sz) { - struct ofw_map translations[sz/sizeof(struct ofw_map)]; + struct ofw_map translations[sz/(4*sizeof(cell_t))]; /*>= 4 cells per */ + pcell_t acells, trans_cells[sz/sizeof(cell_t)]; register_t msr; vm_offset_t off; vm_paddr_t pa_base; - int i; + int i, j; bzero(translations, sz); - if (OF_getprop(mmu, "translations", translations, sz) == -1) + OF_getprop(OF_finddevice("/"), "#address-cells", &acells, + sizeof(acells)); + if (OF_getprop(mmu, "translations", trans_cells, sz) == -1) panic("moea64_bootstrap: can't get ofw translations"); CTR0(KTR_PMAP, "moea64_add_ofw_mappings: translations"); - sz /= sizeof(*translations); + sz /= sizeof(cell_t); + for (i = 0, j = 0; i < sz; j++) { + translations[j].om_va = trans_cells[i++]; + translations[j].om_len = trans_cells[i++]; + translations[j].om_pa = trans_cells[i++]; + if (acells == 2) { + translations[j].om_pa <<= 32; + translations[j].om_pa |= trans_cells[i++]; + } + translations[j].om_mode = trans_cells[i++]; + } + KASSERT(i == sz, ("Translations map has incorrect cell count (%d/%zd)", + i, sz)); + + sz = j; qsort(translations, sz, sizeof (*translations), om_cmp); for (i = 0; i < sz; i++) { - pa_base = translations[i].om_pa_lo; - #ifdef __powerpc64__ - pa_base += (vm_offset_t)translations[i].om_pa_hi << 32; - #else - if (translations[i].om_pa_hi) + pa_base = translations[i].om_pa; + #ifndef __powerpc64__ + if ((translations[i].om_pa >> 32) != 0) panic("OFW translations above 32-bit boundary!"); #endif Modified: stable/10/sys/powerpc/aim/trap.c ============================================================================== --- stable/10/sys/powerpc/aim/trap.c Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/aim/trap.c Wed May 14 14:08:45 2014 (r266019) @@ -89,12 +89,6 @@ static int handle_user_slb_spill(pmap_t extern int n_slbs; #endif -int setfault(faultbuf); /* defined in locore.S */ - -/* Why are these not defined in a header? */ -int badaddr(void *, size_t); -int badaddr_read(void *, size_t, int *); - struct powerpc_exception { u_int vector; char *name; @@ -695,59 +689,6 @@ trap_pfault(struct trapframe *frame, int return (SIGSEGV); } -int -badaddr(void *addr, size_t size) -{ - return (badaddr_read(addr, size, NULL)); -} - -int -badaddr_read(void *addr, size_t size, int *rptr) -{ - struct thread *td; - faultbuf env; - int x; - - /* Get rid of any stale machine checks that have been waiting. */ - __asm __volatile ("sync; isync"); - - td = curthread; - - if (setfault(env)) { - td->td_pcb->pcb_onfault = 0; - __asm __volatile ("sync"); - return 1; - } - - __asm __volatile ("sync"); - - switch (size) { - case 1: - x = *(volatile int8_t *)addr; - break; - case 2: - x = *(volatile int16_t *)addr; - break; - case 4: - x = *(volatile int32_t *)addr; - break; - default: - panic("badaddr: invalid size (%zd)", size); - } - - /* Make sure we took the machine check, if we caused one. */ - __asm __volatile ("sync; isync"); - - td->td_pcb->pcb_onfault = 0; - __asm __volatile ("sync"); /* To be sure. */ - - /* Use the value to avoid reorder. */ - if (rptr) - *rptr = x; - - return (0); -} - /* * For now, this only deals with the particular unaligned access case * that gcc tends to generate. Eventually it should handle all of the Modified: stable/10/sys/powerpc/booke/trap.c ============================================================================== --- stable/10/sys/powerpc/booke/trap.c Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/booke/trap.c Wed May 14 14:08:45 2014 (r266019) @@ -87,12 +87,6 @@ static int fix_unaligned(struct thread * static int handle_onfault(struct trapframe *frame); static void syscall(struct trapframe *frame); -int setfault(faultbuf); /* defined in locore.S */ - -/* Why are these not defined in a header? */ -int badaddr(void *, size_t); -int badaddr_read(void *, size_t, int *); - struct powerpc_exception { u_int vector; char *name; @@ -461,60 +455,6 @@ trap_pfault(struct trapframe *frame, int return ((rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV); } -int -badaddr(void *addr, size_t size) -{ - - return (badaddr_read(addr, size, NULL)); -} - -int -badaddr_read(void *addr, size_t size, int *rptr) -{ - struct thread *td; - faultbuf env; - int x; - - /* Get rid of any stale machine checks that have been waiting. */ - __asm __volatile ("sync; isync"); - - td = curthread; - - if (setfault(env)) { - td->td_pcb->pcb_onfault = 0; - __asm __volatile ("sync"); - return (1); - } - - __asm __volatile ("sync"); - - switch (size) { - case 1: - x = *(volatile int8_t *)addr; - break; - case 2: - x = *(volatile int16_t *)addr; - break; - case 4: - x = *(volatile int32_t *)addr; - break; - default: - panic("badaddr: invalid size (%d)", size); - } - - /* Make sure we took the machine check, if we caused one. */ - __asm __volatile ("sync; isync"); - - td->td_pcb->pcb_onfault = 0; - __asm __volatile ("sync"); /* To be sure. */ - - /* Use the value to avoid reorder. */ - if (rptr) - *rptr = x; - - return (0); -} - /* * For now, this only deals with the particular unaligned access case * that gcc tends to generate. Eventually it should handle all of the Modified: stable/10/sys/powerpc/ofw/ofw_syscons.c ============================================================================== --- stable/10/sys/powerpc/ofw/ofw_syscons.c Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/ofw/ofw_syscons.c Wed May 14 14:08:45 2014 (r266019) @@ -57,9 +57,12 @@ __FBSDID("$FreeBSD$"); #include static int ofwfb_ignore_mmap_checks = 1; +static int ofwfb_reset_on_switch = 1; static SYSCTL_NODE(_hw, OID_AUTO, ofwfb, CTLFLAG_RD, 0, "ofwfb"); SYSCTL_INT(_hw_ofwfb, OID_AUTO, relax_mmap, CTLFLAG_RW, &ofwfb_ignore_mmap_checks, 0, "relaxed mmap bounds checking"); +SYSCTL_INT(_hw_ofwfb, OID_AUTO, reset_on_mode_switch, CTLFLAG_RW, + &ofwfb_reset_on_switch, 0, "reset the framebuffer driver on mode switch"); extern u_char dflt_font_16[]; extern u_char dflt_font_14[]; @@ -447,26 +450,28 @@ ofwfb_set_mode(video_adapter_t *adp, int sc = (struct ofwfb_softc *)adp; - /* - * Open the display device, which will initialize it. - */ - - memset(name, 0, sizeof(name)); - OF_package_to_path(sc->sc_node, name, sizeof(name)); - ih = OF_open(name); - - if (sc->sc_depth == 8) { + if (ofwfb_reset_on_switch) { /* - * Install the ISO6429 colormap - older OFW systems - * don't do this by default + * Open the display device, which will initialize it. */ - for (i = 0; i < 16; i++) { - OF_call_method("color!", ih, 4, 1, - ofwfb_cmap[i].red, - ofwfb_cmap[i].green, - ofwfb_cmap[i].blue, - i, - &retval); + + memset(name, 0, sizeof(name)); + OF_package_to_path(sc->sc_node, name, sizeof(name)); + ih = OF_open(name); + + if (sc->sc_depth == 8) { + /* + * Install the ISO6429 colormap - older OFW systems + * don't do this by default + */ + for (i = 0; i < 16; i++) { + OF_call_method("color!", ih, 4, 1, + ofwfb_cmap[i].red, + ofwfb_cmap[i].green, + ofwfb_cmap[i].blue, + i, + &retval); + } } } Modified: stable/10/sys/powerpc/powermac/grackle.c ============================================================================== --- stable/10/sys/powerpc/powermac/grackle.c Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/powermac/grackle.c Wed May 14 14:08:45 2014 (r266019) @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -59,8 +60,6 @@ __FBSDID("$FreeBSD$"); #include "pcib_if.h" -int badaddr(void *, size_t); /* XXX */ - /* * Device interface. */ @@ -81,6 +80,9 @@ static void grackle_write_config(device static int grackle_enable_config(struct grackle_softc *, u_int, u_int, u_int, u_int); static void grackle_disable_config(struct grackle_softc *); +static int badaddr(void *, size_t); + +int setfault(faultbuf); /* defined in locore.S */ /* * Driver methods. @@ -238,6 +240,50 @@ grackle_disable_config(struct grackle_so out32rb(sc->sc_addr, 0); } +static int +badaddr(void *addr, size_t size) +{ + struct thread *td; + faultbuf env, *oldfaultbuf; + int x; + + /* Get rid of any stale machine checks that have been waiting. */ + __asm __volatile ("sync; isync"); + + td = curthread; + + oldfaultbuf = td->td_pcb->pcb_onfault; + if (setfault(env)) { + td->td_pcb->pcb_onfault = oldfaultbuf; + __asm __volatile ("sync"); + return 1; + } + + __asm __volatile ("sync"); + + switch (size) { + case 1: + x = *(volatile int8_t *)addr; + break; + case 2: + x = *(volatile int16_t *)addr; + break; + case 4: + x = *(volatile int32_t *)addr; + break; + default: + panic("badaddr: invalid size (%zd)", size); + } + + /* Make sure we took the machine check, if we caused one. */ + __asm __volatile ("sync; isync"); + + td->td_pcb->pcb_onfault = oldfaultbuf; + __asm __volatile ("sync"); /* To be sure. */ + + return (0); +} + /* * Driver to swallow Grackle host bridges from the PCI bus side. */ Modified: stable/10/sys/powerpc/powermac/macio.c ============================================================================== --- stable/10/sys/powerpc/powermac/macio.c Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/powermac/macio.c Wed May 14 14:08:45 2014 (r266019) @@ -201,10 +201,6 @@ macio_add_intr(phandle_t devnode, struct return; } - if (OF_searchprop(devnode, "#interrupt-cells", &icells, sizeof(icells)) - <= 0) - icells = 1; - nintr = OF_getprop_alloc(devnode, "interrupts", sizeof(*intr), (void **)&intr); if (nintr == -1) { @@ -221,6 +217,10 @@ macio_add_intr(phandle_t devnode, struct <= 0) panic("Interrupt but no interrupt parent!\n"); + if (OF_getprop(OF_xref_phandle(iparent), "#interrupt-cells", &icells, + sizeof(icells)) <= 0) + icells = 1; + for (i = 0; i < nintr; i+=icells) { u_int irq = MAP_IRQ(iparent, intr[i]); Modified: stable/10/sys/powerpc/powermac/uninorth.c ============================================================================== --- stable/10/sys/powerpc/powermac/uninorth.c Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/powermac/uninorth.c Wed May 14 14:08:45 2014 (r266019) @@ -270,6 +270,7 @@ unin_chip_attach(device_t dev) phandle_t child; phandle_t iparent; device_t cdev; + cell_t acells, scells; char compat[32]; char name[32]; u_int irq, reg[3]; @@ -281,12 +282,21 @@ unin_chip_attach(device_t dev) if (OF_getprop(root, "reg", reg, sizeof(reg)) < 8) return (ENXIO); - if (strcmp(ofw_bus_get_name(dev), "u3") == 0 - || strcmp(ofw_bus_get_name(dev), "u4") == 0) - i = 1; /* #address-cells lies */ - - sc->sc_physaddr = reg[i]; - sc->sc_size = reg[i+1]; + acells = scells = 1; + OF_getprop(OF_parent(root), "#address-cells", &acells, sizeof(acells)); + OF_getprop(OF_parent(root), "#size-cells", &scells, sizeof(scells)); + + i = 0; + sc->sc_physaddr = reg[i++]; + if (acells == 2) { + sc->sc_physaddr <<= 32; + sc->sc_physaddr |= reg[i++]; + } + sc->sc_size = reg[i++]; + if (scells == 2) { + sc->sc_size <<= 32; + sc->sc_size |= reg[i++]; + } sc->sc_mem_rman.rm_type = RMAN_ARRAY; sc->sc_mem_rman.rm_descr = "UniNorth Device Memory"; Modified: stable/10/sys/powerpc/powermac/uninorthpci.c ============================================================================== --- stable/10/sys/powerpc/powermac/uninorthpci.c Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/powermac/uninorthpci.c Wed May 14 14:08:45 2014 (r266019) @@ -134,7 +134,9 @@ uninorth_attach(device_t dev) struct uninorth_softc *sc; const char *compatible; phandle_t node; - u_int32_t reg[3]; + uint32_t reg[3]; + uint64_t regbase; + cell_t acells; node = ofw_bus_get_node(dev); sc = device_get_softc(dev); @@ -149,14 +151,18 @@ uninorth_attach(device_t dev) if (strcmp(compatible, "u4-pcie") == 0) sc->sc_ver = 4; - if (sc->sc_ver >= 3) { - sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[1] + 0x800000, PAGE_SIZE); - sc->sc_data = (vm_offset_t)pmap_mapdev(reg[1] + 0xc00000, PAGE_SIZE); - } else { - sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[0] + 0x800000, PAGE_SIZE); - sc->sc_data = (vm_offset_t)pmap_mapdev(reg[0] + 0xc00000, PAGE_SIZE); + acells = 1; + OF_getprop(OF_parent(node), "#address-cells", &acells, sizeof(acells)); + + regbase = reg[0]; + if (acells == 2) { + regbase <<= 32; + regbase |= reg[1]; } + sc->sc_addr = (vm_offset_t)pmap_mapdev(regbase + 0x800000, PAGE_SIZE); + sc->sc_data = (vm_offset_t)pmap_mapdev(regbase + 0xc00000, PAGE_SIZE); + return (ofw_pci_attach(dev)); } Modified: stable/10/sys/powerpc/powermac/uninorthvar.h ============================================================================== --- stable/10/sys/powerpc/powermac/uninorthvar.h Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/powermac/uninorthvar.h Wed May 14 14:08:45 2014 (r266019) @@ -40,9 +40,9 @@ struct uninorth_softc { }; struct unin_chip_softc { - u_int32_t sc_physaddr; + uint64_t sc_physaddr; + uint64_t sc_size; vm_offset_t sc_addr; - u_int32_t sc_size; struct rman sc_mem_rman; int sc_version; }; Modified: stable/10/sys/powerpc/pseries/phyp_console.c ============================================================================== --- stable/10/sys/powerpc/pseries/phyp_console.c Wed May 14 13:55:14 2014 (r266018) +++ stable/10/sys/powerpc/pseries/phyp_console.c Wed May 14 14:08:45 2014 (r266019) @@ -192,11 +192,9 @@ uart_phyp_cnprobe(struct consdev *cp) { char buf[64]; ihandle_t stdout; - phandle_t input, opts, chosen; + phandle_t input, chosen; static struct uart_phyp_softc sc; - if ((opts = OF_finddevice("/options")) == -1) - goto fail; if ((chosen = OF_finddevice("/chosen")) == -1) goto fail;