From: Andi Kleen <andi@firstfloor.org>
To: Len Brown <lenb@kernel.org>
Cc: sfi-devel@simplefirmware.org, linux-kernel@vger.kernel.org,
Feng Tang <feng.tang@intel.com>, Len Brown <len.brown@intel.com>
Subject: Re: [PATCH 3/8] SFI: core support
Date: Tue, 23 Jun 2009 14:32:56 +0200 [thread overview]
Message-ID: <87iqin166f.fsf@basil.nowhere.org> (raw)
In-Reply-To: <8d9bab79ce1169afd419035f70177e52d47626ca.1245740912.git.len.brown@intel.com> (Len Brown's message of "Tue, 23 Jun 2009 03:14:01 -0400")
Len Brown <lenb@kernel.org> writes:
> +static ulong __init sfi_early_find_syst(void)
> +{
> + unsigned long i;
> + char *pchar = (char *)SFI_SYST_SEARCH_BEGIN;
> +
> + for (i = 0; SFI_SYST_SEARCH_BEGIN + i < SFI_SYST_SEARCH_END; i += 16, pchar += 16) {
> + if (!strncmp(SFI_SIG_SYST, pchar, SFI_SIGNATURE_SIZE))
> + return SFI_SYST_SEARCH_BEGIN + i;
Such additional memory scans are always a bit risky, e.g. if there's
stray hardware there. Has it been verified that existing kernels
already scan this area?
> + mmapt = NULL;
> + for (i = 0; i < tbl_cnt; i++) {
> + if (!strncmp(SFI_SIG_MMAP, (char *)(u32)*pentry, 4)) {
> + mmapt = (struct sfi_table_simple *)(u32)*pentry;
> + break;
> + }
> + pentry++;
> + }
> + if (!mmapt)
> + return -1;
printk here?
> +
> + /* refer copy_e820_memory() */
> + num = SFI_GET_ENTRY_NUM(mmapt, sfi_mem_entry);
> + mentry = (struct sfi_mem_entry *)mmapt->pentry;
> + for (i = 0; i < num; i++) {
> + start = mentry->phy_start;
> + size = mentry->pages << PAGE_SHIFT;
> + end = start + size;
> +
> + if (start > end)
> + return -1;
> +
> + pr_debug(PREFIX "start = 0x%08x end = 0x%08x type = %d\n",
> + (u32)start, (u32)end, mentry->type);
> +
> + /* translate SFI mmap type to E820 map type */
> + switch (mentry->type) {
> + case EFI_CONVENTIONAL_MEMORY:
> + type = E820_RAM;
> + break;
> + case EFI_MEMORY_MAPPED_IO:
> + case EFI_UNUSABLE_MEMORY:
> + case EFI_RUNTIME_SERVICES_DATA:
> + mentry++;
Surely UNUSTABLE and RUNTIME_SERVICES should be added somewhere to the resources,
otherwise MMIO allocation might put something there.
> + }
> +
> + return 0;
> +}
> +
> +#ifdef CONFIG_X86_LOCAL_APIC
> +void __init mp_sfi_register_lapic_address(u64 address)
> +{
> + mp_lapic_addr = (unsigned long) address;
> +
> + set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
> +
> + if (boot_cpu_physical_apicid == -1U)
> + boot_cpu_physical_apicid = read_apic_id();
> +
> + pr_info(PREFIX "Boot CPU = %d\n", boot_cpu_physical_apicid);
That's the same what ACPI does, isn't it? Some code sharing
would be good.
> +static int __init sfi_parse_cpus(struct sfi_table_header *table)
> +{
> + struct sfi_table_simple *sb;
> + struct sfi_cpu_table_entry *pentry;
> + int i;
> + int cpu_num;
> +
> + BUG_ON(!table);
Another useless BUG_ON. Some more below too.
> + sb = (struct sfi_table_simple *)table;
> +
> + cpu_num = SFI_GET_ENTRY_NUM(sb, sfi_cpu_table_entry);
> + pentry = (struct sfi_cpu_table_entry *) sb->pentry;
> +
> + for (i = 0; i < cpu_num; i++) {
> + mp_sfi_register_lapic(pentry->apicid);
> + pentry++;
> + }
Array overflow checking?
> + mp_ioapics[idx].apicver = 0;
> +#endif
> +
> + pr_info(PREFIX "IOAPIC[%d]: apic_id %d, version %d, address 0x%x\n",
> + idx, mp_ioapics[idx].apicid,
> + mp_ioapics[idx].apicver, (u32)mp_ioapics[idx].apicaddr);
> + /*
> + * Build basic GSI lookup table to facilitate gsi->io_apic lookups
> + * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
> + */
> + mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].apicid;
> + mp_ioapic_routing[idx].gsi_base = gsi_base;
> + mp_ioapic_routing[idx].gsi_end = gsi_base +
> + io_apic_get_redir_entries(idx);
> + gsi_base = mp_ioapic_routing[idx].gsi_end + 1;
> + pr_info(PREFIX "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
> + "GSI %d-%d\n", idx, mp_ioapics[idx].apicid,
> + mp_ioapics[idx].apicver, (u32)mp_ioapics[idx].apicaddr,
> + mp_ioapic_routing[idx].gsi_base,
> + mp_ioapic_routing[idx].gsi_end);
That printk should be dependent on the runtime apic verbosity level?
> +
> +/*
> + * flag for whether using ioremap() to map the sfi tables, if yes
> + * each table only need be mapped once, otherwise each arch's
> + * early_ioremap and early_iounmap should be used each time a
> + * table is visited
> + */
> +static u32 sfi_tbl_permanant_mapped;
permanant is a typo?
> +
> +static void __iomem *sfi_map_memory(u32 phys, u32 size)
> +{
> + if (!phys || !size)
> + return NULL;
> +
> + if (sfi_tbl_permanant_mapped)
> + return ioremap((unsigned long)phys, size);
> + else
> + return arch_early_ioremap((unsigned long)phys, size);
> +}
imho it would be cleaner if the callers just called these functions
directly. Are the !phys !size checks really needed?
> +
> +void sfi_tb_install_table(u64 addr, u32 flags)
> +{
> + struct sfi_table_header *table;
> + u32 length;
> +
> + /* only map table header before knowing actual length */
> + table = sfi_map_memory(addr, sizeof(struct sfi_table_header));
> + if (!table)
> + return;
> +
> + length = table->length;
> + sfi_unmap_memory(table, sizeof(struct sfi_table_header));
> +
> + table = sfi_map_memory(addr, length);
> + if (!table)
> + return;
Since the mappings are always 4K you would only need to remap
if the size is > PAGE_SIZE
> +
> + if (sfi_tb_verify_checksum(table, length))
> + goto unmap_and_exit;
> +
> + /* Initialize sfi_tblist entry */
> + sfi_tblist.tables[sfi_tblist.count].flags = flags;
> + sfi_tblist.tables[sfi_tblist.count].address = addr;
> + sfi_tblist.tables[sfi_tblist.count].pointer = NULL;
> + memcpy(&sfi_tblist.tables[sfi_tblist.count].header,
> + table, sizeof(struct sfi_table_header));
To be honest I'm not sure why this list exists at all.
Is it that difficult to just rewalk the firmware supplied
table as needed?
-andi
--
ak@linux.intel.com -- Speaking for myself only.
next prev parent reply other threads:[~2009-06-23 12:33 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-23 7:13 [RFC/PATCH 2.6.32] Simple Firmware Interface (SFI): initial support Len Brown
2009-06-23 7:13 ` [PATCH 1/8] SFI: Simple Firmware Interface - new Linux sub-system Len Brown
2009-06-23 7:14 ` [PATCH 2/8] SFI: include/linux/sfi.h Len Brown
2009-06-23 7:28 ` Ingo Molnar
2009-06-23 7:47 ` Feng Tang
2009-06-23 8:00 ` Ingo Molnar
2009-06-23 8:02 ` Feng Tang
2009-06-23 8:09 ` Ingo Molnar
2009-06-23 15:14 ` H. Peter Anvin
2009-06-30 21:57 ` Andrew Morton
2009-06-30 21:59 ` Ingo Molnar
2009-06-23 9:06 ` Sam Ravnborg
2009-06-23 15:52 ` Feng Tang
2009-06-23 19:26 ` Sam Ravnborg
2009-06-23 7:14 ` [PATCH 3/8] SFI: core support Len Brown
2009-06-23 7:56 ` Ingo Molnar
2009-06-23 8:32 ` Feng Tang
2009-06-23 9:03 ` Ingo Molnar
2009-06-23 9:15 ` Feng Tang
2009-06-23 17:20 ` Len Brown
2009-06-23 19:20 ` Ingo Molnar
2009-06-23 12:32 ` Andi Kleen [this message]
2009-06-23 16:57 ` Len Brown
2009-06-24 3:34 ` Feng Tang
2009-06-24 7:12 ` Andi Kleen
2009-06-24 7:40 ` Feng Tang
2009-06-24 7:55 ` Andi Kleen
2009-06-23 7:14 ` [PATCH 4/8] SFI: Hook boot-time initialization Len Brown
2009-06-23 7:14 ` [PATCH 5/8] SFI: Hook e820 memory map initialization Len Brown
2009-06-23 7:14 ` [PATCH 6/8] SFI: add ACPI extensions Len Brown
2009-06-23 12:18 ` Andi Kleen
2009-06-23 16:51 ` Len Brown
2009-06-23 7:14 ` [PATCH 7/8] SFI, PCI: Hook MMCONFIG Len Brown
2009-06-23 7:14 ` [PATCH 8/8] SFI: expose IO-APIC routines to SFI, not just ACPI Len Brown
2009-06-23 7:58 ` Ingo Molnar
2009-06-23 7:23 ` [PATCH 1/8] SFI: Simple Firmware Interface - new Linux sub-system Ingo Molnar
2009-06-23 18:31 ` [RFC/PATCH 2.6.32] Simple Firmware Interface (SFI): initial support Matthew Garrett
2009-06-23 18:41 ` Len Brown
2009-06-22 19:43 ` Pavel Machek
2009-06-24 21:13 ` Len Brown
2009-07-11 22:02 ` Pavel Machek
2009-07-13 3:25 ` [SFI-devel] " Peter Stuge
2009-06-23 18:51 ` Matthew Garrett
2009-06-23 20:00 ` Len Brown
2009-06-23 20:23 ` Matthew Garrett
2009-06-23 20:45 ` Matthew Garrett
2009-06-23 21:23 ` Alan Cox
2009-06-23 22:34 ` Len Brown
2009-06-23 22:20 ` Len Brown
2009-06-23 22:56 ` Matthew Garrett
2009-06-23 23:00 ` [SFI-devel] " Justen, Jordan L
2009-06-24 0:35 ` Len Brown
2009-06-23 21:33 ` Len Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87iqin166f.fsf@basil.nowhere.org \
--to=andi@firstfloor.org \
--cc=feng.tang@intel.com \
--cc=len.brown@intel.com \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sfi-devel@simplefirmware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox