BUS_ADJUST_RESOURCE(9)

πŸ’… BUS_ADJUST_RESOURCE(9) πŸ’…

ok so bestie, this is a page from the Kernel Developer's Manual, and today's main character is bus_adjust_resource β€” she adjusts resources that got allocated from a parent bus. yes she's niche. yes she's iconic. let's get into it πŸŽ€


✨ NAME ✨

bus_adjust_resource β€” adjust resource allocated from a parent bus

like. the whole vibe is "hey parent bus, can we move this thing a lil bit" πŸ¦‹


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/bus.h>

#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>

int
bus_adjust_resource(device_t dev, int type, struct resource *r,
    rman_res_t start, rman_res_t end);

look at those includes. four files. she's high maintenance and she's worth it πŸ’–


✨ DESCRIPTION ✨

okay so here's the tea β˜• β€” this function is literally you going up to the parent bus and being like "hi bestie, can we adjust the resource range assigned to this resource i already allocated?" and the parent bus is like "bet."

the resource r should have been allocated by a previous call to bus_alloc_resource(9). no bootlegging. no vibes-based resources. you gotta have actually gotten it from there first 🫢

the new resource range must overlap the existing range of r. that's not a suggestion, that's the law. if it doesn't overlap, we're not doing this (see ERRORS, she will not be happy).

and the type argument? it should match the type argument you passed to bus_alloc_resource(9) back when the resource was initially allocated. consistency is the whole aesthetic, fr fr ✨

🚨 okay this is the important part, do NOT skip it β€” none of the constraints of the original allocation request β€” like alignment or boundary restrictions β€” are checked by bus_adjust_resource(). she does not check them. she will not check them. it is the caller's responsibility to enforce any such requirements. that's you. you're the caller. it's giving main character energy and also it's giving "you're on your own, babe" 😭

✨ RETURN VALUES ✨

the bus_adjust_resource() method returns zero on success or an error code on failure.

zero = slay. error code = not slay but at least she told you πŸ’€


✨ EXAMPLES ✨

here's a lil demo where we grow an existing memory resource by 4096 bytes. glow up, but make it hardware 🧚

struct resource *res;
int error;

error = bus_adjust_resource(dev, SYS_RES_MEMORY, res,
    rman_get_start(res), rman_get_end(res) + 0x1000);

look at that + 0x1000. that's 4096 in hex. she ate that πŸ’…


✨ ERRORS ✨

bus_adjust_resource() will fail if:

  • [EINVAL] β€” The dev device does not have a parent device. orphan behavior. no parent, no adjustment, no service πŸ₯²
  • [EINVAL] β€” The r resource is a shared resource. sharing is caring but not here bestie, she said no 🚫
  • [EINVAL] β€” The new address range does not overlap with the existing address range of r. remember that whole overlap rule from DESCRIPTION? yeah. this is what happens when you ignore it 😀
  • [EBUSY] β€” The new address range conflicts with another allocated resource. somebody else already called dibs. respectfully, find another range 🌸

✨ SEE ALSO ✨

the whole friend group 🫢 go read them too, they're all valid


and that's the whole page, bestie!! no cap, you now understand bus_adjust_resource better than like 90% of people who have ever typed rman_res_t. periodt. πŸ’–

this one came from <strong>Debian</strong>, dated <strong>April 23, 2016</strong> β€” yes she's an elder but she's still serving looks ✨ go forth and adjust responsibly, and remember: overlap the range, match the type, and enforce your own alignment constraints like a grown-up πŸŒˆπŸ’œ

πŸ“¦ where this page comes from