From owner-svn-src-user@FreeBSD.ORG Tue Oct 28 06:11:32 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9C072106566C; Tue, 28 Oct 2008 06:11:32 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 895BA8FC16; Tue, 28 Oct 2008 06:11:32 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9S6BWwt084403; Tue, 28 Oct 2008 06:11:32 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9S6BWqd084388; Tue, 28 Oct 2008 06:11:32 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810280611.m9S6BWqd084388@svn.freebsd.org> From: Kip Macy Date: Tue, 28 Oct 2008 06:11:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184390 - in user/kmacy/HEAD_ECMP/sys/powerpc: aim booke conf include mpc85xx powermac X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Oct 2008 06:11:32 -0000 Author: kmacy Date: Tue Oct 28 06:11:31 2008 New Revision: 184390 URL: http://svn.freebsd.org/changeset/base/184390 Log: IF_HEAD part1 184043:184389 Added: user/kmacy/HEAD_ECMP/sys/powerpc/mpc85xx/lbc.c user/kmacy/HEAD_ECMP/sys/powerpc/mpc85xx/lbc.h user/kmacy/HEAD_ECMP/sys/powerpc/powermac/cuda.c user/kmacy/HEAD_ECMP/sys/powerpc/powermac/cudavar.h user/kmacy/HEAD_ECMP/sys/powerpc/powermac/macgpio.c user/kmacy/HEAD_ECMP/sys/powerpc/powermac/macgpiovar.h user/kmacy/HEAD_ECMP/sys/powerpc/powermac/pmu.c user/kmacy/HEAD_ECMP/sys/powerpc/powermac/pmuvar.h user/kmacy/HEAD_ECMP/sys/powerpc/powermac/viareg.h Modified: user/kmacy/HEAD_ECMP/sys/powerpc/aim/locore.S user/kmacy/HEAD_ECMP/sys/powerpc/booke/locore.S user/kmacy/HEAD_ECMP/sys/powerpc/booke/pmap.c user/kmacy/HEAD_ECMP/sys/powerpc/booke/trap.c user/kmacy/HEAD_ECMP/sys/powerpc/conf/GENERIC user/kmacy/HEAD_ECMP/sys/powerpc/conf/MPC85XX user/kmacy/HEAD_ECMP/sys/powerpc/include/cpu.h user/kmacy/HEAD_ECMP/sys/powerpc/include/profile.h user/kmacy/HEAD_ECMP/sys/powerpc/mpc85xx/ocpbus.c user/kmacy/HEAD_ECMP/sys/powerpc/powermac/ata_kauai.c user/kmacy/HEAD_ECMP/sys/powerpc/powermac/dbdma.c user/kmacy/HEAD_ECMP/sys/powerpc/powermac/dbdmavar.h user/kmacy/HEAD_ECMP/sys/powerpc/powermac/macio.c Modified: user/kmacy/HEAD_ECMP/sys/powerpc/aim/locore.S ============================================================================== --- user/kmacy/HEAD_ECMP/sys/powerpc/aim/locore.S Tue Oct 28 06:00:13 2008 (r184389) +++ user/kmacy/HEAD_ECMP/sys/powerpc/aim/locore.S Tue Oct 28 06:11:31 2008 (r184390) @@ -111,11 +111,14 @@ openfirmware_entry: srsave: .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .text + .globl btext +btext: + /* * This symbol is here for the benefit of kvm_mkdb, and is supposed to * mark the start of kernel text. */ - .text .globl kernel_text kernel_text: Modified: user/kmacy/HEAD_ECMP/sys/powerpc/booke/locore.S ============================================================================== --- user/kmacy/HEAD_ECMP/sys/powerpc/booke/locore.S Tue Oct 28 06:00:13 2008 (r184389) +++ user/kmacy/HEAD_ECMP/sys/powerpc/booke/locore.S Tue Oct 28 06:11:31 2008 (r184390) @@ -41,11 +41,14 @@ #define TMPSTACKSZ 16384 + .text + .globl btext +btext: + /* * This symbol is here for the benefit of kvm_mkdb, and is supposed to * mark the start of kernel text. */ - .text .globl kernel_text kernel_text: Modified: user/kmacy/HEAD_ECMP/sys/powerpc/booke/pmap.c ============================================================================== --- user/kmacy/HEAD_ECMP/sys/powerpc/booke/pmap.c Tue Oct 28 06:00:13 2008 (r184389) +++ user/kmacy/HEAD_ECMP/sys/powerpc/booke/pmap.c Tue Oct 28 06:11:31 2008 (r184390) @@ -2296,14 +2296,25 @@ mmu_booke_dev_direct_mapped(mmu_t mmu, v static void * mmu_booke_mapdev(mmu_t mmu, vm_offset_t pa, vm_size_t size) { + void *res; uintptr_t va; + vm_size_t sz; va = (pa >= 0x80000000) ? pa : (0xe2000000 + pa); - if (bootverbose) - printf("Wiring VA=%x to PA=%x (size=%x), using TLB1[%d]\n", - va, pa, size, tlb1_idx); - tlb1_set_entry(va, pa, size, _TLB_ENTRY_IO); - return ((void *)va); + res = (void *)va; + + do { + sz = 1 << (ilog2(size) & ~1); + if (bootverbose) + printf("Wiring VA=%x to PA=%x (size=%x), " + "using TLB1[%d]\n", va, pa, sz, tlb1_idx); + tlb1_set_entry(va, pa, sz, _TLB_ENTRY_IO); + size -= sz; + pa += sz; + va += sz; + } while (size > 0); + + return (res); } /* Modified: user/kmacy/HEAD_ECMP/sys/powerpc/booke/trap.c ============================================================================== --- user/kmacy/HEAD_ECMP/sys/powerpc/booke/trap.c Tue Oct 28 06:00:13 2008 (r184389) +++ user/kmacy/HEAD_ECMP/sys/powerpc/booke/trap.c Tue Oct 28 06:11:31 2008 (r184390) @@ -103,9 +103,6 @@ int badaddr_read(void *, size_t, int *); extern char *syscallnames[]; -extern char interrupt_vector_base[]; -extern char interrupt_vector_top[]; - struct powerpc_exception { u_int vector; char *name; Modified: user/kmacy/HEAD_ECMP/sys/powerpc/conf/GENERIC ============================================================================== --- user/kmacy/HEAD_ECMP/sys/powerpc/conf/GENERIC Tue Oct 28 06:00:13 2008 (r184389) +++ user/kmacy/HEAD_ECMP/sys/powerpc/conf/GENERIC Tue Oct 28 06:11:31 2008 (r184390) @@ -157,6 +157,11 @@ device fwe # Ethernet over FireWire (n # Misc device powermac_nvram # Open Firmware configuration NVRAM +# ADB support +device adb +device cuda +device pmu + options KTR options KTR_COMPILE=0xffffffff #options KTR_MASK=KTR_SIG Modified: user/kmacy/HEAD_ECMP/sys/powerpc/conf/MPC85XX ============================================================================== --- user/kmacy/HEAD_ECMP/sys/powerpc/conf/MPC85XX Tue Oct 28 06:00:13 2008 (r184389) +++ user/kmacy/HEAD_ECMP/sys/powerpc/conf/MPC85XX Tue Oct 28 06:11:31 2008 (r184390) @@ -50,6 +50,7 @@ options WITNESS_SKIPSPIN device ata device atadisk device bpf +device cfi device da device em device ether Modified: user/kmacy/HEAD_ECMP/sys/powerpc/include/cpu.h ============================================================================== --- user/kmacy/HEAD_ECMP/sys/powerpc/include/cpu.h Tue Oct 28 06:00:13 2008 (r184389) +++ user/kmacy/HEAD_ECMP/sys/powerpc/include/cpu.h Tue Oct 28 06:11:31 2008 (r184390) @@ -69,6 +69,9 @@ get_cyclecount(void) #define cpu_getstack(td) ((td)->td_frame->fixreg[1]) #define cpu_spinwait() /* nothing */ +extern char btext[]; +extern char etext[]; + void cpu_halt(void); void cpu_reset(void); void fork_trampoline(void); Modified: user/kmacy/HEAD_ECMP/sys/powerpc/include/profile.h ============================================================================== --- user/kmacy/HEAD_ECMP/sys/powerpc/include/profile.h Tue Oct 28 06:00:13 2008 (r184389) +++ user/kmacy/HEAD_ECMP/sys/powerpc/include/profile.h Tue Oct 28 06:11:31 2008 (r184390) @@ -81,61 +81,87 @@ typedef u_int fptrdiff_t; #define _PLT #endif -#define MCOUNT \ -__asm(" .globl _mcount \n" \ -" .type _mcount,@function \n" \ -"_mcount: \n" \ -" stwu %r1,-64(%r1) /* alloca for reg save space */ \n" \ -" stw %r3,16(%r1) /* save parameter registers, */ \n" \ -" stw %r4,20(%r1) /* r3-10 */ \n" \ -" stw %r5,24(%r1) \n" \ -" stw %r6,28(%r1) \n" \ -" stw %r7,32(%r1) \n" \ -" stw %r8,36(%r1) \n" \ -" stw %r9,40(%r1) \n" \ -" stw %r10,44(%r1) \n" \ -" \n" \ -" mflr %r4 /* link register is 'selfpc' */ \n" \ -" stw %r4,48(%r1) /* save since bl will scrub */ \n" \ -" lwz %r3,68(%r1) /* get 'frompc' from LR-save */ \n" \ -" bl __mcount" _PLT " /* __mcount(frompc, selfpc)*/ \n" \ -" lwz %r3,68(%r1) \n" \ -" mtlr %r3 /* restore caller's lr */ \n" \ -" lwz %r4,48(%r1) \n" \ -" mtctr %r4 /* set up ctr for call back */ \n" \ -" /* note that blr is not used!*/ \n" \ -" lwz %r3,16(%r1) /* restore r3-10 parameters */ \n" \ -" lwz %r4,20(%r1) \n" \ -" lwz %r5,24(%r1) \n" \ -" lwz %r6,28(%r1) \n" \ -" lwz %r7,32(%r1) \n" \ -" lwz %r8,36(%r1) \n" \ -" lwz %r9,40(%r1) \n" \ -" lwz %r10,44(%r1) \n" \ -" addi %r1,%r1,64 /* blow away alloca save area */ \n" \ -" bctr /* return with indirect call */ \n" \ -"_mcount_end: \n" \ -" .size _mcount,_mcount_end-_mcount"); - +#define MCOUNT \ +__asm( " .globl _mcount \n" \ + " .type _mcount,@function \n" \ + " .align 4 \n" \ + "_mcount: \n" \ + " stwu %r1,-64(%r1) \n" \ + " stw %r3,16(%r1) \n" \ + " stw %r4,20(%r1) \n" \ + " stw %r5,24(%r1) \n" \ + " stw %r6,28(%r1) \n" \ + " stw %r7,32(%r1) \n" \ + " stw %r8,36(%r1) \n" \ + " stw %r9,40(%r1) \n" \ + " stw %r10,44(%r1) \n" \ + " mflr %r4 \n" \ + " stw %r4,48(%r1) \n" \ + " lwz %r3,68(%r1) \n" \ + " bl __mcount" _PLT " \n" \ + " lwz %r3,68(%r1) \n" \ + " mtlr %r3 \n" \ + " lwz %r4,48(%r1) \n" \ + " mtctr %r4 \n" \ + " lwz %r3,16(%r1) \n" \ + " lwz %r4,20(%r1) \n" \ + " lwz %r5,24(%r1) \n" \ + " lwz %r6,28(%r1) \n" \ + " lwz %r7,32(%r1) \n" \ + " lwz %r8,36(%r1) \n" \ + " lwz %r9,40(%r1) \n" \ + " lwz %r10,44(%r1) \n" \ + " addi %r1,%r1,64 \n" \ + " bctr \n" \ + "_mcount_end: \n" \ + " .size _mcount,_mcount_end-_mcount"); #ifdef _KERNEL -#define MCOUNT_ENTER(s) s = intr_disable(); -#define MCOUNT_EXIT(s) intr_restore(s); -#define MCOUNT_DECL(s) register_t s - -void bintr(void); -void btrap(void); -void eintr(void); -void user(void); - -#define MCOUNT_FROMPC_USER(pc) \ - ((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc) - -#define MCOUNT_FROMPC_INTR(pc) \ - ((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ? \ - ((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr : \ - (uintfptr_t)btrap) : ~0U) +#define MCOUNT_ENTER(s) s = intr_disable() +#define MCOUNT_EXIT(s) intr_restore(s) +#define MCOUNT_DECL(s) register_t s; + +#ifndef COMPILING_LINT +#ifdef AIM +#include +#define __PROFILE_VECTOR_BASE EXC_RST +#define __PROFILE_VECTOR_TOP (EXC_LAST + 0x100) +#endif /* AIM */ +#ifdef E500 +extern char interrupt_vector_base[]; +extern char interrupt_vector_top[]; +#define __PROFILE_VECTOR_BASE (uintfptr_t)interrupt_vector_base +#define __PROFILE_VECTOR_TOP (uintfptr_t)interrupt_vector_top +#endif /* E500 */ +#endif /* !COMPILING_LINT */ + +#ifndef __PROFILE_VECTOR_BASE +#define __PROFILE_VECTOR_BASE 0 +#endif +#ifndef __PROFILE_VECTOR_TOP +#define __PROFILE_VECTOR_TOP 1 +#endif + +static __inline void +powerpc_profile_interrupt(void) +{ +} + +static __inline void +powerpc_profile_userspace(void) +{ +} + +#define MCOUNT_FROMPC_USER(pc) \ + ((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? \ + (uintfptr_t)powerpc_profile_userspace : pc) + +#define MCOUNT_FROMPC_INTR(pc) \ + ((pc >= __PROFILE_VECTOR_BASE && \ + pc < __PROFILE_VECTOR_TOP) ? \ + (uintfptr_t)powerpc_profile_interrupt : ~0U) +void __mcount(uintfptr_t frompc, uintfptr_t selfpc); #else /* !_KERNEL */ Added: user/kmacy/HEAD_ECMP/sys/powerpc/mpc85xx/lbc.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/kmacy/HEAD_ECMP/sys/powerpc/mpc85xx/lbc.c Tue Oct 28 06:11:31 2008 (r184390) @@ -0,0 +1,328 @@ +/*- + * Copyright (c) 2006-2008, Juniper Networks, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +struct lbc_softc { + device_t sc_dev; + + struct resource *sc_res; + bus_space_handle_t sc_bsh; + bus_space_tag_t sc_bst; + int sc_rid; + + struct rman sc_rman; + uintptr_t sc_kva; +}; + +struct lbc_devinfo { + int lbc_devtype; + int lbc_memtype; + /* Also the BAR number */ + int lbc_unit; +}; + +static int lbc_probe(device_t); +static int lbc_attach(device_t); +static int lbc_shutdown(device_t); +static int lbc_get_resource(device_t, device_t, int, int, u_long *, + u_long *); +static struct resource *lbc_alloc_resource(device_t, device_t, int, int *, + u_long, u_long, u_long, u_int); +static int lbc_print_child(device_t, device_t); +static int lbc_release_resource(device_t, device_t, int, int, + struct resource *); +static int lbc_read_ivar(device_t, device_t, int, uintptr_t *); + +/* + * Bus interface definition + */ +static device_method_t lbc_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, lbc_probe), + DEVMETHOD(device_attach, lbc_attach), + DEVMETHOD(device_shutdown, lbc_shutdown), + + /* Bus interface */ + DEVMETHOD(bus_print_child, lbc_print_child), + DEVMETHOD(bus_read_ivar, lbc_read_ivar), + DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), + DEVMETHOD(bus_teardown_intr, NULL), + + DEVMETHOD(bus_get_resource, NULL), + DEVMETHOD(bus_alloc_resource, lbc_alloc_resource), + DEVMETHOD(bus_release_resource, lbc_release_resource), + DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), + DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), + + { 0, 0 } +}; + +static driver_t lbc_driver = { + "lbc", + lbc_methods, + sizeof(struct lbc_softc) +}; +devclass_t lbc_devclass; +DRIVER_MODULE(lbc, ocpbus, lbc_driver, lbc_devclass, 0, 0); + +static device_t +lbc_mk_child(device_t dev, int type, int mtype, int unit) +{ + struct lbc_devinfo *dinfo; + device_t child; + + child = device_add_child(dev, NULL, -1); + if (child == NULL) { + device_printf(dev, "could not add child device\n"); + return (NULL); + } + dinfo = malloc(sizeof(struct lbc_devinfo), M_DEVBUF, M_WAITOK | M_ZERO); + dinfo->lbc_devtype = type; + dinfo->lbc_memtype = mtype; + dinfo->lbc_unit = unit; + device_set_ivars(child, dinfo); + return (child); +} + +static int +lbc_probe(device_t dev) +{ + device_t parent; + uintptr_t devtype; + int error; + + parent = device_get_parent(dev); + error = BUS_READ_IVAR(parent, dev, OCPBUS_IVAR_DEVTYPE, &devtype); + if (error) + return (error); + if (devtype != OCPBUS_DEVTYPE_LBC) + return (ENXIO); + + device_set_desc(dev, "Freescale MPC85xx Local Bus Controller"); + return (BUS_PROBE_DEFAULT); +} + +static int +lbc_attach(device_t dev) +{ + struct lbc_softc *sc; + struct rman *rm; + u_long start, size; + int error; + + sc = device_get_softc(dev); + sc->sc_dev = dev; + + sc->sc_rid = 0; + sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rid, + RF_ACTIVE); + if (sc->sc_res == NULL) + return (ENXIO); + + sc->sc_bst = rman_get_bustag(sc->sc_res); + sc->sc_bsh = rman_get_bushandle(sc->sc_res); + + error = bus_get_resource(dev, SYS_RES_MEMORY, 1, &start, &size); + if (error) + goto fail; + + rm = &sc->sc_rman; + rm->rm_type = RMAN_ARRAY; + rm->rm_descr = "MPC85XX Local Bus Space"; + rm->rm_start = start; + rm->rm_end = start + size - 1; + error = rman_init(rm); + if (error) + goto fail; + + error = rman_manage_region(rm, rm->rm_start, rm->rm_end); + if (error) { + rman_fini(rm); + goto fail; + } + + sc->sc_kva = (uintptr_t)pmap_mapdev(start, size); + + lbc_mk_child(dev, LBC_DEVTYPE_CFI, 0, 0); + + return (bus_generic_attach(dev)); + + fail: + bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rid, sc->sc_res); + return (error); +} + +static int +lbc_shutdown(device_t dev) +{ + + /* TODO */ + return(0); +} + +static struct resource * +lbc_alloc_resource(device_t dev, device_t child, int type, int *rid, + u_long start, u_long end, u_long count, u_int flags) +{ + struct lbc_softc *sc; + struct resource *rv; + struct rman *rm; + int error; + + sc = device_get_softc(dev); + + if (type != SYS_RES_MEMORY && type != SYS_RES_IRQ) + return (NULL); + + /* We only support default allocations. */ + if (start != 0ul || end != ~0ul) + return (NULL); + + if (type == SYS_RES_IRQ) + return (bus_alloc_resource(dev, type, rid, start, end, count, + flags)); + + error = lbc_get_resource(dev, child, type, *rid, &start, &count); + if (error) + return (NULL); + + rm = &sc->sc_rman; + end = start + count - 1; + rv = rman_reserve_resource(rm, start, end, count, flags, child); + if (rv != NULL) { + rman_set_bustag(rv, &bs_be_tag); + rman_set_bushandle(rv, sc->sc_kva + rman_get_start(rv) - + rm->rm_start); + } + return (rv); +} + +static int +lbc_print_child(device_t dev, device_t child) +{ + u_long size, start; + int error, retval, rid; + + retval = bus_print_child_header(dev, child); + + rid = 0; + while (1) { + error = lbc_get_resource(dev, child, SYS_RES_MEMORY, rid, + &start, &size); + if (error) + break; + retval += (rid == 0) ? printf(" iomem ") : printf(","); + retval += printf("%#lx", start); + if (size > 1) + retval += printf("-%#lx", start + size - 1); + rid++; + } + + retval += bus_print_child_footer(dev, child); + return (retval); +} + +static int +lbc_read_ivar(device_t dev, device_t child, int index, uintptr_t *result) +{ + struct lbc_devinfo *dinfo; + + if (device_get_parent(child) != dev) + return (EINVAL); + + dinfo = device_get_ivars(child); + + switch (index) { + case LBC_IVAR_DEVTYPE: + *result = dinfo->lbc_devtype; + return (0); + case LBC_IVAR_CLOCK: + *result = 1843200; + return (0); + case LBC_IVAR_REGSHIFT: + *result = 0; + return (0); + default: + break; + } + return (EINVAL); +} + +static int +lbc_release_resource(device_t dev, device_t child, int type, int rid, + struct resource *res) +{ + + return (rman_release_resource(res)); +} + +static int +lbc_get_resource(device_t dev, device_t child, int type, int rid, + u_long *startp, u_long *countp) +{ + struct lbc_softc *sc; + struct lbc_devinfo *dinfo; + + if (type != SYS_RES_MEMORY) + return (ENOENT); + + /* Currently all devices have a single RID per type. */ + if (rid != 0) + return (ENOENT); + + sc = device_get_softc(dev); + dinfo = device_get_ivars(child); + + switch (dinfo->lbc_devtype) { + case LBC_DEVTYPE_CFI: + *startp = sc->sc_rman.rm_start; + *countp = sc->sc_rman.rm_end - sc->sc_rman.rm_start + 1; + break; + default: + return(EDOOFUS); + } + return(0); +} Added: user/kmacy/HEAD_ECMP/sys/powerpc/mpc85xx/lbc.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/kmacy/HEAD_ECMP/sys/powerpc/mpc85xx/lbc.h Tue Oct 28 06:11:31 2008 (r184390) @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2006-2008, Juniper Networks, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_LBC_H_ +#define _MACHINE_LBC_H_ + +#define LBC_IVAR_DEVTYPE 1 +#define LBC_IVAR_CLOCK 2 +#define LBC_IVAR_REGSHIFT 3 + +/* Device types. */ +#define LBC_DEVTYPE_CFI 1 +#define LBC_DEVTYPE_UART 2 + +#endif /* _MACHINE_LBC_H_ */ Modified: user/kmacy/HEAD_ECMP/sys/powerpc/mpc85xx/ocpbus.c ============================================================================== --- user/kmacy/HEAD_ECMP/sys/powerpc/mpc85xx/ocpbus.c Tue Oct 28 06:00:13 2008 (r184389) +++ user/kmacy/HEAD_ECMP/sys/powerpc/mpc85xx/ocpbus.c Tue Oct 28 06:11:31 2008 (r184390) @@ -172,6 +172,10 @@ ocpbus_write_law(int trgt, int type, u_l addr = 0xA0000000; size = 0x10000000; break; + case OCP85XX_TGTIF_LBC: + addr = 0xff800000; + size = 0x00800000; + break; default: return (EINVAL); } Modified: user/kmacy/HEAD_ECMP/sys/powerpc/powermac/ata_kauai.c ============================================================================== --- user/kmacy/HEAD_ECMP/sys/powerpc/powermac/ata_kauai.c Tue Oct 28 06:00:13 2008 (r184389) +++ user/kmacy/HEAD_ECMP/sys/powerpc/powermac/ata_kauai.c Tue Oct 28 06:11:31 2008 (r184390) @@ -292,16 +292,12 @@ ata_kauai_attach(device_t dev) #endif /* Set up initial mode */ - if (sc->shasta) - sc->pioconf[0] = sc->pioconf[1] = pio_timing_shasta[4]; - else - sc->pioconf[0] = sc->pioconf[1] = pio_timing_kauai[4]; + sc->pioconf[0] = sc->pioconf[1] = + bus_read_4(sc->sc_memr, PIO_CONFIG_REG) & 0x0f000fff; sc->udmaconf[0] = sc->udmaconf[1] = 0; sc->wdmaconf[0] = sc->wdmaconf[1] = 0; - bus_write_4(sc->sc_memr, PIO_CONFIG_REG, sc->pioconf[0]); - /* Magic FCR value from Apple */ bus_write_4(sc->sc_memr, 0, 0x00000007); Added: user/kmacy/HEAD_ECMP/sys/powerpc/powermac/cuda.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/kmacy/HEAD_ECMP/sys/powerpc/powermac/cuda.c Tue Oct 28 06:11:31 2008 (r184390) @@ -0,0 +1,641 @@ +/*- + * Copyright (c) 2006 Michael Lorenz + * Copyright 2008 by Nathan Whitehorn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include "cudavar.h" +#include "viareg.h" + +/* + * MacIO interface + */ +static int cuda_probe(device_t); +static int cuda_attach(device_t); +static int cuda_detach(device_t); + +static u_int cuda_adb_send(device_t dev, u_char command_byte, int len, + u_char *data, u_char poll); +static u_int cuda_adb_autopoll(device_t dev, uint16_t mask); +static void cuda_poll(device_t dev); + +static device_method_t cuda_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, cuda_probe), + DEVMETHOD(device_attach, cuda_attach), + DEVMETHOD(device_detach, cuda_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + DEVMETHOD(device_suspend, bus_generic_suspend), + DEVMETHOD(device_resume, bus_generic_resume), + + /* bus interface, for ADB root */ + DEVMETHOD(bus_print_child, bus_generic_print_child), + DEVMETHOD(bus_driver_added, bus_generic_driver_added), + + /* ADB bus interface */ + DEVMETHOD(adb_hb_send_raw_packet, cuda_adb_send), + DEVMETHOD(adb_hb_controller_poll, cuda_poll), + DEVMETHOD(adb_hb_set_autopoll_mask, cuda_adb_autopoll), + + { 0, 0 }, +}; + +static driver_t cuda_driver = { + "cuda", + cuda_methods, + sizeof(struct cuda_softc), +}; + +static devclass_t cuda_devclass; + +DRIVER_MODULE(cuda, macio, cuda_driver, cuda_devclass, 0, 0); +DRIVER_MODULE(adb, cuda, adb_driver, adb_devclass, 0, 0); + +static void cuda_intr(void *arg); +static uint8_t cuda_read_reg(struct cuda_softc *sc, u_int offset); +static void cuda_write_reg(struct cuda_softc *sc, u_int offset, uint8_t value); +static void cuda_idle(struct cuda_softc *); +static void cuda_tip(struct cuda_softc *); +static void cuda_clear_tip(struct cuda_softc *); +static void cuda_in(struct cuda_softc *); +static void cuda_out(struct cuda_softc *); +static void cuda_toggle_ack(struct cuda_softc *); +static void cuda_ack_off(struct cuda_softc *); +static int cuda_intr_state(struct cuda_softc *); + +static int +cuda_probe(device_t dev) +{ + const char *type = ofw_bus_get_type(dev); + + if (strcmp(type, "via-cuda") != 0) + return (ENXIO); + + device_set_desc(dev, CUDA_DEVSTR); + return (0); +} + +static int +cuda_attach(device_t dev) +{ + struct cuda_softc *sc; + + volatile int i; + uint8_t reg; + phandle_t node,child; + + sc = device_get_softc(dev); + sc->sc_dev = dev; + + sc->sc_memrid = 0; + sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + &sc->sc_memrid, RF_ACTIVE); + + if (sc->sc_memr == NULL) { + device_printf(dev, "Could not alloc mem resource!\n"); + return (ENXIO); + } + + sc->sc_irqrid = 0; + sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->sc_irqrid, + RF_ACTIVE); + if (sc->sc_irq == NULL) { + device_printf(dev, "could not allocate interrupt\n"); + return (ENXIO); + } + + if (bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC | INTR_MPSAFE + | INTR_ENTROPY, NULL, cuda_intr, dev, &sc->sc_ih) != 0) { + device_printf(dev, "could not setup interrupt\n"); + bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irqrid, + sc->sc_irq); + return (ENXIO); + } + + mtx_init(&sc->sc_mutex,"cuda",NULL,MTX_DEF | MTX_RECURSE); + + sc->sc_sent = 0; + sc->sc_received = 0; + sc->sc_waiting = 0; + sc->sc_polling = 0; + sc->sc_state = CUDA_NOTREADY; + sc->sc_error = 0; + sc->sc_autopoll = 0; + + /* Init CUDA */ + + reg = cuda_read_reg(sc, vDirB); + reg |= 0x30; /* register B bits 4 and 5: outputs */ + cuda_write_reg(sc, vDirB, reg); + + reg = cuda_read_reg(sc, vDirB); + reg &= 0xf7; /* register B bit 3: input */ + cuda_write_reg(sc, vDirB, reg); + + reg = cuda_read_reg(sc, vACR); + reg &= ~vSR_OUT; /* make sure SR is set to IN */ + cuda_write_reg(sc, vACR, reg); + + cuda_write_reg(sc, vACR, (cuda_read_reg(sc, vACR) | 0x0c) & ~0x10); + + sc->sc_state = CUDA_IDLE; /* used by all types of hardware */ + + cuda_write_reg(sc, vIER, 0x84); /* make sure VIA interrupts are on */ + + cuda_idle(sc); /* reset ADB */ + + /* Reset CUDA */ + + i = cuda_read_reg(sc, vSR); /* clear interrupt */ + cuda_write_reg(sc, vIER, 0x04); /* no interrupts while clearing */ + cuda_idle(sc); /* reset state to idle */ + DELAY(150); + cuda_tip(sc); /* signal start of frame */ + DELAY(150); + cuda_toggle_ack(sc); + DELAY(150); + cuda_clear_tip(sc); + DELAY(150); + cuda_idle(sc); /* back to idle state */ + i = cuda_read_reg(sc, vSR); /* clear interrupt */ + cuda_write_reg(sc, vIER, 0x84); /* ints ok now */ + + /* Initialize child buses (ADB) */ + node = ofw_bus_get_node(dev); + + for (child = OF_child(node); child != 0; child = OF_peer(child)) { + char name[32]; + + memset(name, 0, sizeof(name)); + OF_getprop(child, "name", name, sizeof(name)); + + if (bootverbose) + device_printf(dev, "CUDA child <%s>\n",name); + + if (strncmp(name, "adb", 4) == 0) { + sc->adb_bus = device_add_child(dev,"adb",-1); + } + } + + return (bus_generic_attach(dev)); +} + +static int cuda_detach(device_t dev) { + struct cuda_softc *sc; + + sc = device_get_softc(dev); + + bus_teardown_intr(dev, sc->sc_irq, sc->sc_ih); + bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irqrid, sc->sc_irq); + bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_memrid, sc->sc_memr); + mtx_destroy(&sc->sc_mutex); + + return (bus_generic_detach(dev)); +} + +static uint8_t +cuda_read_reg(struct cuda_softc *sc, u_int offset) { + return (bus_read_1(sc->sc_memr, offset)); +} + +static void +cuda_write_reg(struct cuda_softc *sc, u_int offset, uint8_t value) { + bus_write_1(sc->sc_memr, offset, value); +} + +static void +cuda_idle(struct cuda_softc *sc) +{ + uint8_t reg; + + reg = cuda_read_reg(sc, vBufB); + reg |= (vPB4 | vPB5); + cuda_write_reg(sc, vBufB, reg); +} + +static void +cuda_tip(struct cuda_softc *sc) +{ + uint8_t reg; + + reg = cuda_read_reg(sc, vBufB); + reg &= ~vPB5; + cuda_write_reg(sc, vBufB, reg); +} + +static void +cuda_clear_tip(struct cuda_softc *sc) +{ + uint8_t reg; + + reg = cuda_read_reg(sc, vBufB); + reg |= vPB5; + cuda_write_reg(sc, vBufB, reg); +} + +static void +cuda_in(struct cuda_softc *sc) +{ + uint8_t reg; + + reg = cuda_read_reg(sc, vACR); + reg &= ~vSR_OUT; + cuda_write_reg(sc, vACR, reg); +} + +static void +cuda_out(struct cuda_softc *sc) +{ + uint8_t reg; + + reg = cuda_read_reg(sc, vACR); + reg |= vSR_OUT; + cuda_write_reg(sc, vACR, reg); +} + +static void +cuda_toggle_ack(struct cuda_softc *sc) +{ + uint8_t reg; + + reg = cuda_read_reg(sc, vBufB); + reg ^= vPB4; + cuda_write_reg(sc, vBufB, reg); +} + +static void +cuda_ack_off(struct cuda_softc *sc) +{ + uint8_t reg; + + reg = cuda_read_reg(sc, vBufB); + reg |= vPB4; + cuda_write_reg(sc, vBufB, reg); +} + +static int +cuda_intr_state(struct cuda_softc *sc) +{ + return ((cuda_read_reg(sc, vBufB) & vPB3) == 0); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***