The Ryzen Embedded V1000 processors have an arm64-style Synposys
DesignWare UART instead if a PC-compatible NS16x50 UART.  To make this
UART work as a serial console, we need to pass some more information
from the bootloader to the kernel.  This diff adds the logic to handle
that information to the kernel.  I'd like some folks that use a serial
console on their amd64 machines to test this.  But testing this diff
on amd64 machines with a glass console doesn't hurt.

Thanks,

Mark


Index: dev/acpi/com_acpi.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/com_acpi.c,v
retrieving revision 1.8
diff -u -p -r1.8 com_acpi.c
--- dev/acpi/com_acpi.c 6 Apr 2022 18:59:27 -0000       1.8
+++ dev/acpi/com_acpi.c 27 Jun 2022 21:42:08 -0000
@@ -49,6 +49,7 @@ const struct cfattach com_acpi_ca = {
 };
 
 const char *com_hids[] = {
+       "AMDI0020",
        "HISI0031",
        "PNP0501",
        NULL
@@ -86,10 +87,14 @@ com_acpi_attach(struct device *parent, s
        printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]);
        printf(" irq %d", aaa->aaa_irq[0]);
 
+       sc->sc.sc_frequency = COM_FREQ;
+       if (strcmp(aaa->aaa_dev, "AMDI0020") == 0)
+               sc->sc.sc_frequency = 48000000;
+
        sc->sc.sc_iot = aaa->aaa_bst[0];
        sc->sc.sc_iobase = aaa->aaa_addr[0];
        sc->sc.sc_frequency = acpi_getpropint(sc->sc_node, "clock-frequency",
-           COM_FREQ);
+           sc->sc.sc_frequency);
 
        if (com_acpi_is_designware(aaa->aaa_dev)) {
                intr = com_acpi_intr_designware;
@@ -153,7 +158,8 @@ com_acpi_is_console(struct com_acpi_soft
 int
 com_acpi_is_designware(const char *hid)
 {
-       return strcmp("HISI0031", hid) == 0;
+       return strcmp(hid, "AMDI0020") == 0 ||
+           strcmp(hid, "HISI0031") == 0;
 }
 
 int
Index: arch/amd64/amd64/bus_space.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/bus_space.c,v
retrieving revision 1.26
diff -u -p -r1.26 bus_space.c
--- arch/amd64/amd64/bus_space.c        25 Apr 2015 21:31:24 -0000      1.26
+++ arch/amd64/amd64/bus_space.c        27 Jun 2022 21:42:09 -0000
@@ -43,6 +43,8 @@
 #include <dev/isa/isareg.h>
 #include <machine/isa_machdep.h>
 
+extern int pmap_initialized;
+
 /*
  * Extent maps to manage I/O and memory space.  Allocate
  * storage for 16 regions in each, initially.  Later, ioport_malloc_safe
@@ -376,6 +378,11 @@ bus_space_map(bus_space_tag_t t, bus_add
                return(0);
        }
 
+       if (!pmap_initialized && bpa < 0x100000000) {
+               *bshp = (bus_space_handle_t)PMAP_DIRECT_MAP(bpa);
+               return(0);
+       }
+
        /*
         * For memory space, map the bus physical address to
         * a kernel virtual address.
@@ -585,6 +592,11 @@ bus_space_unmap(bus_space_tag_t t, bus_s
                bpa = (bus_addr_t)ISA_PHYSADDR(bsh);
                if (IOM_BEGIN <= bpa && bpa <= IOM_END)
                        goto ok;
+
+               if (bsh >= PMAP_DIRECT_BASE && bsh < PMAP_DIRECT_END) {
+                       bpa = PMAP_DIRECT_UNMAP(bsh);
+                       goto ok;
+               }
 
                va = trunc_page(bsh);
                endva = round_page(bsh + size);
Index: arch/amd64/amd64/machdep.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/machdep.c,v
retrieving revision 1.277
diff -u -p -r1.277 machdep.c
--- arch/amd64/amd64/machdep.c  1 Feb 2022 20:29:53 -0000       1.277
+++ arch/amd64/amd64/machdep.c  27 Jun 2022 21:42:09 -0000
@@ -1945,11 +1945,40 @@ getbootinfo(char *bootinfo, int bootinfo
                        /* generated by i386 boot loader */
                        break;
                case BOOTARG_CONSDEV:
-                       if (q->ba_size >= sizeof(bios_consdev_t) +
+                       if (q->ba_size > sizeof(bios_oconsdev_t) +
                            offsetof(struct _boot_args32, ba_arg)) {
 #if NCOM > 0
                                bios_consdev_t *cdp =
                                    (bios_consdev_t*)q->ba_arg;
+                               static const int ports[] =
+                                   { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
+                               int unit = minor(cdp->consdev);
+                               uint64_t consaddr = cdp->consaddr;
+                               if (consaddr == -1 && unit >= 0 &&
+                                   unit < nitems(ports))
+                                       consaddr = ports[unit];
+                               if (major(cdp->consdev) == 8 &&
+                                   consaddr != -1) {
+                                       comconsunit = unit;
+                                       comconsaddr = consaddr;
+                                       comconsrate = cdp->conspeed;
+                                       comconsfreq = cdp->consfreq;
+                                       comcons_reg_width = cdp->reg_width;
+                                       comcons_reg_shift = cdp->reg_shift;
+                                       if (cdp->flags & BCD_MMIO)
+                                               comconsiot = X86_BUS_SPACE_MEM;
+                                       else
+                                               comconsiot = X86_BUS_SPACE_IO;
+                               }
+#endif
+#ifdef BOOTINFO_DEBUG
+                               printf(" console 0x%x:%d",
+                                   cdp->consdev, cdp->conspeed);
+#endif
+                       } else {
+#if NCOM > 0
+                               bios_oconsdev_t *cdp =
+                                   (bios_oconsdev_t*)q->ba_arg;
                                static const int ports[] =
                                    { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
                                int unit = minor(cdp->consdev);
Index: arch/amd64/include/biosvar.h
===================================================================
RCS file: /cvs/src/sys/arch/amd64/include/biosvar.h,v
retrieving revision 1.27
diff -u -p -r1.27 biosvar.h
--- arch/amd64/include/biosvar.h        29 Nov 2019 16:16:19 -0000      1.27
+++ arch/amd64/include/biosvar.h        27 Jun 2022 21:42:09 -0000
@@ -162,11 +162,22 @@ typedef struct _bios_pciinfo {
 
 #define        BOOTARG_CONSDEV 5
 typedef struct _bios_consdev {
+       dev_t           consdev;
+       int             conspeed;
+       uint64_t        consaddr;
+       int             consfreq;
+       uint32_t        flags;
+#define BCD_MMIO       0x00000001      /* Memory Mapped IO */
+       int             reg_width;
+       int             reg_shift;
+} __packed bios_consdev_t;
+
+typedef struct _bios_oconsdev {
        dev_t   consdev;
        int     conspeed;
        int     consaddr;
        int     consfreq;
-} __packed bios_consdev_t;
+} __packed bios_oconsdev_t;
 
 #define BOOTARG_BOOTMAC        7
 typedef struct _bios_bootmac {

Reply via email to