Skip to content

Device model#70

Open
remexre wants to merge 8 commits intotrunkfrom
remexre/driver-model
Open

Device model#70
remexre wants to merge 8 commits intotrunkfrom
remexre/driver-model

Conversation

@remexre
Copy link
Member

@remexre remexre commented Nov 9, 2025

On top of #63; merge that one first, then rebase this.


  • Adds initializers. These are used to register drivers with the appropriate subsystems.
  • Adds the device model and documentation about it.
  • Adds support for enumerating devices in the Devicetree.
  • Adds the UART device class.
  • Adds an incomplete ns16550a driver. This is the UART we get in QEMU, and most UARTs in the wild are compatible with it. This driver is currently very basic, since we don't have interrupts (Trap handling #9) and it doesn't do DMA.

Relevant to #10, but it is not resolved by this PR.

The UART device class and ns16550a driver here are not very finished.
They currently act as an example of the device model, but don't implement all of what's needed for the driver itself.

@remexre remexre mentioned this pull request Nov 9, 2025
@remexre remexre changed the base branch from trunk to remexre/split-up-objects-in-makefile January 3, 2026 01:18
@remexre remexre force-pushed the remexre/split-up-objects-in-makefile branch 2 times, most recently from 1d3bead to ac9d91b Compare January 12, 2026 15:35
@remexre remexre force-pushed the remexre/driver-model branch from 62eddfa to 45e23c0 Compare January 12, 2026 15:39
@remexre remexre force-pushed the remexre/split-up-objects-in-makefile branch from ac9d91b to 18dd63d Compare January 12, 2026 16:04
@remexre remexre force-pushed the remexre/driver-model branch from 45e23c0 to 628e825 Compare January 12, 2026 16:04
@remexre remexre force-pushed the remexre/split-up-objects-in-makefile branch from 18dd63d to b3dda97 Compare January 12, 2026 23:20
Base automatically changed from remexre/split-up-objects-in-makefile to trunk January 12, 2026 23:23
@remexre remexre mentioned this pull request Jan 13, 2026
Signed-off-by: Amy Ringo <me@remexre.com>
These functions are for mapping IO memory.

Signed-off-by: Amy Ringo <me@remexre.com>
Signed-off-by: Amy Ringo <me@remexre.com>
Signed-off-by: Amy Ringo <me@remexre.com>
Signed-off-by: Amy Ringo <me@remexre.com>
Signed-off-by: Amy Ringo <me@remexre.com>
Signed-off-by: Amy Ringo <me@remexre.com>
Signed-off-by: Amy Ringo <me@remexre.com>
@remexre remexre force-pushed the remexre/driver-model branch from 628e825 to ff452dc Compare January 13, 2026 00:17
@remexre
Copy link
Member Author

remexre commented Jan 13, 2026

Since there are other drivers in development (#81), despite the actual ns16550a driver and UART device class here being very unfinished, I'm un-drafting this and looking for review.

@remexre remexre marked this pull request as ready for review January 13, 2026 00:29
@KieranMusser
Copy link
Contributor

I'll look a bit more into this later (as I rewrite my driver), but should we include PCI somewhere in this? I feel it might be good to separate the PCI driver from the RTL8139 driver. I'll be doing all the work for PCI as a part of the RTL fixing, but PCI is useful to more than just that one driver.

@remexre
Copy link
Member Author

remexre commented Jan 13, 2026

I'll look a bit more into this later (as I rewrite my driver), but should we include PCI somewhere in this? I feel it might be good to separate the PCI driver from the RTL8139 driver.

Depends how big it is, I suppose; if the PCI and RTL8139 drivers are small enough together that they make sense to review together, then eh, whatever's fine.

If the PCI driver is large enough to need separate review, I would make a separate PR for it that has a target branch of this one, then set the RTL8139 PR to have a target branch of that one.

A few advantages there:

  • The GitHub UI only shows the diff against that other branch, so your reviewers don't end up re-reviewing commits that're really from the other branch.
  • The list of PRs makes it visually obvious when a branch depends on another in this way.
  • Once the target branch gets merged, GitHub will email you and your reviewer(s). The message is phrased a bit rudely ("dismissed their stale review"), but... it's at least a ping lol.

@remexre remexre mentioned this pull request Feb 14, 2026
struct list_head parent_children;

/**
* The children of the node.
Copy link
Contributor

Choose a reason for hiding this comment

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

this is an unnecessary comment.

* Registers a device in the tree of devices and with its device class.
*
* - `name` must be filled out.
* - `parent` and `device_class` must be `nullptr`.
Copy link
Contributor

Choose a reason for hiding this comment

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

im confused, the attribute says nonnull but the comment says must be nullptr.


## Device classes

Each device probably provides some functionality other than simply existing.
Copy link
Contributor

Choose a reason for hiding this comment

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

this is probably not necessary.


Typically, a device class consists of three things: a vtable struct, a device struct, and a list of devices.

The vtable is simply a struct with methods for that kind of device.
Copy link
Contributor

Choose a reason for hiding this comment

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

c++ 😢


uaddr lo, hi;
struct vma *vma;
vma = vma_alloc(&kernel_virtual_allocator, size >> 12);
Copy link
Contributor

Choose a reason for hiding this comment

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

size >> 12 is some magic


/**
* The bits of the Interrupt Enable Register.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add someone a link to the spec sheet for this UART device.

Copy link
Contributor

Choose a reason for hiding this comment

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

im unable to verify these cant find the spec sheet.

return &device->device;

fail:
if (device) {
Copy link
Contributor

Choose a reason for hiding this comment

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

might be a good idea to have a device_free(), so we don't have to remember to free the format name, unmap and free the whole thing.

const struct uart_ops *ops;

/**
* A pointer to the _same_ device.
Copy link
Contributor

Choose a reason for hiding this comment

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

what does same device mean here.


/**
* Maps a region of memory for memory-mapped IO. This may involve special flags
* or other setup to prevent accesses from being cached.
Copy link
Contributor

Choose a reason for hiding this comment

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

where would this setup be? or do we not have that option yet?


if (!handlers) {
assert(!handlers_len);
handlers_cap = 16;
Copy link
Contributor

Choose a reason for hiding this comment

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

magic value

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.

3 participants

Comments