Skip to content

Instantly share code, notes, and snippets.

@mcastelino
Last active August 15, 2018 20:33
Show Gist options
  • Save mcastelino/d3da2d7e6fd122cdec2df96c5d78d2a2 to your computer and use it in GitHub Desktop.
Save mcastelino/d3da2d7e6fd122cdec2df96c5d78d2a2 to your computer and use it in GitHub Desktop.
Summarizing NEMU changes to date

Summary

This tries to capture all the changes made to NEMU while I was on sabbatical. Will also be an attempt to document the overall architecture of the new x86 virt platform.

New Configuration Items

CONFIG_SYS_BUS_DEBUG
CONFIG_ACPI_HW_REDUCED
CONFIG_PCI_LITE

Nature of the configuration changes

TODO: Detail at the high level the nature of the configuration changes

New files added

hw/acpi/link.c
hw/acpi/reduced.c
hw/char/sysbus_debugcon.c
hw/i386/cpu.c
hw/i386/fw.c
hw/i386/kernel-loader.c
hw/i386/memory.c
hw/i386/virt/Makefile.objs
hw/i386/virt/acpi.c
hw/i386/virt/memory.c
hw/i386/virt/virt.c
hw/pci-host/pci_lite.c
include/hw/acpi/reduced.h
include/hw/fw-build.h
include/hw/i386/cpu-internal.h
include/hw/i386/fw.h
include/hw/i386/kernel-loader.h
include/hw/i386/memory.h
include/hw/i386/virt.h
include/hw/pci-host/pci-lite.h

Nature of feature/file changes

hw/acpi/link.c

hw/acpi/reduced.c

hw/char/sysbus_debugcon.c

hw/i386/cpu.c

hw/i386/fw.c

hw/i386/kernel-loader.c

hw/i386/memory.c

hw/i386/virt/Makefile.objs

hw/i386/virt/acpi.c

hw/i386/virt/memory.c

hw/i386/virt/virt.c

hw/pci-host/pci_lite.c

include/hw/acpi/reduced.h

include/hw/fw-build.h

include/hw/i386/cpu-internal.h

include/hw/i386/fw.h

include/hw/i386/kernel-loader.h

include/hw/i386/memory.h

include/hw/i386/virt.h

include/hw/pci-host/pci-lite.h

MachineClass

The top level MachineClass definition enhanced with the addition of a structure that holds the methods used to build the firmware tables. This can be used to hold DT of ACPI tables or any other custom tables.

typedef struct FirmwareBuildMethods {
    union {
        /* ACPI methods */
        struct {
            GArray *(*rsdp)(GArray *table_data, BIOSLinker *linker, unsigned rsdt_tbl_offset);
            GArray *(*madt)(GArray *table_data, BIOSLinker *linker, MachineState *ms, AcpiConfiguration *conf);
            void    (*setup)(MachineState *ms, AcpiConfiguration *conf);
            void    (*mcfg)(GArray *table_data, BIOSLinker *linker, AcpiMcfgInfo *info);
            void    (*srat)(GArray *table_data, BIOSLinker *linker, MachineState *machine, AcpiConfiguration *conf);
            void    (*slit)(GArray *table_data, BIOSLinker *linker);
        } acpi;
    };
} FirmwareBuildMethods;

RSDP (Root System Description Pointer) - Can be found in the EFI_SYSTEM_TABLE in the case of UEFI ACPI MADT (Multiple APIC Description Table) - MCFG - This is the table for PCI Enhanced Configuration Mechanism SRAT - System/Static Resource Affinity Table. Associates each processor and each block of memory with a simple integer value, called a proximity domain in ACPI jargon. SLIT - System Locality Information Table. The distance between nodes is described by the SLIT table

** OPEN: Do we need the SRAT and SLIT tables for a simple not hot plug system **

PCI Segments and MCFG

Older variations of PCI (e.g. "PCI Conventional") were limited to a maximum of 256 PCI bus segments. PCI Express extends this by introducing "PCI Segment Groups", where a system could (in theory) have up to 65536 PCI Segment Groups with 256 PCI bus segments per group, thereby allowing a single computer to have up to a maximum of 16777216 PCI bus segments.

On a typical system for example

[000h 0000   4]                    Signature : "MCFG"    [Memory Mapped Configuration table]
[004h 0004   4]                 Table Length : 0000003C
[008h 0008   1]                     Revision : 01
[009h 0009   1]                     Checksum : DF
...
[02Ch 0044   8]                 Base Address : 0000000060000000
[034h 0052   2]         Segment Group Number : 0000
[036h 0054   1]             Start Bus Number : 00
[037h 0055   1]               End Bus Number : FF
[038h 0056   4]                     Reserved : 00000000

Formula to determine where the (4096-byte) area for a function's PCI configuration space is: Physical_Address = MMIO_Starting_Physical_Address + ( (Bus - MMIO_Starting_Bus) << 20 | Device << 15 | Function << 12 )

ACPI

  • We have created a new type TYPE_VIRT_ACPI with TYPE_SYS_BUS_DEVICE as parent
  • PIIX seems to have TYPE_PIIX4_PM with parent TYPE_PCI_DEVICE as parent
#define VIRT_GED_IRQ_BASE           16
#define VIRT_GED_CPU_HOTPLUG_IRQ    VIRT_GED_IRQ_BASE
#define VIRT_GED_MEMORY_HOTPLUG_IRQ VIRT_GED_IRQ_BASE + 1
#define VIRT_GED_PCI_HOTPLUG_IRQ    VIRT_GED_IRQ_BASE + 2
#define VIRT_GED_NVDIMM_HOTPLUG_IRQ VIRT_GED_IRQ_BASE + 3

AcpiBuildState was defined slightly differently in the hw/arm/virt-acpi-build.c and hw/i386/acpi-build.c Moved in into common include/hw/acpi/acpi.h

AcpiConfiguration was spread across PCMachineClass and PCMachineState and the field AcpiBuildState

** OPEN: State is normally associated with the instance and class data is seperate from the instance data. We seem to be mixing the two together? Is this just a name confusion? **

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment