/* * acpi_tables.c - ACPI Boot-Time Table Parsing * * Copyright (C) 2001 Paul Diefenbaugh * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ #include #include #include #include #include #include #include #include #include #include /*#include */ #define PREFIX "ACPI: " #define ACPI_MAX_TABLES 256 static char *acpi_table_signatures[ACPI_TABLE_COUNT] = { [ACPI_TABLE_UNKNOWN] = "????", [ACPI_APIC] = "APIC", [ACPI_BOOT] = "BOOT", [ACPI_DBGP] = "DBGP", [ACPI_DSDT] = "DSDT", [ACPI_ECDT] = "ECDT", [ACPI_ETDT] = "ETDT", [ACPI_FADT] = "FACP", [ACPI_FACS] = "FACS", [ACPI_OEMX] = "OEM", [ACPI_PSDT] = "PSDT", [ACPI_SBST] = "SBST", [ACPI_SLIT] = "SLIT", [ACPI_SPCR] = "SPCR", [ACPI_SRAT] = "SRAT", [ACPI_SSDT] = "SSDT", [ACPI_SPMI] = "SPMI", [ACPI_HPET] = "HPET", }; static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" }; static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" }; /* System Description Table (RSDT/XSDT) */ struct acpi_table_sdt { unsigned long pa; enum acpi_table_id id; unsigned long size; } __attribute__ ((packed)); static unsigned long sdt_pa; /* Physical Address */ static unsigned long sdt_count; /* Table count */ static struct acpi_table_sdt sdt_entry[ACPI_MAX_TABLES]; void acpi_table_print ( struct acpi_table_header *header, unsigned long phys_addr) { char *name = NULL; if (!header) return; /* Some table signatures aren't good table names */ if (!strncmp((char *) &header->signature, acpi_table_signatures[ACPI_APIC], sizeof(header->signature))) { name = "MADT"; } else if (!strncmp((char *) &header->signature, acpi_table_signatures[ACPI_FADT], sizeof(header->signature))) { name = "FADT"; } else name = header->signature; printk(KERN_INFO PREFIX "%.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n", name, header->revision, header->oem_id, header->oem_table_id, header->oem_revision, header->asl_compiler_id, header->asl_compiler_revision, (void *) phys_addr); } void acpi_table_print_madt_entry ( acpi_table_entry_header *header) { if (!header) return; switch (header->type) { case ACPI_MADT_LAPIC: { struct acpi_table_lapic *p = (struct acpi_table_lapic*) header; printk(KERN_INFO PREFIX "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n", p->acpi_id, p->id, p->flags.enabled?"enabled":"disabled"); } break; case ACPI_MADT_IOAPIC: { struct acpi_table_ioapic *p = (struct acpi_table_ioapic*) header; printk(KERN_INFO PREFIX "IOAPIC (id[0x%02x] address[0x%08x] global_irq_base[0x%x])\n", p->id, p->address, p->global_irq_base); } break; case ACPI_MADT_INT_SRC_OVR: { struct acpi_table_int_src_ovr *p = (struct acpi_table_int_src_ovr*) header; printk(KERN_INFO PREFIX "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n", p->bus, p->bus_irq, p->global_irq, mps_inti_flags_polarity[p->flags.polarity], mps_inti_flags_trigger[p->flags.trigger]); if(p->flags.reserved) printk(KERN_INFO PREFIX "INT_SRC_OVR unexpected reserved flags: 0x%x\n", p->flags.reserved); } break; case ACPI_MADT_NMI_SRC: { struct acpi_table_nmi_src *p = (struct acpi_table_nmi_src*) header; printk(KERN_INFO PREFIX "NMI_SRC (%s %s global_irq %d)\n", mps_inti_flags_polarity[p->flags.polarity], mps_inti_flags_trigger[p->flags.trigger], p->global_irq); } break; case ACPI_MADT_LAPIC_NMI: { struct acpi_table_lapic_nmi *p = (struct acpi_table_lapic_nmi*) header; printk(KERN_INFO PREFIX "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n", p->acpi_id, mps_inti_flags_polarity[p->flags.polarity], mps_inti_flags_trigger[p->flags.trigger], p->lint); } break; case ACPI_MADT_LAPIC_ADDR_OVR: { struct acpi_table_lapic_addr_ovr *p = (struct acpi_table_lapic_addr_ovr*) header; printk(KERN_INFO PREFIX "LAPIC_ADDR_OVR (address[%p])\n", (void *) (unsigned long) p->address); } break; case ACPI_MADT_IOSAPIC: { struct acpi_table_iosapic *p = (struct acpi_table_iosapic*) header; printk(KERN_INFO PREFIX "IOSAPIC (id[0x%x] global_irq_base[0x%x] address[%p])\n", p->id, p->global_irq_base, (void *) (unsigned long) p->address); } break; case ACPI_MADT_LSAPIC: { struct acpi_table_lsapic *p = (struct acpi_table_lsapic*) header; printk(KERN_INFO PREFIX "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n", p->acpi_id, p->id, p->eid, p->flags.enabled?"enabled":"disabled"); } break; case ACPI_MADT_PLAT_INT_SRC: { struct acpi_table_plat_int_src *p = (struct acpi_table_plat_int_src*) header; printk(KERN_INFO PREFIX "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n", mps_inti_flags_polarity[p->flags.polarity], mps_inti_flags_trigger[p->flags.trigger], p->type, p->id, p->eid, p->iosapic_vector, p->global_irq); } break; default: printk(KERN_WARNING PREFIX "Found unsupported MADT entry (type = 0x%x)\n", header->type); break; } } static int acpi_table_compute_checksum ( void *table_pointer, unsigned long length) { u8 *p = (u8 *) table_pointer; unsigned long remains = length; unsigned long sum = 0; if (!p || !length) return -EINVAL; while (remains--) sum += *p++; return (sum & 0xFF); } /* * acpi_get_table_header_early() * for acpi_blacklisted(), acpi_table_get_sdt() */ int __init acpi_get_table_header_early ( enum acpi_table_id id, struct acpi_table_header **header) { unsigned int i; enum acpi_table_id temp_id; /* DSDT is different from the rest */ if (id == ACPI_DSDT) temp_id = ACPI_FADT; else temp_id = id; /* Locate the table. */ for (i = 0; i < sdt_count; i++) { if (sdt_entry[i].id != temp_id) continue; *header = (void *) __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size); if (!*header) { printk(KERN_WARNING PREFIX "Unable to map %s\n", acpi_table_signatures[temp_id]); return -ENODEV; } break; } if (!*header) { printk(KERN_WARNING PREFIX "%s not present\n", acpi_table_signatures[id]); return -ENODEV; } /* Map the DSDT header via the pointer in the FADT */ if (id == ACPI_DSDT) { struct fadt_descriptor_rev2 *fadt = (struct fadt_descriptor_rev2 *) *header; if (fadt->revision == 3 && fadt->Xdsdt) { *header = (void *) __acpi_map_table(fadt->Xdsdt, sizeof(struct acpi_table_header)); } else if (fadt->V1_dsdt) { *header = (void *) __acpi_map_table(fadt->V1_dsdt, sizeof(struct acpi_table_header)); } else *header = 0; if (!*header) { printk(KERN_WARNING PREFIX "Unable to map DSDT\n"); return -ENODEV; } } return 0; } int __init acpi_table_parse_madt_family ( enum acpi_table_id id, unsigned long madt_size, int entry_id, acpi_madt_entry_handler handler) { void *madt = NULL; acpi_table_entry_header *entry = NULL; unsigned long count = 0; unsigned long madt_end = 0; unsigned int i = 0; if (!handler) return -EINVAL; /* Locate the MADT (if exists). There should only be one. */ for (i = 0; i < sdt_count; i++) { if (sdt_entry[i].id != id) continue; madt = (void *) __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size); if (!madt) { printk(KERN_WARNING PREFIX "Unable to map %s\n", acpi_table_signatures[id]); return -ENODEV; } break; } if (!madt) { printk(KERN_WARNING PREFIX "%s not present\n", acpi_table_signatures[id]); return -ENODEV; } madt_end = (unsigned long) madt + sdt_entry[i].size; /* Parse all entries looking for a match. */ entry = (acpi_table_entry_header *) ((unsigned long) madt + madt_size); while (((unsigned long) entry) < madt_end) { if (entry->type == entry_id) { count++; handler(entry); } entry = (acpi_table_entry_header *) ((unsigned long) entry + entry->length); } return count; } int __init acpi_table_parse_madt ( enum acpi_madt_entry_id id, acpi_madt_entry_handler handler) { return acpi_table_parse_madt_family(ACPI_APIC, sizeof(struct acpi_table_madt), id, handler); } int __init acpi_table_parse ( enum acpi_table_id id, acpi_table_h
/*
    ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

#include "hal.h"
#include "ch_test.h"
#include "test_root.h"

/**
 * @page test_sequence_001 Threads Functionality
 *
 * File: @ref test_sequence_001.c
 *
 * <h2>Description</h2>
 * This sequence tests the ChibiOS/NIL functionalities related to threading.
 *
 * <h2>Test Cases</h2>
 * - @subpage test_001_001
 * - @subpage test_001_002
 * .
 */

/****************************************************************************
 * Shared code.
 ****************************************************************************/


/****************************************************************************
 * Test cases.
 ****************************************************************************/

#if TRUE || defined(__DOXYGEN__)
/**
 * @page test_001_001 System Tick Counter functionality
 *
 * <h2>Description</h2>
 * The functionality of the API @p chVTGetSystemTimeX() is tested.
 *
 * <h2>Conditions</h2>
 * None.
 *
 * <h2>Test Steps</h2>
 * - A System Tick Counter increment is expected, the test simply hangs if
 *   it does not happen.
 * .
 */

static void test_001_001_execute(void) {
  systime_t time;

  /* A System Tick Counter increment is expected, the test simply hangs if
     it does not happen.*/
  test_set_step(1);
  {
    time = chVTGetSystemTimeX();
    while (time == chVTGetSystemTimeX()) {
    }
  }
}

static const testcase_t test_001_001 = {
  "System Tick Counter functionality",
  NULL,
  NULL,
  test_001_001_execute
};
#endif /* TRUE */

#if TRUE || defined(__DOXYGEN__)
/**
 * @page test_001_002 Thread Sleep functionality
 *
 * <h2>Description</h2>
 * The functionality of the API @p chThdSleep() and derivatives is tested.
 *
 * <h2>Conditions</h2>
 * None.
 *
 * <h2>Test Steps</h2>
 * - The current system time is read then a sleep is performed for 100 system
 *   ticks and on exit the system time is verified again.
 * - The current system time is read then a sleep is performed for 100000
 *   microseconds and on exit the system time is verified again.
 * - The current system time is read then a sleep is performed for 100
 *   milliseconds and on exit the system time is verified again.
 * - The current system time is read then a sleep is performed for 1
 *   second and on exit the system time is verified again.
 * .
 */

static void test_001_002_execute(void) {
  systime_t time;

  /* The current system time is read then a sleep is performed for 100 system
     ticks and on exit the system time is verified again.*/
  test_set_step(1);
  {
    time = chVTGetSystemTimeX();
    chThdSleep(100);
    test_assert_time_window(time + 100,
                            time + 100 + 1,
                            "out of time window");
  }

  /* The current system time is read then a sleep is performed for 100000
     microseconds and on exit the system time is verified again.*/
  test_set_step(2);
  {
    time = chVTGetSystemTimeX();
    chThdSleepMicroseconds(100);
    test_assert_time_window(time + US2ST(100),
                            time + US2ST(100) + 1,
                            "out of time window");
  }

  /* The current system time is read then a sleep is performed for 100
     milliseconds and on exit the system time is verified again.*/
  test_set_step(3);
  {
    time = chVTGetSystemTimeX();
    chThdSleepMilliseconds(100);
    test_assert_time_window(time + MS2ST(100),
                            time + MS2ST(100) + 1,
                            "out of time window");
  }

  /* The current system time is read then a sleep is performed for 1
     second and on exit the system time is verified again.*/
  test_set_step(4);
  {
    time = chVTGetSystemTimeX();
    chThdSleepSeconds(1);
    test_assert_time_window(time + S2ST(1),
                            time + S2ST(1) + 1,
                            "out of time window");
  }

  test_set_step(5);
  {
    time = chVTGetSystemTimeX();
    chThdSleepUntil(time + 100);
    test_assert_time_window(time + 100,
                            time + 100 + 1,
                            "out of time window");
  }
}

static const testcase_t test_001_002 = {
  "Thread Sleep functionality",
  NULL,
  NULL,
  test_001_002_execute
};
#endif /* TRUE */

 /****************************************************************************
 * Exported data.
 ****************************************************************************/

/**
 * @brief   Sequence brief description.
 */
const testcase_t * const test_sequence_001[] = {
#if TRUE || defined(__DOXYGEN__)
  &test_001_001,
#endif
#if TRUE || defined(__DOXYGEN__)
  &test_001_002,
#endif
  NULL
};