man.bsd.lv manual page server

Manual Page Search Parameters

BUS_ALLOC_RESOURCE(9) Kernel Developer's Manual BUS_ALLOC_RESOURCE(9)

bus_alloc_resource, bus_alloc_resource_any, bus_alloc_resource_anywhereallocate resources from a parent bus

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


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

struct resource *
bus_alloc_resource(device_t dev, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags);

struct resource *
bus_alloc_resource_any(device_t dev, int type, int *rid, u_int flags);

struct resource *
bus_alloc_resource_anywhere(device_t dev, int type, int *rid, rman_res_t count, u_int flags);

This is an easy interface to the resource-management functions. It hides the indirection through the parent's method table. This function generally should be called in attach, but (except in some rare cases) never earlier.

The () and () functions are convenience wrappers for (). bus_alloc_resource_any() sets start, end, and count to the default resource (see description of start below). bus_alloc_resource_anywhere() sets start and end to the default resource and uses the provided count argument.

The arguments are as follows:

A pointer to struct resource is returned on success, a null pointer otherwise.

This is some example code that allocates a 32 byte I/O port range and an IRQ. The values of portid and irqid should be saved in the softc of the device after these calls.

	struct resource *portres, *irqres;
	int portid, irqid;

	portid = 0;
	irqid = 0;
	portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &portid,
			0ul, ~0ul, 32, RF_ACTIVE);
	irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &irqid,
			RF_ACTIVE | RF_SHAREABLE);

bus_activate_resource(9), bus_adjust_resource(9), bus_map_resource(9), bus_release_resource(9), device(9), driver(9)

This manual page was written by Alexander Langer <alex@big.endian.de> with parts by Warner Losh <imp@FreeBSD.org>.

May 20, 2016 FreeBSD-12.0