MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / ofw_map_id

Function ofw_map_id

components/drivers/ofw/base.c:1225–1313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1223}
1224
1225static rt_err_t ofw_map_id(struct rt_ofw_node *np, rt_uint32_t id, const char *map_name, const char *map_mask_name,
1226 const fdt32_t *map, rt_ssize_t map_len, struct rt_ofw_node **ref_np, rt_uint32_t *out_id)
1227{
1228 rt_err_t err = RT_EOK;
1229 rt_uint32_t masked_id, map_mask;
1230
1231 /* Select all bits default */
1232 map_mask = 0xffffffff;
1233
1234 if (map_mask_name)
1235 {
1236 rt_ofw_prop_read_u32(np, map_mask_name, &map_mask);
1237 }
1238
1239 masked_id = map_mask & id;
1240
1241 for (; map_len > 0; map_len -= 4 * sizeof(*map), map += 4)
1242 {
1243 struct rt_ofw_node *phandle_node;
1244 rt_uint32_t id_base = fdt32_to_cpu(*(map + 0));
1245 rt_uint32_t phandle = fdt32_to_cpu(*(map + 1));
1246 rt_uint32_t out_base = fdt32_to_cpu(*(map + 2));
1247 rt_uint32_t id_len = fdt32_to_cpu(*(map + 3));
1248
1249 if (id_base & ~map_mask)
1250 {
1251 LOG_E("%s: Invalid %s translation - %s(0x%x) for id-base = 0x%x",
1252 np->full_name, map_name, map_mask_name, map_mask, id_base);
1253
1254 err = -RT_ERROR;
1255 break;
1256 }
1257
1258 if (masked_id < id_base || masked_id >= id_base + id_len)
1259 {
1260 continue;
1261 }
1262
1263 phandle_node = rt_ofw_find_node_by_phandle((rt_phandle)phandle);
1264
1265 if (!phandle_node)
1266 {
1267 err = -RT_EEMPTY;
1268 break;
1269 }
1270
1271 if (ref_np)
1272 {
1273 if (*ref_np)
1274 {
1275 rt_ofw_node_put(phandle_node);
1276 }
1277 else
1278 {
1279 *ref_np = phandle_node;
1280 }
1281
1282 if (*ref_np != phandle_node)

Callers 1

rt_ofw_map_idFunction · 0.85

Calls 4

rt_ofw_prop_read_u32Function · 0.85
rt_ofw_node_putFunction · 0.85
fdt32_to_cpuFunction · 0.50

Tested by

no test coverage detected