]> git.proxmox.com Git - qemu.git/commit
pci: add accessors to get/set registers by mask
authorMichael S. Tsirkin <mst@redhat.com>
Tue, 21 Feb 2012 13:41:30 +0000 (15:41 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 22 Feb 2012 15:02:18 +0000 (09:02 -0600)
commitc9f50cea70a15967daec9bf48fed37eafefdd584
tree3d14f1e549df1454dcaf6eab695e40c3387d4fb3
parent358b54654aa85f97402aca4be3b1a7b7d08bab70
pci: add accessors to get/set registers by mask

pci_regs.h specifies many registers by mask +
shifted register values.
There's always some duplication when using such:
for example to override device type, we would need:

pci_word_test_and_clear_mask(cap + PCI_EXP_FLAGS,
     PCI_EXP_FLAGS_TYPE);
pci_word_test_and_set_mask(cap + PCI_EXP_FLAGS,
    PCI_EXP_TYPE_ENDPOINT << (ffs(PCI_EXP_FLAGS_TYPE) - 1));

Getting such registers also uses some duplication:

word = pci_get_word(cap + PCI_EXP_FLAGS) & PCI_EXP_FLAGS_TYPE;
if ((word >> ffs((PCI_EXP_FLAGS_TYPE) - 1)) == PCI_EXP_TYPE_ENDPOINT)

Add API to access such registers in one line:
pci_set_word_by_mask(cap + PCI_EXP_FLAGS, PCI_EXP_FLAGS_TYPE,
     PCI_EXP_TYPE_ENDPOINT)

and
word = pci_get_word_by_mask(cap + PCI_EXP_FLAGS, PCI_EXP_FLAGS_TYPE)
if (word == PCI_EXP_TYPE_ENDPOINT)

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/pci.h