ia64/xen-unstable

changeset 12554:a8d31d5ce258

[HVM] Move PCI and PCI-ISA bridge setup to hvmloader.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Nov 22 17:50:20 2006 +0000 (2006-11-22)
parents b8cc9ffda0a3
children 2ef0f17a9af9
files tools/firmware/hvmloader/acpi_madt.c tools/firmware/hvmloader/acpi_utils.c tools/firmware/hvmloader/config.h tools/firmware/hvmloader/hvmloader.c tools/firmware/hvmloader/mp_tables.c tools/firmware/hvmloader/pci_regs.h tools/firmware/hvmloader/smbios.c tools/firmware/hvmloader/util.c tools/firmware/hvmloader/util.h tools/firmware/rombios/rombios.c tools/ioemu/target-i386-dm/piix_pci-dm.c
line diff
     1.1 --- a/tools/firmware/hvmloader/acpi_madt.c	Wed Nov 22 09:52:48 2006 -0700
     1.2 +++ b/tools/firmware/hvmloader/acpi_madt.c	Wed Nov 22 17:50:20 2006 +0000
     1.3 @@ -35,32 +35,34 @@ static int validate_hvm_info(struct hvm_
     1.4      int i;
     1.5  
     1.6      /* strncmp(t->signature, "HVM INFO", 8) */
     1.7 -    for (i = 0; i < 8; i++) {
     1.8 -        if (signature[i] != t->signature[i]) {
     1.9 -            puts("Bad hvm info signature\n");
    1.10 +    for ( i = 0; i < 8; i++ )
    1.11 +    {
    1.12 +        if ( signature[i] != t->signature[i] )
    1.13 +        {
    1.14 +            printf("Bad hvm info signature\n");
    1.15              return 0;
    1.16          }
    1.17      }
    1.18  
    1.19 -    for (i = 0; i < t->length; i++)
    1.20 +    for ( i = 0; i < t->length; i++ )
    1.21          sum += ptr[i];
    1.22  
    1.23      return (sum == 0);
    1.24  }
    1.25  
    1.26  /* xc_vmx_builder wrote hvm info at 0x9F800. Return it. */
    1.27 -struct hvm_info_table *
    1.28 -get_hvm_info_table(void)
    1.29 +struct hvm_info_table *get_hvm_info_table(void)
    1.30  {
    1.31      struct hvm_info_table *t;
    1.32  
    1.33 -    if (table != NULL)
    1.34 +    if ( table != NULL )
    1.35          return table;
    1.36  
    1.37      t = (struct hvm_info_table *)HVM_INFO_PADDR;
    1.38  
    1.39 -    if (!validate_hvm_info(t)) {
    1.40 -        puts("Bad hvm info table\n");
    1.41 +    if ( !validate_hvm_info(t) )
    1.42 +    {
    1.43 +        printf("Bad hvm info table\n");
    1.44          return NULL;
    1.45      }
    1.46  
    1.47 @@ -69,15 +71,13 @@ get_hvm_info_table(void)
    1.48      return table;
    1.49  }
    1.50  
    1.51 -int
    1.52 -get_vcpu_nr(void)
    1.53 +int get_vcpu_nr(void)
    1.54  {
    1.55      struct hvm_info_table *t = get_hvm_info_table();
    1.56      return (t ? t->nr_vcpus : 1); /* default 1 vcpu */
    1.57  }
    1.58  
    1.59 -int
    1.60 -get_acpi_enabled(void)
    1.61 +int get_acpi_enabled(void)
    1.62  {
    1.63      struct hvm_info_table *t = get_hvm_info_table();
    1.64      return (t ? t->acpi_enabled : 0); /* default no acpi */
    1.65 @@ -91,13 +91,14 @@ acpi_madt_get_madt(unsigned char *acpi_s
    1.66      struct acpi_20_madt *madt;
    1.67  
    1.68      rsdt = acpi_rsdt_get(acpi_start);
    1.69 -    if (rsdt == NULL)
    1.70 +    if ( rsdt == NULL )
    1.71          return NULL;
    1.72  
    1.73      madt = (struct acpi_20_madt *)(acpi_start + rsdt->entry[1] -
    1.74                                     ACPI_PHYSICAL_ADDRESS);
    1.75 -    if (madt->header.header.signature != ACPI_2_0_MADT_SIGNATURE) {
    1.76 -        puts("Bad MADT signature \n");
    1.77 +    if ( madt->header.header.signature != ACPI_2_0_MADT_SIGNATURE )
    1.78 +    {
    1.79 +        printf("Bad MADT signature \n");
    1.80          return NULL;
    1.81      }
    1.82  
    1.83 @@ -111,10 +112,11 @@ acpi_madt_set_local_apics(
    1.84  {
    1.85      int i;
    1.86  
    1.87 -    if ((nr_vcpu > MAX_VIRT_CPUS) || (nr_vcpu < 0) || !madt)
    1.88 +    if ( (nr_vcpu > MAX_VIRT_CPUS) || (nr_vcpu < 0) || !madt )
    1.89          return -1;
    1.90  
    1.91 -    for (i = 0; i < nr_vcpu; i++) {
    1.92 +    for ( i = 0; i < nr_vcpu; i++ )
    1.93 +    {
    1.94          madt->lapic[i].type    = ACPI_PROCESSOR_LOCAL_APIC;
    1.95          madt->lapic[i].length  = sizeof(struct acpi_20_madt_lapic);
    1.96          madt->lapic[i].acpi_processor_id = i;
    1.97 @@ -137,11 +139,11 @@ int acpi_madt_update(unsigned char *acpi
    1.98      struct acpi_20_madt *madt;
    1.99  
   1.100      madt = acpi_madt_get_madt(acpi_start);
   1.101 -    if (!madt)
   1.102 +    if ( !madt )
   1.103          return -1;
   1.104  
   1.105      rc = acpi_madt_set_local_apics(get_vcpu_nr(), madt);
   1.106 -    if (rc != 0)
   1.107 +    if ( rc != 0 )
   1.108          return rc;
   1.109  
   1.110      set_checksum(
     2.1 --- a/tools/firmware/hvmloader/acpi_utils.c	Wed Nov 22 09:52:48 2006 -0700
     2.2 +++ b/tools/firmware/hvmloader/acpi_utils.c	Wed Nov 22 17:50:20 2006 +0000
     2.3 @@ -78,7 +78,7 @@ static void acpi_tpm_tis_probe(unsigned 
     2.4                  sizeof(tis_did_vid_rid)) != 0 )
     2.5          return;
     2.6  
     2.7 -    puts("TIS is available\n");
     2.8 +    printf("TIS is available\n");
     2.9      addr = acpi_xsdt_add_entry(acpi_start, freemem, limit,
    2.10                                 AmlCode_TPM, sizeof(AmlCode_TPM));
    2.11      if ( addr == NULL )
    2.12 @@ -133,7 +133,7 @@ struct acpi_20_rsdt *acpi_rsdt_get(unsig
    2.13      rsdp = (struct acpi_20_rsdp *)(acpi_start + sizeof(struct acpi_20_facs));
    2.14      if ( rsdp->signature != ACPI_2_0_RSDP_SIGNATURE )
    2.15      {
    2.16 -        puts("Bad RSDP signature\n");
    2.17 +        printf("Bad RSDP signature\n");
    2.18          return NULL;
    2.19      }
    2.20  
    2.21 @@ -141,7 +141,7 @@ struct acpi_20_rsdt *acpi_rsdt_get(unsig
    2.22          (acpi_start + rsdp->rsdt_address - ACPI_PHYSICAL_ADDRESS);
    2.23      if ( rsdt->header.signature != ACPI_2_0_RSDT_SIGNATURE )
    2.24      {
    2.25 -        puts("Bad RSDT signature\n");
    2.26 +        printf("Bad RSDT signature\n");
    2.27          return NULL;
    2.28      }
    2.29  
    2.30 @@ -192,7 +192,7 @@ struct acpi_20_xsdt *acpi_xsdt_get(unsig
    2.31      rsdp = (struct acpi_20_rsdp *)(acpi_start + sizeof(struct acpi_20_facs));
    2.32      if ( rsdp->signature != ACPI_2_0_RSDP_SIGNATURE )
    2.33      {
    2.34 -        puts("Bad RSDP signature\n");
    2.35 +        printf("Bad RSDP signature\n");
    2.36          return NULL;
    2.37      }
    2.38  
    2.39 @@ -200,7 +200,7 @@ struct acpi_20_xsdt *acpi_xsdt_get(unsig
    2.40          (acpi_start + rsdp->xsdt_address - ACPI_PHYSICAL_ADDRESS);
    2.41      if ( xsdt->header.signature != ACPI_2_0_XSDT_SIGNATURE )
    2.42      {
    2.43 -        puts("Bad XSDT signature\n");
    2.44 +        printf("Bad XSDT signature\n");
    2.45          return NULL;
    2.46      }
    2.47      return xsdt;
    2.48 @@ -270,8 +270,9 @@ static unsigned char *acpi_xsdt_add_entr
    2.49      if ( found )
    2.50      {
    2.51          /* memory below hard limit ? */
    2.52 -        if (*freemem + table_size <= limit) {
    2.53 -            puts("Copying SSDT entry!\n");
    2.54 +        if ( (*freemem + table_size) <= limit )
    2.55 +        {
    2.56 +            printf("Copying SSDT entry\n");
    2.57              addr = *freemem;
    2.58              memcpy(addr, table, table_size);
    2.59              *freemem += table_size;
     3.1 --- a/tools/firmware/hvmloader/config.h	Wed Nov 22 09:52:48 2006 -0700
     3.2 +++ b/tools/firmware/hvmloader/config.h	Wed Nov 22 17:50:20 2006 +0000
     3.3 @@ -7,4 +7,7 @@
     3.4  
     3.5  #define LAPIC_BASE_ADDRESS  0xfee00000
     3.6  
     3.7 +#define PCI_ISA_DEVFN       0x08    /* dev 1, fn 0 */
     3.8 +#define PCI_ISA_IRQ_MASK    0x0c60U /* ISA IRQs 5,6,10,11 are PCI connected */
     3.9 +
    3.10  #endif /* __HVMLOADER_CONFIG_H__ */
     4.1 --- a/tools/firmware/hvmloader/hvmloader.c	Wed Nov 22 09:52:48 2006 -0700
     4.2 +++ b/tools/firmware/hvmloader/hvmloader.c	Wed Nov 22 17:50:20 2006 +0000
     4.3 @@ -1,13 +1,11 @@
     4.4  /*
     4.5   * hvmloader.c: HVM ROMBIOS/VGABIOS/ACPI/VMXAssist image loader.
     4.6   *
     4.7 - * A quicky so that we can boot rom images as if they were a Linux kernel.
     4.8 - * This code will copy the rom images (ROMBIOS/VGABIOS/VM86) into their
     4.9 - * respective spaces and transfer control to VM86 to execute the BIOSes.
    4.10 - *
    4.11   * Leendert van Doorn, leendert@watson.ibm.com
    4.12   * Copyright (c) 2005, International Business Machines Corporation.
    4.13   *
    4.14 + * Copyright (c) 2006, Keir Fraser, XenSource Inc.
    4.15 + *
    4.16   * This program is free software; you can redistribute it and/or modify it
    4.17   * under the terms and conditions of the GNU General Public License,
    4.18   * version 2, as published by the Free Software Foundation.
    4.19 @@ -28,8 +26,10 @@
    4.20  #include "acpi_utils.h"
    4.21  #include "smbios.h"
    4.22  #include "config.h"
    4.23 +#include "pci_regs.h"
    4.24  #include <xen/version.h>
    4.25  #include <xen/hvm/params.h>
    4.26 +#include <xen/hvm/e820.h>
    4.27  
    4.28  /* memory map */
    4.29  #define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
    4.30 @@ -125,7 +125,7 @@ init_hypercalls(void)
    4.31  {
    4.32      uint32_t eax, ebx, ecx, edx;
    4.33      unsigned long i;
    4.34 -    char signature[13], number[13];
    4.35 +    char signature[13];
    4.36      xen_extraversion_t extraversion;
    4.37  
    4.38      cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
    4.39 @@ -137,25 +137,19 @@ init_hypercalls(void)
    4.40  
    4.41      if ( strcmp("XenVMMXenVMM", signature) || (eax < 0x40000002) )
    4.42      {
    4.43 -        puts("FATAL: Xen hypervisor not detected\n");
    4.44 +        printf("FATAL: Xen hypervisor not detected\n");
    4.45          __asm__ __volatile__( "ud2" );
    4.46      }
    4.47  
    4.48 -    cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
    4.49 -
    4.50 -    puts("Detected Xen v");
    4.51 -    puts(itoa(number, eax >> 16));
    4.52 -    puts(".");
    4.53 -    puts(itoa(number, eax & 0xffff));
    4.54 -
    4.55 +    /* Fill in hypercall transfer pages. */
    4.56      cpuid(0x40000002, &eax, &ebx, &ecx, &edx);
    4.57 -
    4.58      for ( i = 0; i < eax; i++ )
    4.59          wrmsr(ebx, HYPERCALL_PHYSICAL_ADDRESS + (i << 12) + i);
    4.60  
    4.61 +    /* Print version information. */
    4.62 +    cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
    4.63      hypercall_xen_version(XENVER_extraversion, extraversion);
    4.64 -    puts(extraversion);
    4.65 -    puts("\n");
    4.66 +    printf("Detected Xen v%u.%u%s\n", eax >> 16, eax & 0xffff, extraversion);
    4.67  }
    4.68  
    4.69  static void apic_setup(void)
    4.70 @@ -172,38 +166,157 @@ static void apic_setup(void)
    4.71      *iowin    = IOAPIC_ID;
    4.72  }
    4.73  
    4.74 +static void pci_setup(void)
    4.75 +{
    4.76 +    uint32_t devfn, bar_reg, bar_data, bar_sz, cmd;
    4.77 +    uint32_t *base, io_base = 0xc000, mem_base = HVM_BELOW_4G_MMIO_START;
    4.78 +    uint16_t class, vendor_id, device_id;
    4.79 +    unsigned int bar, pin, link, isa_irq;
    4.80 +
    4.81 +    /* Program PCI-ISA bridge with appropriate link routes. */
    4.82 +    link = 0;
    4.83 +    for ( isa_irq = 0; isa_irq < 15; isa_irq++ )
    4.84 +    {
    4.85 +        if ( !(PCI_ISA_IRQ_MASK & (1U << isa_irq)) )
    4.86 +            continue;
    4.87 +        pci_writeb(PCI_ISA_DEVFN, 0x60 + link, isa_irq);
    4.88 +        printf("PCI-ISA link %u routed to IRQ%u\n", link, isa_irq);
    4.89 +        if ( link++ == 4 )
    4.90 +            break;
    4.91 +    }
    4.92 +
    4.93 +    /* Program ELCR to match PCI-wired IRQs. */
    4.94 +    outb(0x4d0, (uint8_t)(PCI_ISA_IRQ_MASK >> 0));
    4.95 +    outb(0x4d1, (uint8_t)(PCI_ISA_IRQ_MASK >> 8));
    4.96 +
    4.97 +    /* Scan the PCI bus and map resources. */
    4.98 +    for ( devfn = 0; devfn < 128; devfn++ )
    4.99 +    {
   4.100 +        class     = pci_readw(devfn, PCI_CLASS_DEVICE);
   4.101 +        vendor_id = pci_readw(devfn, PCI_VENDOR_ID);
   4.102 +        device_id = pci_readw(devfn, PCI_DEVICE_ID);
   4.103 +        if ( (vendor_id == 0xffff) && (device_id == 0xffff) )
   4.104 +            continue;
   4.105 +
   4.106 +        ASSERT((devfn != PCI_ISA_DEVFN) ||
   4.107 +               ((vendor_id == 0x8086) && (device_id == 0x7000)));
   4.108 +
   4.109 +        switch ( class )
   4.110 +        {
   4.111 +        case 0x0680:
   4.112 +            ASSERT((vendor_id == 0x8086) && (device_id == 0x7113));
   4.113 +            /*
   4.114 +             * PIIX4 ACPI PM. Special device with special PCI config space.
   4.115 +             * No ordinary BARs.
   4.116 +             */
   4.117 +            pci_writew(devfn, 0x20, 0x0000); /* No smb bus IO enable */
   4.118 +            pci_writew(devfn, 0x22, 0x0000);
   4.119 +            pci_writew(devfn, 0x3c, 0x0009); /* Hardcoded IRQ9 */
   4.120 +            pci_writew(devfn, 0x3d, 0x0001);
   4.121 +            break;
   4.122 +        case 0x0101:
   4.123 +            /* PIIX3 IDE */
   4.124 +            ASSERT((vendor_id == 0x8086) && (device_id == 0x7010));
   4.125 +            pci_writew(devfn, 0x40, 0x8000); /* enable IDE0 */
   4.126 +            pci_writew(devfn, 0x42, 0x8000); /* enable IDE1 */
   4.127 +            /* fall through */
   4.128 +        default:
   4.129 +            /* Default memory mappings. */
   4.130 +            for ( bar = 0; bar < 7; bar++ )
   4.131 +            {
   4.132 +                bar_reg = PCI_BASE_ADDRESS_0 + 4*bar;
   4.133 +                if ( bar == 6 )
   4.134 +                    bar_reg = PCI_ROM_ADDRESS;
   4.135 +
   4.136 +                bar_data = pci_readl(devfn, bar_reg);
   4.137 +
   4.138 +                pci_writel(devfn, bar_reg, ~0);
   4.139 +                bar_sz = pci_readl(devfn, bar_reg);
   4.140 +                if ( bar_sz == 0 )
   4.141 +                    continue;
   4.142 +
   4.143 +                if ( (bar_data & PCI_BASE_ADDRESS_SPACE) ==
   4.144 +                     PCI_BASE_ADDRESS_SPACE_MEMORY )
   4.145 +                {
   4.146 +                    base = &mem_base;
   4.147 +                    bar_sz &= PCI_BASE_ADDRESS_MEM_MASK;
   4.148 +                    bar_data &= ~PCI_BASE_ADDRESS_MEM_MASK;
   4.149 +                }
   4.150 +                else
   4.151 +                {
   4.152 +                    base = &io_base;
   4.153 +                    bar_sz &= PCI_BASE_ADDRESS_IO_MASK & 0xffff;
   4.154 +                    bar_data &= ~PCI_BASE_ADDRESS_IO_MASK;
   4.155 +                }
   4.156 +                bar_sz &= ~(bar_sz - 1);
   4.157 +
   4.158 +                *base = (*base + bar_sz - 1) & ~(bar_sz - 1);
   4.159 +                bar_data |= *base;
   4.160 +                *base += bar_sz;
   4.161 +
   4.162 +                pci_writel(devfn, bar_reg, bar_data);
   4.163 +                printf("pci dev %02x:%x bar %02x size %08x: %08x\n",
   4.164 +                       devfn>>3, devfn&7, bar_reg, bar_sz, bar_data);
   4.165 +
   4.166 +                /* Now enable the memory or I/O mapping. */
   4.167 +                cmd = pci_readw(devfn, PCI_COMMAND);
   4.168 +                if ( (bar_reg == PCI_ROM_ADDRESS) ||
   4.169 +                     ((bar_data & PCI_BASE_ADDRESS_SPACE) ==
   4.170 +                      PCI_BASE_ADDRESS_SPACE_MEMORY) )
   4.171 +                    cmd |= PCI_COMMAND_MEMORY;
   4.172 +                else
   4.173 +                    cmd |= PCI_COMMAND_IO;
   4.174 +                pci_writew(devfn, PCI_COMMAND, cmd);
   4.175 +            }
   4.176 +            break;
   4.177 +        }
   4.178 +
   4.179 +        /* Map the interrupt. */
   4.180 +        pin = pci_readb(devfn, PCI_INTERRUPT_PIN);
   4.181 +        if ( pin != 0 )
   4.182 +        {
   4.183 +            /* This is the barber's pole mapping used by Xen. */
   4.184 +            link = ((pin - 1) + (devfn >> 3)) & 3;
   4.185 +            isa_irq = pci_readb(PCI_ISA_DEVFN, 0x60 + link);
   4.186 +            pci_writeb(devfn, PCI_INTERRUPT_LINE, isa_irq);
   4.187 +            printf("pci dev %02x:%x INT%c->IRQ%u\n",
   4.188 +                   devfn>>3, devfn&7, 'A'+pin-1, isa_irq);
   4.189 +        }
   4.190 +    }
   4.191 +}
   4.192 +
   4.193  int main(void)
   4.194  {
   4.195 -    puts("HVM Loader\n");
   4.196 +    printf("HVM Loader\n");
   4.197  
   4.198      init_hypercalls();
   4.199  
   4.200 -    puts("Writing SMBIOS tables ...\n");
   4.201 +    printf("Writing SMBIOS tables ...\n");
   4.202      hvm_write_smbios_tables();
   4.203  
   4.204 -    puts("Loading ROMBIOS ...\n");
   4.205 +    printf("Loading ROMBIOS ...\n");
   4.206      memcpy((void *)ROMBIOS_PHYSICAL_ADDRESS, rombios, sizeof(rombios));
   4.207  
   4.208      apic_setup();
   4.209 -
   4.210 +    pci_setup();
   4.211      create_mp_tables();
   4.212  
   4.213      if ( cirrus_check() )
   4.214      {
   4.215 -        puts("Loading Cirrus VGABIOS ...\n");
   4.216 +        printf("Loading Cirrus VGABIOS ...\n");
   4.217          memcpy((void *)VGABIOS_PHYSICAL_ADDRESS,
   4.218                 vgabios_cirrusvga, sizeof(vgabios_cirrusvga));
   4.219      }
   4.220      else
   4.221      {
   4.222 -        puts("Loading Standard VGABIOS ...\n");
   4.223 +        printf("Loading Standard VGABIOS ...\n");
   4.224          memcpy((void *)VGABIOS_PHYSICAL_ADDRESS,
   4.225                 vgabios_stdvga, sizeof(vgabios_stdvga));
   4.226      }
   4.227  
   4.228      if ( get_acpi_enabled() != 0 )
   4.229      {
   4.230 -        puts("Loading ACPI ...\n");
   4.231 +        printf("Loading ACPI ...\n");
   4.232          acpi_madt_update((unsigned char *) acpi);
   4.233          if ( (ACPI_PHYSICAL_ADDRESS + sizeof(acpi)) <= 0xF0000 )
   4.234          {
   4.235 @@ -225,23 +338,23 @@ int main(void)
   4.236      if ( check_amd() )
   4.237      {
   4.238          /* AMD implies this is SVM */
   4.239 -        puts("SVM go ...\n");
   4.240 +        printf("SVM go ...\n");
   4.241          vmmcall(SVM_VMMCALL_RESET_TO_REALMODE, 0, 0, 0, 0, 0);
   4.242      }
   4.243      else
   4.244      {
   4.245 -        puts("Loading VMXAssist ...\n");
   4.246 +        printf("Loading VMXAssist ...\n");
   4.247          memcpy((void *)VMXASSIST_PHYSICAL_ADDRESS,
   4.248                 vmxassist, sizeof(vmxassist));
   4.249  
   4.250 -        puts("VMX go ...\n");
   4.251 +        printf("VMX go ...\n");
   4.252          __asm__ __volatile__(
   4.253              "jmp *%%eax"
   4.254              : : "a" (VMXASSIST_PHYSICAL_ADDRESS), "d" (0)
   4.255              );
   4.256      }
   4.257  
   4.258 -    puts("Failed to invoke ROMBIOS\n");
   4.259 +    printf("Failed to invoke ROMBIOS\n");
   4.260      return 0;
   4.261  }
   4.262  
     5.1 --- a/tools/firmware/hvmloader/mp_tables.c	Wed Nov 22 09:52:48 2006 -0700
     5.2 +++ b/tools/firmware/hvmloader/mp_tables.c	Wed Nov 22 17:50:20 2006 +0000
     5.3 @@ -263,10 +263,7 @@ void fill_mp_io_intr_entry(
     5.4  {
     5.5      mpiie->type = ENTRY_TYPE_IO_INTR;
     5.6      mpiie->intr_type = INTR_TYPE_INT;
     5.7 -    mpiie->io_intr_flags = 0;
     5.8 -    /* IRQs 10 and 11 are PCI, so level triggered and active low. */
     5.9 -    if ( (src_bus_irq == 10) || (src_bus_irq == 11) )
    5.10 -        mpiie->io_intr_flags = 0xf;
    5.11 +    mpiie->io_intr_flags = (PCI_ISA_IRQ_MASK & (1U<<src_bus_irq)) ? 0xf : 0x0;
    5.12      mpiie->src_bus_id = src_bus_id;
    5.13      mpiie->src_bus_irq = src_bus_irq;
    5.14      mpiie->dst_ioapic_id = ioapic_id;
    5.15 @@ -349,13 +346,13 @@ void create_mp_tables(void)
    5.16  
    5.17      vcpu_nr = get_vcpu_nr();
    5.18  
    5.19 -    puts("Creating MP tables ...\n");
    5.20 +    printf("Creating MP tables ...\n");
    5.21  
    5.22      /* Find the 'safe' place in ROMBIOS for the MP tables. */
    5.23      mp_table_base = get_mp_table_start();
    5.24      if ( mp_table_base == NULL )
    5.25      {
    5.26 -        puts("Couldn't find start point for MP tables\n");
    5.27 +        printf("Couldn't find start point for MP tables\n");
    5.28          return;
    5.29      }
    5.30  
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/firmware/hvmloader/pci_regs.h	Wed Nov 22 17:50:20 2006 +0000
     6.3 @@ -0,0 +1,108 @@
     6.4 +/*
     6.5 + *	pci_regs.h
     6.6 + *
     6.7 + *	PCI standard defines
     6.8 + *	Copyright 1994, Drew Eckhardt
     6.9 + *	Copyright 1997--1999 Martin Mares <mj@ucw.cz>
    6.10 + *
    6.11 + *	For more information, please consult the following manuals (look at
    6.12 + *	http://www.pcisig.com/ for how to get them):
    6.13 + *
    6.14 + *	PCI BIOS Specification
    6.15 + *	PCI Local Bus Specification
    6.16 + *	PCI to PCI Bridge Specification
    6.17 + *	PCI System Design Guide
    6.18 + */
    6.19 +
    6.20 +#ifndef __HVMLOADER_PCI_REGS_H__
    6.21 +#define __HVMLOADER_PCI_REGS_H__
    6.22 +
    6.23 +#define PCI_VENDOR_ID		0x00	/* 16 bits */
    6.24 +#define PCI_DEVICE_ID		0x02	/* 16 bits */
    6.25 +#define PCI_COMMAND		0x04	/* 16 bits */
    6.26 +#define  PCI_COMMAND_IO		0x1	/* Enable response in I/O space */
    6.27 +#define  PCI_COMMAND_MEMORY	0x2	/* Enable response in Memory space */
    6.28 +#define  PCI_COMMAND_MASTER	0x4	/* Enable bus mastering */
    6.29 +#define  PCI_COMMAND_SPECIAL	0x8	/* Enable response to special cycles */
    6.30 +#define  PCI_COMMAND_INVALIDATE	0x10	/* Use memory write and invalidate */
    6.31 +#define  PCI_COMMAND_VGA_PALETTE 0x20	/* Enable palette snooping */
    6.32 +#define  PCI_COMMAND_PARITY	0x40	/* Enable parity checking */
    6.33 +#define  PCI_COMMAND_WAIT 	0x80	/* Enable address/data stepping */
    6.34 +#define  PCI_COMMAND_SERR	0x100	/* Enable SERR */
    6.35 +#define  PCI_COMMAND_FAST_BACK	0x200	/* Enable back-to-back writes */
    6.36 +#define  PCI_COMMAND_INTX_DISABLE 0x400 /* INTx Emulation Disable */
    6.37 +
    6.38 +#define PCI_STATUS		0x06	/* 16 bits */
    6.39 +#define  PCI_STATUS_CAP_LIST	0x10	/* Support Capability List */
    6.40 +#define  PCI_STATUS_66MHZ	0x20	/* Support 66 Mhz PCI 2.1 bus */
    6.41 +#define  PCI_STATUS_UDF		0x40	/* Support User Definable Features [obsolete] */
    6.42 +#define  PCI_STATUS_FAST_BACK	0x80	/* Accept fast-back to back */
    6.43 +#define  PCI_STATUS_PARITY	0x100	/* Detected parity error */
    6.44 +#define  PCI_STATUS_DEVSEL_MASK	0x600	/* DEVSEL timing */
    6.45 +#define  PCI_STATUS_DEVSEL_FAST		0x000
    6.46 +#define  PCI_STATUS_DEVSEL_MEDIUM	0x200
    6.47 +#define  PCI_STATUS_DEVSEL_SLOW		0x400
    6.48 +#define  PCI_STATUS_SIG_TARGET_ABORT	0x800 /* Set on target abort */
    6.49 +#define  PCI_STATUS_REC_TARGET_ABORT	0x1000 /* Master ack of " */
    6.50 +#define  PCI_STATUS_REC_MASTER_ABORT	0x2000 /* Set on master abort */
    6.51 +#define  PCI_STATUS_SIG_SYSTEM_ERROR	0x4000 /* Set when we drive SERR */
    6.52 +#define  PCI_STATUS_DETECTED_PARITY	0x8000 /* Set on parity error */
    6.53 +
    6.54 +#define PCI_CLASS_REVISION	0x08	/* High 24 bits are class, low 8 revision */
    6.55 +#define PCI_REVISION_ID		0x08	/* Revision ID */
    6.56 +#define PCI_CLASS_PROG		0x09	/* Reg. Level Programming Interface */
    6.57 +#define PCI_CLASS_DEVICE	0x0a	/* Device class */
    6.58 +
    6.59 +#define PCI_CACHE_LINE_SIZE	0x0c	/* 8 bits */
    6.60 +#define PCI_LATENCY_TIMER	0x0d	/* 8 bits */
    6.61 +#define PCI_HEADER_TYPE		0x0e	/* 8 bits */
    6.62 +#define  PCI_HEADER_TYPE_NORMAL		0
    6.63 +#define  PCI_HEADER_TYPE_BRIDGE		1
    6.64 +#define  PCI_HEADER_TYPE_CARDBUS	2
    6.65 +
    6.66 +#define PCI_BIST		0x0f	/* 8 bits */
    6.67 +#define  PCI_BIST_CODE_MASK	0x0f	/* Return result */
    6.68 +#define  PCI_BIST_START		0x40	/* 1 to start BIST, 2 secs or less */
    6.69 +#define  PCI_BIST_CAPABLE	0x80	/* 1 if BIST capable */
    6.70 +
    6.71 +/*
    6.72 + * Base addresses specify locations in memory or I/O space.
    6.73 + * Decoded size can be determined by writing a value of
    6.74 + * 0xffffffff to the register, and reading it back.  Only
    6.75 + * 1 bits are decoded.
    6.76 + */
    6.77 +#define PCI_BASE_ADDRESS_0	0x10	/* 32 bits */
    6.78 +#define PCI_BASE_ADDRESS_1	0x14	/* 32 bits [htype 0,1 only] */
    6.79 +#define PCI_BASE_ADDRESS_2	0x18	/* 32 bits [htype 0 only] */
    6.80 +#define PCI_BASE_ADDRESS_3	0x1c	/* 32 bits */
    6.81 +#define PCI_BASE_ADDRESS_4	0x20	/* 32 bits */
    6.82 +#define PCI_BASE_ADDRESS_5	0x24	/* 32 bits */
    6.83 +#define  PCI_BASE_ADDRESS_SPACE		0x01	/* 0 = memory, 1 = I/O */
    6.84 +#define  PCI_BASE_ADDRESS_SPACE_IO	0x01
    6.85 +#define  PCI_BASE_ADDRESS_SPACE_MEMORY	0x00
    6.86 +#define  PCI_BASE_ADDRESS_MEM_TYPE_MASK	0x06
    6.87 +#define  PCI_BASE_ADDRESS_MEM_TYPE_32	0x00	/* 32 bit address */
    6.88 +#define  PCI_BASE_ADDRESS_MEM_TYPE_1M	0x02	/* Below 1M [obsolete] */
    6.89 +#define  PCI_BASE_ADDRESS_MEM_TYPE_64	0x04	/* 64 bit address */
    6.90 +#define  PCI_BASE_ADDRESS_MEM_PREFETCH	0x08	/* prefetchable? */
    6.91 +#define  PCI_BASE_ADDRESS_MEM_MASK	(~0x0fUL)
    6.92 +#define  PCI_BASE_ADDRESS_IO_MASK	(~0x03UL)
    6.93 +/* bit 1 is reserved if address_space = 1 */
    6.94 +
    6.95 +/* Header type 0 (normal devices) */
    6.96 +#define PCI_CARDBUS_CIS		0x28
    6.97 +#define PCI_SUBSYSTEM_VENDOR_ID	0x2c
    6.98 +#define PCI_SUBSYSTEM_ID	0x2e
    6.99 +#define PCI_ROM_ADDRESS		0x30	/* Bits 31..11 are address, 10..1 reserved */
   6.100 +#define  PCI_ROM_ADDRESS_ENABLE	0x01
   6.101 +#define PCI_ROM_ADDRESS_MASK	(~0x7ffUL)
   6.102 +
   6.103 +#define PCI_CAPABILITY_LIST	0x34	/* Offset of first capability list entry */
   6.104 +
   6.105 +/* 0x35-0x3b are reserved */
   6.106 +#define PCI_INTERRUPT_LINE	0x3c	/* 8 bits */
   6.107 +#define PCI_INTERRUPT_PIN	0x3d	/* 8 bits */
   6.108 +#define PCI_MIN_GNT		0x3e	/* 8 bits */
   6.109 +#define PCI_MAX_LAT		0x3f	/* 8 bits */
   6.110 +
   6.111 +#endif /* __HVMLOADER_PCI_REGS_H__ */
     7.1 --- a/tools/firmware/hvmloader/smbios.c	Wed Nov 22 09:52:48 2006 -0700
     7.2 +++ b/tools/firmware/hvmloader/smbios.c	Wed Nov 22 17:50:20 2006 +0000
     7.3 @@ -30,29 +30,29 @@
     7.4  
     7.5  static size_t
     7.6  write_smbios_tables(void *start,
     7.7 -		    uint32_t vcpus, uint64_t memsize,
     7.8 -		    uint8_t uuid[16], char *xen_version,
     7.9 -		    uint32_t xen_major_version, uint32_t xen_minor_version);
    7.10 +                    uint32_t vcpus, uint64_t memsize,
    7.11 +                    uint8_t uuid[16], char *xen_version,
    7.12 +                    uint32_t xen_major_version, uint32_t xen_minor_version);
    7.13  
    7.14  static void
    7.15  get_cpu_manufacturer(char *buf, int len);
    7.16  static void
    7.17  smbios_entry_point_init(void *start,
    7.18 -			uint16_t max_structure_size,
    7.19 -			uint16_t structure_table_length,
    7.20 -			uint32_t structure_table_address,
    7.21 -			uint16_t number_of_structures);
    7.22 +                        uint16_t max_structure_size,
    7.23 +                        uint16_t structure_table_length,
    7.24 +                        uint32_t structure_table_address,
    7.25 +                        uint16_t number_of_structures);
    7.26  static void *
    7.27  smbios_type_0_init(void *start, const char *xen_version,
    7.28 -		   uint32_t xen_major_version, uint32_t xen_minor_version);
    7.29 +                   uint32_t xen_major_version, uint32_t xen_minor_version);
    7.30  static void *
    7.31  smbios_type_1_init(void *start, const char *xen_version, 
    7.32 -		   uint8_t uuid[16]);
    7.33 +                   uint8_t uuid[16]);
    7.34  static void *
    7.35  smbios_type_3_init(void *start);
    7.36  static void *
    7.37  smbios_type_4_init(void *start, unsigned int cpu_number,
    7.38 -		   char *cpu_manufacturer);
    7.39 +                   char *cpu_manufacturer);
    7.40  static void *
    7.41  smbios_type_16_init(void *start, uint32_t memory_size_mb);
    7.42  static void *
    7.43 @@ -69,64 +69,64 @@ smbios_type_127_init(void *start);
    7.44  static void
    7.45  get_cpu_manufacturer(char *buf, int len)
    7.46  {
    7.47 -	char id[12];
    7.48 -	uint32_t eax = 0;
    7.49 +    char id[12];
    7.50 +    uint32_t eax = 0;
    7.51  
    7.52 -	cpuid(0, &eax, (uint32_t *)&id[0], (uint32_t *)&id[8],
    7.53 -	      (uint32_t *)&id[4]);
    7.54 +    cpuid(0, &eax, (uint32_t *)&id[0], (uint32_t *)&id[8],
    7.55 +          (uint32_t *)&id[4]);
    7.56  
    7.57 -	if (memcmp(id, "GenuineIntel", 12) == 0)
    7.58 -		strncpy(buf, "Intel", len);
    7.59 -	else if (memcmp(id, "AuthenticAMD", 12) == 0)
    7.60 -		strncpy(buf, "AMD", len);
    7.61 -	else
    7.62 -		strncpy(buf, "unknown", len);
    7.63 +    if (memcmp(id, "GenuineIntel", 12) == 0)
    7.64 +        strncpy(buf, "Intel", len);
    7.65 +    else if (memcmp(id, "AuthenticAMD", 12) == 0)
    7.66 +        strncpy(buf, "AMD", len);
    7.67 +    else
    7.68 +        strncpy(buf, "unknown", len);
    7.69  }
    7.70  
    7.71  static size_t
    7.72  write_smbios_tables(void *start,
    7.73 -		    uint32_t vcpus, uint64_t memsize,
    7.74 -		    uint8_t uuid[16], char *xen_version,
    7.75 -		    uint32_t xen_major_version, uint32_t xen_minor_version)
    7.76 +                    uint32_t vcpus, uint64_t memsize,
    7.77 +                    uint8_t uuid[16], char *xen_version,
    7.78 +                    uint32_t xen_major_version, uint32_t xen_minor_version)
    7.79  {
    7.80 -	unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
    7.81 -	char *p, *q;
    7.82 -	char cpu_manufacturer[15];
    7.83 +    unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
    7.84 +    char *p, *q;
    7.85 +    char cpu_manufacturer[15];
    7.86  
    7.87 -	get_cpu_manufacturer(cpu_manufacturer, 15);
    7.88 +    get_cpu_manufacturer(cpu_manufacturer, 15);
    7.89  
    7.90 -	p = (char *)start + sizeof(struct smbios_entry_point);
    7.91 +    p = (char *)start + sizeof(struct smbios_entry_point);
    7.92  
    7.93 -#define do_struct(fn) do {			\
    7.94 -	q = (fn);				\
    7.95 -	nr_structs++;				\
    7.96 -	if ((q - p) > max_struct_size)		\
    7.97 -		max_struct_size = q - p;	\
    7.98 -	p = q;					\
    7.99 +#define do_struct(fn) do {                      \
   7.100 +    q = (fn);                                   \
   7.101 +    nr_structs++;                               \
   7.102 +    if ( (q - p) > max_struct_size )            \
   7.103 +        max_struct_size = q - p;                \
   7.104 +    p = q;                                      \
   7.105  } while (0)
   7.106  
   7.107 -	do_struct(smbios_type_0_init(p, xen_version, xen_major_version,
   7.108 -				     xen_minor_version));
   7.109 -	do_struct(smbios_type_1_init(p, xen_version, uuid));
   7.110 -	do_struct(smbios_type_3_init(p));
   7.111 -	for (cpu_num = 1; cpu_num <= vcpus; cpu_num++)
   7.112 -		do_struct(smbios_type_4_init(p, cpu_num, cpu_manufacturer));
   7.113 -	do_struct(smbios_type_16_init(p, memsize));
   7.114 -	do_struct(smbios_type_17_init(p, memsize));
   7.115 -	do_struct(smbios_type_19_init(p, memsize));
   7.116 -	do_struct(smbios_type_20_init(p, memsize));
   7.117 -	do_struct(smbios_type_32_init(p));
   7.118 -	do_struct(smbios_type_127_init(p));
   7.119 +    do_struct(smbios_type_0_init(p, xen_version, xen_major_version,
   7.120 +                                 xen_minor_version));
   7.121 +    do_struct(smbios_type_1_init(p, xen_version, uuid));
   7.122 +    do_struct(smbios_type_3_init(p));
   7.123 +    for ( cpu_num = 1; cpu_num <= vcpus; cpu_num++ )
   7.124 +        do_struct(smbios_type_4_init(p, cpu_num, cpu_manufacturer));
   7.125 +    do_struct(smbios_type_16_init(p, memsize));
   7.126 +    do_struct(smbios_type_17_init(p, memsize));
   7.127 +    do_struct(smbios_type_19_init(p, memsize));
   7.128 +    do_struct(smbios_type_20_init(p, memsize));
   7.129 +    do_struct(smbios_type_32_init(p));
   7.130 +    do_struct(smbios_type_127_init(p));
   7.131  
   7.132  #undef do_struct
   7.133  
   7.134 -	smbios_entry_point_init(
   7.135 -		start, max_struct_size,
   7.136 -		(p - (char *)start) - sizeof(struct smbios_entry_point),
   7.137 -		SMBIOS_PHYSICAL_ADDRESS + sizeof(struct smbios_entry_point),
   7.138 -		nr_structs);
   7.139 +    smbios_entry_point_init(
   7.140 +        start, max_struct_size,
   7.141 +        (p - (char *)start) - sizeof(struct smbios_entry_point),
   7.142 +        SMBIOS_PHYSICAL_ADDRESS + sizeof(struct smbios_entry_point),
   7.143 +        nr_structs);
   7.144  
   7.145 -	return (size_t)((char *)p - (char *)start);
   7.146 +    return (size_t)((char *)p - (char *)start);
   7.147  }
   7.148  
   7.149  /* This tries to figure out how much pseudo-physical memory (in MB)
   7.150 @@ -142,428 +142,439 @@ write_smbios_tables(void *start,
   7.151  static uint64_t
   7.152  get_memsize(void)
   7.153  {
   7.154 -	struct e820entry *map = NULL;
   7.155 -	uint8_t num_entries = 0;
   7.156 -	uint64_t memsize = 0;
   7.157 -	uint8_t i;
   7.158 +    struct e820entry *map = NULL;
   7.159 +    uint8_t num_entries = 0;
   7.160 +    uint64_t memsize = 0;
   7.161 +    uint8_t i;
   7.162  
   7.163 -	map = (struct e820entry *) (E820_MAP_PAGE + E820_MAP_OFFSET);
   7.164 -	num_entries = *((uint8_t *) (E820_MAP_PAGE + E820_MAP_NR_OFFSET));
   7.165 +    map = (struct e820entry *) (E820_MAP_PAGE + E820_MAP_OFFSET);
   7.166 +    num_entries = *((uint8_t *) (E820_MAP_PAGE + E820_MAP_NR_OFFSET));
   7.167  
   7.168 -	/* walk through e820map, ignoring any entries that aren't marked
   7.169 -	   as usable or reserved. */
   7.170 +    /* walk through e820map, ignoring any entries that aren't marked
   7.171 +       as usable or reserved. */
   7.172  
   7.173 -	for (i = 0; i < num_entries; i++) {
   7.174 -		if (map->type == E820_RAM || map->type == E820_RESERVED)
   7.175 -			memsize += map->size;
   7.176 -		map++;
   7.177 -	}
   7.178 +    for ( i = 0; i < num_entries; i++ )
   7.179 +    {
   7.180 +        if (map->type == E820_RAM || map->type == E820_RESERVED)
   7.181 +            memsize += map->size;
   7.182 +        map++;
   7.183 +    }
   7.184  
   7.185 -	/* Round up to the nearest MB.  The user specifies domU
   7.186 -	   pseudo-physical memory in megabytes, so not doing this
   7.187 -	   could easily lead to reporting one less MB than the user
   7.188 -	   specified. */
   7.189 -	if (memsize & ((1<<20)-1))
   7.190 -		memsize = (memsize >> 20) + 1;
   7.191 -	else
   7.192 -		memsize = (memsize >> 20);
   7.193 +    /* Round up to the nearest MB.  The user specifies domU
   7.194 +       pseudo-physical memory in megabytes, so not doing this
   7.195 +       could easily lead to reporting one less MB than the user
   7.196 +       specified. */
   7.197 +    if ( memsize & ((1<<20)-1) )
   7.198 +        memsize = (memsize >> 20) + 1;
   7.199 +    else
   7.200 +        memsize = (memsize >> 20);
   7.201  
   7.202 -	return memsize;
   7.203 +    return memsize;
   7.204  }
   7.205  
   7.206  void
   7.207  hvm_write_smbios_tables(void)
   7.208  {
   7.209 -	uint8_t uuid[16]; /* ** This will break if xen_domain_handle_t is
   7.210 -			     not uint8_t[16]. ** */
   7.211 -	uint16_t xen_major_version, xen_minor_version;
   7.212 -	uint32_t xen_version;
   7.213 -	char xen_extra_version[XEN_EXTRAVERSION_LEN];
   7.214 -	/* guess conservatively on buffer length for Xen version string */
   7.215 -	char xen_version_str[80];
   7.216 -	/* temporary variables used to build up Xen version string */
   7.217 -	char *p = NULL; /* points to next point of insertion */
   7.218 -	unsigned len = 0; /* length of string already composed */
   7.219 -	char *tmp = NULL; /* holds result of itoa() */
   7.220 -	unsigned tmp_len; /* length of next string to add */
   7.221 +    uint8_t uuid[16]; /* ** This will break if xen_domain_handle_t is
   7.222 +                         not uint8_t[16]. ** */
   7.223 +    uint16_t xen_major_version, xen_minor_version;
   7.224 +    uint32_t xen_version;
   7.225 +    char xen_extra_version[XEN_EXTRAVERSION_LEN];
   7.226 +    /* guess conservatively on buffer length for Xen version string */
   7.227 +    char xen_version_str[80];
   7.228 +    /* temporary variables used to build up Xen version string */
   7.229 +    char *p = NULL; /* points to next point of insertion */
   7.230 +    unsigned len = 0; /* length of string already composed */
   7.231 +    char *tmp = NULL; /* holds result of itoa() */
   7.232 +    unsigned tmp_len; /* length of next string to add */
   7.233  
   7.234 -	hypercall_xen_version(XENVER_guest_handle, uuid);
   7.235 +    hypercall_xen_version(XENVER_guest_handle, uuid);
   7.236  
   7.237 -	/* xen_version major and minor */
   7.238 -	xen_version = hypercall_xen_version(XENVER_version, NULL);
   7.239 -	xen_major_version = (uint16_t) (xen_version >> 16);
   7.240 -	xen_minor_version = (uint16_t) xen_version;
   7.241 +    /* xen_version major and minor */
   7.242 +    xen_version = hypercall_xen_version(XENVER_version, NULL);
   7.243 +    xen_major_version = (uint16_t) (xen_version >> 16);
   7.244 +    xen_minor_version = (uint16_t) xen_version;
   7.245  
   7.246 -	hypercall_xen_version(XENVER_extraversion, xen_extra_version);
   7.247 +    hypercall_xen_version(XENVER_extraversion, xen_extra_version);
   7.248  
   7.249 -	/* build up human-readable Xen version string */
   7.250 -	p = xen_version_str;
   7.251 -	len = 0;
   7.252 +    /* build up human-readable Xen version string */
   7.253 +    p = xen_version_str;
   7.254 +    len = 0;
   7.255  
   7.256 -	itoa(tmp, xen_major_version);
   7.257 -	tmp_len = strlen(tmp);
   7.258 -	len += tmp_len;
   7.259 -	if (len >= sizeof(xen_version_str))
   7.260 -		goto error_out;
   7.261 -	strcpy(p, tmp);
   7.262 -	p += tmp_len;
   7.263 +    itoa(tmp, xen_major_version);
   7.264 +    tmp_len = strlen(tmp);
   7.265 +    len += tmp_len;
   7.266 +    if ( len >= sizeof(xen_version_str) )
   7.267 +        goto error_out;
   7.268 +    strcpy(p, tmp);
   7.269 +    p += tmp_len;
   7.270  
   7.271 -	len++;
   7.272 -	if (len >= sizeof(xen_version_str))
   7.273 -		goto error_out;
   7.274 -	*p = '.';
   7.275 -	p++;
   7.276 +    len++;
   7.277 +    if ( len >= sizeof(xen_version_str) )
   7.278 +        goto error_out;
   7.279 +    *p = '.';
   7.280 +    p++;
   7.281  
   7.282 -	itoa(tmp, xen_minor_version);
   7.283 -	tmp_len = strlen(tmp);
   7.284 -	len += tmp_len;
   7.285 -	if (len >= sizeof(xen_version_str))
   7.286 -		goto error_out;
   7.287 -	strcpy(p, tmp);
   7.288 -	p += tmp_len;
   7.289 +    itoa(tmp, xen_minor_version);
   7.290 +    tmp_len = strlen(tmp);
   7.291 +    len += tmp_len;
   7.292 +    if ( len >= sizeof(xen_version_str) )
   7.293 +        goto error_out;
   7.294 +    strcpy(p, tmp);
   7.295 +    p += tmp_len;
   7.296  
   7.297 -	tmp_len = strlen(xen_extra_version);
   7.298 -	len += tmp_len;
   7.299 -	if (len >= sizeof(xen_version_str))
   7.300 -		goto error_out;
   7.301 -	strcpy(p, xen_extra_version);
   7.302 -	p += tmp_len;
   7.303 +    tmp_len = strlen(xen_extra_version);
   7.304 +    len += tmp_len;
   7.305 +    if ( len >= sizeof(xen_version_str) )
   7.306 +        goto error_out;
   7.307 +    strcpy(p, xen_extra_version);
   7.308 +    p += tmp_len;
   7.309  
   7.310 -	xen_version_str[sizeof(xen_version_str)-1] = '\0';
   7.311 +    xen_version_str[sizeof(xen_version_str)-1] = '\0';
   7.312  
   7.313 -	/* NB. 0xC0000 is a safe large memory area for scratch. */
   7.314 -	len = write_smbios_tables((void *)0xC0000,
   7.315 -				  get_vcpu_nr(), get_memsize(),
   7.316 -				  uuid, xen_version_str,
   7.317 -				  xen_major_version, xen_minor_version);
   7.318 -	if (len > SMBIOS_SIZE_LIMIT)
   7.319 -		goto error_out;
   7.320 -	/* Okay, not too large: copy out of scratch to final location. */
   7.321 -	memcpy((void *)SMBIOS_PHYSICAL_ADDRESS, (void *)0xC0000, len);
   7.322 +    /* NB. 0xC0000 is a safe large memory area for scratch. */
   7.323 +    len = write_smbios_tables((void *)0xC0000,
   7.324 +                              get_vcpu_nr(), get_memsize(),
   7.325 +                              uuid, xen_version_str,
   7.326 +                              xen_major_version, xen_minor_version);
   7.327 +    if ( len > SMBIOS_SIZE_LIMIT )
   7.328 +        goto error_out;
   7.329 +    /* Okay, not too large: copy out of scratch to final location. */
   7.330 +    memcpy((void *)SMBIOS_PHYSICAL_ADDRESS, (void *)0xC0000, len);
   7.331  
   7.332 -	return;
   7.333 +    return;
   7.334  
   7.335   error_out:
   7.336 -	puts("Could not write SMBIOS tables, error in hvmloader.c:"
   7.337 -	     "hvm_write_smbios_tables()\n");
   7.338 +    printf("Could not write SMBIOS tables, error in hvmloader.c:"
   7.339 +           "hvm_write_smbios_tables()\n");
   7.340  }
   7.341  
   7.342  
   7.343  static void
   7.344  smbios_entry_point_init(void *start,
   7.345 -			uint16_t max_structure_size,
   7.346 -			uint16_t structure_table_length,
   7.347 -			uint32_t structure_table_address,
   7.348 -			uint16_t number_of_structures)
   7.349 +                        uint16_t max_structure_size,
   7.350 +                        uint16_t structure_table_length,
   7.351 +                        uint32_t structure_table_address,
   7.352 +                        uint16_t number_of_structures)
   7.353  {
   7.354 -	uint8_t sum;
   7.355 -	int i;
   7.356 -	struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
   7.357 +    uint8_t sum;
   7.358 +    int i;
   7.359 +    struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
   7.360  
   7.361 -	strncpy(ep->anchor_string, "_SM_", 4);
   7.362 -	ep->length = 0x1f;
   7.363 -	ep->smbios_major_version = 2;
   7.364 -	ep->smbios_minor_version = 4;
   7.365 -	ep->max_structure_size = max_structure_size;
   7.366 -	ep->entry_point_revision = 0;
   7.367 -	memset(ep->formatted_area, 0, 5);
   7.368 -	strncpy(ep->intermediate_anchor_string, "_DMI_", 5);
   7.369 +    strncpy(ep->anchor_string, "_SM_", 4);
   7.370 +    ep->length = 0x1f;
   7.371 +    ep->smbios_major_version = 2;
   7.372 +    ep->smbios_minor_version = 4;
   7.373 +    ep->max_structure_size = max_structure_size;
   7.374 +    ep->entry_point_revision = 0;
   7.375 +    memset(ep->formatted_area, 0, 5);
   7.376 +    strncpy(ep->intermediate_anchor_string, "_DMI_", 5);
   7.377      
   7.378 -	ep->structure_table_length = structure_table_length;
   7.379 -	ep->structure_table_address = structure_table_address;
   7.380 -	ep->number_of_structures = number_of_structures;
   7.381 -	ep->smbios_bcd_revision = 0x24;
   7.382 +    ep->structure_table_length = structure_table_length;
   7.383 +    ep->structure_table_address = structure_table_address;
   7.384 +    ep->number_of_structures = number_of_structures;
   7.385 +    ep->smbios_bcd_revision = 0x24;
   7.386  
   7.387 -	ep->checksum = 0;
   7.388 -	ep->intermediate_checksum = 0;
   7.389 +    ep->checksum = 0;
   7.390 +    ep->intermediate_checksum = 0;
   7.391      
   7.392 -	sum = 0;
   7.393 -	for (i = 0; i < 0x10; ++i)
   7.394 -		sum += ((int8_t *)start)[i];
   7.395 -	ep->checksum = -sum;
   7.396 +    sum = 0;
   7.397 +    for ( i = 0; i < 0x10; i++ )
   7.398 +        sum += ((int8_t *)start)[i];
   7.399 +    ep->checksum = -sum;
   7.400  
   7.401 -	sum = 0;
   7.402 -	for (i = 0x10; i < ep->length; ++i)
   7.403 -		sum += ((int8_t *)start)[i];
   7.404 -	ep->intermediate_checksum = -sum;
   7.405 +    sum = 0;
   7.406 +    for ( i = 0x10; i < ep->length; i++ )
   7.407 +        sum += ((int8_t *)start)[i];
   7.408 +    ep->intermediate_checksum = -sum;
   7.409  }
   7.410  
   7.411  /* Type 0 -- BIOS Information */
   7.412  static void *
   7.413  smbios_type_0_init(void *start, const char *xen_version,
   7.414 -		   uint32_t xen_major_version, uint32_t xen_minor_version)
   7.415 +                   uint32_t xen_major_version, uint32_t xen_minor_version)
   7.416  {
   7.417 -	struct smbios_type_0 *p = (struct smbios_type_0 *)start;
   7.418 +    struct smbios_type_0 *p = (struct smbios_type_0 *)start;
   7.419      
   7.420 -	p->header.type = 0;
   7.421 -	p->header.length = sizeof(struct smbios_type_0);
   7.422 -	p->header.handle = 0;
   7.423 +    p->header.type = 0;
   7.424 +    p->header.length = sizeof(struct smbios_type_0);
   7.425 +    p->header.handle = 0;
   7.426      
   7.427 -	p->vendor_str = 1;
   7.428 -	p->version_str = 2;
   7.429 -	p->starting_address_segment = 0xe800;
   7.430 -	p->release_date_str = 0;
   7.431 -	p->rom_size = 0;
   7.432 +    p->vendor_str = 1;
   7.433 +    p->version_str = 2;
   7.434 +    p->starting_address_segment = 0xe800;
   7.435 +    p->release_date_str = 0;
   7.436 +    p->rom_size = 0;
   7.437      
   7.438 -	memset(p->characteristics, 0, 8);
   7.439 -	p->characteristics[7] = 0x08; /* BIOS characteristics not supported */
   7.440 -	p->characteristics_extension_bytes[0] = 0;
   7.441 -	p->characteristics_extension_bytes[1] = 0;
   7.442 +    memset(p->characteristics, 0, 8);
   7.443 +    p->characteristics[7] = 0x08; /* BIOS characteristics not supported */
   7.444 +    p->characteristics_extension_bytes[0] = 0;
   7.445 +    p->characteristics_extension_bytes[1] = 0;
   7.446      
   7.447 -	p->major_release = (uint8_t) xen_major_version;
   7.448 -	p->minor_release = (uint8_t) xen_minor_version;
   7.449 -	p->embedded_controller_major = 0xff;
   7.450 -	p->embedded_controller_minor = 0xff;
   7.451 +    p->major_release = (uint8_t) xen_major_version;
   7.452 +    p->minor_release = (uint8_t) xen_minor_version;
   7.453 +    p->embedded_controller_major = 0xff;
   7.454 +    p->embedded_controller_minor = 0xff;
   7.455  
   7.456 -	start += sizeof(struct smbios_type_0);
   7.457 -	strcpy((char *)start, "Xen");
   7.458 -	start += strlen("Xen") + 1;
   7.459 -	strcpy((char *)start, xen_version);
   7.460 -	start += strlen(xen_version) + 1;
   7.461 +    start += sizeof(struct smbios_type_0);
   7.462 +    strcpy((char *)start, "Xen");
   7.463 +    start += strlen("Xen") + 1;
   7.464 +    strcpy((char *)start, xen_version);
   7.465 +    start += strlen(xen_version) + 1;
   7.466  
   7.467 -	*((uint8_t *)start) = 0;
   7.468 -	return start + 1;
   7.469 +    *((uint8_t *)start) = 0;
   7.470 +    return start + 1;
   7.471  }
   7.472  
   7.473  /* Type 1 -- System Information */
   7.474  static void *
   7.475  smbios_type_1_init(void *start, const char *xen_version, 
   7.476 -		   uint8_t uuid[16])
   7.477 +                   uint8_t uuid[16])
   7.478  {
   7.479 -	char uuid_str[37];
   7.480 -	struct smbios_type_1 *p = (struct smbios_type_1 *)start;
   7.481 -	p->header.type = 1;
   7.482 -	p->header.length = sizeof(struct smbios_type_1);
   7.483 -	p->header.handle = 0x100;
   7.484 +    char uuid_str[37];
   7.485 +    struct smbios_type_1 *p = (struct smbios_type_1 *)start;
   7.486 +    p->header.type = 1;
   7.487 +    p->header.length = sizeof(struct smbios_type_1);
   7.488 +    p->header.handle = 0x100;
   7.489  
   7.490 -	p->manufacturer_str = 1;
   7.491 -	p->product_name_str = 2;
   7.492 -	p->version_str = 3;
   7.493 -	p->serial_number_str = 4;
   7.494 +    p->manufacturer_str = 1;
   7.495 +    p->product_name_str = 2;
   7.496 +    p->version_str = 3;
   7.497 +    p->serial_number_str = 4;
   7.498      
   7.499 -	memcpy(p->uuid, uuid, 16);
   7.500 +    memcpy(p->uuid, uuid, 16);
   7.501  
   7.502 -	p->wake_up_type = 0x06; /* power switch */
   7.503 -	p->sku_str = 0;
   7.504 -	p->family_str = 0;
   7.505 +    p->wake_up_type = 0x06; /* power switch */
   7.506 +    p->sku_str = 0;
   7.507 +    p->family_str = 0;
   7.508  
   7.509 -	start += sizeof(struct smbios_type_1);
   7.510 +    start += sizeof(struct smbios_type_1);
   7.511      
   7.512 -	strcpy((char *)start, "Xen");
   7.513 -	start += strlen("Xen") + 1;
   7.514 -	strcpy((char *)start, "HVM domU");
   7.515 -	start += strlen("HVM domU") + 1;
   7.516 -	strcpy((char *)start, xen_version);
   7.517 -	start += strlen(xen_version) + 1;
   7.518 -	uuid_to_string(uuid_str, uuid);	
   7.519 -	strcpy((char *)start, uuid_str);
   7.520 -	start += strlen(uuid_str) + 1;
   7.521 -	*((uint8_t *)start) = 0;
   7.522 +    strcpy((char *)start, "Xen");
   7.523 +    start += strlen("Xen") + 1;
   7.524 +    strcpy((char *)start, "HVM domU");
   7.525 +    start += strlen("HVM domU") + 1;
   7.526 +    strcpy((char *)start, xen_version);
   7.527 +    start += strlen(xen_version) + 1;
   7.528 +    uuid_to_string(uuid_str, uuid); 
   7.529 +    strcpy((char *)start, uuid_str);
   7.530 +    start += strlen(uuid_str) + 1;
   7.531 +    *((uint8_t *)start) = 0;
   7.532      
   7.533 -	return start+1; 
   7.534 +    return start+1; 
   7.535  }
   7.536  
   7.537  /* Type 3 -- System Enclosure */
   7.538  static void *
   7.539  smbios_type_3_init(void *start)
   7.540  {
   7.541 -	struct smbios_type_3 *p = (struct smbios_type_3 *)start;
   7.542 +    struct smbios_type_3 *p = (struct smbios_type_3 *)start;
   7.543      
   7.544 -	p->header.type = 3;
   7.545 -	p->header.length = sizeof(struct smbios_type_3);
   7.546 -	p->header.handle = 0x300;
   7.547 +    p->header.type = 3;
   7.548 +    p->header.length = sizeof(struct smbios_type_3);
   7.549 +    p->header.handle = 0x300;
   7.550  
   7.551 -	p->manufacturer_str = 1;
   7.552 -	p->type = 0x01; /* other */
   7.553 -	p->version_str = 0;
   7.554 -	p->serial_number_str = 0;
   7.555 -	p->asset_tag_str = 0;
   7.556 -	p->boot_up_state = 0x03; /* safe */
   7.557 -	p->power_supply_state = 0x03; /* safe */
   7.558 -	p->thermal_state = 0x03; /* safe */
   7.559 -	p->security_status = 0x02; /* unknown */
   7.560 +    p->manufacturer_str = 1;
   7.561 +    p->type = 0x01; /* other */
   7.562 +    p->version_str = 0;
   7.563 +    p->serial_number_str = 0;
   7.564 +    p->asset_tag_str = 0;
   7.565 +    p->boot_up_state = 0x03; /* safe */
   7.566 +    p->power_supply_state = 0x03; /* safe */
   7.567 +    p->thermal_state = 0x03; /* safe */
   7.568 +    p->security_status = 0x02; /* unknown */
   7.569  
   7.570 -	start += sizeof(struct smbios_type_3);
   7.571 +    start += sizeof(struct smbios_type_3);
   7.572      
   7.573 -	strcpy((char *)start, "Xen");
   7.574 -	start += strlen("Xen") + 1;
   7.575 -	*((uint8_t *)start) = 0;
   7.576 -	return start+1;
   7.577 +    strcpy((char *)start, "Xen");
   7.578 +    start += strlen("Xen") + 1;
   7.579 +    *((uint8_t *)start) = 0;
   7.580 +    return start+1;
   7.581  }
   7.582  
   7.583  /* Type 4 -- Processor Information */
   7.584  static void *
   7.585  smbios_type_4_init(void *start, unsigned int cpu_number, char *cpu_manufacturer)
   7.586  {
   7.587 -	char buf[80]; 
   7.588 -	struct smbios_type_4 *p = (struct smbios_type_4 *)start;
   7.589 -	uint32_t eax, ebx, ecx, edx;
   7.590 +    char buf[80]; 
   7.591 +    struct smbios_type_4 *p = (struct smbios_type_4 *)start;
   7.592 +    uint32_t eax, ebx, ecx, edx;
   7.593  
   7.594 -	p->header.type = 4;
   7.595 -	p->header.length = sizeof(struct smbios_type_4);
   7.596 -	p->header.handle = 0x400 + cpu_number;
   7.597 +    p->header.type = 4;
   7.598 +    p->header.length = sizeof(struct smbios_type_4);
   7.599 +    p->header.handle = 0x400 + cpu_number;
   7.600  
   7.601 -	p->socket_designation_str = 1;
   7.602 -	p->processor_type = 0x03; /* CPU */
   7.603 -	p->processor_family = 0x01; /* other */
   7.604 -	p->manufacturer_str = 2;
   7.605 +    p->socket_designation_str = 1;
   7.606 +    p->processor_type = 0x03; /* CPU */
   7.607 +    p->processor_family = 0x01; /* other */
   7.608 +    p->manufacturer_str = 2;
   7.609  
   7.610 -	cpuid(1, &eax, &ebx, &ecx, &edx);
   7.611 +    cpuid(1, &eax, &ebx, &ecx, &edx);
   7.612  
   7.613 -	p->cpuid[0] = eax;
   7.614 -	p->cpuid[1] = edx;
   7.615 +    p->cpuid[0] = eax;
   7.616 +    p->cpuid[1] = edx;
   7.617  
   7.618 -	p->version_str = 0;
   7.619 -	p->voltage = 0;
   7.620 -	p->external_clock = 0;
   7.621 +    p->version_str = 0;
   7.622 +    p->voltage = 0;
   7.623 +    p->external_clock = 0;
   7.624  
   7.625 -	p->max_speed = 0; /* unknown */
   7.626 -	p->current_speed = 0; /* unknown */
   7.627 +    p->max_speed = 0; /* unknown */
   7.628 +    p->current_speed = 0; /* unknown */
   7.629  
   7.630 -	p->status = 0x41; /* socket populated, CPU enabled */
   7.631 -	p->upgrade = 0x01; /* other */
   7.632 +    p->status = 0x41; /* socket populated, CPU enabled */
   7.633 +    p->upgrade = 0x01; /* other */
   7.634  
   7.635 -	start += sizeof(struct smbios_type_4);
   7.636 +    start += sizeof(struct smbios_type_4);
   7.637  
   7.638 -	strncpy(buf, "CPU ", sizeof(buf));
   7.639 -	if ((sizeof(buf) - strlen("CPU ")) >= 3)
   7.640 -		itoa(buf + strlen("CPU "), cpu_number);
   7.641 +    strncpy(buf, "CPU ", sizeof(buf));
   7.642 +    if ( (sizeof(buf) - strlen("CPU ")) >= 3 )
   7.643 +        itoa(buf + strlen("CPU "), cpu_number);
   7.644  
   7.645 -	strcpy((char *)start, buf);
   7.646 -	start += strlen(buf) + 1;
   7.647 +    strcpy((char *)start, buf);
   7.648 +    start += strlen(buf) + 1;
   7.649  
   7.650 -	strcpy((char *)start, cpu_manufacturer);
   7.651 -	start += strlen(cpu_manufacturer) + 1;
   7.652 +    strcpy((char *)start, cpu_manufacturer);
   7.653 +    start += strlen(cpu_manufacturer) + 1;
   7.654  
   7.655 -	*((uint8_t *)start) = 0;
   7.656 -	return start+1;
   7.657 +    *((uint8_t *)start) = 0;
   7.658 +    return start+1;
   7.659  }
   7.660  
   7.661  /* Type 16 -- Physical Memory Array */
   7.662  static void *
   7.663  smbios_type_16_init(void *start, uint32_t memsize)
   7.664  {
   7.665 -	struct smbios_type_16 *p = (struct smbios_type_16*)start;
   7.666 +    struct smbios_type_16 *p = (struct smbios_type_16*)start;
   7.667  
   7.668 -	p->header.type = 16;
   7.669 -	p->header.handle = 0x1000;
   7.670 -	p->header.length = sizeof(struct smbios_type_16);
   7.671 +    p->header.type = 16;
   7.672 +    p->header.handle = 0x1000;
   7.673 +    p->header.length = sizeof(struct smbios_type_16);
   7.674      
   7.675 -	p->location = 0x01; /* other */
   7.676 -	p->use = 0x03; /* system memory */
   7.677 -	p->error_correction = 0x01; /* other */
   7.678 -	p->maximum_capacity = memsize * 1024;
   7.679 -	p->memory_error_information_handle = 0xfffe; /* none provided */
   7.680 -	p->number_of_memory_devices = 1;
   7.681 +    p->location = 0x01; /* other */
   7.682 +    p->use = 0x03; /* system memory */
   7.683 +    p->error_correction = 0x01; /* other */
   7.684 +    p->maximum_capacity = memsize * 1024;
   7.685 +    p->memory_error_information_handle = 0xfffe; /* none provided */
   7.686 +    p->number_of_memory_devices = 1;
   7.687  
   7.688 -	start += sizeof(struct smbios_type_16);
   7.689 -	*((uint16_t *)start) = 0;
   7.690 -	return start + 2;
   7.691 +    start += sizeof(struct smbios_type_16);
   7.692 +    *((uint16_t *)start) = 0;
   7.693 +    return start + 2;
   7.694  }
   7.695  
   7.696  /* Type 17 -- Memory Device */
   7.697  static void *
   7.698  smbios_type_17_init(void *start, uint32_t memory_size_mb)
   7.699  {
   7.700 -	struct smbios_type_17 *p = (struct smbios_type_17 *)start;
   7.701 +    struct smbios_type_17 *p = (struct smbios_type_17 *)start;
   7.702      
   7.703 -	p->header.type = 17;
   7.704 -	p->header.length = sizeof(struct smbios_type_17);
   7.705 -	p->header.handle = 0x1100;
   7.706 +    p->header.type = 17;
   7.707 +    p->header.length = sizeof(struct smbios_type_17);
   7.708 +    p->header.handle = 0x1100;
   7.709  
   7.710 -	p->physical_memory_array_handle = 0x1000;
   7.711 -	p->total_width = 64;
   7.712 -	p->data_width = 64;
   7.713 -	/* truncate memory_size_mb to 16 bits and clear most significant
   7.714 -	   bit [indicates size in MB] */
   7.715 -	p->size = (uint16_t) memory_size_mb & 0x7fff;
   7.716 -	p->form_factor = 0x09; /* DIMM */
   7.717 -	p->device_set = 0;
   7.718 -	p->device_locator_str = 1;
   7.719 -	p->bank_locator_str = 0;
   7.720 -	p->memory_type = 0x07; /* RAM */
   7.721 -	p->type_detail = 0;
   7.722 +    p->physical_memory_array_handle = 0x1000;
   7.723 +    p->total_width = 64;
   7.724 +    p->data_width = 64;
   7.725 +    /* truncate memory_size_mb to 16 bits and clear most significant
   7.726 +       bit [indicates size in MB] */
   7.727 +    p->size = (uint16_t) memory_size_mb & 0x7fff;
   7.728 +    p->form_factor = 0x09; /* DIMM */
   7.729 +    p->device_set = 0;
   7.730 +    p->device_locator_str = 1;
   7.731 +    p->bank_locator_str = 0;
   7.732 +    p->memory_type = 0x07; /* RAM */
   7.733 +    p->type_detail = 0;
   7.734  
   7.735 -	start += sizeof(struct smbios_type_17);
   7.736 -	strcpy((char *)start, "DIMM 1");
   7.737 -	start += strlen("DIMM 1") + 1;
   7.738 -	*((uint8_t *)start) = 0;
   7.739 +    start += sizeof(struct smbios_type_17);
   7.740 +    strcpy((char *)start, "DIMM 1");
   7.741 +    start += strlen("DIMM 1") + 1;
   7.742 +    *((uint8_t *)start) = 0;
   7.743  
   7.744 -	return start+1;
   7.745 +    return start+1;
   7.746  }
   7.747  
   7.748  /* Type 19 -- Memory Array Mapped Address */
   7.749  static void *
   7.750  smbios_type_19_init(void *start, uint32_t memory_size_mb)
   7.751  {
   7.752 -	struct smbios_type_19 *p = (struct smbios_type_19 *)start;
   7.753 +    struct smbios_type_19 *p = (struct smbios_type_19 *)start;
   7.754      
   7.755 -	p->header.type = 19;
   7.756 -	p->header.length = sizeof(struct smbios_type_19);
   7.757 -	p->header.handle = 0x1300;
   7.758 +    p->header.type = 19;
   7.759 +    p->header.length = sizeof(struct smbios_type_19);
   7.760 +    p->header.handle = 0x1300;
   7.761  
   7.762 -	p->starting_address = 0;
   7.763 -	p->ending_address = (memory_size_mb-1) * 1024;
   7.764 -	p->memory_array_handle = 0x1000;
   7.765 -	p->partition_width = 1;
   7.766 +    p->starting_address = 0;
   7.767 +    p->ending_address = (memory_size_mb-1) * 1024;
   7.768 +    p->memory_array_handle = 0x1000;
   7.769 +    p->partition_width = 1;
   7.770  
   7.771 -	start += sizeof(struct smbios_type_19);
   7.772 -	*((uint16_t *)start) = 0;
   7.773 -	return start + 2;
   7.774 +    start += sizeof(struct smbios_type_19);
   7.775 +    *((uint16_t *)start) = 0;
   7.776 +    return start + 2;
   7.777  }
   7.778  
   7.779  /* Type 20 -- Memory Device Mapped Address */
   7.780  static void *
   7.781  smbios_type_20_init(void *start, uint32_t memory_size_mb)
   7.782  {
   7.783 -	struct smbios_type_20 *p = (struct smbios_type_20 *)start;
   7.784 +    struct smbios_type_20 *p = (struct smbios_type_20 *)start;
   7.785  
   7.786 -	p->header.type = 20;
   7.787 -	p->header.length = sizeof(struct smbios_type_20);
   7.788 -	p->header.handle = 0x1400;
   7.789 +    p->header.type = 20;
   7.790 +    p->header.length = sizeof(struct smbios_type_20);
   7.791 +    p->header.handle = 0x1400;
   7.792  
   7.793 -	p->starting_address = 0;
   7.794 -	p->ending_address = (memory_size_mb-1)*1024;
   7.795 -	p->memory_device_handle = 0x1100;
   7.796 -	p->memory_array_mapped_address_handle = 0x1300;
   7.797 -	p->partition_row_position = 1;
   7.798 -	p->interleave_position = 0;
   7.799 -	p->interleaved_data_depth = 0;
   7.800 +    p->starting_address = 0;
   7.801 +    p->ending_address = (memory_size_mb-1)*1024;
   7.802 +    p->memory_device_handle = 0x1100;
   7.803 +    p->memory_array_mapped_address_handle = 0x1300;
   7.804 +    p->partition_row_position = 1;
   7.805 +    p->interleave_position = 0;
   7.806 +    p->interleaved_data_depth = 0;
   7.807  
   7.808 -	start += sizeof(struct smbios_type_20);
   7.809 +    start += sizeof(struct smbios_type_20);
   7.810  
   7.811 -	*((uint16_t *)start) = 0;
   7.812 -	return start+2;
   7.813 +    *((uint16_t *)start) = 0;
   7.814 +    return start+2;
   7.815  }
   7.816  
   7.817  /* Type 32 -- System Boot Information */
   7.818  static void *
   7.819  smbios_type_32_init(void *start)
   7.820  {
   7.821 -	struct smbios_type_32 *p = (struct smbios_type_32 *)start;
   7.822 +    struct smbios_type_32 *p = (struct smbios_type_32 *)start;
   7.823  
   7.824 -	p->header.type = 32;
   7.825 -	p->header.length = sizeof(struct smbios_type_32);
   7.826 -	p->header.handle = 0x2000;
   7.827 -	memset(p->reserved, 0, 6);
   7.828 -	p->boot_status = 0; /* no errors detected */
   7.829 +    p->header.type = 32;
   7.830 +    p->header.length = sizeof(struct smbios_type_32);
   7.831 +    p->header.handle = 0x2000;
   7.832 +    memset(p->reserved, 0, 6);
   7.833 +    p->boot_status = 0; /* no errors detected */
   7.834      
   7.835 -	start += sizeof(struct smbios_type_32);
   7.836 -	*((uint16_t *)start) = 0;
   7.837 -	return start+2;
   7.838 +    start += sizeof(struct smbios_type_32);
   7.839 +    *((uint16_t *)start) = 0;
   7.840 +    return start+2;
   7.841  }
   7.842  
   7.843  /* Type 127 -- End of Table */
   7.844  static void *
   7.845  smbios_type_127_init(void *start)
   7.846  {
   7.847 -	struct smbios_type_127 *p = (struct smbios_type_127 *)start;
   7.848 +    struct smbios_type_127 *p = (struct smbios_type_127 *)start;
   7.849 +
   7.850 +    p->header.type = 127;
   7.851 +    p->header.length = sizeof(struct smbios_type_127);
   7.852 +    p->header.handle = 0x7f00;
   7.853  
   7.854 -	p->header.type = 127;
   7.855 -	p->header.length = sizeof(struct smbios_type_127);
   7.856 -	p->header.handle = 0x7f00;
   7.857 +    start += sizeof(struct smbios_type_127);
   7.858 +    *((uint16_t *)start) = 0;
   7.859 +    return start + 2;
   7.860 +}
   7.861  
   7.862 -	start += sizeof(struct smbios_type_127);
   7.863 -	*((uint16_t *)start) = 0;
   7.864 -	return start + 2;
   7.865 -}
   7.866 +/*
   7.867 + * Local variables:
   7.868 + * mode: C
   7.869 + * c-set-style: "BSD"
   7.870 + * c-basic-offset: 4
   7.871 + * tab-width: 4
   7.872 + * indent-tabs-mode: nil
   7.873 + * End:
   7.874 + */
     8.1 --- a/tools/firmware/hvmloader/util.c	Wed Nov 22 09:52:48 2006 -0700
     8.2 +++ b/tools/firmware/hvmloader/util.c	Wed Nov 22 17:50:20 2006 +0000
     8.3 @@ -20,175 +20,193 @@
     8.4  
     8.5  #include "acpi/acpi2_0.h"  /* for ACPI_PHYSICAL_ADDRESS */
     8.6  #include "util.h"
     8.7 +#include "config.h"
     8.8  #include <stdint.h>
     8.9 +#include <xenctrl.h>
    8.10 +
    8.11 +void outb(uint16_t addr, uint8_t val)
    8.12 +{
    8.13 +    __asm__ __volatile__ ( "outb %%al, %%dx" :: "d"(addr), "a"(val) );
    8.14 +}
    8.15  
    8.16  void outw(uint16_t addr, uint16_t val)
    8.17  {
    8.18 -	__asm__ __volatile__ ("outw %%ax, %%dx" :: "d"(addr), "a"(val));
    8.19 +    __asm__ __volatile__ ( "outw %%ax, %%dx" :: "d"(addr), "a"(val) );
    8.20  }
    8.21  
    8.22 -void outb(uint16_t addr, uint8_t val)
    8.23 +void outl(uint16_t addr, uint32_t val)
    8.24  {
    8.25 -	__asm__ __volatile__ ("outb %%al, %%dx" :: "d"(addr), "a"(val));
    8.26 +    __asm__ __volatile__ ( "outl %%eax, %%dx" :: "d"(addr), "a"(val) );
    8.27  }
    8.28  
    8.29  uint8_t inb(uint16_t addr)
    8.30  {
    8.31 -	uint8_t val;
    8.32 -	__asm__ __volatile__ ("inb %w1,%0" : "=a" (val) : "Nd" (addr));
    8.33 -	return val;
    8.34 +    uint8_t val;
    8.35 +    __asm__ __volatile__ ( "inb %%dx,%%al" : "=a" (val) : "d" (addr) );
    8.36 +    return val;
    8.37 +}
    8.38 +
    8.39 +uint16_t inw(uint16_t addr)
    8.40 +{
    8.41 +    uint16_t val;
    8.42 +    __asm__ __volatile__ ( "inw %%dx,%%ax" : "=a" (val) : "d" (addr) );
    8.43 +    return val;
    8.44 +}
    8.45 +
    8.46 +uint32_t inl(uint16_t addr)
    8.47 +{
    8.48 +    uint32_t val;
    8.49 +    __asm__ __volatile__ ( "inl %%dx,%%eax" : "=a" (val) : "d" (addr) );
    8.50 +    return val;
    8.51  }
    8.52  
    8.53  char *itoa(char *a, unsigned int i)
    8.54  {
    8.55 -	unsigned int _i = i, x = 0;
    8.56 +    unsigned int _i = i, x = 0;
    8.57  
    8.58 -	do {
    8.59 -		x++;
    8.60 -		_i /= 10;
    8.61 -	} while (_i != 0);
    8.62 +    do {
    8.63 +        x++;
    8.64 +        _i /= 10;
    8.65 +    } while ( _i != 0 );
    8.66  
    8.67 -	a += x;
    8.68 -	*a-- = '\0';
    8.69 +    a += x;
    8.70 +    *a-- = '\0';
    8.71  
    8.72 -	do {
    8.73 -		*a-- = (i % 10) + '0';
    8.74 -		i /= 10;
    8.75 -	} while (i != 0);
    8.76 +    do {
    8.77 +        *a-- = (i % 10) + '0';
    8.78 +        i /= 10;
    8.79 +    } while ( i != 0 );
    8.80  
    8.81 -	return a + 1;
    8.82 +    return a + 1;
    8.83  }
    8.84  
    8.85  int strcmp(const char *cs, const char *ct)
    8.86  {
    8.87 -	signed char res;
    8.88 +    signed char res;
    8.89  
    8.90 -	while (((res = *cs - *ct++) == 0) && (*cs++ != '\0'))
    8.91 -		continue;
    8.92 +    while ( ((res = *cs - *ct++) == 0) && (*cs++ != '\0') )
    8.93 +        continue;
    8.94  
    8.95 -	return res;
    8.96 +    return res;
    8.97  }
    8.98  
    8.99  void *memcpy(void *dest, const void *src, unsigned n)
   8.100  {
   8.101 -	int t0, t1, t2;
   8.102 +    int t0, t1, t2;
   8.103  
   8.104 -	__asm__ __volatile__(
   8.105 -		"cld\n"
   8.106 -		"rep; movsl\n"
   8.107 -		"testb $2,%b4\n"
   8.108 -		"je 1f\n"
   8.109 -		"movsw\n"
   8.110 -		"1: testb $1,%b4\n"
   8.111 -		"je 2f\n"
   8.112 -		"movsb\n"
   8.113 -		"2:"
   8.114 -		: "=&c" (t0), "=&D" (t1), "=&S" (t2)
   8.115 -		: "0" (n/4), "q" (n), "1" ((long) dest), "2" ((long) src)
   8.116 -		: "memory"
   8.117 -	);
   8.118 -	return dest;
   8.119 +    __asm__ __volatile__ (
   8.120 +        "cld\n"
   8.121 +        "rep; movsl\n"
   8.122 +        "testb $2,%b4\n"
   8.123 +        "je 1f\n"
   8.124 +        "movsw\n"
   8.125 +        "1: testb $1,%b4\n"
   8.126 +        "je 2f\n"
   8.127 +        "movsb\n"
   8.128 +        "2:"
   8.129 +        : "=&c" (t0), "=&D" (t1), "=&S" (t2)
   8.130 +        : "0" (n/4), "q" (n), "1" ((long) dest), "2" ((long) src)
   8.131 +        : "memory" );
   8.132 +    return dest;
   8.133  }
   8.134  
   8.135  void *memmove(void *dest, const void *src, unsigned n)
   8.136  {
   8.137 -	if ((long)dest > (long)src) {
   8.138 -		n--;
   8.139 -		while (n > 0) {
   8.140 -			((char *)dest)[n] = ((char *)src)[n];
   8.141 -			n--;
   8.142 -		}
   8.143 -	} else {
   8.144 -		memcpy(dest, src, n);
   8.145 -	}
   8.146 -	return dest;
   8.147 -}
   8.148 -
   8.149 -
   8.150 -
   8.151 -
   8.152 -void puts(const char *s)
   8.153 -{
   8.154 -	while (*s)
   8.155 -		outb(0xE9, *s++);
   8.156 +    if ( (long)dest > (long)src )
   8.157 +    {
   8.158 +        n--;
   8.159 +        while ( n > 0 )
   8.160 +        {
   8.161 +            ((char *)dest)[n] = ((char *)src)[n];
   8.162 +            n--;
   8.163 +        }
   8.164 +    }
   8.165 +    else
   8.166 +    {
   8.167 +        memcpy(dest, src, n);
   8.168 +    }
   8.169 +    return dest;
   8.170  }
   8.171  
   8.172  char *
   8.173  strcpy(char *dest, const char *src)
   8.174  {
   8.175 -	char *p = dest;
   8.176 -	while (*src)
   8.177 -		*p++ = *src++;
   8.178 -	*p = 0;
   8.179 -	return dest;
   8.180 +    char *p = dest;
   8.181 +    while ( *src )
   8.182 +        *p++ = *src++;
   8.183 +    *p = 0;
   8.184 +    return dest;
   8.185  }
   8.186  
   8.187  char *
   8.188  strncpy(char *dest, const char *src, unsigned n)
   8.189  {
   8.190 -	int i = 0;
   8.191 -	char *p = dest;
   8.192 +    int i = 0;
   8.193 +    char *p = dest;
   8.194  
   8.195 -	/* write non-NUL characters from src into dest until we run
   8.196 -	   out of room in dest or encounter a NUL in src */
   8.197 -	while (i < n && *src) {
   8.198 -		*p++ = *src++;
   8.199 -		++i;
   8.200 -	}
   8.201 +    /* write non-NUL characters from src into dest until we run
   8.202 +       out of room in dest or encounter a NUL in src */
   8.203 +    while ( (i < n) && *src )
   8.204 +    {
   8.205 +        *p++ = *src++;
   8.206 +        i++;
   8.207 +    }
   8.208  
   8.209 -	/* pad remaining bytes of dest with NUL bytes */
   8.210 -	while (i < n) {
   8.211 -		*p++ = 0;
   8.212 -		++i;
   8.213 -	}
   8.214 +    /* pad remaining bytes of dest with NUL bytes */
   8.215 +    while ( i < n )
   8.216 +    {
   8.217 +        *p++ = 0;
   8.218 +        i++;
   8.219 +    }
   8.220  
   8.221 -	return dest;
   8.222 +    return dest;
   8.223  }
   8.224  
   8.225  unsigned
   8.226  strlen(const char *s)
   8.227  {
   8.228 -	int i = 0;
   8.229 -	while (*s++)
   8.230 -		++i;
   8.231 -	return i;
   8.232 +    int i = 0;
   8.233 +    while ( *s++ )
   8.234 +        i++;
   8.235 +    return i;
   8.236  }
   8.237  
   8.238  void *
   8.239  memset(void *s, int c, unsigned n)
   8.240  {
   8.241 -	uint8_t b = (uint8_t) c;
   8.242 -	uint8_t *p = (uint8_t *)s;
   8.243 -	int i;
   8.244 -	for (i = 0; i < n; ++i)
   8.245 -		*p++ = b;
   8.246 -	return s;
   8.247 +    uint8_t b = (uint8_t) c;
   8.248 +    uint8_t *p = (uint8_t *)s;
   8.249 +    int i;
   8.250 +    for ( i = 0; i < n; i++ )
   8.251 +        *p++ = b;
   8.252 +    return s;
   8.253  }
   8.254  
   8.255  int
   8.256  memcmp(const void *s1, const void *s2, unsigned n)
   8.257  {
   8.258 -	unsigned i;
   8.259 -	uint8_t *p1 = (uint8_t *) s1;
   8.260 -	uint8_t *p2 = (uint8_t *) s2;
   8.261 +    unsigned i;
   8.262 +    uint8_t *p1 = (uint8_t *) s1;
   8.263 +    uint8_t *p2 = (uint8_t *) s2;
   8.264  
   8.265 -	for (i = 0; i < n; ++i) {
   8.266 -		if (p1[i] < p2[i])
   8.267 -			return -1;
   8.268 -		else if (p1[i] > p2[i])
   8.269 -			return 1;
   8.270 -	}
   8.271 +    for ( i = 0; i < n; i++ )
   8.272 +    {
   8.273 +        if ( p1[i] < p2[i] )
   8.274 +            return -1;
   8.275 +        else if ( p1[i] > p2[i] )
   8.276 +            return 1;
   8.277 +    }
   8.278  
   8.279 -	return 0;
   8.280 +    return 0;
   8.281  }
   8.282  
   8.283  void
   8.284  cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
   8.285  {
   8.286 -	__asm__ __volatile__(
   8.287 -		"cpuid"
   8.288 -		: "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
   8.289 -		: "0" (idx) );
   8.290 +    __asm__ __volatile__ (
   8.291 +        "cpuid"
   8.292 +        : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
   8.293 +        : "0" (idx) );
   8.294  }
   8.295  
   8.296  /* Write a two-character hex representation of 'byte' to digits[].
   8.297 @@ -196,18 +214,18 @@ cpuid(uint32_t idx, uint32_t *eax, uint3
   8.298  void
   8.299  byte_to_hex(char *digits, uint8_t byte)
   8.300  {
   8.301 -	uint8_t nybbel = byte >> 4;
   8.302 +    uint8_t nybbel = byte >> 4;
   8.303  
   8.304 -	if (nybbel > 9)
   8.305 -		digits[0] = 'a' + nybbel-10;
   8.306 -	else
   8.307 -		digits[0] = '0' + nybbel;
   8.308 +    if ( nybbel > 9 )
   8.309 +        digits[0] = 'a' + nybbel-10;
   8.310 +    else
   8.311 +        digits[0] = '0' + nybbel;
   8.312  
   8.313 -	nybbel = byte & 0x0f;
   8.314 -	if (nybbel > 9)
   8.315 -		digits[1] = 'a' + nybbel-10;
   8.316 -	else
   8.317 -		digits[1] = '0' + nybbel;
   8.318 +    nybbel = byte & 0x0f;
   8.319 +    if ( nybbel > 9 )
   8.320 +        digits[1] = 'a' + nybbel-10;
   8.321 +    else
   8.322 +        digits[1] = '0' + nybbel;
   8.323  }
   8.324  
   8.325  /* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
   8.326 @@ -217,34 +235,39 @@ byte_to_hex(char *digits, uint8_t byte)
   8.327  void
   8.328  uuid_to_string(char *dest, uint8_t *uuid)
   8.329  {
   8.330 -	int i = 0;
   8.331 -	char *p = dest;
   8.332 +    int i = 0;
   8.333 +    char *p = dest;
   8.334  
   8.335 -	for (i = 0; i < 4; ++i) {
   8.336 -		byte_to_hex(p, uuid[i]);
   8.337 -		p += 2;
   8.338 -	}
   8.339 -	*p++ = '-';
   8.340 -	for (i = 4; i < 6; ++i) {
   8.341 -		byte_to_hex(p, uuid[i]);
   8.342 -		p += 2;
   8.343 -	}
   8.344 -	*p++ = '-';
   8.345 -	for (i = 6; i < 8; ++i) {
   8.346 -		byte_to_hex(p, uuid[i]);
   8.347 -		p += 2;
   8.348 -	}
   8.349 -	*p++ = '-';
   8.350 -	for (i = 8; i < 10; ++i) {
   8.351 -		byte_to_hex(p, uuid[i]);
   8.352 -		p += 2;
   8.353 -	}
   8.354 -	*p++ = '-';
   8.355 -	for (i = 10; i < 16; ++i) {
   8.356 -		byte_to_hex(p, uuid[i]);
   8.357 -		p += 2;
   8.358 -	}
   8.359 -	*p = 0;
   8.360 +    for ( i = 0; i < 4; i++ )
   8.361 +    {
   8.362 +        byte_to_hex(p, uuid[i]);
   8.363 +        p += 2;
   8.364 +    }
   8.365 +    *p++ = '-';
   8.366 +    for ( i = 4; i < 6; i++ )
   8.367 +    {
   8.368 +        byte_to_hex(p, uuid[i]);
   8.369 +        p += 2;
   8.370 +    }
   8.371 +    *p++ = '-';
   8.372 +    for ( i = 6; i < 8; i++ )
   8.373 +    {
   8.374 +        byte_to_hex(p, uuid[i]);
   8.375 +        p += 2;
   8.376 +    }
   8.377 +    *p++ = '-';
   8.378 +    for ( i = 8; i < 10; i++ )
   8.379 +    {
   8.380 +        byte_to_hex(p, uuid[i]);
   8.381 +        p += 2;
   8.382 +    }
   8.383 +    *p++ = '-';
   8.384 +    for ( i = 10; i < 16; i++ )
   8.385 +    {
   8.386 +        byte_to_hex(p, uuid[i]);
   8.387 +        p += 2;
   8.388 +    }
   8.389 +    *p = '\0';
   8.390  }
   8.391  
   8.392  #include <xen/hvm/e820.h>
   8.393 @@ -252,31 +275,222 @@ uuid_to_string(char *dest, uint8_t *uuid
   8.394  #define E820_MAP    ((struct e820entry *)(E820_MAP_PAGE + E820_MAP_OFFSET))
   8.395  uint64_t e820_malloc(uint64_t size, uint32_t type, uint64_t mask)
   8.396  {
   8.397 -	uint64_t addr = 0;
   8.398 -	int c = *E820_MAP_NR - 1;
   8.399 -	struct e820entry *e820entry = (struct e820entry *)E820_MAP;
   8.400 +    uint64_t addr = 0;
   8.401 +    int c = *E820_MAP_NR - 1;
   8.402 +    struct e820entry *e820entry = (struct e820entry *)E820_MAP;
   8.403 +
   8.404 +    while ( c >= 0 )
   8.405 +    {
   8.406 +        if ( (e820entry[c].type  == E820_RAM) &&
   8.407 +             ((e820entry[c].addr & (~mask)) == 0) &&
   8.408 +             (e820entry[c].size >= size) )
   8.409 +        {
   8.410 +            addr = e820entry[c].addr;
   8.411 +            if ( e820entry[c].size != size )
   8.412 +            {
   8.413 +                (*E820_MAP_NR)++;
   8.414 +                memmove(&e820entry[c+1],
   8.415 +                        &e820entry[c],
   8.416 +                        (*E820_MAP_NR - c) *
   8.417 +                        sizeof(struct e820entry));
   8.418 +                e820entry[c].size -= size;
   8.419 +                addr += e820entry[c].size;
   8.420 +                c++;
   8.421 +            }
   8.422 +            e820entry[c].addr = addr;
   8.423 +            e820entry[c].size = size;
   8.424 +            e820entry[c].type = type;
   8.425 +            break;
   8.426 +        }
   8.427 +        c--;
   8.428 +    }
   8.429 +    return addr;
   8.430 +}
   8.431 +
   8.432 +uint32_t ioapic_read(uint32_t reg)
   8.433 +{
   8.434 +    uint32_t *ioregsel = (uint32_t *)(IOAPIC_BASE_ADDRESS + 0x00);
   8.435 +    uint32_t *iowin    = (uint32_t *)(IOAPIC_BASE_ADDRESS + 0x10);
   8.436 +
   8.437 +    *ioregsel = reg;
   8.438 +    mb();
   8.439 +    return *iowin;
   8.440 +}
   8.441 +
   8.442 +void ioapic_write(uint32_t reg, uint32_t val)
   8.443 +{
   8.444 +    uint32_t *ioregsel = (uint32_t *)(IOAPIC_BASE_ADDRESS + 0x00);
   8.445 +    uint32_t *iowin    = (uint32_t *)(IOAPIC_BASE_ADDRESS + 0x10);
   8.446 +
   8.447 +    *ioregsel = reg;
   8.448 +    wmb();
   8.449 +    *iowin = val;
   8.450 +}
   8.451 +
   8.452 +#define PCI_CONF1_ADDRESS(bus, devfn, reg) \
   8.453 +    (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
   8.454 +
   8.455 +uint32_t pci_read(uint32_t devfn, uint32_t reg, uint32_t len)
   8.456 +{
   8.457 +    outl(0xcf8, PCI_CONF1_ADDRESS(0, devfn, reg));
   8.458 +
   8.459 +    switch ( len )
   8.460 +    {
   8.461 +    case 1: return inb(0xcfc + (reg & 3));
   8.462 +    case 2: return inw(0xcfc + (reg & 2));
   8.463 +    }
   8.464 +
   8.465 +    return inl(0xcfc);
   8.466 +}
   8.467 +
   8.468 +void pci_write(uint32_t devfn, uint32_t reg, uint32_t len, uint32_t val)
   8.469 +{
   8.470 +    outl(0xcf8, PCI_CONF1_ADDRESS(0, devfn, reg));
   8.471 +
   8.472 +    switch ( len )
   8.473 +    {
   8.474 +    case 1: outb(0xcfc + (reg & 3), val); break;
   8.475 +    case 2: outw(0xcfc + (reg & 2), val); break;
   8.476 +    case 4: outl(0xcfc,             val); break;
   8.477 +    }
   8.478 +}
   8.479 +
   8.480 +static char *printnum(char *p, unsigned long num, int base)
   8.481 +{
   8.482 +    unsigned long n;
   8.483 +
   8.484 +    if ( (n = num/base) > 0 )
   8.485 +        p = printnum(p, n, base);
   8.486 +    *p++ = "0123456789abcdef"[(int)(num % base)];
   8.487 +    *p = '\0';
   8.488 +    return p;
   8.489 +}
   8.490 +
   8.491 +static void _doprint(void (*put)(char), char const *fmt, va_list ap)
   8.492 +{
   8.493 +    register char *str, c;
   8.494 +    int lflag, zflag, nflag;
   8.495 +    char buffer[17];
   8.496 +    unsigned value;
   8.497 +    int i, slen, pad;
   8.498 +
   8.499 +    for ( ; *fmt != '\0'; fmt++ )
   8.500 +    {
   8.501 +        if ( *fmt != '%' )
   8.502 +        {
   8.503 +            put(*fmt);
   8.504 +            continue;
   8.505 +        }
   8.506  
   8.507 -	while (c >= 0) {
   8.508 -		if (e820entry[c].type  == E820_RAM     &&
   8.509 -		    (e820entry[c].addr & (~mask)) == 0 &&
   8.510 -		    e820entry[c].size >= size) {
   8.511 -			addr = e820entry[c].addr;
   8.512 -			if (e820entry[c].size != size) {
   8.513 -				(*E820_MAP_NR)++;
   8.514 -				memmove(&e820entry[c+1],
   8.515 -				        &e820entry[c],
   8.516 -				        (*E820_MAP_NR - c) *
   8.517 -				            sizeof(struct e820entry));
   8.518 -				e820entry[c].size -= size;
   8.519 -				addr += e820entry[c].size;
   8.520 -				c++;
   8.521 -			}
   8.522 -			e820entry[c].addr = addr;
   8.523 -			e820entry[c].size = size;
   8.524 -			e820entry[c].type = type;
   8.525 -			break;
   8.526 -		}
   8.527 -		c--;
   8.528 -	}
   8.529 -        return addr;
   8.530 +        pad = zflag = nflag = lflag = 0;
   8.531 +        c = *++fmt;
   8.532 +        if ( (c == '-') || isdigit(c) )
   8.533 +        {
   8.534 +            if ( c == '-' )
   8.535 +            {
   8.536 +                nflag = 1;
   8.537 +                c = *++fmt;
   8.538 +            }
   8.539 +            zflag = c == '0';
   8.540 +            for ( pad = 0; isdigit(c); c = *++fmt )
   8.541 +                pad = (pad * 10) + c - '0';
   8.542 +        }
   8.543 +        if ( c == 'l' ) /* long extension */
   8.544 +        {
   8.545 +            lflag = 1;
   8.546 +            c = *++fmt;
   8.547 +        }
   8.548 +        if ( (c == 'd') || (c == 'u') || (c == 'o') || (c == 'x') )
   8.549 +        {
   8.550 +            if ( lflag )
   8.551 +                value = va_arg(ap, unsigned);
   8.552 +            else
   8.553 +                value = (unsigned) va_arg(ap, unsigned int);
   8.554 +            str = buffer;
   8.555 +            printnum(str, value,
   8.556 +                     c == 'o' ? 8 : (c == 'x' ? 16 : 10));
   8.557 +            goto printn;
   8.558 +        }
   8.559 +        else if ( (c == 'O') || (c == 'D') || (c == 'X') )
   8.560 +        {
   8.561 +            value = va_arg(ap, unsigned);
   8.562 +            str = buffer;
   8.563 +            printnum(str, value,
   8.564 +                     c == 'O' ? 8 : (c == 'X' ? 16 : 10));
   8.565 +        printn:
   8.566 +            slen = strlen(str);
   8.567 +            for ( i = pad - slen; i > 0; i-- )
   8.568 +                put(zflag ? '0' : ' ');
   8.569 +            while ( *str )
   8.570 +                put(*str++);
   8.571 +        }
   8.572 +        else if ( c == 's' )
   8.573 +        {
   8.574 +            str = va_arg(ap, char *);
   8.575 +            slen = strlen(str);
   8.576 +            if ( nflag == 0 )
   8.577 +                for ( i = pad - slen; i > 0; i-- )
   8.578 +                    put(' ');
   8.579 +            while ( *str )
   8.580 +                put(*str++);
   8.581 +            if ( nflag )
   8.582 +                for ( i = pad - slen; i > 0; i-- )
   8.583 +                    put(' ');
   8.584 +        }
   8.585 +        else if ( c == 'c' )
   8.586 +        {
   8.587 +            put(va_arg(ap, int));
   8.588 +        }
   8.589 +        else
   8.590 +        {
   8.591 +            put(*fmt);
   8.592 +        }
   8.593 +    }
   8.594  }
   8.595 +
   8.596 +static void putchar(char c)
   8.597 +{
   8.598 +    outb(0xe9, c);
   8.599 +}
   8.600 +
   8.601 +int printf(const char *fmt, ...)
   8.602 +{
   8.603 +    va_list ap;
   8.604 +
   8.605 +    va_start(ap, fmt);
   8.606 +    _doprint(putchar, fmt, ap);
   8.607 +    va_end(ap);
   8.608 +
   8.609 +    return 0;
   8.610 +}
   8.611 +
   8.612 +int vprintf(const char *fmt, va_list ap)
   8.613 +{
   8.614 +    _doprint(putchar, fmt, ap);
   8.615 +    return 0;
   8.616 +}
   8.617 +
   8.618 +void __assert_failed(char *assertion, char *file, int line)
   8.619 +{
   8.620 +    printf("HVMLoader assertion '%s' failed at %s:%d\n",
   8.621 +           assertion, file, line);
   8.622 +    for ( ; ; )
   8.623 +        __asm__ __volatile__ ( "ud2" );
   8.624 +}
   8.625 +
   8.626 +void __bug(char *file, int line)
   8.627 +{
   8.628 +    printf("HVMLoader bug at %s:%d\n", file, line);
   8.629 +    for ( ; ; )
   8.630 +        __asm__ __volatile__ ( "ud2" );
   8.631 +}
   8.632 +
   8.633 +/*
   8.634 + * Local variables:
   8.635 + * mode: C
   8.636 + * c-set-style: "BSD"
   8.637 + * c-basic-offset: 4
   8.638 + * tab-width: 4
   8.639 + * indent-tabs-mode: nil
   8.640 + * End:
   8.641 + */
     9.1 --- a/tools/firmware/hvmloader/util.h	Wed Nov 22 09:52:48 2006 -0700
     9.2 +++ b/tools/firmware/hvmloader/util.h	Wed Nov 22 17:50:20 2006 +0000
     9.3 @@ -1,12 +1,34 @@
     9.4  #ifndef __HVMLOADER_UTIL_H__
     9.5  #define __HVMLOADER_UTIL_H__
     9.6  
     9.7 +#include <stdarg.h>
     9.8 +
     9.9 +extern void __assert_failed(char *assertion, char *file, int line)
    9.10 +    __attribute__((noreturn));
    9.11 +#define ASSERT(p) \
    9.12 +    do { if (!(p)) __assert_failed(#p, __FILE__, __LINE__); } while (0)
    9.13 +extern void __bug(char *file, int line) __attribute__((noreturn));
    9.14 +#define BUG() __bug()
    9.15 +
    9.16  /* I/O output */
    9.17 +void outb(uint16_t addr, uint8_t  val);
    9.18  void outw(uint16_t addr, uint16_t val);
    9.19 -void outb(uint16_t addr, uint8_t val);
    9.20 +void outl(uint16_t addr, uint32_t val);
    9.21  
    9.22  /* I/O input */
    9.23 -uint8_t inb(uint16_t addr);
    9.24 +uint8_t  inb(uint16_t addr);
    9.25 +uint16_t inw(uint16_t addr);
    9.26 +uint32_t inl(uint16_t addr);
    9.27 +
    9.28 +/* PCI access */
    9.29 +uint32_t pci_read(uint32_t devfn, uint32_t reg, uint32_t len);
    9.30 +#define pci_readb(devfn, reg) ((uint8_t) pci_read(devfn, reg, 1))
    9.31 +#define pci_readw(devfn, reg) ((uint16_t)pci_read(devfn, reg, 2))
    9.32 +#define pci_readl(devfn, reg) ((uint32_t)pci_read(devfn, reg, 4))
    9.33 +void pci_write(uint32_t devfn, uint32_t reg, uint32_t len, uint32_t val);
    9.34 +#define pci_writeb(devfn, reg, val) (pci_write(devfn, reg, 1, (uint8_t) val))
    9.35 +#define pci_writew(devfn, reg, val) (pci_write(devfn, reg, 2, (uint16_t)val))
    9.36 +#define pci_writel(devfn, reg, val) (pci_write(devfn, reg, 4, (uint32_t)val))
    9.37  
    9.38  /* Do cpuid instruction, with operation 'idx' */
    9.39  void cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx,
    9.40 @@ -31,15 +53,16 @@ char *itoa(char *a, unsigned int i);
    9.41  void byte_to_hex(char *digits, uint8_t byte);
    9.42  
    9.43  /* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
    9.44 -   string.
    9.45 -
    9.46 -   Pre-condition: sizeof(dest) >= 37 */
    9.47 +   string. Pre-condition: sizeof(dest) >= 37 */
    9.48  void uuid_to_string(char *dest, uint8_t *uuid);
    9.49  
    9.50  /* Debug output */
    9.51 -void puts(const char *s);
    9.52 +int printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
    9.53 +int vprintf(const char *fmt, va_list ap);
    9.54  
    9.55  /* Allocate region of specified type in the e820 table. */
    9.56  uint64_t e820_malloc(uint64_t size, uint32_t type, uint64_t mask);
    9.57  
    9.58 +#define isdigit(c) ((c) >= '0' && (c) <= '9')
    9.59 +
    9.60  #endif /* __HVMLOADER_UTIL_H__ */
    10.1 --- a/tools/firmware/rombios/rombios.c	Wed Nov 22 09:52:48 2006 -0700
    10.2 +++ b/tools/firmware/rombios/rombios.c	Wed Nov 22 17:50:20 2006 +0000
    10.3 @@ -9104,78 +9104,78 @@ pci_routing_table_structure:
    10.4    db 0 ;; pci bus number
    10.5    db 0x08 ;; pci device number (bit 7-3)
    10.6    db 0x61 ;; link value INTA#: pointer into PCI2ISA config space
    10.7 -  dw 0xdef8 ;; IRQ bitmap INTA# 
    10.8 +  dw 0x0c60 ;; IRQ bitmap INTA# 
    10.9    db 0x62 ;; link value INTB#
   10.10 -  dw 0xdef8 ;; IRQ bitmap INTB# 
   10.11 +  dw 0x0c60 ;; IRQ bitmap INTB# 
   10.12    db 0x63 ;; link value INTC#
   10.13 -  dw 0xdef8 ;; IRQ bitmap INTC# 
   10.14 +  dw 0x0c60 ;; IRQ bitmap INTC# 
   10.15    db 0x60 ;; link value INTD#
   10.16 -  dw 0xdef8 ;; IRQ bitmap INTD#
   10.17 +  dw 0x0c60 ;; IRQ bitmap INTD#
   10.18    db 0 ;; physical slot (0 = embedded)
   10.19    db 0 ;; reserved
   10.20    ;; second slot entry: 1st PCI slot
   10.21    db 0 ;; pci bus number
   10.22    db 0x10 ;; pci device number (bit 7-3)
   10.23    db 0x62 ;; link value INTA#
   10.24 -  dw 0xdef8 ;; IRQ bitmap INTA# 
   10.25 +  dw 0x0c60 ;; IRQ bitmap INTA# 
   10.26    db 0x63 ;; link value INTB#
   10.27 -  dw 0xdef8 ;; IRQ bitmap INTB# 
   10.28 +  dw 0x0c60 ;; IRQ bitmap INTB# 
   10.29    db 0x60 ;; link value INTC#
   10.30 -  dw 0xdef8 ;; IRQ bitmap INTC# 
   10.31 +  dw 0x0c60 ;; IRQ bitmap INTC# 
   10.32    db 0x61 ;; link value INTD#
   10.33 -  dw 0xdef8 ;; IRQ bitmap INTD#
   10.34 +  dw 0x0c60 ;; IRQ bitmap INTD#
   10.35    db 1 ;; physical slot (0 = embedded)
   10.36    db 0 ;; reserved
   10.37    ;; third slot entry: 2nd PCI slot
   10.38    db 0 ;; pci bus number
   10.39    db 0x18 ;; pci device number (bit 7-3)
   10.40    db 0x63 ;; link value INTA#
   10.41 -  dw 0xdef8 ;; IRQ bitmap INTA# 
   10.42 +  dw 0x0c60 ;; IRQ bitmap INTA# 
   10.43    db 0x60 ;; link value INTB#
   10.44 -  dw 0xdef8 ;; IRQ bitmap INTB# 
   10.45 +  dw 0x0c60 ;; IRQ bitmap INTB# 
   10.46    db 0x61 ;; link value INTC#
   10.47 -  dw 0xdef8 ;; IRQ bitmap INTC# 
   10.48 +  dw 0x0c60 ;; IRQ bitmap INTC# 
   10.49    db 0x62 ;; link value INTD#
   10.50 -  dw 0xdef8 ;; IRQ bitmap INTD#
   10.51 +  dw 0x0c60 ;; IRQ bitmap INTD#
   10.52    db 2 ;; physical slot (0 = embedded)
   10.53    db 0 ;; reserved
   10.54    ;; 4th slot entry: 3rd PCI slot
   10.55    db 0 ;; pci bus number
   10.56    db 0x20 ;; pci device number (bit 7-3)
   10.57    db 0x60 ;; link value INTA#
   10.58 -  dw 0xdef8 ;; IRQ bitmap INTA# 
   10.59 +  dw 0x0c60 ;; IRQ bitmap INTA# 
   10.60    db 0x61 ;; link value INTB#
   10.61 -  dw 0xdef8 ;; IRQ bitmap INTB# 
   10.62 +  dw 0x0c60 ;; IRQ bitmap INTB# 
   10.63    db 0x62 ;; link value INTC#
   10.64 -  dw 0xdef8 ;; IRQ bitmap INTC# 
   10.65 +  dw 0x0c60 ;; IRQ bitmap INTC# 
   10.66    db 0x63 ;; link value INTD#
   10.67 -  dw 0xdef8 ;; IRQ bitmap INTD#
   10.68 +  dw 0x0c60 ;; IRQ bitmap INTD#
   10.69    db 3 ;; physical slot (0 = embedded)
   10.70    db 0 ;; reserved
   10.71    ;; 5th slot entry: 4rd PCI slot
   10.72    db 0 ;; pci bus number
   10.73    db 0x28 ;; pci device number (bit 7-3)
   10.74    db 0x61 ;; link value INTA#
   10.75 -  dw 0xdef8 ;; IRQ bitmap INTA# 
   10.76 +  dw 0x0c60 ;; IRQ bitmap INTA# 
   10.77    db 0x62 ;; link value INTB#
   10.78 -  dw 0xdef8 ;; IRQ bitmap INTB# 
   10.79 +  dw 0x0c60 ;; IRQ bitmap INTB# 
   10.80    db 0x63 ;; link value INTC#
   10.81 -  dw 0xdef8 ;; IRQ bitmap INTC# 
   10.82 +  dw 0x0c60 ;; IRQ bitmap INTC# 
   10.83    db 0x60 ;; link value INTD#
   10.84 -  dw 0xdef8 ;; IRQ bitmap INTD#
   10.85 +  dw 0x0c60 ;; IRQ bitmap INTD#
   10.86    db 4 ;; physical slot (0 = embedded)
   10.87    db 0 ;; reserved
   10.88    ;; 6th slot entry: 5rd PCI slot
   10.89    db 0 ;; pci bus number
   10.90    db 0x30 ;; pci device number (bit 7-3)
   10.91    db 0x62 ;; link value INTA#
   10.92 -  dw 0xdef8 ;; IRQ bitmap INTA# 
   10.93 +  dw 0x0c60 ;; IRQ bitmap INTA# 
   10.94    db 0x63 ;; link value INTB#
   10.95 -  dw 0xdef8 ;; IRQ bitmap INTB# 
   10.96 +  dw 0x0c60 ;; IRQ bitmap INTB# 
   10.97    db 0x60 ;; link value INTC#
   10.98 -  dw 0xdef8 ;; IRQ bitmap INTC# 
   10.99 +  dw 0x0c60 ;; IRQ bitmap INTC# 
  10.100    db 0x61 ;; link value INTD#
  10.101 -  dw 0xdef8 ;; IRQ bitmap INTD#
  10.102 +  dw 0x0c60 ;; IRQ bitmap INTD#
  10.103    db 5 ;; physical slot (0 = embedded)
  10.104    db 0 ;; reserved
  10.105  
    11.1 --- a/tools/ioemu/target-i386-dm/piix_pci-dm.c	Wed Nov 22 09:52:48 2006 -0700
    11.2 +++ b/tools/ioemu/target-i386-dm/piix_pci-dm.c	Wed Nov 22 17:50:20 2006 +0000
    11.3 @@ -84,12 +84,6 @@ PCIBus *i440fx_init(void)
    11.4  
    11.5  static PCIDevice *piix3_dev;
    11.6  
    11.7 -static int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
    11.8 -{
    11.9 -    /* This is the barber's pole mapping used by Xen. */
   11.10 -    return (irq_num + (pci_dev->devfn >> 3)) & 3;
   11.11 -}
   11.12 -
   11.13  static void piix3_write_config(PCIDevice *d, 
   11.14                                 uint32_t address, uint32_t val, int len)
   11.15  {
   11.16 @@ -114,12 +108,9 @@ static void piix3_reset(PCIDevice *d)
   11.17      uint8_t *pci_conf = d->config;
   11.18  
   11.19      pci_conf[0x04] = 0x07; // master, memory and I/O
   11.20 -    pci_conf[0x05] = 0x00;
   11.21 -    pci_conf[0x06] = 0x00;
   11.22      pci_conf[0x07] = 0x02; // PCI_status_devsel_medium
   11.23      pci_conf[0x4c] = 0x4d;
   11.24      pci_conf[0x4e] = 0x03;
   11.25 -    pci_conf[0x4f] = 0x00;
   11.26      pci_conf[0x60] = 0x80;
   11.27      pci_conf[0x61] = 0x80;
   11.28      pci_conf[0x62] = 0x80;
   11.29 @@ -129,22 +120,9 @@ static void piix3_reset(PCIDevice *d)
   11.30      pci_conf[0x76] = 0x0c;
   11.31      pci_conf[0x77] = 0x0c;
   11.32      pci_conf[0x78] = 0x02;
   11.33 -    pci_conf[0x79] = 0x00;
   11.34 -    pci_conf[0x80] = 0x00;
   11.35 -    pci_conf[0x82] = 0x00;
   11.36      pci_conf[0xa0] = 0x08;
   11.37      pci_conf[0xa0] = 0x08;
   11.38 -    pci_conf[0xa2] = 0x00;
   11.39 -    pci_conf[0xa3] = 0x00;
   11.40 -    pci_conf[0xa4] = 0x00;
   11.41 -    pci_conf[0xa5] = 0x00;
   11.42 -    pci_conf[0xa6] = 0x00;
   11.43 -    pci_conf[0xa7] = 0x00;
   11.44      pci_conf[0xa8] = 0x0f;
   11.45 -    pci_conf[0xaa] = 0x00;
   11.46 -    pci_conf[0xab] = 0x00;
   11.47 -    pci_conf[0xac] = 0x00;
   11.48 -    pci_conf[0xae] = 0x00;
   11.49  }
   11.50  
   11.51  int piix3_init(PCIBus *bus)
   11.52 @@ -171,227 +149,4 @@ int piix3_init(PCIBus *bus)
   11.53      return d->devfn;
   11.54  }
   11.55  
   11.56 -/***********************************************************/
   11.57 -/* XXX: the following should be moved to the PC BIOS */
   11.58 -
   11.59 -static __attribute__((unused)) uint32_t isa_inb(uint32_t addr)
   11.60 -{
   11.61 -    return cpu_inb(NULL, addr);
   11.62 -}
   11.63 -
   11.64 -static void isa_outb(uint32_t val, uint32_t addr)
   11.65 -{
   11.66 -    cpu_outb(NULL, addr, val);
   11.67 -}
   11.68 -
   11.69 -static __attribute__((unused)) uint32_t isa_inw(uint32_t addr)
   11.70 -{
   11.71 -    return cpu_inw(NULL, addr);
   11.72 -}
   11.73 -
   11.74 -static __attribute__((unused)) void isa_outw(uint32_t val, uint32_t addr)
   11.75 -{
   11.76 -    cpu_outw(NULL, addr, val);
   11.77 -}
   11.78 -
   11.79 -static __attribute__((unused)) uint32_t isa_inl(uint32_t addr)
   11.80 -{
   11.81 -    return cpu_inl(NULL, addr);
   11.82 -}
   11.83 -
   11.84 -static __attribute__((unused)) void isa_outl(uint32_t val, uint32_t addr)
   11.85 -{
   11.86 -    cpu_outl(NULL, addr, val);
   11.87 -}
   11.88 -
   11.89 -static uint32_t pci_bios_io_addr;
   11.90 -static uint32_t pci_bios_mem_addr;
   11.91 -/* host irqs corresponding to PCI irqs A-D */
   11.92 -static uint8_t pci_irqs[4] = { 10, 11, 10, 11 };
   11.93 -
   11.94 -static void pci_config_writel(PCIDevice *d, uint32_t addr, uint32_t val)
   11.95 -{
   11.96 -    PCIBus *s = d->bus;
   11.97 -    addr |= (pci_bus_num(s) << 16) | (d->devfn << 8);
   11.98 -    pci_data_write(s, addr, val, 4);
   11.99 -}
  11.100 -
  11.101 -static void pci_config_writew(PCIDevice *d, uint32_t addr, uint32_t val)
  11.102 -{
  11.103 -    PCIBus *s = d->bus;
  11.104 -    addr |= (pci_bus_num(s) << 16) | (d->devfn << 8);
  11.105 -    pci_data_write(s, addr, val, 2);
  11.106 -}
  11.107 -
  11.108 -static void pci_config_writeb(PCIDevice *d, uint32_t addr, uint32_t val)
  11.109 -{
  11.110 -    PCIBus *s = d->bus;
  11.111 -    addr |= (pci_bus_num(s) << 16) | (d->devfn << 8);
  11.112 -    pci_data_write(s, addr, val, 1);
  11.113 -}
  11.114 -
  11.115 -static __attribute__((unused)) uint32_t pci_config_readl(PCIDevice *d, uint32_t addr)
  11.116 -{
  11.117 -    PCIBus *s = d->bus;
  11.118 -    addr |= (pci_bus_num(s) << 16) | (d->devfn << 8);
  11.119 -    return pci_data_read(s, addr, 4);
  11.120 -}
  11.121 -
  11.122 -static uint32_t pci_config_readw(PCIDevice *d, uint32_t addr)
  11.123 -{
  11.124 -    PCIBus *s = d->bus;
  11.125 -    addr |= (pci_bus_num(s) << 16) | (d->devfn << 8);
  11.126 -    return pci_data_read(s, addr, 2);
  11.127 -}
  11.128 -
  11.129 -static uint32_t pci_config_readb(PCIDevice *d, uint32_t addr)
  11.130 -{
  11.131 -    PCIBus *s = d->bus;
  11.132 -    addr |= (pci_bus_num(s) << 16) | (d->devfn << 8);
  11.133 -    return pci_data_read(s, addr, 1);
  11.134 -}
  11.135 -
  11.136 -static void pci_set_io_region_addr(PCIDevice *d, int region_num, uint32_t addr)
  11.137 -{
  11.138 -    PCIIORegion *r;
  11.139 -    uint16_t cmd;
  11.140 -    uint32_t ofs;
  11.141 -
  11.142 -    if ( region_num == PCI_ROM_SLOT ) {
  11.143 -        ofs = 0x30;
  11.144 -    }else{
  11.145 -        ofs = 0x10 + region_num * 4;
  11.146 -    }
  11.147 -
  11.148 -    pci_config_writel(d, ofs, addr);
  11.149 -    r = &d->io_regions[region_num];
  11.150 -
  11.151 -    /* enable memory mappings */
  11.152 -    cmd = pci_config_readw(d, PCI_COMMAND);
  11.153 -    if ( region_num == PCI_ROM_SLOT )
  11.154 -        cmd |= 2;
  11.155 -    else if (r->type & PCI_ADDRESS_SPACE_IO)
  11.156 -        cmd |= 1;
  11.157 -    else
  11.158 -        cmd |= 2;
  11.159 -    pci_config_writew(d, PCI_COMMAND, cmd);
  11.160 -}
  11.161 -
  11.162 -static void pci_bios_init_device(PCIDevice *d)
  11.163 -{
  11.164 -    int class;
  11.165 -    PCIIORegion *r;
  11.166 -    uint32_t *paddr;
  11.167 -    int i, pin, pic_irq, vendor_id, device_id;
  11.168 -
  11.169 -    class = pci_config_readw(d, PCI_CLASS_DEVICE);
  11.170 -    vendor_id = pci_config_readw(d, PCI_VENDOR_ID);
  11.171 -    device_id = pci_config_readw(d, PCI_DEVICE_ID);
  11.172 -    switch(class) {
  11.173 -    case 0x0101:
  11.174 -        if (vendor_id == 0x8086 && device_id == 0x7010) {
  11.175 -            /* PIIX3 IDE */
  11.176 -            pci_config_writew(d, 0x40, 0x8000); // enable IDE0
  11.177 -            pci_config_writew(d, 0x42, 0x8000); // enable IDE1
  11.178 -            goto default_map;
  11.179 -        } else {
  11.180 -            /* IDE: we map it as in ISA mode */
  11.181 -            pci_set_io_region_addr(d, 0, 0x1f0);
  11.182 -            pci_set_io_region_addr(d, 1, 0x3f4);
  11.183 -            pci_set_io_region_addr(d, 2, 0x170);
  11.184 -            pci_set_io_region_addr(d, 3, 0x374);
  11.185 -        }
  11.186 -        break;
  11.187 -    case 0x0680:
  11.188 -        if (vendor_id == 0x8086 && device_id == 0x7113) {
  11.189 -            /*
  11.190 -             * PIIX4 ACPI PM.
  11.191 -             * Special device with special PCI config space. No ordinary BARs.
  11.192 -             */
  11.193 -            pci_config_writew(d, 0x20, 0x0000); // No smb bus IO enable
  11.194 -            pci_config_writew(d, 0x22, 0x0000);
  11.195 -            pci_config_writew(d, 0x3c, 0x0009); // Hardcoded IRQ9
  11.196 -            pci_config_writew(d, 0x3d, 0x0001);
  11.197 -        }
  11.198 -        break;
  11.199 -    case 0x0300:
  11.200 -        if (vendor_id != 0x1234)
  11.201 -            goto default_map;
  11.202 -        /* VGA: map frame buffer to default Bochs VBE address */
  11.203 -        pci_set_io_region_addr(d, 0, 0xE0000000);
  11.204 -        break;
  11.205 -    case 0x0800:
  11.206 -        /* PIC */
  11.207 -        vendor_id = pci_config_readw(d, PCI_VENDOR_ID);
  11.208 -        device_id = pci_config_readw(d, PCI_DEVICE_ID);
  11.209 -        if (vendor_id == 0x1014) {
  11.210 -            /* IBM */
  11.211 -            if (device_id == 0x0046 || device_id == 0xFFFF) {
  11.212 -                /* MPIC & MPIC2 */
  11.213 -                pci_set_io_region_addr(d, 0, 0x80800000 + 0x00040000);
  11.214 -            }
  11.215 -        }
  11.216 -        break;
  11.217 -    case 0xff00:
  11.218 -        if (vendor_id == 0x0106b &&
  11.219 -            (device_id == 0x0017 || device_id == 0x0022)) {
  11.220 -            /* macio bridge */
  11.221 -            pci_set_io_region_addr(d, 0, 0x80800000);
  11.222 -        }
  11.223 -        break;
  11.224 -    default:
  11.225 -    default_map:
  11.226 -        /* default memory mappings */
  11.227 -        for(i = 0; i < PCI_NUM_REGIONS; i++) {
  11.228 -            r = &d->io_regions[i];
  11.229 -            if (r->size) {
  11.230 -                if (r->type & PCI_ADDRESS_SPACE_IO)
  11.231 -                    paddr = &pci_bios_io_addr;
  11.232 -                else
  11.233 -                    paddr = &pci_bios_mem_addr;
  11.234 -                *paddr = (*paddr + r->size - 1) & ~(r->size - 1);
  11.235 -                pci_set_io_region_addr(d, i, *paddr);
  11.236 -                *paddr += r->size;
  11.237 -            }
  11.238 -        }
  11.239 -        break;
  11.240 -    }
  11.241 -
  11.242 -    /* map the interrupt */
  11.243 -    pin = pci_config_readb(d, PCI_INTERRUPT_PIN);
  11.244 -    if (pin != 0) {
  11.245 -        pin = pci_slot_get_pirq(d, pin - 1);
  11.246 -        pic_irq = pci_irqs[pin];
  11.247 -        pci_config_writeb(d, PCI_INTERRUPT_LINE, pic_irq);
  11.248 -    }
  11.249 -}
  11.250 -
  11.251 -/*
  11.252 - * This function initializes the PCI devices as a normal PCI BIOS
  11.253 - * would do. It is provided just in case the BIOS has no support for
  11.254 - * PCI.
  11.255 - */
  11.256 -void pci_bios_init(void)
  11.257 -{
  11.258 -    int i, irq;
  11.259 -    uint8_t elcr[2];
  11.260 -
  11.261 -    pci_bios_io_addr = 0xc000;
  11.262 -    pci_bios_mem_addr = HVM_BELOW_4G_MMIO_START;
  11.263 -
  11.264 -    /* activate IRQ mappings */
  11.265 -    elcr[0] = 0x00;
  11.266 -    elcr[1] = 0x00;
  11.267 -    for(i = 0; i < 4; i++) {
  11.268 -        irq = pci_irqs[i];
  11.269 -        /* set to trigger level */
  11.270 -        elcr[irq >> 3] |= (1 << (irq & 7));
  11.271 -        /* activate irq remapping in PIIX */
  11.272 -        pci_config_writeb(piix3_dev, 0x60 + i, irq);
  11.273 -    }
  11.274 -    isa_outb(elcr[0], 0x4d0);
  11.275 -    isa_outb(elcr[1], 0x4d1);
  11.276 -
  11.277 -    pci_for_each_device(pci_bios_init_device);
  11.278 -}
  11.279 -
  11.280 +void pci_bios_init(void) {}