static void update_drconf_affinity(struct dr_node *lmb, struct drconf_mem *drmem) { struct of_node *node; struct of_property *prop; uint32_t assoc_prop_sz; uint32_t *assoc_prop; uint32_t assoc_entries; uint32_t assoc_entry_sz; uint32_t *prop_val; int i; /* find the ibm,associativity property */ node = lmb->lmb_of_node; for (prop = node->properties; prop; prop = prop->next) { if (!strcmp(prop->name, "ibm,associativity")) break; } if (!prop) return; /* find the associtivity index atrrays */ assoc_prop_sz = get_property_size(DYNAMIC_RECONFIG_MEM, "ibm,associativity-lookup-arrays"); assoc_prop = zalloc(assoc_prop_sz); if (!assoc_prop) return; get_property(DYNAMIC_RECONFIG_MEM, "ibm,associativity-lookup-arrays", assoc_prop, assoc_prop_sz); assoc_entries = be32toh(assoc_prop[0]); assoc_entry_sz = be32toh(assoc_prop[1]); prop_val = (uint32_t *)prop->value; for (i = 0; i < assoc_entries; i++) { if (memcmp(&assoc_prop[(i * assoc_entry_sz) + 2], &prop_val[1], assoc_entry_sz * sizeof(uint32_t))) continue; /* found it */ drmem->assoc_index = htobe32(i); break; } free(assoc_prop); return; }
static inline struct obs_property *new_prop(struct obs_category *cat, const char *name, const char *desc, enum obs_property_type type) { size_t data_size = get_property_size(type); struct obs_property *p; p = bmalloc(sizeof(struct obs_property) + data_size); memset(p, 0, sizeof(struct obs_property) + data_size); p->type = type; p->name = name; p->desc = desc; category_add(cat, p); return p; }
/** * get_of_list_prop * @breif retrieve the specified open firmware property list * * @param full_path * @param prop_name * @param prop * @returns 0 on success, !0 otherwise */ static int get_of_list_prop(char *full_path, char *prop_name, struct of_list_prop *prop) { int size, rc; size = get_property_size(full_path, prop_name); prop->_data = zalloc(size); if (prop->_data == NULL) return -1; rc = get_property(full_path, prop_name, prop->_data, size); if (rc) { free(prop->_data); return -1; } prop->n_entries = *(uint *)prop->_data; prop->val = prop->_data + sizeof(uint); return 0; }
int print_drconf_mem(struct cmd_opts *opts, struct lmb_list_head *lmb_list) { struct dr_node *lmb; struct mem_scn *scn; int scn_offset = strlen("/sys/devices/system/memory/memory"); char *aa_buf; __be32 *aa; int aa_size, aa_list_sz; int i, rc; uint32_t drc_index = 0; aa_size = get_property_size(DYNAMIC_RECONFIG_MEM, "ibm,associativity-lookup-arrays"); aa_buf = zalloc(aa_size); rc = get_property(DYNAMIC_RECONFIG_MEM, "ibm,associativity-lookup-arrays", aa_buf, aa_size); if (rc) { say(ERROR, "Could not get associativity information.\n"); return -1; } aa = (__be32 *)aa_buf; /* skip past the number of associativity lists */ aa++; aa_list_sz = be32toh(*aa++); if (opts->s_name) drc_index = strtol(opts->s_name, NULL, 0); printf("Dynamic Reconfiguration Memory (LMB size 0x%x)\n", lmb_list->lmbs->lmb_size); for (lmb = lmb_list->lmbs; lmb; lmb = lmb->next) { int first = 1; int aa_start, aa_end; if (drc_index && drc_index != lmb->drc_index) continue; else if ((output_level < DEBUG) && !lmb->is_owned) continue; printf("%s: %s\n", lmb->drc_name, lmb->is_owned ? "" : "Not Owned"); printf(" DRC Index: %x Address: %lx\n", lmb->drc_index, lmb->lmb_address); printf(" Removable: %s Associativity: ", lmb->is_removable ? "Yes" : "No "); if (lmb->lmb_aa_index == 0xffffffff) { printf("Not Set\n"); } else { printf("(index: %d) ", lmb->lmb_aa_index); aa_start = lmb->lmb_aa_index * aa_list_sz; aa_end = aa_start + aa_list_sz; for (i = aa_start; i < aa_end; i++) printf("%d ", be32toh(aa[i])); printf("\n"); } if (lmb->is_owned) { printf(" Section(s):"); for (scn = lmb->lmb_mem_scns; scn; scn = scn->next) { if (first) { printf(" %s", &scn->sysfs_path[scn_offset]); first = 0; } else printf(", %s", &scn->sysfs_path[scn_offset]); } printf("\n"); } } free(aa_buf); return 0; }
/** * get_dynamic_reconfig_lmbs * @brief Retrieve lmbs from OF device tree located in the ibm,dynamic-memory * property. * * @param lmb_list pointer to lmb list head to populate * @returns 0 on success, !0 on failure */ int get_dynamic_reconfig_lmbs(struct lmb_list_head *lmb_list) { struct drconf_mem *drmem; uint64_t lmb_sz; int i, num_entries; int rc = 0; rc = get_property(DYNAMIC_RECONFIG_MEM, "ibm,lmb-size", &lmb_sz, sizeof(lmb_sz)); /* convert for LE systems */ lmb_sz = be64toh(lmb_sz); if (rc) { say(DEBUG, "Could not retrieve drconf LMB size\n"); return rc; } lmb_list->drconf_buf_sz = get_property_size(DYNAMIC_RECONFIG_MEM, "ibm,dynamic-memory"); lmb_list->drconf_buf = zalloc(lmb_list->drconf_buf_sz); if (lmb_list->drconf_buf == NULL) { say(DEBUG, "Could not allocate buffer to get dynamic " "reconfigurable memory\n"); return -1; } rc = get_property(DYNAMIC_RECONFIG_MEM, "ibm,dynamic-memory", lmb_list->drconf_buf, lmb_list->drconf_buf_sz); if (rc) { say(DEBUG, "Could not retrieve dynamic reconfigurable memory " "property\n"); return -1; } /* The first integer of the buffer is the number of entries */ num_entries = *(int *)lmb_list->drconf_buf; /* convert for LE systems */ num_entries = be32toh(num_entries); /* Followed by the actual entries */ drmem = (struct drconf_mem *) (lmb_list->drconf_buf + sizeof(num_entries)); for (i = 0; i < num_entries; i++) { struct dr_node *lmb; lmb = lmb_list_add(be32toh(drmem->drc_index), lmb_list); if (lmb == NULL) { say(DEBUG, "Could not find LMB with drc-index of %x\n", drmem->drc_index); rc = -1; break; } sprintf(lmb->ofdt_path, DYNAMIC_RECONFIG_MEM); lmb->lmb_size = lmb_sz; lmb->lmb_address = be64toh(drmem->address); lmb->lmb_aa_index = be32toh(drmem->assoc_index); if (be32toh(drmem->flags) & DRMEM_ASSIGNED) { lmb->is_owned = 1; /* find the associated sysfs memory blocks */ rc = get_mem_scns(lmb); if (rc) break; } lmb_list->lmbs_found++; drmem++; /* trust your compiler */ } say(INFO, "Found %d LMBs currently allocated\n", lmb_list->lmbs_found); return rc; }