Skip to content

Commit 86eb16f

Browse files
Puneetha-RamachandraCQ Bot
authored andcommitted
[devicetree][iommu] Add names property
This would help to retrieve iommus using GetBtiByName in drivers. Fixed: 381100101 Test: bti-visitor-test Change-Id: I42261972bdb20859936be343f8019c6ac7c77cfd Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1179376 Commit-Queue: Victor Costan <[email protected]> Fuchsia-Auto-Submit: Victor Costan <[email protected]> Fuchsia-Auto-Submit: Puneetha Ramachandra <[email protected]> Reviewed-by: Victor Costan <[email protected]>
1 parent 0dd1400 commit 86eb16f

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

sdk/lib/driver/devicetree/visitors/default/bti/bti.cc

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ using namespace fuchsia_driver_framework;
1818
namespace fdf_devicetree {
1919

2020
constexpr const char kBtiProp[] = "iommus";
21+
constexpr const char kBtiNameProp[] = "iommu-names";
2122
constexpr const char kIommuCellsProp[] = "#iommu-cells";
2223

2324
// #iommu-cells == 1.
@@ -45,6 +46,7 @@ BtiVisitor::BtiVisitor() {
4546
fdf_devicetree::Properties properties = {};
4647
properties.emplace_back(
4748
std::make_unique<fdf_devicetree::ReferenceProperty>(kBtiProp, kIommuCellsProp));
49+
properties.emplace_back(std::make_unique<fdf_devicetree::StringListProperty>(kBtiNameProp));
4850
reference_parser_ = std::make_unique<fdf_devicetree::PropertyParser>(std::move(properties));
4951
}
5052

@@ -61,10 +63,25 @@ zx::result<> BtiVisitor::Visit(Node& node, const devicetree::PropertyDecoder& de
6163
return zx::ok();
6264
}
6365

66+
std::vector<std::optional<std::string>> iommu_names((*parser_output)[kBtiProp].size());
67+
if (parser_output->find(kBtiNameProp) != parser_output->end()) {
68+
if ((*parser_output)[kBtiNameProp].size() > (*parser_output)[kBtiProp].size()) {
69+
FDF_LOG(ERROR, "Node '%s' has %zu iommu entries but has %zu iommmu names.",
70+
node.name().c_str(), (*parser_output)[kBtiProp].size(),
71+
(*parser_output)[kBtiNameProp].size());
72+
return zx::error(ZX_ERR_INVALID_ARGS);
73+
}
74+
size_t name_idx = 0;
75+
for (auto& name : (*parser_output)[kBtiNameProp]) {
76+
iommu_names[name_idx++] = name.AsString();
77+
}
78+
}
79+
6480
for (uint32_t index = 0; index < (*parser_output)[kBtiProp].size(); index++) {
6581
auto reference = (*parser_output)[kBtiProp][index].AsReference();
6682
if (reference && IsIommu(reference->first.name())) {
67-
auto result = ReferenceChildVisit(node, reference->first, reference->second);
83+
auto result =
84+
ReferenceChildVisit(node, reference->first, reference->second, iommu_names[index]);
6885
if (result.is_error()) {
6986
return result.take_error();
7087
}
@@ -75,7 +92,8 @@ zx::result<> BtiVisitor::Visit(Node& node, const devicetree::PropertyDecoder& de
7592
}
7693

7794
zx::result<> BtiVisitor::ReferenceChildVisit(Node& child, ReferenceNode& parent,
78-
PropertyCells reference_cells) {
95+
PropertyCells reference_cells,
96+
std::optional<std::string> iommu_name) {
7997
std::optional<uint32_t> iommu_index;
8098

8199
// Check if iommu is already registered.
@@ -97,9 +115,11 @@ zx::result<> BtiVisitor::ReferenceChildVisit(Node& child, ReferenceNode& parent,
97115
fuchsia_hardware_platform_bus::Bti bti = {{
98116
.iommu_index = iommu_index,
99117
.bti_id = iommu_cell.bti_id(),
118+
.name = std::move(iommu_name),
100119
}};
101-
FDF_LOG(DEBUG, "BTI (0x%0x, 0x%0x) added to node '%s'.", *bti.iommu_index(), *bti.bti_id(),
102-
child.name().c_str());
120+
FDF_LOG(DEBUG, "BTI %s index: 0x%0x, id: 0x%0x, added to node '%s'.",
121+
bti.name().has_value() ? bti.name()->c_str() : "(no name)", *bti.iommu_index(),
122+
*bti.bti_id(), child.name().c_str());
103123
child.AddBti(bti);
104124

105125
return zx::ok();

sdk/lib/driver/devicetree/visitors/default/bti/bti.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class BtiVisitor : public Visitor {
2525

2626
private:
2727
zx::result<> ReferenceChildVisit(Node& child, ReferenceNode& parent,
28-
PropertyCells reference_cells);
28+
PropertyCells reference_cells,
29+
std::optional<std::string> iommu_name);
2930

3031
std::vector<Phandle> iommu_nodes_;
3132
std::unique_ptr<PropertyParser> reference_parser_;

sdk/lib/driver/devicetree/visitors/default/bti/test/bti-test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ TEST(BtiVisitorTest, TestBtiProperty) {
6060
// iommu index is 0, as there is only one iommu provider.
6161
ASSERT_EQ(0u, *(*bti2)[0].iommu_index());
6262
ASSERT_EQ((uint32_t)TEST_BTI_ID2, *(*bti2)[0].bti_id());
63+
ASSERT_EQ(TEST_BTI_ID2_NAME, *(*bti2)[0].name());
6364

6465
node_tested_count++;
6566
}

sdk/lib/driver/devicetree/visitors/default/bti/test/dts/iommu.dts.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
sample-bti-device2 {
2626
compatible = "fuchsia,sample-bti-device";
2727
iommus = <&dummy_iommu TEST_BTI_ID2>;
28+
iommu-names = TEST_BTI_ID2_NAME;
2829
};
2930
};

sdk/lib/driver/devicetree/visitors/default/bti/test/dts/iommu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
#define TEST_BTI_ID1 6
1212
#define TEST_BTI_ID2 3
1313

14+
#define TEST_BTI_ID2_NAME "device2"
15+
1416
#endif // LIB_DRIVER_DEVICETREE_VISITORS_DEFAULT_BTI_TEST_DTS_IOMMU_H_

0 commit comments

Comments
 (0)