Skip to content

Acacia I2C, Serial and Timer + new Python tooling - #751

Draft
omeh-a wants to merge 8 commits into
mainfrom
sdfgenpy
Draft

Acacia I2C, Serial and Timer + new Python tooling#751
omeh-a wants to merge 8 commits into
mainfrom
sdfgenpy

Conversation

@omeh-a

@omeh-a omeh-a commented Jul 8, 2026

Copy link
Copy Markdown
Member

This PR introduces Acacia to the sDDF and reworks all of our meta tooling around it.

  • Instead of storing our sDDF driver generation code in sdf_gen, we now store it locally in ./acacia_sddf/driver_class.py. Common logic is in ./acacia_sddf/sddf.py
  • tools/meta is removed and remaining Python like board.py is moved to ./acacia_sddf. This is to allow all of the Python in the sDDF to sit in one module that can be imported all in one blast. I moved acacia_sddf to the root of the repository to reflect its significance, as this code is in fact critical to assemble anything in the sDDF (as opposed to being a "two generic subdirectories deep tool")
  • board.py has been changed to get rid of some indirection, we now store compatible strings there for sanity.
  • All config.jsons are redundant and replaced with new functionality in driver_manifest.py. This file offers an API to let this same information be stored globally, and I intend for this to be used by each driver_class.py ... e.g. in i2c.py
# meson
add_driver_config(
    "meson",
    sDDFDriverConfig(
        compatible="amlogic,meson-axg-i2c",
        regions=[DTSRegion("regs", "rw", 4096, 0)],
        irqs=[DTSIRQ(0), DTSIRQ(1)],
    ),
)

# opentitan
add_driver_config(
    "opentitan",
    sDDFDriverConfig(
        compatible="eth,i2c",
        regions=[DTSRegion("regs", "rw", 4096, 0)],
        irqs=[DTSIRQ(4), DTSIRQ(0), DTSIRQ(1), DTSIRQ(7), DTSIRQ(9)],
    ),
)

... i.e. we store the old config.json in i2c.py.

There's not too much to see otherwise besides the new Acacia subsystem generation in i2c.py, serial.py and timer.py. Please let me know what you think about these.

I am leaving this PR as a draft until we have merged Acacia, just in case API changes occur.

I've implemented these three classes as an exemplar for Acacia usage in advance of porting the other classes by others. These three are also mutually dependent and it isn't possible to do i2c without the other two.

omeh-a added 3 commits July 3, 2026 09:20
Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>

Timer tests out with acacia

Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>

Serial tests out with Acacia

Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>

Refactor: acacia_sddf is now a python module that inherits all subfiles, sDDF itself is a python module for import! Needed for SDK

Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>

Fix issues with i2c.py - maps were swapped.

Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>

Further fixes to keep up with Acacia PR request changes

Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>
Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>
Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>
@omeh-a omeh-a added drivers Issues pertaining to driver code for a device class driver-examples Issues related to examples for drivers for a target serial timer i2c labels Jul 8, 2026
Comment thread acacia_sddf/board.py
blk: Optional[DriverDouble] = DriverDouble(None, None)
partition: int = 0
baud_rate: Optional[int] = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How does this work when you have multiple ethernet devices (of the same or different kinds) in the same board? I think these should be lists of DriverDouble

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It didn't before these changes, from tools/meta/board.py it was reasonably similar. @Courtney3141 might need to comment on what the Firewall does, which I think uses a different board definition.

In general I think we mostly assume we have "single" instances of the driver subsystems/components. There are plenty of cases where it makes sense for systems to have multiple different block drivers, or i2c, or serial, and even multiple connections per client.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think for now we should keep assuming that.


Maybe what we should do instead is that when you construct a system, by default what should happen is we iterate over the DTS file and instantiate a driver for every compatible string in the DTS we know about.

We can have a user API that has a stable naming/ordering scheme and then you ask for the Network subsystem "manager" to connect your client to e.g. ethernet device 0 or 1, or ethernet device at this PCI bus location, or identified by this PCI vendor+device, or at this DTS location. Most of our examples can then get away with asking for device 0 (because, maybe say, we use the DTS chosen node in the DTS we provide to force it to be the right one).

Then maybe users of our build system can construct systems in which you have connections, and if a particular block driver has no connections then we purge it from the system. (For clock drivers, maybe not, though you would assume there would be a connection between them and device drivers depending on them, so it could probably follow the same idea).

This makes sense in the LionsOS context too, really.

Comment thread acacia_sddf/board.py

# Keep this list in alphabetical order by board name
# TODO: convert to Dictionary
BOARDS: List[Board] = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I personally would prefer splitting these out one per supported board, then just importing the one you want.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(I know the old sdfgen tooling did it this way)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Then examples need to import every board anyway?

Comment thread acacia_sddf/board.py
Comment thread acacia_sddf/board.py
Comment thread acacia_sddf/i2c.py
from .sddf import sDDFDriverClass, DeviceResourcesFactory, RegionResourceFactory
from collections import defaultdict
from typing import List, Dict, Type, Union, Optional

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rearrange imports to put standard ones first

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also reframe from multiple imports on one line.

Comment thread acacia_sddf/sddf.py
Comment thread acacia_sddf/timer.py


# pulp
add_driver_config(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reckon these should be in per-driver files imported rather than enumerated here. So that the tooling can be used with third-party drivers without changing this file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well, you can already, see 'add_driver_config' you can import that and call it. I think there needs to be an global registry of drivers in some sense otherwise your meta program needs to duplicate driver selection logic.

Though it might be better to follow the "driver finder library" approach or something instead of doing what Linux calls the midlayer mistake. But then maybe that doesn't work with my proposed solution of creating drivers for every found DTS node where a compatible matches?


SUPPORTED_BOARDS := \
odroidc4 \
maaxboard \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

separate change, different PR

Comment thread examples/serial/meta.py
board = next(filter(lambda b: b.name == args.board, BOARDS))
if board.arch != x86_64:
dtb = DeviceTreeBlob(args.dtb)
else:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An alternative would be to fudge up a DTS for the X86 systems we use. Linux X86 can use a DTB as an additional source of information (mainly to get the PCI and IOAPIC info)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Something like that isn't a bad idea... for what it's worth: this check is redundant. If there's no DTB given, this creates an empty dtb which is recognised by Acacia as being an x86 system

Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>
omeh-a added 2 commits July 13, 2026 10:09
Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>
Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>
Comment thread acacia_sddf/__init__.py
@@ -0,0 +1,8 @@
# Copyright 2026, UNSW

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this should be under acacia_sddf. It's not really clear what acacia is for a user. I think the timer/serial classes should either live in the appropriate serial/ or timer/ directory and helpers under tools/meta or tools/acacia.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There is a blunt reason for this: it means that we only need one Python import and it means that each driver class doesn't need to abuse importlib to find the others. I really think it's fine to have end users learn what Acacia is, given that they have to install it to use the sDDF. I did it as you suggest initially and it made things horrible. I'm really not eager to change this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think having to set up PYTHONPATH (which you can do entirely in the Makefile) is that bad. If you want just one import you can still do that without separating the components from the rest of the components, you just have some path-mangling.

The other thing is to consider external users: LionsOS, for instance, could just do "import sddf.timer" if it's located in the timer folder, whereas with this way you need to either do "import sddf.acacia_sddf.timer" or have top level exports (not necessary if your project structure follows python module structure, no need for init.py etc). They'd have to put sDDF in their PythonPath but that's fine and reasonable.

tldr; no, I disagree.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Users of anything will be using acacia anyway though? How can a user of acacia who must be using it in their metaprogram not already know what acacia is? Making the entire sDDF tree a python module just complicates things. The only functional diff from what you're describing is whether the module is called sddf or acacia_sddf. We can rename acacia_sddf to just sddf if it matters ... I personally think it's inconsequential, but I also really think it's worse for code organisation to scatter the python through the source tree.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sidenote: I don't think we will need to import sddf.acacia_sddf.blah either? We can do this exactly as it is done in the metaprogram and not make a top level sDDF module

Comment thread acacia_sddf/board.py
arch: Arch
paddr_top: int
# Driver mappings -> (compatible, preferred_node) tuples
serial: Optional[DriverDouble] = DriverDouble(None, None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional[] but then the default isn't None, instead it's DriveDouble(None, None). Why would it ever be None then?

Also, if it is DriverDouble(None, None), then this doesn't type-hint as DriverDouble is (str, str), not Optional[str].

Comment thread acacia_sddf/board.py
blk: Optional[DriverDouble] = DriverDouble(None, None)
partition: int = 0
baud_rate: Optional[int] = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It didn't before these changes, from tools/meta/board.py it was reasonably similar. @Courtney3141 might need to comment on what the Firewall does, which I think uses a different board definition.

In general I think we mostly assume we have "single" instances of the driver subsystems/components. There are plenty of cases where it makes sense for systems to have multiple different block drivers, or i2c, or serial, and even multiple connections per client.

Comment thread acacia_sddf/board.py

# Keep this list in alphabetical order by board name
# TODO: convert to Dictionary
BOARDS: List[Board] = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Then examples need to import every board anyway?

Comment thread acacia_sddf/board.py
blk: Optional[DriverDouble] = DriverDouble(None, None)
partition: int = 0
baud_rate: Optional[int] = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think for now we should keep assuming that.


Maybe what we should do instead is that when you construct a system, by default what should happen is we iterate over the DTS file and instantiate a driver for every compatible string in the DTS we know about.

We can have a user API that has a stable naming/ordering scheme and then you ask for the Network subsystem "manager" to connect your client to e.g. ethernet device 0 or 1, or ethernet device at this PCI bus location, or identified by this PCI vendor+device, or at this DTS location. Most of our examples can then get away with asking for device 0 (because, maybe say, we use the DTS chosen node in the DTS we provide to force it to be the right one).

Then maybe users of our build system can construct systems in which you have connections, and if a particular block driver has no connections then we purge it from the system. (For clock drivers, maybe not, though you would assume there would be a connection between them and device drivers depending on them, so it could probably follow the same idea).

This makes sense in the LionsOS context too, really.

Comment thread acacia_sddf/timer.py


# pulp
add_driver_config(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well, you can already, see 'add_driver_config' you can import that and call it. I think there needs to be an global registry of drivers in some sense otherwise your meta program needs to duplicate driver selection logic.

Though it might be better to follow the "driver finder library" approach or something instead of doing what Linux calls the midlayer mistake. But then maybe that doesn't work with my proposed solution of creating drivers for every found DTS node where a compatible matches?

f.write(sdf.render())
out_file = f"{output_dir}/{sdf_file}"
sdf.make_config_structs()
print(f"Saving to {out_file}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove

Comment thread examples/ina219/meta.py
f.write(sdf.render())
out_file = f"{output_dir}/{sdf_file}"
sdf.make_config_structs()
print(f"Saving to {out_file}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove

Comment thread examples/timer/meta.py
BOARDS = board_module.BOARDS

ProtectionDomain = SystemDescription.ProtectionDomain
# board_module = importlib.import_module("board")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

?

Comment thread examples/timer/meta.py
f.write(sdf.render())
sdf.make_config_structs()
out_file = f"{output_dir}/{sdf_file}"
print(f"Saving to {out_file}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove

assert type(self.irqs) is list


class __sDDFDriverManifest:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If anything I feel like this PR should just transliterate the exact same functionality from the zig sdfgen classes to Python, so that the difference is extremely minimal limited to a few type changes and import differences. Then we can discuss changing the API exposed in meta.py files at a later point in time to improve them wholistically.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These changes were necessary due to acacia working differently than sdf-gen. There's no real way around this without basically just putting the same functionality elsewhere in the python that is added, and indeed this is doing something similarly to what sdf_gen did by scanning the sddf for config.jsons and keeping a register of them

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not all of the changes were necessary. Perhaps moving away from config.json is better. Is it definitely? IDK. But it's a separate change that is logically distinct from a Zig -> Python rewrite.

@omeh-a omeh-a Aug 5, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can't just do a zig to python rewrite when we need to move all the changes that were formerly in a different tool, in a different language, to here. Again, this is just doing something similar to what sdf_gen did.

See sddf.zig ... this is a replacement for these

var drivers: std.array_list.Managed(Config.Driver) = undefined;
var classes: std.array_list.Managed(Config.DeviceClass) = undefined;

We can obviously change this in the future. But this bookkeeping isn't new.

(I can add searching for config.jsons if we want, just simpler calling direct for now..)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if this was considered and then decided against but can you avoid all the add_driver_config repetition and use the json by doing something like this:

Make the sDDFDriverClass class use the DT path to find the DT node like it does atm, then can it retrieve the compatible strings and provide this to the sDDFDriverManifest. Then the sDDFDriverManifest selects the json config from the compatible strings and parses the config into the form equivalent to what all the add_driver_config function calls are doing atm? I guess you would also provide the driver class name so the manifest knows which directory to search.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Make the sDDFDriverClass class use the DT path to find the DT node like it does atm, then can it retrieve the compatible strings and provide this to the sDDFDriverManifest. Then the sDDFDriverManifest selects the json config from the compatible strings and parses the config into the form equivalent to what all the add_driver_config function calls are doing atm? I guess you would also provide the driver class name so the manifest knows which directory to search.

The main thing is that we will need to rejig this all soon anyway. Fundamentally the sdf_gen model isn't really any good for handling dependencies or per-board deviations. The goal here for me was to basically do the same thing minimally for now

omeh-a added 2 commits August 6, 2026 15:56
… update classes to respect this. Minor changes to api; got rid of (perilous) manual call to create resources

Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>
Signed-off-by: Lesley Rossouw <lesley.rossouw@unsw.edu.au>
Comment thread acacia_sddf/board.py


@dataclass
class Board:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we remove the board.py indirection? This seems to duplicate information already present in the DTB which is never ideal since a human has to do this and is likely to make mistakes (such as the zcu paddr being wrong previously).

This is probably a consideration independent of this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Per other comment I replied to, basically yes we can, and we probably should, but that's something that is beyond the scope of just adding Acacia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

driver-examples Issues related to examples for drivers for a target drivers Issues pertaining to driver code for a device class i2c serial timer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants