Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic Simplify regmap initialization, and fix an regmap...



details:   https://anonhg.NetBSD.org/src/rev/8cbfcd6466b0
branches:  trunk
changeset: 995954:8cbfcd6466b0
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Jan 11 23:10:40 2019 +0000

description:
Simplify regmap initialization, and fix an regmap issue that
affected TI OMAP (LCR register would get clobbered due to
using the wrong offset for the MDR1 register) reported by Lwazi Dube
(who also found the root cause).

diffstat:

 sys/arch/mips/alchemy/dev/com_aubus.c |  32 +++++++++++++++++-------------
 sys/arch/mips/ralink/ralink_com.c     |  36 +++++++++++++++++++---------------
 sys/dev/ic/com.c                      |  32 ++++++++++++++++++++++--------
 sys/dev/ic/comvar.h                   |  30 +++++++++++++++-------------
 sys/dev/ic/ns16550reg.h               |   8 ++++++-
 5 files changed, 84 insertions(+), 54 deletions(-)

diffs (256 lines):

diff -r af9ebc33d895 -r 8cbfcd6466b0 sys/arch/mips/alchemy/dev/com_aubus.c
--- a/sys/arch/mips/alchemy/dev/com_aubus.c     Fri Jan 11 20:41:53 2019 +0000
+++ b/sys/arch/mips/alchemy/dev/com_aubus.c     Fri Jan 11 23:10:40 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: com_aubus.c,v 1.8 2018/12/08 21:14:36 thorpej Exp $ */
+/* $NetBSD: com_aubus.c,v 1.9 2019/01/11 23:10:40 thorpej Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com_aubus.c,v 1.8 2018/12/08 21:14:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_aubus.c,v 1.9 2019/01/11 23:10:40 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -172,6 +172,21 @@
            AUCOM_MODCTL, 0);
 }
 
+static const bus_size_t com_aubus_regmap[COM_REGMAP_NENTRIES] = {
+       [COM_REG_RXDATA]        =       AUCOM_RXDATA,
+       [COM_REG_TXDATA]        =       AUCOM_TXDATA,
+       [COM_REG_DLBL]          =       AUCOM_DLB,
+       [COM_REG_DLBH]          =       AUCOM_DLB,
+       [COM_REG_IER]           =       AUCOM_IER,
+       [COM_REG_IIR]           =       AUCOM_IIR,
+       [COM_REG_FIFO]          =       AUCOM_FIFO,
+       [COM_REG_TCR]           =       AUCOM_FIFO,
+       [COM_REG_LCR]           =       AUCOM_LCTL,
+       [COM_REG_MCR]           =       AUCOM_MCR,
+       [COM_REG_LSR]           =       AUCOM_LSR,
+       [COM_REG_MSR]           =       AUCOM_MSR,
+};
+
 void
 com_aubus_init_regs(struct com_regs *regsp, bus_space_tag_t bst,
                    bus_space_handle_t bsh, bus_addr_t addr)
@@ -179,19 +194,8 @@
 
        com_init_regs(regsp, bst, bsh, addr);
 
+       memcpy(regsp->cr_map, com_aubus_regmap, sizeof(regsp->cr_map));
        regsp->cr_nports = AUCOM_NPORTS;
-       regsp->cr_map[COM_REG_RXDATA] = AUCOM_RXDATA;
-       regsp->cr_map[COM_REG_TXDATA] = AUCOM_TXDATA;
-       regsp->cr_map[COM_REG_DLBL] = AUCOM_DLB;
-       regsp->cr_map[COM_REG_DLBH] = AUCOM_DLB;
-       regsp->cr_map[COM_REG_IER] = AUCOM_IER;
-       regsp->cr_map[COM_REG_IIR] = AUCOM_IIR;
-       regsp->cr_map[COM_REG_FIFO] = AUCOM_FIFO;
-       regsp->cr_map[COM_REG_EFR] = 0;
-       regsp->cr_map[COM_REG_LCR] = AUCOM_LCTL;
-       regsp->cr_map[COM_REG_MCR] = AUCOM_MCR;
-       regsp->cr_map[COM_REG_LSR] = AUCOM_LSR;
-       regsp->cr_map[COM_REG_MSR] = AUCOM_MSR;
 }
 
 int
diff -r af9ebc33d895 -r 8cbfcd6466b0 sys/arch/mips/ralink/ralink_com.c
--- a/sys/arch/mips/ralink/ralink_com.c Fri Jan 11 20:41:53 2019 +0000
+++ b/sys/arch/mips/ralink/ralink_com.c Fri Jan 11 23:10:40 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ralink_com.c,v 1.7 2018/12/08 21:14:36 thorpej Exp $   */
+/*     $NetBSD: ralink_com.c,v 1.8 2019/01/11 23:10:40 thorpej Exp $   */
 /*-
  * Copyright (c) 2011 CradlePoint Technology, Inc.
  * All rights reserved.
@@ -130,7 +130,7 @@
 /* ralink_com.c -- Ralink 3052 uart console driver */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ralink_com.c,v 1.7 2018/12/08 21:14:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ralink_com.c,v 1.8 2019/01/11 23:10:40 thorpej Exp $");
 
 #include "locators.h"
 #include <sys/param.h>
@@ -367,6 +367,23 @@
        com_attach_subr(sc);
 }
 
+static const bus_size_t ralink_com_regmap[] = {
+       [COM_REG_RXDATA]        =       RA_UART_RBR,
+       [COM_REG_TXDATA]        =       RA_UART_TBR,
+       [COM_REG_DLBL]          =       RA_UART_DLL,
+#if defined(MT7628)
+       [COM_REG_DLBH]          =       RA_UART_DLM,
+#endif
+       [COM_REG_IER]           =       RA_UART_IER,
+       [COM_REG_IIR]           =       RA_UART_IIR,
+       [COM_REG_FIFO]          =       RA_UART_FCR,
+       [COM_REG_TCR]           =       RA_UART_FCR,
+       [COM_REG_LCR]           =       RA_UART_LCR,
+       [COM_REG_MCR]           =       RA_UART_MCR,
+       [COM_REG_LSR]           =       RA_UART_LSR,
+       [COM_REG_MSR]           =       RA_UART_MSR,
+};
+
 static void
 ralink_com_init_regs(struct com_regs *regsp, bus_space_tag_t st,
                     bus_space_handle_t sh, bus_addr_t addr)
@@ -374,20 +391,7 @@
 
        com_init_regs(regsp, st, sh, addr);
 
-       regsp->cr_map[COM_REG_RXDATA] = RA_UART_RBR;
-       regsp->cr_map[COM_REG_TXDATA] = RA_UART_TBR;
-       regsp->cr_map[COM_REG_DLBL]   = RA_UART_DLL;
-#if defined(MT7628)
-       regsp->cr_map[COM_REG_DLBH]   = RA_UART_DLM;
-#endif
-       regsp->cr_map[COM_REG_IER]    = RA_UART_IER;
-       regsp->cr_map[COM_REG_IIR]    = RA_UART_IIR;
-       regsp->cr_map[COM_REG_FIFO]   = RA_UART_FCR;
-       regsp->cr_map[COM_REG_LCR]    = RA_UART_LCR;
-       regsp->cr_map[COM_REG_MCR]    = RA_UART_MCR;
-       regsp->cr_map[COM_REG_LSR]    = RA_UART_LSR;
-       regsp->cr_map[COM_REG_MSR]    = RA_UART_MSR;
-
+       memcpy(regsp->cr_map, ralink_com_regmap, sizeof(regsp->cr_map));
        regsp->cr_nports = 32;
 }
 
diff -r af9ebc33d895 -r 8cbfcd6466b0 sys/dev/ic/com.c
--- a/sys/dev/ic/com.c  Fri Jan 11 20:41:53 2019 +0000
+++ b/sys/dev/ic/com.c  Fri Jan 11 23:10:40 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.354 2018/12/11 06:34:00 thorpej Exp $ */
+/* $NetBSD: com.c,v 1.355 2019/01/11 23:10:40 thorpej 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.354 2018/12/11 06:34:00 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.355 2019/01/11 23:10:40 thorpej Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -236,13 +236,27 @@
 #endif /* KGDB */
 
 /* initializer for typical 16550-ish hardware */
-#define        COM_REG_STD { \
-       com_data, com_data, com_dlbl, com_dlbh, com_ier, com_iir, com_fifo, \
-       com_efr, com_lcr, com_mcr, com_lsr, com_msr, 0, 0, 0, 0, 0, 0, 0, 0, \
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, com_usr, com_tfl, com_rfl, \
-       0, 0, 0, 0, 0, 0, 0, com_halt }
-
-static const bus_size_t com_std_map[42] = COM_REG_STD;
+static const bus_size_t com_std_map[COM_REGMAP_NENTRIES] = {
+       [COM_REG_RXDATA]        =       com_data,
+       [COM_REG_TXDATA]        =       com_data,
+       [COM_REG_DLBL]          =       com_dlbl,
+       [COM_REG_DLBH]          =       com_dlbh,
+       [COM_REG_IER]           =       com_ier,
+       [COM_REG_IIR]           =       com_iir,
+       [COM_REG_FIFO]          =       com_fifo,
+       [COM_REG_TCR]           =       com_fifo,
+       [COM_REG_EFR]           =       com_efr,
+       [COM_REG_TLR]           =       com_efr,
+       [COM_REG_LCR]           =       com_lcr,
+       [COM_REG_MCR]           =       com_mcr,
+       [COM_REG_LSR]           =       com_lsr,
+       [COM_REG_MSR]           =       com_msr,
+       [COM_REG_USR]           =       com_usr,
+       [COM_REG_TFL]           =       com_tfl,
+       [COM_REG_RFL]           =       com_rfl,
+       [COM_REG_HALT]          =       com_halt,
+       [COM_REG_MDR1]          =       com_mdr1,
+};
 
 #define        COMDIALOUT_MASK TTDIALOUT_MASK
 
diff -r af9ebc33d895 -r 8cbfcd6466b0 sys/dev/ic/comvar.h
--- a/sys/dev/ic/comvar.h       Fri Jan 11 20:41:53 2019 +0000
+++ b/sys/dev/ic/comvar.h       Fri Jan 11 23:10:40 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: comvar.h,v 1.91 2018/12/11 06:34:00 thorpej Exp $      */
+/*     $NetBSD: comvar.h,v 1.92 2019/01/11 23:10:41 thorpej Exp $      */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -83,25 +83,27 @@
 #define        COM_REG_IER             4
 #define        COM_REG_IIR             5
 #define        COM_REG_FIFO            6
-#define        COM_REG_TCR             6
-#define        COM_REG_EFR             7
-#define        COM_REG_TLR             7
-#define        COM_REG_LCR             8
-#define        COM_REG_MDR1            8
-#define        COM_REG_MCR             9
-#define        COM_REG_LSR             10
-#define        COM_REG_MSR             11
-#define        COM_REG_USR             31              /* 16750/DW APB */
-#define        COM_REG_TFL             com_tfl         /* DW APB */
-#define        COM_REG_RFL             com_rfl         /* DW APB */
-#define        COM_REG_HALT            com_halt        /* DW APB */
+#define        COM_REG_TCR             7
+#define        COM_REG_EFR             8
+#define        COM_REG_TLR             9
+#define        COM_REG_LCR             10
+#define        COM_REG_MCR             11
+#define        COM_REG_LSR             12
+#define        COM_REG_MSR             13
+#define        COM_REG_MDR1            14              /* TI OMAP */
+#define        COM_REG_USR             15              /* 16750/DW APB */
+#define        COM_REG_TFL             16              /* DW APB */
+#define        COM_REG_RFL             17              /* DW APB */
+#define        COM_REG_HALT            18              /* DW APB */
+
+#define        COM_REGMAP_NENTRIES     19
 
 struct com_regs {
        bus_space_tag_t         cr_iot;
        bus_space_handle_t      cr_ioh;
        bus_addr_t              cr_iobase;
        bus_size_t              cr_nports;
-       bus_size_t              cr_map[42];
+       bus_size_t              cr_map[COM_REGMAP_NENTRIES];
 };
 
 void   com_init_regs(struct com_regs *, bus_space_tag_t, bus_space_handle_t,
diff -r af9ebc33d895 -r 8cbfcd6466b0 sys/dev/ic/ns16550reg.h
--- a/sys/dev/ic/ns16550reg.h   Fri Jan 11 20:41:53 2019 +0000
+++ b/sys/dev/ic/ns16550reg.h   Fri Jan 11 23:10:40 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ns16550reg.h,v 1.12 2017/10/29 14:06:08 jmcneill Exp $ */
+/*     $NetBSD: ns16550reg.h,v 1.13 2019/01/11 23:10:41 thorpej Exp $  */
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -43,12 +43,18 @@
 #define        com_fifo        2       /* FIFO control (W) */
 #define        com_lctl        3       /* line control register (R/W) */
 #define        com_cfcr        3       /* line control register (R/W) */
+#define        com_lcr         com_cfcr
 #define        com_mcr         4       /* modem control register (R/W) */
 #define        com_lsr         5       /* line status register (R/W) */
 #define        com_msr         6       /* modem status register (R/W) */
 #define        com_scratch     7       /* scratch register (R/W) */
 
 /*
+ * Additional registers present on TI OMAP hardware
+ */
+#define        com_mdr1        8       /* mode definition register 1 (OMAP) */
+
+/*
  * Additional register present in NS16750 
  */
 #define com_usr                31      /* status register (R) (16750/SUNXI) */



Home | Main Index | Thread Index | Old Index