BUS_ACTIVATE_RESOURCE(9)
π BUS_ACTIVATE_RESOURCE(9) β the kernel dev manual, bestie edition
okay so this is a page from the Kernel Developer's Manual, and we're talking about bus_activate_resource(9) β the whole glow-up of a resource from "allocated" to "actually usable." buckle up π
β¨ NAME β¨
bus_activate_resource, bus_deactivate_resource β activate or deactivate a resource. that's it, that's the vibe. on and off. the light switch of kernel resources π‘
πΈ SYNOPSIS πΈ
#include <sys/param.h>
#include <sys/bus.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
int
bus_activate_resource(device_t dev, struct resource *r);
int
bus_deactivate_resource(device_t dev, struct resource *r);
yes bestie, all five includes. every single one. they're all invited to the function signature party π«Ά
π DESCRIPTION π
so these two functions activate or deactivate a resource you already allocated earlier. lowkey the important part: in general, resources must be activated before they can be accessed by the driver. like, no activation, no access. that's the rule, fr fr.
bus drivers may do extra little side quests to make sure the resource is genuinely ready to be accessed. iconic example: the PCI bus driver enables memory decoding in a PCI device's command register when it activates a memory resource. slay π
the arguments, bestie β respect them:
devβ the device that's requesting ownership of the resource. and note this: before allocation, the resource is owned by the parent bus. so it's a whole custody situation πrβ a pointer to thestruct resourcereturned bybus_alloc_resource(9). that's where you got it, that's who you thank.
π¦ Resource Mapping π¦
okay this part is kind of the main character. resources that can be mapped for CPU access by a bus_space(9) tag and handle will create a mapping of the entire resource when activated. the whole thing. no crumbs π
the tag and handle for this mapping live inside r, and you can retrieve them via rman_get_bustag(9) and rman_get_bushandle(9). then you can use them with the bus_space(9) API to access device registers or memory described by r. and if the mapping is associated with a virtual address, you get that virtual address via rman_get_virtual(9). it's giving full access package β¨
not feeling the implicit mapping? totally valid. you can disable it by passing the RF_UNMAPPED flag to bus_alloc_resource(9). a driver might do this if it wants to allocate its own mappings of a resource using bus_map_resource(9). DIY energy, we respect it π οΈ
there's also a wrapper API for bus_space(9) that takes the associated resource as the first argument instead of the bus_space(9) tag and handle. the functions in this wrapper API are named similarly to the bus_space(9) API, except that β_spaceβ is removed from their name. so for example, bus_read_4() can be used in place of bus_space_read_4(). and listen β the wrapper API is preferred in new drivers. new drivers, take notes π
these two statements both read a 32-bit register at the start of a resource, no cap:
bus_space_read_4(rman_get_bustag(res), rman_get_bushandle(res), 0);
bus_read_4(res, 0);
same result, but one of them is the aesthetic choice π
π₯ RETURN VALUES π₯
zero is returned on success. otherwise, an error is returned. that's it. 0 = slay, anything else = not slay π
π SEE ALSO π
the whole friend group, honestly π«Ά
π AUTHORS π
this manual page was written by Warner Losh <imp@FreeBSD.org>. king behavior, thank you for your service π
π friendly reminder bestie: activate before you access. the manpage said it, not me.
and that's the page!! this edition came from Debian, dated March 13, 2024 β mwah, bye bestie, go activate some resources πβ¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2003 M. Warner Losh <imp@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms