direct-io.hg

changeset 12523: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 -
    7.50 -	cpuid(0, &eax, (uint32_t *)&id[0], (uint32_t *)&id[8],
    7.51 -	      (uint32_t *)&id[4]);
    7.52 +    char id[12];
    7.53 +    uint32_t eax = 0;
    7.54  
    7.55 -	if (memcmp(id, "GenuineIntel", 12) == 0)
    7.56 -		strncpy(buf, "Intel", len);
    7.57 -	else if (memcmp(id, "AuthenticAMD", 12) == 0)
    7.58 -		strncpy(buf, "AMD", len);
    7.59 -	else
    7.60 -		strncpy(buf, "unknown", len);
    7.61 +    cpuid(0, &eax, (uint32_t *)&id[0], (uint32_t *)&id[8],
    7.62 +          (uint32_t *)&id[4]);
    7.63 +
    7.64 +    if (memcmp(id, "GenuineIntel", 12) == 0)
    7.65 +        strncpy(buf, "Intel", len);
    7.66 +    else if (memcmp(id, "AuthenticAMD", 12) == 0)
    7.67 +        strncpy(buf, "AMD", len);
    7.68 +    else
    7.69 +        strncpy(buf, "unknown", len);
    7.70  }
    7.71  
    7.72  static size_t
    7.73  write_smbios_tables(void *start,
    7.74 -		    uint32_t vcpus, uint64_t memsize,
    7.75 -		    uint8_t uuid[16], char *xen_version,
    7.76 -		    uint32_t xen_major_version, uint32_t xen_minor_version)
    7.77 +                    uint32_t vcpus, uint64_t memsize,
    7.78 +                    uint8_t uuid[16], char *xen_version,
    7.79 +                    uint32_t xen_major_version, uint32_t xen_minor_version)
    7.80  {
    7.81 -	unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
    7.82 -	char *p, *q;
    7.83 -	char cpu_manufacturer[15];
    7.84 +    unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
    7.85 +    char *p, *q;
    7.86 +    char cpu_manufacturer[15];
    7.87  
    7.88 -	get_cpu_manufacturer(cpu_manufacturer, 15);
    7.89 -
    7.90 -	p = (char *)start + sizeof(struct smbios_entry_point);
    7.91 +    get_cpu_manufacturer(cpu_manufacturer, 15);
    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 +    p = (char *)start + sizeof(struct smbios_entry_point);
   7.100 +
   7.101 +#define do_struct(fn) do {                      \
   7.102 +    q = (fn);                                   \
   7.103 +    nr_structs++;                               \
   7.104 +    if ( (q - p) > max_struct_size )            \
   7.105 +        max_struct_size = q - p;                \
   7.106 +    p = q;                                      \
   7.107  } while (0)
   7.108  
   7.109 -	do_struct(smbios_type_0_init(p, xen_version, xen_major_version,
   7.110 -				     xen_minor_version));
   7.111 -	do_struct(smbios_type_1_init(p, xen_version, uuid));
   7.112 -	do_struct(smbios_type_3_init(p));
   7.113 -	for (cpu_num = 1; cpu_num <= vcpus; cpu_num++)
   7.114 -		do_struct(smbios_type_4_init(p, cpu_num, cpu_manufacturer));
   7.115 -	do_struct(smbios_type_16_init(p, memsize));
   7.116 -	do_struct(smbios_type_17_init(p, memsize));
   7.117 -	do_struct(smbios_type_19_init(p, memsize));
   7.118 -	do_struct(smbios_type_20_init(p, memsize));
   7.119 -	do_struct(smbios_type_32_init(p));
   7.120 -	do_struct(smbios_type_127_init(p));
   7.121 +    do_struct(smbios_type_0_init(p, xen_version, xen_major_version,
   7.122 +                                 xen_minor_version));
   7.123 +    do_struct(smbios_type_1_init(p, xen_version, uuid));
   7.124 +    do_struct(smbios_type_3_init(p));
   7.125 +    for ( cpu_num = 1; cpu_num <= vcpus; cpu_num++ )
   7.126 +        do_struct(smbios_type_4_init(p, cpu_num, cpu_manufacturer));
   7.127 +    do_struct(smbios_type_16_init(p, memsize));
   7.128 +    do_struct(smbios_type_17_init(p, memsize));
   7.129 +    do_struct(smbios_type_19_init(p, memsize));
   7.130 +    do_struct(smbios_type_20_init(p, memsize));
   7.131 +    do_struct(smbios_type_32_init(p));
   7.132 +    do_struct(smbios_type_127_init(p));
   7.133  
   7.134  #undef do_struct
   7.135  
   7.136 -	smbios_entry_point_init(
   7.137 -		start, max_struct_size,
   7.138 -		(p - (char *)start) - sizeof(struct smbios_entry_point),
   7.139 -		SMBIOS_PHYSICAL_ADDRESS + sizeof(struct smbios_entry_point),
   7.140 -		nr_structs);
   7.141 +    smbios_entry_point_init(
   7.142 +        start, max_struct_size,
   7.143 +        (p - (char *)start) - sizeof(struct smbios_entry_point),
   7.144 +        SMBIOS_PHYSICAL_ADDRESS + sizeof(struct smbios_entry_point),
   7.145 +        nr_structs);
   7.146  
   7.147 -	return (size_t)((char *)p - (char *)start);
   7.148 +    return (size_t)((char *)p - (char *)start);
   7.149  }
   7.150  
   7.151  /* This tries to figure out how much pseudo-physical memory (in MB)
   7.152 @@ -142,428 +142,439 @@ write_smbios_tables(void *start,
   7.153  static uint64_t
   7.154  get_memsize(void)
   7.155  {
   7.156 -	struct e820entry *map = NULL;
   7.157 -	uint8_t num_entries = 0;
   7.158 -	uint64_t memsize = 0;
   7.159 -	uint8_t i;
   7.160 -
   7.161 -	map = (struct e820entry *) (E820_MAP_PAGE + E820_MAP_OFFSET);
   7.162 -	num_entries = *((uint8_t *) (E820_MAP_PAGE + E820_MAP_NR_OFFSET));
   7.163 -
   7.164 -	/* walk through e820map, ignoring any entries that aren't marked
   7.165 -	   as usable or reserved. */
   7.166 +    struct e820entry *map = NULL;
   7.167 +    uint8_t num_entries = 0;
   7.168 +    uint64_t memsize = 0;
   7.169 +    uint8_t i;
   7.170  
   7.171 -	for (i = 0; i < num_entries; i++) {
   7.172 -		if (map->type == E820_RAM || map->type == E820_RESERVED)
   7.173 -			memsize += map->size;
   7.174 -		map++;
   7.175 -	}
   7.176 +    map = (struct e820entry *) (E820_MAP_PAGE + E820_MAP_OFFSET);
   7.177 +    num_entries = *((uint8_t *) (E820_MAP_PAGE + E820_MAP_NR_OFFSET));
   7.178  
   7.179 -	/* Round up to the nearest MB.  The user specifies domU
   7.180 -	   pseudo-physical memory in megabytes, so not doing this
   7.181 -	   could easily lead to reporting one less MB than the user
   7.182 -	   specified. */
   7.183 -	if (memsize & ((1<<20)-1))
   7.184 -		memsize = (memsize >> 20) + 1;
   7.185 -	else
   7.186 -		memsize = (memsize >> 20);
   7.187 +    /* walk through e820map, ignoring any entries that aren't marked
   7.188 +       as usable or reserved. */
   7.189  
   7.190 -	return memsize;
   7.191 +    for ( i = 0; i < num_entries; i++ )
   7.192 +    {
   7.193 +        if (map->type == E820_RAM || map->type == E820_RESERVED)
   7.194 +            memsize += map->size;
   7.195 +        map++;
   7.196 +    }
   7.197 +
   7.198 +    /* Round up to the nearest MB.  The user specifies domU
   7.199 +       pseudo-physical memory in megabytes, so not doing this
   7.200 +       could easily lead to reporting one less MB than the user
   7.201 +       specified. */
   7.202 +    if ( memsize & ((1<<20)-1) )
   7.203 +        memsize = (memsize >> 20) + 1;
   7.204 +    else
   7.205 +        memsize = (memsize >> 20);
   7.206 +
   7.207 +    return memsize;
   7.208  }
   7.209  
   7.210  void
   7.211  hvm_write_smbios_tables(void)
   7.212  {
   7.213 -	uint8_t uuid[16]; /* ** This will break if xen_domain_handle_t is
   7.214 -			     not uint8_t[16]. ** */
   7.215 -	uint16_t xen_major_version, xen_minor_version;
   7.216 -	uint32_t xen_version;
   7.217 -	char xen_extra_version[XEN_EXTRAVERSION_LEN];
   7.218 -	/* guess conservatively on buffer length for Xen version string */
   7.219 -	char xen_version_str[80];
   7.220 -	/* temporary variables used to build up Xen version string */
   7.221 -	char *p = NULL; /* points to next point of insertion */
   7.222 -	unsigned len = 0; /* length of string already composed */
   7.223 -	char *tmp = NULL; /* holds result of itoa() */
   7.224 -	unsigned tmp_len; /* length of next string to add */
   7.225 -
   7.226 -	hypercall_xen_version(XENVER_guest_handle, uuid);
   7.227 -
   7.228 -	/* xen_version major and minor */
   7.229 -	xen_version = hypercall_xen_version(XENVER_version, NULL);
   7.230 -	xen_major_version = (uint16_t) (xen_version >> 16);
   7.231 -	xen_minor_version = (uint16_t) xen_version;
   7.232 -
   7.233 -	hypercall_xen_version(XENVER_extraversion, xen_extra_version);
   7.234 -
   7.235 -	/* build up human-readable Xen version string */
   7.236 -	p = xen_version_str;
   7.237 -	len = 0;
   7.238 -
   7.239 -	itoa(tmp, xen_major_version);
   7.240 -	tmp_len = strlen(tmp);
   7.241 -	len += tmp_len;
   7.242 -	if (len >= sizeof(xen_version_str))
   7.243 -		goto error_out;
   7.244 -	strcpy(p, tmp);
   7.245 -	p += tmp_len;
   7.246 +    uint8_t uuid[16]; /* ** This will break if xen_domain_handle_t is
   7.247 +                         not uint8_t[16]. ** */
   7.248 +    uint16_t xen_major_version, xen_minor_version;
   7.249 +    uint32_t xen_version;
   7.250 +    char xen_extra_version[XEN_EXTRAVERSION_LEN];
   7.251 +    /* guess conservatively on buffer length for Xen version string */
   7.252 +    char xen_version_str[80];
   7.253 +    /* temporary variables used to build up Xen version string */
   7.254 +    char *p = NULL; /* points to next point of insertion */
   7.255 +    unsigned len = 0; /* length of string already composed */
   7.256 +    char *tmp = NULL; /* holds result of itoa() */
   7.257 +    unsigned tmp_len; /* length of next string to add */
   7.258  
   7.259 -	len++;
   7.260 -	if (len >= sizeof(xen_version_str))
   7.261 -		goto error_out;
   7.262 -	*p = '.';
   7.263 -	p++;
   7.264 -
   7.265 -	itoa(tmp, xen_minor_version);
   7.266 -	tmp_len = strlen(tmp);
   7.267 -	len += tmp_len;
   7.268 -	if (len >= sizeof(xen_version_str))
   7.269 -		goto error_out;
   7.270 -	strcpy(p, tmp);
   7.271 -	p += tmp_len;
   7.272 +    hypercall_xen_version(XENVER_guest_handle, uuid);
   7.273  
   7.274 -	tmp_len = strlen(xen_extra_version);
   7.275 -	len += tmp_len;
   7.276 -	if (len >= sizeof(xen_version_str))
   7.277 -		goto error_out;
   7.278 -	strcpy(p, xen_extra_version);
   7.279 -	p += tmp_len;
   7.280 -
   7.281 -	xen_version_str[sizeof(xen_version_str)-1] = '\0';
   7.282 +    /* xen_version major and minor */
   7.283 +    xen_version = hypercall_xen_version(XENVER_version, NULL);
   7.284 +    xen_major_version = (uint16_t) (xen_version >> 16);
   7.285 +    xen_minor_version = (uint16_t) xen_version;
   7.286  
   7.287 -	/* NB. 0xC0000 is a safe large memory area for scratch. */
   7.288 -	len = write_smbios_tables((void *)0xC0000,
   7.289 -				  get_vcpu_nr(), get_memsize(),
   7.290 -				  uuid, xen_version_str,
   7.291 -				  xen_major_version, xen_minor_version);
   7.292 -	if (len > SMBIOS_SIZE_LIMIT)
   7.293 -		goto error_out;
   7.294 -	/* Okay, not too large: copy out of scratch to final location. */
   7.295 -	memcpy((void *)SMBIOS_PHYSICAL_ADDRESS, (void *)0xC0000, len);
   7.296 +    hypercall_xen_version(XENVER_extraversion, xen_extra_version);
   7.297  
   7.298 -	return;
   7.299 +    /* build up human-readable Xen version string */
   7.300 +    p = xen_version_str;
   7.301 +    len = 0;
   7.302 +
   7.303 +    itoa(tmp, xen_major_version);
   7.304 +    tmp_len = strlen(tmp);
   7.305 +    len += tmp_len;
   7.306 +    if ( len >= sizeof(xen_version_str) )
   7.307 +        goto error_out;
   7.308 +    strcpy(p, tmp);
   7.309 +    p += tmp_len;
   7.310 +
   7.311 +    len++;
   7.312 +    if ( len >= sizeof(xen_version_str) )
   7.313 +        goto error_out;
   7.314 +    *p = '.';
   7.315 +    p++;
   7.316 +
   7.317 +    itoa(tmp, xen_minor_version);
   7.318 +    tmp_len = strlen(tmp);
   7.319 +    len += tmp_len;
   7.320 +    if ( len >= sizeof(xen_version_str) )
   7.321 +        goto error_out;
   7.322 +    strcpy(p, tmp);
   7.323 +    p += tmp_len;
   7.324 +
   7.325 +    tmp_len = strlen(xen_extra_version);
   7.326 +    len += tmp_len;
   7.327 +    if ( len >= sizeof(xen_version_str) )
   7.328 +        goto error_out;
   7.329 +    strcpy(p, xen_extra_version);
   7.330 +    p += tmp_len;
   7.331 +
   7.332 +    xen_version_str[sizeof(xen_version_str)-1] = '\0';
   7.333 +
   7.334 +    /* NB. 0xC0000 is a safe large memory area for scratch. */
   7.335 +    len = write_smbios_tables((void *)0xC0000,
   7.336 +                              get_vcpu_nr(), get_memsize(),
   7.337 +                              uuid, xen_version_str,
   7.338 +                              xen_major_version, xen_minor_version);
   7.339 +    if ( len > SMBIOS_SIZE_LIMIT )
   7.340 +        goto error_out;
   7.341 +    /* Okay, not too large: copy out of scratch to final location. */
   7.342 +    memcpy((void *)SMBIOS_PHYSICAL_ADDRESS, (void *)0xC0000, len);
   7.343 +
   7.344 +    return;
   7.345  
   7.346   error_out:
   7.347 -	puts("Could not write SMBIOS tables, error in hvmloader.c:"
   7.348 -	     "hvm_write_smbios_tables()\n");
   7.349 +    printf("Could not write SMBIOS tables, error in hvmloader.c:"
   7.350 +           "hvm_write_smbios_tables()\n");
   7.351  }
   7.352  
   7.353  
   7.354  static void
   7.355  smbios_entry_point_init(void *start,
   7.356 -			uint16_t max_structure_size,
   7.357 -			uint16_t structure_table_length,
   7.358 -			uint32_t structure_table_address,
   7.359 -			uint16_t number_of_structures)
   7.360 +                        uint16_t max_structure_size,
   7.361 +                        uint16_t structure_table_length,
   7.362 +                        uint32_t structure_table_address,
   7.363 +                        uint16_t number_of_structures)
   7.364  {
   7.365 -	uint8_t sum;
   7.366 -	int i;
   7.367 -	struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
   7.368 +    uint8_t sum;
   7.369 +    int i;
   7.370 +    struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
   7.371  
   7.372 -	strncpy(ep->anchor_string, "_SM_", 4);
   7.373 -	ep->length = 0x1f;
   7.374 -	ep->smbios_major_version = 2;
   7.375 -	ep->smbios_minor_version = 4;
   7.376 -	ep->max_structure_size = max_structure_size;
   7.377 -	ep->entry_point_revision = 0;
   7.378 -	memset(ep->formatted_area, 0, 5);
   7.379 -	strncpy(ep->intermediate_anchor_string, "_DMI_", 5);
   7.380 +    strncpy(ep->anchor_string, "_SM_", 4);
   7.381 +    ep->length = 0x1f;
   7.382 +    ep->smbios_major_version = 2;
   7.383 +    ep->smbios_minor_version = 4;
   7.384 +    ep->max_structure_size = max_structure_size;
   7.385 +    ep->entry_point_revision = 0;
   7.386 +    memset(ep->formatted_area, 0, 5);
   7.387 +    strncpy(ep->intermediate_anchor_string, "_DMI_", 5);
   7.388      
   7.389 -	ep->structure_table_length = structure_table_length;
   7.390 -	ep->structure_table_address = structure_table_address;
   7.391 -	ep->number_of_structures = number_of_structures;
   7.392 -	ep->smbios_bcd_revision = 0x24;
   7.393 +    ep->structure_table_length = structure_table_length;
   7.394 +    ep->structure_table_address = structure_table_address;
   7.395 +    ep->number_of_structures = number_of_structures;
   7.396 +    ep->smbios_bcd_revision = 0x24;
   7.397  
   7.398 -	ep->checksum = 0;
   7.399 -	ep->intermediate_checksum = 0;
   7.400 +    ep->checksum = 0;
   7.401 +    ep->intermediate_checksum = 0;
   7.402      
   7.403 -	sum = 0;
   7.404 -	for (i = 0; i < 0x10; ++i)
   7.405 -		sum += ((int8_t *)start)[i];
   7.406 -	ep->checksum = -sum;
   7.407 +    sum = 0;
   7.408 +    for ( i = 0; i < 0x10; i++ )
   7.409 +        sum += ((int8_t *)start)[i];
   7.410 +    ep->checksum = -sum;
   7.411  
   7.412 -	sum = 0;
   7.413 -	for (i = 0x10; i < ep->length; ++i)
   7.414 -		sum += ((int8_t *)start)[i];
   7.415 -	ep->intermediate_checksum = -sum;
   7.416 +    sum = 0;
   7.417 +    for ( i = 0x10; i < ep->length; i++ )
   7.418 +        sum += ((int8_t *)start)[i];
   7.419 +    ep->intermediate_checksum = -sum;
   7.420  }
   7.421  
   7.422  /* Type 0 -- BIOS Information */
   7.423  static void *
   7.424  smbios_type_0_init(void *start, const char *xen_version,
   7.425 -		   uint32_t xen_major_version, uint32_t xen_minor_version)
   7.426 +                   uint32_t xen_major_version, uint32_t xen_minor_version)
   7.427  {
   7.428 -	struct smbios_type_0 *p = (struct smbios_type_0 *)start;
   7.429 -    
   7.430 -	p->header.type = 0;
   7.431 -	p->header.length = sizeof(struct smbios_type_0);
   7.432 -	p->header.handle = 0;
   7.433 -    
   7.434 -	p->vendor_str = 1;
   7.435 -	p->version_str = 2;
   7.436 -	p->starting_address_segment = 0xe800;
   7.437 -	p->release_date_str = 0;
   7.438 -	p->rom_size = 0;
   7.439 +    struct smbios_type_0 *p = (struct smbios_type_0 *)start;
   7.440      
   7.441 -	memset(p->characteristics, 0, 8);
   7.442 -	p->characteristics[7] = 0x08; /* BIOS characteristics not supported */
   7.443 -	p->characteristics_extension_bytes[0] = 0;
   7.444 -	p->characteristics_extension_bytes[1] = 0;
   7.445 +    p->header.type = 0;
   7.446 +    p->header.length = sizeof(struct smbios_type_0);
   7.447 +    p->header.handle = 0;
   7.448      
   7.449 -	p->major_release = (uint8_t) xen_major_version;
   7.450 -	p->minor_release = (uint8_t) xen_minor_version;
   7.451 -	p->embedded_controller_major = 0xff;
   7.452 -	p->embedded_controller_minor = 0xff;
   7.453 +    p->vendor_str = 1;
   7.454 +    p->version_str = 2;
   7.455 +    p->starting_address_segment = 0xe800;
   7.456 +    p->release_date_str = 0;
   7.457 +    p->rom_size = 0;
   7.458 +    
   7.459 +    memset(p->characteristics, 0, 8);
   7.460 +    p->characteristics[7] = 0x08; /* BIOS characteristics not supported */
   7.461 +    p->characteristics_extension_bytes[0] = 0;
   7.462 +    p->characteristics_extension_bytes[1] = 0;
   7.463 +    
   7.464 +    p->major_release = (uint8_t) xen_major_version;
   7.465 +    p->minor_release = (uint8_t) xen_minor_version;
   7.466 +    p->embedded_controller_major = 0xff;
   7.467 +    p->embedded_controller_minor = 0xff;
   7.468  
   7.469 -	start += sizeof(struct smbios_type_0);
   7.470 -	strcpy((char *)start, "Xen");
   7.471 -	start += strlen("Xen") + 1;
   7.472 -	strcpy((char *)start, xen_version);
   7.473 -	start += strlen(xen_version) + 1;
   7.474 +    start += sizeof(struct smbios_type_0);
   7.475 +    strcpy((char *)start, "Xen");
   7.476 +    start += strlen("Xen") + 1;
   7.477 +    strcpy((char *)start, xen_version);
   7.478 +    start += strlen(xen_version) + 1;
   7.479  
   7.480 -	*((uint8_t *)start) = 0;
   7.481 -	return start + 1;
   7.482 +    *((uint8_t *)start) = 0;
   7.483 +    return start + 1;
   7.484  }
   7.485  
   7.486  /* Type 1 -- System Information */
   7.487  static void *
   7.488  smbios_type_1_init(void *start, const char *xen_version, 
   7.489 -		   uint8_t uuid[16])
   7.490 +                   uint8_t uuid[16])
   7.491  {
   7.492 -	char uuid_str[37];
   7.493 -	struct smbios_type_1 *p = (struct smbios_type_1 *)start;
   7.494 -	p->header.type = 1;
   7.495 -	p->header.length = sizeof(struct smbios_type_1);
   7.496 -	p->header.handle = 0x100;
   7.497 -
   7.498 -	p->manufacturer_str = 1;
   7.499 -	p->product_name_str = 2;
   7.500 -	p->version_str = 3;
   7.501 -	p->serial_number_str = 4;
   7.502 -    
   7.503 -	memcpy(p->uuid, uuid, 16);
   7.504 +    char uuid_str[37];
   7.505 +    struct smbios_type_1 *p = (struct smbios_type_1 *)start;
   7.506 +    p->header.type = 1;
   7.507 +    p->header.length = sizeof(struct smbios_type_1);
   7.508 +    p->header.handle = 0x100;
   7.509  
   7.510 -	p->wake_up_type = 0x06; /* power switch */
   7.511 -	p->sku_str = 0;
   7.512 -	p->family_str = 0;
   7.513 -
   7.514 -	start += sizeof(struct smbios_type_1);
   7.515 +    p->manufacturer_str = 1;
   7.516 +    p->product_name_str = 2;
   7.517 +    p->version_str = 3;
   7.518 +    p->serial_number_str = 4;
   7.519      
   7.520 -	strcpy((char *)start, "Xen");
   7.521 -	start += strlen("Xen") + 1;
   7.522 -	strcpy((char *)start, "HVM domU");
   7.523 -	start += strlen("HVM domU") + 1;
   7.524 -	strcpy((char *)start, xen_version);
   7.525 -	start += strlen(xen_version) + 1;
   7.526 -	uuid_to_string(uuid_str, uuid);	
   7.527 -	strcpy((char *)start, uuid_str);
   7.528 -	start += strlen(uuid_str) + 1;
   7.529 -	*((uint8_t *)start) = 0;
   7.530 +    memcpy(p->uuid, uuid, 16);
   7.531 +
   7.532 +    p->wake_up_type = 0x06; /* power switch */
   7.533 +    p->sku_str = 0;
   7.534 +    p->family_str = 0;
   7.535 +
   7.536 +    start += sizeof(struct smbios_type_1);
   7.537      
   7.538 -	return start+1; 
   7.539 +    strcpy((char *)start, "Xen");
   7.540 +    start += strlen("Xen") + 1;
   7.541 +    strcpy((char *)start, "HVM domU");
   7.542 +    start += strlen("HVM domU") + 1;
   7.543 +    strcpy((char *)start, xen_version);
   7.544 +    start += strlen(xen_version) + 1;
   7.545 +    uuid_to_string(uuid_str, uuid); 
   7.546 +    strcpy((char *)start, uuid_str);
   7.547 +    start += strlen(uuid_str) + 1;
   7.548 +    *((uint8_t *)start) = 0;
   7.549 +    
   7.550 +    return start+1; 
   7.551  }
   7.552  
   7.553  /* Type 3 -- System Enclosure */
   7.554  static void *
   7.555  smbios_type_3_init(void *start)
   7.556  {
   7.557 -	struct smbios_type_3 *p = (struct smbios_type_3 *)start;
   7.558 +    struct smbios_type_3 *p = (struct smbios_type_3 *)start;
   7.559      
   7.560 -	p->header.type = 3;
   7.561 -	p->header.length = sizeof(struct smbios_type_3);
   7.562 -	p->header.handle = 0x300;
   7.563 +    p->header.type = 3;
   7.564 +    p->header.length = sizeof(struct smbios_type_3);
   7.565 +    p->header.handle = 0x300;
   7.566  
   7.567 -	p->manufacturer_str = 1;
   7.568 -	p->type = 0x01; /* other */
   7.569 -	p->version_str = 0;
   7.570 -	p->serial_number_str = 0;
   7.571 -	p->asset_tag_str = 0;
   7.572 -	p->boot_up_state = 0x03; /* safe */
   7.573 -	p->power_supply_state = 0x03; /* safe */
   7.574 -	p->thermal_state = 0x03; /* safe */
   7.575 -	p->security_status = 0x02; /* unknown */
   7.576 +    p->manufacturer_str = 1;
   7.577 +    p->type = 0x01; /* other */
   7.578 +    p->version_str = 0;
   7.579 +    p->serial_number_str = 0;
   7.580 +    p->asset_tag_str = 0;
   7.581 +    p->boot_up_state = 0x03; /* safe */
   7.582 +    p->power_supply_state = 0x03; /* safe */
   7.583 +    p->thermal_state = 0x03; /* safe */
   7.584 +    p->security_status = 0x02; /* unknown */
   7.585  
   7.586 -	start += sizeof(struct smbios_type_3);
   7.587 +    start += sizeof(struct smbios_type_3);
   7.588      
   7.589 -	strcpy((char *)start, "Xen");
   7.590 -	start += strlen("Xen") + 1;
   7.591 -	*((uint8_t *)start) = 0;
   7.592 -	return start+1;
   7.593 +    strcpy((char *)start, "Xen");
   7.594 +    start += strlen("Xen") + 1;
   7.595 +    *((uint8_t *)start) = 0;
   7.596 +    return start+1;
   7.597  }
   7.598  
   7.599  /* Type 4 -- Processor Information */
   7.600  static void *
   7.601  smbios_type_4_init(void *start, unsigned int cpu_number, char *cpu_manufacturer)
   7.602  {
   7.603 -	char buf[80]; 
   7.604 -	struct smbios_type_4 *p = (struct smbios_type_4 *)start;
   7.605 -	uint32_t eax, ebx, ecx, edx;
   7.606 -
   7.607 -	p->header.type = 4;
   7.608 -	p->header.length = sizeof(struct smbios_type_4);
   7.609 -	p->header.handle = 0x400 + cpu_number;
   7.610 -
   7.611 -	p->socket_designation_str = 1;
   7.612 -	p->processor_type = 0x03; /* CPU */
   7.613 -	p->processor_family = 0x01; /* other */
   7.614 -	p->manufacturer_str = 2;
   7.615 -
   7.616 -	cpuid(1, &eax, &ebx, &ecx, &edx);
   7.617 -
   7.618 -	p->cpuid[0] = eax;
   7.619 -	p->cpuid[1] = edx;
   7.620 +    char buf[80]; 
   7.621 +    struct smbios_type_4 *p = (struct smbios_type_4 *)start;
   7.622 +    uint32_t eax, ebx, ecx, edx;
   7.623  
   7.624 -	p->version_str = 0;
   7.625 -	p->voltage = 0;
   7.626 -	p->external_clock = 0;
   7.627 -
   7.628 -	p->max_speed = 0; /* unknown */
   7.629 -	p->current_speed = 0; /* unknown */
   7.630 -
   7.631 -	p->status = 0x41; /* socket populated, CPU enabled */
   7.632 -	p->upgrade = 0x01; /* other */
   7.633 -
   7.634 -	start += sizeof(struct smbios_type_4);
   7.635 +    p->header.type = 4;
   7.636 +    p->header.length = sizeof(struct smbios_type_4);
   7.637 +    p->header.handle = 0x400 + cpu_number;
   7.638  
   7.639 -	strncpy(buf, "CPU ", sizeof(buf));
   7.640 -	if ((sizeof(buf) - strlen("CPU ")) >= 3)
   7.641 -		itoa(buf + strlen("CPU "), cpu_number);
   7.642 +    p->socket_designation_str = 1;
   7.643 +    p->processor_type = 0x03; /* CPU */
   7.644 +    p->processor_family = 0x01; /* other */
   7.645 +    p->manufacturer_str = 2;
   7.646  
   7.647 -	strcpy((char *)start, buf);
   7.648 -	start += strlen(buf) + 1;
   7.649 +    cpuid(1, &eax, &ebx, &ecx, &edx);
   7.650  
   7.651 -	strcpy((char *)start, cpu_manufacturer);
   7.652 -	start += strlen(cpu_manufacturer) + 1;
   7.653 +    p->cpuid[0] = eax;
   7.654 +    p->cpuid[1] = edx;
   7.655  
   7.656 -	*((uint8_t *)start) = 0;
   7.657 -	return start+1;
   7.658 +    p->version_str = 0;
   7.659 +    p->voltage = 0;
   7.660 +    p->external_clock = 0;
   7.661 +
   7.662 +    p->max_speed = 0; /* unknown */
   7.663 +    p->current_speed = 0; /* unknown */
   7.664 +
   7.665 +    p->status = 0x41; /* socket populated, CPU enabled */
   7.666 +    p->upgrade = 0x01; /* other */
   7.667 +
   7.668 +    start += sizeof(struct smbios_type_4);
   7.669 +
   7.670 +    strncpy(buf, "CPU ", sizeof(buf));
   7.671 +    if ( (sizeof(buf) - strlen("CPU ")) >= 3 )
   7.672 +        itoa(buf + strlen("CPU "), cpu_number);
   7.673 +
   7.674 +    strcpy((char *)start, buf);
   7.675 +    start += strlen(buf) + 1;
   7.676 +
   7.677 +    strcpy((char *)start, cpu_manufacturer);
   7.678 +    start += strlen(cpu_manufacturer) + 1;
   7.679 +
   7.680 +    *((uint8_t *)start) = 0;
   7.681 +    return start+1;
   7.682  }
   7.683  
   7.684  /* Type 16 -- Physical Memory Array */
   7.685  static void *
   7.686  smbios_type_16_init(void *start, uint32_t memsize)
   7.687  {
   7.688 -	struct smbios_type_16 *p = (struct smbios_type_16*)start;
   7.689 +    struct smbios_type_16 *p = (struct smbios_type_16*)start;
   7.690  
   7.691 -	p->header.type = 16;
   7.692 -	p->header.handle = 0x1000;
   7.693 -	p->header.length = sizeof(struct smbios_type_16);
   7.694 +    p->header.type = 16;
   7.695 +    p->header.handle = 0x1000;
   7.696 +    p->header.length = sizeof(struct smbios_type_16);
   7.697      
   7.698 -	p->location = 0x01; /* other */
   7.699 -	p->use = 0x03; /* system memory */
   7.700 -	p->error_correction = 0x01; /* other */
   7.701 -	p->maximum_capacity = memsize * 1024;
   7.702 -	p->memory_error_information_handle = 0xfffe; /* none provided */
   7.703 -	p->number_of_memory_devices = 1;
   7.704 +    p->location = 0x01; /* other */
   7.705 +    p->use = 0x03; /* system memory */
   7.706 +    p->error_correction = 0x01; /* other */
   7.707 +    p->maximum_capacity = memsize * 1024;
   7.708 +    p->memory_error_information_handle = 0xfffe; /* none provided */
   7.709 +    p->number_of_memory_devices = 1;
   7.710  
   7.711 -	start += sizeof(struct smbios_type_16);
   7.712 -	*((uint16_t *)start) = 0;
   7.713 -	return start + 2;
   7.714 +    start += sizeof(struct smbios_type_16);
   7.715 +    *((uint16_t *)start) = 0;
   7.716 +    return start + 2;
   7.717  }
   7.718  
   7.719  /* Type 17 -- Memory Device */
   7.720  static void *
   7.721  smbios_type_17_init(void *start, uint32_t memory_size_mb)
   7.722  {
   7.723 -	struct smbios_type_17 *p = (struct smbios_type_17 *)start;
   7.724 +    struct smbios_type_17 *p = (struct smbios_type_17 *)start;
   7.725      
   7.726 -	p->header.type = 17;
   7.727 -	p->header.length = sizeof(struct smbios_type_17);
   7.728 -	p->header.handle = 0x1100;
   7.729 +    p->header.type = 17;
   7.730 +    p->header.length = sizeof(struct smbios_type_17);
   7.731 +    p->header.handle = 0x1100;
   7.732  
   7.733 -	p->physical_memory_array_handle = 0x1000;
   7.734 -	p->total_width = 64;
   7.735 -	p->data_width = 64;
   7.736 -	/* truncate memory_size_mb to 16 bits and clear most significant
   7.737 -	   bit [indicates size in MB] */
   7.738 -	p->size = (uint16_t) memory_size_mb & 0x7fff;
   7.739 -	p->form_factor = 0x09; /* DIMM */
   7.740 -	p->device_set = 0;
   7.741 -	p->device_locator_str = 1;
   7.742 -	p->bank_locator_str = 0;
   7.743 -	p->memory_type = 0x07; /* RAM */
   7.744 -	p->type_detail = 0;
   7.745 +    p->physical_memory_array_handle = 0x1000;
   7.746 +    p->total_width = 64;
   7.747 +    p->data_width = 64;
   7.748 +    /* truncate memory_size_mb to 16 bits and clear most significant
   7.749 +       bit [indicates size in MB] */
   7.750 +    p->size = (uint16_t) memory_size_mb & 0x7fff;
   7.751 +    p->form_factor = 0x09; /* DIMM */
   7.752 +    p->device_set = 0;
   7.753 +    p->device_locator_str = 1;
   7.754 +    p->bank_locator_str = 0;
   7.755 +    p->memory_type = 0x07; /* RAM */
   7.756 +    p->type_detail = 0;
   7.757  
   7.758 -	start += sizeof(struct smbios_type_17);
   7.759 -	strcpy((char *)start, "DIMM 1");
   7.760 -	start += strlen("DIMM 1") + 1;
   7.761 -	*((uint8_t *)start) = 0;
   7.762 +    start += sizeof(struct smbios_type_17);
   7.763 +    strcpy((char *)start, "DIMM 1");
   7.764 +    start += strlen("DIMM 1") + 1;
   7.765 +    *((uint8_t *)start) = 0;
   7.766  
   7.767 -	return start+1;
   7.768 +    return start+1;
   7.769  }
   7.770  
   7.771  /* Type 19 -- Memory Array Mapped Address */
   7.772  static void *
   7.773  smbios_type_19_init(void *start, uint32_t memory_size_mb)
   7.774  {
   7.775 -	struct smbios_type_19 *p = (struct smbios_type_19 *)start;
   7.776 +    struct smbios_type_19 *p = (struct smbios_type_19 *)start;
   7.777      
   7.778 -	p->header.type = 19;
   7.779 -	p->header.length = sizeof(struct smbios_type_19);
   7.780 -	p->header.handle = 0x1300;
   7.781 +    p->header.type = 19;
   7.782 +    p->header.length = sizeof(struct smbios_type_19);
   7.783 +    p->header.handle = 0x1300;
   7.784  
   7.785 -	p->starting_address = 0;
   7.786 -	p->ending_address = (memory_size_mb-1) * 1024;
   7.787 -	p->memory_array_handle = 0x1000;
   7.788 -	p->partition_width = 1;
   7.789 +    p->starting_address = 0;
   7.790 +    p->ending_address = (memory_size_mb-1) * 1024;
   7.791 +    p->memory_array_handle = 0x1000;
   7.792 +    p->partition_width = 1;
   7.793  
   7.794 -	start += sizeof(struct smbios_type_19);
   7.795 -	*((uint16_t *)start) = 0;
   7.796 -	return start + 2;
   7.797 +    start += sizeof(struct smbios_type_19);
   7.798 +    *((uint16_t *)start) = 0;
   7.799 +    return start + 2;
   7.800  }
   7.801  
   7.802  /* Type 20 -- Memory Device Mapped Address */
   7.803  static void *
   7.804  smbios_type_20_init(void *start, uint32_t memory_size_mb)
   7.805  {
   7.806 -	struct smbios_type_20 *p = (struct smbios_type_20 *)start;
   7.807 -
   7.808 -	p->header.type = 20;
   7.809 -	p->header.length = sizeof(struct smbios_type_20);
   7.810 -	p->header.handle = 0x1400;
   7.811 +    struct smbios_type_20 *p = (struct smbios_type_20 *)start;
   7.812  
   7.813 -	p->starting_address = 0;
   7.814 -	p->ending_address = (memory_size_mb-1)*1024;
   7.815 -	p->memory_device_handle = 0x1100;
   7.816 -	p->memory_array_mapped_address_handle = 0x1300;
   7.817 -	p->partition_row_position = 1;
   7.818 -	p->interleave_position = 0;
   7.819 -	p->interleaved_data_depth = 0;
   7.820 +    p->header.type = 20;
   7.821 +    p->header.length = sizeof(struct smbios_type_20);
   7.822 +    p->header.handle = 0x1400;
   7.823  
   7.824 -	start += sizeof(struct smbios_type_20);
   7.825 +    p->starting_address = 0;
   7.826 +    p->ending_address = (memory_size_mb-1)*1024;
   7.827 +    p->memory_device_handle = 0x1100;
   7.828 +    p->memory_array_mapped_address_handle = 0x1300;
   7.829 +    p->partition_row_position = 1;
   7.830 +    p->interleave_position = 0;
   7.831 +    p->interleaved_data_depth = 0;
   7.832  
   7.833 -	*((uint16_t *)start) = 0;
   7.834 -	return start+2;
   7.835 +    start += sizeof(struct smbios_type_20);
   7.836 +
   7.837 +    *((uint16_t *)start) = 0;
   7.838 +    return start+2;
   7.839  }
   7.840  
   7.841  /* Type 32 -- System Boot Information */
   7.842  static void *
   7.843  smbios_type_32_init(void *start)
   7.844  {
   7.845 -	struct smbios_type_32 *p = (struct smbios_type_32 *)start;
   7.846 +    struct smbios_type_32 *p = (struct smbios_type_32 *)start;
   7.847  
   7.848 -	p->header.type = 32;
   7.849 -	p->header.length = sizeof(struct smbios_type_32);
   7.850 -	p->header.handle = 0x2000;
   7.851 -	memset(p->reserved, 0, 6);
   7.852 -	p->boot_status = 0; /* no errors detected */
   7.853 +    p->header.type = 32;
   7.854 +    p->header.length = sizeof(struct smbios_type_32);
   7.855 +    p->header.handle = 0x2000;
   7.856 +    memset(p->reserved, 0, 6);
   7.857 +    p->boot_status = 0; /* no errors detected */
   7.858      
   7.859 -	start += sizeof(struct smbios_type_32);
   7.860 -	*((uint16_t *)start) = 0;
   7.861 -	return start+2;
   7.862 +    start += sizeof(struct smbios_type_32);
   7.863 +    *((uint16_t *)start) = 0;
   7.864 +    return start+2;
   7.865  }
   7.866  
   7.867  /* Type 127 -- End of Table */
   7.868  static void *
   7.869  smbios_type_127_init(void *start)
   7.870  {
   7.871 -	struct smbios_type_127 *p = (struct smbios_type_127 *)start;
   7.872 +    struct smbios_type_127 *p = (struct smbios_type_127 *)start;
   7.873  
   7.874 -	p->header.type = 127;
   7.875 -	p->header.length = sizeof(struct smbios_type_127);
   7.876 -	p->header.handle = 0x7f00;
   7.877 +    p->header.type = 127;
   7.878 +    p->header.length = sizeof(struct smbios_type_127);
   7.879 +    p->header.handle = 0x7f00;
   7.880  
   7.881 -	start += sizeof(struct smbios_type_127);
   7.882 -	*((uint16_t *)start) = 0;
   7.883 -	return start + 2;
   7.884 +    start += sizeof(struct smbios_type_127);
   7.885 +    *((uint16_t *)start) = 0;
   7.886 +    return start + 2;
   7.887  }
   7.888 +
   7.889 +/*
   7.890 + * Local variables:
   7.891 + * mode: C
   7.892 + * c-set-style: "BSD"
   7.893 + * c-basic-offset: 4
   7.894 + * tab-width: 4
   7.895 + * indent-tabs-mode: nil
   7.896 + * End:
   7.897 + */
     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 -
    8.57 -	do {
    8.58 -		x++;
    8.59 -		_i /= 10;
    8.60 -	} while (_i != 0);
    8.61 +    unsigned int _i = i, x = 0;
    8.62  
    8.63 -	a += x;
    8.64 -	*a-- = '\0';
    8.65 +    do {
    8.66 +        x++;
    8.67 +        _i /= 10;
    8.68 +    } while ( _i != 0 );
    8.69  
    8.70 -	do {
    8.71 -		*a-- = (i % 10) + '0';
    8.72 -		i /= 10;
    8.73 -	} while (i != 0);
    8.74 +    a += x;
    8.75 +    *a-- = '\0';
    8.76  
    8.77 -	return a + 1;
    8.78 +    do {
    8.79 +        *a-- = (i % 10) + '0';
    8.80 +        i /= 10;
    8.81 +    } while ( i != 0 );
    8.82 +
    8.83 +    return a + 1;
    8.84  }
    8.85  
    8.86  int strcmp(const char *cs, const char *ct)
    8.87  {
    8.88 -	signed char res;
    8.89 +    signed char res;
    8.90  
    8.91 -	while (((res = *cs - *ct++) == 0) && (*cs++ != '\0'))
    8.92 -		continue;
    8.93 +    while ( ((res = *cs - *ct++) == 0) && (*cs++ != '\0') )
    8.94 +        continue;
    8.95  
    8.96 -	return res;
    8.97 +    return res;
    8.98  }
    8.99  
   8.100  void *memcpy(void *dest, const void *src, unsigned n)
   8.101  {
   8.102 -	int t0, t1, t2;
   8.103 +    int t0, t1, t2;
   8.104  
   8.105 -	__asm__ __volatile__(
   8.106 -		"cld\n"
   8.107 -		"rep; movsl\n"
   8.108 -		"testb $2,%b4\n"
   8.109 -		"je 1f\n"
   8.110 -		"movsw\n"
   8.111 -		"1: testb $1,%b4\n"
   8.112 -		"je 2f\n"
   8.113 -		"movsb\n"
   8.114 -		"2:"
   8.115 -		: "=&c" (t0), "=&D" (t1), "=&S" (t2)
   8.116 -		: "0" (n/4), "q" (n), "1" ((long) dest), "2" ((long) src)
   8.117 -		: "memory"
   8.118 -	);
   8.119 -	return dest;
   8.120 +    __asm__ __volatile__ (
   8.121 +        "cld\n"
   8.122 +        "rep; movsl\n"
   8.123 +        "testb $2,%b4\n"
   8.124 +        "je 1f\n"
   8.125 +        "movsw\n"
   8.126 +        "1: testb $1,%b4\n"
   8.127 +        "je 2f\n"
   8.128 +        "movsb\n"
   8.129 +        "2:"
   8.130 +        : "=&c" (t0), "=&D" (t1), "=&S" (t2)
   8.131 +        : "0" (n/4), "q" (n), "1" ((long) dest), "2" ((long) src)
   8.132 +        : "memory" );
   8.133 +    return dest;
   8.134  }
   8.135  
   8.136  void *memmove(void *dest, const void *src, unsigned n)
   8.137  {
   8.138 -	if ((long)dest > (long)src) {
   8.139 -		n--;
   8.140 -		while (n > 0) {
   8.141 -			((char *)dest)[n] = ((char *)src)[n];
   8.142 -			n--;
   8.143 -		}
   8.144 -	} else {
   8.145 -		memcpy(dest, src, n);
   8.146 -	}
   8.147 -	return dest;
   8.148 -}
   8.149 -
   8.150 -
   8.151 -
   8.152 -
   8.153 -void puts(const char *s)
   8.154 -{
   8.155 -	while (*s)
   8.156 -		outb(0xE9, *s++);
   8.157 +    if ( (long)dest > (long)src )
   8.158 +    {
   8.159 +        n--;
   8.160 +        while ( n > 0 )
   8.161 +        {
   8.162 +            ((char *)dest)[n] = ((char *)src)[n];
   8.163 +            n--;
   8.164 +        }
   8.165 +    }
   8.166 +    else
   8.167 +    {
   8.168 +        memcpy(dest, src, n);
   8.169 +    }
   8.170 +    return dest;
   8.171  }
   8.172  
   8.173  char *
   8.174  strcpy(char *dest, const char *src)
   8.175  {
   8.176 -	char *p = dest;
   8.177 -	while (*src)
   8.178 -		*p++ = *src++;
   8.179 -	*p = 0;
   8.180 -	return dest;
   8.181 +    char *p = dest;
   8.182 +    while ( *src )
   8.183 +        *p++ = *src++;
   8.184 +    *p = 0;
   8.185 +    return dest;
   8.186  }
   8.187  
   8.188  char *
   8.189  strncpy(char *dest, const char *src, unsigned n)
   8.190  {
   8.191 -	int i = 0;
   8.192 -	char *p = dest;
   8.193 +    int i = 0;
   8.194 +    char *p = dest;
   8.195  
   8.196 -	/* write non-NUL characters from src into dest until we run
   8.197 -	   out of room in dest or encounter a NUL in src */
   8.198 -	while (i < n && *src) {
   8.199 -		*p++ = *src++;
   8.200 -		++i;
   8.201 -	}
   8.202 +    /* write non-NUL characters from src into dest until we run
   8.203 +       out of room in dest or encounter a NUL in src */
   8.204 +    while ( (i < n) && *src )
   8.205 +    {
   8.206 +        *p++ = *src++;
   8.207 +        i++;
   8.208 +    }
   8.209  
   8.210 -	/* pad remaining bytes of dest with NUL bytes */
   8.211 -	while (i < n) {
   8.212 -		*p++ = 0;
   8.213 -		++i;
   8.214 -	}
   8.215 +    /* pad remaining bytes of dest with NUL bytes */
   8.216 +    while ( i < n )
   8.217 +    {
   8.218 +        *p++ = 0;
   8.219 +        i++;
   8.220 +    }
   8.221  
   8.222 -	return dest;
   8.223 +    return dest;
   8.224  }
   8.225  
   8.226  unsigned
   8.227  strlen(const char *s)
   8.228  {
   8.229 -	int i = 0;
   8.230 -	while (*s++)
   8.231 -		++i;
   8.232 -	return i;
   8.233 +    int i = 0;
   8.234 +    while ( *s++ )
   8.235 +        i++;
   8.236 +    return i;
   8.237  }
   8.238  
   8.239  void *
   8.240  memset(void *s, int c, unsigned n)
   8.241  {
   8.242 -	uint8_t b = (uint8_t) c;
   8.243 -	uint8_t *p = (uint8_t *)s;
   8.244 -	int i;
   8.245 -	for (i = 0; i < n; ++i)
   8.246 -		*p++ = b;
   8.247 -	return s;
   8.248 +    uint8_t b = (uint8_t) c;
   8.249 +    uint8_t *p = (uint8_t *)s;
   8.250 +    int i;
   8.251 +    for ( i = 0; i < n; i++ )
   8.252 +        *p++ = b;
   8.253 +    return s;
   8.254  }
   8.255  
   8.256  int
   8.257  memcmp(const void *s1, const void *s2, unsigned n)
   8.258  {
   8.259 -	unsigned i;
   8.260 -	uint8_t *p1 = (uint8_t *) s1;
   8.261 -	uint8_t *p2 = (uint8_t *) s2;
   8.262 +    unsigned i;
   8.263 +    uint8_t *p1 = (uint8_t *) s1;
   8.264 +    uint8_t *p2 = (uint8_t *) s2;
   8.265  
   8.266 -	for (i = 0; i < n; ++i) {
   8.267 -		if (p1[i] < p2[i])
   8.268 -			return -1;
   8.269 -		else if (p1[i] > p2[i])
   8.270 -			return 1;
   8.271 -	}
   8.272 +    for ( i = 0; i < n; i++ )
   8.273 +    {
   8.274 +        if ( p1[i] < p2[i] )
   8.275 +            return -1;
   8.276 +        else if ( p1[i] > p2[i] )
   8.277 +            return 1;
   8.278 +    }
   8.279  
   8.280 -	return 0;
   8.281 +    return 0;
   8.282  }
   8.283  
   8.284  void
   8.285  cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
   8.286  {
   8.287 -	__asm__ __volatile__(
   8.288 -		"cpuid"
   8.289 -		: "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
   8.290 -		: "0" (idx) );
   8.291 +    __asm__ __volatile__ (
   8.292 +        "cpuid"
   8.293 +        : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
   8.294 +        : "0" (idx) );
   8.295  }
   8.296  
   8.297  /* Write a two-character hex representation of 'byte' to digits[].
   8.298 @@ -196,18 +214,18 @@ cpuid(uint32_t idx, uint32_t *eax, uint3
   8.299  void
   8.300  byte_to_hex(char *digits, uint8_t byte)
   8.301  {
   8.302 -	uint8_t nybbel = byte >> 4;
   8.303 +    uint8_t nybbel = byte >> 4;
   8.304  
   8.305 -	if (nybbel > 9)
   8.306 -		digits[0] = 'a' + nybbel-10;
   8.307 -	else
   8.308 -		digits[0] = '0' + nybbel;
   8.309 +    if ( nybbel > 9 )
   8.310 +        digits[0] = 'a' + nybbel-10;
   8.311 +    else
   8.312 +        digits[0] = '0' + nybbel;
   8.313  
   8.314 -	nybbel = byte & 0x0f;
   8.315 -	if (nybbel > 9)
   8.316 -		digits[1] = 'a' + nybbel-10;
   8.317 -	else
   8.318 -		digits[1] = '0' + nybbel;
   8.319 +    nybbel = byte & 0x0f;
   8.320 +    if ( nybbel > 9 )
   8.321 +        digits[1] = 'a' + nybbel-10;
   8.322 +    else
   8.323 +        digits[1] = '0' + nybbel;
   8.324  }
   8.325  
   8.326  /* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
   8.327 @@ -217,34 +235,39 @@ byte_to_hex(char *digits, uint8_t byte)
   8.328  void
   8.329  uuid_to_string(char *dest, uint8_t *uuid)
   8.330  {
   8.331 -	int i = 0;
   8.332 -	char *p = dest;
   8.333 +    int i = 0;
   8.334 +    char *p = dest;
   8.335  
   8.336 -	for (i = 0; i < 4; ++i) {
   8.337 -		byte_to_hex(p, uuid[i]);
   8.338 -		p += 2;
   8.339 -	}
   8.340 -	*p++ = '-';
   8.341 -	for (i = 4; i < 6; ++i) {
   8.342 -		byte_to_hex(p, uuid[i]);
   8.343 -		p += 2;
   8.344 -	}
   8.345 -	*p++ = '-';
   8.346 -	for (i = 6; i < 8; ++i) {
   8.347 -		byte_to_hex(p, uuid[i]);
   8.348 -		p += 2;
   8.349 -	}
   8.350 -	*p++ = '-';
   8.351 -	for (i = 8; i < 10; ++i) {
   8.352 -		byte_to_hex(p, uuid[i]);
   8.353 -		p += 2;
   8.354 -	}
   8.355 -	*p++ = '-';
   8.356 -	for (i = 10; i < 16; ++i) {
   8.357 -		byte_to_hex(p, uuid[i]);
   8.358 -		p += 2;
   8.359 -	}
   8.360 -	*p = 0;
   8.361 +    for ( i = 0; i < 4; i++ )
   8.362 +    {
   8.363 +        byte_to_hex(p, uuid[i]);
   8.364 +        p += 2;
   8.365 +    }
   8.366 +    *p++ = '-';
   8.367 +    for ( i = 4; i < 6; i++ )
   8.368 +    {
   8.369 +        byte_to_hex(p, uuid[i]);
   8.370 +        p += 2;
   8.371 +    }
   8.372 +    *p++ = '-';
   8.373 +    for ( i = 6; i < 8; i++ )
   8.374 +    {
   8.375 +        byte_to_hex(p, uuid[i]);
   8.376 +        p += 2;
   8.377 +    }
   8.378 +    *p++ = '-';
   8.379 +    for ( i = 8; i < 10; i++ )
   8.380 +    {
   8.381 +        byte_to_hex(p, uuid[i]);
   8.382 +        p += 2;
   8.383 +    }
   8.384 +    *p++ = '-';
   8.385 +    for ( i = 10; i < 16; i++ )
   8.386 +    {
   8.387 +        byte_to_hex(p, uuid[i]);
   8.388 +        p += 2;
   8.389 +    }
   8.390 +    *p = '\0';
   8.391  }
   8.392  
   8.393  #include <xen/hvm/e820.h>
   8.394 @@ -252,31 +275,222 @@ uuid_to_string(char *dest, uint8_t *uuid
   8.395  #define E820_MAP    ((struct e820entry *)(E820_MAP_PAGE + E820_MAP_OFFSET))
   8.396  uint64_t e820_malloc(uint64_t size, uint32_t type, uint64_t mask)
   8.397  {
   8.398 -	uint64_t addr = 0;
   8.399 -	int c = *E820_MAP_NR - 1;
   8.400 -	struct e820entry *e820entry = (struct e820entry *)E820_MAP;
   8.401 +    uint64_t addr = 0;
   8.402 +    int c = *E820_MAP_NR - 1;
   8.403 +    struct e820entry *e820entry = (struct e820entry *)E820_MAP;
   8.404  
   8.405 -	while (c >= 0) {
   8.406 -		if (e820entry[c].type  == E820_RAM     &&
   8.407 -		    (e820entry[c].addr & (~mask)) == 0 &&
   8.408 -		    e820entry[c].size >= size) {
   8.409 -			addr = e820entry[c].addr;
   8.410 -			if (e820entry[c].size != size) {
   8.411 -				(*E820_MAP_NR)++;
   8.412 -				memmove(&e820entry[c+1],
   8.413 -				        &e820entry[c],
   8.414 -				        (*E820_MAP_NR - c) *
   8.415 -				            sizeof(struct e820entry));
   8.416 -				e820entry[c].size -= size;
   8.417 -				addr += e820entry[c].size;
   8.418 -				c++;
   8.419 -			}
   8.420 -			e820entry[c].addr = addr;
   8.421 -			e820entry[c].size = size;
   8.422 -			e820entry[c].type = type;
   8.423 -			break;
   8.424 -		}
   8.425 -		c--;
   8.426 -	}
   8.427 -        return addr;
   8.428 +    while ( c >= 0 )
   8.429 +    {
   8.430 +        if ( (e820entry[c].type  == E820_RAM) &&
   8.431 +             ((e820entry[c].addr & (~mask)) == 0) &&
   8.432 +             (e820entry[c].size >= size) )
   8.433 +        {
   8.434 +            addr = e820entry[c].addr;
   8.435 +            if ( e820entry[c].size != size )
   8.436 +            {
   8.437 +                (*E820_MAP_NR)++;
   8.438 +                memmove(&e820entry[c+1],
   8.439 +                        &e820entry[c],
   8.440 +                        (*E820_MAP_NR - c) *
   8.441 +                        sizeof(struct e820entry));
   8.442 +                e820entry[c].size -= size;
   8.443 +                addr += e820entry[c].size;
   8.444 +                c++;
   8.445 +            }
   8.446 +            e820entry[c].addr = addr;
   8.447 +            e820entry[c].size = size;
   8.448 +            e820entry[c].type = type;
   8.449 +            break;
   8.450 +        }
   8.451 +        c--;
   8.452 +    }
   8.453 +    return addr;
   8.454  }
   8.455 +
   8.456 +uint32_t ioapic_read(uint32_t reg)
   8.457 +{
   8.458 +    uint32_t *ioregsel = (uint32_t *)(IOAPIC_BASE_ADDRESS + 0x00);
   8.459 +    uint32_t *iowin    = (uint32_t *)(IOAPIC_BASE_ADDRESS + 0x10);
   8.460 +
   8.461 +    *ioregsel = reg;
   8.462 +    mb();
   8.463 +    return *iowin;
   8.464 +}
   8.465 +
   8.466 +void ioapic_write(uint32_t reg, uint32_t val)
   8.467 +{
   8.468 +    uint32_t *ioregsel = (uint32_t *)(IOAPIC_BASE_ADDRESS + 0x00);
   8.469 +    uint32_t *iowin    = (uint32_t *)(IOAPIC_BASE_ADDRESS + 0x10);
   8.470 +
   8.471 +    *ioregsel = reg;
   8.472 +    wmb();
   8.473 +    *iowin = val;
   8.474 +}
   8.475 +
   8.476 +#define PCI_CONF1_ADDRESS(bus, devfn, reg) \
   8.477 +    (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
   8.478 +
   8.479 +uint32_t pci_read(uint32_t devfn, uint32_t reg, uint32_t len)
   8.480 +{
   8.481 +    outl(0xcf8, PCI_CONF1_ADDRESS(0, devfn, reg));
   8.482 +
   8.483 +    switch ( len )
   8.484 +    {
   8.485 +    case 1: return inb(0xcfc + (reg & 3));
   8.486 +    case 2: return inw(0xcfc + (reg & 2));
   8.487 +    }
   8.488 +
   8.489 +    return inl(0xcfc);
   8.490 +}
   8.491 +
   8.492 +void pci_write(uint32_t devfn, uint32_t reg, uint32_t len, uint32_t val)
   8.493 +{
   8.494 +    outl(0xcf8, PCI_CONF1_ADDRESS(0, devfn, reg));
   8.495 +
   8.496 +    switch ( len )
   8.497 +    {
   8.498 +    case 1: outb(0xcfc + (reg & 3), val); break;
   8.499 +    case 2: outw(0xcfc + (reg & 2), val); break;
   8.500 +    case 4: outl(0xcfc,             val); break;
   8.501 +    }
   8.502 +}
   8.503 +
   8.504 +static char *printnum(char *p, unsigned long num, int base)
   8.505 +{
   8.506 +    unsigned long n;
   8.507 +
   8.508 +    if ( (n = num/base) > 0 )
   8.509 +        p = printnum(p, n, base);
   8.510 +    *p++ = "0123456789abcdef"[(int)(num % base)];
   8.511 +    *p = '\0';
   8.512 +    return p;
   8.513 +}
   8.514 +
   8.515 +static void _doprint(void (*put)(char), char const *fmt, va_list ap)
   8.516 +{
   8.517 +    register char *str, c;
   8.518 +    int lflag, zflag, nflag;
   8.519 +    char buffer[17];
   8.520 +    unsigned value;
   8.521 +    int i, slen, pad;
   8.522 +
   8.523 +    for ( ; *fmt != '\0'; fmt++ )
   8.524 +    {
   8.525 +        if ( *fmt != '%' )
   8.526 +        {
   8.527 +            put(*fmt);
   8.528 +            continue;
   8.529 +        }
   8.530 +
   8.531 +        pad = zflag = nflag = lflag = 0;
   8.532 +        c = *++fmt;
   8.533 +        if ( (c == '-') || isdigit(c) )
   8.534 +        {
   8.535 +            if ( c == '-' )
   8.536 +            {
   8.537 +                nflag = 1;
   8.538 +                c = *++fmt;
   8.539 +            }
   8.540 +            zflag = c == '0';
   8.541 +            for ( pad = 0; isdigit(c); c = *++fmt )
   8.542 +                pad = (pad * 10) + c - '0';
   8.543 +        }
   8.544 +        if ( c == 'l' ) /* long extension */
   8.545 +        {
   8.546 +            lflag = 1;
   8.547 +            c = *++fmt;
   8.548 +        }
   8.549 +        if ( (c == 'd') || (c == 'u') || (c == 'o') || (c == 'x') )
   8.550 +        {
   8.551 +            if ( lflag )
   8.552 +                value = va_arg(ap, unsigned);
   8.553 +            else
   8.554 +                value = (unsigned) va_arg(ap, unsigned int);
   8.555 +            str = buffer;
   8.556 +            printnum(str, value,
   8.557 +                     c == 'o' ? 8 : (c == 'x' ? 16 : 10));
   8.558 +            goto printn;
   8.559 +        }
   8.560 +        else if ( (c == 'O') || (c == 'D') || (c == 'X') )
   8.561 +        {
   8.562 +            value = va_arg(ap, unsigned);
   8.563 +            str = buffer;
   8.564 +            printnum(str, value,
   8.565 +                     c == 'O' ? 8 : (c == 'X' ? 16 : 10));
   8.566 +        printn:
   8.567 +            slen = strlen(str);
   8.568 +            for ( i = pad - slen; i > 0; i-- )
   8.569 +                put(zflag ? '0' : ' ');
   8.570 +            while ( *str )
   8.571 +                put(*str++);
   8.572 +        }
   8.573 +        else if ( c == 's' )
   8.574 +        {
   8.575 +            str = va_arg(ap, char *);
   8.576 +            slen = strlen(str);
   8.577 +            if ( nflag == 0 )
   8.578 +                for ( i = pad - slen; i > 0; i-- )
   8.579 +                    put(' ');
   8.580 +            while ( *str )
   8.581 +                put(*str++);
   8.582 +            if ( nflag )
   8.583 +                for ( i = pad - slen; i > 0; i-- )
   8.584 +                    put(' ');
   8.585 +        }
   8.586 +        else if ( c == 'c' )
   8.587 +        {
   8.588 +            put(va_arg(ap, int));
   8.589 +        }
   8.590 +        else
   8.591 +        {
   8.592 +            put(*fmt);
   8.593 +        }
   8.594 +    }
   8.595 +}
   8.596 +
   8.597 +static void putchar(char c)
   8.598 +{
   8.599 +    outb(0xe9, c);
   8.600 +}
   8.601 +
   8.602 +int printf(const char *fmt, ...)
   8.603 +{
   8.604 +    va_list ap;
   8.605 +
   8.606 +    va_start(ap, fmt);
   8.607 +    _doprint(putchar, fmt, ap);
   8.608 +    va_end(ap);
   8.609 +
   8.610 +    return 0;
   8.611 +}
   8.612 +
   8.613 +int vprintf(const char *fmt, va_list ap)
   8.614 +{
   8.615 +    _doprint(putchar, fmt, ap);
   8.616 +    return 0;
   8.617 +}
   8.618 +
   8.619 +void __assert_failed(char *assertion, char *file, int line)
   8.620 +{
   8.621 +    printf("HVMLoader assertion '%s' failed at %s:%d\n",
   8.622 +           assertion, file, line);
   8.623 +    for ( ; ; )
   8.624 +        __asm__ __volatile__ ( "ud2" );
   8.625 +}
   8.626 +
   8.627 +void __bug(char *file, int line)
   8.628 +{
   8.629 +    printf("HVMLoader bug at %s:%d\n", file, line);
   8.630 +    for ( ; ; )
   8.631 +        __asm__ __volatile__ ( "ud2" );
   8.632 +}
   8.633 +
   8.634 +/*
   8.635 + * Local variables:
   8.636 + * mode: C
   8.637 + * c-set-style: "BSD"
   8.638 + * c-basic-offset: 4
   8.639 + * tab-width: 4
   8.640 + * indent-tabs-mode: nil
   8.641 + * End:
   8.642 + */
     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) {}