19092a4bcSAlexander Langer.\" -*- nroff -*- 29092a4bcSAlexander Langer.\" 39092a4bcSAlexander Langer.\" Copyright (c) 2000 Alexander Langer 49092a4bcSAlexander Langer.\" 59092a4bcSAlexander Langer.\" All rights reserved. 69092a4bcSAlexander Langer.\" 79092a4bcSAlexander Langer.\" This program is free software. 89092a4bcSAlexander Langer.\" 99092a4bcSAlexander Langer.\" Redistribution and use in source and binary forms, with or without 109092a4bcSAlexander Langer.\" modification, are permitted provided that the following conditions 119092a4bcSAlexander Langer.\" are met: 129092a4bcSAlexander Langer.\" 1. Redistributions of source code must retain the above copyright 139092a4bcSAlexander Langer.\" notice, this list of conditions and the following disclaimer. 149092a4bcSAlexander Langer.\" 2. Redistributions in binary form must reproduce the above copyright 159092a4bcSAlexander Langer.\" notice, this list of conditions and the following disclaimer in the 169092a4bcSAlexander Langer.\" documentation and/or other materials provided with the distribution. 179092a4bcSAlexander Langer.\" 189092a4bcSAlexander Langer.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 199092a4bcSAlexander Langer.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 209092a4bcSAlexander Langer.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 219092a4bcSAlexander Langer.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 229092a4bcSAlexander Langer.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 239092a4bcSAlexander Langer.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 249092a4bcSAlexander Langer.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 259092a4bcSAlexander Langer.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 269092a4bcSAlexander Langer.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 279092a4bcSAlexander Langer.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 289092a4bcSAlexander Langer.\" 29cc981af2SJohn Baldwin.Dd May 20, 2016 309092a4bcSAlexander Langer.Dt BUS_ALLOC_RESOURCE 9 313d45e180SRuslan Ermilov.Os 329092a4bcSAlexander Langer.Sh NAME 33bdffb39fSNate Lawson.Nm bus_alloc_resource , 34*7eadf512SEnji Cooper.Nm bus_alloc_resource_any , 35ac6c1372SJustin Hibbits.Nm bus_alloc_resource_anywhere 368c307294SMike Makonnen.Nd allocate resources from a parent bus 379092a4bcSAlexander Langer.Sh SYNOPSIS 3832eef9aeSRuslan Ermilov.In sys/param.h 3932eef9aeSRuslan Ermilov.In sys/bus.h 40a10f4352SBruce Evans.Pp 4132eef9aeSRuslan Ermilov.In machine/bus.h 4232eef9aeSRuslan Ermilov.In sys/rman.h 4332eef9aeSRuslan Ermilov.In machine/resource.h 449092a4bcSAlexander Langer.Ft struct resource * 452dd1bdf1SJustin Hibbits.Fo bus_alloc_resource 462dd1bdf1SJustin Hibbits.Fa "device_t dev" "int type" "int *rid" "rman_res_t start" "rman_res_t end" 472dd1bdf1SJustin Hibbits.Fa "rman_res_t count" "u_int flags" 482dd1bdf1SJustin Hibbits.Fc 49bdffb39fSNate Lawson.Ft struct resource * 50bdffb39fSNate Lawson.Fn bus_alloc_resource_any "device_t dev" "int type" "int *rid" "u_int flags" 51ac6c1372SJustin Hibbits.Ft struct resource * 52ee9e0ce4SChristian Brueffer.Fo bus_alloc_resource_anywhere 53ee9e0ce4SChristian Brueffer.Fa "device_t dev" "int type" "int *rid" "rman_res_t count" "u_int flags" 54ee9e0ce4SChristian Brueffer.Fc 559092a4bcSAlexander Langer.Sh DESCRIPTION 569092a4bcSAlexander LangerThis is an easy interface to the resource-management functions. 579092a4bcSAlexander LangerIt hides the indirection through the parent's method table. 589092a4bcSAlexander LangerThis function generally should be called in attach, but (except in some 59c4ac3bc5SWarner Loshrare cases) never earlier. 609092a4bcSAlexander Langer.Pp 61bdffb39fSNate LawsonThe 62bdffb39fSNate Lawson.Fn bus_alloc_resource_any 63ac6c1372SJustin Hibbitsand 64ac6c1372SJustin Hibbits.Fn bus_alloc_resource_anywhere 65ac6c1372SJustin Hibbitsfunctions are convenience wrappers for 66bdffb39fSNate Lawson.Fn bus_alloc_resource . 67ac6c1372SJustin Hibbits.Fn bus_alloc_resource_any 68ac6c1372SJustin Hibbitssets 69bdffb39fSNate Lawson.Fa start , 70bdffb39fSNate Lawson.Fa end , 71bdffb39fSNate Lawsonand 72bdffb39fSNate Lawson.Fa count 73bdffb39fSNate Lawsonto the default resource (see description of 74bdffb39fSNate Lawson.Fa start 75bdffb39fSNate Lawsonbelow). 76ac6c1372SJustin Hibbits.Fn bus_alloc_resource_anywhere 77ac6c1372SJustin Hibbitssets 78ac6c1372SJustin Hibbits.Fa start 79ac6c1372SJustin Hibbitsand 80ac6c1372SJustin Hibbits.Fa end 81ac6c1372SJustin Hibbitsto the default resource and uses the provided 82ac6c1372SJustin Hibbits.Fa count 83ac6c1372SJustin Hibbitsargument. 84bdffb39fSNate Lawson.Pp 85bdffb39fSNate LawsonThe arguments are as follows: 869092a4bcSAlexander Langer.Bl -item 879092a4bcSAlexander Langer.It 889092a4bcSAlexander Langer.Fa dev 899092a4bcSAlexander Langeris the device that requests ownership of the resource. 9029c92779SJeroen Ruigrok van der WervenBefore allocation, the resource is owned by the parent bus. 919092a4bcSAlexander Langer.It 929092a4bcSAlexander Langer.Fa type 939092a4bcSAlexander Langeris the type of resource you want to allocate. 949092a4bcSAlexander LangerIt is one of: 959092a4bcSAlexander Langer.Bl -tag -width SYS_RES_MEMORY 9655c661caSJohn Baldwin.It Dv PCI_RES_BUS 9755c661caSJohn Baldwinfor PCI bus numbers 989092a4bcSAlexander Langer.It Dv SYS_RES_IRQ 999092a4bcSAlexander Langerfor IRQs 1009092a4bcSAlexander Langer.It Dv SYS_RES_DRQ 1019092a4bcSAlexander Langerfor ISA DMA lines 1029092a4bcSAlexander Langer.It Dv SYS_RES_IOPORT 1039092a4bcSAlexander Langerfor I/O ports 1049092a4bcSAlexander Langer.It Dv SYS_RES_MEMORY 1059092a4bcSAlexander Langerfor I/O memory 1069092a4bcSAlexander Langer.El 1079092a4bcSAlexander Langer.It 1089092a4bcSAlexander Langer.Fa rid 1099092a4bcSAlexander Langerpoints to a bus specific handle that identifies the resource being allocated. 1109092a4bcSAlexander LangerFor ISA this is an index into an array of resources that have been setup 1119092a4bcSAlexander Langerfor this device by either the PnP mechanism, or via the hints mechanism. 11281c968ebSWarner LoshFor PCCARD, this is an index into the array of resources described by the PC Card's 11381c968ebSWarner LoshCIS entry. 11455c661caSJohn BaldwinFor PCI, the offset into PCI config space which has the BAR to use to access 11581c968ebSWarner Loshthe resource. 1169092a4bcSAlexander LangerThe bus methods are free to change the RIDs that they are given as a parameter. 1179092a4bcSAlexander LangerYou must not depend on the value you gave it earlier. 1189092a4bcSAlexander Langer.It 1199092a4bcSAlexander Langer.Fa start 1209092a4bcSAlexander Langerand 1219092a4bcSAlexander Langer.Fa end 1229092a4bcSAlexander Langerare the start/end addresses of the resource. 123ba4594dcSNate LawsonIf you specify values of 0ul for 124c4ac3bc5SWarner Losh.Fa start 125ba4594dcSNate Lawsonand ~0ul for 126c4ac3bc5SWarner Losh.Fa end 127c8185672SRuslan Ermilovand 1 for 128c4ac3bc5SWarner Losh.Fa count , 129c4ac3bc5SWarner Loshthe default values for the bus are calculated. 1309092a4bcSAlexander Langer.It 1319092a4bcSAlexander Langer.Fa count 132ba4594dcSNate Lawsonis the size of the resource. 133ba4594dcSNate LawsonFor example, the size of an I/O port is usually 1 byte (but some devices 134ba4594dcSNate Lawsonoverride this). 135aa3524dbSAlexander LangerIf you specified the default values for 1369092a4bcSAlexander Langer.Fa start 1379092a4bcSAlexander Langerand 1389092a4bcSAlexander Langer.Fa end , 1399092a4bcSAlexander Langerthen the default value of the bus is used if 1409092a4bcSAlexander Langer.Fa count 1419092a4bcSAlexander Langeris smaller than the default value and 1429092a4bcSAlexander Langer.Fa count 143ba4594dcSNate Lawsonis used, if it is bigger than the default value. 1449092a4bcSAlexander Langer.It 1459092a4bcSAlexander Langer.Fa flags 146aa3524dbSAlexander Langersets the flags for the resource. 147aa3524dbSAlexander LangerYou can set one or more of these flags: 1489092a4bcSAlexander Langer.Bl -tag -width RF_SHAREABLE 1499092a4bcSAlexander Langer.It Dv RF_ALLOCATED 1509092a4bcSAlexander Langerresource has been reserved. 1519092a4bcSAlexander LangerThe resource still needs to be activated with 152c4ac3bc5SWarner Losh.Xr bus_activate_resource 9 . 1539092a4bcSAlexander Langer.It Dv RF_ACTIVE 1549092a4bcSAlexander Langeractivate resource atomically. 1559a1be350SJohn Baldwin.It Dv RF_PREFETCHABLE 1569a1be350SJohn Baldwinresource is prefetchable. 1579092a4bcSAlexander Langer.It Dv RF_SHAREABLE 1589092a4bcSAlexander Langerresource permits contemporaneous sharing. 159ba4594dcSNate LawsonIt should always be set unless you know that the resource cannot be shared. 160bf7f20c2SRuslan ErmilovIt is the bus driver's task to filter out the flag if the bus does not 161ba4594dcSNate Lawsonsupport sharing. 162ba4594dcSNate LawsonFor example, 163ba4594dcSNate Lawson.Xr pccard 4 164ba4594dcSNate Lawsoncannot share IRQs while 165ba4594dcSNate Lawson.Xr cardbus 4 166ba4594dcSNate Lawsoncan. 167cc981af2SJohn Baldwin.It Dv RF_UNMAPPED 168cc981af2SJohn Baldwindo not establish implicit mapping when activated via 169cc981af2SJohn Baldwin.Xr bus_activate_resource 9 . 1709092a4bcSAlexander Langer.El 1719092a4bcSAlexander Langer.El 1729092a4bcSAlexander Langer.Sh RETURN VALUES 1739092a4bcSAlexander LangerA pointer to 174ada6ba6eSJohn-Mark Gurney.Va struct resource 1759092a4bcSAlexander Langeris returned on success, a null pointer otherwise. 1769092a4bcSAlexander Langer.Sh EXAMPLES 177ab27179eSWarner LoshThis is some example code that allocates a 32 byte I/O port range and an IRQ. 178aa3524dbSAlexander LangerThe values of 1799092a4bcSAlexander Langer.Va portid 1809092a4bcSAlexander Langerand 1819092a4bcSAlexander Langer.Va irqid 1829092a4bcSAlexander Langershould be saved in the softc of the device after these calls. 1839092a4bcSAlexander Langer.Bd -literal 184fff86fc4SBrian Somers struct resource *portres, *irqres; 1859092a4bcSAlexander Langer int portid, irqid; 1869092a4bcSAlexander Langer 1879092a4bcSAlexander Langer portid = 0; 1889092a4bcSAlexander Langer irqid = 0; 1899092a4bcSAlexander Langer portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &portid, 190ab27179eSWarner Losh 0ul, ~0ul, 32, RF_ACTIVE); 191bdffb39fSNate Lawson irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &irqid, 192bdffb39fSNate Lawson RF_ACTIVE | RF_SHAREABLE); 1939092a4bcSAlexander Langer.Ed 1949092a4bcSAlexander Langer.Sh SEE ALSO 195c4ac3bc5SWarner Losh.Xr bus_activate_resource 9 , 19685ee63c9SJohn Baldwin.Xr bus_adjust_resource 9 , 197cc981af2SJohn Baldwin.Xr bus_map_resource 9 , 1985521ff5aSRuslan Ermilov.Xr bus_release_resource 9 , 1999092a4bcSAlexander Langer.Xr device 9 , 2005521ff5aSRuslan Ermilov.Xr driver 9 2019092a4bcSAlexander Langer.Sh AUTHORS 202f4d874a1SRuslan Ermilov.An -nosplit 203571dba6eSHiten PandyaThis manual page was written by 2048a7314fcSBaptiste Daroussin.An Alexander Langer Aq Mt alex@big.endian.de 2059092a4bcSAlexander Langerwith parts by 2068a7314fcSBaptiste Daroussin.An Warner Losh Aq Mt imp@FreeBSD.org . 207