Skip to contentSkip to conversation

hvm bios: add PMM (a memory manager during POST)

PATCH In review Kouya Shimura 2 participants 4 messages Jan 22, 2009 – Jan 23, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hvm bios: add PMM (a memory manager during POST)

The PMM (POST Memory Manager) offers malloc/free functionality for PCI option ROMs during POST (Power On Self Test).

This patch adds a PMM functionality to the guest BIOS.

For example, the option ROM on LSI Logic SAS card uses PMM and failed to initialize the device without PMM. Thus, the HVM can't boot up directly from the passthroughed SCSI disk.
gPXE also uses PMM (I don't know what happens without PMM).

With this patch, we succeeded in SAS boot of HVM.

For further information about PMM:
http://www.phoenix.com/en/OEM-ODM/Customer+Services/White+Papers-Specs/PC+Industry+Specifications.htm
http://www.phoenix.com/NR/rdonlyres/873A00CF-33AC-4775-B77E-08E7B9754993/0/specspmm101.pdf

Thanks,
Kouya

tools/firmware/hvmloader/config.h +2 -0
diff -r af1d9af1a993 tools/firmware/hvmloader/config.h
@@ -45,6 +45,8 @@
 #define E820_NR_OFFSET                0x0
 #define E820_OFFSET                   0x8
 
+#define PMM_ENTRY_POINT               0xFFC0
+
 /* Xen Platform Device */
 #define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */
 
tools/firmware/hvmloader/hvmloader.c +37 -1
diff -r af1d9af1a993 tools/firmware/hvmloader/hvmloader.c
@@ -442,6 +442,35 @@
     return round_option_rom(rom->rom_size * 512 + 1);
 }
 
+typedef struct {
+    uint8_t signature[4]; /* "$PMM" */
+    uint8_t revision;     /* 01h */
+    uint8_t length;
+    uint8_t checksum;
+    uint16_t entrypoint[2];
+    uint8_t reserved[5];  /* All 0 */
+} __attribute__ ((packed)) pmm_struct_t;
+
+/*
+ * Set up POST Memory Manager.
+ */
+static void setup_pmm(uint32_t addr)
+{
+    pmm_struct_t *pmms = (pmm_struct_t *)addr;
+    uint8_t *p, csum;
+
+    memset(pmms, 0, sizeof(*pmms));
+    memcpy(pmms->signature, "$PMM", 4);
+    pmms->revision = 0x01;
+    pmms->length = sizeof(pmm_struct_t);
+    pmms->entrypoint[0] = PMM_ENTRY_POINT;
+    pmms->entrypoint[1] = ROMBIOS_SEG;
+
+    for (csum = 0, p = (uint8_t *)pmms; p < (uint8_t *)(pmms + 1); p++)
+        csum += *p;
+    pmms->checksum = -csum;
+}
+
 /*
  * Scan the PCI bus for the first NIC supported by etherboot, and copy
  * the corresponding rom data to *copy_rom_dest. Returns the length of the
@@ -648,7 +677,7 @@
 {
     int option_rom_sz = 0, vgabios_sz = 0, etherboot_sz = 0;
     int rombios_sz, smbios_sz;
-    uint32_t etherboot_phys_addr, option_rom_phys_addr;
+    uint32_t etherboot_phys_addr, option_rom_phys_addr, pmm_phys_addr;
     uint16_t xen_pfiob;
 
     printf("HVM Loader\n");
@@ -666,6 +695,13 @@
 
     printf("Writing SMBIOS tables ...\n");
     smbios_sz = hvm_write_smbios_tables();
+
+    pmm_phys_addr = SMBIOS_PHYSICAL_ADDRESS + round_option_rom(smbios_sz);
+    if ( pmm_phys_addr + sizeof(pmm_struct_t) < ROMBIOS_PHYSICAL_ADDRESS )
+    {
+        setup_pmm(pmm_phys_addr);
+        printf("Setup PMM at %x\n", pmm_phys_addr);
+    }
 
     printf("Loading ROMBIOS ...\n");
     rombios_sz = sizeof(rombios);
tools/firmware/rombios/32bit/32bitbios.c +2 -0
diff -r af1d9af1a993 tools/firmware/rombios/32bit/32bitbios.c
@@ -49,5 +49,7 @@
 
 	TABLE_ENTRY(IDX_GET_S3_WAKING_VECTOR, get_s3_waking_vector),
 
+	TABLE_ENTRY(IDX_PMM, pmm),
+
 	TABLE_ENTRY(IDX_LAST       , 0)     /* keep last */
 };
tools/firmware/rombios/32bit/Makefile +1 -1
diff -r af1d9af1a993 tools/firmware/rombios/32bit/Makefile
@@ -18,7 +18,7 @@
 clean: subdirs-clean
 	rm -rf *.o $(TARGET) $(DEPS)
 
-$(TARGET): 32bitbios.o $(MODULES) util.o
+$(TARGET): 32bitbios.o $(MODULES) util.o pmm.o
 	$(LD) $(LDFLAGS_DIRECT) -s -r $^ -o 32bitbios_all.o
 	@nm 32bitbios_all.o |                                \
 	  egrep '^ +U ' >/dev/null && {                      \
tools/firmware/rombios/32bit/pmm.c new file +532 -0

532 lines not on this page · raw message

tools/firmware/rombios/32bitprotos.h +4 -1
diff -r af1d9af1a993 tools/firmware/rombios/32bitprotos.h
@@ -18,7 +18,8 @@
 #define IDX_TCPA_INITIALIZE_TPM            11
 #define IDX_TCPA_MEASURE_POST              12
 #define IDX_GET_S3_WAKING_VECTOR           13
-#define IDX_LAST                           14 /* keep last! */
+#define IDX_PMM                            14
+#define IDX_LAST                           15 /* keep last! */
 
 #ifdef GCC_PROTOS
   #define PARMS(x...) x
@@ -44,4 +45,6 @@
 
 Bit32u get_s3_waking_vector( PARMS(void) );
 
+void pmm( PARMS(pushad_regs_t *regs, ...) );
+
 #endif
tools/firmware/rombios/rombios.c +11 -0
diff -r af1d9af1a993 tools/firmware/rombios/rombios.c
@@ -11631,6 +11631,17 @@
   HALT(__LINE__)
   iret
 
+.org PMM_ENTRY_POINT
+pmm_entry_point:
+  pushf
+  pushad
+  call pmm_upcall
+  popad
+  popf
+  db 0xcb ;; lret
+pmm_upcall:
+  DoUpcall(IDX_PMM)
+
 #ifdef HVMTEST
 .org 0xffe0
   jmp 0xf000:post;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 4 lines · Kouya Shimura

The PMM (POST Memory Manager) offers malloc/free functionality for PCI option ROMs during POST (Power On Self Test).

This patch adds a PMM functionality to the guest BIOS.

Hardcoding the entry point and setting up $PMM in hvmloader is not very nice. I think you should define the $PMM struct as data in rombios.c, and then you can directly reference pmm_entry_point without needing a .org directive. The only difficulty then is the checksum, which I think you should calculate in rombios.c rather than doing it in hvmloader. It's a tiny bit of C or pretty trivial asm to do it that way. Overall this avoids further tying together hvmloader and rombios unnecessarily.

Beyond that, the allocator looks pretty complicated, but as long as it works I suppose that is fine. It would be nice if you could add a top-of-file comment explaining the allocator algorithm, where it allocates memory from (scavenging from rombios's e820 perhaps), and other details like that. Otherwise it's rather unnecessarily opaque new code. A few more comments scattered through (especially at tops of functions) would be nice too!

-- Keir

#2 lore raw

Hi Keir,

Thanks for your review.
Here is an updated patch using new 32-bit gateway interface.

Thanks,
Kouya

Quoted 15 lines · Keir Fraser
Quoted 4 lines · Kouya Shimura

The PMM (POST Memory Manager) offers malloc/free functionality for PCI option ROMs during POST (Power On Self Test).

This patch adds a PMM functionality to the guest BIOS.

Hardcoding the entry point and setting up $PMM in hvmloader is not very nice. I think you should define the $PMM struct as data in rombios.c, and then you can directly reference pmm_entry_point without needing a .org directive. The only difficulty then is the checksum, which I think you should calculate in rombios.c rather than doing it in hvmloader. It's a tiny bit of C or pretty trivial asm to do it that way. Overall this avoids further tying together hvmloader and rombios unnecessarily.

Quoted 6 lines

Beyond that, the allocator looks pretty complicated, but as long as it works I suppose that is fine. It would be nice if you could add a top-of-file comment explaining the allocator algorithm, where it allocates memory from (scavenging from rombios's e820 perhaps), and other details like that. Otherwise it's rather unnecessarily opaque new code. A few more comments scattered through (especially at tops of functions) would be nice too!

tools/firmware/rombios/32bit/Makefile +1 -1
diff -r 9b0289a165eb tools/firmware/rombios/32bit/Makefile
@@ -18,7 +18,7 @@
 clean: subdirs-clean
 	rm -rf *.o $(TARGET) $(DEPS)
 
-$(TARGET): 32bitbios.o $(MODULES) util.o
+$(TARGET): 32bitbios.o $(MODULES) util.o pmm.o
 	$(LD) $(LDFLAGS_DIRECT) -s -r $^ -o 32bitbios_all.o
 	@nm 32bitbios_all.o |                                \
 	  egrep '^ +U ' >/dev/null && {                      \
tools/firmware/rombios/32bit/pmm.c new file +530 -0

530 lines not on this page · raw message

tools/firmware/rombios/32bitprotos.h +1 -0
diff -r 9b0289a165eb tools/firmware/rombios/32bitprotos.h
@@ -13,3 +13,4 @@
 X(11, void,   tcpa_measure_post, Bit32u from, Bit32u to)
 X(12, Bit32u, tcpa_initialize_tpm, Bit32u physpres)
 X(13, Bit32u, get_s3_waking_vector, void)
+X(14, Bit32u, pmm, void *argp)
tools/firmware/rombios/rombios.c +32 -1
diff -r 9b0289a165eb tools/firmware/rombios/rombios.c
@@ -160,6 +160,8 @@
 #define BX_ELTORITO_BOOT 1
 
 #define BX_TCGBIOS       0   /* main switch for TCG BIOS ext. */
+
+#define BX_PMM           1   /* POST Memory Manager */
 
 #define BX_MAX_ATA_INTERFACES   4
 #define BX_MAX_ATA_DEVICES      (BX_MAX_ATA_INTERFACES*2)
@@ -2054,7 +2056,10 @@
   "rombios32 "
 #endif
 #if BX_TCGBIOS
-  "TCG-enabled"
+  "TCG-enabled "
+#endif
+#if BX_PMM
+  "PMM "
 #endif
   "\n\n");
 }
@@ -10356,6 +10361,32 @@
   dw 0xffff, 0, 0x9300, 0x0000 ; 16 bit data segment base=0x0 limit=0xffff
 #endif // BX_ROMBIOS32
 
+#if BX_PMM
+; according to POST Memory Manager Specification Version 1.01
+.align 16
+pmm_structure:
+  db 0x24,0x50,0x4d,0x4d ;; "$PMM" signature
+  db 0x01 ;; revision
+  db 16 ;; length
+  db (-((pmm_entry_point>>8)+pmm_entry_point+0x20f))&0xff;; checksum
+  dw pmm_entry_point,0xf000 ;; far call entrypoint
+  db 0,0,0,0,0 ;; reserved
+
+pmm_entry_point:
+  pushad
+  mov   eax, esp
+  add   eax, #(8*4+2+2) ;; skip regs of pushad, ip, cs
+  push  eax ;; pointer to PMM function args
+  call _pmm
+  mov   bx, sp
+SEG SS
+  mov   [bx+(4+7*4)], ax
+SEG SS
+  mov   [bx+(4+5*4)], dx
+  pop   eax
+  popad
+  db 0xcb ;; lret
+#endif // BX_PMM
 
 ; parallel port detection: base address in DX, index in BX, timeout in CL
 detect_parport:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 2 lines · Kouya Shimura

Thanks for your review.
Here is an updated patch using new 32-bit gateway interface.

That looks great. Thanks Kouya!

-- Keir