Skip to content

virtio: provide a rust interface of virtio_driver in rust #841

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: rust
Choose a base branch
from

Conversation

Richardhongyu
Copy link

Wrap the struct virtio_driver in rust.

Signed-off-by: Li Hongyu [email protected]

@Richardhongyu
Copy link
Author

The new commit fixes the above errors in the comment.

@Richardhongyu Richardhongyu force-pushed the rust_virtio branch 2 times, most recently from f936248 to 1fe931d Compare July 29, 2022 12:46
@fbq
Copy link
Member

fbq commented Aug 2, 2022

This looks great, but one question: shouldn't we use a dedicated crate for virtio support? First VIRTIO is not always enabled, we at least need to put some "cfg gate"s somewhere, second the virtio support is not a basic part of core kernel, we should separate it for maintainship.

Copy link

@wedsonaf wedsonaf left a comment

Choose a reason for hiding this comment

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

Other than the of ids, this looks good! Thanks for contributing.

vdrv.remove = Some(Self::remove_callback);
if let Some(t) = T::ID_TABLE {
vdrv.id_table = t.as_ref();
}
Copy link

Choose a reason for hiding this comment

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

If you want of ids to work here, you must set vdrv.driver.of_match_table -- see platform.rs for an example.

Copy link
Author

Choose a reason for hiding this comment

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

I found that in the virtio drivers of C sides, the common way to match the driver with the device is to use 'id_table' rather than of. I write a macro define_virtio_id_table to implement this. It's more like define_amba_id_table in the amba.rs.

// duration of this call, so it is guaranteed to remain alive for the lifetime of
// `vdev`.
let mut dev = unsafe { Device::from_ptr(vdev) };
let data = T::probe(&mut dev)?;
Copy link

Choose a reason for hiding this comment

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

of identifiers are allowed to carry some data with them. If the match happened through one of them, ideally you'll pass this data to the probe function. See get_id_info in platform.rs for an example of this. (Perhaps we should move this function to the driver module so all drivers that support of can use it.)

Copy link
Author

Choose a reason for hiding this comment

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

The virtio drivers use id_table to match the driver with the device, which does not contain any data field. The probe function in the virtio Driver is more like the probe function in the amba Driver.
It's reasonable to move get_id_info into the driver module. I can open a new PR about it.

@wedsonaf
Copy link

wedsonaf commented Aug 2, 2022

This looks great, but one question: shouldn't we use a dedicated crate for virtio support? First VIRTIO is not always enabled, we at least need to put some "cfg gate"s somewhere, second the virtio support is not a basic part of core kernel, we should separate it for maintainship.

I don't think we support putting it a different crate just yet, although @ojeda has been thinking about this.

As for a cfg gate, I agree we should have it. We normally put it in lib.rs when declaring the module, this way they're excluded when the feature is not configured.

@Richardhongyu
Copy link
Author

This looks great, but one question: shouldn't we use a dedicated crate for virtio support? First VIRTIO is not always enabled, we at least need to put some "cfg gate"s somewhere, second the virtio support is not a basic part of core kernel, we should separate it for maintainship.

Thanks for reviewing! I use '#[cfg(CONFIG_VIRTIO)]' in the new commit.

@Richardhongyu
Copy link
Author

Other than the of ids, this looks good! Thanks for contributing.

Thanks for reviewing! It seems I confuse the id_table and of_match_table. The drivers of virtio usually use id_table to match the driver with the device just like amba drivers. I write a new macro define_virtio_id_table to declare the ID_TABLE. In this case, the ID_TABLE should be passed to vdrv.id_table and there is no data field.

@Richardhongyu
Copy link
Author

@wedsonaf Hi, could you help have a look at this whenever you have time? Thanks in advance!

Wrap the struct virtio_driver in rust.

Signed-off-by: Li Hongyu <[email protected]>
@Richardhongyu
Copy link
Author

Now the code in the comments does not use ignore.

@vtta vtta mentioned this pull request Nov 14, 2022
@bjorn3 bjorn3 removed their request for review May 28, 2024 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants