Skip to content

Commit 81fda9c

Browse files
committed
virt: Add EHCI and SDHCI platform device
Since PCI is not exposed, add EHCI and SDHCI device for basic I/O on Windows RT.
1 parent 20350e8 commit 81fda9c

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

hw/arm/virt-acpi-build.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,57 @@ static void acpi_dsdt_add_virtio(Aml *scope,
156156
}
157157
}
158158

159+
static void acpi_dsdt_add_ehci(Aml *scope, const MemMapEntry *ehci_memmap,
160+
uint32_t ehci_irq)
161+
{
162+
Aml *dev = aml_device("USB0");
163+
aml_append(dev, aml_name_decl("_HID", aml_string("PNP0D20")));
164+
aml_append(dev, aml_name_decl("_UID", aml_int(0)));
165+
166+
Aml *crs = aml_resource_template();
167+
aml_append(crs,
168+
aml_memory32_fixed(ehci_memmap->base,
169+
ehci_memmap->size, AML_READ_WRITE));
170+
aml_append(crs,
171+
aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
172+
AML_EXCLUSIVE, &ehci_irq, 1));
173+
aml_append(dev, aml_name_decl("_CRS", crs));
174+
aml_append(scope, dev);
175+
}
176+
177+
static void acpi_dsdt_add_mmci(Aml *scope, const MemMapEntry *sdhci_memmap,
178+
uint32_t sdhci_irq)
179+
{
180+
Aml *dev = aml_device("SDC1");
181+
aml_append(dev, aml_name_decl("_HID", aml_string("PNP0D40")));
182+
aml_append(dev, aml_name_decl("_UID", aml_int(0)));
183+
184+
Aml *crs = aml_resource_template();
185+
aml_append(crs,
186+
aml_memory32_fixed(sdhci_memmap->base,
187+
sdhci_memmap->size, AML_READ_WRITE));
188+
aml_append(crs,
189+
aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
190+
AML_EXCLUSIVE, &sdhci_irq, 1));
191+
aml_append(dev, aml_name_decl("_CRS", crs));
192+
193+
/* Add a child device that represents the SD card,
194+
which is marked as non-removable */
195+
Aml *carddev = aml_device("SDMM");
196+
197+
Aml *adr = aml_method("_ADR", 0, AML_NOTSERIALIZED);
198+
aml_append(adr, aml_return(aml_int(0)));
199+
200+
Aml *rmv = aml_method("_RMV", 0, AML_NOTSERIALIZED);
201+
aml_append(rmv, aml_return(aml_int(0)));
202+
203+
aml_append(carddev, adr);
204+
aml_append(carddev, rmv);
205+
aml_append(dev, carddev);
206+
207+
aml_append(scope, dev);
208+
}
209+
159210
// static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap,
160211
// uint32_t irq, bool use_highmem, bool highmem_ecam,
161212
// VirtMachineState *vms)
@@ -869,6 +920,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
869920
(irqmap[VIRT_MMIO] + ARM_SPI_BASE), NUM_VIRTIO_TRANSPORTS);
870921
// acpi_dsdt_add_pci(scope, memmap, (irqmap[VIRT_PCIE] + ARM_SPI_BASE),
871922
// vms->highmem, vms->highmem_ecam, vms);
923+
acpi_dsdt_add_ehci(scope, &memmap[VIRT_EHCI], irqmap[VIRT_EHCI] + ARM_SPI_BASE);
924+
acpi_dsdt_add_mmci(scope, &memmap[VIRT_SDHCI], irqmap[VIRT_SDHCI] + ARM_SPI_BASE);
872925
if (vms->acpi_dev) {
873926
build_ged_aml(scope, "\\_SB."GED_DEVICE,
874927
HOTPLUG_HANDLER(vms->acpi_dev),

hw/arm/virt.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include "hw/virtio/virtio-iommu.h"
7979
#include "hw/char/pl011.h"
8080
#include "qemu/guest-random.h"
81+
#include "hw/sd/sdhci.h"
8182

8283
#define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
8384
static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
@@ -153,6 +154,8 @@ static const MemMapEntry base_memmap[] = {
153154
[VIRT_NVDIMM_ACPI] = { 0x09090000, NVDIMM_ACPI_IO_LEN},
154155
[VIRT_PVTIME] = { 0x090a0000, 0x00010000 },
155156
[VIRT_SECURE_GPIO] = { 0x090b0000, 0x00001000 },
157+
[VIRT_EHCI] = { 0x090c0000, 0x00010000 },
158+
[VIRT_SDHCI] = { 0x090d0000, 0x00010000 },
156159
[VIRT_MMIO] = { 0x0a000000, 0x00000200 },
157160
/* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */
158161
[VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 },
@@ -189,6 +192,8 @@ static const int a15irqmap[] = {
189192
[VIRT_GPIO] = 7,
190193
[VIRT_SECURE_UART] = 8,
191194
[VIRT_ACPI_GED] = 9,
195+
[VIRT_EHCI] = 11,
196+
[VIRT_SDHCI] = 12,
192197
[VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */
193198
[VIRT_GIC_V2M] = 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */
194199
[VIRT_SMMU] = 74, /* ...to 74 + NUM_SMMU_IRQS - 1 */
@@ -1289,6 +1294,44 @@ static void create_pcie_irq_map(const MachineState *ms,
12891294
0x7 /* PCI irq */);
12901295
}
12911296

1297+
static void create_ehci(const VirtMachineState *vms)
1298+
{
1299+
hwaddr base = vms->memmap[VIRT_EHCI].base;
1300+
int irq = vms->irqmap[VIRT_EHCI];
1301+
1302+
sysbus_create_simple("platform-ehci-usb", base,
1303+
qdev_get_gpio_in(vms->gic, irq));
1304+
}
1305+
1306+
static void create_sdhci(const VirtMachineState *vms)
1307+
{
1308+
1309+
hwaddr base = vms->memmap[VIRT_SDHCI].base;
1310+
int irq = vms->irqmap[VIRT_SDHCI];
1311+
DeviceState *dev;
1312+
SysBusDevice *busdev;
1313+
DriveInfo *di;
1314+
BlockBackend *blk;
1315+
DeviceState *carddev;
1316+
1317+
dev = qdev_new(TYPE_SYSBUS_SDHCI);
1318+
qdev_prop_set_uint64(dev, "capareg", VIRT_SDHCI_CAPABILITIES);
1319+
1320+
busdev = SYS_BUS_DEVICE(dev);
1321+
sysbus_realize_and_unref(busdev, &error_fatal);
1322+
sysbus_mmio_map(busdev, 0, base);
1323+
sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(vms->gic, irq));
1324+
1325+
1326+
di = drive_get_next(IF_SD);
1327+
blk = di ? blk_by_legacy_dinfo(di) : NULL;
1328+
carddev = qdev_new(TYPE_SD_CARD);
1329+
qdev_prop_set_drive(carddev, "drive", blk);
1330+
qdev_realize_and_unref(carddev, qdev_get_child_bus(dev, "sd-bus"),
1331+
&error_fatal);
1332+
1333+
}
1334+
12921335
static void create_smmu(const VirtMachineState *vms,
12931336
PCIBus *bus)
12941337
{
@@ -2150,6 +2193,12 @@ static void machvirt_init(MachineState *machine)
21502193
*/
21512194
create_virtio_devices(vms);
21522195

2196+
/* Create platform EHCI controller device */
2197+
create_ehci(vms);
2198+
2199+
/* Create platform SD host controller device */
2200+
create_sdhci(vms);
2201+
21532202
vms->fw_cfg = create_fw_cfg(vms, &address_space_memory);
21542203
rom_set_fw(vms->fw_cfg);
21552204

include/hw/arm/virt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ enum {
7070
VIRT_GIC_REDIST,
7171
VIRT_SMMU,
7272
VIRT_UART,
73+
VIRT_EHCI,
74+
VIRT_SDHCI,
7375
VIRT_MMIO,
7476
VIRT_RTC,
7577
VIRT_FW_CFG,
@@ -175,6 +177,9 @@ struct VirtMachineState {
175177

176178
#define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
177179

180+
/* Copied from EXYNOS4210_SDHCI_CAPABILITIES */
181+
#define VIRT_SDHCI_CAPABILITIES 0x05E80080
182+
178183
#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt")
179184
OBJECT_DECLARE_TYPE(VirtMachineState, VirtMachineClass, VIRT_MACHINE)
180185

0 commit comments

Comments
 (0)