Message ID | 20200614165958.159716-9-sjg@chromium.org |
---|---|
State | Accepted |
Commit | 20b049e88548a88bac3609fae99790bb79ee1233 |
Headers | show |
Series | x86: Enhance MTRR functionality to support multiple CPUs | expand |
On Mon, Jun 15, 2020 at 1:00 AM Simon Glass <sjg at chromium.org> wrote: > > This function is misnamed since it does not actually init the BSP. Also > it is convenient to adjust it to return a little more information. > > Rename and update the function, to allow it to return the BSP CPU device > and number, as well as the total number of CPUs. > > Signed-off-by: Simon Glass <sjg at chromium.org> > Reviewed-by: Wolfgang Wallner <wolfgang.wallner at br-automation.com> > --- > > Changes in v2: > - Drop change to include/dm/uclass.h > - Mention error return in get_bsp() > > arch/x86/cpu/mp_init.c | 35 ++++++++++++++++++++++------------- > 1 file changed, 22 insertions(+), 13 deletions(-) > > diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c > index e0270e71db..cd4cae559d 100644 > --- a/arch/x86/cpu/mp_init.c > +++ b/arch/x86/cpu/mp_init.c > @@ -421,9 +421,17 @@ static int bsp_do_flight_plan(struct udevice *cpu, struct mp_flight_plan *plan, > return ret; > } > > -static int init_bsp(struct udevice **devp) > +/** > + * get_bsp() - Get information about the bootstrap processor > + * > + * @devp: If non-NULL, returns CPU device corresponding to the BSP > + * @cpu_countp: If non-NULL, returns the total number of CPUs > + * @return CPU number of the BSP, or -ve on error The return value of BSP CPU number seems not useful in this patch. But I see it will be used in future patches. > + */ > +static int get_bsp(struct udevice **devp, int *cpu_countp) > { > char processor_name[CPU_MAX_NAME_LEN]; > + struct udevice *dev; > int apic_id; > int ret; > > @@ -431,13 +439,20 @@ static int init_bsp(struct udevice **devp) > debug("CPU: %s\n", processor_name); > > apic_id = lapicid(); > - ret = find_cpu_by_apic_id(apic_id, devp); > - if (ret) { > + ret = find_cpu_by_apic_id(apic_id, &dev); > + if (ret < 0) { > printf("Cannot find boot CPU, APIC ID %d\n", apic_id); > return ret; > } > + ret = cpu_get_count(dev); > + if (ret < 0) > + return log_msg_ret("count", ret); > + if (devp) > + *devp = dev; > + if (cpu_countp) > + *cpu_countp = ret; > > - return 0; > + return dev->req_seq; > } > > static int mp_init_cpu(struct udevice *cpu, void *unused) > @@ -476,24 +491,18 @@ int mp_init(void) > uclass_id_foreach_dev(UCLASS_CPU, cpu, uc) > cpu->req_seq = dev_read_u32_default(cpu, "reg", -1); > > - ret = init_bsp(&cpu); > - if (ret) { > + ret = get_bsp(&cpu, &num_cpus); > + if (ret < 0) { > debug("Cannot init boot CPU: err=%d\n", ret); > return ret; > } > > - num_cpus = cpu_get_count(cpu); > - if (num_cpus < 0) { > - debug("Cannot get number of CPUs: err=%d\n", num_cpus); > - return num_cpus; > - } > - > if (num_cpus < 2) > debug("Warning: Only 1 CPU is detected\n"); > > ret = check_cpu_devices(num_cpus); > if (ret) > - debug("Warning: Device tree does not describe all CPUs. Extra ones will not be started correctly\n"); > + log_warning("Warning: Device tree does not describe all CPUs. Extra ones will not be started correctly\n"); > > /* Copy needed parameters so that APs have a reference to the plan */ > mp_info.num_records = ARRAY_SIZE(mp_steps); > -- Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c index e0270e71db..cd4cae559d 100644 --- a/arch/x86/cpu/mp_init.c +++ b/arch/x86/cpu/mp_init.c @@ -421,9 +421,17 @@ static int bsp_do_flight_plan(struct udevice *cpu, struct mp_flight_plan *plan, return ret; } -static int init_bsp(struct udevice **devp) +/** + * get_bsp() - Get information about the bootstrap processor + * + * @devp: If non-NULL, returns CPU device corresponding to the BSP + * @cpu_countp: If non-NULL, returns the total number of CPUs + * @return CPU number of the BSP, or -ve on error + */ +static int get_bsp(struct udevice **devp, int *cpu_countp) { char processor_name[CPU_MAX_NAME_LEN]; + struct udevice *dev; int apic_id; int ret; @@ -431,13 +439,20 @@ static int init_bsp(struct udevice **devp) debug("CPU: %s\n", processor_name); apic_id = lapicid(); - ret = find_cpu_by_apic_id(apic_id, devp); - if (ret) { + ret = find_cpu_by_apic_id(apic_id, &dev); + if (ret < 0) { printf("Cannot find boot CPU, APIC ID %d\n", apic_id); return ret; } + ret = cpu_get_count(dev); + if (ret < 0) + return log_msg_ret("count", ret); + if (devp) + *devp = dev; + if (cpu_countp) + *cpu_countp = ret; - return 0; + return dev->req_seq; } static int mp_init_cpu(struct udevice *cpu, void *unused) @@ -476,24 +491,18 @@ int mp_init(void) uclass_id_foreach_dev(UCLASS_CPU, cpu, uc) cpu->req_seq = dev_read_u32_default(cpu, "reg", -1); - ret = init_bsp(&cpu); - if (ret) { + ret = get_bsp(&cpu, &num_cpus); + if (ret < 0) { debug("Cannot init boot CPU: err=%d\n", ret); return ret; } - num_cpus = cpu_get_count(cpu); - if (num_cpus < 0) { - debug("Cannot get number of CPUs: err=%d\n", num_cpus); - return num_cpus; - } - if (num_cpus < 2) debug("Warning: Only 1 CPU is detected\n"); ret = check_cpu_devices(num_cpus); if (ret) - debug("Warning: Device tree does not describe all CPUs. Extra ones will not be started correctly\n"); + log_warning("Warning: Device tree does not describe all CPUs. Extra ones will not be started correctly\n"); /* Copy needed parameters so that APs have a reference to the plan */ mp_info.num_records = ARRAY_SIZE(mp_steps);