Source-Changes-HG archive

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

[src/trunk]: src/sys/arch PR port-evbarm/40307 options KGDB doesn't work for ...



details:   https://anonhg.NetBSD.org/src/rev/e90e66f886f4
branches:  trunk
changeset: 1026385:e90e66f886f4
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sun Nov 21 08:44:28 2021 +0000

description:
PR port-evbarm/40307 options KGDB doesn't work for some evbarm hosts

Apply patch from Lloyd Parkes with some KNF tweaks from me.

diffstat:

 sys/arch/arm/ep93xx/epcom.c           |  158 ++++++++++++++++++++++++++-------
 sys/arch/arm/ep93xx/epcomvar.h        |    3 +-
 sys/arch/evbarm/tsarm/tsarm_machdep.c |    8 +-
 3 files changed, 131 insertions(+), 38 deletions(-)

diffs (279 lines):

diff -r c935910f1065 -r e90e66f886f4 sys/arch/arm/ep93xx/epcom.c
--- a/sys/arch/arm/ep93xx/epcom.c       Sun Nov 21 08:25:26 2021 +0000
+++ b/sys/arch/arm/ep93xx/epcom.c       Sun Nov 21 08:44:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: epcom.c,v 1.33 2021/11/21 08:25:26 skrll Exp $ */
+/*     $NetBSD: epcom.c,v 1.34 2021/11/21 08:44:28 skrll Exp $ */
 /*
  * Copyright (c) 1998, 1999, 2001, 2002, 2004 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: epcom.c,v 1.33 2021/11/21 08:25:26 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: epcom.c,v 1.34 2021/11/21 08:44:28 skrll Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -144,9 +144,13 @@
        bus_addr_t              sc_hwbase;
        int                     sc_ospeed;
        tcflag_t                sc_cflag;
-       int                     sc_attached;
 } epcomcn_sc;
 
+static int     epcom_common_getc(struct epcom_cons_softc *, dev_t);
+static void    epcom_common_putc(struct epcom_cons_softc *, int);
+static void    epcominit(struct epcom_cons_softc *, bus_space_tag_t,
+                         bus_addr_t, bus_space_handle_t, int, tcflag_t);
+
 static struct cnm_state epcom_cnm_state;
 
 extern struct cfdriver epcom_cd;
@@ -180,6 +184,19 @@
        NULL, NULL, NODEV, CN_NORMAL
 };
 
+#if defined(KGDB)
+#include <sys/kgdb.h>
+
+static int     epcom_kgdb_getc(void *);
+static void    epcom_kgdb_putc(void *, int);
+
+/*
+ * Reuse the console softc structure because
+ * we'll be reusing the console I/O code.
+ */
+static struct epcom_cons_softc kgdb_sc;
+#endif
+
 #ifndef DEFAULT_COMSPEED
 #define DEFAULT_COMSPEED 115200
 #endif
@@ -197,7 +214,6 @@
 
        if (sc->sc_iot == epcomcn_sc.sc_iot
            && sc->sc_hwbase == epcomcn_sc.sc_hwbase) {
-               epcomcn_sc.sc_attached = 1;
                sc->sc_lcrlo = EPCOMSPEED2BRD(epcomcn_sc.sc_ospeed) & 0xff;
                sc->sc_lcrmid = EPCOMSPEED2BRD(epcomcn_sc.sc_ospeed) >> 8;
 
@@ -236,6 +252,18 @@
                aprint_normal("%s: console\n", device_xname(sc->sc_dev));
        }
 
+#ifdef KGDB
+       /*
+        * Allow kgdb to "take over" this port.  If this is
+        * the kgdb device, it has exclusive use.
+        */
+       if (sc->sc_iot == kgdb_sc.sc_iot &&
+           sc->sc_hwbase == kgdb_sc.sc_hwbase) {
+               SET(sc->sc_hwflags, COM_HW_KGDB);
+               printf("%s: kgdb\n", sc->sc_dev.dv_xname);
+       }
+#endif
+
        sc->sc_si = softint_establish(SOFTINT_SERIAL, epcomsoft, sc);
 
 #ifdef RND_COM
@@ -786,35 +814,11 @@
 epcomcnattach(bus_space_tag_t iot, bus_addr_t iobase, bus_space_handle_t ioh,
     int ospeed, tcflag_t cflag)
 {
-       u_int lcrlo, lcrmid, lcrhi, ctrl, pwrcnt;
-       bus_space_handle_t syscon_ioh;
-
        cn_tab = &epcomcons;
        cn_init_magic(&epcom_cnm_state);
        cn_set_magic("\047\001");
 
-       epcomcn_sc.sc_iot = iot;
-       epcomcn_sc.sc_ioh = ioh;
-       epcomcn_sc.sc_hwbase = iobase;
-       epcomcn_sc.sc_ospeed = ospeed;
-       epcomcn_sc.sc_cflag = cflag;
-
-       lcrhi = cflag2lcrhi(cflag);
-       lcrlo = EPCOMSPEED2BRD(ospeed) & 0xff;
-       lcrmid = EPCOMSPEED2BRD(ospeed) >> 8;
-       ctrl = Ctrl_UARTE;
-
-       bus_space_map(iot, EP93XX_APB_HWBASE + EP93XX_APB_SYSCON,
-               EP93XX_APB_SYSCON_SIZE, 0, &syscon_ioh);
-       pwrcnt = bus_space_read_4(iot, syscon_ioh, EP93XX_SYSCON_PwrCnt);
-       pwrcnt &= ~(PwrCnt_UARTBAUD);
-       bus_space_write_4(iot, syscon_ioh, EP93XX_SYSCON_PwrCnt, pwrcnt);
-       bus_space_unmap(iot, syscon_ioh, EP93XX_APB_SYSCON_SIZE);
-
-       bus_space_write_4(iot, ioh, EPCOM_LinCtrlLow, lcrlo);
-       bus_space_write_4(iot, ioh, EPCOM_LinCtrlMid, lcrmid);
-       bus_space_write_4(iot, ioh, EPCOM_LinCtrlHigh, lcrhi);
-       bus_space_write_4(iot, ioh, EPCOM_Ctrl, ctrl);
+       epcominit(&epcomcn_sc, iot, iobase, ioh, ospeed, cflag);
 
        return (0);
 }
@@ -833,9 +837,15 @@
 void
 epcomcnputc(dev_t dev, int c)
 {
+       epcom_common_putc(&epcomcn_sc, c);
+}
+
+static void
+epcom_common_putc(struct epcom_cons_softc *sc, int c)
+{
        int                     s;
-       bus_space_tag_t         iot = epcomcn_sc.sc_iot;
-       bus_space_handle_t      ioh = epcomcn_sc.sc_ioh;
+       bus_space_tag_t         iot = sc->sc_iot;
+       bus_space_handle_t      ioh = sc->sc_ioh;
 
        s = splserial();
 
@@ -857,10 +867,16 @@
 int
 epcomcngetc(dev_t dev)
 {
+       return epcom_common_getc (&epcomcn_sc, dev);
+}
+
+static int
+epcom_common_getc(struct epcom_cons_softc *sc, dev_t dev)
+{
        int                     c, sts;
        int                     s;
-       bus_space_tag_t         iot = epcomcn_sc.sc_iot;
-       bus_space_handle_t      ioh = epcomcn_sc.sc_ioh;
+       bus_space_tag_t         iot = sc->sc_iot;
+       bus_space_handle_t      ioh = sc->sc_ioh;
 
         s = splserial();
 
@@ -1138,3 +1154,79 @@
 #endif
        return (1);
 }
+
+#ifdef KGDB
+int
+epcom_kgdb_attach(bus_space_tag_t iot, bus_addr_t iobase, int rate,
+                 tcflag_t cflag)
+{
+       bus_space_handle_t ioh;
+
+       if (iot == epcomcn_sc.sc_iot && iobase == epcomcn_sc.sc_hwbase) {
+#if !defined(DDB)
+               return EBUSY; /* cannot share with console */
+#else
+               /*
+                * XXX I have no intention of ever testing and code path
+                * implied by getting here
+                */
+               kgdb_sc = epcomcn_sc;
+#endif
+       } else {
+               bus_space_map(iot, iobase, EP93XX_APB_UART_SIZE, 0, &ioh);
+               epcominit(&kgdb_sc, iot, iobase, ioh, rate, cflag);
+       }
+
+       kgdb_attach(epcom_kgdb_getc, epcom_kgdb_putc, &kgdb_sc);
+       kgdb_dev = 123; /* unneeded, only to satisfy some tests */
+
+       return 0;
+}
+
+static int
+epcom_kgdb_getc (void *sc)
+{
+       return epcom_common_getc(sc, NODEV);
+}
+
+static void
+epcom_kgdb_putc (void *sc, int c)
+{
+       epcom_common_putc(sc, c);
+}
+#endif /* KGDB */
+
+/*
+ * Common code used for initialisation of the console or KGDB connection
+ */
+static void
+epcominit(struct epcom_cons_softc *sc, bus_space_tag_t iot,
+         bus_addr_t iobase, bus_space_handle_t ioh, int rate, tcflag_t cflag)
+{
+       u_int lcrlo, lcrmid, lcrhi, ctrl, pwrcnt;
+       bus_space_handle_t syscon_ioh;
+
+       sc->sc_iot = iot;
+       sc->sc_ioh = ioh;
+       sc->sc_hwbase = iobase;
+       sc->sc_ospeed = rate;
+       sc->sc_cflag = cflag;
+
+       lcrhi = cflag2lcrhi(cflag);
+       lcrlo = EPCOMSPEED2BRD(rate) & 0xff;
+       lcrmid = EPCOMSPEED2BRD(rate) >> 8;
+       ctrl = Ctrl_UARTE;
+
+       /* Make sure the UARTs are clocked at the system default rate */
+       bus_space_map(iot, EP93XX_APB_HWBASE + EP93XX_APB_SYSCON,
+               EP93XX_APB_SYSCON_SIZE, 0, &syscon_ioh);
+       pwrcnt = bus_space_read_4(iot, syscon_ioh, EP93XX_SYSCON_PwrCnt);
+       pwrcnt &= ~(PwrCnt_UARTBAUD);
+       bus_space_write_4(iot, syscon_ioh, EP93XX_SYSCON_PwrCnt, pwrcnt);
+       bus_space_unmap(iot, syscon_ioh, EP93XX_APB_SYSCON_SIZE);
+
+       bus_space_write_4(iot, ioh, EPCOM_LinCtrlLow, lcrlo);
+       bus_space_write_4(iot, ioh, EPCOM_LinCtrlMid, lcrmid);
+       bus_space_write_4(iot, ioh, EPCOM_LinCtrlHigh, lcrhi);
+       bus_space_write_4(iot, ioh, EPCOM_Ctrl, ctrl);
+}
diff -r c935910f1065 -r e90e66f886f4 sys/arch/arm/ep93xx/epcomvar.h
--- a/sys/arch/arm/ep93xx/epcomvar.h    Sun Nov 21 08:25:26 2021 +0000
+++ b/sys/arch/arm/ep93xx/epcomvar.h    Sun Nov 21 08:44:28 2021 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: epcomvar.h,v 1.8 2015/04/14 20:32:35 riastradh Exp $        */
+/*      $NetBSD: epcomvar.h,v 1.9 2021/11/21 08:44:28 skrll Exp $        */
 /*-
  * Copyright (c) 2004 Jesse Off
  *
@@ -96,5 +96,6 @@
 int    epcomintr(void* arg);
 int    epcomcnattach(bus_space_tag_t, bus_addr_t, bus_space_handle_t,
                       int, tcflag_t);
+int    epcom_kgdb_attach(bus_space_tag_t, bus_addr_t, int, tcflag_t);
 
 #endif /* _EPCOMVAR_H_ */
diff -r c935910f1065 -r e90e66f886f4 sys/arch/evbarm/tsarm/tsarm_machdep.c
--- a/sys/arch/evbarm/tsarm/tsarm_machdep.c     Sun Nov 21 08:25:26 2021 +0000
+++ b/sys/arch/evbarm/tsarm/tsarm_machdep.c     Sun Nov 21 08:44:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tsarm_machdep.c,v 1.32 2021/08/17 22:00:29 andvar Exp $ */
+/*     $NetBSD: tsarm_machdep.c,v 1.33 2021/11/21 08:44:28 skrll Exp $ */
 
 /*
  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsarm_machdep.c,v 1.32 2021/08/17 22:00:29 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsarm_machdep.c,v 1.33 2021/11/21 08:44:28 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_console.h"
@@ -829,8 +829,8 @@
 #if KGDB
 #if NEPCOM > 0
        if (strcmp(kgdb_devname, "epcom") == 0) {
-               com_kgdb_attach(&ep93xx_bs_tag, kgdb_devaddr, kgdb_devrate,
-                       kgdb_devmode);
+               epcom_kgdb_attach(&ep93xx_bs_tag, kgdb_devaddr, kgdb_devrate,
+                                 kgdb_devmode);
        }
 #endif /* NEPCOM > 0 */
 #endif /* KGDB */



Home | Main Index | Thread Index | Old Index