BUS_MAP_RESOURCE(9)
π BUS_MAP_RESOURCE(9) π
okay bestie, so this is a page from the Kernel Developer's Manual and it's all about bus_map_resource, bus_unmap_resource, and resource_init_map_request β aka the glow-up that lets your CPU actually touch a resource. slay.
β¨ NAME β¨
bus_map_resource, bus_unmap_resource, resource_init_map_request β map or unmap an active resource πΊοΈ
πΈ SYNOPSIS πΈ
#include <sys/param.h>
#include <sys/bus.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
int
bus_map_resource(device_t dev, int type, struct resource *r,
struct resource_map_request *args, struct resource_map *map);
int
bus_unmap_resource(device_t dev, int type, struct resource *r,
struct resource_map *map);
void
resource_init_map_request(struct resource_map_request *args);
π¦ DESCRIPTION π¦
so these functions either create or destroy a mapping of a resource that you already activated earlier. no cap. and like, what even is a mapping? it's the thing that lets the CPU get in there via the bus_space(9) API. it's giving backstage pass energy. π
the arguments, bestie, are as follows:
devβ the device that owns the resource. it's the main character here honestly.typeβ the type of resource to map. it's one of:SYS_RES_IOPORTβ for I/O portsSYS_RES_MEMORYβ for I/O memory
rβ a pointer to thestruct resourcethatbus_alloc_resource(9)handed you.argsβ a lil set of optional properties to apply when you create a mapping. you can set this toNULLif you want a mapping of the entire resource with the default properties. no thoughts, just vibes.mapβ the resource mapping you're creating or destroying.
π«Ά Resource Mappings
resource mappings are described by a struct resource_map object. this structure contains a bus_space(9) tag and handle in the r_bustag and r_bushandle members, and those are what you use for CPU access to the mapping. it also contains a r_vaddr member, which holds the virtual address of the mapping if one even exists. π
the wrapper API for struct resource objects described in bus_activate_resource(9) can also be used with struct resource_map. for example, you can pass a pointer to a mapping object as the first argument to bus_read_4(). and honestly? that wrapper API is preferred over poking r_bustag and r_bushandle directly. periodt. π
π Optional Mapping Properties
the struct resource_map_request object you pass in args is how you specify optional properties of a mapping. you must initialize the structure first by invoking resource_init_map_request(). after that, you set one or more of these members:
offset,lengthβ these two members specify a region of the resource to map. by default a mapping gets created for the entire resource. the offset is relative to the start of the resource. π―memattrβ specifies a memory attribute to use when mapping the resource. by default, memory mappings use theVM_MEMATTR_UNCACHEABLEattribute. iykyk.
β RETURN VALUES β
zero is returned on success. otherwise an error is returned. that's it, that's the tea. π
π₯ EXAMPLES π₯
this maps a PCI memory BAR with the write-combining memory attribute and reads the first 32-bit word. iconic behaviour, honestly:
struct resource *r;
struct resource_map map;
struct resource_map_request req;
uint32_t val;
int rid;
rid = PCIR_BAR(0);
r = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE |
RF_UNMAPPED);
resource_init_map_request(&req);
req.memattr = VM_MEMATTR_WRITE_COMBINING;
bus_map_resource(dev, SYS_RES_MEMORY, r, &req, &map);
val = bus_read_4(&map, 0);
π SEE ALSO π
bus_activate_resource(9), bus_alloc_resource(9), bus_space(9), device(9), driver(9)
go read those next bestie, fr fr. πβ¨
π AUTHORS π
this manual page was written by John Baldwin <jhb@FreeBSD.org>. thank you king πββοΈπ
and that's the whole page, bestie!! this one came from Debian, dated February 5, 2018, and it lives under the name BUS_MAP_RESOURCE(9). mwah, go map some resources responsibly π
πβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2016 John H. Baldwin <jhb@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms