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 1 commit into
base: master
Choose a base branch
from

Conversation

otischung
Copy link

This change updates pci_set_bar() to accept a single layout bitmask instead of separate boolean flags, simplifying BAR configuration. The new layout argument encodes I/O vs. memory space, 32-/64-bit decoding, and prefetchable settings via standard PCI_BASE_ADDRESS_* macros. Existing callers can now pass any combination of:

  • PCI_BASE_ADDRESS_SPACE_IO or PCI_BASE_ADDRESS_SPACE_MEMORY
  • PCI_BASE_ADDRESS_MEM_TYPE_32 or PCI_BASE_ADDRESS_MEM_TYPE_64
  • PCI_BASE_ADDRESS_MEM_PREFETCH The function writes the full layout to the BAR, derives bar_is_io_space from bit[0], and initializes the region with the provided callback. Docstrings updated with Doxygen examples illustrating MMIO and port I/O.

BREAKING CHANGE: pci_set_bar() signature changed; call sites must be updated to pass the new layout parameter rather than separate flags.

This change updates pci_set_bar() to accept a single `layout` bitmask
instead of separate boolean flags, simplifying BAR configuration. The
new `layout` argument encodes I/O vs. memory space, 32-/64-bit decoding,
and prefetchable settings via standard PCI_BASE_ADDRESS_* macros.
Existing callers can now pass any combination of:
  - PCI_BASE_ADDRESS_SPACE_IO or PCI_BASE_ADDRESS_SPACE_MEMORY
  - PCI_BASE_ADDRESS_MEM_TYPE_32 or PCI_BASE_ADDRESS_MEM_TYPE_64
  - PCI_BASE_ADDRESS_MEM_PREFETCH
The function writes the full layout to the BAR, derives `bar_is_io_space`
from bit[0], and initializes the region with the provided callback.
Docstrings updated with Doxygen examples illustrating MMIO and port I/O.

BREAKING CHANGE: pci_set_bar() signature changed; call sites must be
updated to pass the new `layout` parameter rather than separate flags.
Comment on lines +49 to +77
/**
* @brief Configure and initialize a PCI Base Address Register (BAR).
*
* This writes the caller-provided layout bitmask into the BAR register
* in the PCI configuration header, records the region size and I/O type,
* and sets up the address space (MMIO or port I/O) with the specified
* callback.
*
* @param dev Pointer to the pci_dev representing the device.
* @param bar BAR index to program (0–5 in a standard PCI header).
* @param bar_size Size of the BAR region in bytes (must be a power of two).
* @param layout Bitmask of PCI_BASE_ADDRESS_* flags defined in
* `/usr/include/linux/pci_regs.h`:
* - Bit 0: I/O space (1) vs. memory space (0)
* (`PCI_BASE_ADDRESS_SPACE_IO` or
* `PCI_BASE_ADDRESS_SPACE_MEMORY`)
* - Bits [2:1]: Memory decoding type
* (`PCI_BASE_ADDRESS_MEM_TYPE_32` or
* `PCI_BASE_ADDRESS_MEM_TYPE_64`)
* - Bit 3: Prefetchable flag for memory
* (`PCI_BASE_ADDRESS_MEM_PREFETCH`)
* @param do_io Callback (dev_io_fn) invoked on accesses within
* the BAR region.
*
* @note bar_size must be a power of two for correct decoding by the
* PCI framework.
* @note For 64-bit memory BARs, callers must reserve the next BAR index
* (n+1) for the high 32 bits if required by the platform.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Shorten the comments. Follow the style of the existing comments.

@@ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants