-
Notifications
You must be signed in to change notification settings - Fork 29
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
base: master
Are you sure you want to change the base?
Replace BAR flags with unified layout
parameter
#41
Conversation
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.
src/pci.h
Outdated
/** | ||
* @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. | ||
*/ |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the comment informative.
- Remove verbose Doxygen-style documentation for pci_set_bar() to match the existing concise comment style used throughout the codebase - Update PCI_BASE_ADDRESS_MEM_PREFETCH comment to clarify it's an optional flag that users can uncomment if prefetchable memory is needed, rather than implying it's technically not supported The original verbose comment was inconsistent with the project's comment style, which favors brief, direct explanations. The prefetch flag comment now better explains that it's a user choice rather than a limitation.
I've completed the requested changes to simplify the PCI-related comments and make them more consistent with the existing codebase style. Please review and approve when ready. |
This change updates pci_set_bar() to accept a single
layout
bitmask instead of separate boolean flags, simplifying BAR configuration. The newlayout
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: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.