Skip to contentSkip to conversation

qemu-palcode: Changes to support booting NetBSD/alpha

PATCH In review Jason Thorpe 3 participants 5 messages Oct 7, 2020 – Oct 15, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-palcode: Changes to support booting NetBSD/alpha

There are additional changes in Qemu itself. Those will be sent as a follow-up.

- Change the $a2 value at VM start from "cpu count" to "config word". Bits 0-5 are cpu count, and bit 6 communicates the "-nographic" option from the VM.
- Provide a Console Terminal Block in the HWRPB. Initialize this based on the location of the PCI VGA, or to the serial port if Qemu has been run with "-nographic".
- Initialize hwrpb.hwrpb.cpuid correctly; it's the WHAMI of the primary CPU, not the CPU type.
- Don't set the "PALcode memory valid" bit in the PCS flags field; those HWRPB fields are not, in fact, valid.
- Allow swppal() to specify the new $pv value. Use this to pass the CPU_Restart_data to the cpu spinup entry point.
- Fix a bug in PCI address configuration that caused the CMD646 IDE registers to be mapped incorrectly.
- When configuring the PCI bus, program system-specific interrupt routing information into the PCI device "line" register (as SRM does).
- When building the PALcode, don't include outside header files; put everything that's needed in protos.h.

---
 hwrpb.h       | 59 ++++++++++++++++++++++++++++++++++
 init.c        | 89 +++++++++++++++++++++++++++++++++++++++------------
 memcpy.c      |  2 +-
 memset.c      |  2 +-
 pal.S         | 16 ++++++---
 pci.c         | 33 ++++++++++++++-----
 pci.h         |  5 +++
 printf.c      | 11 +++++--
 protos.h      | 33 ++++++++++++++++---
 sys-clipper.h | 27 ++++++++++++++++
 vgaio.c       |  2 ++
 11 files changed, 236 insertions(+), 43 deletions(-)
hwrpb.h +59 -0
index 2166bad..1981d40 100644
@@ -146,6 +146,65 @@ struct crb_struct {
 	struct vf_map_struct map[1];
 };
 
+struct ctb_struct {
+	unsigned long type;
+	unsigned long unit;
+	unsigned long res0;
+	unsigned long len;
+	unsigned long ipl;
+	unsigned long tintr_vec;
+	unsigned long rintr_vec;
+	unsigned long term_type;
+	unsigned long keybd_type;
+	unsigned long keybd_trans;
+	unsigned long keybd_map;
+	unsigned long keybd_state;
+	unsigned long keybd_last;
+	unsigned long font_us;
+	unsigned long font_mcs;
+	unsigned long font_width;
+	unsigned long font_height;
+	unsigned long mon_width;
+	unsigned long mon_height;
+	unsigned long dpi;
+	unsigned long planes;
+	unsigned long cur_width;
+	unsigned long cur_height;
+	unsigned long head_cnt;
+	unsigned long opwindow;
+	unsigned long head_offset;
+	unsigned long putchar;
+	unsigned long io_state;
+	unsigned long listen_state;
+	unsigned long xaddr;
+	unsigned long turboslot;
+	unsigned long server_off;
+	unsigned long line_off;
+	unsigned char csd;
+};
+
+#define	CTB_NONE	0x00
+#define	CTB_PRINTERPORT	0x02
+#define	CTB_GRAPHICS	0x03
+#define	CTB_TYPE4	0x04
+
+/*
+ * Format of the Console Terminal Block Type 4 `turboslot' field:
+ *
+ *  63                   40 39       32 31     24 23      16 15   8 7    0
+ *  |      reserved        |  channel  |  hose   | bus type |  bus | slot|
+ */
+#define	CTB_TURBOSLOT_CHANNEL(x)	(((x) >> 32) & 0xff)
+#define	CTB_TURBOSLOT_HOSE(x)		(((x) >> 24) & 0xff)
+#define	CTB_TURBOSLOT_TYPE(x)		(((x) >> 16) & 0xff)
+#define	CTB_TURBOSLOT_BUS(x)		(((x) >> 8) & 0xff)
+#define	CTB_TURBOSLOT_SLOT(x)		((x) & 0xff)
+
+#define	CTB_TURBOSLOT_TYPE_TC           0       /* TURBOchannel */
+#define	CTB_TURBOSLOT_TYPE_ISA          1       /* ISA */
+#define	CTB_TURBOSLOT_TYPE_EISA         2       /* EISA */
+#define	CTB_TURBOSLOT_TYPE_PCI          3       /* PCI */
+
 struct memclust_struct {
 	unsigned long start_pfn;
 	unsigned long numpages;
init.c +68 -21

202 lines not on this page · raw message

memcpy.c +1 -1
index b6bbb74..9e1e913 100644
@@ -8,7 +8,7 @@
  * This is a reasonably optimized memcpy() routine.
  */
 
-#include <string.h>
+#include "protos.h"
 
 /*
  * Note that the C code is written to be optimized into good assembly. However,
memset.c +1 -1
index e8481dc..f9b0a6d 100644
@@ -19,7 +19,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 
-#include <string.h>
+#include "protos.h"
 
 void *memset(void *optr, int ival, unsigned long size)
 {
pal.S +11 -5
index 64941a8..1e83b78 100644
@@ -566,6 +566,8 @@ ENDFN	CallPal_Cserve_Cont
  *	r17 (a1) = New PC
  *	r18 (a2) = New PCB
  *	r19 (a3) = New VptPtr
+ *	r20 (a4) = New Procedure Value (to place into $27)
+ *	           (Non-standard; See note below.)
  * 
  * OUTPUT PARAMETERS:
  *
@@ -574,11 +576,15 @@ ENDFN	CallPal_Cserve_Cont
  *			1 - Unknown PALcode variant
  *			2 - Known PALcode variant, but PALcode not loaded
  *
- *	r26 (ra) = r27 (pv) = New PC
- *		Note that this is non-architected, but is relied on by
+ *	r26 (ra) = New PC
+ *	r27 (pv) = From $20
+ *		Note that this is non-architected, but is relied upon by
  *		the usage of SwpPal within our own console code in order
- *		to simplify its use within C code.
- *
+ *		to simplify its use within C code.  We can get away with
+ *		the extra non-standard argument (in $20) because as
+ *		architected, all registers except SP and R0 are
+ *		UNPREDICTABLE; therefore private internal usage is
+ *		fine.
  */
 	ORG_CALL_PAL_PRIV(0x0A)
 CallPal_SwpPal:
@@ -624,7 +630,7 @@ CallPal_SwpPal_Cont:
 	mtpr	$31, qemu_tbia		// Flush TLB for new PTBR
 
 	mov	a1, $26
-	mov	a1, $27
+	mov	a4, $27
 	hw_ret	(a1)
 ENDFN	CallPal_SwpPal_Cont
 	.previous
pci.c +25 -8
index 87a101c..a521e2a 100644
@@ -29,12 +29,9 @@
 #include "protos.h"
 #include "pci.h"
 #include "pci_regs.h"
+#include SYSTEM_H
 
 
-#define PCI_DEVFN(slot, func)	((((slot) & 0x1f) << 3) | ((func) & 0x07))
-#define PCI_BUS(devfn)		((devfn) >> 8)
-#define PCI_SLOT(devfn)		(((devfn) >> 3) & 0x1f)
-#define PCI_FUNC(devfn)		((devfn) & 0x07)
 #define PCI_SLOT_MAX		32
 #define PCI_FUNC_MAX		8
 #define PCI_REGION_ROM		6
@@ -88,7 +85,7 @@ pci_setup_device(int bdf, uint32_t *p_io_base, uint32_t *p_mem_base)
   device_id = pci_config_readw(bdf, PCI_DEVICE_ID);
   class_id = pci_config_readw(bdf, PCI_CLASS_DEVICE);
 
-  printf("PCI: %02x:%02x:%x class %04x id %04x:%04x\r\n",
+  printf("PCI: %d:%d:%d class %04x id %04x:%04x\r\n",
 	 PCI_BUS(bdf), PCI_SLOT(bdf), PCI_FUNC(bdf),
          class_id, vendor_id, device_id);
 
@@ -122,9 +119,11 @@ pci_setup_device(int bdf, uint32_t *p_io_base, uint32_t *p_mem_base)
 	  *p_base = addr + size;
 	  pci_config_writel(bdf, ofs, addr);
 
-	  printf("PCI:   region %d: %08x\r\n", region, addr);
+	  printf("PCI:   region %d (BAR %02x): %08x\r\n",
+	         region, ofs, addr);
 
-	  if ((val & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
+	  if ((old & PCI_BASE_ADDRESS_SPACE_IO) == 0 &&
+	      (old & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
 	      == PCI_BASE_ADDRESS_MEM_TYPE_64)
 	    {
 	      pci_config_writel(bdf, ofs + 4, 0);
@@ -135,7 +134,25 @@ pci_setup_device(int bdf, uint32_t *p_io_base, uint32_t *p_mem_base)
 
   pci_config_maskw(bdf, PCI_COMMAND, 0, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
 
-  /* Map the interrupt.  */
+  /* Map the interrupt and program the IRQ into the line register.
+     Some operating systems rely on the Console providing this information
+     in order to avoid having mapping tables for every possible system
+     variation.  */
+
+  const uint8_t pin = pci_config_readb(bdf, PCI_INTERRUPT_PIN);
+  const uint8_t slot = PCI_SLOT(bdf);
+  const int irq = MAP_PCI_INTERRUPT(slot, pin, class_id);
+
+  if (irq == -1)
+    {
+      /* No interrupt mapping.  */
+      pci_config_writeb(bdf, PCI_INTERRUPT_LINE, 0xff);
+    }
+  else
+    {
+      printf("PCI:   intr pin %d -> irq %d\r\n", pin, irq);
+      pci_config_writeb(bdf, PCI_INTERRUPT_LINE, irq);
+    }
 }
 
 void
pci.h +5 -0
index b751c6f..b4a4f80 100644
@@ -60,6 +60,11 @@ extern void pci_config_maskw(int bdf, int addr, uint16_t off, uint16_t on);
 
 extern int pci_next(int bdf, int *pmax);
 
+#define PCI_DEVFN(slot, func)	((((slot) & 0x1f) << 3) | ((func) & 0x07))
+#define PCI_BUS(devfn)		((devfn) >> 8)
+#define PCI_SLOT(devfn)		(((devfn) >> 3) & 0x1f)
+#define PCI_FUNC(devfn)		((devfn) & 0x07)
+
 #define foreachpci(BDF, MAX)				\
 	for (MAX = 0x0100, BDF = pci_next(0, &MAX);	\
 	     BDF >= 0;					\
printf.c +8 -3
index 469b82c..bbc1caa 100644
@@ -18,10 +18,8 @@
    along with this program; see the file COPYING.  If not see
    <http://www.gnu.org/licenses/>.  */
 
-#include <stdarg.h>
-#include <stdbool.h>
-#include <string.h>
 #include "console.h"
+#include "protos.h"
 
 static int print_buf_pad(char *buf, int buflen, char *p, int width, int pad)
 {
@@ -201,3 +199,10 @@ int printf(const char *fmt, ...)
   va_end(args);
   return r;
 }
+
+int puts(const char *s)
+{
+  int len = strlen(s);
+  crb_puts(0, s, len);
+  return len;
+}
protos.h +29 -4
index 3ed1381..4c6f4bf 100644
@@ -21,11 +21,33 @@
 #ifndef PROTOS_H
 #define PROTOS_H 1
 
-#include <stdint.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <string.h>
+/*
+ * Stand-alone definitions for various types, compatible with
+ * the Alpha Linux ABI and GCC.  This eliminates dependencies
+ * on external headers.
+ */
+typedef unsigned char  uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int   uint32_t;
+typedef unsigned long  uint64_t;
+typedef unsigned long  size_t;
+
+#define	bool	_Bool
+#define	true	1
+#define	false	0
+
+#define	offsetof(type, member) __builtin_offsetof(type, member)
+
+typedef __builtin_va_list va_list;
+#define	va_start(ap, last)	__builtin_va_start((ap), (last))
+#define	va_arg			__builtin_va_arg
+#define	va_end(ap)		__builtin_va_end(ap)
+
+#define	NULL	((void *)0)
 
+extern void *memset(void *, int, size_t);
+extern void *memcpy(void *, const void *, size_t);
+extern size_t strlen(const char *);
 
 /*
  * Call_Pal functions.
@@ -202,6 +224,8 @@ extern unsigned long crb_fixup(unsigned long vptptr, unsigned long hwrpb);
  */
 
 extern bool have_vga;
+extern unsigned int pci_vga_bus;
+extern unsigned int pci_vga_dev;
 
 extern void do_console(void);
 extern void entInt(void);
@@ -211,6 +235,7 @@ extern void entInt(void);
  */
 
 extern int printf(const char *, ...);
+extern int puts(const char *);
 extern void ndelay(unsigned long nsec);
 
 static inline void udelay(unsigned long msec)
sys-clipper.h +27 -0
index 31094ff..150fe49 100644
@@ -27,4 +27,31 @@
 #define SYS_VARIATION	(5 << 10)
 #define SYS_REVISION	0
 
+#ifndef __ASSEMBLER__
+
+#define MAP_PCI_INTERRUPT(SLOT, PIN, CLASS_ID)				\
+({									\
+  int IRQ;								\
+    									\
+  if (CLASS_ID == 0x0601)						\
+    {									\
+      /* PCI-ISA bridge is hard-wired to IRQ 55 on real hardware,	\
+	 and comes in at a different SCB vector; force the line		\
+         register to -1.  */						\
+      IRQ = -1;								\
+    }									\
+  else if (PIN >= 1 && PIN <= 4)					\
+    {									\
+      /* See hw/alpha/dp264.c:clipper_pci_map_irq()  */			\
+      IRQ = (SLOT + 1) * 4 + (PIN - 1);					\
+    }									\
+  else									\
+    {									\
+      IRQ = -1;								\
+    }									\
+  IRQ;									\
+})
+
+#endif /* ! __ASSEMBLER__ */
+
 #endif
vgaio.c +2 -0
index 2dd7eb7..1fb0d52 100644
@@ -570,6 +570,8 @@ vgahw_init(void)
 
  found:
   have_vga = 1;
+  pci_vga_bus = PCI_BUS(bdf);
+  pci_vga_dev = PCI_SLOT(bdf);
 
   vmode_g = find_vga_entry(3);
 
Signature · 1 line
2.28.0
#1 lore raw
Quoted 13 lines · Jason Thorpe

There are additional changes in Qemu itself. Those will be sent as a follow-up.

- Change the $a2 value at VM start from "cpu count" to "config word". Bits 0-5 are cpu count, and bit 6 communicates the "-nographic" option from the VM.
- Provide a Console Terminal Block in the HWRPB. Initialize this based on the location of the PCI VGA, or to the serial port if Qemu has been run with "-nographic".
- Initialize hwrpb.hwrpb.cpuid correctly; it's the WHAMI of the primary CPU, not the CPU type.
- Don't set the "PALcode memory valid" bit in the PCS flags field; those HWRPB fields are not, in fact, valid.

Quoted 8 lines

- Allow swppal() to specify the new $pv value. Use this to pass the CPU_Restart_data to the cpu spinup entry point.
- Fix a bug in PCI address configuration that caused the CMD646 IDE registers to be mapped incorrectly.
- When configuring the PCI bus, program system-specific interrupt routing information into the PCI device "line" register (as SRM does).
- When building the PALcode, don't include outside header files; put everything that's needed in protos.h.

I'm certainly open to these changes. But it'll need to be split up -- one patch per bullet, basically.

r~

#2 lore raw
Quoted 5 lines · Richard Henderson

I'm certainly open to these changes. But it'll need to be split up -- one patch per bullet, basically.

That's fine. What's the convention for patches that stack on top of one another?

-- thorpej

#3 lore raw
Quoted 7 lines · Jason Thorpe
Quoted 5 lines · Richard Henderson

I'm certainly open to these changes. But it'll need to be split up -- one patch per bullet, basically.

That's fine. What's the convention for patches that stack on top of one another?

git format-patch --cover-letter
git send-email --thread --no-chain-reply-to

r~

#4 lore raw
Quoted 11 lines · Richard Henderson
Quoted 7 lines · Jason Thorpe
Quoted 5 lines · Richard Henderson

I'm certainly open to these changes. But it'll need to be split up -- one patch per bullet, basically.

That's fine. What's the convention for patches that stack on top of one another?

git format-patch --cover-letter
git send-email --thread --no-chain-reply-to

Alternatively git-publish:

https://github.com/stefanha/git-publish