From 6293d307684215a040bef54f1fb8479bfec0755c Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Tue, 3 Apr 2012 16:07:56 -0700 Subject: Factor out function to find driver for a CPU This function can be used outside of the normal CPU setup Change-Id: I810c63b8aff868a6f69d5b992bea1cfae5a5996b Signed-off-by: Duncan Laurie Signed-off-by: Stefan Reinauer Reviewed-on: http://review.coreboot.org/868 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich --- src/arch/x86/include/arch/cpu.h | 3 +++ src/arch/x86/lib/cpu.c | 18 +++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/arch/x86/include/arch/cpu.h b/src/arch/x86/include/arch/cpu.h index 891e62bbcb..604abde861 100644 --- a/src/arch/x86/include/arch/cpu.h +++ b/src/arch/x86/include/arch/cpu.h @@ -154,6 +154,9 @@ struct cpu_driver { struct cpu_device_id *id_table; }; +struct device; +struct cpu_driver *find_cpu_driver(struct device *cpu); + struct cpu_info { device_t cpu; unsigned long index; diff --git a/src/arch/x86/lib/cpu.c b/src/arch/x86/lib/cpu.c index fac523f902..98ede068ef 100644 --- a/src/arch/x86/lib/cpu.c +++ b/src/arch/x86/lib/cpu.c @@ -211,23 +211,27 @@ static void identify_cpu(struct device *cpu) } } -static void set_cpu_ops(struct device *cpu) +struct cpu_driver *find_cpu_driver(struct device *cpu) { struct cpu_driver *driver; - cpu->ops = 0; for (driver = cpu_drivers; driver < ecpu_drivers; driver++) { struct cpu_device_id *id; - for(id = driver->id_table; id->vendor != X86_VENDOR_INVALID; id++) { + for (id = driver->id_table; + id->vendor != X86_VENDOR_INVALID; id++) { if ((cpu->vendor == id->vendor) && (cpu->device == id->device)) { - goto found; + return driver; } } } - return; -found: - cpu->ops = driver->ops; + return NULL; +} + +static void set_cpu_ops(struct device *cpu) +{ + struct cpu_driver *driver = find_cpu_driver(cpu); + cpu->ops = driver ? driver->ops : NULL; } void cpu_initialize(void) -- cgit v1.2.3