Skip to content

Replace BAR flags with unified layout parameter #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,13 @@ static void pci_mmio_io(void *owner,
void pci_set_bar(struct pci_dev *dev,
uint8_t bar,
uint32_t bar_size,
bool is_io_space,
uint32_t layout,
dev_io_fn do_io)
{
/* TODO: mem type, prefetch */
/* FIXME: bar_size must be power of 2 */
PCI_HDR_WRITE(dev->hdr, PCI_BAR_OFFSET(bar), is_io_space, 32);
PCI_HDR_WRITE(dev->hdr, PCI_BAR_OFFSET(bar), layout, 32);
dev->bar_size[bar] = bar_size;
dev->bar_is_io_space[bar] = is_io_space;
dev->bar_is_io_space[bar] = layout & 0x1U; // Get the bit[0] of layout
dev_init(&dev->space_dev[bar], 0, bar_size, dev, do_io);
}

Expand Down
5 changes: 4 additions & 1 deletion src/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ struct pci {
struct dev pci_mmio_dev;
};

/* Configure PCI BAR with layout flags from linux/pci_regs.h.
* FIXME: bar_size must be a power of two.
*/
void pci_set_bar(struct pci_dev *dev,
uint8_t bar,
uint32_t bar_size,
bool is_io_space,
uint32_t is_io_space,
dev_io_fn do_io);
void pci_set_status(struct pci_dev *dev, uint16_t status);
void pci_dev_register(struct pci_dev *dev);
Expand Down
4 changes: 3 additions & 1 deletion src/virtio-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ void virtio_pci_init(struct virtio_pci_dev *dev,
PCI_HDR_WRITE(dev->pci_dev.hdr, PCI_HEADER_TYPE, PCI_HEADER_TYPE_NORMAL, 8);
PCI_HDR_WRITE(dev->pci_dev.hdr, PCI_INTERRUPT_PIN, 1, 8);
pci_set_status(&dev->pci_dev, PCI_STATUS_CAP_LIST | PCI_STATUS_INTERRUPT);
pci_set_bar(&dev->pci_dev, 0, 0x100, PCI_BASE_ADDRESS_SPACE_MEMORY,
pci_set_bar(&dev->pci_dev, 0, 0x100,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the comment informative.

PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_32
/* | PCI_BASE_ADDRESS_MEM_PREFETCH: uncomment if prefetchable */,
virtio_pci_space_io);
virtio_pci_set_cap(dev, cap_list);
dev->device_feature |=
Expand Down