[syslinux:master] hdt: Adding code documentation
syslinux-bot for Erwan Velu
erwan.velu at free.fr
Sun Feb 6 14:07:15 PST 2011
Commit-ID: f3caf9ccab869a5ee3f5cf50907e5cb25bc6561c
Gitweb: http://syslinux.zytor.com/commit/f3caf9ccab869a5ee3f5cf50907e5cb25bc6561c
Author: Erwan Velu <erwan.velu at free.fr>
AuthorDate: Mon, 7 Dec 2009 21:17:28 +0100
Committer: Erwan Velu <erwan.velu at free.fr>
CommitDate: Mon, 7 Dec 2009 21:17:28 +0100
hdt: Adding code documentation
Impact: Adding comments
Adding some comments to explain some part of the code
---
com32/hdt/hdt-cli-acpi.c | 35 ++++++++++++++++++++++++++++++++++-
com32/hdt/hdt-cli-cpu.c | 21 ++++++++++++++++++++-
com32/hdt/hdt-util.c | 3 +++
3 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/com32/hdt/hdt-cli-acpi.c b/com32/hdt/hdt-cli-acpi.c
index a8a4352..6e75d26 100644
--- a/com32/hdt/hdt-cli-acpi.c
+++ b/com32/hdt/hdt-cli-acpi.c
@@ -34,6 +34,8 @@
#include <errno.h>
#include <acpi/acpi.h>
+/* Print ACPI's table header in a defined formating
+ * this particular version is made for displaying 32bit addresses*/
static void show_header_32(uint32_t address, s_acpi_description_header * h)
{
more_printf("%-4s v%03x %-6s %-7s 0x%08x %-4s 0x%08x @ 0x%016x\n",
@@ -41,6 +43,8 @@ static void show_header_32(uint32_t address, s_acpi_description_header * h)
h->oem_revision, h->creator_id, h->creator_revision, address)
}
+/* Print ACPI's table header in a defined formating */
+static void show_header_32(uint32_t address, s_acpi_description_header * h)
static void show_header(uint64_t address, s_acpi_description_header * h)
{
more_printf("%-4s v%03x %-6s %-7s 0x%08x %-4s 0x%08x @ 0x%016llx\n",
@@ -48,12 +52,14 @@ static void show_header(uint64_t address, s_acpi_description_header * h)
h->oem_revision, h->creator_id, h->creator_revision, address)
}
+/* That's an helper to visualize columns*/
void show_table_separator()
{
more_printf
("----|----|------|--------|----------|-------|-----------|--------------------\n");
}
+/* Display the main header before displaying the ACPI tables */
void show_table_name()
{
more_printf
@@ -61,6 +67,7 @@ void show_table_name()
show_table_separator();
}
+/* called by "show acpi" */
void main_show_acpi(int argc __unused, char **argv __unused,
struct s_hardware *hardware)
{
@@ -70,13 +77,18 @@ void main_show_acpi(int argc __unused, char **argv __unused,
more_printf("No ACPI Tables detected\n");
return;
}
+
show_table_name();
+
+ /* RSDP tables aren't using the same headers as the other
+ * So let's use a dedicated rendering */
if (hardware->acpi.rsdp.valid) {
s_rsdp *r = &hardware->acpi.rsdp;
more_printf
("RSDP v%03x %-6s @ 0x%016llx\n",
r->revision, r->oem_id, r->address);
}
+
if (hardware->acpi.rsdt.valid)
show_header_32(hardware->acpi.rsdt.address,
&hardware->acpi.rsdt.header);
@@ -94,6 +106,7 @@ void main_show_acpi(int argc __unused, char **argv __unused,
if (hardware->acpi.dsdt.valid)
show_header(hardware->acpi.dsdt.address, &hardware->acpi.dsdt.header);
+ /* SSDT includes many optional tables, let's display them */
for (int i = 0; i < hardware->acpi.ssdt_count; i++) {
if ((hardware->acpi.ssdt[i] != NULL) && (hardware->acpi.ssdt[i]->valid))
show_header(hardware->acpi.ssdt[i]->address,
@@ -106,6 +119,7 @@ void main_show_acpi(int argc __unused, char **argv __unused,
if (hardware->acpi.ecdt.valid)
show_header(hardware->acpi.ecdt.address, &hardware->acpi.ecdt.header);
+ /* FACS isn't having the same headers, let's use a dedicated rendering */
if (hardware->acpi.facs.valid) {
s_facs *fa = &hardware->acpi.facs;
more_printf
@@ -114,18 +128,21 @@ void main_show_acpi(int argc __unused, char **argv __unused,
}
}
+/* Let's display the Processor Local APIC configuration */
static void show_local_apic(s_madt * madt)
{
- printf("Local APIC at 0x%08x\n", madt->local_apic_address);
if (madt->processor_local_apic_count == 0) {
more_printf("No Processor Local APIC found\n");
return;
}
+
+ /* For all detected logical CPU */
for (int i = 0; i < madt->processor_local_apic_count; i++) {
s_processor_local_apic *sla = &madt->processor_local_apic[i];
char buffer[8];
memset(buffer, 0, sizeof(buffer));
strcpy(buffer, "disable");
+ /* Let's check if the flags reports the cpu as enabled */
if ((sla->flags & PROCESSOR_LOCAL_APIC_ENABLE) ==
PROCESSOR_LOCAL_APIC_ENABLE)
strcpy(buffer, "enable");
@@ -134,6 +151,7 @@ static void show_local_apic(s_madt * madt)
}
}
+/* M1PS flags have to be interpreted as strings */
static char *flags_to_string(char *buffer, uint16_t flags)
{
memset(buffer, 0, sizeof(buffer));
@@ -152,12 +170,14 @@ static char *flags_to_string(char *buffer, uint16_t flags)
return buffer;
}
+/* Display the local apic NMI configuration */
static void show_local_apic_nmi(s_madt * madt)
{
if (madt->local_apic_nmi_count == 0) {
more_printf("No Local APIC NMI found\n");
return;
}
+
for (int i = 0; i < madt->local_apic_nmi_count; i++) {
s_local_apic_nmi *slan = &madt->local_apic_nmi[i];
char buffer[20];
@@ -168,16 +188,21 @@ static void show_local_apic_nmi(s_madt * madt)
}
}
+/* Display the IO APIC configuration */
static void show_io_apic(s_madt * madt)
{
if (madt->io_apic_count == 0) {
more_printf("No IO APIC found\n");
return;
}
+
+ /* For all IO APICS */
for (int i = 0; i < madt->io_apic_count; i++) {
s_io_apic *sio = &madt->io_apic[i];
char buffer[15];
memset(buffer, 0, sizeof(buffer));
+ /* GSI base reports the GSI configuration
+ * Let's interpret it as string */
switch (sio->global_system_interrupt_base) {
case 0:
strcpy(buffer, "GSI 0-23");
@@ -198,17 +223,21 @@ static void show_io_apic(s_madt * madt)
}
}
+/* Display the interrupt source override configuration */
static void show_interrupt_source_override(s_madt * madt)
{
if (madt->interrupt_source_override_count == 0) {
more_printf("No interrupt source override found\n");
return;
}
+
+ /* Let's process each interrupt source override */
for (int i = 0; i < madt->interrupt_source_override_count; i++) {
s_interrupt_source_override *siso = &madt->interrupt_source_override[i];
char buffer[20];
char bus_type[10];
memset(bus_type, 0, sizeof(bus_type));
+ /* Spec report bus type 0 as ISA */
if (siso->bus == 0)
strcpy(bus_type, "ISA");
else
@@ -222,6 +251,8 @@ static void show_interrupt_source_override(s_madt * madt)
}
}
+/* Display the madt configuration
+ * This is called by acpi> show madt */
static void show_acpi_madt(int argc __unused, char **argv __unused,
struct s_hardware *hardware)
{
@@ -236,8 +267,10 @@ static void show_acpi_madt(int argc __unused, char **argv __unused,
more_printf("No MADT table found\n");
return;
}
+
show_table_name();
show_header(madt->address, &madt->header);
+ more_printf("Local APIC at 0x%08x\n", madt->local_apic_address);
show_table_separator();
show_local_apic(madt);
show_local_apic_nmi(madt);
diff --git a/com32/hdt/hdt-cli-cpu.c b/com32/hdt/hdt-cli-cpu.c
index b7949f3..170de9a 100644
--- a/com32/hdt/hdt-cli-cpu.c
+++ b/com32/hdt/hdt-cli-cpu.c
@@ -38,6 +38,10 @@ void main_show_cpu(int argc __unused, char **argv __unused,
struct s_hardware *hardware)
{
char features[81];
+ /* We know the total number of logical cores and we
+ * know the number of cores of the first CPU. Let's consider
+ * the system as symetrical, and so compute the number of
+ * physical CPUs. This is only possible if ACPI is present */
if (hardware->acpi.madt.processor_local_apic_count > 0) {
more_printf("CPU (%d logical / %d phys)\n",
hardware->acpi.madt.processor_local_apic_count,
@@ -59,15 +63,24 @@ void main_show_cpu(int argc __unused, char **argv __unused,
strcat(features, "x86 32bit ");
if (hardware->cpu.flags.smp)
strcat(features, "SMP ");
+
+ /* This CPU is featuring Intel or AMD Virtualisation Technology */
if (hardware->cpu.flags.vmx || hardware->cpu.flags.svm)
strcat(features, "HwVIRT ");
more_printf("%s\n", features);
}
+/* Let's compute the cpu flags display
+ * We have to maximize the number of flags per line */
static void show_flag(char *buffer, bool flag, char *flag_name, bool flush)
{
char output_buffer[81];
+ /* Flush is only set when no more flags are present
+ * When it's set, or if the line is complete,
+ * we have to end the string computation and display the line.
+ * Before adding the flag into the buffer, let's check that adding it
+ * will not overflow the rendering.*/
if ((((strlen(buffer) + strlen(flag_name)) > 66) && flag) || flush) {
snprintf(output_buffer, sizeof output_buffer, "Flags : %s\n",
buffer);
@@ -76,6 +89,7 @@ static void show_flag(char *buffer, bool flag, char *flag_name, bool flush)
if (flush)
return;
}
+ /* Let's add the flag name only if the flag is present */
if (flag)
strcat(buffer, flag_name);
}
@@ -85,6 +99,10 @@ static void show_cpu(int argc __unused, char **argv __unused,
{
char buffer[81];
reset_more_printf();
+ /* We know the total number of logical cores and we
+ * know the number of cores of the first CPU. Let's consider
+ * the system as symetrical, and so compute the number of
+ * physical CPUs. This is only possible if ACPI is present*/
if (hardware->acpi.madt.processor_local_apic_count > 0) {
more_printf("CPU (%d logical / %d phys)\n",
hardware->acpi.madt.processor_local_apic_count,
@@ -133,6 +151,7 @@ static void show_cpu(int argc __unused, char **argv __unused,
more_printf("HwVirt : no\n");
}
+ /* Let's display the supported cpu flags */
memset(buffer, 0, sizeof(buffer));
show_flag(buffer, hardware->cpu.flags.fpu, "fpu ", false);
show_flag(buffer, hardware->cpu.flags.vme, "vme ", false);
@@ -221,7 +240,7 @@ static void show_cpu(int argc __unused, char **argv __unused,
show_flag(buffer, hardware->cpu.flags.ept, "ept ", false);
show_flag(buffer, hardware->cpu.flags.vpid, "vpid ", false);
- /* Let's flush the remaining flags */
+ /* No more flags, let's display the remaining flags */
show_flag(buffer, false, "", true);
}
diff --git a/com32/hdt/hdt-util.c b/com32/hdt/hdt-util.c
index 3b41a91..b8d743d 100644
--- a/com32/hdt/hdt-util.c
+++ b/com32/hdt/hdt-util.c
@@ -75,6 +75,9 @@ void sectors_to_size_dec(char *previous_unit, int *previous_size, char *unit,
}
}
+/* Return the human readable size of device
+ * This function avoid disk's size rounding while
+ * not using float as they aren't currently supported */
void sectors_to_size_dec2(int sectors, char *buffer)
{
int b = (sectors / 2);
More information about the Syslinux-commits
mailing list