Skip to content

Commit fef01f0

Browse files
committed
new-bus: Remove the 'type' argument from BUS_ADJUST_RESOURCE
The public bus_adjust_resource() API still accepts both forms, but the internal kobj method no longer passes the argument. Implementations which need the type now use rman_get_type() to fetch the value from the allocated resource. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D44128
1 parent 582b84c commit fef01f0

File tree

28 files changed

+117
-152
lines changed

28 files changed

+117
-152
lines changed

share/man/man9/bus_adjust_resource.9

+4-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd April 23, 2016
28+
.Dd March 13, 2024
2929
.Dt BUS_ADJUST_RESOURCE 9
3030
.Os
3131
.Sh NAME
@@ -40,7 +40,7 @@
4040
.In machine/resource.h
4141
.Ft int
4242
.Fo bus_adjust_resource
43-
.Fa "device_t dev" "int type" "struct resource *r"
43+
.Fa "device_t dev" "struct resource *r"
4444
.Fa "rman_res_t start" "rman_res_t end"
4545
.Fc
4646
.Sh DESCRIPTION
@@ -52,13 +52,6 @@ should have been allocated by a previous call to
5252
.Xr bus_alloc_resource 9 .
5353
The new resource range must overlap the existing range of
5454
.Fa r .
55-
The
56-
.Fa type
57-
argument should match the
58-
.Fa type
59-
argument passed to
60-
.Xr bus_alloc_resource 9
61-
when the resource was initially allocated.
6255
.Pp
6356
Note that none of the constraints of the original allocation request such
6457
as alignment or boundary restrictions are checked by
@@ -74,8 +67,8 @@ Grow an existing memory resource by 4096 bytes.
7467
struct resource *res;
7568
int error;
7669

77-
error = bus_adjust_resource(dev, SYS_RES_MEMORY, res,
78-
rman_get_start(res), rman_get_end(res) + 0x1000);
70+
error = bus_adjust_resource(dev, res, rman_get_start(res),
71+
rman_get_end(res) + 0x1000);
7972
.Ed
8073
.Sh ERRORS
8174
.Fn bus_adjust_resource

sys/arm/mv/mv_pci.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static int mv_pcib_attach(device_t);
345345
static struct rman *mv_pcib_get_rman(device_t, int, u_int);
346346
static struct resource *mv_pcib_alloc_resource(device_t, device_t, int, int *,
347347
rman_res_t, rman_res_t, rman_res_t, u_int);
348-
static int mv_pcib_adjust_resource(device_t, device_t, int, struct resource *,
348+
static int mv_pcib_adjust_resource(device_t, device_t, struct resource *,
349349
rman_res_t, rman_res_t);
350350
static int mv_pcib_release_resource(device_t, device_t, int, int,
351351
struct resource *);
@@ -941,26 +941,25 @@ mv_pcib_alloc_resource(device_t dev, device_t child, int type, int *rid,
941941
}
942942

943943
static int
944-
mv_pcib_adjust_resource(device_t dev, device_t child, int type,
944+
mv_pcib_adjust_resource(device_t dev, device_t child,
945945
struct resource *r, rman_res_t start, rman_res_t end)
946946
{
947947
#ifdef PCI_RES_BUS
948948
struct mv_pcib_softc *sc = device_get_softc(dev);
949949
#endif
950950

951-
switch (type) {
951+
switch (rman_get_type(r)) {
952952
case SYS_RES_IOPORT:
953953
case SYS_RES_MEMORY:
954-
return (bus_generic_rman_adjust_resource(dev, child, type, r,
955-
start, end));
954+
return (bus_generic_rman_adjust_resource(dev, child, r, start,
955+
end));
956956
#ifdef PCI_RES_BUS
957957
case PCI_RES_BUS:
958958
return (pci_domain_adjust_bus(sc->ap_segment, child, r, start,
959959
end));
960960
#endif
961961
default:
962-
return (bus_generic_adjust_resource(dev, child, type, r,
963-
start, end));
962+
return (bus_generic_adjust_resource(dev, child, r, start, end));
964963
}
965964
}
966965

sys/arm64/cavium/thunder_pcie_pem.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122

123123
static int thunder_pem_activate_resource(device_t, device_t, int, int,
124124
struct resource *);
125-
static int thunder_pem_adjust_resource(device_t, device_t, int,
125+
static int thunder_pem_adjust_resource(device_t, device_t,
126126
struct resource *, rman_res_t, rman_res_t);
127127
static struct resource * thunder_pem_alloc_resource(device_t, device_t, int,
128128
int *, rman_res_t, rman_res_t, rman_res_t, u_int);
@@ -355,26 +355,26 @@ thunder_pem_unmap_resource(device_t dev, device_t child, int type,
355355
}
356356

357357
static int
358-
thunder_pem_adjust_resource(device_t dev, device_t child, int type,
359-
struct resource *res, rman_res_t start, rman_res_t end)
358+
thunder_pem_adjust_resource(device_t dev, device_t child, struct resource *res,
359+
rman_res_t start, rman_res_t end)
360360
{
361361
#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
362362
struct thunder_pem_softc *sc;
363363

364364
sc = device_get_softc(dev);
365365
#endif
366-
switch (type) {
366+
switch (rman_get_type(res)) {
367367
#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
368368
case PCI_RES_BUS:
369369
return (pci_domain_adjust_bus(sc->id, child, res, start, end));
370370
#endif
371371
case SYS_RES_MEMORY:
372372
case SYS_RES_IOPORT:
373-
return (bus_generic_rman_adjust_resource(dev, child, type, res,
374-
start, end));
373+
return (bus_generic_rman_adjust_resource(dev, child, res, start,
374+
end));
375375
default:
376-
return (bus_generic_adjust_resource(dev, child, type, res,
377-
start, end));
376+
return (bus_generic_adjust_resource(dev, child, res, start,
377+
end));
378378
}
379379
}
380380

sys/dev/acpica/acpi.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1570,13 +1570,13 @@ acpi_managed_resource(device_t bus, int type, struct resource *r)
15701570
}
15711571

15721572
static int
1573-
acpi_adjust_resource(device_t bus, device_t child, int type, struct resource *r,
1573+
acpi_adjust_resource(device_t bus, device_t child, struct resource *r,
15741574
rman_res_t start, rman_res_t end)
15751575
{
15761576

15771577
if (acpi_is_resource_managed(bus, r))
15781578
return (rman_adjust_resource(r, start, end));
1579-
return (bus_generic_adjust_resource(bus, child, type, r, start, end));
1579+
return (bus_generic_adjust_resource(bus, child, r, start, end));
15801580
}
15811581

15821582
static int

sys/dev/acpica/acpi_pcib_acpi.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static struct resource *acpi_pcib_acpi_alloc_resource(device_t dev,
9797
u_int flags);
9898
#ifdef NEW_PCIB
9999
static int acpi_pcib_acpi_adjust_resource(device_t dev,
100-
device_t child, int type, struct resource *r,
100+
device_t child, struct resource *r,
101101
rman_res_t start, rman_res_t end);
102102
#ifdef PCI_RES_BUS
103103
static int acpi_pcib_acpi_release_resource(device_t dev,
@@ -745,19 +745,18 @@ acpi_pcib_acpi_alloc_resource(device_t dev, device_t child, int type, int *rid,
745745

746746
#ifdef NEW_PCIB
747747
int
748-
acpi_pcib_acpi_adjust_resource(device_t dev, device_t child, int type,
748+
acpi_pcib_acpi_adjust_resource(device_t dev, device_t child,
749749
struct resource *r, rman_res_t start, rman_res_t end)
750750
{
751751
struct acpi_hpcib_softc *sc;
752752

753753
sc = device_get_softc(dev);
754754
#ifdef PCI_RES_BUS
755-
if (type == PCI_RES_BUS)
755+
if (rman_get_type(r) == PCI_RES_BUS)
756756
return (pci_domain_adjust_bus(sc->ap_segment, child, r, start,
757757
end));
758758
#endif
759-
return (pcib_host_res_adjust(&sc->ap_host_res, child, type, r, start,
760-
end));
759+
return (pcib_host_res_adjust(&sc->ap_host_res, child, r, start, end));
761760
}
762761

763762
#ifdef PCI_RES_BUS

sys/dev/bhnd/bhndb/bhndb.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ bhndb_release_resource(device_t dev, device_t child, int type, int rid,
10801080
* Default bhndb(4) implementation of BUS_ADJUST_RESOURCE().
10811081
*/
10821082
static int
1083-
bhndb_adjust_resource(device_t dev, device_t child, int type,
1083+
bhndb_adjust_resource(device_t dev, device_t child,
10841084
struct resource *r, rman_res_t start, rman_res_t end)
10851085
{
10861086
struct bhndb_softc *sc;
@@ -1093,10 +1093,10 @@ bhndb_adjust_resource(device_t dev, device_t child, int type,
10931093

10941094
/* Delegate to our parent device's bus if the requested resource type
10951095
* isn't handled locally. */
1096-
rm = bhndb_get_rman(sc, child, type);
1096+
rm = bhndb_get_rman(sc, child, rman_get_type(r));
10971097
if (rm == NULL) {
10981098
return (BUS_ADJUST_RESOURCE(device_get_parent(sc->parent_dev),
1099-
child, type, r, start, end));
1099+
child, r, start, end));
11001100
}
11011101

11021102
/* Verify basic constraints */

sys/dev/bhnd/cores/chipc/chipc.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ chipc_release_resource(device_t dev, device_t child, int type, int rid,
913913
}
914914

915915
static int
916-
chipc_adjust_resource(device_t dev, device_t child, int type,
916+
chipc_adjust_resource(device_t dev, device_t child,
917917
struct resource *r, rman_res_t start, rman_res_t end)
918918
{
919919
struct chipc_softc *sc;
@@ -923,10 +923,9 @@ chipc_adjust_resource(device_t dev, device_t child, int type,
923923
sc = device_get_softc(dev);
924924

925925
/* Handled by parent bus? */
926-
rm = chipc_get_rman(dev, type, rman_get_flags(r));
926+
rm = chipc_get_rman(dev, rman_get_type(r), rman_get_flags(r));
927927
if (rm == NULL || !rman_is_region_manager(r, rm)) {
928-
return (bus_generic_adjust_resource(dev, child, type, r, start,
929-
end));
928+
return (bus_generic_adjust_resource(dev, child, r, start, end));
930929
}
931930

932931
/* The range is limited to the existing region mapping */

sys/dev/dpaa2/dpaa2_mc.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,16 @@ dpaa2_mc_alloc_resource(device_t mcdev, device_t child, int type, int *rid,
343343
}
344344

345345
int
346-
dpaa2_mc_adjust_resource(device_t mcdev, device_t child, int type,
346+
dpaa2_mc_adjust_resource(device_t mcdev, device_t child,
347347
struct resource *r, rman_res_t start, rman_res_t end)
348348
{
349349
struct rman *rm;
350350

351-
rm = dpaa2_mc_rman(mcdev, type, rman_get_flags(r));
351+
rm = dpaa2_mc_rman(mcdev, rman_get_type(r), rman_get_flags(r));
352352
if (rm)
353-
return (bus_generic_rman_adjust_resource(mcdev, child, type, r,
353+
return (bus_generic_rman_adjust_resource(mcdev, child, r,
354354
start, end));
355-
return (bus_generic_adjust_resource(mcdev, child, type, r, start, end));
355+
return (bus_generic_adjust_resource(mcdev, child, r, start, end));
356356
}
357357

358358
int

sys/dev/dpaa2/dpaa2_mc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ struct rman *dpaa2_mc_rman(device_t mcdev, int type, u_int flags);
183183
struct resource * dpaa2_mc_alloc_resource(device_t mcdev, device_t child,
184184
int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count,
185185
u_int flags);
186-
int dpaa2_mc_adjust_resource(device_t mcdev, device_t child, int type,
186+
int dpaa2_mc_adjust_resource(device_t mcdev, device_t child,
187187
struct resource *r, rman_res_t start, rman_res_t end);
188188
int dpaa2_mc_release_resource(device_t mcdev, device_t child, int type,
189189
int rid, struct resource *r);

sys/dev/fdt/simplebus.c

+1-13
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
static int simplebus_probe(device_t dev);
4747
static struct resource *simplebus_alloc_resource(device_t, device_t, int,
4848
int *, rman_res_t, rman_res_t, rman_res_t, u_int);
49-
static int simplebus_adjust_resource(device_t bus, device_t child,
50-
int type, struct resource *r, rman_res_t start, rman_res_t end);
5149
static int simplebus_release_resource(device_t bus, device_t child,
5250
int type, int rid, struct resource *r);
5351
static int simplebus_activate_resource(device_t bus,
@@ -99,7 +97,7 @@ static device_method_t simplebus_methods[] = {
9997
DEVMETHOD(bus_release_resource, simplebus_release_resource),
10098
DEVMETHOD(bus_activate_resource, simplebus_activate_resource),
10199
DEVMETHOD(bus_deactivate_resource, simplebus_deactivate_resource),
102-
DEVMETHOD(bus_adjust_resource, simplebus_adjust_resource),
100+
DEVMETHOD(bus_adjust_resource, bus_generic_adjust_resource),
103101
DEVMETHOD(bus_map_resource, simplebus_map_resource),
104102
DEVMETHOD(bus_unmap_resource, simplebus_unmap_resource),
105103
DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
@@ -496,16 +494,6 @@ simplebus_alloc_resource(device_t bus, device_t child, int type, int *rid,
496494
count, flags));
497495
}
498496

499-
static int
500-
simplebus_adjust_resource(device_t bus, device_t child, int type,
501-
struct resource *r, rman_res_t start, rman_res_t end)
502-
{
503-
504-
if (type == SYS_RES_IOPORT)
505-
type = SYS_RES_MEMORY;
506-
return (bus_generic_adjust_resource(bus, child, type, r, start, end));
507-
}
508-
509497
static int
510498
simplebus_release_resource(device_t bus, device_t child, int type, int rid,
511499
struct resource *r)

sys/dev/hyperv/pcib/vmbus_pcib.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1713,15 +1713,15 @@ vmbus_pcib_alloc_resource(device_t dev, device_t child, int type, int *rid,
17131713
}
17141714

17151715
static int
1716-
vmbus_pcib_adjust_resource(device_t dev, device_t child, int type,
1716+
vmbus_pcib_adjust_resource(device_t dev, device_t child,
17171717
struct resource *r, rman_res_t start, rman_res_t end)
17181718
{
17191719
struct vmbus_pcib_softc *sc = device_get_softc(dev);
17201720

1721-
if (type == PCI_RES_BUS)
1721+
if (rman_get_type(r) == PCI_RES_BUS)
17221722
return (pci_domain_adjust_bus(sc->hbus->pci_domain, child, r,
17231723
start, end));
1724-
return (bus_generic_adjust_resource(dev, child, type, r, start, end));
1724+
return (bus_generic_adjust_resource(dev, child, r, start, end));
17251725
}
17261726

17271727
static int

sys/dev/ofw/ofw_pcib.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int ofw_pcib_activate_resource(device_t, device_t, int, int,
7373
struct resource *);
7474
static int ofw_pcib_deactivate_resource(device_t, device_t, int, int,
7575
struct resource *);
76-
static int ofw_pcib_adjust_resource(device_t, device_t, int,
76+
static int ofw_pcib_adjust_resource(device_t, device_t,
7777
struct resource *, rman_res_t, rman_res_t);
7878
static int ofw_pcib_map_resource(device_t, device_t, int, struct resource *,
7979
struct resource_map_request *, struct resource_map *);
@@ -656,27 +656,27 @@ ofw_pcib_deactivate_resource(device_t bus, device_t child, int type, int rid,
656656
}
657657

658658
static int
659-
ofw_pcib_adjust_resource(device_t bus, device_t child, int type,
659+
ofw_pcib_adjust_resource(device_t bus, device_t child,
660660
struct resource *res, rman_res_t start, rman_res_t end)
661661
{
662662
#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
663663
struct ofw_pci_softc *sc;
664664

665665
sc = device_get_softc(bus);
666666
#endif
667-
switch (type) {
667+
switch (rman_get_type(res)) {
668668
#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
669669
case PCI_RES_BUS:
670670
return (pci_domain_adjust_bus(sc->sc_pci_domain, child, res,
671671
start, end));
672672
#endif
673673
case SYS_RES_MEMORY:
674674
case SYS_RES_IOPORT:
675-
return (bus_generic_rman_adjust_resource(bus, child, type, res,
675+
return (bus_generic_rman_adjust_resource(bus, child, res,
676676
start, end));
677677
default:
678-
return (bus_generic_adjust_resource(bus, child, type, res,
679-
start, end));
678+
return (bus_generic_adjust_resource(bus, child, res, start,
679+
end));
680680
}
681681
}
682682

sys/dev/pccbb/pccbb_pci.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -803,18 +803,18 @@ cbb_pci_alloc_resource(device_t bus, device_t child, int type, int *rid,
803803
}
804804

805805
static int
806-
cbb_pci_adjust_resource(device_t bus, device_t child, int type,
806+
cbb_pci_adjust_resource(device_t bus, device_t child,
807807
struct resource *r, rman_res_t start, rman_res_t end)
808808
{
809809
struct cbb_softc *sc;
810810

811811
sc = device_get_softc(bus);
812-
if (type == PCI_RES_BUS) {
812+
if (rman_get_type(r) == PCI_RES_BUS) {
813813
if (!rman_is_region_manager(r, &sc->bus.rman))
814814
return (EINVAL);
815815
return (rman_adjust_resource(r, start, end));
816816
}
817-
return (bus_generic_adjust_resource(bus, child, type, r, start, end));
817+
return (bus_generic_adjust_resource(bus, child, r, start, end));
818818
}
819819

820820
static int

sys/dev/pci/pci_host_generic.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -614,27 +614,27 @@ generic_pcie_deactivate_resource(device_t dev, device_t child, int type,
614614
}
615615

616616
static int
617-
generic_pcie_adjust_resource(device_t dev, device_t child, int type,
617+
generic_pcie_adjust_resource(device_t dev, device_t child,
618618
struct resource *res, rman_res_t start, rman_res_t end)
619619
{
620620
#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
621621
struct generic_pcie_core_softc *sc;
622622

623623
sc = device_get_softc(dev);
624624
#endif
625-
switch (type) {
625+
switch (rman_get_type(res)) {
626626
#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
627627
case PCI_RES_BUS:
628628
return (pci_domain_adjust_bus(sc->ecam, child, res, start,
629629
end));
630630
#endif
631631
case SYS_RES_IOPORT:
632632
case SYS_RES_MEMORY:
633-
return (bus_generic_rman_adjust_resource(dev, child, type, res,
633+
return (bus_generic_rman_adjust_resource(dev, child, res,
634634
start, end));
635635
default:
636-
return (bus_generic_adjust_resource(dev, child, type, res,
637-
start, end));
636+
return (bus_generic_adjust_resource(dev, child, res, start,
637+
end));
638638
}
639639
}
640640

0 commit comments

Comments
 (0)