* [Qemu-devel] [PATCH] Align PCI capabilities in pci_find_space
@ 2012-09-25 20:59 mjr
2012-09-25 21:37 ` Alex Williamson
0 siblings, 1 reply; 2+ messages in thread
From: mjr @ 2012-09-25 20:59 UTC (permalink / raw)
To: qemu-devel
From: Matt Renzelmann <mjr@cs.wisc.edu>
The current implementation of pci_find_space does not properly align
PCI capabilities in the PCI configuration space. This patch fixes
this issue.
Signed-off-by: Matt Renzelmann <mjr@cs.wisc.edu>
---
This is my first patch to QEMU so I hope I'm not screwing up too much.
The purpose of this patch is to mask off the low-order two bits--Linux
masks these while scanning the PCI configuration space, for example,
so we need to make sure QEMU's behavior matches the standard.
No current QEMU hardware is likely using this but it may be important
later.
hw/pci.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index e149305..8771b7e 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1571,11 +1571,17 @@ static int pci_find_space(PCIDevice *pdev, uint8_t size)
int config_size = pci_config_size(pdev);
int offset = PCI_CONFIG_HEADER_SIZE;
int i;
- for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; ++i)
- if (pdev->used[i])
- offset = i + 1;
- else if (i - offset + 1 == size)
+ int masked;
+
+ for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; ++i) {
+ masked = i & (~3);
+ if (pdev->used[i]) {
+ offset = masked + 4;
+ } else if (i - offset + 1 == size) {
return offset;
+ }
+ }
+
return 0;
}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] Align PCI capabilities in pci_find_space
2012-09-25 20:59 [Qemu-devel] [PATCH] Align PCI capabilities in pci_find_space mjr
@ 2012-09-25 21:37 ` Alex Williamson
0 siblings, 0 replies; 2+ messages in thread
From: Alex Williamson @ 2012-09-25 21:37 UTC (permalink / raw)
To: mjr; +Cc: qemu-devel
On Tue, 2012-09-25 at 15:59 -0500, mjr@cs.wisc.edu wrote:
> From: Matt Renzelmann <mjr@cs.wisc.edu>
>
> The current implementation of pci_find_space does not properly align
> PCI capabilities in the PCI configuration space. This patch fixes
> this issue.
>
> Signed-off-by: Matt Renzelmann <mjr@cs.wisc.edu>
> ---
>
> This is my first patch to QEMU so I hope I'm not screwing up too much.
> The purpose of this patch is to mask off the low-order two bits--Linux
> masks these while scanning the PCI configuration space, for example,
> so we need to make sure QEMU's behavior matches the standard.
>
> No current QEMU hardware is likely using this but it may be important
> later.
>
> hw/pci.c | 14 ++++++++++----
> 1 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/hw/pci.c b/hw/pci.c
> index e149305..8771b7e 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -1571,11 +1571,17 @@ static int pci_find_space(PCIDevice *pdev, uint8_t size)
> int config_size = pci_config_size(pdev);
> int offset = PCI_CONFIG_HEADER_SIZE;
> int i;
> - for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; ++i)
> - if (pdev->used[i])
> - offset = i + 1;
> - else if (i - offset + 1 == size)
> + int masked;
> +
> + for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; ++i) {
> + masked = i & (~3);
> + if (pdev->used[i]) {
> + offset = masked + 4;
> + } else if (i - offset + 1 == size) {
> return offset;
> + }
> + }
> +
> return 0;
> }
>
I think you could just search every 4th byte. In fact, this whole used
byte-map could be turned into a single uint64_t bitmap for standard
config space. Thanks,
Alex
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-25 21:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-25 20:59 [Qemu-devel] [PATCH] Align PCI capabilities in pci_find_space mjr
2012-09-25 21:37 ` Alex Williamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).