diff options
| author | cvs2svn <cvs2svn@FreeBSD.org> | 2006-02-22 21:51:10 +0000 |
|---|---|---|
| committer | cvs2svn <cvs2svn@FreeBSD.org> | 2006-02-22 21:51:10 +0000 |
| commit | 428e0183837d116cd932bd7b2fe0754cb36fa7ee (patch) | |
| tree | 9833d8d1a04d39773904b378198f8d62e64f37de /tools | |
| parent | 42b51b46656a2c87cadeadbd44881c94cf957a32 (diff) | |
Notes
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/regression/geom_eli/init-i-P.t | 22 | ||||
| -rw-r--r-- | tools/tools/ncpus/Makefile | 11 | ||||
| -rw-r--r-- | tools/tools/ncpus/acpidump.h | 177 | ||||
| -rw-r--r-- | tools/tools/ncpus/biosmptable.c | 265 | ||||
| -rw-r--r-- | tools/tools/ncpus/ncpus.c | 14 |
5 files changed, 489 insertions, 0 deletions
diff --git a/tools/regression/geom_eli/init-i-P.t b/tools/regression/geom_eli/init-i-P.t new file mode 100644 index 000000000000..a77c1c6db38e --- /dev/null +++ b/tools/regression/geom_eli/init-i-P.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD$ + +base=`basename $0` +no=45 +sectors=100 +keyfile=`mktemp /tmp/$base.XXXXXX` || exit 1 +mdconfig -a -t malloc -s `expr $sectors + 1` -u $no || exit 1 + +echo "1..1" + +dd if=/dev/random of=${keyfile} bs=512 count=16 >/dev/null 2>&1 + +geli init -i 64 -P -K ${keyfile} md${no} 2>/dev/null +if [ $? -ne 0 ]; then + echo "ok 1" +else + echo "not ok 1" +fi + +mdconfig -d -u $no +rm -f $keyfile diff --git a/tools/tools/ncpus/Makefile b/tools/tools/ncpus/Makefile new file mode 100644 index 000000000000..7d2410c2e138 --- /dev/null +++ b/tools/tools/ncpus/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +PROG= ncpus +SRCS= ncpus.c acpi.c biosmptable.c +NO_MAN= noman +BINDIR= /usr/local/bin + +DPADD= ${LIBDEVINFO} +LDADD= -ldevinfo + +.include <bsd.prog.mk> diff --git a/tools/tools/ncpus/acpidump.h b/tools/tools/ncpus/acpidump.h new file mode 100644 index 000000000000..9c2b5b6e502d --- /dev/null +++ b/tools/tools/ncpus/acpidump.h @@ -0,0 +1,177 @@ +/*- + * Copyright (c) 1999 Doug Rabson + * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _ACPIDUMP_H_ +#define _ACPIDUMP_H_ + +/* Root System Description Pointer */ +struct ACPIrsdp { + u_char signature[8]; + u_char sum; + u_char oem[6]; + u_char revision; + u_int32_t rsdt_addr; + u_int32_t length; + u_int64_t xsdt_addr; + u_char xsum; + u_char _reserved_[3]; +} __packed; + +/* System Description Table */ +struct ACPIsdt { + u_char signature[4]; + u_int32_t len; + u_char rev; + u_char check; + u_char oemid[6]; + u_char oemtblid[8]; + u_int32_t oemrev; + u_char creator[4]; + u_int32_t crerev; +#define SIZEOF_SDT_HDR 36 /* struct size except body */ + u_int32_t body[1];/* This member should be casted */ +} __packed; + +struct MADT_local_apic { + u_char cpu_id; + u_char apic_id; + u_int32_t flags; +#define ACPI_MADT_APIC_LOCAL_FLAG_ENABLED 1 +} __packed; + +struct MADT_io_apic { + u_char apic_id; + u_char reserved; + u_int32_t apic_addr; + u_int32_t int_base; +} __packed; + +struct MADT_int_override { + u_char bus; + u_char source; + u_int32_t intr; + u_int16_t mps_flags; +#define MPS_INT_FLAG_POLARITY_MASK 0x3 +#define MPS_INT_FLAG_POLARITY_CONFORM 0x0 +#define MPS_INT_FLAG_POLARITY_HIGH 0x1 +#define MPS_INT_FLAG_POLARITY_LOW 0x3 +#define MPS_INT_FLAG_TRIGGER_MASK 0xc +#define MPS_INT_FLAG_TRIGGER_CONFORM 0x0 +#define MPS_INT_FLAG_TRIGGER_EDGE 0x4 +#define MPS_INT_FLAG_TRIGGER_LEVEL 0xc +} __packed; + +struct MADT_nmi { + u_int16_t mps_flags; + u_int32_t intr; +} __packed; + +struct MADT_local_nmi { + u_char cpu_id; + u_int16_t mps_flags; + u_char lintpin; +} __packed; + +struct MADT_local_apic_override { + u_char reserved[2]; + u_int64_t apic_addr; +} __packed; + +struct MADT_io_sapic { + u_char apic_id; + u_char reserved; + u_int32_t int_base; + u_int64_t apic_addr; +} __packed; + +struct MADT_local_sapic { + u_char cpu_id; + u_char apic_id; + u_char apic_eid; + u_char reserved[3]; + u_int32_t flags; +} __packed; + +struct MADT_int_src { + u_int16_t mps_flags; + u_char type; +#define ACPI_MADT_APIC_INT_SOURCE_PMI 1 +#define ACPI_MADT_APIC_INT_SOURCE_INIT 2 +#define ACPI_MADT_APIC_INT_SOURCE_CPEI 3 /* Corrected Platform Error */ + u_char cpu_id; + u_char cpu_eid; + u_char sapic_vector; + u_int32_t intr; + u_char reserved[4]; +} __packed; + +struct MADT_APIC { + u_char type; +#define ACPI_MADT_APIC_TYPE_LOCAL_APIC 0 +#define ACPI_MADT_APIC_TYPE_IO_APIC 1 +#define ACPI_MADT_APIC_TYPE_INT_OVERRIDE 2 +#define ACPI_MADT_APIC_TYPE_NMI 3 +#define ACPI_MADT_APIC_TYPE_LOCAL_NMI 4 +#define ACPI_MADT_APIC_TYPE_LOCAL_OVERRIDE 5 +#define ACPI_MADT_APIC_TYPE_IO_SAPIC 6 +#define ACPI_MADT_APIC_TYPE_LOCAL_SAPIC 7 +#define ACPI_MADT_APIC_TYPE_INT_SRC 8 + u_char len; + union { + struct MADT_local_apic local_apic; + struct MADT_io_apic io_apic; + struct MADT_int_override int_override; + struct MADT_nmi nmi; + struct MADT_local_nmi local_nmi; + struct MADT_local_apic_override local_apic_override; + struct MADT_io_sapic io_sapic; + struct MADT_local_sapic local_sapic; + struct MADT_int_src int_src; + } body; +} __packed; + +struct MADTbody { + u_int32_t lapic_addr; + u_int32_t flags; +#define ACPI_APIC_FLAG_PCAT_COMPAT 1 /* System has dual-8259 setup. */ + u_char body[1]; +} __packed; + +/* + * Addresses to scan on ia32 for the RSD PTR. According to section 5.2.2 + * of the ACPI spec, we only consider two regions for the base address: + * 1. EBDA (1 KB area addressed to by 16 bit pointer at 0x40E) + * 2. High memory (0xE0000 - 0xFFFFF) + */ +#define RSDP_EBDA_PTR 0x40E +#define RSDP_EBDA_SIZE 0x400 +#define RSDP_HI_START 0xE0000 +#define RSDP_HI_SIZE 0x20000 + +#endif /* !_ACPIDUMP_H_ */ diff --git a/tools/tools/ncpus/biosmptable.c b/tools/tools/ncpus/biosmptable.c new file mode 100644 index 000000000000..da48700691cc --- /dev/null +++ b/tools/tools/ncpus/biosmptable.c @@ -0,0 +1,265 @@ +/*- + * Copyright (c) 2005 Sandvine Incorporated. All righs reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Author: Ed Maste <emaste@phaedrus.sandvine.ca> + */ + +/* + * This module detects Intel Multiprocessor spec info (mptable) and returns + * the number of cpu's identified. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <unistd.h> +#include <fcntl.h> +#include <paths.h> +#include <err.h> + +#include <machine/mptable.h> + +#define MPFPS_SIG "_MP_" +#define MPCTH_SIG "PCMP" + +#define PTOV(pa) ((off_t)(pa)) + +static mpfps_t biosmptable_find_mpfps(void); +static mpfps_t biosmptable_search_mpfps(off_t base, int length); +static mpcth_t biosmptable_check_mpcth(off_t addr); + +static int memopen(void); +static void memclose(void); + +int +biosmptable_detect(void) +{ + mpfps_t mpfps; + mpcth_t mpcth; + char buf[16]; + char *entry_type_p; + proc_entry_ptr proc; + int ncpu, i; + + if (!memopen()) + return -1; /* XXX 0? */ + /* locate and validate the mpfps */ + mpfps = biosmptable_find_mpfps(); + mpcth = NULL; + if (mpfps == NULL) { + ncpu = 0; + } else if (mpfps->config_type != 0) { + /* + * If thie config_type is nonzero then this is a default configuration + * from Chapter 5 in the MP spec. Report 2 cpus and 1 I/O APIC. + */ + ncpu = 2; + } else { + ncpu = 0; + mpcth = biosmptable_check_mpcth(PTOV(mpfps->pap)); + if (mpcth != NULL) { + entry_type_p = (char *)(mpcth + 1); + for (i = 0; i < mpcth->entry_count; i++) { + switch (*entry_type_p) { + case 0: + entry_type_p += sizeof(struct PROCENTRY); + proc = (proc_entry_ptr) entry_type_p; + warnx("MPTable: Found CPU APIC ID %d %s", + proc->apic_id, + proc->cpu_flags & PROCENTRY_FLAG_EN ? + "enabled" : "disabled"); + if (proc->cpu_flags & PROCENTRY_FLAG_EN) + ncpu++; + break; + case 1: + entry_type_p += sizeof(struct BUSENTRY); + break; + case 2: + entry_type_p += sizeof(struct IOAPICENTRY); + break; + case 3: + case 4: + entry_type_p += sizeof(struct INTENTRY); + break; + default: + warnx("unknown mptable entry type (%d)", *entry_type_p); + goto done; /* XXX error return? */ + } + } + done: + ; + } + } + memclose(); + if (mpcth != NULL) + free(mpcth); + if (mpfps != NULL) + free(mpfps); + + return ncpu; +} + +static int pfd = -1; + +static int +memopen(void) +{ + if (pfd < 0) { + pfd = open(_PATH_MEM, O_RDONLY); + if (pfd < 0) + warn("%s: cannot open", _PATH_MEM); + } + return pfd >= 0; +} + +static void +memclose(void) +{ + if (pfd >= 0) { + close(pfd); + pfd = -1; + } +} + +static int +memread(off_t addr, void* entry, size_t size) +{ + if (pread(pfd, entry, size, addr) != size) { + warn("pread (%lu @ 0x%lx)", size, addr); + return 0; + } + return 1; +} + + +/* + * Find the MP Floating Pointer Structure. See the MP spec section 4.1. + */ +static mpfps_t +biosmptable_find_mpfps(void) +{ + mpfps_t mpfps; + uint16_t addr; + + /* EBDA is the 1 KB addressed by the 16 bit pointer at 0x40E. */ + if (!memread(PTOV(0x40E), &addr, sizeof(addr))) + return (NULL); + mpfps = biosmptable_search_mpfps(PTOV(addr << 4), 0x400); + if (mpfps != NULL) + return (mpfps); + + /* Check the BIOS. */ + mpfps = biosmptable_search_mpfps(PTOV(0xf0000), 0x10000); + if (mpfps != NULL) + return (mpfps); + + return (NULL); +} + +static mpfps_t +biosmptable_search_mpfps(off_t base, int length) +{ + mpfps_t mpfps; + u_int8_t *cp, sum; + int ofs, idx; + + mpfps = malloc(sizeof(*mpfps)); + if (mpfps == NULL) { + warnx("unable to malloc space for MP Floating Pointer Structure"); + return (NULL); + } + /* search on 16-byte boundaries */ + for (ofs = 0; ofs < length; ofs += 16) { + if (!memread(base + ofs, mpfps, sizeof(*mpfps))) + break; + + /* compare signature, validate checksum */ + if (!strncmp(mpfps->signature, MPFPS_SIG, strlen(MPFPS_SIG))) { + cp = (u_int8_t *)mpfps; + sum = 0; + /* mpfps is 16 bytes, or one "paragraph" */ + if (mpfps->length != 1) { + warnx("bad mpfps length (%d)", mpfps->length); + continue; + } + for (idx = 0; idx < mpfps->length * 16; idx++) + sum += *(cp + idx); + if (sum != 0) { + warnx("bad mpfps checksum (%d)\n", sum); + continue; + } + return (mpfps); + } + } + free(mpfps); + return (NULL); +} + +static mpcth_t +biosmptable_check_mpcth(off_t addr) +{ + mpcth_t mpcth; + u_int8_t *cp, sum; + int idx, table_length; + + /* mpcth must be in the first 1MB */ + if ((u_int32_t)addr >= 1024 * 1024) { + warnx("bad mpcth address (0x%lx)\n", addr); + return (NULL); + } + + mpcth = malloc(sizeof(*mpcth)); + if (mpcth == NULL) { + warnx("unable to malloc space for MP Configuration Table Header"); + return (NULL); + } + if (!memread(addr, mpcth, sizeof(*mpcth))) + goto bad; + /* Compare signature and validate checksum. */ + if (strncmp(mpcth->signature, MPCTH_SIG, strlen(MPCTH_SIG)) != 0) { + warnx("bad mpcth signature"); + goto bad; + } + table_length = mpcth->base_table_length; + mpcth = (mpcth_t) realloc(mpcth, table_length); + if (mpcth == NULL) { + warnx("unable to realloc space for mpcth (len %u)", table_length); + return (NULL); + } + if (!memread(addr, mpcth, table_length)) + goto bad; + cp = (u_int8_t *)mpcth; + sum = 0; + for (idx = 0; idx < mpcth->base_table_length; idx++) + sum += *(cp + idx); + if (sum != 0) { + warnx("bad mpcth checksum (%d)", sum); + goto bad; + } + + return mpcth; +bad: + free(mpcth); + return (NULL); +} diff --git a/tools/tools/ncpus/ncpus.c b/tools/tools/ncpus/ncpus.c new file mode 100644 index 000000000000..f0d3a6bcd61d --- /dev/null +++ b/tools/tools/ncpus/ncpus.c @@ -0,0 +1,14 @@ +/* $FreeBSD$ */ + +#include <stdio.h> + +extern int acpi_detect(void); +extern int biosmptable_detect(void); + +int +main(int argc, char *argv[]) +{ + printf("acpi: %d\n", acpi_detect()); + printf("mptable: %d\n", biosmptable_detect()); + return 0; +} |
