qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3] Align PCI capabilities in pci_find_space


From: Matt Renzelmann
Subject: Re: [Qemu-devel] [PATCH v3] Align PCI capabilities in pci_find_space
Date: Wed, 26 Sep 2012 13:05:11 -0500

> 
> Mismatched uses of "size" here.  We need both the end of the range to
> search and the size of the sub-range we're looking for.  Maybe start,
> end, and size.  Thanks,
> 

Ah of course, how's this:

static int pci_find_space(PCIDevice *pdev, uint32_t start,
                          uint32_t end, uint32_t size)
{
    int offset = start;
    int i;
    uint32_t *dword_used = &pdev->used[start];

    /* This approach ensures the capability is dword-aligned, as 
       required by the PCI and PCI-E specifications */
    for (i = start; i < end; i += 4, dword_used++) { 
        if (*dword_used)
            offset = i + 4;
        else if (i - offset + 4 >= size)
            return offset;
    }

    return 0;
}

static int pci_find_legacy_space(PCIDevice *pdev, uint8_t size) {
    return pci_find_space(pdev, PCI_CONFIG_HEADER_SIZE,
                          PCI_CONFIG_SPACE_SIZE, size);
}

static int pci_find_express_space(PCIDevice *pdev, uint16_t size) {
    assert (pci_config_size(pdev) >= PCIE_CONFIG_SPACE_SIZE);
    return pci_find_space(pdev, PCI_CONFIG_SPACE_SIZE,
                          PCIE_CONFIG_SPACE_SIZE, size);
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]