-
Notifications
You must be signed in to change notification settings - Fork 388
Feat driver testing enhancement #2328
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,20 +25,31 @@ | |
|
|
||
| namespace hw { | ||
|
|
||
| struct pcidev_info { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this different to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answer later at Deichman RN. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a superset of it. struct pcidev_info {
const uintptr_t pci_addr;
uint32_t vendor;
hw::PCI_Device::class_revision_t dev_class;
};The union vendor_product_t {
uint32_t both;
struct __attribute__((packed)) {
uint16_t vendor;
uint16_t product;
};
};It is an union right. It can further be broken down to vendor and product thus its name vendor_product. Vendor can be e.g. redhat or Virtio (1af4) and product can be VirtioFS 105a (if I didn't forget). struct pcidev_info {
const uintptr_t pci_addr;
vendor_product_t product;
hw::PCI_Device::class_revision_t dev_class;
};Something like the above would be better since we have a type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, of course. Maybe it's overkill, but would we benefit from providing an interface to the |
||
| const uintptr_t pci_addr; | ||
| uint32_t vendor; | ||
| hw::PCI_Device::class_revision_t dev_class; | ||
| }; | ||
|
|
||
| class PCI_manager { | ||
| public: | ||
| // a <...> driver is constructed from a PCI device, | ||
| // and returns a unique_ptr to itself | ||
| using NIC_driver = delegate< std::unique_ptr<hw::Nic> (PCI_Device&, uint16_t) >; | ||
| using Device_vector = std::vector<const hw::PCI_Device*>; | ||
| using Devinfo_vector = std::vector<pcidev_info>; | ||
| static void register_nic(uint16_t, uint16_t, NIC_driver); | ||
|
|
||
| using BLK_driver = delegate< std::unique_ptr<hw::Block_device> (PCI_Device&) >; | ||
| static void register_blk(uint16_t, uint16_t, BLK_driver); | ||
|
|
||
| static void init(); | ||
| static void init_devices(uint8_t classcode); | ||
| static Device_vector devices(); | ||
| /* Returns devices that were attempted to be initialized */ | ||
| static Device_vector devices(); | ||
| /* Returns all PCI device information except PCI bridges. | ||
| Useful for testing driver code outside of src. */ | ||
| static const Devinfo_vector &devinfos(); | ||
|
|
||
| private: | ||
| static void scan_bus(int bus); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Could we change these
#definevalues to proper types? I assume these are addresses, in which case I would place them asstatic const uint8_tvalues underPCI::Registry::. Alternatively under an enumeration if it makes sense to switch-case over them (could also make for cleaner code, but that's subjective).I see
PCI::msghas auint8_t regfield. I think it would be nice to make this "pointer" a proper type, for instancePCI::registry_pmaybe (opinionated names), which you could use for all these_REGvalues, instead ofuint8_tmentioned above.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.
For next PR. Keeping this PR short.
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.
I don't want conflicts as I integrate Virtio.
Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah, that's fair. I generally dislike
#definevalues, which is why I bring it up. They are inherently not typesafe: changing the order of parameters in functions makes for very easy bugs that are annoying to debug (this guy brings up plenty of examples in this regard: https://youtu.be/gV7jhTMYkKc).We currently have 403 files with a total of 1483
#defines across the code: migrating all of them in a single PR would be a huge task. Instead, converting them over while already touching related code makes this burden better over time. That's just my opinion though, I think this can be merged as-is too.That said: does it makes sense to make a specific type for registry addresses?
Uh oh!
There was an error while loading. Please reload this page.
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.
I dunno. I think it may have made sense to have a specific registry type when it was made, but converting entire codebase to proper types is risky in terms of breaking something (mistakes and low level sensitivity). I would be careful.
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.
I agree with you both. We probably do want these defines to be strongly typed. Because:
From here:
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-macro
But also - we can do a separate pass at this. One problem will be that enum class doesn't support bitwise ops by default. We did add useful helpers for that here:
https://github.com/includeos/IncludeOS/blob/main/api/util/bitops.hpp
So it's not hard to add, but it it should be done consistently. Wrt risky; we might also find some bugs when we do this.
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.
Please make a task to address conversion to enum class.
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.
That's a good thing!
Can confirm, they work great.
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.
I added a tracking issue in #2333