1.1 --- a/pkg/devices/util/src/memory.cc Tue Sep 27 23:21:50 2022 +0200
1.2 +++ b/pkg/devices/util/src/memory.cc Sun May 28 22:35:09 2023 +0200
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Memory and resource allocation utility functions.
1.6 *
1.7 - * Copyright (C) 2018, 2019 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2018, 2019, 2023 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -45,7 +45,7 @@
1.13 if (result < 0)
1.14 return result;
1.15
1.16 - result = get_resource(dh, &res, L4IO_RESOURCE_IRQ);
1.17 + result = get_resource(dh, &res, L4VBUS_RESOURCE_IRQ);
1.18
1.19 if (result)
1.20 return result;
1.21 @@ -57,7 +57,7 @@
1.22 }
1.23
1.24 int get_resource(l4io_device_handle_t dh, l4io_resource_t *res,
1.25 - enum l4io_resource_types_t type)
1.26 + enum l4vbus_resource_type_t type)
1.27 {
1.28 int current = 0, result = 0;
1.29 l4_cap_idx_t vbus = l4re_env_get_cap("vbus");
1.30 @@ -84,7 +84,7 @@
1.31 if (result < 0)
1.32 return result;
1.33
1.34 - result = get_resource(dh, &res, L4IO_RESOURCE_MEM);
1.35 + result = get_resource(dh, &res, L4VBUS_RESOURCE_MEM);
1.36
1.37 if (result)
1.38 return result;
1.39 @@ -99,3 +99,39 @@
1.40
1.41 return 0;
1.42 }
1.43 +
1.44 +static int _find_resource(l4vbus_device_handle_t device,
1.45 + l4vbus_resource_t *resource,
1.46 + enum l4vbus_resource_type_t type,
1.47 + l4vbus_device_t info)
1.48 +{
1.49 + l4_cap_idx_t vbus = l4re_env_get_cap("vbus");
1.50 +
1.51 + for (unsigned int i = 0; i < info.num_resources; i++)
1.52 + {
1.53 + int result = l4vbus_get_resource(vbus, device, i, resource);
1.54 +
1.55 + if (!result && (resource->type == type))
1.56 + return 1;
1.57 + }
1.58 +
1.59 + return 0;
1.60 +}
1.61 +
1.62 +int find_resource(l4vbus_device_handle_t *device, l4vbus_resource_t *resource,
1.63 + enum l4vbus_resource_type_t type)
1.64 +{
1.65 + l4_cap_idx_t vbus = l4re_env_get_cap("vbus");
1.66 + l4vbus_device_t info;
1.67 +
1.68 + /* Search within devices only, not within the top-level of the bus itself. */
1.69 +
1.70 + while (!l4vbus_get_next_device(vbus, L4VBUS_ROOT_BUS, device,
1.71 + L4VBUS_MAX_DEPTH, &info))
1.72 + {
1.73 + if (_find_resource(*device, resource, type, info))
1.74 + return 1;
1.75 + }
1.76 +
1.77 + return 0;
1.78 +}