Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/mac68k PR port-mac68k/24883



details:   https://anonhg.NetBSD.org/src/rev/405ebbc6fd47
branches:  trunk
changeset: 457844:405ebbc6fd47
user:      rin <rin%NetBSD.org@localhost>
date:      Tue Jul 23 07:52:53 2019 +0000

description:
PR port-mac68k/24883

Style-only changes in preparation to import AV DMA code:

- G/C unused from esp_softc
- clean up headers:
    - prefer <sys/bus.h> over <machine/bus.h>
    - G/C unused
    - sort
- staticify private functions and variables
- stop using inline qualifier for functions called via function pointers
- use C99 initializer
- provide bus_space_vaddr(9) and use it, instead of using member of
  bus_handle_t directly
- use uint*_t:
    - u_char --> uint8_t
    - u_int*_t --> uint*_t
- use proper names from ncr53c9xreg.h instead of magic numbers
- and some KNF, and etc.

No functional changes intended.

diffstat:

 sys/arch/mac68k/include/bus.h |    9 +-
 sys/arch/mac68k/obio/esp.c    |  205 +++++++++++++++++++----------------------
 sys/arch/mac68k/obio/espvar.h |   11 +-
 3 files changed, 108 insertions(+), 117 deletions(-)

diffs (truncated from 500 to 300 lines):

diff -r 8ed0ff6bb971 -r 405ebbc6fd47 sys/arch/mac68k/include/bus.h
--- a/sys/arch/mac68k/include/bus.h     Tue Jul 23 07:46:22 2019 +0000
+++ b/sys/arch/mac68k/include/bus.h     Tue Jul 23 07:52:53 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus.h,v 1.26 2008/04/28 20:23:27 martin Exp $  */
+/*     $NetBSD: bus.h,v 1.27 2019/07/23 07:52:53 rin Exp $     */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -786,6 +786,13 @@
 #define        BUS_SPACE_BARRIER_READ  0x01            /* force read barrier */
 #define        BUS_SPACE_BARRIER_WRITE 0x02            /* force write barrier */
 
+/*
+ *     void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
+ *
+ * Get the kernel virtual address for the mapped bus space.
+ */
+#define        bus_space_vaddr(t, h)   ((void)(t), (void *)(h.base))
+
 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
 
 #include <m68k/bus_dma.h>
diff -r 8ed0ff6bb971 -r 405ebbc6fd47 sys/arch/mac68k/obio/esp.c
--- a/sys/arch/mac68k/obio/esp.c        Tue Jul 23 07:46:22 2019 +0000
+++ b/sys/arch/mac68k/obio/esp.c        Tue Jul 23 07:52:53 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: esp.c,v 1.56 2019/01/08 19:41:09 jdolecek Exp $        */
+/*     $NetBSD: esp.c,v 1.57 2019/07/23 07:52:53 rin Exp $     */
 
 /*
  * Copyright (c) 1997 Jason R. Thorpe.
@@ -77,38 +77,27 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.56 2019/01/08 19:41:09 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.57 2019/07/23 07:52:53 rin Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
+#include <sys/buf.h>
+#include <sys/bus.h>
 #include <sys/device.h>
-#include <sys/buf.h>
-#include <sys/proc.h>
-#include <sys/queue.h>
-#include <sys/mutex.h>
 
-#include <dev/scsipi/scsi_all.h>
-#include <dev/scsipi/scsipi_all.h>
 #include <dev/scsipi/scsiconf.h>
-#include <dev/scsipi/scsi_message.h>
-
-#include <machine/cpu.h>
-#include <machine/bus.h>
 
 #include <dev/ic/ncr53c9xreg.h>
 #include <dev/ic/ncr53c9xvar.h>
 
+#include <machine/cpu.h>
 #include <machine/viareg.h>
 
 #include <mac68k/obio/espvar.h>
 #include <mac68k/obio/obiovar.h>
 
-int    espmatch(device_t, cfdata_t, void *);
-void   espattach(device_t, device_t, void *);
+static int     espmatch(device_t, cfdata_t, void *);
+static void    espattach(device_t, device_t, void *);
 
 /* Linkup to the rest of the kernel */
 CFATTACH_DECL_NEW(esp, sizeof(struct esp_softc),
@@ -117,74 +106,74 @@
 /*
  * Functions and the switch for the MI code.
  */
-uint8_t        esp_read_reg(struct ncr53c9x_softc *, int);
-void   esp_write_reg(struct ncr53c9x_softc *, int, uint8_t);
-int    esp_dma_isintr(struct ncr53c9x_softc *);
-void   esp_dma_reset(struct ncr53c9x_softc *);
-int    esp_dma_intr(struct ncr53c9x_softc *);
-int    esp_dma_setup(struct ncr53c9x_softc *, uint8_t **, size_t *, int,
-           size_t *);
-void   esp_dma_go(struct ncr53c9x_softc *);
-void   esp_dma_stop(struct ncr53c9x_softc *);
-int    esp_dma_isactive(struct ncr53c9x_softc *);
-void   esp_quick_write_reg(struct ncr53c9x_softc *, int, u_char);
-int    esp_quick_dma_intr(struct ncr53c9x_softc *);
-int    esp_quick_dma_setup(struct ncr53c9x_softc *, uint8_t **, size_t *, int,
-            size_t *);
-void   esp_quick_dma_go(struct ncr53c9x_softc *);
+static uint8_t esp_read_reg(struct ncr53c9x_softc *, int);
+static void    esp_write_reg(struct ncr53c9x_softc *, int, uint8_t);
+static int     esp_dma_isintr(struct ncr53c9x_softc *);
+static void    esp_dma_reset(struct ncr53c9x_softc *);
+static int     esp_dma_intr(struct ncr53c9x_softc *);
+static int     esp_dma_setup(struct ncr53c9x_softc *, uint8_t **, size_t *,
+                       int, size_t *);
+static void    esp_dma_go(struct ncr53c9x_softc *);
+static void    esp_dma_stop(struct ncr53c9x_softc *);
+static int     esp_dma_isactive(struct ncr53c9x_softc *);
+static void    esp_quick_write_reg(struct ncr53c9x_softc *, int, uint8_t);
+static int     esp_quick_dma_intr(struct ncr53c9x_softc *);
+static int     esp_quick_dma_setup(struct ncr53c9x_softc *, uint8_t **,
+                       size_t *, int, size_t *);
+static void    esp_quick_dma_go(struct ncr53c9x_softc *);
 
-void   esp_intr(void *);
-void   esp_dualbus_intr(void *);
-static struct esp_softc                *esp0, *esp1;
+static void    esp_intr(void *);
+static void    esp_dualbus_intr(void *);
 
-static inline int esp_dafb_have_dreq(struct esp_softc *);
-static inline int esp_iosb_have_dreq(struct esp_softc *);
+static int     esp_dafb_have_dreq(struct esp_softc *);
+static int     esp_iosb_have_dreq(struct esp_softc *);
 int (*esp_have_dreq)(struct esp_softc *);
 
-struct ncr53c9x_glue esp_glue = {
-       esp_read_reg,
-       esp_write_reg,
-       esp_dma_isintr,
-       esp_dma_reset,
-       esp_dma_intr,
-       esp_dma_setup,
-       esp_dma_go,
-       esp_dma_stop,
-       esp_dma_isactive,
-       NULL,                   /* gl_clear_latched_intr */
+static struct esp_softc *esp0, *esp1;
+
+static struct ncr53c9x_glue esp_glue = {
+       .gl_read_reg = esp_read_reg,
+       .gl_write_reg = esp_write_reg,
+       .gl_dma_isintr = esp_dma_isintr,
+       .gl_dma_reset = esp_dma_reset,
+       .gl_dma_intr = esp_dma_intr,
+       .gl_dma_setup = esp_dma_setup,
+       .gl_dma_go = esp_dma_go,
+       .gl_dma_stop = esp_dma_stop,
+       .gl_dma_isactive = esp_dma_isactive,
+       .gl_clear_latched_intr = NULL,
 };
 
-int
+static int
 espmatch(device_t parent, cfdata_t cf, void *aux)
 {
        struct obio_attach_args *oa = aux;
 
-       if (oa->oa_addr == 0 && mac68k_machine.scsi96) {
+       if (oa->oa_addr == 0 && mac68k_machine.scsi96)
                return 1;
-       }
-       if (oa->oa_addr == 1 && mac68k_machine.scsi96_2) {
+       if (oa->oa_addr == 1 && mac68k_machine.scsi96_2)
                return 1;
-       }
        return 0;
 }
 
 /*
  * Attach this instance, and then all the sub-devices
  */
-void
+static void
 espattach(device_t parent, device_t self, void *aux)
 {
        struct esp_softc        *esc = device_private(self);
        struct ncr53c9x_softc   *sc = &esc->sc_ncr53c9x;
        struct obio_attach_args *oa = aux;
+       bus_addr_t              addr;
+       unsigned long           reg_offset;
        int                     quick = 0;
-       unsigned long           reg_offset;
+       uint8_t                 irq_mask;       /* mask for clearing IRQ */
        extern vaddr_t          SCSIBase;
 
        sc->sc_dev = self;
 
        reg_offset = SCSIBase - IOBase;
-       esc->sc_tag = oa->oa_tag;
 
        /*
         * For Wombat, Primus and Optimus motherboards, DREQ is
@@ -196,33 +185,34 @@
         * a (12-bit) configuration register for DAFB's control of the
         * pseudo-DMA timing.  The default value is 0x1d1.
         */
-       esp_have_dreq = esp_dafb_have_dreq;
        if (oa->oa_addr == 0) {
                if (reg_offset == 0x10000) {
                        quick = 1;
                        esp_have_dreq = esp_iosb_have_dreq;
-               } else if (reg_offset == 0x18000) {
+               } else if (reg_offset == 0x18000)
                        quick = 0;
-               } else {
-                       if (bus_space_map(esc->sc_tag, 0xf9800024,
-                                         4, 0, &esc->sc_bsh)) {
-                               aprint_error(": failed to map 4"
-                                   " at 0xf9800024.\n");
-                       } else {
-                               quick = 1;
-                               bus_space_write_4(esc->sc_tag,
-                                                 esc->sc_bsh, 0, 0x1d1);
-                       }
+               else {
+                       addr = 0xf9800024;
+                       goto dafb_dreq;
                }
        } else {
-               if (bus_space_map(esc->sc_tag, 0xf9800028,
-                                 4, 0, &esc->sc_bsh)) {
-                       aprint_error(": failed to map 4 at 0xf9800028.\n");
-               } else {
+               bus_space_tag_t bst;
+               bus_space_handle_t bsh;
+
+               addr = 0xf9800028;
+
+dafb_dreq:     bst = oa->oa_tag;
+               if (bus_space_map(bst, addr, 4, 0, &bsh))
+                       aprint_error(": failed to map 4 at 0x%lx.\n", addr);
+               else {
                        quick = 1;
-                       bus_space_write_4(esc->sc_tag, esc->sc_bsh, 0, 0x1d1);
+                       esp_have_dreq = esp_dafb_have_dreq;
+                       esc->sc_dreqreg = (volatile uint32_t *)
+                           bus_space_vaddr(bst, bsh);
+                       *esc->sc_dreqreg = 0x1d1;
                }
        }
+
        if (quick) {
                esp_glue.gl_write_reg = esp_quick_write_reg;
                esp_glue.gl_dma_intr = esp_quick_dma_intr;
@@ -243,28 +233,25 @@
 
                esc->sc_reg = (volatile uint8_t *)SCSIBase;
                via2_register_irq(VIA2_SCSIIRQ, esp_intr, esc);
-               esc->irq_mask = V2IF_SCSIIRQ;
+               irq_mask = V2IF_SCSIIRQ;
                if (reg_offset == 0x10000) {
                        /* From the Q650 developer's note */
                        sc->sc_freq = 16500000;
-               } else {
+               } else
                        sc->sc_freq = 25000000;
-               }
 
-               if (esp_glue.gl_dma_go == esp_quick_dma_go) {
+               if (quick)
                        aprint_normal(" (quick)");
-               }
        } else {
                esp1 = esc;
 
                esc->sc_reg = (volatile uint8_t *)SCSIBase + 0x402;
                via2_register_irq(VIA2_SCSIIRQ, esp_dualbus_intr, NULL);
-               esc->irq_mask = 0;
+               irq_mask = 0;
                sc->sc_freq = 25000000;
 
-               if (esp_glue.gl_dma_go == esp_quick_dma_go) {
+               if (quick)
                        printf(" (quick)");
-               }
        }
 
        aprint_normal(": address %p", esc->sc_reg);
@@ -313,10 +300,10 @@
        /*
         * Configure interrupts.
         */
-       if (esc->irq_mask) {
+       if (irq_mask) {
                via2_reg(vPCR) = 0x22;
-               via2_reg(vIFR) = esc->irq_mask;
-               via2_reg(vIER) = 0x80 | esc->irq_mask;
+               via2_reg(vIFR) = irq_mask;
+               via2_reg(vIER) = 0x80 | irq_mask;
        }
 
        /*
@@ -331,7 +318,7 @@
  * Glue functions.
  */
 
-uint8_t
+static uint8_t
 esp_read_reg(struct ncr53c9x_softc *sc, int reg)
 {
        struct esp_softc *esc = (struct esp_softc *)sc;



Home | Main Index | Thread Index | Old Index