Module Name: src Committed By: rkujawa Date: Sun Dec 22 02:21:51 UTC 2013
Modified Files: src/sys/arch/amiga/amiga: autoconf.c src/sys/arch/amiga/conf: GENERIC.in files.amiga src/sys/arch/amiga/include: bus.h Added Files: src/sys/arch/amiga/amiga: amiga_bus_simple_0x4000.c src/sys/arch/amiga/dev: acafh.c acafhreg.h acafhvar.h wdc_acafh.c Log Message: Add preliminary support for the Individual Computers ACA500 in the form of acahf driver. If ACA500 is equipped with supported accelerator with MMU, it allows running NetBSD on an Amiga 500. Since ACA is not autoconf-aware, and the probe procedure does not exist yet, the driver is activated with the ACA500_SUPPORT kernel option. The acahf driver is commented out in the GENERIC kernel for now (at least until it stops being very experimental and hackish). When it comes to ACA-specific hardware, for now the boot CF slot works. Support for everything else is incoming... To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/arch/amiga/amiga/amiga_bus_simple_0x4000.c cvs rdiff -u -r1.114 -r1.115 src/sys/arch/amiga/amiga/autoconf.c cvs rdiff -u -r1.120 -r1.121 src/sys/arch/amiga/conf/GENERIC.in cvs rdiff -u -r1.171 -r1.172 src/sys/arch/amiga/conf/files.amiga cvs rdiff -u -r0 -r1.1 src/sys/arch/amiga/dev/acafh.c \ src/sys/arch/amiga/dev/acafhreg.h src/sys/arch/amiga/dev/acafhvar.h \ src/sys/arch/amiga/dev/wdc_acafh.c cvs rdiff -u -r1.27 -r1.28 src/sys/arch/amiga/include/bus.h 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/amiga/amiga/autoconf.c diff -u src/sys/arch/amiga/amiga/autoconf.c:1.114 src/sys/arch/amiga/amiga/autoconf.c:1.115 --- src/sys/arch/amiga/amiga/autoconf.c:1.114 Sat Oct 27 17:17:26 2012 +++ src/sys/arch/amiga/amiga/autoconf.c Sun Dec 22 02:21:51 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.114 2012/10/27 17:17:26 chs Exp $ */ +/* $NetBSD: autoconf.c,v 1.115 2013/12/22 02:21:51 rkujawa Exp $ */ /* * Copyright (c) 1994 Christian E. Hopps @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.114 2012/10/27 17:17:26 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.115 2013/12/22 02:21:51 rkujawa Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -53,6 +53,8 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v #include <amiga/pci/p5pbvar.h> #endif /* P5PB_CONSOLE */ +#include "opt_acafh.h" + static void findroot(void); void mbattach(device_t, device_t, void *); int mbprint(void *, const char *); @@ -300,6 +302,10 @@ mbattach(device_t parent, device_t self, #endif config_found(self, __UNCONST("aucc"), simple_devprint); +#ifdef ACA500_SUPPORT + config_found(self, __UNCONST("acafh"), simple_devprint); +#endif + config_found(self, __UNCONST("zbus"), simple_devprint); } Index: src/sys/arch/amiga/conf/GENERIC.in diff -u src/sys/arch/amiga/conf/GENERIC.in:1.120 src/sys/arch/amiga/conf/GENERIC.in:1.121 --- src/sys/arch/amiga/conf/GENERIC.in:1.120 Fri Oct 4 15:13:51 2013 +++ src/sys/arch/amiga/conf/GENERIC.in Sun Dec 22 02:21:51 2013 @@ -1,4 +1,4 @@ -# $NetBSD: GENERIC.in,v 1.120 2013/10/04 15:13:51 rkujawa Exp $ +# $NetBSD: GENERIC.in,v 1.121 2013/12/22 02:21:51 rkujawa Exp $ # ## # GENERIC machine description file @@ -52,7 +52,7 @@ include "arch/amiga/conf/std.amiga" options INCLUDE_CONFIG_FILE # embed config file in kernel binary -#ident "GENERIC-$Revision: 1.120 $" +#ident "GENERIC-$Revision: 1.121 $" m4_ifdef(`INSTALL_CONFIGURATION', `m4_dnl makeoptions COPTS="-Os" @@ -515,6 +515,10 @@ scsibus* at cbiiisc0 empsc0 at zbus0 # Emplant scsi scsibus* at empsc0 +#acafh0 at mainbus0 # Individual Computers ACA500 +#options ACA500_SUPPORT +#wdc* at acafhbus? + wdc0 at mainbus0 # A4000 & A1200 IDE bus wdc* at zbus0 # Buddha / Catweasel #efa0 at mainbus0 # ELBOX FastATA 1200 Mk-III/Mk-IV Index: src/sys/arch/amiga/conf/files.amiga diff -u src/sys/arch/amiga/conf/files.amiga:1.171 src/sys/arch/amiga/conf/files.amiga:1.172 --- src/sys/arch/amiga/conf/files.amiga:1.171 Thu Aug 8 21:23:51 2013 +++ src/sys/arch/amiga/conf/files.amiga Sun Dec 22 02:21:51 2013 @@ -1,4 +1,4 @@ -# $NetBSD: files.amiga,v 1.171 2013/08/08 21:23:51 rkujawa Exp $ +# $NetBSD: files.amiga,v 1.172 2013/12/22 02:21:51 rkujawa Exp $ # maxpartitions must be first item in files.${ARCH}.newconf maxpartitions 16 # NOTE THAT AMIGA IS SPECIAL! @@ -34,6 +34,8 @@ defflag DEVRELOAD defflag opt_p5pb.h P5PB_DEBUG P5PB_CONSOLE +defflag opt_acafh.h ACA500_SUPPORT + defparam IOBZCLOCK device mainbus {} @@ -58,6 +60,9 @@ file arch/amiga/amiga/amiga_bus_simple_1 define amibus_b800 file arch/amiga/amiga/amiga_bus_simple_0x800.c amibus_b800 +define amibus_b4000 +file arch/amiga/amiga/amiga_bus_simple_0x4000.c amibus_b4000 + define amibus_empb file arch/amiga/pci/empb_bsm.c amibus_empb @@ -579,6 +584,15 @@ file arch/amiga/dev/z3rambd.c z3rambd ne attach slhci at zbus with slhci_zbus file arch/amiga/dev/slhci_zbus.c slhci_zbus +define acafhbus {} + +device acafh: acafhbus, amibus_b4000 +attach acafh at mainbus +file arch/amiga/dev/acafh.c acafh needs-flag + +attach wdc at acafhbus with wdc_acafh +file arch/amiga/dev/wdc_acafh.c wdc_acafh & acafh + include "arch/amiga/clockport/files.clockport" include "arch/amiga/conf/majors.amiga" Index: src/sys/arch/amiga/include/bus.h diff -u src/sys/arch/amiga/include/bus.h:1.27 src/sys/arch/amiga/include/bus.h:1.28 --- src/sys/arch/amiga/include/bus.h:1.27 Fri Jun 1 09:41:35 2012 +++ src/sys/arch/amiga/include/bus.h Sun Dec 22 02:21:51 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bus.h,v 1.27 2012/06/01 09:41:35 rkujawa Exp $ */ +/* $NetBSD: bus.h,v 1.28 2013/12/22 02:21:51 rkujawa Exp $ */ /* * Copyright (c) 1996 Leo Weppelman. All rights reserved. @@ -279,6 +279,7 @@ extern const struct amiga_bus_space_meth extern const struct amiga_bus_space_methods amiga_bus_stride_4; extern const struct amiga_bus_space_methods amiga_bus_stride_4swap; extern const struct amiga_bus_space_methods amiga_bus_stride_16; +extern const struct amiga_bus_space_methods amiga_bus_stride_0x4000; extern const struct amiga_bus_space_methods empb_bus_swap; /* Added files: Index: src/sys/arch/amiga/amiga/amiga_bus_simple_0x4000.c diff -u /dev/null src/sys/arch/amiga/amiga/amiga_bus_simple_0x4000.c:1.1 --- /dev/null Sun Dec 22 02:21:51 2013 +++ src/sys/arch/amiga/amiga/amiga_bus_simple_0x4000.c Sun Dec 22 02:21:51 2013 @@ -0,0 +1,38 @@ +/* $NetBSD: amiga_bus_simple_0x4000.c,v 1.1 2013/12/22 02:21:51 rkujawa Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Ignatios Souvatzis. + * + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FOUNDATION OR CONTRIBUTORS + * 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 <sys/cdefs.h> +__KERNEL_RCSID(1, "$NetBSD: amiga_bus_simple_0x4000.c,v 1.1 2013/12/22 02:21:51 rkujawa Exp $"); + +#define AMIGA_SIMPLE_BUS_STRIDE 0x4000 /* 1 byte per 0x4000 bytes */ +#define AMIGA_SIMPLE_BUS_WORD_METHODS + +#include "simple_busfuncs.c" Index: src/sys/arch/amiga/dev/acafh.c diff -u /dev/null src/sys/arch/amiga/dev/acafh.c:1.1 --- /dev/null Sun Dec 22 02:21:51 2013 +++ src/sys/arch/amiga/dev/acafh.c Sun Dec 22 02:21:51 2013 @@ -0,0 +1,185 @@ +/* $NetBSD: acafh.c,v 1.1 2013/12/22 02:21:51 rkujawa Exp $ */ + +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Radoslaw Kujawa. + * + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FOUNDATION OR CONTRIBUTORS + * 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 <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: acafh.c,v 1.1 2013/12/22 02:21:51 rkujawa Exp $"); + +/* + * Individual Computers ACA500 driver. + */ + +#include <sys/param.h> +#include <sys/device.h> +#include <sys/malloc.h> +#include <sys/socket.h> +#include <sys/systm.h> +#include <sys/bus.h> + +#include <uvm/uvm.h> + +#include <machine/cpu.h> + +#include <amiga/amiga/device.h> +#include <amiga/amiga/isr.h> + +#include <amiga/dev/zbusvar.h> +#include <amiga/dev/acafhvar.h> +#include <amiga/dev/acafhreg.h> + +int acafh_match(device_t, cfdata_t , void *); +void acafh_attach(device_t, device_t, void *); +static int acafh_print(void *, const char *); +static uint8_t acafh_reg_read(struct acafh_softc *, uint8_t); +static uint8_t acafh_revision(struct acafh_softc *); + +CFATTACH_DECL_NEW(acafh, sizeof(struct acafh_softc), + acafh_match, acafh_attach, NULL, NULL); + +int +acafh_match(device_t parent, cfdata_t cf, void *aux) +{ + if (matchname(aux, "acafh") == 0) + return(0); + return(1); +} + +void +acafh_attach(device_t parent, device_t self, void *aux) +{ + struct acafh_softc *sc; + vaddr_t aca_vbase; + int i; + struct acafhbus_attach_args aaa_wdc; + + sc = device_private(self); + sc->sc_dev = self; + + /* XXX: we should be sure to prepare enough kva during early init... */ + aca_vbase = uvm_km_alloc(kernel_map, + ACAFH_END - ACAFH_BASE, 0, UVM_KMF_VAONLY | UVM_KMF_NOWAIT); + + if (aca_vbase == 0) { + aprint_error_dev(sc->sc_dev, + "failed allocating virtual memory\n"); + return; + } + + for (i = ACAFH_BASE; i < ACAFH_END; i += PAGE_SIZE) + pmap_enter(vm_map_pmap(kernel_map), + i - ACAFH_BASE + aca_vbase, i, + VM_PROT_READ | VM_PROT_WRITE, true); + pmap_update(vm_map_pmap(kernel_map)); + + aca_vbase += ACAFH_FIRST_REG_OFF; + + sc->sc_aca_bst.base = (bus_addr_t) aca_vbase; + sc->sc_aca_bst.absm = &amiga_bus_stride_1; +/* sc->sc_aca_bst.absm = &amiga_bus_stride_0x4000; */ + sc->sc_aca_iot = &sc->sc_aca_bst; + + bus_space_map(sc->sc_aca_iot, 0, 0xF, 0, &sc->sc_aca_ioh); + +#ifdef ACAFH_DEBUG + aprint_normal_dev(sc->sc_dev, + "ACA500 registers mapped to pa %x (va %x)\n", + kvtop((void*)sc->sc_aca_ioh), sc->sc_aca_bst.base); + aprint_normal_dev(sc->sc_dev, "AUX intr enable %x\n", + acafh_reg_read(sc, ACAFH_MEMPROBE_AUXIRQ)); +#endif /* ACAFH_DEBUG */ + + aprint_normal(": Individual Computers ACA500 (rev %x)\n", + acafh_revision(sc)); + + aprint_normal_dev(sc->sc_dev, "CF cards present: "); + if (acafh_reg_read(sc, ACAFH_CF_DETECT_BOOT)) { + aprint_normal("BOOT "); + } + if (acafh_reg_read(sc, ACAFH_CF_DETECT_AUX)) { + aprint_normal("AUX "); + } + aprint_normal("\n"); + + aaa_wdc.aaa_base = (bus_addr_t) 0xDA0000 + 2; + strcpy(aaa_wdc.aaa_name, "wdc_acafh"); + config_found_ia(sc->sc_dev, "acafhbus", &aaa_wdc, acafh_print); +} + +uint8_t +acafh_cf_intr_status(struct acafh_softc *sc, uint8_t slot) +{ + uint8_t status; + + if (slot == 0) { + status = acafh_reg_read(sc, ACAFH_CF_IRQ_BOOT); + } else { + status = acafh_reg_read(sc, ACAFH_CF_IRQ_AUX); + } + + return status; +} + +static uint8_t +acafh_revision(struct acafh_softc *sc) +{ + uint8_t revbit0, revbit1, revbit2, revbit3; + + revbit3 = acafh_reg_read(sc, ACAFH_VERSION_BIT3); + revbit2 = acafh_reg_read(sc, ACAFH_VERSION_BIT2); + revbit1 = acafh_reg_read(sc, ACAFH_VERSION_BIT1); + revbit0 = acafh_reg_read(sc, ACAFH_VERSION_BIT0); + + return revbit0 | (revbit1 << 1) | (revbit2 << 2) | (revbit3 << 3); +} + +static uint8_t +acafh_reg_read(struct acafh_softc *sc, uint8_t reg) +{ + uint16_t val; + + val = bus_space_read_2(sc->sc_aca_iot, sc->sc_aca_ioh, reg * 0x4000); +#ifdef ACAFH_DEBUG + aprint_normal_dev(sc->sc_dev, "read out reg %x from %lx (%x), val %x\n", + reg, sc->sc_aca_ioh + reg, (bus_addr_t) kvtop((void*) + ((unsigned) sc->sc_aca_ioh + reg * 0x4000)), val); +#endif /* ACAFH_DEBUG */ + + return (val & ACAFH_MSB_MASK) >> ACAFH_MSB_SHIFT; +} + +static int +acafh_print(void *aux, const char *w) +{ + if (w == NULL) + return 0; + + return 0; +} + Index: src/sys/arch/amiga/dev/acafhreg.h diff -u /dev/null src/sys/arch/amiga/dev/acafhreg.h:1.1 --- /dev/null Sun Dec 22 02:21:51 2013 +++ src/sys/arch/amiga/dev/acafhreg.h Sun Dec 22 02:21:51 2013 @@ -0,0 +1,62 @@ +/* $NetBSD: acafhreg.h,v 1.1 2013/12/22 02:21:51 rkujawa Exp $ */ + +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Radoslaw Kujawa. + * + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FOUNDATION OR CONTRIBUTORS + * 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. + */ + +#ifndef _AMIGA_ACAFHREG_H_ + +#define GAYLE_IDE_BASE 0xDA0000 /* ACA500 has Gayle-compatible IDE */ + +#define ACAFH_MSB_SHIFT 0xF +#define ACAFH_MSB_MASK 0x8000 + +#define ACAFH_BASE 0xB00000 +#define ACAFH_FIRST_REG_OFF 0x3000 +#define ACAFH_END 0xB3B002 +/* registers have stride of 16kB */ +#define ACAFH_CF_DETECT_BOOT 0x0 +#define ACAFH_CF_DETECT_AUX 0x1 +#define ACAFH_CF_IRQ_BOOT 0x2 +#define ACAFH_CF_IRQ_AUX 0x3 + +#define ACAFH_VERSION_BIT3 0x4 +#define ACAFH_VERSION_BIT2 0x5 +#define ACAFH_VERSION_BIT1 0x6 +#define ACAFH_VERSION_BIT0 0x7 + +#define ACAFH_MAPROM 0x8 +#define ACAFH_CHIPMAP 0x9 +#define ACAFH_FLASH_WRITE 0xA +#define ACAFH_VBR_MOVE 0xB +#define ACAFH_MEMPROBE_AUXIRQ 0xC +#define ACAFH_POWERUP 0xD +#define ACAFH_C0WIPE 0xE + +#endif /* _AMIGA_ACAFHREG_H_ */ + Index: src/sys/arch/amiga/dev/acafhvar.h diff -u /dev/null src/sys/arch/amiga/dev/acafhvar.h:1.1 --- /dev/null Sun Dec 22 02:21:51 2013 +++ src/sys/arch/amiga/dev/acafhvar.h Sun Dec 22 02:21:51 2013 @@ -0,0 +1,52 @@ +/* $NetBSD: acafhvar.h,v 1.1 2013/12/22 02:21:51 rkujawa Exp $ */ + +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Radoslaw Kujawa. + * + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FOUNDATION OR CONTRIBUTORS + * 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. + */ + +#ifndef _AMIGA_ACAFHVAR_H_ + +#include <sys/bus.h> + +struct acafh_softc { + device_t sc_dev; + + struct bus_space_tag sc_aca_bst; + bus_space_tag_t sc_aca_iot; + bus_space_handle_t sc_aca_ioh; +}; + +struct acafhbus_attach_args { + char aaa_name[32]; + bus_addr_t aaa_base; +}; + +uint8_t acafh_cf_intr_status(struct acafh_softc *, uint8_t); + +#endif /* _AMIGA_ACAFHVAR_H_ */ + Index: src/sys/arch/amiga/dev/wdc_acafh.c diff -u /dev/null src/sys/arch/amiga/dev/wdc_acafh.c:1.1 --- /dev/null Sun Dec 22 02:21:51 2013 +++ src/sys/arch/amiga/dev/wdc_acafh.c Sun Dec 22 02:21:51 2013 @@ -0,0 +1,176 @@ +/* $NetBSD: wdc_acafh.c,v 1.1 2013/12/22 02:21:51 rkujawa Exp $ */ + +/*- + * Copyright (c) 2000, 2003, 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Radoslaw Kujawa. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Michael L. Hitch. + * + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FOUNDATION OR CONTRIBUTORS + * 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 <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: wdc_acafh.c,v 1.1 2013/12/22 02:21:51 rkujawa Exp $"); + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/malloc.h> +#include <sys/device.h> +#include <sys/bus.h> + +#include <machine/cpu.h> +#include <machine/intr.h> +#include <sys/bswap.h> + +#include <amiga/amiga/cia.h> +#include <amiga/amiga/custom.h> +#include <amiga/amiga/device.h> +#include <amiga/amiga/gayle.h> +#include <amiga/dev/zbusvar.h> +#include <amiga/dev/acafhvar.h> + +#include <dev/ata/atavar.h> +#include <dev/ic/wdcvar.h> + +struct wdc_acafh_softc { + struct wdc_softc sc_wdcdev; + struct ata_channel *sc_chanlist[1]; + struct ata_channel sc_channel; + struct ata_queue sc_chqueue; + struct wdc_regs sc_wdc_regs; + struct isr sc_isr; + volatile u_char *sc_intreg; + struct bus_space_tag cmd_iot; + struct bus_space_tag ctl_iot; + struct acafh_softc *aca_sc; +}; + +int wdc_acafh_match(device_t, cfdata_t, void *); +void wdc_acafh_attach(device_t, device_t, void *); +int wdc_acafh_intr(void *); + +CFATTACH_DECL_NEW(wdc_acafh, sizeof(struct wdc_acafh_softc), + wdc_acafh_match, wdc_acafh_attach, NULL, NULL); + +int +wdc_acafh_match(device_t parent, cfdata_t cfp, void *aux) +{ + struct acafhbus_attach_args *aap = aux; + + if (strcmp(aap->aaa_name, "wdc_acafh") != 0) + return(0); + return 1; +} + +void +wdc_acafh_attach(device_t parent, device_t self, void *aux) +{ + struct wdc_acafh_softc *sc = device_private(self); + struct wdc_regs *wdr; + int i; + + aprint_normal("\n"); + gayle_init(); + + sc->aca_sc = device_private(parent); + + sc->sc_wdcdev.sc_atac.atac_dev = self; + sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs; + + sc->cmd_iot.base = (u_long) ztwomap(0xda0000 + 2); + gayle_init(); + sc->sc_intreg = &gayle.intreq; + + sc->cmd_iot.absm = sc->ctl_iot.absm = &amiga_bus_stride_4swap; + wdr->cmd_iot = &sc->cmd_iot; + wdr->ctl_iot = &sc->ctl_iot; + + if (bus_space_map(wdr->cmd_iot, 0, 0x40, 0, + &wdr->cmd_baseioh)) { + aprint_error_dev(self, "couldn't map registers\n"); + return; + } + + for (i = 0; i < WDC_NREG; i++) { + if (bus_space_subregion(wdr->cmd_iot, + wdr->cmd_baseioh, i, i == 0 ? 4 : 1, + &wdr->cmd_iohs[i]) != 0) { + + bus_space_unmap(wdr->cmd_iot, + wdr->cmd_baseioh, 0x40); + aprint_error_dev(self, "couldn't map registers\n"); + return; + } + } + + if (bus_space_subregion(wdr->cmd_iot, + wdr->cmd_baseioh, 0x406, 1, &wdr->ctl_ioh)) + return; + + sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16; + sc->sc_wdcdev.sc_atac.atac_pio_cap = 0; + sc->sc_chanlist[0] = &sc->sc_channel; + sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist; + sc->sc_wdcdev.sc_atac.atac_nchannels = 1; + sc->sc_wdcdev.wdc_maxdrives = 2; + sc->sc_channel.ch_channel = 0; + sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac; + sc->sc_channel.ch_queue = &sc->sc_chqueue; + + wdc_init_shadow_regs(&sc->sc_channel); + + sc->sc_isr.isr_intr = wdc_acafh_intr; + sc->sc_isr.isr_arg = sc; + sc->sc_isr.isr_ipl = 2; + add_isr (&sc->sc_isr); + + gayle.intena |= GAYLE_INT_IDE; + + wdcattach(&sc->sc_channel); +} + +int +wdc_acafh_intr(void *arg) +{ + struct wdc_acafh_softc *sc = (struct wdc_acafh_softc *)arg; + int ret = 0; + u_char intreq = *sc->sc_intreg; + + if (intreq & GAYLE_INT_IDE) { +/* + if (acafh_cf_intr_status(sc->aca_sc, 1) == 1) + aprint_normal_dev(sc->aca_sc->sc_dev, "intr at slot 1\n"); + if (acafh_cf_intr_status(sc->aca_sc, 0) == 1) + aprint_normal_dev(sc->aca_sc->sc_dev, "intr at slot 0\n"); +*/ + ret = wdcintr(&sc->sc_channel); + gayle.intreq = 0x7c | (intreq & 0x03); + } + + return ret; +} +