This patch series reorganizes the POST initialization sequence to make it more reusable should SeaBIOS be hooked up as a UEFI Compatibility Support Module (CSM). This is a work in progress.
-Kevin
Kevin O'Connor (3): post: Avoid calling maininit() from init reloc_init(). Normalize POST initialization function name suffixes. POST: Reorganize post init functions for better grouping and reusability.
src/acpi.c | 12 +- src/acpi.h | 2 +- src/ahci.c | 14 +-- src/ata.c | 4 +- src/block.c | 2 +- src/blockcmd.c | 2 +- src/blockcmd.h | 2 +- src/boot.c | 22 ++-- src/boot.h | 5 +- src/bootsplash.c | 2 + src/cdrom.c | 4 +- src/clock.c | 12 +- src/coreboot.c | 6 +- src/disk.h | 4 +- src/esp-scsi.c | 4 +- src/kbd.c | 2 +- src/lsi-scsi.c | 4 +- src/megasas.c | 4 +- src/memmap.c | 2 +- src/memmap.h | 2 +- src/misc.c | 2 +- src/mouse.c | 2 +- src/mptable.c | 2 +- src/mptable.h | 2 +- src/optionroms.c | 12 +- src/output.c | 2 +- src/paravirt.c | 6 +- src/paravirt.h | 4 +- src/pci.h | 2 +- src/pcibios.c | 2 +- src/pciinit.c | 52 ++++----- src/pirtable.c | 2 +- src/pmm.c | 15 ++- src/pnpbios.c | 2 +- src/post.c | 331 ++++++++++++++++++++++++++++-------------------------- src/ps2port.c | 4 +- src/resume.c | 10 +- src/smbios.c | 12 +- src/smbios.h | 2 +- src/smm.c | 10 +- src/smp.c | 2 +- src/usb-ehci.c | 12 +- src/usb-ehci.h | 2 +- src/usb-hid.c | 16 +-- src/usb-hid.h | 2 +- src/usb-hub.c | 2 +- src/usb-hub.h | 2 +- src/usb-msc.c | 12 +- src/usb-msc.h | 2 +- src/usb-ohci.c | 2 +- src/usb-ohci.h | 2 +- src/usb-uas.c | 14 +-- src/usb-uas.h | 2 +- src/usb-uhci.c | 2 +- src/usb-uhci.h | 2 +- src/usb.c | 30 ++--- src/util.h | 46 ++++---- src/virtio-scsi.c | 4 +- src/xen.c | 8 +- src/xen.h | 8 +- vgasrc/bochsvga.c | 4 +- vgasrc/bochsvga.h | 2 +- vgasrc/clext.c | 6 +- vgasrc/clext.h | 2 +- vgasrc/geodevga.c | 10 +- vgasrc/geodevga.h | 2 +- vgasrc/stdvga.c | 4 +- vgasrc/stdvga.h | 2 +- vgasrc/vgabios.c | 4 +- vgasrc/vgahw.h | 12 +- 70 files changed, 408 insertions(+), 399 deletions(-)
Call maininit() and startBoot() from handle_post(). This reduces the chaining of calls during the relocation phase, and allows maininit() to return (which may be useful when using SeaBIOS as a CSM).
This change relies on reloc_init() modifying the maininit() call in handle_post() when relocations are enabled. It technically may not be safe to modify gcc generated code when in that gcc code, but it should be safe in practice.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/pmm.c | 5 +++++ src/post.c | 46 ++++++++++++++++------------------------------ 2 files changed, 21 insertions(+), 30 deletions(-)
diff --git a/src/pmm.c b/src/pmm.c index 1657c10..6ddeae1 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -265,6 +265,11 @@ malloc_fixupreloc(void) return; dprintf(3, "malloc fixup reloc\n");
+ // Move low-memory initial variable content to new location. + extern u8 datalow_start[], datalow_end[], final_datalow_start[]; + memmove(final_datalow_start, datalow_start, datalow_end - datalow_start); + + // Fixup pointers back to ZoneX globals. int i; for (i=0; i<ARRAY_SIZE(Zones); i++) { struct zone_s *zone = Zones[i]; diff --git a/src/post.c b/src/post.c index f3b56b8..6a91f81 100644 --- a/src/post.c +++ b/src/post.c @@ -200,7 +200,7 @@ init_hw(void) }
// Begin the boot process by invoking an int0x19 in 16bit mode. -void VISIBLE32FLAT +static void startBoot(void) { // Clear low-memory allocations (required by PMM spec). @@ -214,9 +214,12 @@ startBoot(void) }
// Main setup code. -static void +void VISIBLE32INIT maininit(void) { + // Running at new code address - do code relocation fixups + malloc_fixupreloc(); + // Setup romfile items. qemu_cfg_romfile_setup(); coreboot_cbfs_setup(); @@ -287,9 +290,6 @@ maininit(void)
// Write protect bios memory. make_bios_readonly(); - - // Invoke int 19 to start boot process. - startBoot(); }
@@ -297,21 +297,6 @@ maininit(void) * POST entry and code relocation ****************************************************************/
-// Relocation fixup code that runs at new address after relocation complete. -static void -afterReloc(void) -{ - // Running at new code address - do code relocation fixups - malloc_fixupreloc(); - - // Move low-memory initial variable content to new location. - extern u8 datalow_start[], datalow_end[], final_datalow_start[]; - memmove(final_datalow_start, datalow_start, datalow_end - datalow_start); - - // Run main code - maininit(); -} - // Update given relocs for the code at 'dest' with a given 'delta' static void updateRelocs(void *dest, u32 *rstart, u32 *rend, u32 delta) @@ -325,10 +310,8 @@ updateRelocs(void *dest, u32 *rstart, u32 *rend, u32 delta) static void reloc_init(void) { - if (!CONFIG_RELOCATE_INIT) { - maininit(); + if (!CONFIG_RELOCATE_INIT) return; - } // Symbols populated by the build. extern u8 code32flat_start[]; extern u8 _reloc_min_align; @@ -359,15 +342,12 @@ reloc_init(void) updateRelocs(codedest, _reloc_rel_start, _reloc_rel_end, -delta); updateRelocs(code32flat_start, _reloc_init_start, _reloc_init_end, delta);
- // Call maininit() in relocated code. - void (*func)(void) = (void*)afterReloc + delta; barrier(); - func(); }
// Setup for code relocation and then call reloc_init void VISIBLE32INIT -dopost(void) +doreloc(void) { HaveRunPost = 1;
@@ -376,7 +356,7 @@ dopost(void) ram_probe(); malloc_setup();
- // Relocate initialization code and call maininit(). + // Relocate initialization code. reloc_init(); }
@@ -404,6 +384,12 @@ handle_post(void) // Allow writes to modify bios area (0xf0000) make_bios_writable();
- // Now that memory is read/writable - start post process. - dopost(); + // Do pre-relocation setup and then relocate initialization code. + doreloc(); + + // Run main code + maininit(); + + // Invoke int 19 to start boot process. + startBoot(); }
The POST phase has to invoke many initialization functions, and these functions can have complex inter-dependencies. Try to categorize the functions into 4 classes:
preinit - functions called very early in POST where function ordering is very important and the code has limited access to other interfaces.
init - functions that initialize internal interfaces and standard external interfaces. This code is generally not dependent on particular hardware and typically does not communicate directly with any hardware devices.
setup - functions which access hardware or are dependent on particular hardware or platform devices.
prepboot - functions that finalize internal interfaces and that prepare for the boot phase.
This patch attempts to normalize the suffixes - functions that used _init(), _setup(), _finalize(), or similar that did not follow the above pattern were renamed. Other than function name changes, there should be no code impact to this patch.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/acpi.c | 12 ++++---- src/acpi.h | 2 +- src/ahci.c | 14 ++++----- src/ata.c | 4 +-- src/block.c | 2 +- src/blockcmd.c | 2 +- src/blockcmd.h | 2 +- src/boot.c | 8 ++--- src/boot.h | 4 +-- src/cdrom.c | 4 +-- src/clock.c | 12 ++++---- src/coreboot.c | 6 ++-- src/disk.h | 4 +-- src/esp-scsi.c | 4 +-- src/kbd.c | 2 +- src/lsi-scsi.c | 4 +-- src/megasas.c | 4 +-- src/memmap.c | 2 +- src/memmap.h | 2 +- src/misc.c | 2 +- src/mouse.c | 2 +- src/mptable.c | 2 +- src/mptable.h | 2 +- src/optionroms.c | 12 ++++---- src/output.c | 2 +- src/paravirt.c | 6 ++-- src/paravirt.h | 4 +-- src/pci.h | 2 +- src/pcibios.c | 2 +- src/pciinit.c | 52 +++++++++++++++---------------- src/pirtable.c | 2 +- src/pmm.c | 10 +++--- src/pnpbios.c | 2 +- src/post.c | 92 +++++++++++++++++++++++++++---------------------------- src/ps2port.c | 4 +-- src/resume.c | 10 +++--- src/smbios.c | 12 ++++---- src/smbios.h | 2 +- src/smm.c | 10 +++--- src/smp.c | 2 +- src/usb-ehci.c | 12 ++++---- src/usb-ehci.h | 2 +- src/usb-hid.c | 16 +++++----- src/usb-hid.h | 2 +- src/usb-hub.c | 2 +- src/usb-hub.h | 2 +- src/usb-msc.c | 12 ++++---- src/usb-msc.h | 2 +- src/usb-ohci.c | 2 +- src/usb-ohci.h | 2 +- src/usb-uas.c | 14 ++++----- src/usb-uas.h | 2 +- src/usb-uhci.c | 2 +- src/usb-uhci.h | 2 +- src/usb.c | 30 +++++++++--------- src/util.h | 46 +++++++++++++--------------- src/virtio-scsi.c | 4 +-- src/xen.c | 8 ++--- src/xen.h | 8 ++--- vgasrc/bochsvga.c | 4 +-- vgasrc/bochsvga.h | 2 +- vgasrc/clext.c | 6 ++-- vgasrc/clext.h | 2 +- vgasrc/geodevga.c | 10 +++--- vgasrc/geodevga.h | 2 +- vgasrc/stdvga.c | 4 +-- vgasrc/stdvga.h | 2 +- vgasrc/vgabios.c | 4 +-- vgasrc/vgahw.h | 12 ++++---- 69 files changed, 272 insertions(+), 274 deletions(-)
diff --git a/src/acpi.c b/src/acpi.c index 6267d7b..03cda34 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -236,7 +236,7 @@ build_header(struct acpi_table_header *h, u32 sig, int len, u8 rev)
#define PIIX4_PM_INTRRUPT 9 // irq 9
-static void piix4_fadt_init(struct pci_device *pci, void *arg) +static void piix4_fadt_setup(struct pci_device *pci, void *arg) { struct fadt_descriptor_rev1 *fadt = arg;
@@ -262,7 +262,7 @@ static void piix4_fadt_init(struct pci_device *pci, void *arg) }
/* PCI_VENDOR_ID_INTEL && PCI_DEVICE_ID_INTEL_ICH9_LPC */ -void ich9_lpc_fadt_init(struct pci_device *dev, void *arg) +void ich9_lpc_fadt_setup(struct pci_device *dev, void *arg) { struct fadt_descriptor_rev1 *fadt = arg;
@@ -290,9 +290,9 @@ void ich9_lpc_fadt_init(struct pci_device *dev, void *arg) static const struct pci_device_id fadt_init_tbl[] = { /* PIIX4 Power Management device (for ACPI) */ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, - piix4_fadt_init), + piix4_fadt_setup), PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_LPC, - ich9_lpc_fadt_init), + ich9_lpc_fadt_setup), PCI_DEVICE_END };
@@ -325,7 +325,7 @@ build_fadt(struct pci_device *pci) /* FADT */ memset(fadt, 0, sizeof(*fadt)); fadt->firmware_ctrl = cpu_to_le32((u32)facs); - fadt->dsdt = 0; /* dsdt will be filled later in acpi_bios_init() + fadt->dsdt = 0; /* dsdt will be filled later in acpi_setup() by fill_dsdt() */ pci_init_device(fadt_init_tbl, pci, fadt);
@@ -796,7 +796,7 @@ struct rsdp_descriptor *RsdpAddr;
#define MAX_ACPI_TABLES 20 void -acpi_bios_init(void) +acpi_setup(void) { if (! CONFIG_ACPI) return; diff --git a/src/acpi.h b/src/acpi.h index 715d19d..8bbf25c 100644 --- a/src/acpi.h +++ b/src/acpi.h @@ -3,7 +3,7 @@
#include "types.h" // u32
-void acpi_bios_init(void); +void acpi_setup(void); u32 find_resume_vector(void);
#define RSDP_SIGNATURE 0x2052545020445352LL // "RSD PTR " diff --git a/src/ahci.c b/src/ahci.c index 4a8eafb..879a991 100644 --- a/src/ahci.c +++ b/src/ahci.c @@ -422,7 +422,7 @@ static void ahci_port_release(struct ahci_port_s *port) #define MAXMODEL 40
/* See ahci spec chapter 10.1 "Software Initialization of HBA" */ -static int ahci_port_init(struct ahci_port_s *port) +static int ahci_port_setup(struct ahci_port_s *port) { struct ahci_ctrl_s *ctrl = port->ctrl; u32 pnr = port->pnr; @@ -549,7 +549,7 @@ ahci_port_detect(void *data)
dprintf(2, "AHCI/%d: probing\n", port->pnr); ahci_port_reset(port->ctrl, port->pnr); - rc = ahci_port_init(port); + rc = ahci_port_setup(port); if (rc < 0) ahci_port_release(port); else { @@ -567,7 +567,7 @@ ahci_port_detect(void *data)
// Initialize an ata controller and detect its drives. static void -ahci_init_controller(struct pci_device *pci) +ahci_controller_setup(struct pci_device *pci) { struct ahci_ctrl_s *ctrl = malloc_fseg(sizeof(*ctrl)); struct ahci_port_s *port; @@ -579,7 +579,7 @@ ahci_init_controller(struct pci_device *pci) return; }
- if (bounce_buf_init() < 0) { + if (create_bounce_buf() < 0) { warn_noalloc(); free(ctrl); return; @@ -616,7 +616,7 @@ ahci_init_controller(struct pci_device *pci)
// Locate and init ahci controllers. static void -ahci_init(void) +ahci_scan(void) { // Scan PCI bus for ATA adapters struct pci_device *pci; @@ -625,7 +625,7 @@ ahci_init(void) continue; if (pci->prog_if != 1 /* AHCI rev 1 */) continue; - ahci_init_controller(pci); + ahci_controller_setup(pci); } }
@@ -637,5 +637,5 @@ ahci_setup(void) return;
dprintf(3, "init ahci\n"); - ahci_init(); + ahci_scan(); } diff --git a/src/ata.c b/src/ata.c index f604b37..d1d8dff 100644 --- a/src/ata.c +++ b/src/ata.c @@ -1006,7 +1006,7 @@ static const struct pci_device_id pci_ata_tbl[] = {
// Locate and init ata controllers. static void -ata_init(void) +ata_scan(void) { if (!CONFIG_COREBOOT && !PCIDevices) { // No PCI devices found - probably a QEMU "-M isapc" machine. @@ -1035,7 +1035,7 @@ ata_setup(void) dprintf(3, "init hard drives\n");
SpinupEnd = calc_future_tsc(IDE_TIMEOUT); - ata_init(); + ata_scan();
SET_BDA(disk_control_byte, 0xc0);
diff --git a/src/block.c b/src/block.c index cfe5c33..e5f3038 100644 --- a/src/block.c +++ b/src/block.c @@ -40,7 +40,7 @@ int getDriveId(u8 exttype, struct drive_s *drive_g) return -1; }
-int bounce_buf_init(void) +int create_bounce_buf(void) { if (bounce_buf_fl) return 0; diff --git a/src/blockcmd.c b/src/blockcmd.c index 81b191b..e033ba7 100644 --- a/src/blockcmd.c +++ b/src/blockcmd.c @@ -101,7 +101,7 @@ scsi_is_ready(struct disk_op_s *op)
// Validate drive, find block size / sector count, and register drive. int -scsi_init_drive(struct drive_s *drive, const char *s, int prio) +scsi_drive_setup(struct drive_s *drive, const char *s, int prio) { struct disk_op_s dop; memset(&dop, 0, sizeof(dop)); diff --git a/src/blockcmd.h b/src/blockcmd.h index b45bbb7..8bacfcf 100644 --- a/src/blockcmd.h +++ b/src/blockcmd.h @@ -113,6 +113,6 @@ int cdb_write(struct disk_op_s *op);
int scsi_is_ready(struct disk_op_s *op); struct drive_s; -int scsi_init_drive(struct drive_s *drive, const char *s, int prio); +int scsi_drive_setup(struct drive_s *drive, const char *s, int prio);
#endif // blockcmd.h diff --git a/src/boot.c b/src/boot.c index 56843e3..2cb3b86 100644 --- a/src/boot.c +++ b/src/boot.c @@ -238,7 +238,7 @@ static int DefaultHDPrio = 103; static int DefaultBEVPrio = 104;
void -boot_setup(void) +boot_init(void) { if (! CONFIG_BOOT) return; @@ -476,7 +476,7 @@ add_bev(int type, u32 vector)
// Prepare for boot - show menu and run bcvs. void -boot_prep(void) +boot_prepboot(void) { if (! CONFIG_BOOT) { wait_threads(); @@ -695,7 +695,7 @@ int BootSequence VARLOW = -1; void VISIBLE32FLAT handle_18(void) { - debug_serial_setup(); + debug_serial_preinit(); debug_enter(NULL, DEBUG_HDL_18); int seq = BootSequence + 1; BootSequence = seq; @@ -706,7 +706,7 @@ handle_18(void) void VISIBLE32FLAT handle_19(void) { - debug_serial_setup(); + debug_serial_preinit(); debug_enter(NULL, DEBUG_HDL_19); BootSequence = 0; do_boot(0); diff --git a/src/boot.h b/src/boot.h index afe9f2e..4a93d0f 100644 --- a/src/boot.h +++ b/src/boot.h @@ -3,7 +3,7 @@ #define __BOOT_H
// boot.c -void boot_setup(void); +void boot_init(void); void boot_add_bev(u16 seg, u16 bev, u16 desc, int prio); void boot_add_bcv(u16 seg, u16 ip, u16 desc, int prio); struct drive_s; @@ -11,7 +11,7 @@ void boot_add_floppy(struct drive_s *drive_g, const char *desc, int prio); void boot_add_hd(struct drive_s *drive_g, const char *desc, int prio); void boot_add_cd(struct drive_s *drive_g, const char *desc, int prio); void boot_add_cbfs(void *data, const char *desc, int prio); -void boot_prep(void); +void boot_prepboot(void); struct pci_device; int bootprio_find_pci_device(struct pci_device *pci); int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun); diff --git a/src/cdrom.c b/src/cdrom.c index 42d8e08..81b97f7 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -107,13 +107,13 @@ process_cdemu_op(struct disk_op_s *op) }
void -cdemu_setup(void) +cdrom_prepboot(void) { if (!CONFIG_CDROM_EMU) return; if (!CDCount) return; - if (bounce_buf_init() < 0) + if (create_bounce_buf() < 0) return;
struct drive_s *drive_g = malloc_fseg(sizeof(*drive_g)); diff --git a/src/clock.c b/src/clock.c index 71b913e..3edcaf5 100644 --- a/src/clock.c +++ b/src/clock.c @@ -133,7 +133,7 @@ u16 pmtimer_ioport VAR16VISIBLE; u32 pmtimer_wraps VARLOW; u32 pmtimer_last VARLOW;
-void pmtimer_init(u16 ioport, u32 khz) +void pmtimer_setup(u16 ioport, u32 khz) { if (!CONFIG_PMTIMER) return; @@ -266,7 +266,7 @@ pit_setup(void) }
static void -init_rtc(void) +rtc_setup(void) { outb_cmos(0x26, CMOS_STATUS_A); // 32,768Khz src, 976.5625us updates u8 regB = inb_cmos(CMOS_STATUS_B); @@ -288,7 +288,7 @@ timer_setup(void) calibrate_tsc(); pit_setup();
- init_rtc(); + rtc_setup(); rtc_updating(); u32 seconds = bcd2bin(inb_cmos(CMOS_RTC_SECONDS)); u32 minutes = bcd2bin(inb_cmos(CMOS_RTC_MINUTES)); @@ -393,7 +393,7 @@ handle_1a03(struct bregs *regs) // Bit4 in try#1 flipped in hardware (forced low) due to bit7=1 // My assumption: RegB = ((RegB & 01100000b) | 00000010b) if (rtc_updating()) { - init_rtc(); + rtc_setup(); // fall through as if an update were not in progress } outb_cmos(regs->dh, CMOS_RTC_SECONDS); @@ -447,7 +447,7 @@ handle_1a05(struct bregs *regs) // Bit4 in try#1 flipped in hardware (forced low) due to bit7=1 // My assumption: RegB = (RegB & 01111111b) if (rtc_updating()) { - init_rtc(); + rtc_setup(); set_invalid(regs); return; } @@ -486,7 +486,7 @@ handle_1a06(struct bregs *regs) return; } if (rtc_updating()) { - init_rtc(); + rtc_setup(); // fall through as if an update were not in progress } outb_cmos(regs->dh, CMOS_RTC_SECONDS_ALARM); diff --git a/src/coreboot.c b/src/coreboot.c index e4767f1..5d013cf 100644 --- a/src/coreboot.c +++ b/src/coreboot.c @@ -123,7 +123,7 @@ const char *CBvendor = "", *CBpart = "";
// Populate max ram and e820 map info by scanning for a coreboot table. void -coreboot_setup(void) +coreboot_preinit(void) { dprintf(3, "Attempting to find coreboot table\n");
@@ -204,7 +204,7 @@ scan_tables(u32 start, u32 size) }
void -coreboot_copy_biostable(void) +coreboot_biostable_setup(void) { struct cb_memory *cbm = CBMemTable; if (! CONFIG_COREBOOT || !cbm) @@ -324,7 +324,7 @@ cbfs_copyfile(struct romfile_s *file, void *dst, u32 maxlen) }
void -coreboot_cbfs_setup(void) +coreboot_cbfs_init(void) { if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH) return; diff --git a/src/disk.h b/src/disk.h index 21debec..8e49124 100644 --- a/src/disk.h +++ b/src/disk.h @@ -266,7 +266,7 @@ void map_hd_drive(struct drive_s *drive_g); void map_cd_drive(struct drive_s *drive_g); int process_op(struct disk_op_s *op); int send_disk_op(struct disk_op_s *op); -int bounce_buf_init(void); +int create_bounce_buf(void);
// floppy.c extern struct floppy_ext_dbt_s diskette_param_table2; @@ -281,7 +281,7 @@ extern u8 CDRom_locks[]; extern struct cdemu_s CDEmu; extern struct drive_s *cdemu_drive_gf; int process_cdemu_op(struct disk_op_s *op); -void cdemu_setup(void); +void cdrom_prepboot(void); void cdemu_134b(struct bregs *regs); int cdrom_boot(struct drive_s *drive_g);
diff --git a/src/esp-scsi.c b/src/esp-scsi.c index c43e55b..4d1f7d2 100644 --- a/src/esp-scsi.c +++ b/src/esp-scsi.c @@ -17,7 +17,7 @@ #include "pci_ids.h" // PCI_DEVICE_ID #include "pci_regs.h" // PCI_VENDOR_ID #include "boot.h" // bootprio_find_scsi_device -#include "blockcmd.h" // scsi_init_drive +#include "blockcmd.h" // scsi_drive_setup #include "disk.h"
#define ESP_TCLO 0x00 @@ -174,7 +174,7 @@ esp_scsi_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), pci_bdf_to_fn(pci->bdf), target, lun); int prio = bootprio_find_scsi_device(pci, target, lun); - int ret = scsi_init_drive(&llun->drive, name, prio); + int ret = scsi_drive_setup(&llun->drive, name, prio); free(name); if (ret) goto fail; diff --git a/src/kbd.c b/src/kbd.c index e9ea594..05845e5 100644 --- a/src/kbd.c +++ b/src/kbd.c @@ -35,7 +35,7 @@ #define KF2_101KBD (1<<4)
void -kbd_setup(void) +kbd_init(void) { dprintf(3, "init keyboard\n"); u16 x = offsetof(struct bios_data_area_s, kbd_buf); diff --git a/src/lsi-scsi.c b/src/lsi-scsi.c index f8d715b..76e9d1d 100644 --- a/src/lsi-scsi.c +++ b/src/lsi-scsi.c @@ -17,7 +17,7 @@ #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID #include "boot.h" // bootprio_find_scsi_device -#include "blockcmd.h" // scsi_init_drive +#include "blockcmd.h" // scsi_drive_setup #include "disk.h"
#define LSI_REG_DSTAT 0x0c @@ -152,7 +152,7 @@ lsi_scsi_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), pci_bdf_to_fn(pci->bdf), target, lun); int prio = bootprio_find_scsi_device(pci, target, lun); - int ret = scsi_init_drive(&llun->drive, name, prio); + int ret = scsi_drive_setup(&llun->drive, name, prio); free(name); if (ret) goto fail; diff --git a/src/megasas.c b/src/megasas.c index 3ccdd0a..170700f 100644 --- a/src/megasas.c +++ b/src/megasas.c @@ -17,7 +17,7 @@ #include "pci_ids.h" // PCI_DEVICE_ID_XXX #include "pci_regs.h" // PCI_VENDOR_ID #include "boot.h" // bootprio_find_scsi_device -#include "blockcmd.h" // scsi_init_drive +#include "blockcmd.h" // scsi_drive_setup #include "disk.h"
#define MFI_DB 0x0 // Doorbell @@ -223,7 +223,7 @@ megasas_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), pci_bdf_to_fn(pci->bdf), target, lun); prio = bootprio_find_scsi_device(pci, target, lun); - ret = scsi_init_drive(&mlun->drive, name, prio); + ret = scsi_drive_setup(&mlun->drive, name, prio); free(name); if (ret) { free(mlun->frame); diff --git a/src/memmap.c b/src/memmap.c index 3783518..29ca644 100644 --- a/src/memmap.c +++ b/src/memmap.c @@ -133,7 +133,7 @@ add_e820(u64 start, u64 size, u32 type)
// Report on final memory locations. void -memmap_finalize(void) +memmap_prepboot(void) { dump_map(); } diff --git a/src/memmap.h b/src/memmap.h index 01c7ddb..783a042 100644 --- a/src/memmap.h +++ b/src/memmap.h @@ -17,7 +17,7 @@ struct e820entry { };
void add_e820(u64 start, u64 size, u32 type); -void memmap_finalize(void); +void memmap_prepboot(void);
// A typical OS page size #define PAGE_SIZE 4096 diff --git a/src/misc.c b/src/misc.c index 54d8aef..bcc450a 100644 --- a/src/misc.c +++ b/src/misc.c @@ -61,7 +61,7 @@ handle_02(void) }
void -mathcp_setup(void) +mathcp_init(void) { dprintf(3, "math cp init\n"); // 80x87 coprocessor installed diff --git a/src/mouse.c b/src/mouse.c index 7b28a63..5371cf6 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -12,7 +12,7 @@ #include "usb-hid.h" // usb_mouse_command
void -mouse_setup(void) +mouse_init(void) { if (! CONFIG_MOUSE) return; diff --git a/src/mptable.c b/src/mptable.c index 3aa3427..2d4e441 100644 --- a/src/mptable.c +++ b/src/mptable.c @@ -13,7 +13,7 @@ #include "pci_regs.h"
void -mptable_init(void) +mptable_setup(void) { if (! CONFIG_MPTABLE) return; diff --git a/src/mptable.h b/src/mptable.h index c4e3c51..6252854 100644 --- a/src/mptable.h +++ b/src/mptable.h @@ -75,6 +75,6 @@ struct mpt_intsrc { } PACKED;
// mptable.c -void mptable_init(void); +void mptable_setup(void);
#endif // mptable.h diff --git a/src/optionroms.c b/src/optionroms.c index 00697b2..c79a706 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -40,7 +40,7 @@ __callrom(struct rom_header *rom, u16 offset, u16 bdf) farcall16big(&br); finish_preempt();
- debug_serial_setup(); + debug_serial_preinit(); }
// Execute a given option rom at the standard entry vector. @@ -410,13 +410,13 @@ optionrom_setup(void) * VGA init ****************************************************************/
-static int S3ResumeVgaInit; +static int S3ResumeVga; int ScreenAndDebug; struct rom_header *VgaROM;
// Call into vga code to turn on console. void -vga_setup(void) +vgarom_setup(void) { if (! CONFIG_OPTIONROMS) return; @@ -425,7 +425,7 @@ vga_setup(void)
// Load some config settings that impact VGA. EnforceChecksum = romfile_loadint("etc/optionroms-checksum", 1); - S3ResumeVgaInit = romfile_loadint("etc/s3-resume-vga-init", !CONFIG_COREBOOT); + S3ResumeVga = romfile_loadint("etc/s3-resume-vga-init", !CONFIG_COREBOOT); ScreenAndDebug = romfile_loadint("etc/screen-and-debug", 1);
if (CONFIG_OPTIONROMS_DEPLOYED) { @@ -459,9 +459,9 @@ vga_setup(void) }
void -s3_resume_vga_init(void) +s3_resume_vga(void) { - if (!S3ResumeVgaInit) + if (!S3ResumeVga) return; if (!VgaROM || ! is_valid_rom(VgaROM)) return; diff --git a/src/output.c b/src/output.c index 83de7f4..e623d37 100644 --- a/src/output.c +++ b/src/output.c @@ -26,7 +26,7 @@ struct putcinfo { u16 DebugOutputPort VAR16VISIBLE = 0x402;
void -debug_serial_setup(void) +debug_serial_preinit(void) { if (!CONFIG_DEBUG_SERIAL) return; diff --git a/src/paravirt.c b/src/paravirt.c index 4b5c441..f180261 100644 --- a/src/paravirt.c +++ b/src/paravirt.c @@ -11,7 +11,7 @@ #include "util.h" // dprintf #include "byteorder.h" // be32_to_cpu #include "ioport.h" // outw -#include "paravirt.h" // qemu_cfg_port_probe +#include "paravirt.h" // qemu_cfg_preinit #include "smbios.h" // struct smbios_structure_header
int qemu_cfg_present; @@ -42,7 +42,7 @@ qemu_cfg_read_entry(void *buf, int e, int len) qemu_cfg_read(buf, len); }
-void qemu_cfg_port_probe(void) +void qemu_cfg_preinit(void) { char *sig = "QEMU"; int i; @@ -321,7 +321,7 @@ struct QemuCfgFile { char name[56]; };
-void qemu_cfg_romfile_setup(void) +void qemu_romfile_init(void) { if (CONFIG_COREBOOT || !qemu_cfg_present) return; diff --git a/src/paravirt.h b/src/paravirt.h index a284c41..765a6c1 100644 --- a/src/paravirt.h +++ b/src/paravirt.h @@ -43,7 +43,7 @@ static inline int kvm_para_available(void)
extern int qemu_cfg_present;
-void qemu_cfg_port_probe(void); +void qemu_cfg_preinit(void); int qemu_cfg_show_boot_menu(void); void qemu_cfg_get_uuid(u8 *uuid); int qemu_cfg_irq0_override(void); @@ -64,6 +64,6 @@ struct e820_reservation { }; u32 qemu_cfg_e820_entries(void); void* qemu_cfg_e820_load_next(void *addr); -void qemu_cfg_romfile_setup(void); +void qemu_romfile_init(void);
#endif diff --git a/src/pci.h b/src/pci.h index fe663b8..aa54dd7 100644 --- a/src/pci.h +++ b/src/pci.h @@ -118,7 +118,7 @@ u32 pci_readl(u32 addr); void pci_writel(u32 addr, u32 val);
// pirtable.c -void create_pirtable(void); +void pirtable_setup(void);
/**************************************************************** diff --git a/src/pcibios.c b/src/pcibios.c index e4bd7c0..f084fa1 100644 --- a/src/pcibios.c +++ b/src/pcibios.c @@ -229,7 +229,7 @@ struct bios32_s BIOS32HEADER __aligned(16) VAR16EXPORT = { };
void -bios32_setup(void) +bios32_init(void) { dprintf(3, "init bios32\n");
diff --git a/src/pciinit.c b/src/pciinit.c index a406bbd..34b47b6 100644 --- a/src/pciinit.c +++ b/src/pciinit.c @@ -105,7 +105,7 @@ static int pci_slot_get_irq(struct pci_device *pci, int pin) }
/* PIIX3/PIIX4 PCI to ISA bridge */ -static void piix_isa_bridge_init(struct pci_device *pci, void *arg) +static void piix_isa_bridge_setup(struct pci_device *pci, void *arg) { int i, irq; u8 elcr[2]; @@ -126,7 +126,7 @@ static void piix_isa_bridge_init(struct pci_device *pci, void *arg)
/* ICH9 LPC PCI to ISA bridge */ /* PCI_VENDOR_ID_INTEL && PCI_DEVICE_ID_INTEL_ICH9_LPC */ -void mch_isa_bridge_init(struct pci_device *dev, void *arg) +void mch_isa_bridge_setup(struct pci_device *dev, void *arg) { u16 bdf = dev->bdf; int i, irq; @@ -160,10 +160,10 @@ void mch_isa_bridge_init(struct pci_device *dev, void *arg) /* acpi enable, SCI: IRQ9 000b = irq9*/ pci_config_writeb(bdf, ICH9_LPC_ACPI_CTRL, ICH9_LPC_ACPI_CTRL_ACPI_EN);
- pmtimer_init(PORT_ACPI_PM_BASE + 0x08, PM_TIMER_FREQUENCY / 1000); + pmtimer_setup(PORT_ACPI_PM_BASE + 0x08, PM_TIMER_FREQUENCY / 1000); }
-static void storage_ide_init(struct pci_device *pci, void *arg) +static void storage_ide_setup(struct pci_device *pci, void *arg) { /* IDE: we map it as in ISA mode */ pci_set_io_region_addr(pci, 0, PORT_ATA1_CMD_BASE, 0); @@ -173,27 +173,27 @@ static void storage_ide_init(struct pci_device *pci, void *arg) }
/* PIIX3/PIIX4 IDE */ -static void piix_ide_init(struct pci_device *pci, void *arg) +static void piix_ide_setup(struct pci_device *pci, void *arg) { u16 bdf = pci->bdf; pci_config_writew(bdf, 0x40, 0x8000); // enable IDE0 pci_config_writew(bdf, 0x42, 0x8000); // enable IDE1 }
-static void pic_ibm_init(struct pci_device *pci, void *arg) +static void pic_ibm_setup(struct pci_device *pci, void *arg) { /* PIC, IBM, MPIC & MPIC2 */ pci_set_io_region_addr(pci, 0, 0x80800000 + 0x00040000, 0); }
-static void apple_macio_init(struct pci_device *pci, void *arg) +static void apple_macio_setup(struct pci_device *pci, void *arg) { /* macio bridge */ pci_set_io_region_addr(pci, 0, 0x80800000, 0); }
/* PIIX4 Power Management device (for ACPI) */ -static void piix4_pm_init(struct pci_device *pci, void *arg) +static void piix4_pm_setup(struct pci_device *pci, void *arg) { u16 bdf = pci->bdf; // acpi sci is hardwired to 9 @@ -204,12 +204,12 @@ static void piix4_pm_init(struct pci_device *pci, void *arg) pci_config_writel(bdf, 0x90, PORT_SMB_BASE | 1); pci_config_writeb(bdf, 0xd2, 0x09); /* enable SMBus io space */
- pmtimer_init(PORT_ACPI_PM_BASE + 0x08, PM_TIMER_FREQUENCY / 1000); + pmtimer_setup(PORT_ACPI_PM_BASE + 0x08, PM_TIMER_FREQUENCY / 1000); }
/* ICH9 SMBUS */ /* PCI_VENDOR_ID_INTEL && PCI_DEVICE_ID_INTEL_ICH9_SMBUS */ -void ich9_smbus_init(struct pci_device *dev, void *arg) +void ich9_smbus_setup(struct pci_device *dev, void *arg) { u16 bdf = dev->bdf; /* map smbus into io space */ @@ -223,35 +223,35 @@ void ich9_smbus_init(struct pci_device *dev, void *arg) static const struct pci_device_id pci_device_tbl[] = { /* PIIX3/PIIX4 PCI to ISA bridge */ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_0, - piix_isa_bridge_init), + piix_isa_bridge_setup), PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0, - piix_isa_bridge_init), + piix_isa_bridge_setup), PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_LPC, - mch_isa_bridge_init), + mch_isa_bridge_setup),
/* STORAGE IDE */ PCI_DEVICE_CLASS(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_1, - PCI_CLASS_STORAGE_IDE, piix_ide_init), + PCI_CLASS_STORAGE_IDE, piix_ide_setup), PCI_DEVICE_CLASS(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB, - PCI_CLASS_STORAGE_IDE, piix_ide_init), + PCI_CLASS_STORAGE_IDE, piix_ide_setup), PCI_DEVICE_CLASS(PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE, - storage_ide_init), + storage_ide_setup),
/* PIC, IBM, MIPC & MPIC2 */ PCI_DEVICE_CLASS(PCI_VENDOR_ID_IBM, 0x0046, PCI_CLASS_SYSTEM_PIC, - pic_ibm_init), + pic_ibm_setup), PCI_DEVICE_CLASS(PCI_VENDOR_ID_IBM, 0xFFFF, PCI_CLASS_SYSTEM_PIC, - pic_ibm_init), + pic_ibm_setup),
/* PIIX4 Power Management device (for ACPI) */ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, - piix4_pm_init), + piix4_pm_setup), PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_SMBUS, - ich9_smbus_init), + ich9_smbus_setup),
/* 0xff00 */ - PCI_DEVICE_CLASS(PCI_VENDOR_ID_APPLE, 0x0017, 0xff00, apple_macio_init), - PCI_DEVICE_CLASS(PCI_VENDOR_ID_APPLE, 0x0022, 0xff00, apple_macio_init), + PCI_DEVICE_CLASS(PCI_VENDOR_ID_APPLE, 0x0017, 0xff00, apple_macio_setup), + PCI_DEVICE_CLASS(PCI_VENDOR_ID_APPLE, 0x0022, 0xff00, apple_macio_setup),
PCI_DEVICE_END, }; @@ -288,7 +288,7 @@ static void pci_bios_init_devices(void) * Platform device initialization ****************************************************************/
-void i440fx_mem_addr_init(struct pci_device *dev, void *arg) +void i440fx_mem_addr_setup(struct pci_device *dev, void *arg) { if (RamSize <= 0x80000000) pcimem_start = 0x80000000; @@ -296,7 +296,7 @@ void i440fx_mem_addr_init(struct pci_device *dev, void *arg) pcimem_start = 0xc0000000; }
-void mch_mem_addr_init(struct pci_device *dev, void *arg) +void mch_mem_addr_setup(struct pci_device *dev, void *arg) { u64 addr = Q35_HOST_BRIDGE_PCIEXBAR_ADDR; u32 size = Q35_HOST_BRIDGE_PCIEXBAR_SIZE; @@ -316,9 +316,9 @@ void mch_mem_addr_init(struct pci_device *dev, void *arg)
static const struct pci_device_id pci_platform_tbl[] = { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, - i440fx_mem_addr_init), + i440fx_mem_addr_setup), PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q35_MCH, - mch_mem_addr_init), + mch_mem_addr_setup), PCI_DEVICE_END };
diff --git a/src/pirtable.c b/src/pirtable.c index 8eadbf0..62b62b8 100644 --- a/src/pirtable.c +++ b/src/pirtable.c @@ -92,7 +92,7 @@ struct pir_table PIR_TABLE __aligned(16) VAR16EXPORT = { #endif // CONFIG_PIRTABLE && !CONFIG_COREBOOT
void -create_pirtable(void) +pirtable_setup(void) { if (! CONFIG_PIRTABLE) return; diff --git a/src/pmm.c b/src/pmm.c index 6ddeae1..cf05bd0 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -217,7 +217,7 @@ rom_confirm(u32 size) ****************************************************************/
void -malloc_setup(void) +malloc_preinit(void) { ASSERT32FLAT(); dprintf(3, "malloc setup\n"); @@ -258,7 +258,7 @@ malloc_setup(void)
// Update pointers after code relocation. void -malloc_fixupreloc(void) +malloc_fixupreloc_init(void) { ASSERT32FLAT(); if (!CONFIG_RELOCATE_INIT) @@ -286,7 +286,7 @@ malloc_fixupreloc(void) }
void -malloc_finalize(void) +malloc_prepboot(void) { ASSERT32FLAT(); dprintf(3, "malloc finalize\n"); @@ -550,7 +550,7 @@ handle_pmm(u16 *args) }
void -pmm_setup(void) +pmm_init(void) { if (! CONFIG_PMM) return; @@ -562,7 +562,7 @@ pmm_setup(void) }
void -pmm_finalize(void) +pmm_prepboot(void) { if (! CONFIG_PMM) return; diff --git a/src/pnpbios.c b/src/pnpbios.c index b1bebc9..c8bc8f4 100644 --- a/src/pnpbios.c +++ b/src/pnpbios.c @@ -90,7 +90,7 @@ extern void entry_pnp_real(void); extern void entry_pnp_prot(void);
void -pnp_setup(void) +pnp_init(void) { if (! CONFIG_PNPBIOS) return; diff --git a/src/post.c b/src/post.c index 6a91f81..6f5dfef 100644 --- a/src/post.c +++ b/src/post.c @@ -23,7 +23,7 @@ #include "usb.h" // usb_setup #include "smbios.h" // smbios_init #include "paravirt.h" // qemu_cfg_port_probe -#include "xen.h" // xen_probe_hvm_info +#include "xen.h" // xen_preinit #include "ps2port.h" // ps2port_setup #include "virtio-blk.h" // virtio_blk_setup #include "virtio-scsi.h" // virtio_scsi_setup @@ -36,7 +36,7 @@ ****************************************************************/
static void -init_ivt(void) +ivt_init(void) { dprintf(3, "init ivt\n");
@@ -76,7 +76,7 @@ init_ivt(void) }
static void -init_bda(void) +bda_init(void) { dprintf(3, "init bda\n");
@@ -101,13 +101,13 @@ init_bda(void) }
static void -ram_probe(void) +ramsize_preinit(void) { dprintf(3, "Find memory size\n"); if (CONFIG_COREBOOT) { - coreboot_setup(); + coreboot_preinit(); } else if (usingXen()) { - xen_setup(); + xen_ramsize_preinit(); } else { // On emulators, get memory size from nvram. u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16) @@ -158,29 +158,29 @@ ram_probe(void) }
static void -init_bios_tables(void) +biostable_setup(void) { if (CONFIG_COREBOOT) { - coreboot_copy_biostable(); + coreboot_biostable_setup(); return; } if (usingXen()) { - xen_copy_biostables(); + xen_biostable_setup(); return; }
- create_pirtable(); + pirtable_setup();
- mptable_init(); + mptable_setup();
- smbios_init(); + smbios_setup();
- acpi_bios_init(); + acpi_setup(); }
// Initialize hardware devices static void -init_hw(void) +device_hardware_setup(void) { usb_setup(); ps2port_setup(); @@ -218,58 +218,58 @@ void VISIBLE32INIT maininit(void) { // Running at new code address - do code relocation fixups - malloc_fixupreloc(); + malloc_fixupreloc_init();
// Setup romfile items. - qemu_cfg_romfile_setup(); - coreboot_cbfs_setup(); + qemu_romfile_init(); + coreboot_cbfs_init();
// Setup ivt/bda/ebda - init_ivt(); - init_bda(); + ivt_init(); + bda_init();
// Init base pc hardware. pic_setup(); timer_setup(); - mathcp_setup(); + mathcp_init();
// Initialize pci pci_setup(); - smm_init(); + smm_setup();
// Initialize mtrr mtrr_setup();
// Setup Xen hypercalls - xen_init_hypercalls(); + xen_hypercall_setup();
// Initialize internal tables - boot_setup(); + boot_init();
// Start hardware initialization (if optionrom threading) if (CONFIG_THREADS && CONFIG_THREAD_OPTIONROMS) - init_hw(); + device_hardware_setup();
// Find and initialize other cpus - smp_probe(); + smp_setup();
// Setup interfaces that option roms may need - bios32_setup(); - pmm_setup(); - pnp_setup(); - kbd_setup(); - mouse_setup(); - init_bios_tables(); + bios32_init(); + pmm_init(); + pnp_init(); + kbd_init(); + mouse_init(); + biostable_setup();
// Run vga option rom - vga_setup(); + vgarom_setup();
// SMBIOS tables and VGA console are ready, print UUID display_uuid();
// Do hardware initialization (if running synchronously) if (!CONFIG_THREADS || !CONFIG_THREAD_OPTIONROMS) { - init_hw(); + device_hardware_setup(); wait_threads(); }
@@ -277,13 +277,13 @@ maininit(void) optionrom_setup();
// Run BCVs and show optional boot menu - boot_prep(); + boot_prepboot();
// Finalize data structures before boot - cdemu_setup(); - pmm_finalize(); - malloc_finalize(); - memmap_finalize(); + cdrom_prepboot(); + pmm_prepboot(); + malloc_prepboot(); + memmap_prepboot();
// Setup bios checksum. BiosChecksum -= checksum((u8*)BUILD_BIOS_ADDR, BUILD_BIOS_SIZE); @@ -308,7 +308,7 @@ updateRelocs(void *dest, u32 *rstart, u32 *rend, u32 delta)
// Relocate init code and then call maininit() at new address. static void -reloc_init(void) +reloc_preinit(void) { if (!CONFIG_RELOCATE_INIT) return; @@ -352,12 +352,12 @@ doreloc(void) HaveRunPost = 1;
// Detect ram and setup internal malloc. - qemu_cfg_port_probe(); - ram_probe(); - malloc_setup(); + qemu_cfg_preinit(); + ramsize_preinit(); + malloc_preinit();
// Relocate initialization code. - reloc_init(); + reloc_preinit(); }
// Entry point for Power On Self Test (POST) - the BIOS initilization @@ -366,7 +366,7 @@ doreloc(void) void VISIBLE32FLAT handle_post(void) { - debug_serial_setup(); + debug_serial_preinit(); dprintf(1, "Start bios (version %s)\n", VERSION);
// Enable CPU caching @@ -376,10 +376,10 @@ handle_post(void) outb_cmos(0, CMOS_RESET_CODE);
// Make sure legacy DMA isn't running. - init_dma(); + dma_preinit();
// Check if we are running under Xen. - xen_probe(); + xen_preinit();
// Allow writes to modify bios area (0xf0000) make_bios_writable(); diff --git a/src/ps2port.c b/src/ps2port.c index d4626d6..9b760fd 100644 --- a/src/ps2port.c +++ b/src/ps2port.c @@ -417,7 +417,7 @@ done: ****************************************************************/
static void -keyboard_init(void *data) +ps2_keyboard_setup(void *data) { /* flush incoming keys */ int ret = i8042_flush(); @@ -500,5 +500,5 @@ ps2port_setup(void) enable_hwirq(1, FUNC16(entry_09)); enable_hwirq(12, FUNC16(entry_74));
- run_thread(keyboard_init, NULL); + run_thread(ps2_keyboard_setup, NULL); } diff --git a/src/resume.c b/src/resume.c index f1a96ac..99265cd 100644 --- a/src/resume.c +++ b/src/resume.c @@ -19,7 +19,7 @@ int HaveRunPost VAR16VISIBLE;
// Reset DMA controller void -init_dma(void) +dma_preinit(void) { // first reset the DMA controllers outb(0, PORT_DMA1_MASTER_CLEAR); @@ -35,12 +35,12 @@ void VISIBLE16 handle_resume(void) { ASSERT16(); - debug_serial_setup(); + debug_serial_preinit(); int status = inb_cmos(CMOS_RESET_CODE); outb_cmos(0, CMOS_RESET_CODE); dprintf(1, "In resume (status=%d)\n", status);
- init_dma(); + dma_preinit();
switch (status) { case 0x01 ... 0x04: @@ -109,9 +109,9 @@ s3_resume(void) }
pic_setup(); - smm_init(); + smm_setup();
- s3_resume_vga_init(); + s3_resume_vga();
make_bios_readonly();
diff --git a/src/smbios.c b/src/smbios.c index 23713a2..c235564 100644 --- a/src/smbios.c +++ b/src/smbios.c @@ -12,10 +12,10 @@ struct smbios_entry_point *SMBiosAddr;
static void -smbios_entry_point_init(u16 max_structure_size, - u16 structure_table_length, - void *structure_table_address, - u16 number_of_structures) +smbios_entry_point_setup(u16 max_structure_size, + u16 structure_table_length, + void *structure_table_address, + u16 number_of_structures) { struct smbios_entry_point *ep = malloc_fseg(sizeof(*ep)); void *finaltable; @@ -441,7 +441,7 @@ smbios_init_type_127(void *start) #define TEMPSMBIOSSIZE (32 * 1024)
void -smbios_init(void) +smbios_setup(void) { if (! CONFIG_SMBIOS) return; @@ -518,7 +518,7 @@ smbios_init(void)
#undef add_struct
- smbios_entry_point_init(max_struct_size, p - start, start, nr_structs); + smbios_entry_point_setup(max_struct_size, p - start, start, nr_structs); free(start); }
diff --git a/src/smbios.h b/src/smbios.h index 5bf0392..a4c1444 100644 --- a/src/smbios.h +++ b/src/smbios.h @@ -2,7 +2,7 @@ #define __SMBIOS_H
// smbios.c -void smbios_init(void); +void smbios_setup(void);
/* SMBIOS entry point -- must be written to a 16-bit aligned address between 0xf0000 and 0xfffff. diff --git a/src/smm.c b/src/smm.c index 7977ac7..c69f0fd 100644 --- a/src/smm.c +++ b/src/smm.c @@ -112,7 +112,7 @@ smm_relocate_and_restore(void) #define PIIX_APMC_EN (1 << 25)
// This code is hardcoded for PIIX4 Power Management device. -static void piix4_apmc_smm_init(struct pci_device *pci, void *arg) +static void piix4_apmc_smm_setup(struct pci_device *pci, void *arg) { struct pci_device *i440_pci = pci_find_device(PCI_VENDOR_ID_INTEL , PCI_DEVICE_ID_INTEL_82441); @@ -139,7 +139,7 @@ static void piix4_apmc_smm_init(struct pci_device *pci, void *arg) }
/* PCI_VENDOR_ID_INTEL && PCI_DEVICE_ID_INTEL_ICH9_LPC */ -void ich9_lpc_apmc_smm_init(struct pci_device *dev, void *arg) +void ich9_lpc_apmc_smm_setup(struct pci_device *dev, void *arg) { struct pci_device *mch_dev; int mch_bdf; @@ -174,15 +174,15 @@ void ich9_lpc_apmc_smm_init(struct pci_device *dev, void *arg)
static const struct pci_device_id smm_init_tbl[] = { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, - piix4_apmc_smm_init), + piix4_apmc_smm_setup), PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_LPC, - ich9_lpc_apmc_smm_init), + ich9_lpc_apmc_smm_setup),
PCI_DEVICE_END, };
void -smm_init(void) +smm_setup(void) { if (CONFIG_COREBOOT) // SMM only supported on emulators. diff --git a/src/smp.c b/src/smp.c index 4975412..18bb05f 100644 --- a/src/smp.c +++ b/src/smp.c @@ -82,7 +82,7 @@ int apic_id_is_present(u8 apic_id)
// find and initialize the CPUs by launching a SIPI to them void -smp_probe(void) +smp_setup(void) { ASSERT32FLAT(); u32 eax, ebx, ecx, cpuid_features; diff --git a/src/usb-ehci.c b/src/usb-ehci.c index 2676615..f28f343 100644 --- a/src/usb-ehci.c +++ b/src/usb-ehci.c @@ -13,8 +13,8 @@ #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "usb.h" // struct usb_s #include "biosvar.h" // GET_LOWFLAT -#include "usb-uhci.h" // init_uhci -#include "usb-ohci.h" // init_ohci +#include "usb-uhci.h" // uhci_setup +#include "usb-ohci.h" // ohci_setup
struct usb_ehci_s { struct usb_s usb; @@ -58,13 +58,13 @@ ehci_note_port(struct usb_ehci_s *cntl) if (!pci) break;
- // ohci/uhci_init call pci_config_XXX - don't run from irq handler. + // ohci/uhci_setup call pci_config_X - don't run from irq handler. wait_preempt();
if (pci_classprog(pci) == PCI_CLASS_SERIAL_USB_UHCI) - uhci_init(pci, cntl->usb.busid + i); + uhci_setup(pci, cntl->usb.busid + i); else if (pci_classprog(pci) == PCI_CLASS_SERIAL_USB_OHCI) - ohci_init(pci, cntl->usb.busid + i); + ohci_setup(pci, cntl->usb.busid + i); } }
@@ -327,7 +327,7 @@ fail: }
int -ehci_init(struct pci_device *pci, int busid, struct pci_device *comppci) +ehci_setup(struct pci_device *pci, int busid, struct pci_device *comppci) { if (! CONFIG_USB_EHCI) return -1; diff --git a/src/usb-ehci.h b/src/usb-ehci.h index 32e4109..5672033 100644 --- a/src/usb-ehci.h +++ b/src/usb-ehci.h @@ -2,7 +2,7 @@ #define __USB_EHCI_H
// usb-ehci.c -int ehci_init(struct pci_device *pci, int busid, struct pci_device *comppci); +int ehci_setup(struct pci_device *pci, int busid, struct pci_device *comppci); struct usbdevice_s; struct usb_endpoint_descriptor; struct usb_pipe *ehci_alloc_pipe(struct usbdevice_s *usbdev diff --git a/src/usb-hid.c b/src/usb-hid.c index 8c4b803..0d5f371 100644 --- a/src/usb-hid.c +++ b/src/usb-hid.c @@ -49,8 +49,8 @@ set_idle(struct usb_pipe *pipe, int ms) #define KEYREPEATMS 33
static int -usb_kbd_init(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc) +usb_kbd_setup(struct usbdevice_s *usbdev + , struct usb_endpoint_descriptor *epdesc) { if (! CONFIG_USB_KEYBOARD) return -1; @@ -79,8 +79,8 @@ usb_kbd_init(struct usbdevice_s *usbdev }
static int -usb_mouse_init(struct usbdevice_s *usbdev - , struct usb_endpoint_descriptor *epdesc) +usb_mouse_setup(struct usbdevice_s *usbdev + , struct usb_endpoint_descriptor *epdesc) { if (! CONFIG_USB_MOUSE) return -1; @@ -106,11 +106,11 @@ usb_mouse_init(struct usbdevice_s *usbdev
// Initialize a found USB HID device (if applicable). int -usb_hid_init(struct usbdevice_s *usbdev) +usb_hid_setup(struct usbdevice_s *usbdev) { if (! CONFIG_USB_KEYBOARD || ! CONFIG_USB_MOUSE) return -1; - dprintf(2, "usb_hid_init %p\n", usbdev->defpipe); + dprintf(2, "usb_hid_setup %p\n", usbdev->defpipe);
struct usb_interface_descriptor *iface = usbdev->iface; if (iface->bInterfaceSubClass != USB_INTERFACE_SUBCLASS_BOOT) @@ -126,9 +126,9 @@ usb_hid_init(struct usbdevice_s *usbdev) }
if (iface->bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD) - return usb_kbd_init(usbdev, epdesc); + return usb_kbd_setup(usbdev, epdesc); if (iface->bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE) - return usb_mouse_init(usbdev, epdesc); + return usb_mouse_setup(usbdev, epdesc); return -1; }
diff --git a/src/usb-hid.h b/src/usb-hid.h index bd6445c..ef34e79 100644 --- a/src/usb-hid.h +++ b/src/usb-hid.h @@ -3,7 +3,7 @@
// usb-hid.c struct usbdevice_s; -int usb_hid_init(struct usbdevice_s *usbdev); +int usb_hid_setup(struct usbdevice_s *usbdev); inline int usb_kbd_active(void); inline int usb_kbd_command(int command, u8 *param); inline int usb_mouse_active(void); diff --git a/src/usb-hub.c b/src/usb-hub.c index 6f1aaa1..894ed7d 100644 --- a/src/usb-hub.c +++ b/src/usb-hub.c @@ -158,7 +158,7 @@ static struct usbhub_op_s HubOp = {
// Configure a usb hub and then find devices connected to it. int -usb_hub_init(struct usbdevice_s *usbdev) +usb_hub_setup(struct usbdevice_s *usbdev) { ASSERT32FLAT(); if (!CONFIG_USB_HUB) diff --git a/src/usb-hub.h b/src/usb-hub.h index a75cbda..5b09947 100644 --- a/src/usb-hub.h +++ b/src/usb-hub.h @@ -3,7 +3,7 @@
// usb-hub.c struct usbdevice_s; -int usb_hub_init(struct usbdevice_s *usbdev); +int usb_hub_setup(struct usbdevice_s *usbdev);
/**************************************************************** diff --git a/src/usb-msc.c b/src/usb-msc.c index 83c7397..7b2524d 100644 --- a/src/usb-msc.c +++ b/src/usb-msc.c @@ -6,7 +6,7 @@
#include "util.h" // dprintf #include "config.h" // CONFIG_USB_MSC -#include "usb-msc.h" // usb_msc_init +#include "usb-msc.h" // usb_msc_setup #include "usb.h" // struct usb_s #include "biosvar.h" // GET_GLOBAL #include "blockcmd.h" // cdb_read @@ -135,8 +135,8 @@ usb_msc_maxlun(struct usb_pipe *pipe) }
static int -usb_msc_init_lun(struct usb_pipe *inpipe, struct usb_pipe *outpipe, - struct usbdevice_s *usbdev, int lun) +usb_msc_lun_setup(struct usb_pipe *inpipe, struct usb_pipe *outpipe, + struct usbdevice_s *usbdev, int lun) { // Allocate drive structure. struct usbdrive_s *udrive_g = malloc_fseg(sizeof(*udrive_g)); @@ -151,7 +151,7 @@ usb_msc_init_lun(struct usb_pipe *inpipe, struct usb_pipe *outpipe, udrive_g->lun = lun;
int prio = bootprio_find_usb(usbdev, lun); - int ret = scsi_init_drive(&udrive_g->drive, "USB MSC", prio); + int ret = scsi_drive_setup(&udrive_g->drive, "USB MSC", prio); if (ret) { dprintf(1, "Unable to configure USB MSC drive.\n"); free(udrive_g); @@ -166,7 +166,7 @@ usb_msc_init_lun(struct usb_pipe *inpipe, struct usb_pipe *outpipe,
// Configure a usb msc device. int -usb_msc_init(struct usbdevice_s *usbdev) +usb_msc_setup(struct usbdevice_s *usbdev) { if (!CONFIG_USB_MSC) return -1; @@ -198,7 +198,7 @@ usb_msc_init(struct usbdevice_s *usbdev) int maxlun = usb_msc_maxlun(usbdev->defpipe); int lun, pipesused = 0; for (lun = 0; lun < maxlun + 1; lun++) { - int ret = usb_msc_init_lun(inpipe, outpipe, usbdev, lun); + int ret = usb_msc_lun_setup(inpipe, outpipe, usbdev, lun); if (!ret) pipesused = 1; } diff --git a/src/usb-msc.h b/src/usb-msc.h index 3746b77..c40d755 100644 --- a/src/usb-msc.h +++ b/src/usb-msc.h @@ -5,6 +5,6 @@ struct disk_op_s; int usb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); struct usbdevice_s; -int usb_msc_init(struct usbdevice_s *usbdev); +int usb_msc_setup(struct usbdevice_s *usbdev);
#endif // ush-msc.h diff --git a/src/usb-ohci.c b/src/usb-ohci.c index e219c5f..ef6a52c 100644 --- a/src/usb-ohci.c +++ b/src/usb-ohci.c @@ -262,7 +262,7 @@ free: }
void -ohci_init(struct pci_device *pci, int busid) +ohci_setup(struct pci_device *pci, int busid) { if (! CONFIG_USB_OHCI) return; diff --git a/src/usb-ohci.h b/src/usb-ohci.h index 25900a7..ad0ffec 100644 --- a/src/usb-ohci.h +++ b/src/usb-ohci.h @@ -2,7 +2,7 @@ #define __USB_OHCI_H
// usb-ohci.c -void ohci_init(struct pci_device *pci, int busid); +void ohci_setup(struct pci_device *pci, int busid); struct usbdevice_s; struct usb_endpoint_descriptor; struct usb_pipe *ohci_alloc_pipe(struct usbdevice_s *usbdev diff --git a/src/usb-uas.c b/src/usb-uas.c index be153ed..3169389 100644 --- a/src/usb-uas.c +++ b/src/usb-uas.c @@ -164,10 +164,10 @@ fail: }
static int -uas_init_lun(struct usbdevice_s *usbdev, - struct usb_pipe *command, struct usb_pipe *status, - struct usb_pipe *data_in, struct usb_pipe *data_out, - int lun) +uas_lun_setup(struct usbdevice_s *usbdev, + struct usb_pipe *command, struct usb_pipe *status, + struct usb_pipe *data_in, struct usb_pipe *data_out, + int lun) { // Allocate drive structure. struct uasdrive_s *drive = malloc_fseg(sizeof(*drive)); @@ -184,7 +184,7 @@ uas_init_lun(struct usbdevice_s *usbdev, drive->lun = lun;
int prio = bootprio_find_usb(usbdev, lun); - int ret = scsi_init_drive(&drive->drive, "USB UAS", prio); + int ret = scsi_drive_setup(&drive->drive, "USB UAS", prio); if (ret) { free(drive); return -1; @@ -193,7 +193,7 @@ uas_init_lun(struct usbdevice_s *usbdev, }
int -usb_uas_init(struct usbdevice_s *usbdev) +usb_uas_setup(struct usbdevice_s *usbdev) { if (!CONFIG_USB_UAS) return -1; @@ -247,7 +247,7 @@ usb_uas_init(struct usbdevice_s *usbdev) goto fail;
/* TODO: send REPORT LUNS. For now, only LUN 0 is recognized. */ - int ret = uas_init_lun(usbdev, command, status, data_in, data_out, 0); + int ret = uas_lun_setup(usbdev, command, status, data_in, data_out, 0); if (ret < 0) { dprintf(1, "Unable to configure UAS drive.\n"); goto fail; diff --git a/src/usb-uas.h b/src/usb-uas.h index ed1d473..ad91c5f 100644 --- a/src/usb-uas.h +++ b/src/usb-uas.h @@ -4,6 +4,6 @@ struct disk_op_s; int uas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); struct usbdevice_s; -int usb_uas_init(struct usbdevice_s *usbdev); +int usb_uas_setup(struct usbdevice_s *usbdev);
#endif /* __USB_UAS_H */ diff --git a/src/usb-uhci.c b/src/usb-uhci.c index 17145e5..4098bf2 100644 --- a/src/usb-uhci.c +++ b/src/usb-uhci.c @@ -235,7 +235,7 @@ fail: }
void -uhci_init(struct pci_device *pci, int busid) +uhci_setup(struct pci_device *pci, int busid) { if (! CONFIG_USB_UHCI) return; diff --git a/src/usb-uhci.h b/src/usb-uhci.h index 9e3297c..b83c487 100644 --- a/src/usb-uhci.h +++ b/src/usb-uhci.h @@ -2,7 +2,7 @@ #define __USB_UHCI_H
// usb-uhci.c -void uhci_init(struct pci_device *pci, int busid); +void uhci_setup(struct pci_device *pci, int busid); struct usbdevice_s; struct usb_endpoint_descriptor; struct usb_pipe *uhci_alloc_pipe(struct usbdevice_s *usbdev diff --git a/src/usb.c b/src/usb.c index 421d0b8..6e43f13 100644 --- a/src/usb.c +++ b/src/usb.c @@ -9,13 +9,13 @@ #include "config.h" // CONFIG_* #include "pci_regs.h" // PCI_CLASS_REVISION #include "pci_ids.h" // PCI_CLASS_SERIAL_USB_UHCI -#include "usb-uhci.h" // uhci_init -#include "usb-ohci.h" // ohci_init -#include "usb-ehci.h" // ehci_init +#include "usb-uhci.h" // uhci_setup +#include "usb-ohci.h" // ohci_setup +#include "usb-ehci.h" // ehci_setup #include "usb-hid.h" // usb_keyboard_setup -#include "usb-hub.h" // usb_hub_init -#include "usb-msc.h" // usb_msc_init -#include "usb-uas.h" // usb_uas_init +#include "usb-hub.h" // usb_hub_setup +#include "usb-msc.h" // usb_msc_setup +#include "usb-uas.h" // usb_uas_setup #include "usb.h" // struct usb_s #include "biosvar.h" // GET_GLOBAL
@@ -323,14 +323,14 @@ configure_usb_device(struct usbdevice_s *usbdev) usbdev->iface = iface; usbdev->imax = (void*)config + config->wTotalLength - (void*)iface; if (iface->bInterfaceClass == USB_CLASS_HUB) - ret = usb_hub_init(usbdev); + ret = usb_hub_setup(usbdev); else if (iface->bInterfaceClass == USB_CLASS_MASS_STORAGE) { if (iface->bInterfaceProtocol == US_PR_BULK) - ret = usb_msc_init(usbdev); + ret = usb_msc_setup(usbdev); if (iface->bInterfaceProtocol == US_PR_UAS) - ret = usb_uas_init(usbdev); + ret = usb_uas_setup(usbdev); } else - ret = usb_hid_init(usbdev); + ret = usb_hid_setup(usbdev); if (ret) goto fail;
@@ -342,7 +342,7 @@ fail: }
static void -usb_init_hub_port(void *data) +usb_hub_port_setup(void *data) { struct usbdevice_s *usbdev = data; struct usbhub_s *hub = usbdev->hub; @@ -403,7 +403,7 @@ usb_enumerate(struct usbhub_s *hub) memset(usbdev, 0, sizeof(*usbdev)); usbdev->hub = hub; usbdev->port = i; - run_thread(usb_init_hub_port, usbdev); + run_thread(usb_hub_port_setup, usbdev); }
// Wait for threads to complete. @@ -435,7 +435,7 @@ usb_setup(void) for (;;) { if (pci_classprog(ehcipci) == PCI_CLASS_SERIAL_USB_EHCI) { // Found an ehci controller. - int ret = ehci_init(ehcipci, count++, pci); + int ret = ehci_setup(ehcipci, count++, pci); if (ret) // Error break; @@ -454,8 +454,8 @@ usb_setup(void) }
if (pci_classprog(pci) == PCI_CLASS_SERIAL_USB_UHCI) - uhci_init(pci, count++); + uhci_setup(pci, count++); else if (pci_classprog(pci) == PCI_CLASS_SERIAL_USB_OHCI) - ohci_init(pci, count++); + ohci_setup(pci, count++); } } diff --git a/src/util.h b/src/util.h index 7723bb1..eb35d02 100644 --- a/src/util.h +++ b/src/util.h @@ -202,7 +202,7 @@ void check_preempt(void);
// output.c extern u16 DebugOutputPort; -void debug_serial_setup(void); +void debug_serial_preinit(void); void panic(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))) __noreturn; void printf(const char *fmt, ...) @@ -262,19 +262,14 @@ void hexdump(const void *d, int len); __set_code_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
// kbd.c -void kbd_setup(void); +void kbd_init(void); void handle_15c2(struct bregs *regs); void process_key(u8 key);
// mouse.c -void mouse_setup(void); +void mouse_init(void); void process_mouse(u8 data);
-// system.c -extern u32 RamSize; -extern u64 RamSizeOver4G; -void mathcp_setup(void); - // serial.c void serial_setup(void); void lpt_setup(void); @@ -282,7 +277,7 @@ void lpt_setup(void); // clock.c #define PIT_TICK_RATE 1193180 // Underlying HZ of PIT #define PIT_TICK_INTERVAL 65536 // Default interval for 18.2Hz timer -void pmtimer_init(u16 ioport, u32 khz); +void pmtimer_setup(u16 ioport, u32 khz); int check_tsc(u64 end); void timer_setup(void); void ndelay(u32 count); @@ -307,7 +302,7 @@ void handle_1553(struct bregs *regs);
// pcibios.c void handle_1ab1(struct bregs *regs); -void bios32_setup(void); +void bios32_init(void);
// shadow.c void make_bios_writable(void); @@ -319,23 +314,23 @@ extern const u8 pci_irqs[4]; void pci_setup(void);
// smm.c -void smm_init(void); +void smm_setup(void);
// smp.c extern u32 CountCPUs; extern u32 MaxCountCPUs; void wrmsr_smp(u32 index, u64 val); -void smp_probe(void); +void smp_setup(void); int apic_id_is_present(u8 apic_id);
// coreboot.c extern const char *CBvendor, *CBpart; struct cbfs_file; void cbfs_run_payload(struct cbfs_file *file); -void coreboot_copy_biostable(void); +void coreboot_biostable_setup(void); void cbfs_payload_setup(void); -void coreboot_setup(void); -void coreboot_cbfs_setup(void); +void coreboot_preinit(void); +void coreboot_cbfs_init(void);
// biostable.c void copy_table(void *pos); @@ -348,8 +343,8 @@ void vgahook_setup(struct pci_device *pci); // optionroms.c void call_bcv(u16 seg, u16 ip); void optionrom_setup(void); -void vga_setup(void); -void s3_resume_vga_init(void); +void vgarom_setup(void); +void s3_resume_vga(void); extern int ScreenAndDebug;
// bootsplash.c @@ -359,12 +354,12 @@ void disable_bootsplash(void);
// resume.c extern int HaveRunPost; -void init_dma(void); +void dma_preinit(void);
// pnpbios.c #define PNP_SIGNATURE 0x506e5024 // $PnP u16 get_pnp_offset(void); -void pnp_setup(void); +void pnp_init(void);
// pmm.c extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh; @@ -372,13 +367,13 @@ u32 rom_get_top(void); u32 rom_get_last(void); struct rom_header *rom_reserve(u32 size); int rom_confirm(u32 size); -void malloc_setup(void); -void malloc_fixupreloc(void); -void malloc_finalize(void); +void malloc_preinit(void); +void malloc_fixupreloc_init(void); +void malloc_prepboot(void); void *pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align); int pmm_free(void *data); -void pmm_setup(void); -void pmm_finalize(void); +void pmm_init(void); +void pmm_prepboot(void); #define PMM_DEFAULT_HANDLE 0xFFFFFFFF // Minimum alignment of malloc'd memory #define MALLOC_MIN_ALIGN 16 @@ -451,6 +446,9 @@ u64 romfile_loadint(const char *name, u64 defval); void reset_vector(void) __noreturn;
// misc.c +void mathcp_init(void); +extern u32 RamSize; +extern u64 RamSizeOver4G; extern u8 BiosChecksum;
// version (auto generated file out/version.c) diff --git a/src/virtio-scsi.c b/src/virtio-scsi.c index ab74729..4bbff8f 100644 --- a/src/virtio-scsi.c +++ b/src/virtio-scsi.c @@ -14,7 +14,7 @@ #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID #include "boot.h" // bootprio_find_scsi_device -#include "blockcmd.h" // scsi_init_drive +#include "blockcmd.h" // scsi_drive_setup #include "virtio-pci.h" #include "virtio-ring.h" #include "virtio-scsi.h" @@ -114,7 +114,7 @@ virtio_scsi_add_lun(struct pci_device *pci, u16 ioaddr, vlun->lun = lun;
int prio = bootprio_find_scsi_device(pci, target, lun); - int ret = scsi_init_drive(&vlun->drive, "virtio-scsi", prio); + int ret = scsi_drive_setup(&vlun->drive, "virtio-scsi", prio); if (ret) goto fail; return 0; diff --git a/src/xen.c b/src/xen.c index a4669d0..c9759f0 100644 --- a/src/xen.c +++ b/src/xen.c @@ -47,7 +47,7 @@ static void validate_info(struct xen_seabios_info *t) panic("Bad Xen info checksum\n"); }
-void xen_probe(void) +void xen_preinit(void) { u32 base, eax, ebx, ecx, edx; char signature[13]; @@ -86,7 +86,7 @@ static int hypercall_xen_version( int cmd, void *arg) }
/* Fill in hypercall transfer pages. */ -void xen_init_hypercalls(void) +void xen_hypercall_setup(void) { u32 eax, ebx, ecx, edx; xen_extraversion_t extraversion; @@ -111,7 +111,7 @@ void xen_init_hypercalls(void) dprintf(1, "Detected Xen v%u.%u%s\n", eax >> 16, eax & 0xffff, extraversion); }
-void xen_copy_biostables(void) +void xen_biostable_setup(void) { struct xen_seabios_info *info = (void *)INFO_PHYSICAL_ADDRESS; void **tables = (void*)info->tables; @@ -122,7 +122,7 @@ void xen_copy_biostables(void) copy_table(tables[i]); }
-void xen_setup(void) +void xen_ramsize_preinit(void) { u64 maxram = 0, maxram_over4G = 0; int i; diff --git a/src/xen.h b/src/xen.h index b664d9c..9b4178a 100644 --- a/src/xen.h +++ b/src/xen.h @@ -6,10 +6,10 @@
extern u32 xen_cpuid_base;
-void xen_probe(void); -void xen_setup(void); -void xen_init_hypercalls(void); -void xen_copy_biostables(void); +void xen_preinit(void); +void xen_ramsize_preinit(void); +void xen_hypercall_setup(void); +void xen_biostable_setup(void);
static inline int usingXen(void) { if (!CONFIG_XEN) diff --git a/vgasrc/bochsvga.c b/vgasrc/bochsvga.c index 938dba0..bb5a64d 100644 --- a/vgasrc/bochsvga.c +++ b/vgasrc/bochsvga.c @@ -329,9 +329,9 @@ bochsvga_set_mode(struct vgamode_s *vmode_g, int flags) ****************************************************************/
int -bochsvga_init(void) +bochsvga_setup(void) { - int ret = stdvga_init(); + int ret = stdvga_setup(); if (ret) return ret;
diff --git a/vgasrc/bochsvga.h b/vgasrc/bochsvga.h index 1c98203..87fb6ea 100644 --- a/vgasrc/bochsvga.h +++ b/vgasrc/bochsvga.h @@ -66,6 +66,6 @@ int bochsvga_size_state(int states); int bochsvga_save_state(u16 seg, void *data, int states); int bochsvga_restore_state(u16 seg, void *data, int states); int bochsvga_set_mode(struct vgamode_s *vmode_g, int flags); -int bochsvga_init(void); +int bochsvga_setup(void);
#endif // bochsvga.h diff --git a/vgasrc/clext.c b/vgasrc/clext.c index fc5459a..dd45df3 100644 --- a/vgasrc/clext.c +++ b/vgasrc/clext.c @@ -5,7 +5,7 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "clext.h" // clext_init +#include "clext.h" // clext_setup #include "vgabios.h" // VBE_VENDOR_STRING #include "biosvar.h" // GET_GLOBAL #include "util.h" // dprintf @@ -603,9 +603,9 @@ cirrus_get_memsize(void) }
int -clext_init(void) +clext_setup(void) { - int ret = stdvga_init(); + int ret = stdvga_setup(); if (ret) return ret;
diff --git a/vgasrc/clext.h b/vgasrc/clext.h index 78dba01..efc98b9 100644 --- a/vgasrc/clext.h +++ b/vgasrc/clext.h @@ -17,6 +17,6 @@ int clext_restore_state(u16 seg, void *data, int states); int clext_set_mode(struct vgamode_s *vmode_g, int flags); struct bregs; void clext_1012(struct bregs *regs); -int clext_init(void); +int clext_setup(void);
#endif // clext.h diff --git a/vgasrc/geodevga.c b/vgasrc/geodevga.c index 5b42e00..c2dabf5 100644 --- a/vgasrc/geodevga.c +++ b/vgasrc/geodevga.c @@ -6,7 +6,7 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "geodevga.h" // geodevga_init +#include "geodevga.h" // geodevga_setup #include "farptr.h" // SET_FARVAR #include "biosvar.h" // GET_BDA #include "vgabios.h" // VGAREG_* @@ -369,16 +369,16 @@ static u8 geode_crtc_13[] VAR16 = { 0x9b, 0x8d, 0x8f, 0x28, 0x40, 0x98, 0xb9, 0xa3, 0xff };
-int geodevga_init(void) +int geodevga_setup(void) { - int ret = stdvga_init(); + int ret = stdvga_setup(); if (ret) return ret;
- dprintf(1,"GEODEVGA_INIT\n"); + dprintf(1,"GEODEVGA_SETUP\n");
if ((ret=legacyio_check())) { - dprintf(1,"GEODEVGA_INIT legacyio_check=0x%x\n",ret); + dprintf(1,"GEODEVGA_SETUP legacyio_check=0x%x\n",ret); }
// Updated timings from geode datasheets, table 6-53 in particular diff --git a/vgasrc/geodevga.h b/vgasrc/geodevga.h index 5993b23..180bd05 100644 --- a/vgasrc/geodevga.h +++ b/vgasrc/geodevga.h @@ -84,6 +84,6 @@ /* Mask */ #define DC_CFG_MSK 0xf000a6
-int geodevga_init(); +int geodevga_setup();
#endif diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c index ae6c0be..a29d6d4 100644 --- a/vgasrc/stdvga.c +++ b/vgasrc/stdvga.c @@ -6,7 +6,7 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "vgabios.h" // struct vgamode_s -#include "stdvga.h" // stdvga_init +#include "stdvga.h" // stdvga_setup #include "ioport.h" // outb #include "farptr.h" // SET_FARVAR #include "biosvar.h" // GET_GLOBAL @@ -490,7 +490,7 @@ stdvga_enable_video_addressing(u8 disable) }
int -stdvga_init(void) +stdvga_setup(void) { // switch to color mode and enable CPU access 480 lines stdvga_misc_write(0xc3); diff --git a/vgasrc/stdvga.h b/vgasrc/stdvga.h index c9a9ba1..d712a32 100644 --- a/vgasrc/stdvga.h +++ b/vgasrc/stdvga.h @@ -107,6 +107,6 @@ int stdvga_size_state(int states); int stdvga_save_state(u16 seg, void *data, int states); int stdvga_restore_state(u16 seg, void *data, int states); void stdvga_enable_video_addressing(u8 disable); -int stdvga_init(void); +int stdvga_setup(void);
#endif // stdvga.h diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index afaf018..3e26e32 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -1281,7 +1281,7 @@ int HaveRunInit VAR16; void VISIBLE16 vga_post(struct bregs *regs) { - debug_serial_setup(); + debug_serial_preinit(); dprintf(1, "Start SeaVGABIOS (version %s)\n", VERSION); debug_enter(regs, DEBUG_VGA_POST);
@@ -1294,7 +1294,7 @@ vga_post(struct bregs *regs) SET_VGA(VgaBDF, bdf); }
- int ret = vgahw_init(); + int ret = vgahw_setup(); if (ret) { dprintf(1, "Failed to initialize VGA hardware. Exiting.\n"); return; diff --git a/vgasrc/vgahw.h b/vgasrc/vgahw.h index 044cd32..f69a5ac 100644 --- a/vgasrc/vgahw.h +++ b/vgasrc/vgahw.h @@ -7,7 +7,7 @@ #include "clext.h" // clext_set_mode #include "bochsvga.h" // bochsvga_set_mode #include "stdvga.h" // stdvga_set_mode -#include "geodevga.h" // geodevga_init +#include "geodevga.h" // geodevga_setup
static inline struct vgamode_s *vgahw_find_mode(int mode) { if (CONFIG_VGA_CIRRUS) @@ -34,14 +34,14 @@ static inline void vgahw_list_modes(u16 seg, u16 *dest, u16 *last) { stdvga_list_modes(seg, dest, last); }
-static inline int vgahw_init(void) { +static inline int vgahw_setup(void) { if (CONFIG_VGA_CIRRUS) - return clext_init(); + return clext_setup(); if (CONFIG_VGA_BOCHS) - return bochsvga_init(); + return bochsvga_setup(); if (CONFIG_VGA_GEODEGX2 || CONFIG_VGA_GEODELX) - return geodevga_init(); - return stdvga_init(); + return geodevga_setup(); + return stdvga_setup(); }
static inline int vgahw_get_window(struct vgamode_s *vmode_g, int window) {
Place the "interface initialization" functions together, "platform hardware initialization" functions together, and "prepare to boot" functions together. This may also be useful for using SeaBIOS as a CSM.
This slightly changes the order of some function invocations, but should otherwise not change code behavior at all.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/boot.c | 16 ++-- src/boot.h | 3 +- src/bootsplash.c | 2 + src/post.c | 255 ++++++++++++++++++++++++++++++------------------------- 4 files changed, 148 insertions(+), 128 deletions(-)
diff --git a/src/boot.c b/src/boot.c index 2cb3b86..3bafa5a 100644 --- a/src/boot.c +++ b/src/boot.c @@ -392,9 +392,11 @@ boot_add_cbfs(void *data, const char *desc, int prio) #define DEFAULT_BOOTMENU_WAIT 2500
// Show IPL option menu. -static void +void interactive_bootmenu(void) { + // XXX - show available drives? + if (! CONFIG_BOOTMENU || ! qemu_cfg_show_boot_menu()) return;
@@ -476,18 +478,10 @@ add_bev(int type, u32 vector)
// Prepare for boot - show menu and run bcvs. void -boot_prepboot(void) +bcv_prepboot(void) { - if (! CONFIG_BOOT) { - wait_threads(); + if (! CONFIG_BOOT) return; - } - - // XXX - show available drives? - - // Allow user to modify BCV/IPL order. - interactive_bootmenu(); - wait_threads();
int haltprio = find_prio("HALT"); if (haltprio >= 0) diff --git a/src/boot.h b/src/boot.h index 4a93d0f..4d4943b 100644 --- a/src/boot.h +++ b/src/boot.h @@ -11,7 +11,8 @@ void boot_add_floppy(struct drive_s *drive_g, const char *desc, int prio); void boot_add_hd(struct drive_s *drive_g, const char *desc, int prio); void boot_add_cd(struct drive_s *drive_g, const char *desc, int prio); void boot_add_cbfs(void *data, const char *desc, int prio); -void boot_prepboot(void); +void interactive_bootmenu(void); +void bcv_prepboot(void); struct pci_device; int bootprio_find_pci_device(struct pci_device *pci); int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun); diff --git a/src/bootsplash.c b/src/bootsplash.c index 3aac459..84fca7f 100644 --- a/src/bootsplash.c +++ b/src/bootsplash.c @@ -12,6 +12,7 @@ #include "jpeg.h" // splash #include "vbe.h" // struct vbe_info #include "bmp.h" // bmp_alloc +#include "smbios.h" // display_uuid
/**************************************************************** @@ -46,6 +47,7 @@ enable_vga_console(void)
// Write to screen. printf("SeaBIOS (version %s)\n", VERSION); + display_uuid(); }
static int diff --git a/src/post.c b/src/post.c index 6f5dfef..dbf4944 100644 --- a/src/post.c +++ b/src/post.c @@ -31,11 +31,69 @@ #include "esp-scsi.h" // esp_scsi_setup #include "megasas.h" // megasas_setup
+ /**************************************************************** * BIOS init ****************************************************************/
static void +ramsize_preinit(void) +{ + dprintf(3, "Find memory size\n"); + if (CONFIG_COREBOOT) { + coreboot_preinit(); + } else if (usingXen()) { + xen_ramsize_preinit(); + } else { + // On emulators, get memory size from nvram. + u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16) + | (inb_cmos(CMOS_MEM_EXTMEM2_HIGH) << 24)); + if (rs) + rs += 16 * 1024 * 1024; + else + rs = (((inb_cmos(CMOS_MEM_EXTMEM_LOW) << 10) + | (inb_cmos(CMOS_MEM_EXTMEM_HIGH) << 18)) + + 1 * 1024 * 1024); + RamSize = rs; + add_e820(0, rs, E820_RAM); + + // Check for memory over 4Gig + u64 high = ((inb_cmos(CMOS_MEM_HIGHMEM_LOW) << 16) + | ((u32)inb_cmos(CMOS_MEM_HIGHMEM_MID) << 24) + | ((u64)inb_cmos(CMOS_MEM_HIGHMEM_HIGH) << 32)); + RamSizeOver4G = high; + add_e820(0x100000000ull, high, E820_RAM); + + /* reserve 256KB BIOS area at the end of 4 GB */ + add_e820(0xfffc0000, 256*1024, E820_RESERVED); + } + + // Don't declare any memory between 0xa0000 and 0x100000 + add_e820(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END, E820_HOLE); + + // Mark known areas as reserved. + add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED); + + u32 count = qemu_cfg_e820_entries(); + if (count) { + struct e820_reservation entry; + int i; + + for (i = 0; i < count; i++) { + qemu_cfg_e820_load_next(&entry); + add_e820(entry.address, entry.length, entry.type); + } + } else if (kvm_para_available()) { + // Backwards compatibility - provide hard coded range. + // 4 pages before the bios, 3 pages for vmx tss pages, the + // other page for EPT real mode pagetable + add_e820(0xfffbc000, 4*4096, E820_RESERVED); + } + + dprintf(1, "Ram Size=0x%08x (0x%016llx high)\n", RamSize, RamSizeOver4G); +} + +static void ivt_init(void) { dprintf(3, "init ivt\n"); @@ -101,81 +159,27 @@ bda_init(void) }
static void -ramsize_preinit(void) +interface_init(void) { - dprintf(3, "Find memory size\n"); - if (CONFIG_COREBOOT) { - coreboot_preinit(); - } else if (usingXen()) { - xen_ramsize_preinit(); - } else { - // On emulators, get memory size from nvram. - u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16) - | (inb_cmos(CMOS_MEM_EXTMEM2_HIGH) << 24)); - if (rs) - rs += 16 * 1024 * 1024; - else - rs = (((inb_cmos(CMOS_MEM_EXTMEM_LOW) << 10) - | (inb_cmos(CMOS_MEM_EXTMEM_HIGH) << 18)) - + 1 * 1024 * 1024); - RamSize = rs; - add_e820(0, rs, E820_RAM); - - // Check for memory over 4Gig - u64 high = ((inb_cmos(CMOS_MEM_HIGHMEM_LOW) << 16) - | ((u32)inb_cmos(CMOS_MEM_HIGHMEM_MID) << 24) - | ((u64)inb_cmos(CMOS_MEM_HIGHMEM_HIGH) << 32)); - RamSizeOver4G = high; - add_e820(0x100000000ull, high, E820_RAM); - - /* reserve 256KB BIOS area at the end of 4 GB */ - add_e820(0xfffc0000, 256*1024, E820_RESERVED); - } - - // Don't declare any memory between 0xa0000 and 0x100000 - add_e820(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END, E820_HOLE); - - // Mark known areas as reserved. - add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED); - - u32 count = qemu_cfg_e820_entries(); - if (count) { - struct e820_reservation entry; - int i; - - for (i = 0; i < count; i++) { - qemu_cfg_e820_load_next(&entry); - add_e820(entry.address, entry.length, entry.type); - } - } else if (kvm_para_available()) { - // Backwards compatibility - provide hard coded range. - // 4 pages before the bios, 3 pages for vmx tss pages, the - // other page for EPT real mode pagetable - add_e820(0xfffbc000, 4*4096, E820_RESERVED); - } - - dprintf(1, "Ram Size=0x%08x (0x%016llx high)\n", RamSize, RamSizeOver4G); -} - -static void -biostable_setup(void) -{ - if (CONFIG_COREBOOT) { - coreboot_biostable_setup(); - return; - } - if (usingXen()) { - xen_biostable_setup(); - return; - } - - pirtable_setup(); + // Running at new code address - do code relocation fixups + malloc_fixupreloc_init();
- mptable_setup(); + // Setup romfile items. + qemu_romfile_init(); + coreboot_cbfs_init();
- smbios_setup(); + // Setup ivt/bda/ebda + ivt_init(); + bda_init();
- acpi_setup(); + // Other interfaces + mathcp_init(); + boot_init(); + bios32_init(); + pmm_init(); + pnp_init(); + kbd_init(); + mouse_init(); }
// Initialize hardware devices @@ -199,39 +203,33 @@ device_hardware_setup(void) megasas_setup(); }
-// Begin the boot process by invoking an int0x19 in 16bit mode. static void -startBoot(void) +biostable_setup(void) { - // Clear low-memory allocations (required by PMM spec). - memset((void*)BUILD_STACK_ADDR, 0, BUILD_EBDA_MINIMUM - BUILD_STACK_ADDR); + if (CONFIG_COREBOOT) { + coreboot_biostable_setup(); + return; + } + if (usingXen()) { + xen_biostable_setup(); + return; + }
- dprintf(3, "Jump to int19\n"); - struct bregs br; - memset(&br, 0, sizeof(br)); - br.flags = F_IF; - call16_int(0x19, &br); -} + pirtable_setup();
-// Main setup code. -void VISIBLE32INIT -maininit(void) -{ - // Running at new code address - do code relocation fixups - malloc_fixupreloc_init(); + mptable_setup();
- // Setup romfile items. - qemu_romfile_init(); - coreboot_cbfs_init(); + smbios_setup();
- // Setup ivt/bda/ebda - ivt_init(); - bda_init(); + acpi_setup(); +}
+static void +platform_hardware_setup(void) +{ // Init base pc hardware. pic_setup(); timer_setup(); - mathcp_init();
// Initialize pci pci_setup(); @@ -243,9 +241,6 @@ maininit(void) // Setup Xen hypercalls xen_hypercall_setup();
- // Initialize internal tables - boot_init(); - // Start hardware initialization (if optionrom threading) if (CONFIG_THREADS && CONFIG_THREAD_OPTIONROMS) device_hardware_setup(); @@ -253,20 +248,39 @@ maininit(void) // Find and initialize other cpus smp_setup();
- // Setup interfaces that option roms may need - bios32_init(); - pmm_init(); - pnp_init(); - kbd_init(); - mouse_init(); + // Setup external BIOS interface tables biostable_setup(); +} + +static void +prepareboot(void) +{ + // Run BCVs + bcv_prepboot(); + + // Finalize data structures before boot + cdrom_prepboot(); + pmm_prepboot(); + malloc_prepboot(); + memmap_prepboot(); + + // Setup bios checksum. + BiosChecksum -= checksum((u8*)BUILD_BIOS_ADDR, BUILD_BIOS_SIZE); +} + +// Main setup code. +void VISIBLE32INIT +maininit(void) +{ + // Initialize internal interfaces. + interface_init(); + + // Setup platform devices. + platform_hardware_setup();
// Run vga option rom vgarom_setup();
- // SMBIOS tables and VGA console are ready, print UUID - display_uuid(); - // Do hardware initialization (if running synchronously) if (!CONFIG_THREADS || !CONFIG_THREAD_OPTIONROMS) { device_hardware_setup(); @@ -276,22 +290,31 @@ maininit(void) // Run option roms optionrom_setup();
- // Run BCVs and show optional boot menu - boot_prepboot(); + // Allow user to modify overall boot order. + interactive_bootmenu(); + wait_threads();
- // Finalize data structures before boot - cdrom_prepboot(); - pmm_prepboot(); - malloc_prepboot(); - memmap_prepboot(); - - // Setup bios checksum. - BiosChecksum -= checksum((u8*)BUILD_BIOS_ADDR, BUILD_BIOS_SIZE); + // Prepare for boot. + prepareboot();
// Write protect bios memory. make_bios_readonly(); }
+// Begin the boot process by invoking an int0x19 in 16bit mode. +static void +startBoot(void) +{ + // Clear low-memory allocations (required by PMM spec). + memset((void*)BUILD_STACK_ADDR, 0, BUILD_EBDA_MINIMUM - BUILD_STACK_ADDR); + + dprintf(3, "Jump to int19\n"); + struct bregs br; + memset(&br, 0, sizeof(br)); + br.flags = F_IF; + call16_int(0x19, &br); +} +
/**************************************************************** * POST entry and code relocation
Looks good, thanks. I've updated the tree at git:// and http://git.infradead.org/users/dwmw2/seabios.git/ to be based on it.
My build now only has 480 bytes of '32bit flat init size'; I suspect I need to mark a whole bunch of functions as VISIBLE32INIT as well as just making them non-static.
I'm still having to hack platform_hardware_setup() somewhat — although I could probably get away with just calling timer_setup() and pci_probe_devices() instead of using it at all.
But we're getting there...