-
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
Open
otischung
wants to merge
1
commit into
sysprog21:master
Choose a base branch
from
otischung:fix/pci-bar-unified-layout-param
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Replace BAR flags with unified layout
parameter
#41
otischung
wants to merge
1
commit into
sysprog21:master
from
otischung:fix/pci-bar-unified-layout-param
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
jserv
reviewed
Jul 4, 2025
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. | ||
*/ |
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.
jserv
reviewed
Jul 4, 2025
@@ -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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.