Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/amiga Rework handling of Commodore Gayle chip. Avoi...



details:   https://anonhg.NetBSD.org/src/rev/7fcb4ed24ef3
branches:  trunk
changeset: 325670:7fcb4ed24ef3
user:      rkujawa <rkujawa%NetBSD.org@localhost>
date:      Fri Jan 03 00:33:06 2014 +0000

description:
Rework handling of Commodore Gayle chip. Avoid ugly struct casts, introduce
proper bus_space accesses and some abstraction layer. All drivers that utilised
Gayle also had to be refactored.

I tried not to break anything more, but this clearly needs more testing...

diffstat:

 sys/arch/amiga/amiga/amiga_bus_simple_0x1000.c |   38 +++++
 sys/arch/amiga/amiga/gayle.c                   |  183 +++++++++++++++++++++++-
 sys/arch/amiga/amiga/gayle.h                   |   93 +++++++-----
 sys/arch/amiga/conf/files.amiga                |    7 +-
 sys/arch/amiga/dev/acafhreg.h                  |    6 +-
 sys/arch/amiga/dev/efa.c                       |   12 +-
 sys/arch/amiga/dev/efareg.h                    |    3 +-
 sys/arch/amiga/dev/gayle_pcmcia.c              |   44 +++---
 sys/arch/amiga/dev/wdc_acafh.c                 |   20 +-
 sys/arch/amiga/dev/wdc_amiga.c                 |   37 ++--
 sys/arch/amiga/include/bus.h                   |    3 +-
 11 files changed, 334 insertions(+), 112 deletions(-)

diffs (truncated from 759 to 300 lines):

diff -r d593b353337f -r 7fcb4ed24ef3 sys/arch/amiga/amiga/amiga_bus_simple_0x1000.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amiga/amiga/amiga_bus_simple_0x1000.c    Fri Jan 03 00:33:06 2014 +0000
@@ -0,0 +1,38 @@
+/* $NetBSD: amiga_bus_simple_0x1000.c,v 1.1 2014/01/03 00:33:06 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_0x1000.c,v 1.1 2014/01/03 00:33:06 rkujawa Exp $");
+
+#define AMIGA_SIMPLE_BUS_STRIDE 0x1000         /* 1 byte per 0x1000 bytes */
+#define AMIGA_SIMPLE_BUS_WORD_METHODS
+
+#include "simple_busfuncs.c"
diff -r d593b353337f -r 7fcb4ed24ef3 sys/arch/amiga/amiga/gayle.c
--- a/sys/arch/amiga/amiga/gayle.c      Fri Jan 03 00:02:01 2014 +0000
+++ b/sys/arch/amiga/amiga/gayle.c      Fri Jan 03 00:33:06 2014 +0000
@@ -1,30 +1,193 @@
-/*     $NetBSD: gayle.c,v 1.6 2005/12/11 12:16:26 christos Exp $       */
+/*     $NetBSD: gayle.c,v 1.7 2014/01/03 00:33:06 rkujawa Exp $        */
 
 /* public domain */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gayle.c,v 1.6 2005/12/11 12:16:26 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gayle.c,v 1.7 2014/01/03 00:33:06 rkujawa Exp $");
 
 /*
- * Gayle management routines
+ * Gayle management - provide functions for use in the drivers that utilise
+ * the chip.
  *
- *   Any module that uses gayle should call gayle_init() before using anything
- *   related to gayle. gayle_init() can be called multiple times.
+ * These overly complicated routines try to deal with a few variants of
+ * Gayle chip that exists. 
  */
+#include <sys/bus.h>
+#include <sys/systm.h>
+
+#include <machine/cpu.h>
 
 #include <amiga/amiga/gayle.h>
 #include <amiga/dev/zbusvar.h>
 
-struct gayle_struct *gayle_base_virtual_address = 0;
+/* #define GAYLE_DEBUG 1 */
+
+struct gayle_tag {
+       struct bus_space_tag gayle_io_bst;
+       bus_space_tag_t gayle_io_t;
+       bus_space_handle_t gayle_io_h;
+
+       struct bus_space_tag gayle_isr_bst;
+       bus_space_tag_t gayle_isr_t;
+       bus_space_handle_t gayle_isr_h;
+};
 
-#define GAYLE_PHYS_ADDRESS      0xda8000
+typedef struct gayle_tag *gayle_tag_t;
 
+/*
+ * Having these as static variables is ugly, but they don't fit into
+ * driver's softc, as the chip might be utilised by many different drivers.
+ * And since we can only have one Gayle per system it should be okay.
+ */
+static struct gayle_tag gayle;
+static gayle_tag_t gayle_t = NULL;
+
+/*
+ * Any module that uses gayle should call gayle_init() before using anything
+ *   related to gayle. gayle_init() can be called multiple times.
+ */
 void
 gayle_init(void) {
+       bus_addr_t gayle_vbase;
 
-       if (gayle_base_virtual_address != 0)
+       if (gayle_t != NULL)
                return;
 
-       gayle_base_virtual_address =
-           (struct gayle_struct *) __UNVOLATILE(ztwomap(GAYLE_PHYS_ADDRESS));
+#ifdef GAYLE_DEBUG
+       aprint_normal("gayle: doing init\n");
+#endif /* GAYLE_DEBUG */
+
+       gayle_t = &gayle;
+
+       gayle_vbase = (bus_addr_t) __UNVOLATILE(ztwomap(GAYLE_REGS_BASE));
+
+       gayle_t->gayle_io_bst.base = gayle_vbase;
+       gayle_t->gayle_io_bst.absm = &amiga_bus_stride_0x1000;
+       gayle_t->gayle_io_t = &(gayle_t->gayle_io_bst);
+
+       bus_space_map(gayle_t->gayle_io_t, 0, 0x4, 0, &gayle_t->gayle_io_h);
+
+       /* 
+        * The A4000 variant of Gayle has interrupt status register at offset
+        * +0x1000 from IDE registers.
+        * XXX: in fact, on A4000 we should initialise only this part...
+        */
+       if (is_a4000()) {
+               gayle_t->gayle_isr_bst.base = (bus_addr_t) __UNVOLATILE(ztwomap(
+                   GAYLE_IDE_BASE_A4000+GAYLE_IDE_INTREQ_A4000));
+
+               gayle_t->gayle_io_bst.absm = &amiga_bus_stride_1;
+               gayle_t->gayle_isr_t = &(gayle_t->gayle_isr_bst);
+       } else {
+               bus_space_subregion(gayle_t->gayle_io_t, gayle_t->gayle_io_h, 
+                   GAYLE_INTREQ, 0x1, &(gayle_t->gayle_isr_h));
+
+               gayle_t->gayle_isr_bst = gayle_t->gayle_io_bst;
+               gayle_t->gayle_isr_t = gayle_t->gayle_io_t;
+       }
+
+}
+
+uint8_t 
+gayle_intr_status(void)
+{
+       uint8_t rv;
+
+       rv = bus_space_read_1(gayle_t->gayle_isr_t, gayle_t->gayle_isr_h, 0); 
+#ifdef GAYLE_DEBUG
+       aprint_normal("gayle: intr status %x\n", rv);
+#endif /* GAYLE_DEBUG */
+
+       return rv;
+}
+
+uint8_t
+gayle_intr_enable_read(void)
+{
+       uint8_t rv;
+
+       rv = bus_space_read_1(gayle_t->gayle_io_t, gayle_t->gayle_io_h, 
+           GAYLE_INTENA);
+#ifdef GAYLE_DEBUG
+       aprint_normal("gayle: intr enable register read %x\n", rv);
+#endif /* GAYLE_DEBUG */
+
+       return rv;
 }
+
+void
+gayle_intr_enable_write(uint8_t val)
+{
+#ifdef GAYLE_DEBUG
+       aprint_normal("gayle: intr enable register write %x\n", val);
+#endif /* GAYLE_DEBUG */
+       bus_space_write_1(gayle_t->gayle_io_t, gayle_t->gayle_io_h, 
+           GAYLE_INTENA, val);
+}
+
+void
+gayle_intr_enable_set(uint8_t bits)
+{
+       uint8_t val;
+       val = gayle_intr_enable_read();
+       gayle_intr_enable_write(val | bits);
+}
+
+void 
+gayle_intr_ack(uint8_t val)
+{
+#ifdef GAYLE_DEBUG
+       aprint_normal("gayle: intr ack write %x\n", val);
+#endif /* GAYLE_DEBUG */
+       bus_space_write_1(gayle_t->gayle_io_t, gayle_t->gayle_io_h, 
+           GAYLE_INTREQ, val);
+}
+
+uint8_t
+gayle_pcmcia_status_read(void)
+{
+       uint8_t rv;
+
+       rv = bus_space_read_1(gayle_t->gayle_io_t, gayle_t->gayle_io_h, 
+           GAYLE_PCC_STATUS);
+#ifdef GAYLE_DEBUG
+       aprint_normal("gayle: pcmcia status read %x\n", rv);
+#endif /* GAYLE_DEBUG */
+
+       return rv;
+}
+
+void 
+gayle_pcmcia_status_write(uint8_t val)
+{
+#ifdef GAYLE_DEBUG
+       aprint_normal("gayle: pcmcia status write %x\n", val);
+#endif /* GAYLE_DEBUG */
+       bus_space_write_1(gayle_t->gayle_io_t, gayle_t->gayle_io_h, 
+           GAYLE_PCC_STATUS, val);
+}
+
+void 
+gayle_pcmcia_config_write(uint8_t val)
+{
+#ifdef GAYLE_DEBUG
+       aprint_normal("gayle: pcmcia config write %x\n", val);
+#endif /* GAYLE_DEBUG */
+       bus_space_write_1(gayle_t->gayle_io_t, gayle_t->gayle_io_h, 
+           GAYLE_PCC_CONFIG, val);
+}
+
+uint8_t
+gayle_pcmcia_config_read(void)
+{
+       uint8_t rv;
+
+       rv = bus_space_read_1(gayle_t->gayle_io_t, gayle_t->gayle_io_h, 
+           GAYLE_PCC_CONFIG);
+#ifdef GAYLE_DEBUG
+       aprint_normal("gayle: pcmcia config read %x\n", rv);
+#endif /* GAYLE_DEBUG */
+
+       return rv;
+}
+
diff -r d593b353337f -r 7fcb4ed24ef3 sys/arch/amiga/amiga/gayle.h
--- a/sys/arch/amiga/amiga/gayle.h      Fri Jan 03 00:02:01 2014 +0000
+++ b/sys/arch/amiga/amiga/gayle.h      Fri Jan 03 00:33:06 2014 +0000
@@ -1,58 +1,73 @@
-/*     $NetBSD: gayle.h,v 1.2 2002/01/26 13:24:54 aymeric Exp $        */
+/*     $NetBSD: gayle.h,v 1.3 2014/01/03 00:33:06 rkujawa Exp $        */
 #ifndef AMIGA_GAYLE_H_
 #define AMIGA_GAYLE_H_
 
 #include <sys/types.h>
 
-struct gayle_struct {
-       volatile u_int8_t       pcc_status;
+#define GAYLE_IDE_BASE          0xDA0000
+#define GAYLE_IDE_BASE_A4000   0xDD2020
+#define GAYLE_IDE_INTREQ_A4000         0x1000  /* with stride of 1 */
+
+#define GAYLE_REGS_BASE                0xDA8000
+
+#define GAYLE_PCC_STATUS               0x0
+
 /* Depending on the mode the card is in, most of the bits have different
    meanings */
-#define GAYLE_CCMEM_DETECT     0x40
-#define GAYLE_CCMEM_BVD1       0x20
-#define GAYLE_CCMEM_BVD2       0x10
-#define GAYLE_CCMEM_WP         0x08
-#define GAYLE_CCMEM_BUSY       0x04
+#define GAYLE_CCMEM_DETECT                     __BIT(6)        
+#define GAYLE_CCMEM_BVD1                       __BIT(5)
+#define GAYLE_CCMEM_BVD2                       __BIT(4)
+#define GAYLE_CCMEM_WP                         __BIT(3)
+#define GAYLE_CCMEM_BUSY                       __BIT(2)
 
-#define GAYLE_CCIO_STSCHG      0x20
-#define GAYLE_CCIO_SPKR                0x10
-#define GAYLE_CCIO_IREQ                0x04
+#define GAYLE_CCIO_STSCHG                      __BIT(5)
+#define GAYLE_CCIO_SPKR                                __BIT(4)        
+#define GAYLE_CCIO_IREQ                                __BIT(2)        
 
-       u_int8_t __pad0[0xfff];
-       volatile u_int8_t       intreq;
+#define GAYLE_INTREQ                   0x1 /* 0x1000 */
+#define GAYLE_INTENA                   0x2 /* 0x2000 */
 
-       u_int8_t __pad1[0xfff];
-       volatile u_int8_t       intena;
-#define GAYLE_INT_IDE          0x80
-#define GAYLE_INT_DETECT       0x40
-#define GAYLE_INT_BVD1         0x20



Home | Main Index | Thread Index | Old Index