From c4717d5cd73679d8016c0e40102437236768f43f Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Sun, 21 Jun 2009 13:41:28 +0800 Subject: [PATCH] Use mptable_iterate_entries() in mptable_pass2() --- sys/platform/pc32/i386/mp_machdep.c | 122 ++++++++++++---------------- 1 file changed, 50 insertions(+), 72 deletions(-) diff --git a/sys/platform/pc32/i386/mp_machdep.c b/sys/platform/pc32/i386/mp_machdep.c index 206200ec0a..600266f683 100644 --- a/sys/platform/pc32/i386/mp_machdep.c +++ b/sys/platform/pc32/i386/mp_machdep.c @@ -655,15 +655,10 @@ mp_enable(u_int boot_addr) mptable_imcr(&mpt); - /* - * We can safely map physical memory into SMPpt after - * mptable_pass1() completes. - */ - mptable_pass1(&mpt); - /* * Examine the MP table for needed info */ + mptable_pass1(&mpt); mptable_pass2(&mpt); mptable_unmap(&mpt); @@ -839,9 +834,9 @@ static int nintrs; static int processor_entry (const struct PROCENTRY *entry, int cpu); #ifdef APIC_IO -static int bus_entry (bus_entry_ptr entry, int bus); -static int io_apic_entry (io_apic_entry_ptr entry, int apic); -static int int_entry (int_entry_ptr entry, int intr); +static int bus_entry (const struct BUSENTRY *entry, int bus); +static int io_apic_entry (const struct IOAPICENTRY *entry, int apic); +static int int_entry (const struct INTENTRY *entry, int intr); #endif static int lookup_bus_type (char *name); @@ -920,6 +915,39 @@ mptable_pass1(struct mptable_pos *mpt) #endif /* APIC_IO */ } +#ifdef APIC_IO + +struct mptable_ioapic2_cbarg { + int bus; + int apic; + int intr; +}; + +static int +mptable_ioapic_pass2_callback(void *xarg, const void *pos, int type) +{ + struct mptable_ioapic2_cbarg *arg = xarg; + + switch (type) { + case 1: + if (bus_entry(pos, arg->bus)) + ++arg->bus; + break; + + case 2: + if (io_apic_entry(pos, arg->apic)) + ++arg->apic; + break; + + case 3: + if (int_entry(pos, arg->intr)) + ++arg->intr; + break; + } + return 0; +} + +#endif /* APIC_IO */ /* * 2nd pass on motherboard's Intel MP specification table. @@ -933,22 +961,16 @@ mptable_pass1(struct mptable_pos *mpt) static void mptable_pass2(struct mptable_pos *mpt) { - int x; +#ifdef APIC_IO + struct mptable_ioapic2_cbarg arg; mpfps_t fps; - mpcth_t cth; - int totalSize; - void* position; - int count; - int type; - int apic, bus, intr; - int i; + int error, x; POSTCODE(MPTABLE_PASS2_POST); fps = mpt->mp_fps; KKASSERT(fps != NULL); -#ifdef APIC_IO MALLOC(io_apic_versions, u_int32_t *, sizeof(u_int32_t) * mp_napics, M_DEVBUF, M_WAITOK); MALLOC(ioapic, volatile ioapic_t **, sizeof(ioapic_t *) * mp_napics, @@ -957,23 +979,16 @@ mptable_pass2(struct mptable_pos *mpt) M_DEVBUF, M_WAITOK); MALLOC(bus_data, bus_datum *, sizeof(bus_datum) * mp_nbusses, M_DEVBUF, M_WAITOK); -#endif -#ifdef APIC_IO - for (i = 0; i < mp_napics; i++) { - ioapic[i] = permanent_io_mapping(io_apic_address[i]); - } -#endif + for (x = 0; x < mp_napics; x++) + ioapic[x] = permanent_io_mapping(io_apic_address[x]); /* clear various tables */ for (x = 0; x < NAPICID; ++x) { -#ifdef APIC_IO ID_TO_IO(x) = -1; /* phy APIC ID to log CPU/IO table */ IO_TO_ID(x) = -1; /* logical IO to APIC ID table */ -#endif } -#ifdef APIC_IO /* clear bus data table */ for (x = 0; x < mp_nbusses; ++x) bus_data[x].bus_id = 0xff; @@ -983,7 +998,6 @@ mptable_pass2(struct mptable_pos *mpt) io_apic_ints[x].int_type = 0xff; io_apic_ints[x].int_vector = 0xff; } -#endif /* check for use of 'default' configuration */ if (fps->mpfb1 != 0) { @@ -991,48 +1005,12 @@ mptable_pass2(struct mptable_pos *mpt) return; } - cth = mpt->mp_cth; - KKASSERT(cth != NULL); - - /* walk the table, recording info of interest */ - totalSize = cth->base_table_length - sizeof(struct MPCTH); - position = (u_char *) cth + sizeof(struct MPCTH); - count = cth->entry_count; - apic = bus = intr = 0; - - while (count--) { - switch (type = *(u_char *) position) { - case 0: - break; - case 1: -#ifdef APIC_IO - if (bus_entry(position, bus)) - ++bus; -#endif - break; - case 2: -#ifdef APIC_IO - if (io_apic_entry(position, apic)) - ++apic; -#endif - break; - case 3: -#ifdef APIC_IO - if (int_entry(position, intr)) - ++intr; + bzero(&arg, sizeof(arg)); + error = mptable_iterate_entries(mpt->mp_cth, + mptable_ioapic_pass2_callback, &arg); + if (error) + panic("mptable_iterate_entries(ioapic_pass2) failed\n"); #endif - break; - case 4: - /* int_entry(position); */ - break; - default: - panic("mpfps Base Table HOSED!"); - /* NOTREACHED */ - } - - totalSize -= basetable_entry_types[type].length; - position = (uint8_t *)position + basetable_entry_types[type].length; - } } /* @@ -1626,7 +1604,7 @@ processor_entry(const struct PROCENTRY *entry, int cpu) #ifdef APIC_IO static int -bus_entry(bus_entry_ptr entry, int bus) +bus_entry(const struct BUSENTRY *entry, int bus) { int x; char c, name[8]; @@ -1649,7 +1627,7 @@ bus_entry(bus_entry_ptr entry, int bus) } static int -io_apic_entry(io_apic_entry_ptr entry, int apic) +io_apic_entry(const struct IOAPICENTRY *entry, int apic) { if (!(entry->apic_flags & IOAPICENTRY_FLAG_EN)) return 0; @@ -1677,7 +1655,7 @@ lookup_bus_type(char *name) #ifdef APIC_IO static int -int_entry(int_entry_ptr entry, int intr) +int_entry(const struct INTENTRY *entry, int intr) { int apic; -- 2.41.0