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