Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic com: Add support for 32-bit IO accesses.



details:   https://anonhg.NetBSD.org/src/rev/aee257f1c658
branches:  trunk
changeset: 1025557:aee257f1c658
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Nov 12 21:57:13 2021 +0000

description:
com: Add support for 32-bit IO accesses.

diffstat:

 sys/dev/ic/com.c    |  117 ++++++++++++++++++++++++++++++++++++++++++++++++---
 sys/dev/ic/comvar.h |   10 ++++-
 2 files changed, 118 insertions(+), 9 deletions(-)

diffs (194 lines):

diff -r 13120854bcde -r aee257f1c658 sys/dev/ic/com.c
--- a/sys/dev/ic/com.c  Fri Nov 12 21:55:46 2021 +0000
+++ b/sys/dev/ic/com.c  Fri Nov 12 21:57:13 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.372 2021/10/30 11:43:17 jmcneill Exp $ */
+/* $NetBSD: com.c,v 1.373 2021/11/12 21:57:13 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.372 2021/10/30 11:43:17 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.373 2021/11/12 21:57:13 jmcneill Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -128,17 +128,20 @@
 
 #include "ioconf.h"
 
+#define        CSR_READ_1(r, o)        \
+       (r)->cr_read((r), (r)->cr_map[o])
 #define        CSR_WRITE_1(r, o, v)    \
-       bus_space_write_1((r)->cr_iot, (r)->cr_ioh, (r)->cr_map[o], v)
-#define        CSR_READ_1(r, o)        \
-       bus_space_read_1((r)->cr_iot, (r)->cr_ioh, (r)->cr_map[o])
+       (r)->cr_write((r), (r)->cr_map[o], (v))
+#define        CSR_WRITE_MULTI(r, o, p, n)     \
+       (r)->cr_write_multi((r), (r)->cr_map[o], (p), (n))
+
+/*
+ * XXX COM_TYPE_AU1x00 specific
+ */
 #define        CSR_WRITE_2(r, o, v)    \
        bus_space_write_2((r)->cr_iot, (r)->cr_ioh, (r)->cr_map[o], v)
 #define        CSR_READ_2(r, o)        \
        bus_space_read_2((r)->cr_iot, (r)->cr_ioh, (r)->cr_map[o])
-#define        CSR_WRITE_MULTI(r, o, p, n)     \
-       bus_space_write_multi_1((r)->cr_iot, (r)->cr_ioh, (r)->cr_map[o], p, n)
-
 
 static void com_enable_debugport(struct com_softc *);
 
@@ -275,6 +278,70 @@
        bus_space_barrier((r)->cr_iot, (r)->cr_ioh, 0, (r)->cr_nports, (f))
 
 /*
+ * com_read_1 --
+ *     Default register read callback using single byte accesses.
+ */
+static uint8_t
+com_read_1(struct com_regs *regs, u_int reg)
+{
+       return bus_space_read_1(regs->cr_iot, regs->cr_ioh, reg);
+}
+
+/*
+ * com_write_1 --
+ *     Default register write callback using single byte accesses.
+ */
+static void
+com_write_1(struct com_regs *regs, u_int reg, uint8_t val)
+{
+       bus_space_write_1(regs->cr_iot, regs->cr_ioh, reg, val);
+}
+
+/*
+ * com_write_multi_1 --
+ *     Default register multi write callback using single byte accesses.
+ */
+static void
+com_write_multi_1(struct com_regs *regs, u_int reg, const uint8_t *datap,
+    bus_size_t count)
+{
+       bus_space_write_multi_1(regs->cr_iot, regs->cr_ioh, reg, datap, count);
+}
+
+/*
+ * com_read_4 --
+ *     Default register read callback using dword accesses.
+ */
+static uint8_t
+com_read_4(struct com_regs *regs, u_int reg)
+{
+       return bus_space_read_4(regs->cr_iot, regs->cr_ioh, reg) & 0xff;
+}
+
+/*
+ * com_write_4 --
+ *     Default register write callback using dword accesses.
+ */
+static void
+com_write_4(struct com_regs *regs, u_int reg, uint8_t val)
+{
+       bus_space_write_4(regs->cr_iot, regs->cr_ioh, reg, val);
+}
+
+/*
+ * com_write_multi_4 --
+ *     Default register multi write callback using dword accesses.
+ */
+static void
+com_write_multi_4(struct com_regs *regs, u_int reg, const uint8_t *datap,
+    bus_size_t count)
+{
+       while (count-- > 0) {
+               bus_space_write_4(regs->cr_iot, regs->cr_ioh, reg, *datap++);
+       }
+}
+
+/*
  * com_init_regs --
  *     Driver front-ends use this to initialize our register map
  *     in the standard fashion.  They may then tailor the map to
@@ -290,6 +357,9 @@
        regs->cr_ioh = sh;
        regs->cr_iobase = addr;
        regs->cr_nports = COM_NPORTS;
+       regs->cr_read = com_read_1;
+       regs->cr_write = com_write_1;
+       regs->cr_write_multi = com_write_multi_1;
        memcpy(regs->cr_map, com_std_map, sizeof(regs->cr_map));
 }
 
@@ -310,6 +380,37 @@
        regs->cr_nports <<= regshift;
 }
 
+/*
+ * com_init_regs_stride_width --
+ *     Convenience function for front-ends that have a stride between
+ *     registers and specific I/O width requirements.
+ */
+void
+com_init_regs_stride_width(struct com_regs *regs, bus_space_tag_t st,
+                          bus_space_handle_t sh, bus_addr_t addr,
+                          u_int regshift, u_int width)
+{
+
+       com_init_regs(regs, st, sh, addr);
+       for (size_t i = 0; i < __arraycount(regs->cr_map); i++) {
+               regs->cr_map[i] <<= regshift;
+       }
+       regs->cr_nports <<= regshift;
+
+       switch (width) {
+       case 1:
+               /* Already set by com_init_regs */
+               break;
+       case 4:
+               regs->cr_read = com_read_4;
+               regs->cr_write = com_write_4;
+               regs->cr_write_multi = com_write_multi_4;
+               break;
+       default:
+               panic("com: unsupported I/O width %d", width);
+       }
+}
+
 /*ARGSUSED*/
 int
 comspeed(long speed, long frequency, int type)
diff -r 13120854bcde -r aee257f1c658 sys/dev/ic/comvar.h
--- a/sys/dev/ic/comvar.h       Fri Nov 12 21:55:46 2021 +0000
+++ b/sys/dev/ic/comvar.h       Fri Nov 12 21:57:13 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: comvar.h,v 1.95 2021/10/12 00:21:34 thorpej Exp $      */
+/*     $NetBSD: comvar.h,v 1.96 2021/11/12 21:57:13 jmcneill Exp $     */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -103,12 +103,20 @@
        bus_addr_t              cr_iobase;
        bus_size_t              cr_nports;
        bus_size_t              cr_map[COM_REGMAP_NENTRIES];
+       uint8_t                 (*cr_read)(struct com_regs *, u_int);
+       void                    (*cr_write)(struct com_regs *, u_int, uint8_t);
+       void                    (*cr_write_multi)(struct com_regs *, u_int,
+                                                 const uint8_t *,
+                                                 bus_size_t);
+       
 };
 
 void   com_init_regs(struct com_regs *, bus_space_tag_t, bus_space_handle_t,
                      bus_addr_t);
 void   com_init_regs_stride(struct com_regs *, bus_space_tag_t,
                             bus_space_handle_t, bus_addr_t, u_int);
+void   com_init_regs_stride_width(struct com_regs *, bus_space_tag_t,
+                                  bus_space_handle_t, bus_addr_t, u_int, u_int);
 
 struct comcons_info {
        struct com_regs regs;



Home | Main Index | Thread Index | Old Index