Revision 5fafdf24 hw/pci.c
b/hw/pci.c | ||
---|---|---|
2 | 2 |
* QEMU PCI bus manager |
3 | 3 |
* |
4 | 4 |
* Copyright (c) 2004 Fabrice Bellard |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | 7 |
* of this software and associated documentation files (the "Software"), to deal |
8 | 8 |
* in the Software without restriction, including without limitation the rights |
... | ... | |
96 | 96 |
} |
97 | 97 |
|
98 | 98 |
/* -1 for devfn means auto assign */ |
99 |
PCIDevice *pci_register_device(PCIBus *bus, const char *name,
|
|
99 |
PCIDevice *pci_register_device(PCIBus *bus, const char *name, |
|
100 | 100 |
int instance_size, int devfn, |
101 |
PCIConfigReadFunc *config_read,
|
|
101 |
PCIConfigReadFunc *config_read, |
|
102 | 102 |
PCIConfigWriteFunc *config_write) |
103 | 103 |
{ |
104 | 104 |
PCIDevice *pci_dev; |
105 | 105 |
|
106 | 106 |
if (pci_irq_index >= PCI_DEVICES_MAX) |
107 | 107 |
return NULL; |
108 |
|
|
108 |
|
|
109 | 109 |
if (devfn < 0) { |
110 | 110 |
for(devfn = bus->devfn_min ; devfn < 256; devfn += 8) { |
111 | 111 |
if (!bus->devices[devfn]) |
... | ... | |
134 | 134 |
return pci_dev; |
135 | 135 |
} |
136 | 136 |
|
137 |
void pci_register_io_region(PCIDevice *pci_dev, int region_num,
|
|
138 |
uint32_t size, int type,
|
|
137 |
void pci_register_io_region(PCIDevice *pci_dev, int region_num, |
|
138 |
uint32_t size, int type, |
|
139 | 139 |
PCIMapIORegionFunc *map_func) |
140 | 140 |
{ |
141 | 141 |
PCIIORegion *r; |
... | ... | |
166 | 166 |
PCIIORegion *r; |
167 | 167 |
int cmd, i; |
168 | 168 |
uint32_t last_addr, new_addr, config_ofs; |
169 |
|
|
169 |
|
|
170 | 170 |
cmd = le16_to_cpu(*(uint16_t *)(d->config + PCI_COMMAND)); |
171 | 171 |
for(i = 0; i < PCI_NUM_REGIONS; i++) { |
172 | 172 |
r = &d->io_regions[i]; |
... | ... | |
178 | 178 |
if (r->size != 0) { |
179 | 179 |
if (r->type & PCI_ADDRESS_SPACE_IO) { |
180 | 180 |
if (cmd & PCI_COMMAND_IO) { |
181 |
new_addr = le32_to_cpu(*(uint32_t *)(d->config +
|
|
181 |
new_addr = le32_to_cpu(*(uint32_t *)(d->config + |
|
182 | 182 |
config_ofs)); |
183 | 183 |
new_addr = new_addr & ~(r->size - 1); |
184 | 184 |
last_addr = new_addr + r->size - 1; |
... | ... | |
192 | 192 |
} |
193 | 193 |
} else { |
194 | 194 |
if (cmd & PCI_COMMAND_MEMORY) { |
195 |
new_addr = le32_to_cpu(*(uint32_t *)(d->config +
|
|
195 |
new_addr = le32_to_cpu(*(uint32_t *)(d->config + |
|
196 | 196 |
config_ofs)); |
197 | 197 |
/* the ROM slot has a specific enable bit */ |
198 | 198 |
if (i == PCI_ROM_SLOT && !(new_addr & 1)) |
... | ... | |
227 | 227 |
} |
228 | 228 |
} else { |
229 | 229 |
cpu_register_physical_memory(pci_to_cpu_addr(r->addr), |
230 |
r->size,
|
|
230 |
r->size, |
|
231 | 231 |
IO_MEM_UNASSIGNED); |
232 | 232 |
} |
233 | 233 |
} |
... | ... | |
240 | 240 |
} |
241 | 241 |
} |
242 | 242 |
|
243 |
uint32_t pci_default_read_config(PCIDevice *d,
|
|
243 |
uint32_t pci_default_read_config(PCIDevice *d, |
|
244 | 244 |
uint32_t address, int len) |
245 | 245 |
{ |
246 | 246 |
uint32_t val; |
... | ... | |
266 | 266 |
return val; |
267 | 267 |
} |
268 | 268 |
|
269 |
void pci_default_write_config(PCIDevice *d,
|
|
269 |
void pci_default_write_config(PCIDevice *d, |
|
270 | 270 |
uint32_t address, uint32_t val, int len) |
271 | 271 |
{ |
272 | 272 |
int can_write, i; |
273 | 273 |
uint32_t end, addr; |
274 | 274 |
|
275 |
if (len == 4 && ((address >= 0x10 && address < 0x10 + 4 * 6) ||
|
|
275 |
if (len == 4 && ((address >= 0x10 && address < 0x10 + 4 * 6) || |
|
276 | 276 |
(address >= 0x30 && address < 0x34))) { |
277 | 277 |
PCIIORegion *r; |
278 | 278 |
int reg; |
... | ... | |
367 | 367 |
PCIBus *s = opaque; |
368 | 368 |
PCIDevice *pci_dev; |
369 | 369 |
int config_addr, bus_num; |
370 |
|
|
370 |
|
|
371 | 371 |
#if defined(DEBUG_PCI) && 0 |
372 | 372 |
printf("pci_data_write: addr=%08x val=%08x len=%d\n", |
373 | 373 |
addr, val, len); |
... | ... | |
440 | 440 |
PCIDevice *pci_dev = (PCIDevice *)opaque; |
441 | 441 |
PCIBus *bus; |
442 | 442 |
int change; |
443 |
|
|
443 |
|
|
444 | 444 |
change = level - pci_dev->irq_state[irq_num]; |
445 | 445 |
if (!change) |
446 | 446 |
return; |
... | ... | |
465 | 465 |
const char *desc; |
466 | 466 |
} pci_class_desc; |
467 | 467 |
|
468 |
static pci_class_desc pci_class_descriptions[] =
|
|
468 |
static pci_class_desc pci_class_descriptions[] = |
|
469 | 469 |
{ |
470 | 470 |
{ 0x0100, "SCSI controller"}, |
471 | 471 |
{ 0x0101, "IDE controller"}, |
... | ... | |
538 | 538 |
if (r->size != 0) { |
539 | 539 |
term_printf(" BAR%d: ", i); |
540 | 540 |
if (r->type & PCI_ADDRESS_SPACE_IO) { |
541 |
term_printf("I/O at 0x%04x [0x%04x].\n",
|
|
541 |
term_printf("I/O at 0x%04x [0x%04x].\n", |
|
542 | 542 |
r->addr, r->addr + r->size - 1); |
543 | 543 |
} else { |
544 |
term_printf("32 bit memory at 0x%08x [0x%08x].\n",
|
|
544 |
term_printf("32 bit memory at 0x%08x [0x%08x].\n", |
|
545 | 545 |
r->addr, r->addr + r->size - 1); |
546 | 546 |
} |
547 | 547 |
} |
... | ... | |
556 | 556 |
PCIBus *bus = first_bus; |
557 | 557 |
PCIDevice *d; |
558 | 558 |
int devfn; |
559 |
|
|
559 |
|
|
560 | 560 |
while (bus && bus->bus_num != bus_num) |
561 | 561 |
bus = bus->next; |
562 | 562 |
if (bus) { |
... | ... | |
603 | 603 |
PCIBus *bus; |
604 | 604 |
} PCIBridge; |
605 | 605 |
|
606 |
void pci_bridge_write_config(PCIDevice *d,
|
|
606 |
void pci_bridge_write_config(PCIDevice *d, |
|
607 | 607 |
uint32_t address, uint32_t val, int len) |
608 | 608 |
{ |
609 | 609 |
PCIBridge *s = (PCIBridge *)d; |
... | ... | |
624 | 624 |
pci_map_irq_fn map_irq, const char *name) |
625 | 625 |
{ |
626 | 626 |
PCIBridge *s; |
627 |
s = (PCIBridge *)pci_register_device(bus, name, sizeof(PCIBridge),
|
|
627 |
s = (PCIBridge *)pci_register_device(bus, name, sizeof(PCIBridge), |
|
628 | 628 |
devfn, NULL, pci_bridge_write_config); |
629 | 629 |
s->dev.config[0x00] = id >> 16; |
630 | 630 |
s->dev.config[0x01] = id >> 24; |
Also available in: Unified diff