1.\" Copyright (c) 2000 Alexander Langer 2.\" 3.\" All rights reserved. 4.\" 5.\" This program is free software. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.\" 27.\" $FreeBSD: src/share/man/man9/bus_alloc_resource.9,v 1.2.2.10 2004/03/17 17:54:24 njl Exp $ 28.\" 29.Dd May 18, 2000 30.Dt BUS_ALLOC_RESOURCE 9 31.Os 32.Sh NAME 33.Nm bus_alloc_resource , 34.Nm bus_alloc_resource_any 35.Nd alloc resources on a bus 36.Sh SYNOPSIS 37.In sys/param.h 38.In sys/bus.h 39.Pp 40.In sys/rman.h 41.In sys/resource.h 42.Ft struct resource * 43.Fn bus_alloc_resource "device_t dev" "int type" "int *rid" "u_long start" "u_long end" "u_long count" "u_int flags" 44.Ft struct resource * 45.Fn bus_alloc_resource_any "device_t dev" "int type" "int *rid" "u_int flags" 46.Sh DESCRIPTION 47This is an easy interface to the resource-management functions. 48It hides the indirection through the parent's method table. 49This function generally should be called in attach, but (except in some 50race cases) never earlier. 51.Pp 52The 53.Fn bus_alloc_resource_any 54function is a convenience wrapper for 55.Fn bus_alloc_resource . 56It sets the values for 57.Fa start , 58.Fa end , 59and 60.Fa count 61to the default resource (see description of 62.Fa start 63below). 64.Pp 65The arguments are as follows: 66.Bl -item 67.It 68.Fa dev 69is the device that requests ownership of the resource. 70Before allocation, the resource is owned by the parent bus. 71.It 72.Fa type 73is the type of resource you want to allocate. 74It is one of: 75.Bl -tag -width ".Dv SYS_RES_MEMORY" 76.It Dv SYS_RES_IRQ 77for IRQs 78.It Dv SYS_RES_DRQ 79for ISA DMA lines 80.It Dv SYS_RES_IOPORT 81for I/O ports 82.It Dv SYS_RES_MEMORY 83for I/O memory 84.El 85.It 86.Fa rid 87points to a bus specific handle that identifies the resource being allocated. 88For ISA this is an index into an array of resources that have been setup 89for this device by either the PnP mechanism, or via the hints mechanism. 90For PCCARD, similar things are used as of writing, 91but that may change in the future with newcard. 92For PCI it just happens to be the offset into pci config space which has 93a word that describes the resource. 94The bus methods are free to change the RIDs that they are given as a parameter. 95You must not depend on the value you gave it earlier. 96.It 97.Fa start 98and 99.Fa end 100are the start/end addresses of the resource. 101If you specify values of 102.Dv 0 103for start and 104.Dv ~0 105for end, the default values for the bus are calculated. 106.It 107.Fa count 108is the size of the resource, e.g. the size of an I/O port (often 109.Dv 1 110on PCI and device-dependent on ISA and PCCARD). 111If you specified the default values for 112.Fa start 113and 114.Fa end , 115then the default value of the bus is used if 116.Fa count 117is smaller than the default value and 118.Fa count 119is used, if it is bigger than the default value. 120.It 121.Fa flags 122sets the flags for the resource. 123You can set one or more of these flags: 124.Bl -tag -width ".Dv RF_SHAREABLE" 125.It Dv RF_ALLOCATED 126resource has been reserved. 127The resource still needs to be activated with 128.Xr rman_activate_resource 9 . 129.It Dv RF_ACTIVE 130activate resource atomically. 131.It Dv RF_SHAREABLE 132resource permits contemporaneous sharing. 133Should always be set unless you know, that the resource cannot be shared. 134It is the bus-code's task to filter out the flag if the bus doesn't 135support sharing, which is, for example, the case for pccard/cardbus, 136which can or cannot share devices, depending on the bus. 137.It Dv RF_TIMESHARE 138resource permits time-division sharing. 139.El 140.El 141.Sh RETURN VALUES 142A pointer to 143.Va struct res 144is returned on success, a null pointer otherwise. 145.Sh EXAMPLES 146This is some example code. 147The values of 148.Va portid 149and 150.Va irqid 151should be saved in the softc of the device after these calls. 152.Bd -literal 153 struct resource *portres, irqres; 154 int portid, irqid; 155 156 portid = 0; 157 irqid = 0; 158 portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &portid, 159 0ul, ~0ul, 32, RF_ACTIVE); 160 irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &irqid, 161 RF_ACTIVE | RF_SHAREABLE); 162.Ed 163.Sh SEE ALSO 164.Xr bus_release_resource 9 , 165.Xr device 9 , 166.Xr driver 9 167.Sh AUTHORS 168.An -nosplit 169This man page was written by 170.An Alexander Langer Aq alex@big.endian.de 171with parts by 172.An Warner Losh Aq imp@FreeBSD.org . 173