diff mbox

[U-Boot,15/69] x86: cpu: Add functions to return the family and stepping

Message ID 1457317732-18406-16-git-send-email-sjg@chromium.org
State Superseded
Delegated to: Bin Meng
Headers show

Commit Message

Simon Glass March 7, 2016, 2:27 a.m. UTC
These two identifiers can be useful for drivers which need to adjust their
behaviour depending on the CPU family or stepping (revision).

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/x86/cpu/cpu.c         | 10 ++++++++++
 arch/x86/include/asm/cpu.h | 14 ++++++++++++++
 2 files changed, 24 insertions(+)

Comments

Bin Meng March 11, 2016, 4:52 a.m. UTC | #1
Hi Simon,

On Mon, Mar 7, 2016 at 10:27 AM, Simon Glass <sjg@chromium.org> wrote:
> These two identifiers can be useful for drivers which need to adjust their
> behaviour depending on the CPU family or stepping (revision).
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/x86/cpu/cpu.c         | 10 ++++++++++
>  arch/x86/include/asm/cpu.h | 14 ++++++++++++++
>  2 files changed, 24 insertions(+)
>
> diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
> index 8800e09..e2aad19 100644
> --- a/arch/x86/cpu/cpu.c
> +++ b/arch/x86/cpu/cpu.c
> @@ -333,6 +333,16 @@ static inline void get_fms(struct cpuinfo_x86 *c, uint32_t tfms)
>                 c->x86_model += ((tfms >> 16) & 0xF) << 4;
>  }
>
> +u32 cpu_get_family_model(void)
> +{
> +       return gd->arch.x86_device & 0x0fff0ff0;

The decrypted family and model are stored in gd->arch.x86 and
gd->arch.x86_model. Returning raw data would still need the caller to
parse it. Why not just return these directly?

> +}
> +
> +u32 cpu_get_stepping(void)
> +{
> +       return gd->arch.x86_device & 0xf;

This is gd->arch.x86_mask.

> +}
> +
>  int x86_cpu_init_f(void)
>  {
>         const u32 em_rst = ~X86_CR0_EM;
> diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
> index 18b0345..987dc65 100644
> --- a/arch/x86/include/asm/cpu.h
> +++ b/arch/x86/include/asm/cpu.h
> @@ -260,4 +260,18 @@ void cpu_call32(ulong code_seg32, ulong target, ulong table);
>   */
>  int cpu_jump_to_64bit(ulong setup_base, ulong target);
>
> +/**
> + * cpu_get_family_model() - Get the family and model for the CPU
> + *
> + * @return the CPU ID masked with 0x0fff0ff0
> + */
> +u32 cpu_get_family_model(void);
> +
> +/**
> + * cpu_get_stepping() - Get the stepping value for the CPU
> + *
> + * @return the CPU ID masked with 0xf
> + */
> +u32 cpu_get_stepping(void);
> +
>  #endif
> --

Regards,
Bin
Simon Glass March 12, 2016, 5:04 a.m. UTC | #2
Hi Bin,

On 10 March 2016 at 21:52, Bin Meng <bmeng.cn@gmail.com> wrote:
> Hi Simon,
>
> On Mon, Mar 7, 2016 at 10:27 AM, Simon Glass <sjg@chromium.org> wrote:
>> These two identifiers can be useful for drivers which need to adjust their
>> behaviour depending on the CPU family or stepping (revision).
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>>  arch/x86/cpu/cpu.c         | 10 ++++++++++
>>  arch/x86/include/asm/cpu.h | 14 ++++++++++++++
>>  2 files changed, 24 insertions(+)
>>
>> diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
>> index 8800e09..e2aad19 100644
>> --- a/arch/x86/cpu/cpu.c
>> +++ b/arch/x86/cpu/cpu.c
>> @@ -333,6 +333,16 @@ static inline void get_fms(struct cpuinfo_x86 *c, uint32_t tfms)
>>                 c->x86_model += ((tfms >> 16) & 0xF) << 4;
>>  }
>>
>> +u32 cpu_get_family_model(void)
>> +{
>> +       return gd->arch.x86_device & 0x0fff0ff0;
>
> The decrypted family and model are stored in gd->arch.x86 and
> gd->arch.x86_model. Returning raw data would still need the caller to
> parse it. Why not just return these directly?

I want to compare them in one shot to BROADWELL_FAMILY_ULT, etc.

What exactly are you suggesting?

>
>> +}
>> +
>> +u32 cpu_get_stepping(void)
>> +{
>> +       return gd->arch.x86_device & 0xf;
>
> This is gd->arch.x86_mask.

OK. That's a funny name for stepping.

>
>> +}
>> +
>>  int x86_cpu_init_f(void)
>>  {
>>         const u32 em_rst = ~X86_CR0_EM;
>> diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
>> index 18b0345..987dc65 100644
>> --- a/arch/x86/include/asm/cpu.h
>> +++ b/arch/x86/include/asm/cpu.h
>> @@ -260,4 +260,18 @@ void cpu_call32(ulong code_seg32, ulong target, ulong table);
>>   */
>>  int cpu_jump_to_64bit(ulong setup_base, ulong target);
>>
>> +/**
>> + * cpu_get_family_model() - Get the family and model for the CPU
>> + *
>> + * @return the CPU ID masked with 0x0fff0ff0
>> + */
>> +u32 cpu_get_family_model(void);
>> +
>> +/**
>> + * cpu_get_stepping() - Get the stepping value for the CPU
>> + *
>> + * @return the CPU ID masked with 0xf
>> + */
>> +u32 cpu_get_stepping(void);
>> +
>>  #endif
>> --
>
> Regards,
> Bin
Bin Meng March 14, 2016, 4:22 a.m. UTC | #3
Hi Simon,

On Sat, Mar 12, 2016 at 1:04 PM, Simon Glass <sjg@chromium.org> wrote:
> Hi Bin,
>
> On 10 March 2016 at 21:52, Bin Meng <bmeng.cn@gmail.com> wrote:
>> Hi Simon,
>>
>> On Mon, Mar 7, 2016 at 10:27 AM, Simon Glass <sjg@chromium.org> wrote:
>>> These two identifiers can be useful for drivers which need to adjust their
>>> behaviour depending on the CPU family or stepping (revision).
>>>
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>> ---
>>>
>>>  arch/x86/cpu/cpu.c         | 10 ++++++++++
>>>  arch/x86/include/asm/cpu.h | 14 ++++++++++++++
>>>  2 files changed, 24 insertions(+)
>>>
>>> diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
>>> index 8800e09..e2aad19 100644
>>> --- a/arch/x86/cpu/cpu.c
>>> +++ b/arch/x86/cpu/cpu.c
>>> @@ -333,6 +333,16 @@ static inline void get_fms(struct cpuinfo_x86 *c, uint32_t tfms)
>>>                 c->x86_model += ((tfms >> 16) & 0xF) << 4;
>>>  }
>>>
>>> +u32 cpu_get_family_model(void)
>>> +{
>>> +       return gd->arch.x86_device & 0x0fff0ff0;
>>
>> The decrypted family and model are stored in gd->arch.x86 and
>> gd->arch.x86_model. Returning raw data would still need the caller to
>> parse it. Why not just return these directly?
>
> I want to compare them in one shot to BROADWELL_FAMILY_ULT, etc.
>
> What exactly are you suggesting?
>

I guess we can also break BROADWELL_FAMILY_ULT down to values and have
them compared to gd->arch.x86 and gd->arch.x86_model. But I suppose
you have your logic already working, so this is fine.

>>
>>> +}
>>> +
>>> +u32 cpu_get_stepping(void)
>>> +{
>>> +       return gd->arch.x86_device & 0xf;
>>
>> This is gd->arch.x86_mask.
>
> OK. That's a funny name for stepping.

Yep, we can rename this to stepping in the future.

[snip]

Regards,
Bin
diff mbox

Patch

diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
index 8800e09..e2aad19 100644
--- a/arch/x86/cpu/cpu.c
+++ b/arch/x86/cpu/cpu.c
@@ -333,6 +333,16 @@  static inline void get_fms(struct cpuinfo_x86 *c, uint32_t tfms)
 		c->x86_model += ((tfms >> 16) & 0xF) << 4;
 }
 
+u32 cpu_get_family_model(void)
+{
+	return gd->arch.x86_device & 0x0fff0ff0;
+}
+
+u32 cpu_get_stepping(void)
+{
+	return gd->arch.x86_device & 0xf;
+}
+
 int x86_cpu_init_f(void)
 {
 	const u32 em_rst = ~X86_CR0_EM;
diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
index 18b0345..987dc65 100644
--- a/arch/x86/include/asm/cpu.h
+++ b/arch/x86/include/asm/cpu.h
@@ -260,4 +260,18 @@  void cpu_call32(ulong code_seg32, ulong target, ulong table);
  */
 int cpu_jump_to_64bit(ulong setup_base, ulong target);
 
+/**
+ * cpu_get_family_model() - Get the family and model for the CPU
+ *
+ * @return the CPU ID masked with 0x0fff0ff0
+ */
+u32 cpu_get_family_model(void);
+
+/**
+ * cpu_get_stepping() - Get the stepping value for the CPU
+ *
+ * @return the CPU ID masked with 0xf
+ */
+u32 cpu_get_stepping(void);
+
 #endif