diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-05-30 17:28:13 +0200 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-05-30 17:28:13 +0200 |
commit | de4bd288b2c1eec5e3133df916ab5aa225d8ed96 (patch) | |
tree | 849bb285557fda63a16a5bb8c9adf5d1fd40a9a2 /src/hardware/dmidecode.c | |
parent | dec0ce45beeb80fd125dd2500c28a0a5d4535625 (diff) | |
download | openlmi-providers-de4bd288b2c1eec5e3133df916ab5aa225d8ed96.tar.gz openlmi-providers-de4bd288b2c1eec5e3133df916ab5aa225d8ed96.tar.xz openlmi-providers-de4bd288b2c1eec5e3133df916ab5aa225d8ed96.zip |
Hardware: Connect processor(s) and memory with chassis
New providers:
* LMI_ProcessorChipContainer
* LMI_MemorySlot
* LMI_MemorySlotContainer
* LMI_MemoryPhysicalPackage
* LMI_MemoryPhysicalPackageInConnector
* LMI_PhysicalMemoryContainer
This commmit brings also provider for memory slot, and memory physical package,
which is plugged in memory slot.
Diffstat (limited to 'src/hardware/dmidecode.c')
-rw-r--r-- | src/hardware/dmidecode.c | 95 |
1 files changed, 76 insertions, 19 deletions
diff --git a/src/hardware/dmidecode.c b/src/hardware/dmidecode.c index ab3b359..4023cf3 100644 --- a/src/hardware/dmidecode.c +++ b/src/hardware/dmidecode.c @@ -716,6 +716,8 @@ void init_dmi_memory_struct(DmiMemory *memory) memory->end_addr = 0; memory->modules = NULL; memory->modules_nb = 0; + memory->slots = NULL; + memory->slots_nb = 0; } /* @@ -740,6 +742,16 @@ void init_dmi_memory_module_struct(DmiMemoryModule *mem) } /* + * Initialize DmiMemorySlot attributes. + * @param slot + */ +void init_dmi_memory_slot_struct(DmiMemorySlot *slot) +{ + slot->slot_number = -1; + slot->name = NULL; +} + +/* * Check attributes of memory structure and fill in defaults if needed. * @param memory * @return 0 if success, negative value otherwise @@ -795,6 +807,20 @@ short check_dmi_memory_attributes(DmiMemory *memory) } } + for (i = 0; i < memory->slots_nb; i++) { + if (memory->slots[i].slot_number < 0) { + memory->slots[i].slot_number = i; + } + if (!memory->slots[i].name) { + if (asprintf(&memory->slots[i].name, "Memory Slot %d", + memory->slots[i].slot_number) < 0) { + memory->slots[i].name = NULL; + ret = -9; + goto done; + } + } + } + ret = 0; done: @@ -809,7 +835,8 @@ short dmi_get_memory(DmiMemory *memory) { short ret = -1; int curr_mem = -1, last_mem = -1, slot = -1; - unsigned i, j, buffer_size = 0, data_width = 0, total_width = 0; + unsigned i, j, buffer_size = 0, data_width = 0, total_width = 0, + current_slot = 0; unsigned long memory_size; char **buffer = NULL, *buf, *str_format; @@ -924,22 +951,24 @@ short dmi_get_memory(DmiMemory *memory) } continue; } - if (!strstr(buffer[i], "Bank Locator:")) { - /* Slot */ - buf = copy_string_part_after_delim(buffer[i], "Locator: "); - if (buf) { - sscanf(buf, "%*s %d", &memory->modules[curr_mem].slot); - free(buf); - buf = NULL; - continue; - } - } else { - /* Memory Module Bank Label */ - buf = copy_string_part_after_delim(buffer[i], "Bank Locator: "); - if (buf) { - memory->modules[curr_mem].bank_label = buf; - buf = NULL; - continue; + if (strstr(buffer[i], "Locator:")) { + if (strstr(buffer[i], "Bank Locator:")) { + /* Memory Module Bank Label */ + buf = copy_string_part_after_delim(buffer[i], "Bank Locator: "); + if (buf) { + memory->modules[curr_mem].bank_label = buf; + buf = NULL; + continue; + } + } else { + /* Slot */ + buf = copy_string_part_after_delim(buffer[i], "Locator: "); + if (buf) { + sscanf(buf, "%*s %d", &memory->modules[curr_mem].slot); + free(buf); + buf = NULL; + continue; + } } } /* Form Factor */ @@ -988,13 +1017,32 @@ short dmi_get_memory(DmiMemory *memory) goto done; } + /* count slots */ + for (i = 0; i < buffer_size; i++) { + if (strstr(buffer[i], "Socket Designation: ")) { + memory->slots_nb++; + } + } + + /* allocate memory for slots */ + memory->slots = (DmiMemorySlot *)calloc(memory->slots_nb, sizeof(DmiMemorySlot)); + if (!memory->slots) { + warn("Failed to allocate memory."); + ret = -10; + goto done; + } + /* parse additional information about modules */ for (i = 0; i < buffer_size; i++) { /* Slot */ buf = copy_string_part_after_delim(buffer[i], "Socket Designation: "); if (buf) { - sscanf(buf, "%*s %*s %d", &slot); - free(buf); + init_dmi_memory_slot_struct(&memory->slots[current_slot]); + if (sscanf(buf, "%*s %*s %d", &slot) == 1) { + memory->slots[current_slot].slot_number = slot; + } + memory->slots[current_slot].name = buf; + current_slot++; buf = NULL; continue; } @@ -1098,8 +1146,17 @@ void dmi_free_memory(DmiMemory *memory) } free(memory->modules); } + if (memory->slots_nb > 0) { + for (i = 0; i < memory->slots_nb; i++) { + free(memory->slots[i].name); + memory->slots[i].name = NULL; + } + free(memory->slots); + } memory->modules_nb = 0; memory->modules = NULL; + memory->slots_nb = 0; + memory->slots = NULL; } |