Copyright (c) 2000 Alexander Langer All rights reserved. This program is free software. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaim...
NAMEbus_alloc_resource bus_alloc_resource_any bus_alloc_resource_anywhere - allocate resources from a parent bus
SYNOPSISIn sys/param.h In sys/bus.h
In machine/bus.h In sys/rman.h In machine/resource.h Ft struct resource * Fo bus_alloc_resource Fa device_t dev int type int *rid rman_res_t start rman_res_t end Fa rman_res_t count u_int flags Fc Ft struct resource * Fn bus_alloc_resource_any device_t dev int type int *rid u_int flags Ft struct resource * Fo bus_alloc_resource_anywhere Fa device_t dev int type int *rid rman_res_t count u_int flags Fc
DESCRIPTIONThis 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 Fn bus_alloc_resource_any and Fn bus_alloc_resource_anywhere functions are convenience wrappers for Fn bus_alloc_resource . Fn bus_alloc_resource_any sets Fa start , Fa end , and Fa count to the default resource (see description of Fa start below). Fn bus_alloc_resource_anywhere sets Fa start and Fa end to the default resource and uses the provided Fa count argument.
The arguments are as follows:
- Fa dev
- is the device that requests ownership of the resource. Before allocation, the resource is owned by the parent bus.
- Fa type
is the type of resource you want to allocate.
It is one of:
- for PCI bus numbers
- for IRQs
- for ISA DMA lines
- for I/O ports
- for I/O memory
- Fa rid
- points to a bus specific handle that identifies the resource being allocated. For ISA this is an index into an array of resources that have been setup for this device by either the PnP mechanism, or via the hints mechanism. For PCCARD, this is an index into the array of resources described by the PC Card's CIS entry. For PCI, the offset into PCI config space which has the BAR to use to access the resource. The bus methods are free to change the RIDs that they are given as a parameter. You must not depend on the value you gave it earlier.
- Fa start
- and Fa end are the start/end addresses of the resource. If you specify values of 0ul for Fa start and ~0ul for Fa end and 1 for Fa count , the default values for the bus are calculated.
- Fa count
- is the size of the resource. For example, the size of an I/O port is usually 1 byte (but some devices override this). If you specified the default values for Fa start and Fa end , then the default value of the bus is used if Fa count is smaller than the default value and Fa count is used, if it is bigger than the default value.
- Fa flags
sets the flags for the resource.
You can set one or more of these flags:
- resource has been reserved. The resource still needs to be activated with bus_activate_resource9.
- activate resource atomically.
- resource is prefetchable.
- resource permits contemporaneous sharing. It should always be set unless you know that the resource cannot be shared. It is the bus driver's task to filter out the flag if the bus does not support sharing. For example, pccard(4) cannot share IRQs while cardbus(4) can.
- do not establish implicit mapping when activated via bus_activate_resource9.
RETURN VALUESA pointer to struct resource is returned on success, a null pointer otherwise.
EXAMPLESThis 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);