Updated: October 28, 2024 |
Use the hwi_alloc_tag() and hwi_alloc_item() functions to add tags and items to the hwinfo section of the system page.
To build an item:
You can build the items in any order you wish, provided that the parent is built before the child.
When building a child item, if you remembered its owner only in a variable, or you know only its item name, you can find the correct value of the owner argument by calling the hwi_find_item() function.
Before main() is invoked in the startup program, the library adds some initial entries to serve as a basis for later items.
HWI_TAG_INFO() is a macro defined in the startup.h header and expands out to the three name, size, align parameters for hwi_alloc_tag() and hwi_alloc_item() based on some clever macro names.
void hwi_default() { hwi_tag *tag; hwi_tag *tag; hwi_alloc_item(HWI_TAG_INFO(group), HWI_ITEM_ROOT_AS, HWI_NULL_OFF); tag = hwi_alloc_item(HWI_TAG_INFO(group), HWI_ITEM_ROOT_HW, HWI_NULL_OFF); hwi_alloc_item(HWI_TAG_INFO(bus), HWI_ITEM_BUS_UNKNOWN, hwi_tag2off(tag)); loc = hwi_find_item(HWI_NULL_OFF, HWI_ITEM_ROOT_AS, NULL); tag = hwi_alloc_item(HWI_TAG_INFO(addrspace), HWI_ITEM_AS_MEMORY, loc); tag->addrspace.base = 0; tag->addrspace.len = (uint64_t)1 << 32; #ifndef __X86__ loc = hwi_tag2off(tag); #endif tag = hwi_alloc_item(HWI_TAG_INFO(addrspace), HWI_ITEM_AS_IO, loc); tag->addrspace.base = 0; #ifdef __X86__ tag->addrspace.len = (uint64_t)1 << 16; #else tag->addrspace.len = (uint64_t)1 << 32; #endif }
Given a pointer to the start of a tag, return the offset, in bytes, from the start of the hwinfo section.
Given an offset, in bytes, from the start of the hwinfo section, return a pointer to the start of the tag.
Find the tag named tagname. The start parameter works the same as in hwi_find_item(). The curr_item parameter restricts the search to the current item. If this parameter is nonzero, the search stops at the end of the item that start points to. If curr_item is zero, the search continues until the end of the section. If the tag isn't found, HWI_NULL_OFF is returned.
Get the offset of the next item after the given offset from the start of the hwinfo section.
Get the offset of the next tag after the given offset from the start of the hwinfo section. As it is for hwi_find_tag(), curr_item restricts the search to the current item.