mirror of https://github.com/xemu-project/xemu.git
pci: consolidate pci_add_capability_at_offset() into pci_add_capability().
By making pci_add_capability() the special case of pci_add_capability_at_offset() of offset = 0, consolidate pci_add_capability_at_offset() into pci_add_capability(). Cc: Stefan Weil <weil@mail.berlios.de> Cc: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
68f799944b
commit
ca77089d2d
|
@ -539,7 +539,7 @@ static void e100_pci_reset(EEPRO100State * s, E100PCIDeviceInfo *e100_device)
|
||||||
if (e100_device->power_management) {
|
if (e100_device->power_management) {
|
||||||
/* Power Management Capabilities */
|
/* Power Management Capabilities */
|
||||||
int cfg_offset = 0xdc;
|
int cfg_offset = 0xdc;
|
||||||
int r = pci_add_capability_at_offset(&s->dev, PCI_CAP_ID_PM,
|
int r = pci_add_capability(&s->dev, PCI_CAP_ID_PM,
|
||||||
cfg_offset, PCI_PM_SIZEOF);
|
cfg_offset, PCI_PM_SIZEOF);
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
pci_set_word(pci_conf + cfg_offset + PCI_PM_PMC, 0x7e21);
|
pci_set_word(pci_conf + cfg_offset + PCI_PM_PMC, 0x7e21);
|
||||||
|
|
|
@ -73,7 +73,8 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->msix_bar_size = new_size;
|
pdev->msix_bar_size = new_size;
|
||||||
config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX, MSIX_CAP_LENGTH);
|
config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX,
|
||||||
|
0, MSIX_CAP_LENGTH);
|
||||||
if (config_offset < 0)
|
if (config_offset < 0)
|
||||||
return config_offset;
|
return config_offset;
|
||||||
config = pdev->config + config_offset;
|
config = pdev->config + config_offset;
|
||||||
|
|
31
hw/pci.c
31
hw/pci.c
|
@ -1682,11 +1682,25 @@ static void pci_del_option_rom(PCIDevice *pdev)
|
||||||
pdev->rom_offset = 0;
|
pdev->rom_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reserve space and add capability to the linked list in pci config space */
|
/*
|
||||||
int pci_add_capability_at_offset(PCIDevice *pdev, uint8_t cap_id,
|
* if !offset
|
||||||
|
* Reserve space and add capability to the linked list in pci config space
|
||||||
|
*
|
||||||
|
* if offset = 0,
|
||||||
|
* Find and reserve space and add capability to the linked list
|
||||||
|
* in pci config space */
|
||||||
|
int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
|
||||||
uint8_t offset, uint8_t size)
|
uint8_t offset, uint8_t size)
|
||||||
{
|
{
|
||||||
uint8_t *config = pdev->config + offset;
|
uint8_t *config;
|
||||||
|
if (!offset) {
|
||||||
|
offset = pci_find_space(pdev, size);
|
||||||
|
if (!offset) {
|
||||||
|
return -ENOSPC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config = pdev->config + offset;
|
||||||
config[PCI_CAP_LIST_ID] = cap_id;
|
config[PCI_CAP_LIST_ID] = cap_id;
|
||||||
config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
|
config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
|
||||||
pdev->config[PCI_CAPABILITY_LIST] = offset;
|
pdev->config[PCI_CAPABILITY_LIST] = offset;
|
||||||
|
@ -1699,17 +1713,6 @@ int pci_add_capability_at_offset(PCIDevice *pdev, uint8_t cap_id,
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find and reserve space and add capability to the linked list
|
|
||||||
* in pci config space */
|
|
||||||
int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
|
|
||||||
{
|
|
||||||
uint8_t offset = pci_find_space(pdev, size);
|
|
||||||
if (!offset) {
|
|
||||||
return -ENOSPC;
|
|
||||||
}
|
|
||||||
return pci_add_capability_at_offset(pdev, cap_id, offset, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Unlink capability from the pci config space. */
|
/* Unlink capability from the pci config space. */
|
||||||
void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
|
void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
|
||||||
{
|
{
|
||||||
|
|
5
hw/pci.h
5
hw/pci.h
|
@ -183,9 +183,8 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
|
||||||
pcibus_t size, int type,
|
pcibus_t size, int type,
|
||||||
PCIMapIORegionFunc *map_func);
|
PCIMapIORegionFunc *map_func);
|
||||||
|
|
||||||
int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
|
int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
|
||||||
int pci_add_capability_at_offset(PCIDevice *pci_dev, uint8_t cap_id,
|
uint8_t offset, uint8_t size);
|
||||||
uint8_t cap_offset, uint8_t cap_size);
|
|
||||||
|
|
||||||
void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
|
void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue