x86: timer: Use a separate flag for whether timer is inited
Subsystems (6)
PATCH v3 22/108 x86: timer: Use a separate flag for whether timer is inited
At present the value of the timer base is used to determine whether the timer has been set up or not. It is true that the timer is essentially never exactly 0 when it is read. However 'time 0' may indicate the time that the machine was reset so it is useful to be able to denote that.
Update the code to use a separate flag instead.
---
Changes in v3: None
Changes in v2: None
arch/x86/include/asm/global_data.h | 1 + drivers/timer/tsc_timer.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/include/asm/global_data.h +1 -0
@@ -76,6 +76,7 @@ struct arch_global_data {uint8_t x86_mask;uint32_t x86_device;uint64_t tsc_base;/* Initial value returned by rdtsc() */ +bool tsc_inited;/* true if tsc is ready for use */ unsigned long clock_rate;/* Clock rate of timer in Hz */ void *new_fdt;/* Relocated FDT */ uint32_t bist;/* Built-in self test value */
drivers/timer/tsc_timer.c +2 -1
@@ -394,7 +394,7 @@ static int tsc_timer_get_count(struct udevice *dev, u64 *count)static void tsc_timer_ensure_setup (bool early) { -if (gd->arch.tsc_base) +if (gd->arch.tsc_inited)return ; gd->arch.tsc_base =rdtsc ();
@@ -425,6 +425,7 @@ static void tsc_timer_ensure_setup(bool early) done: gd->arch.clock_rate = fast_calibrate *1000000 ; } + gd->arch.tsc_inited = true; }static int tsc_timer_probe (struct udevice *dev)
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 23/108 x86: timer: Allow a timer base of 0
On some platforms the timer is reset to 0 when the SoC is reset. Having this as the timer base is useful since it provides an indication of how long it takes before U-Boot is running.
When U-Boot sets the timer base to something else, time is lost and we no-longer have an accurate account of the time since reset. This particularly affects bootstage.
Add an option to leave the timer base as 0 on boot.
---
Changes in v3: None
Changes in v2: None
drivers/timer/Kconfig | 13 +++++++++++++ drivers/timer/tsc_timer.c | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/timer/Kconfig +13 -0
@@ -174,6 +174,19 @@ config X86_TSC_TIMER help Select this to enable Time-Stamp Counter (TSC) timer for x86. +config X86_TSC_ZERO_BASE + bool "Assume that TSC timer starts at 0" + depends on X86_TSC_TIMER + help + On some platforms the TSC timer tick starts at the value 0 on reset. + This it makes no sense to read the timer on boot and use that as the + base, since we will miss some time taken to load U-Boot, etc. This + delay is controlled by the SoC and we cannot reduce it, but for + bootstage we want to record the time since reset as accurately as + possible. + + Enable this to always us an initial TSC value of 0. + config MTK_TIMER bool "MediaTek timer support" depends on TIMER
drivers/timer/tsc_timer.c +2 -1
@@ -396,7 +396,8 @@ static void tsc_timer_ensure_setup(bool early) {if (gd->arch.tsc_inited)return ; - gd->arch.tsc_base =rdtsc (); +if (!IS_ENABLED (CONFIG_X86_TSC_ZERO_BASE )) + gd->arch.tsc_base =rdtsc ();if (!gd->arch.clock_rate) {unsigned long fast_calibrate;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 23/108 x86: timer: Allow a timer base of 0
Hi Simon,
Quoted 10 lines · Simon Glass
On some platforms the timer is reset to 0 when the SoC is reset. Having this as the timer base is useful since it provides an indication of how long it takes before U-Boot is running.
When U-Boot sets the timer base to something else, time is lost and we no-longer have an accurate account of the time since reset. This particularly affects bootstage.
Add an option to leave the timer base as 0 on boot.
I think we can change the timer base as 0 for all x86 native port. And use rdtsc() for configuration when U-Boot is used as payloads, eg:
efi, coreboot, slimbootloader, etc.
Quoted 11 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/timer/Kconfig | 13 +++++++++++++ drivers/timer/tsc_timer.c | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-)
Regards,
Bin
PATCH v3 24/108 x86: spl: Support init of a PUNIT
In reply to Simon GlassThe x86 power unit handles power management. Support initing this device which is modelled as a new type of system controller since there are no operations needed.
---
Changes in v3:
- Fix 'err-%d' typo
Changes in v2: None
arch/x86/include/asm/cpu.h | 1 + arch/x86/lib/spl.c | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
arch/x86/include/asm/cpu.h +1 -0
@@ -55,6 +55,7 @@ enum {X86_SYSCON_PINCONF ,/* Intel x86 pin configuration */ X86_SYSCON_PMU ,/* Power Management Unit */ X86_SYSCON_SCU ,/* System Controller Unit */ + X86_SYSCON_PUNIT, /* Power unit */ }; struct cpuid_result {
arch/x86/lib/spl.c +40 -0
@@ -5,11 +5,15 @@#include <common.h> #include <debug_uart.h> +#include <dm.h> #include <malloc.h> #include <spl.h> +#include <syscon.h> #include <asm/cpu.h> +#include <asm/cpu_common.h> #include <asm/mrccache.h> #include <asm/mtrr.h> +#include <asm/pci.h> #include <asm/processor.h> #include <asm/spl.h> #include <asm-generic/sections.h>
@@ -21,6 +25,32 @@ __weak int arch_cpu_init_dm(void)return 0 ; } +#ifdef CONFIG_TPL + +static int set_max_freq (void ) +{ +if (cpu_get_burst_mode_state () ==BURST_MODE_UNAVAILABLE ) { +/* +* Burst Mode has been factory-configured as disabled and is not +* available in this physical processor package +*/ +debug ("Burst Mode is factory-disabled\n" ); +return -ENOENT ; + } + +/* Enable burst mode */ +cpu_set_burst_mode (true); + +/* Enable speed step */ +cpu_set_eist (true); + +/* Set P-State ratio */ +cpu_set_p_state_to_turbo_ratio (); + +return 0 ; +} +#endif +static int x86_spl_init (void ) {#ifndef CONFIG_TPL
@@ -31,6 +61,8 @@ static int x86_spl_init(void)* place it immediately below CONFIG_SYS_TEXT_BASE. */ char *ptr = (char *)0x110000 ; +#else +struct udevice *punit;#endif int ret;
@@ -101,6 +133,14 @@ static int x86_spl_init(void) return ret; }mtrr_commit (true); +#else + ret =syscon_get_by_driver_data (X86_SYSCON_PUNIT , &punit); +if (ret) +debug ("Could not find PUNIT (err=%d)\n" , ret); + + ret =set_max_freq (); +if (ret) +debug ("Failed to set CPU frequency (err=%d)\n" , ret);#endif return 0 ;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 24/108 x86: spl: Support init of a PUNIT
Quoted 8 lines · Simon Glass
The x86 power unit handles power management. Support initing this device which is modelled as a new type of system controller since there are no operations needed.
Signed-off-by Simon Glass <[email protected]>---
Quoted 9 lines
Changes in v3:
- Fix 'err-%d' typoChanges in v2: None
arch/x86/include/asm/cpu.h | 1 + arch/x86/lib/spl.c | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
PATCH v3 24/108 x86: spl: Support init of a PUNIT
Quoted 13 lines · Bin Meng
Quoted 11 lines · Simon Glass
The x86 power unit handles power management. Support initing this device which is modelled as a new type of system controller since there are no operations needed.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Fix 'err-%d' typo
Quoted 8 lines
Quoted 6 lines
Changes in v2: None
arch/x86/include/asm/cpu.h | 1 + arch/x86/lib/spl.c | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)Reviewed-by Bin Meng <[email protected]>
applied to u-boot-x86, thanks!
PATCH v3 25/108 x86: tpl: Add a fake PCI bus
In reply to Simon GlassIn TPL we try to minimise code size so do not include the PCI subsystem. We can use fixed BARs and drivers can directly program the devices that they need.
However we do need to bind the devices on the PCI bus and without PCI this does not ordinarily happen. As a work-around, define a fake PCI bus which does this binding, but no other PCI operations. This is a convenient way to ensure that we can use the same device tree for TPL, SPL and U-Boot proper:
TPL - CONFIG_TPL_PCI is not set (no auto-config, fake PCI bus)
SPL - CONFIG_SPL_PCI is set (no auto-config but with real PCI bus)
U-Boot - CONFIG_PCI is set (full auto-config after relocation)
---
Changes in v3:
- Fix 'autoallocation' typo
- Improve wording in commit message
Changes in v2: None
arch/x86/lib/tpl.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
arch/x86/lib/tpl.c +25 -0
@@ -5,6 +5,7 @@#include <common.h> #include <debug_uart.h> +#include <dm.h> #include <spl.h> #include <asm/cpu.h> #include <asm/mtrr.h>
@@ -115,3 +116,27 @@ void spl_board_init(void) {preloader_console_init (); } + +#if !CONFIG_IS_ENABLED (PCI ) +/* +* This is a fake PCI bus for TPL when it doesn't have proper PCI. It is enough +* to bind the devices on the PCI bus, some of which have early-regs properties +* providing fixed BARs. Individual drivers program these BARs themselves so +* that they can access the devices. The BARs are allocated statically in the +* device tree. +* +* Once SPL is running it enables PCI properly, but does not auto-assign BARs +* for devices, so the TPL BARs continue to be used. Once U-Boot starts it does +* the auto allocation (after relocation). +*/ +static const struct udevice_id tpl_fake_pci_ids[] = { + { .compatible ="pci-x86" }, + { } +}; + +U_BOOT_DRIVER (pci_x86) = { + .name ="pci_x86" , + .id =UCLASS_SIMPLE_BUS , + .of_match = tpl_fake_pci_ids, +}; +#endif
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 25/108 x86: tpl: Add a fake PCI bus
Quoted 11 lines · Simon Glass
In TPL we try to minimise code size so do not include the PCI subsystem. We can use fixed BARs and drivers can directly program the devices that they need.
However we do need to bind the devices on the PCI bus and without PCI this does not ordinarily happen. As a work-around, define a fake PCI bus which does this binding, but no other PCI operations. This is a convenient way to ensure that we can use the same device tree for TPL, SPL and U-Boot proper:
Quoted 3 lines
TPL -
CONFIG_TPL_PCIis not set (no auto-config, fake PCI bus)
SPL -CONFIG_SPL_PCIis set (no auto-config but with real PCI bus)
U-Boot -CONFIG_PCIis set (full auto-config after relocation)
PCI(e) bus is present in a lot of SoCs (not exclusively x86). Perhaps better idea is to have something like lib/pci.c with minimum support for PCI type 1 and probably PCI type 2 accessors and other very basic functions.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 25/108 x86: tpl: Add a fake PCI bus
Hi Andy,
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Simon Glass
In TPL we try to minimise code size so do not include the PCI subsystem. We can use fixed BARs and drivers can directly program the devices that they need.
However we do need to bind the devices on the PCI bus and without PCI this does not ordinarily happen. As a work-around, define a fake PCI bus which does this binding, but no other PCI operations. This is a convenient way to ensure that we can use the same device tree for TPL, SPL and U-Boot proper:
Quoted 8 lines
Quoted 3 lines
TPL -
CONFIG_TPL_PCIis not set (no auto-config, fake PCI bus)
SPL -CONFIG_SPL_PCIis set (no auto-config but with real PCI bus)
U-Boot -CONFIG_PCIis set (full auto-config after relocation)PCI(e) bus is present in a lot of SoCs (not exclusively x86). Perhaps better idea is to have something like
lib/pci.cwith minimum support for PCI type 1 and probably PCI type 2 accessors and other very basic functions.
I don't know of any use case for PCI in TPL on other platforms.
x86 is I think unique in that it requires PCI to do anything. For other platforms I am familiar with they can boot a fair way without it.
I do want to avoid the premature-optimisation problem, i.e. inventing new use cases that no one uses. The only thing we really know right now is that we need this for newer x86 platforms.
Regards,
Simon
PATCH v3 25/108 x86: tpl: Add a fake PCI bus
Quoted 11 lines · Simon Glass
Quoted 6 lines · Andy Shevchenko
On Mon, Oct 21, 2019 at 7:24 AM Simon Glass <[email protected]> wrote:
PCI(e) bus is present in a lot of SoCs (not exclusively x86). Perhaps better idea is to have something like
lib/pci.cwith minimum support for PCI type 1 and probably PCI type 2 accessors and other very basic functions.I don't know of any use case for PCI in TPL on other platforms.
x86 is I think unique in that it requires PCI to do anything.
I don't think so. PCI is a core part of the SoC, indeed, though what exactly do we need from it here? IO accessors to PCI configuration space?
Quoted 3 lines
For
other platforms I am familiar with they can boot a fair way without it.
Perhaps we may achieve the same here?
Quoted 3 lines
I do want to avoid the premature-optimisation problem, i.e. inventing new use cases that no one uses. The only thing we really know right now is that we need this for newer x86 platforms.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 25/108 x86: tpl: Add a fake PCI bus
Hi Andy,
Quoted 10 lines · Andy Shevchenko
Quoted 8 lines · Simon Glass
Quoted 6 lines · Andy Shevchenko
On Mon, Oct 21, 2019 at 7:24 AM Simon Glass <[email protected]> wrote:
PCI(e) bus is present in a lot of SoCs (not exclusively x86). Perhaps better idea is to have something like
lib/pci.cwith minimum support for PCI type 1 and probably PCI type 2 accessors and other very basic functions.
Quoted 7 lines
Quoted 3 lines
I don't know of any use case for PCI in TPL on other platforms.
x86 is I think unique in that it requires PCI to do anything.
I don't think so. PCI is a core part of the SoC, indeed, though what exactly do we need from it here? IO accessors to PCI configuration space?
I mean that on other SoCs I am familiar with you can access peripherals through memory-mapped I/O.
On x86 so far as I am aware you can't see any peripheral without doing some PCI config.
Therefore PCI is 'more core' on x86 than others. For example on an Nvidia chip I am familiar with, you can do everything except enable the PCI network chip, which you wouldn't do in TPL.
Quoted 10 lines
Quoted 4 lines
For
other platforms I am familiar with they can boot a fair way without it.Perhaps we may achieve the same here?
Quoted 3 lines
I do want to avoid the premature-optimisation problem, i.e. inventing new use cases that no one uses. The only thing we really know right now is that we need this for newer x86 platforms.
Regards,
Simon
PATCH v3 25/108 x86: tpl: Add a fake PCI bus
In reply to Simon GlassQuoted 18 lines · Simon Glass
In TPL we try to minimise code size so do not include the PCI subsystem. We can use fixed BARs and drivers can directly program the devices that they need.
However we do need to bind the devices on the PCI bus and without PCI this does not ordinarily happen. As a work-around, define a fake PCI bus which does this binding, but no other PCI operations. This is a convenient way to ensure that we can use the same device tree for TPL, SPL and U-Boot proper:
TPL -
CONFIG_TPL_PCIis not set (no auto-config, fake PCI bus)
SPL -CONFIG_SPL_PCIis set (no auto-config but with real PCI bus)
U-Boot -CONFIG_PCIis set (full auto-config after relocation)Signed-off-by Simon Glass <[email protected]>---
Quoted 9 lines
Changes in v3:
- Fix 'autoallocation' typo
- Improve wording in commit messageChanges in v2: None
arch/x86/lib/tpl.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
PATCH v3 25/108 x86: tpl: Add a fake PCI bus
Quoted 24 lines · Bin Meng
Quoted 22 lines · Simon Glass
In TPL we try to minimise code size so do not include the PCI subsystem. We can use fixed BARs and drivers can directly program the devices that they need.
However we do need to bind the devices on the PCI bus and without PCI this does not ordinarily happen. As a work-around, define a fake PCI bus which does this binding, but no other PCI operations. This is a convenient way to ensure that we can use the same device tree for TPL, SPL and U-Boot proper:
TPL -
CONFIG_TPL_PCIis not set (no auto-config, fake PCI bus)
SPL -CONFIG_SPL_PCIis set (no auto-config but with real PCI bus)
U-Boot -CONFIG_PCIis set (full auto-config after relocation)Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Fix 'autoallocation' typo
- Improve wording in commit message
Quoted 7 lines
Quoted 5 lines
Changes in v2: None
arch/x86/lib/tpl.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)Reviewed-by Bin Meng <[email protected]>
applied to u-boot-x86, thanks!
PATCH v3 26/108 x86: timer: Reduce timer code size in TPL on Intel CPUs
In reply to Simon GlassMost of the timer-calibration methods are not needed on recent Intel CPUs and just increase code size. Add an option to use the known-good way to get the clock frequency in TPL. Size reduction is about 700 bytes.
---
Changes in v3: None
Changes in v2: None
drivers/timer/Kconfig | 9 +++++++++ drivers/timer/tsc_timer.c | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/timer/Kconfig +9 -0
@@ -187,6 +187,15 @@ config X86_TSC_ZERO_BASE Enable this to always us an initial TSC value of 0. +config TPL_X86_TSC_TIMER_NATIVE + bool "x86 TSC timer uses native calibration" + depends on TPL && X86_TSC_TIMER + help + Selects native timer calibration for TPL and don't include the other + methods in the code. This helps to reduce code size in TPL and works + on fairly modern Intel chips. Code-size reductions is about 700 + bytes. + config MTK_TIMER bool "MediaTek timer support" depends on TIMER
drivers/timer/tsc_timer.c +5 -2
@@ -49,8 +49,7 @@ static unsigned long native_calibrate_tsc(void)return 0 ; crystal_freq = tsc_info.ecx /1000 ; - -if (!crystal_freq) { +if (!CONFIG_IS_ENABLED (X86_TSC_TIMER_NATIVE ) && !crystal_freq) {switch (gd->arch.x86_model) {case INTEL_FAM6_SKYLAKE_MOBILE :case INTEL_FAM6_SKYLAKE_DESKTOP :
@@ -406,6 +405,10 @@ static void tsc_timer_ensure_setup(bool early)if (fast_calibrate) goto done; +/* Reduce code size by dropping other methods */ +if (CONFIG_IS_ENABLED (X86_TSC_TIMER_NATIVE )) +panic ("no timer" ); + fast_calibrate =cpu_mhz_from_cpuid ();if (fast_calibrate) goto done;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 26/108 x86: timer: Reduce timer code size in TPL on Intel CPUs
Hi Simon,
Quoted 6 lines · Simon Glass
Most of the timer-calibration methods are not needed on recent Intel CPUs and just increase code size. Add an option to use the known-good way to get the clock frequency in TPL. Size reduction is about 700 bytes.
Signed-off-by Simon Glass <[email protected]>
Quoted 9 lines
---
Changes in v3: None
Changes in v2: Nonedrivers/timer/Kconfig | 9 +++++++++ drivers/timer/tsc_timer.c | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
You mentioned in the v2 that this breaks bootstage, and will drop this patch. no?
https://www.mail-archive.com/u-boot at lists.denx.de/msg344229.html
Regards,
Bin
PATCH v3 26/108 x86: timer: Reduce timer code size in TPL on Intel CPUs
Hi BIn,
Quoted 15 lines · Bin Meng
Hi Simon,
Quoted 11 lines · Simon Glass
Most of the timer-calibration methods are not needed on recent Intel CPUs and just increase code size. Add an option to use the known-good way to get the clock frequency in TPL. Size reduction is about 700 bytes.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: None
Quoted 8 lines
Quoted 4 lines
drivers/timer/Kconfig | 9 +++++++++ drivers/timer/tsc_timer.c | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-)You mentioned in the v2 that this breaks bootstage, and will drop this patch. no?
https://www.mail-archive.com/u-boot at lists.denx.de/msg344229.html
Ah yes I found the bug with that, and you've applied the patches. Will update the commit message.
Regards,
Simon
PATCH v3 27/108 x86: Drop unnecessary cpu code for TPL
In reply to Simon GlassWe don't need to know every detail about the CPU in TPL. Drop some superfluous functions to reduce code size. Add a simple CPU detection algorithm which just supports Intel and AMD, since we only support TPL on Intel, so far.
---
Changes in v3: None
Changes in v2: None
arch/x86/cpu/cpu.c | 4 ++++ arch/x86/cpu/i386/cpu.c | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-)
arch/x86/cpu/cpu.c +4 -0
@@ -45,6 +45,7 @@DECLARE_GLOBAL_DATA_PTR ; +#ifndef CONFIG_TPL_BUILD static const char *const x86_vendor_name[] = { [X86_VENDOR_INTEL ] ="Intel" , [X86_VENDOR_CYRIX] = "Cyrix",
@@ -57,6 +58,7 @@ static const char *const x86_vendor_name[] = { [X86_VENDOR_NSC] = "NSC", [X86_VENDOR_SIS] = "SiS", }; +#endif int __weak x86_cleanup_before_linux (void ) {
@@ -113,6 +115,7 @@ int icache_status(void)return 1 ; } +#ifndef CONFIG_TPL_BUILD const char *cpu_vendor_name (int vendor) {const char *name;
@@ -123,6 +126,7 @@ const char *cpu_vendor_name(int vendor) return name; } +#endif char *cpu_get_name (char *name) {
arch/x86/cpu/i386/cpu.c +37 -4
90 lines not on this page · raw message
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 27/108 x86: Drop unnecessary cpu code for TPL
Hi Simon,
Quoted 65 lines · Simon Glass
We don't need to know every detail about the CPU in TPL. Drop some superfluous functions to reduce code size. Add a simple CPU detection algorithm which just supports Intel and AMD, since we only support TPL on Intel, so far.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/cpu/cpu.c | 4 ++++ arch/x86/cpu/i386/cpu.c | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-)arch/x86/cpu/cpu.c +4
-0@@ -45,6 +45,7 @@DECLARE_GLOBAL_DATA_PTR ; +#ifndef CONFIG_TPL_BUILD static const char *const x86_vendor_name[] = { [X86_VENDOR_INTEL ] ="Intel" , [X86_VENDOR_CYRIX] = "Cyrix",@@ -57,6 +58,7 @@ static const char *const x86_vendor_name[] = { [X86_VENDOR_NSC] = "NSC", [X86_VENDOR_SIS] = "SiS", }; +#endif int __weak x86_cleanup_before_linux (void ) {@@ -113,6 +115,7 @@ int icache_status(void)return 1 ; } +#ifndef CONFIG_TPL_BUILD const char *cpu_vendor_name (int vendor) {const char *name;@@ -123,6 +126,7 @@ const char *cpu_vendor_name(int vendor) return name; } +#endif char *cpu_get_name (char *name) {arch/x86/cpu/i386/cpu.c +1
-0@@ -20,6 +20,7 @@#include <common.h> #include <malloc.h> +#include <spl.h> #include <asm/control_regs.h> #include <asm/cpu.h> #include <asm/mp.h>
arch/x86/cpu/i386/cpu.c struct cpuinfo_x86 { · line 61
Quoted 4 lines
arch/x86/cpu/i386/cpu.c +1
-0@@ -57,6 +58,8 @@ struct cpuinfo_x86 {uint8_t x86_mask; }; +/* gcc 7.3 does not what to drop x86_vendors, so use #ifdef */
what => want ?
Quoted 40 lines
arch/x86/cpu/i386/cpu.c +16
-0+#ifndef CONFIG_TPL_BUILD /* * List of cpu vendor strings along with their normalized * id values. @@ -77,6 +80,7 @@ static const struct { { X86_VENDOR_NSC, "Geode by NSC", }, { X86_VENDOR_SIS, "SiS SiS SiS ", }, }; +#endif static void load_ds(u32 segment) {@@ -229,6 +233,7 @@ static bool has_mtrr(void)return cpuid_edx (0x00000001 ) & (1 <<12 ) ? true : false; } +#ifndef CONFIG_TPL_BUILD static int build_vendor_name (char *vendor_name) {struct cpuid_result result;@@ -241,14 +246,42 @@ static int build_vendor_name(char *vendor_name) return result.eax; } +#endif static void identify_cpu (struct cpu_device_id *cpu) { + cpu->device =0 ;/* fix gcc 4.4.4 warning */ + +/* +* Do a quick and dirty check to save space - Intel and AMD only and +* just the vendor. This is enough for most TPL code. +*/ +if (spl_phase () ==PHASE_TPL ) { +struct cpuid_result result; + + result =cpuid (0x00000000 ); +switch (result.ecx >>24 ) { +case 'l' :/* GenuineIntel */
arch/x86/cpu/i386/cpu.c static int build_vendor_name(char *vendor_name) · line 274
Quoted 10 lines
arch/x86/cpu/i386/cpu.c +10
-0+ cpu->vendor =X86_VENDOR_INTEL ; +break ; +case 'D' :/* AuthenticAMD */ + cpu->vendor =X86_VENDOR_AMD ; +break ; +default : + cpu->vendor =X86_VENDOR_ANY ; +break ; + } +if (0 )/* Fix compiler warning */
Can we remove this completely?
arch/x86/cpu/i386/cpu.c static int build_vendor_name(char *vendor_name) · line 279
Quoted 5 lines
arch/x86/cpu/i386/cpu.c +5
-0+deep_magic_nexgen_probe (); +return ; + } + +/* gcc 7.3 does not what to drop x86_vendors, so use #ifdef */
what?
Quoted 22 lines
arch/x86/cpu/i386/cpu.c +3
-4+#ifndef CONFIG_TPL_BUILD char vendor_name[16 ];int i; vendor_name[0 ] ='\0' ;/* Unset */ - cpu->device =0 ;/* fix gcc 4.4.4 warning */ /* Find the id and vendor_name */ if (!has_cpuid ()) {@@ -264,9 +297,8 @@ static void identify_cpu(struct cpu_device_id *cpu)/* Detect NexGen with old hypercode */ else if (deep_magic_nexgen_probe()) memcpy(vendor_name, "NexGenDriven", 13); - } -if (has_cpuid ()) { -int cpuid_level; + }else { +int cpuid_level; cpuid_level =build_vendor_name (vendor_name); vendor_name[12 ] ='\0' ;
arch/x86/cpu/i386/cpu.c static void identify_cpu(struct cpu_device_id *cpu)
Quoted 8 lines
arch/x86/cpu/i386/cpu.c +1
-1@@ -286,6 +318,7 @@ static void identify_cpu(struct cpu_device_id *cpu) break; } } +#endif }static inline void get_fms (struct cpuinfo_x86 *c,uint32_t tfms) --
Regards,
Bin
PATCH v3 28/108 x86: Drop unnecessary interrupt code for TPL
In reply to Simon GlassWe don't expect an exception in TPL and don't need to print out full details if one happens. Add a reduced version of the code for TPL.
---
Changes in v3: None
Changes in v2: None
arch/x86/cpu/i386/interrupt.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/x86/cpu/i386/interrupt.c +13 -0
@@ -13,6 +13,7 @@#include <common.h> #include <dm.h> #include <efi_loader.h> +#include <spl.h> #include <asm/control_regs.h> #include <asm/i8259.h> #include <asm/interrupt.h>
@@ -22,6 +23,10 @@DECLARE_GLOBAL_DATA_PTR ; +#ifndef CONFIG_TPL_BUILD +#define FULL_EXCEPTIONS +#endif +#define DECLARE_INTERRUPT (x) \ ".globl irq_"#x"\n" \ ".hidden irq_"#x"\n" \
@@ -30,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; "pushl $"#x"\n" \ "jmp.d32 irq_common_entry\n" +#ifdef FULL_EXCEPTIONS static char *exceptions[] = {"Divide Error" , "Debug",
@@ -64,7 +70,9 @@ static char *exceptions[] = {"Reserved" ,"Reserved" }; +#endif +#ifdef FULL_EXCEPTIONS /** * show_efi_loaded_images() - show loaded UEFI images *
@@ -159,11 +167,16 @@ static void dump_regs(struct irq_regs *regs) }show_efi_loaded_images (eip); } +#endif static void do_exception (struct irq_regs *regs) { +#ifdef FULL_EXCEPTIONS printf ("%s\n" , exceptions[regs->irq_id]);dump_regs (regs); +#else +printf ("Exception %d\n" , (int )regs->irq_id); +#endif hang (); }
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 28/108 x86: Drop unnecessary interrupt code for TPL
Hi Simon,
Quoted 5 lines · Simon Glass
We don't expect an exception in TPL and don't need to print out full details if one happens. Add a reduced version of the code for TPL.
Signed-off-by Simon Glass <[email protected]>
Can we exclude the whole file from building in TPL?
Quoted 8 lines
---
Changes in v3: None
Changes in v2: Nonearch/x86/cpu/i386/interrupt.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Regards,
Bin
PATCH v3 29/108 x86: Add a CPU init function for TPL
In reply to Simon GlassFor TPL we only need to set up the features and identify the CPU to a basic level. Add a function to handle that.
---
Changes in v3: None
Changes in v2: None
arch/x86/cpu/i386/cpu.c | 8 ++++++++ arch/x86/include/asm/u-boot-x86.h | 9 +++++++++ 2 files changed, 17 insertions(+)
arch/x86/cpu/i386/cpu.c +8 -0
@@ -418,6 +418,14 @@ static void setup_mtrr(void) } } +int x86_cpu_init_tpl (void ) +{ +setup_cpu_features (); +setup_identity (); + +return 0 ; +} +int x86_cpu_init_f (void ) {if (ll_boot_init ())
arch/x86/include/asm/u-boot-x86.h +9 -0
@@ -34,6 +34,15 @@ int x86_cpu_init_f(void);*/ int x86_cpu_reinit_f (void ); +/** +* x86_cpu_init_tpl() - Do the minimum possible CPU init +* +* This just sets up the CPU features and figured out the identity +* +* @return 0 (indicating success, to mimic cpu_init_f()) +*/ +int x86_cpu_init_tpl (void ); +int cpu_init_f (void );void setup_gdt (struct global_data *id,u64 *gdt_addr);/*
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 29/108 x86: Add a CPU init function for TPL
Quoted 5 lines · Simon Glass
For TPL we only need to set up the features and identify the CPU to a basic level. Add a function to handle that.
Signed-off-by Simon Glass <[email protected]>
Quoted 9 lines
---
Changes in v3: None
Changes in v2: Nonearch/x86/cpu/i386/cpu.c | 8 ++++++++ arch/x86/include/asm/u-boot-x86.h | 9 +++++++++ 2 files changed, 17 insertions(+)
PATCH v3 29/108 x86: Add a CPU init function for TPL
Quoted 12 lines · Bin Meng
Quoted 10 lines · Simon Glass
For TPL we only need to set up the features and identify the CPU to a basic level. Add a function to handle that.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: None
Quoted 6 lines
Quoted 4 lines
arch/x86/cpu/i386/cpu.c | 8 ++++++++ arch/x86/include/asm/u-boot-x86.h | 9 +++++++++ 2 files changed, 17 insertions(+)Reviewed-by Bin Meng <[email protected]>
applied to u-boot-x86, thanks!
PATCH v3 30/108 x86: Move CPU init to before spl_init()
In reply to Simon GlassAt present we call spl_init() before identifying the CPU. This is not a good idea - e.g. if bootstage is enabled then it will try to set up the timer which works better if the CPU is identified.
Put explicit code at each entry pointer to identify the CPU.
---
Changes in v3: None
Changes in v2: None
arch/x86/cpu/start_from_spl.S | 1 + arch/x86/lib/spl.c | 4 ++++ arch/x86/lib/tpl.c | 5 +++++ 3 files changed, 10 insertions(+)
arch/x86/cpu/start_from_spl.S +1 -0
@@ -31,6 +31,7 @@ _start: call board_init_f_init_reserve + call x86_cpu_reinit_f xorl %eax, %eax call board_init_f call board_init_f_r
arch/x86/lib/spl.c +4 -0
@@ -67,6 +67,10 @@ static int x86_spl_init(void)int ret;debug ("%s starting\n" , __func__); +if (IS_ENABLED (TPL )) + ret =x86_cpu_reinit_f (); +else + ret =x86_cpu_init_f (); ret =spl_init ();if (ret) {debug ("%s: spl_init() failed\n" , __func__);
arch/x86/lib/tpl.c +5 -0
@@ -24,6 +24,11 @@ static int x86_tpl_init(void)int ret;debug ("%s starting\n" , __func__); + ret =x86_cpu_init_tpl (); +if (ret) { +debug ("%s: x86_cpu_init_tpl() failed\n" , __func__); +return ret; + } ret =spl_init ();if (ret) {debug ("%s: spl_init() failed\n" , __func__);
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 30/108 x86: Move CPU init to before spl_init()
Quoted 10 lines · Simon Glass
At present we call
spl_init()before identifying the CPU. This is not a good idea - e.g. if bootstage is enabled then it will try to set up the timer which works better if the CPU is identified.Put explicit code at each entry pointer to identify the CPU.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v3: None
Changes in v2: Nonearch/x86/cpu/start_from_spl.S | 1 + arch/x86/lib/spl.c | 4 ++++ arch/x86/lib/tpl.c | 5 +++++ 3 files changed, 10 insertions(+)
PATCH v3 30/108 x86: Move CPU init to before spl_init()
Quoted 15 lines · Bin Meng
Quoted 13 lines · Simon Glass
At present we call
spl_init()before identifying the CPU. This is not a good idea - e.g. if bootstage is enabled then it will try to set up the timer which works better if the CPU is identified.Put explicit code at each entry pointer to identify the CPU.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: None
Quoted 7 lines
Quoted 5 lines
arch/x86/cpu/start_from_spl.S | 1 + arch/x86/lib/spl.c | 4 ++++ arch/x86/lib/tpl.c | 5 +++++ 3 files changed, 10 insertions(+)Reviewed-by Bin Meng <[email protected]>
applied to u-boot-x86, thanks!
PATCH v3 31/108 x86: Don't print CPU info in TPL
In reply to Simon GlassWe don't need to do this and it is done (in more detail) in U-Boot proper. Drop this to save code space.
---
Changes in v3: None
Changes in v2: None
arch/x86/lib/tpl.c | 5 ----- 1 file changed, 5 deletions(-)
arch/x86/lib/tpl.c +0 -5
@@ -45,11 +45,6 @@ static int x86_tpl_init(void)return ret; }preloader_console_init (); - ret =print_cpuinfo (); -if (ret) { -debug ("%s: print_cpuinfo() failed\n" , __func__); -return ret; - }return 0 ; }
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 31/108 x86: Don't print CPU info in TPL
Quoted 4 lines · Simon Glass
We don't need to do this and it is done (in more detail) in U-Boot proper. Drop this to save code space.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/lib/tpl.c | 5 ----- 1 file changed, 5 deletions(-)
PATCH v3 31/108 x86: Don't print CPU info in TPL
Quoted 9 lines · Bin Meng
Quoted 7 lines · Simon Glass
We don't need to do this and it is done (in more detail) in U-Boot proper. Drop this to save code space.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Quoted 6 lines
Changes in v3: None
Changes in v2: Nonearch/x86/lib/tpl.c | 5 ----- 1 file changed, 5 deletions(-)Reviewed-by Bin Meng <[email protected]>
applied to u-boot-x86, thanks!
PATCH v3 32/108 x86: Quieten TPL's jump_to_image_no_args()
In reply to Simon GlassWe already a message indicating that U-Boot is about to jump to SPL, so make this one a debug() to reduce code size.
---
Changes in v3: None
Changes in v2: None
arch/x86/lib/tpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/lib/tpl.c +1 -1
@@ -107,7 +107,7 @@ int spl_spi_load_image(void)void __noreturn jump_to_image_no_args (struct spl_image_info *spl_image) { -printf ("Jumping to U-Boot SPL at %lx\n" , (ulong )spl_image->entry_point); +debug ("Jumping to U-Boot SPL at %lx\n" , (ulong )spl_image->entry_point);jump_to_spl (spl_image->entry_point);hang (); }
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 32/108 x86: Quieten TPL's jump_to_image_no_args()
Quoted 4 lines · Simon Glass
We already a message indicating that U-Boot is about to jump to SPL, so make this one a
debug()to reduce code size.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/lib/tpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v3 32/108 x86: Quieten TPL's jump_to_image_no_args()
Quoted 9 lines · Bin Meng
Quoted 7 lines · Simon Glass
We already a message indicating that U-Boot is about to jump to SPL, so make this one a
debug()to reduce code size.Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Quoted 6 lines
Changes in v3: None
Changes in v2: Nonearch/x86/lib/tpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Bin Meng <[email protected]>
applied to u-boot-x86, thanks!
PATCH v3 33/108 x86: power: Add an ACPI PMC uclass
In reply to Simon GlassIntel x86 SoCs have a power manager/controller which handles several power-related aspects of the platform. Add a uclass for this, with a few useful operations.
---
Changes in v3:
- Rename power-mgr uclass to acpi-pmc
Changes in v2: None
drivers/power/Kconfig | 2 + drivers/power/acpi_pmc/Kconfig | 25 +++ drivers/power/acpi_pmc/Makefile | 5 + drivers/power/acpi_pmc/acpi-pmc-uclass.c | 191 +++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/power/acpi_pmc.h | 185 ++++++++++++++++++++++ 6 files changed, 409 insertions(+) create mode 100644 drivers/power/acpi_pmc/Kconfig create mode 100644 drivers/power/acpi_pmc/Makefile create mode 100644 drivers/power/acpi_pmc/acpi-pmc-uclass.c create mode 100644 include/power/acpi_pmc.h
drivers/power/Kconfig +2 -0
@@ -4,6 +4,8 @@ source "drivers/power/domain/Kconfig" source "drivers/power/pmic/Kconfig" +source "drivers/power/acpi_pmc/Kconfig" + source "drivers/power/regulator/Kconfig" choice
drivers/power/acpi_pmc/Kconfig new file +25 -0
@@ -0,0 +1,25 @@ +config ACPI_PMC + bool "Power Manager (x86 PMC) support" + help + Enable support for an x86-style power-management controller which + provides features including checking whether the system started from + resume, powering off the system and enabling/disabling the reset + mechanism. + +config SPL_ACPI_PMC + bool "Power Manager (x86 PMC) support in SPL" + default y if ACPI_PMC + help + Enable support for an x86-style power-management controller which + provides features including checking whether the system started from + resume, powering off the system and enabling/disabling the reset + mechanism. + +config TPL_ACPI_PMC + bool "Power Manager (x86 PMC) support in TPL" + default y if ACPI_PMC + help + Enable support for an x86-style power-management controller which + provides features including checking whether the system started from + resume, powering off the system and enabling/disabling the reset + mechanism.
drivers/power/acpi_pmc/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2019 Google LLC + +obj-$(CONFIG_$(SPL_TPL_)ACPI_PMC) += acpi-pmc-uclass.o
drivers/power/acpi_pmc/acpi-pmc-uclass.c new file +191 -0
191 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -28,6 +28,7 @@ enum uclass_id {UCLASS_AXI_EMUL ,/* sandbox AXI bus device emulator */ /* U-Boot uclasses start here - in alphabetical order */ +UCLASS_ACPI_PMC ,/* (x86) Power-management controller (PMC) */ UCLASS_ADC ,/* Analog-to-digital converter */ UCLASS_AHCI ,/* SATA disk controller */ UCLASS_AUDIO_CODEC, /* Audio codec with control and data path */
include/power/acpi_pmc.h new file +185 -0
185 lines not on this page · raw message
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 33/108 x86: power: Add an ACPI PMC uclass
Quoted 30 lines · Simon Glass
Intel x86 SoCs have a power manager/controller which handles several power-related aspects of the platform. Add a uclass for this, with a few useful operations.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Rename power-mgr uclass to acpi-pmcChanges in v2: None
drivers/power/Kconfig | 2 + drivers/power/acpi_pmc/Kconfig | 25 +++ drivers/power/acpi_pmc/Makefile | 5 + drivers/power/acpi_pmc/acpi-pmc-uclass.c | 191 +++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/power/acpi_pmc.h | 185 ++++++++++++++++++++++ 6 files changed, 409 insertions(+) create mode 100644 drivers/power/acpi_pmc/Kconfig create mode 100644 drivers/power/acpi_pmc/Makefile create mode 100644 drivers/power/acpi_pmc/acpi-pmc-uclass.c create mode 100644 include/power/acpi_pmc.hdrivers/power/Kconfig +0
-0
drivers/power/Kconfig source "drivers/power/domain/Kconfig" · line 7
Quoted 4 lines
drivers/power/Kconfig +1
-0@@ -4,6 +4,8 @@ source "drivers/power/domain/Kconfig" source "drivers/power/pmic/Kconfig" +source "drivers/power/acpi_pmc/Kconfig"
nits: this should be inserted in the alphabetical order
Quoted 437 lines
drivers/power/Kconfig +1
-0+ source "drivers/power/regulator/Kconfig" choicedrivers/power/acpi_pmc/Kconfig new file +25
-0@@ -0,0 +1,25 @@ +config ACPI_PMC + bool "Power Manager (x86 PMC) support" + help + Enable support for an x86-style power-management controller which + provides features including checking whether the system started from + resume, powering off the system and enabling/disabling the reset + mechanism. + +config SPL_ACPI_PMC + bool "Power Manager (x86 PMC) support in SPL" + default y if ACPI_PMC + help + Enable support for an x86-style power-management controller which + provides features including checking whether the system started from + resume, powering off the system and enabling/disabling the reset + mechanism. + +config TPL_ACPI_PMC + bool "Power Manager (x86 PMC) support in TPL" + default y if ACPI_PMC + help + Enable support for an x86-style power-management controller which + provides features including checking whether the system started from + resume, powering off the system and enabling/disabling the reset + mechanism.drivers/power/acpi_pmc/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2019 Google LLC + +obj-$(CONFIG_$(SPL_TPL_)ACPI_PMC) += acpi-pmc-uclass.odrivers/power/acpi_pmc/acpi-pmc-uclass.c new file +191
-0@@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2019 Google LLC +*/ + +#define LOG_CATEGORY UCLASS_ACPI_PMC + +#include <common.h> +#include <acpi_s3.h> +#include <dm.h> +#include <log.h> +#include <asm/io.h> +#ifdef CONFIG_CREATE_ARCH_SYMLINK +#include <asm/arch/gpio.h> +#endif +#include <power/acpi_pmc.h> + +enum { +PM1_STS =0x00 , +PM1_EN =0x02 , +PM1_CNT =0x04 , + +GPE0_STS =0x20 , +GPE0_EN =0x30 , +}; + +struct tco_regs { +u32 tco_rld; +u32 tco_sts; +u32 tco1_cnt; +u32 tco_tmr; +}; + +enum { +TCO_STS_TIMEOUT =1 <<3 , +TCO_STS_SECOND_TO_STS =1 <<17 , +TCO1_CNT_HLT =1 <<11 , +}; + +static void pmc_fill_pm_reg_info (struct udevice *dev) +{ +struct acpi_pmc_upriv *upriv =dev_get_uclass_priv (dev); +int i; + + upriv->pm1_sts =inw (upriv->acpi_base +PM1_STS ); + upriv->pm1_en =inw (upriv->acpi_base +PM1_EN ); + upriv->pm1_cnt =inw (upriv->acpi_base +PM1_CNT ); + +log_debug ("pm1_sts: %04x pm1_en: %04x pm1_cnt: %08x\n" , + upriv->pm1_sts, upriv->pm1_en, upriv->pm1_cnt); + +for (i =0 ; i <GPE0_REG_MAX ; i++) { + upriv->gpe0_sts[i] =inl (upriv->acpi_base +GPE0_STS + i *4 ); + upriv->gpe0_en[i] =inl (upriv->acpi_base +GPE0_EN + i *4 ); +log_debug ("gpe0_sts[%d]: %08x gpe0_en[%d]: %08x\n" , i, + upriv->gpe0_sts[i], i, upriv->gpe0_en[i]); + } +} + +int pmc_disable_tco_base (ulong tco_base) +{ +struct tco_regs *regs = (struct tco_regs *)tco_base; + +debug ("tco_base %lx = %x\n" , (ulong)®s->tco1_cnt,TCO1_CNT_HLT ); +setio_32 (®s->tco1_cnt,TCO1_CNT_HLT ); + +return 0 ; +} + +int pmc_init (struct udevice *dev) +{ +const struct acpi_pmc_ops *ops =acpi_pmc_get_ops (dev); +int ret; + +pmc_fill_pm_reg_info (dev); +if (!ops->init) +return -ENOSYS ; + + ret = ops->init (dev); +if (ret) +return log_msg_ret ("Failed to init pmc" , ret); + +#ifdef DEBUG +pmc_dump_info (dev); +#endif + +return 0 ; +} + +int pmc_prev_sleep_state (struct udevice *dev) +{ +struct acpi_pmc_upriv *upriv =dev_get_uclass_priv (dev); +const struct acpi_pmc_ops *ops =acpi_pmc_get_ops (dev); +int prev_sleep_state =ACPI_S0 ;/* Default to S0 */ + +if (upriv->pm1_sts &WAK_STS ) { +switch (acpi_sleep_from_pm1 (upriv->pm1_cnt)) { +case ACPI_S3 : +if (IS_ENABLED (HAVE_ACPI_RESUME )) + prev_sleep_state =ACPI_S3 ; +break ; +case ACPI_S5 : + prev_sleep_state =ACPI_S5 ; +break ; +default : +break ; + } + +/* Clear SLP_TYP */ +outl (upriv->pm1_cnt & ~SLP_TYP , upriv->acpi_base +PM1_CNT ); + } + +if (!ops->prev_sleep_state) +return prev_sleep_state; + +return ops->prev_sleep_state (dev, prev_sleep_state); +} + +int pmc_disable_tco (struct udevice *dev) +{ +const struct acpi_pmc_ops *ops =acpi_pmc_get_ops (dev); + +pmc_fill_pm_reg_info (dev); +if (!ops->disable_tco) +return -ENOSYS ; + +return ops->disable_tco (dev); +} + +int pmc_global_reset_set_enable (struct udevice *dev,bool enable) +{ +const struct acpi_pmc_ops *ops =acpi_pmc_get_ops (dev); + +if (!ops->global_reset_set_enable) +return -ENOSYS ; + +return ops->global_reset_set_enable (dev, enable); +} + +void pmc_dump_info (struct udevice *dev) +{ +struct acpi_pmc_upriv *upriv =dev_get_uclass_priv (dev); +int i; + +printf ("Device: %s\n" , dev->name); +printf ("ACPI base %x, pmc_bar0 %p, pmc_bar2 %p, gpe_cfg %p\n" , + upriv->acpi_base, upriv->pmc_bar0, upriv->pmc_bar2, + upriv->gpe_cfg); +printf ("pm1_sts: %04x pm1_en: %04x pm1_cnt: %08x\n" , + upriv->pm1_sts, upriv->pm1_en, upriv->pm1_cnt); + +for (i =0 ; i <GPE0_REG_MAX ; i++) { +printf ("gpe0_sts[%d]: %08x gpe0_en[%d]: %08x\n" , i, + upriv->gpe0_sts[i], i, upriv->gpe0_en[i]); + } + +printf ("prsts: %08x\n" , upriv->prsts); +printf ("tco_sts: %04x %04x\n" , upriv->tco1_sts, upriv->tco2_sts); +printf ("gen_pmcon1: %08x gen_pmcon2: %08x gen_pmcon3: %08x\n" , + upriv->gen_pmcon1, upriv->gen_pmcon2, upriv->gen_pmcon3); +} + +int pmc_ofdata_to_uc_platdata (struct udevice *dev) +{ +struct acpi_pmc_upriv *upriv =dev_get_uclass_priv (dev); +int ret; + + ret =dev_read_u32 (dev,"gpe0-dwx-mask" , &upriv->gpe0_dwx_mask); +if (ret) +return log_msg_ret ("no gpe0-dwx-mask" , ret); + ret =dev_read_u32 (dev,"gpe0-dwx-shift-base" , + &upriv->gpe0_dwx_shift_base); +if (ret) +return log_msg_ret ("no gpe0-dwx-shift-base" , ret); + ret =dev_read_u32 (dev,"gpe0-sts" , &upriv->gpe0_sts_reg); +if (ret) +return log_msg_ret ("no gpe0-sts" , ret); + upriv->gpe0_sts_reg += upriv->acpi_base; + ret =dev_read_u32 (dev,"gpe0-en" , &upriv->gpe0_en_reg); +if (ret) +return log_msg_ret ("no gpe0-en" , ret); + upriv->gpe0_en_reg += upriv->acpi_base; + +return 0 ; +} + +UCLASS_DRIVER (acpi_pmc) = { + .id =UCLASS_ACPI_PMC , + .name ="power-mgr" , + .per_device_auto_alloc_size =sizeof (struct acpi_pmc_upriv ), +};include/dm/uclass-id.h +1
-0@@ -28,6 +28,7 @@ enum uclass_id {UCLASS_AXI_EMUL ,/* sandbox AXI bus device emulator */ /* U-Boot uclasses start here - in alphabetical order */ +UCLASS_ACPI_PMC ,/* (x86) Power-management controller (PMC) */ UCLASS_ADC ,/* Analog-to-digital converter */ UCLASS_AHCI ,/* SATA disk controller */ UCLASS_AUDIO_CODEC, /* Audio codec with control and data path */include/power/acpi_pmc.h new file +176
-0@@ -0,0 +1,185 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright 2019 Google LLC +*/ + +#ifndef __ACPI_PMC_H +#define __ACPI_PMC_H + +enum { +GPE0_REG_MAX =4 , +}; + +/** +* struct acpi_pmc_upriv - holds common data for the x86 PMC +* +* @pmc_bar0: Base address 0 of PMC +* @pmc_bar1: Base address 2 of PMC +* @acpi_base: Base address of ACPI block +* @pm1_sts: PM1 status +* @pm1_en: PM1 enable +* @pm1_cnt: PM1 control +* @gpe_cfg: Address of GPE_CFG register +* @gpe0_dwx_mask: Mask to use for each GPE0 (typically 7 or 0xf) +* @gpe0_dwx_shift_base: Base shift value to use for GPE0 (0 or 4) +* @gpe0_sts_req: GPE0 status register offset +* @gpe0_en_req: GPE0 enable register offset +* @gpe0_sts: GPE0 status values +* @gpe0_en: GPE0 enable values +* @gpe0_dw: GPE0 DW values +* @gpe0_count: Number of GPE0 registers +* @tco1_sts: TCO1 status +* @tco2_sts: TCO2 status +* @prsts: Power and reset status +* @gen_pmcon1: General power mgmt configuration 1 +* @gen_pmcon2: General power mgmt configuration 2 +* @gen_pmcon3: General power mgmt configuration 3 +*/ +struct acpi_pmc_upriv { +void *pmc_bar0; +void *pmc_bar2; +u32 acpi_base; +u16 pm1_sts; +u16 pm1_en; +u32 pm1_cnt; +u32 *gpe_cfg; +u32 gpe0_dwx_mask; +u32 gpe0_dwx_shift_base; +u32 gpe0_sts_reg; +u32 gpe0_en_reg; +u32 gpe0_sts[GPE0_REG_MAX ]; +u32 gpe0_en[GPE0_REG_MAX ]; +u32 gpe0_dw[GPE0_REG_MAX ]; +int gpe0_count; +u16 tco1_sts; +u16 tco2_sts; +u32 prsts; +u32 gen_pmcon1; +u32 gen_pmcon2; +u32 gen_pmcon3; +}; + +struct acpi_pmc_ops { +/** +* init() - Set up the PMC for use +* +* This reads the current state of the PMC. Most of the state is read +* automatically by the uclass since it is common. +* +* This is optional. +* +* @dev: PMC device to use +* @return 0 if OK, -ve on error +*/ +int (*init)(struct udevice *dev); + +/** +* prev_sleep_state() - Get the previous sleep state (optional) +* +* This reads various state registers and returns the sleep state from +* which the system woke. If this method is not provided, the uclass +* will return a calculated value. +* +* This is optional. +* +* @dev: PMC device to use +* @prev_sleep_state: Previous sleep state as calculated by the uclass. +* The method can use this as the return value or calculate its +* own. +* +* @return enum acpi_sleep_state indicating the previous sleep state +* (ACPI_S0, ACPI_S3 or ACPI_S5), or -ve on error +*/ +int (*prev_sleep_state)(struct udevice *dev,int prev_sleep_state); + +/** +* disable_tco() - Disable the timer/counter +* +* Disables the timer/counter in the PMC +* +* This is optional. +* +* @dev: PMC device to use +* @return 0 +*/ +int (*disable_tco)(struct udevice *dev); + +/** +* global_reset_set_enable() - Enable/Disable global reset +* +* Enable or disable global reset. If global reset is enabled, both hard +* reset and soft reset will trigger global reset, where both host and +* TXE are reset. This is cleared on cold boot, hard reset, soft reset +* and Sx. +* +* This is optional. +* +* @dev: PMC device to use +* @enable: true to enable global reset, false to disable +* @return 0 +*/ +int (*global_reset_set_enable)(struct udevice *dev,bool enable); +}; + +#define acpi_pmc_get_ops (dev) ((struct acpi_pmc_ops *)(dev)->driver->ops) + +/** +* init() - Set up the PMC for use +* +* This reads the current state of the PMC. This reads in the common registers, +* then calls the device's init() method to read the SoC-specific registers. +* +* @return 0 if OK, -ve on error +*/ +int pmc_init (struct udevice *dev); + +/** +* pmc_prev_sleep_state() - Get the previous sleep state +* +* This reads various state registers and returns the sleep state from +* which the system woke. +* +* @return enum acpi_sleep_state indicating the previous sleep state +* (ACPI_S0, ACPI_S3 or ACPI_S5), or -ve on error +*/ +int pmc_prev_sleep_state (struct udevice *dev); + +/** +* pmc_disable_tco() - Disable the timer/counter +* +* Disables the timer/counter in the PMC +* +* @dev: PMC device to use +* @return 0 +*/ +int pmc_disable_tco (struct udevice *dev); + +/** +* pmc_global_reset_set_enable() - Enable/Disable global reset +* +* Enable or disable global reset. If global reset is enabled, both hard +* reset and soft reset will trigger global reset, where both host and +* TXE are reset. This is cleared on cold boot, hard reset, soft reset +* and Sx. +* +* @dev: PMC device to use +* @enable: true to enable global reset, false to disable +* @return 0 +*/ +int pmc_global_reset_set_enable (struct udevice *dev,bool enable); + +int pmc_ofdata_to_uc_platdata (struct udevice *dev); + +int pmc_disable_tco_base (ulong tco_base); + +void pmc_dump_info (struct udevice *dev); +
include/power/acpi_pmc.h
Quoted 10 lines
include/power/acpi_pmc.h new file +9
-1+/** +* pmc_gpe_init() - Set up general-purpose events +* +* @dev: PMC device +* @return 0 if OK, -ve on error +*/ +int pmc_gpe_init (struct udevice *dev); + +#endif --
PATCH v3 33/108 x86: power: Add an ACPI PMC uclass
In reply to Simon GlassHi Simon,
Quoted 164 lines · Simon Glass
Intel x86 SoCs have a power manager/controller which handles several power-related aspects of the platform. Add a uclass for this, with a few useful operations.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Rename power-mgr uclass to acpi-pmcChanges in v2: None
drivers/power/Kconfig | 2 + drivers/power/acpi_pmc/Kconfig | 25 +++ drivers/power/acpi_pmc/Makefile | 5 + drivers/power/acpi_pmc/acpi-pmc-uclass.c | 191 +++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/power/acpi_pmc.h | 185 ++++++++++++++++++++++ 6 files changed, 409 insertions(+) create mode 100644 drivers/power/acpi_pmc/Kconfig create mode 100644 drivers/power/acpi_pmc/Makefile create mode 100644 drivers/power/acpi_pmc/acpi-pmc-uclass.c create mode 100644 include/power/acpi_pmc.hdrivers/power/Kconfig +2
-0@@ -4,6 +4,8 @@ source "drivers/power/domain/Kconfig" source "drivers/power/pmic/Kconfig" +source "drivers/power/acpi_pmc/Kconfig" + source "drivers/power/regulator/Kconfig" choicedrivers/power/acpi_pmc/Kconfig new file +25
-0@@ -0,0 +1,25 @@ +config ACPI_PMC + bool "Power Manager (x86 PMC) support" + help + Enable support for an x86-style power-management controller which + provides features including checking whether the system started from + resume, powering off the system and enabling/disabling the reset + mechanism. + +config SPL_ACPI_PMC + bool "Power Manager (x86 PMC) support in SPL" + default y if ACPI_PMC + help + Enable support for an x86-style power-management controller which + provides features including checking whether the system started from + resume, powering off the system and enabling/disabling the reset + mechanism. + +config TPL_ACPI_PMC + bool "Power Manager (x86 PMC) support in TPL" + default y if ACPI_PMC + help + Enable support for an x86-style power-management controller which + provides features including checking whether the system started from + resume, powering off the system and enabling/disabling the reset + mechanism.drivers/power/acpi_pmc/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2019 Google LLC + +obj-$(CONFIG_$(SPL_TPL_)ACPI_PMC) += acpi-pmc-uclass.odrivers/power/acpi_pmc/acpi-pmc-uclass.c new file +78
-0@@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2019 Google LLC +*/ + +#define LOG_CATEGORY UCLASS_ACPI_PMC + +#include <common.h> +#include <acpi_s3.h> +#include <dm.h> +#include <log.h> +#include <asm/io.h> +#ifdef CONFIG_CREATE_ARCH_SYMLINK +#include <asm/arch/gpio.h> +#endif +#include <power/acpi_pmc.h> + +enum { +PM1_STS =0x00 , +PM1_EN =0x02 , +PM1_CNT =0x04 , + +GPE0_STS =0x20 , +GPE0_EN =0x30 , +}; + +struct tco_regs { +u32 tco_rld; +u32 tco_sts; +u32 tco1_cnt; +u32 tco_tmr; +}; + +enum { +TCO_STS_TIMEOUT =1 <<3 , +TCO_STS_SECOND_TO_STS =1 <<17 , +TCO1_CNT_HLT =1 <<11 , +}; + +static void pmc_fill_pm_reg_info (struct udevice *dev) +{ +struct acpi_pmc_upriv *upriv =dev_get_uclass_priv (dev); +int i; + + upriv->pm1_sts =inw (upriv->acpi_base +PM1_STS ); + upriv->pm1_en =inw (upriv->acpi_base +PM1_EN ); + upriv->pm1_cnt =inw (upriv->acpi_base +PM1_CNT ); + +log_debug ("pm1_sts: %04x pm1_en: %04x pm1_cnt: %08x\n" , + upriv->pm1_sts, upriv->pm1_en, upriv->pm1_cnt); + +for (i =0 ; i <GPE0_REG_MAX ; i++) { + upriv->gpe0_sts[i] =inl (upriv->acpi_base +GPE0_STS + i *4 ); + upriv->gpe0_en[i] =inl (upriv->acpi_base +GPE0_EN + i *4 ); +log_debug ("gpe0_sts[%d]: %08x gpe0_en[%d]: %08x\n" , i, + upriv->gpe0_sts[i], i, upriv->gpe0_en[i]); + } +} + +int pmc_disable_tco_base (ulong tco_base) +{ +struct tco_regs *regs = (struct tco_regs *)tco_base; + +debug ("tco_base %lx = %x\n" , (ulong)®s->tco1_cnt,TCO1_CNT_HLT ); +setio_32 (®s->tco1_cnt,TCO1_CNT_HLT ); + +return 0 ; +} + +int pmc_init (struct udevice *dev) +{ +const struct acpi_pmc_ops *ops =acpi_pmc_get_ops (dev); +int ret; + +pmc_fill_pm_reg_info (dev); +if (!ops->init) +return -ENOSYS ; +
drivers/power/acpi_pmc/acpi-pmc-uclass.c line 88
Quoted 10 lines
drivers/power/acpi_pmc/acpi-pmc-uclass.c new file +10
-0+ ret = ops->init (dev); +if (ret) +return log_msg_ret ("Failed to init pmc" , ret); + +#ifdef DEBUG +pmc_dump_info (dev); +#endif + +return 0 ; +}
I wonder shouldn't this be covered by the probe() method?
Quoted 20 lines
drivers/power/acpi_pmc/acpi-pmc-uclass.c new file +20
-0+ +int pmc_prev_sleep_state (struct udevice *dev) +{ +struct acpi_pmc_upriv *upriv =dev_get_uclass_priv (dev); +const struct acpi_pmc_ops *ops =acpi_pmc_get_ops (dev); +int prev_sleep_state =ACPI_S0 ;/* Default to S0 */ + +if (upriv->pm1_sts &WAK_STS ) { +switch (acpi_sleep_from_pm1 (upriv->pm1_cnt)) { +case ACPI_S3 : +if (IS_ENABLED (HAVE_ACPI_RESUME )) + prev_sleep_state =ACPI_S3 ; +break ; +case ACPI_S5 : + prev_sleep_state =ACPI_S5 ; +break ; +default : +break ; + } +
drivers/power/acpi_pmc/acpi-pmc-uclass.c line 118
Quoted 10 lines
drivers/power/acpi_pmc/acpi-pmc-uclass.c new file +10
-0+/* Clear SLP_TYP */ +outl (upriv->pm1_cnt & ~SLP_TYP , upriv->acpi_base +PM1_CNT ); + } + +if (!ops->prev_sleep_state) +return prev_sleep_state; + +return ops->prev_sleep_state (dev, prev_sleep_state); +} +
[snip]
Regards,
Bin
PATCH v3 33/108 x86: power: Add an ACPI PMC uclass
Hi Bin,
Quoted 29 lines · Bin Meng
Hi Simon,
Quoted 25 lines · Simon Glass
Intel x86 SoCs have a power manager/controller which handles several power-related aspects of the platform. Add a uclass for this, with a few useful operations.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Rename power-mgr uclass to acpi-pmcChanges in v2: None
drivers/power/Kconfig | 2 + drivers/power/acpi_pmc/Kconfig | 25 +++ drivers/power/acpi_pmc/Makefile | 5 + drivers/power/acpi_pmc/acpi-pmc-uclass.c | 191 +++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/power/acpi_pmc.h | 185 ++++++++++++++++++++++ 6 files changed, 409 insertions(+) create mode 100644 drivers/power/acpi_pmc/Kconfig create mode 100644 drivers/power/acpi_pmc/Makefile create mode 100644 drivers/power/acpi_pmc/acpi-pmc-uclass.c create mode 100644 include/power/acpi_pmc.h
[..]
Quoted 13 lines
Quoted 13 lines
drivers/power/acpi_pmc/acpi-pmc-uclass.c new file +13
-0+int pmc_init (struct udevice *dev) +{ +const struct acpi_pmc_ops *ops =acpi_pmc_get_ops (dev); +int ret; + +pmc_fill_pm_reg_info (dev); +if (!ops->init) +return -ENOSYS ; + + ret = ops->init (dev); +if (ret) +return log_msg_ret ("Failed to init pmc" , ret); +
Quoted 8 lines
drivers/power/acpi_pmc/acpi-pmc-uclass.c line 88
Quoted 6 lines
drivers/power/acpi_pmc/acpi-pmc-uclass.c new file +6
-0+#ifdef DEBUG +pmc_dump_info (dev); +#endif + +return 0 ; +}I wonder shouldn't this be covered by the
probe()method?
This is called at present from SPL to read information that is not needed in TPL. In effect the PMC is mostly just used for info in TPL, so we don't want to
We could have a check in the probe() function and do different things in TPL, but at the moment I feel that it is worth having an 'init' function which actually sets things up when needed.
[..]
Quoted 5 lines
[snip]
Regards,
Bin
PATCH v3 34/108 x86: sandbox: Add a PMC emulator and test
In reply to Simon GlassAdd a simple PMC for sandbox to permit tests to run.
---
Changes in v3:
- Rename power-mgr uclass to acpi-pmc
Changes in v2: None
Makefile | 3 +- arch/Kconfig | 2 + arch/sandbox/dts/sandbox.dtsi | 14 ++ arch/sandbox/dts/test.dts | 14 ++ arch/sandbox/include/asm/test.h | 1 + drivers/Makefile | 2 + drivers/power/acpi_pmc/Kconfig | 9 ++ drivers/power/acpi_pmc/Makefile | 1 + drivers/power/acpi_pmc/pmc_emul.c | 246 ++++++++++++++++++++++++++++++ drivers/power/acpi_pmc/sandbox.c | 97 ++++++++++++ test/dm/Makefile | 1 + test/dm/pmc.c | 33 ++++ 12 files changed, 422 insertions(+), 1 deletion(-) create mode 100644 drivers/power/acpi_pmc/pmc_emul.c create mode 100644 drivers/power/acpi_pmc/sandbox.c create mode 100644 test/dm/pmc.c
Makefile +2 -1
@@ -725,7 +725,8 @@ libs-y += drivers/power/ \ drivers/power/mfd/ \ drivers/power/pmic/ \ drivers/power/battery/ \ - drivers/power/regulator/ + drivers/power/regulator/ \ + drivers/power/acpi_pmc/ libs-y += drivers/spi/ libs-$(CONFIG_FMAN_ENET) += drivers/net/fm/ libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
arch/Kconfig +2 -0
@@ -133,6 +133,8 @@ config SANDBOX imply PHYLIB imply DM_MDIO imply DM_MDIO_MUX + imply ACPI_PMC + imply ACPI_PMC_SANDBOX config SH bool "SuperH architecture"
arch/sandbox/dts/sandbox.dtsi +14 -0
@@ -100,6 +100,17 @@ }; pci-controller { + pci at 1e,0 { + compatible = "sandbox,pmc"; + reg = <0xf000 0 0 0 0>; + sandbox,emul = <&pmc_emul>; + gpe0-dwx-mask = <0xf>; + gpe0-dwx-shift-base = <4>; + gpe0-dw = <6 7 9>; + gpe0-sts = <0x20>; + gpe0-en = <0x30>; + }; + pci at 1f,0 { compatible = "pci-generic"; reg = <0xf800 0 0 0 0>;
@@ -109,6 +120,9 @@ emul { compatible = "sandbox,pci-emul-parent"; + pmc_emul: emul at 1e,0 { + compatible = "sandbox,pmc-emul"; + }; swap_case_emul: emul at 1f,0 { compatible = "sandbox,swap-case"; };
arch/sandbox/dts/test.dts +14 -0
@@ -467,6 +467,17 @@ 0x01000810 0 0 0 0>; sandbox,emul = <&swap_case_emul0_1>; }; + pci at 1e,0 { + compatible = "sandbox,pmc"; + reg = <0xf000 0 0 0 0>; + sandbox,emul = <&pmc_emul1e>; + acpi-base = <0x400>; + gpe0-dwx-mask = <0xf>; + gpe0-dwx-shift-base = <4>; + gpe0-dw = <6 7 9>; + gpe0-sts = <0x20>; + gpe0-en = <0x30>; + }; pci at 1f,0 { compatible = "pci-generic"; /* reg 0 is at 0x10, using FDT_PCI_SPACE_IO */
@@ -487,6 +498,9 @@ swap_case_emul0_1f: emul0 at 1f,0 { compatible = "sandbox,swap-case"; }; + pmc_emul1e: emul at 1e,0 { + compatible = "sandbox,pmc-emul"; + }; }; pci1: pci-controller1 {
arch/sandbox/include/asm/test.h +1 -0
@@ -13,6 +13,7 @@#define SANDBOX_PCI_VENDOR_ID 0x1234#define SANDBOX_PCI_SWAP_CASE_EMUL_ID 0x5678 +#define SANDBOX_PCI_PMC_EMUL_ID 0x5677#define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM#define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL
drivers/Makefile +2 -0
@@ -40,6 +40,7 @@ obj-$(CONFIG_$(SPL_)ALTERA_SDRAM) += ddr/altera/ obj-$(CONFIG_ARCH_IMX8M) += ddr/imx/imx8m/ obj-$(CONFIG_SPL_POWER_SUPPORT) += power/ power/pmic/ obj-$(CONFIG_SPL_POWER_SUPPORT) += power/regulator/ +obj-$(CONFIG_SPL_ACPI_PMC) += power/acpi_pmc/ obj-$(CONFIG_SPL_POWER_DOMAIN) += power/domain/ obj-$(CONFIG_SPL_DM_RESET) += reset/ obj-$(CONFIG_SPL_MTD_SUPPORT) += mtd/
@@ -67,6 +68,7 @@ endif ifdef CONFIG_TPL_BUILD obj-$(CONFIG_TPL_MPC8XXX_INIT_DDR_SUPPORT) += ddr/fsl/ +obj-$(CONFIG_TPL_ACPI_PMC) += power/acpi_pmc/ endif
drivers/power/acpi_pmc/Kconfig +9 -0
@@ -23,3 +23,12 @@ config TPL_ACPI_PMC provides features including checking whether the system started from resume, powering off the system and enabling/disabling the reset mechanism. + +config ACPI_PMC_SANDBOX + bool "Test power manager (PMC) for sandbox" + depends on ACPI_PMC && SANDBOX + help + This driver emulates a PMC (Power-Management Controller) so that + the uclass logic can be tested. You can use the 'pmc' command to + access information from the driver. It uses I/O access to read + from the PMC.
drivers/power/acpi_pmc/Makefile +1 -0
@@ -3,3 +3,4 @@ # Copyright 2019 Google LLC obj-$(CONFIG_$(SPL_TPL_)ACPI_PMC) += acpi-pmc-uclass.o +obj-$(CONFIG_$(SPL_TPL_)ACPI_PMC_SANDBOX) += sandbox.o pmc_emul.o
drivers/power/acpi_pmc/pmc_emul.c new file +246 -0
246 lines not on this page · raw message
drivers/power/acpi_pmc/sandbox.c new file +97 -0
97 lines not on this page · raw message
test/dm/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_PCI_ENDPOINT) += pci_ep.o obj-$(CONFIG_PCH) += pch.o obj-$(CONFIG_PHY) += phy.o obj-$(CONFIG_POWER_DOMAIN) += power-domain.o +obj-$(CONFIG_ACPI_PMC) += pmc.o obj-$(CONFIG_DM_PWM) += pwm.o obj-$(CONFIG_RAM) += ram.o obj-y += regmap.o
test/dm/pmc.c new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Test for power-management controller uclass (PMC) +* +* Copyright 2019 Google LLC +*/ + +#include <common.h> +#include <dm.h> +#include <power/acpi_pmc.h> +#include <dm/test.h> +#include <test/ut.h> + +/* Base test of the PMC uclass */ +static int dm_test_pmc_base (struct unit_test_state *uts) +{ +struct acpi_pmc_upriv *upriv; +struct udevice *dev; + +ut_assertok (uclass_first_device_err (UCLASS_ACPI_PMC , &dev)); + +ut_assertok (pmc_disable_tco (dev)); +ut_assertok (pmc_init (dev)); +ut_assertok (pmc_prev_sleep_state (dev)); + +/* Check some values to see that I/O works */ + upriv =dev_get_uclass_priv (dev); +ut_asserteq (0x24 , upriv->gpe0_sts[1 ]); +ut_asserteq (0x64 , upriv->tco1_sts); + +return 0 ; +} +DM_TEST (dm_test_pmc_base,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 35/108 x86: power: Add a 'pmc' command
In reply to Simon GlassAdd a simple command to show information about the PMC.
---
Changes in v3:
- Rename power-mgr uclass to acpi-pmc
Changes in v2: None
arch/Kconfig | 1 + cmd/Kconfig | 8 ++++++ cmd/Makefile | 1 + cmd/pmc.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 cmd/pmc.c
arch/Kconfig +1 -0
@@ -135,6 +135,7 @@ config SANDBOX imply DM_MDIO_MUX imply ACPI_PMC imply ACPI_PMC_SANDBOX + imply CMD_PMC config SH bool "SuperH architecture"
cmd/Kconfig +8 -0
@@ -228,6 +228,14 @@ config CMD_LICENSE help Print GPL license text +config CMD_PMC + bool "pmc" + help + Provides access to the Intel Power-Management Controller (PMC) so + that its state can be examined. This does not currently support + changing the state but it is still useful for debugging and seeing + what is going on. + config CMD_REGINFO bool "reginfo" depends on PPC
cmd/Makefile +1 -0
@@ -108,6 +108,7 @@ ifdef CONFIG_PCI obj-$(CONFIG_CMD_PCI) += pci.o endif obj-$(CONFIG_CMD_PINMUX) += pinmux.o +obj-$(CONFIG_CMD_PMC) += pmc.o obj-$(CONFIG_CMD_PXE) += pxe.o obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_CMD_QFW) += qfw.o
cmd/pmc.c new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 35/108 x86: power: Add a 'pmc' command
Quoted 2 lines · Simon Glass
Add a simple command to show information about the PMC.
PMC is a part of almost all Intel Atom SoCs. Can you describe how can it be utilized for example in case of Tangier?
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 35/108 x86: power: Add a 'pmc' command
Hi Andy,
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Simon Glass
Add a simple command to show information about the PMC.
PMC is a part of almost all Intel Atom SoCs. Can you describe how can it be utilized for example in case of Tangier?
Well if the driver is enabled then I expect the 'pmc info' command could be used there?
Regards,
SImon
PATCH v3 35/108 x86: power: Add a 'pmc' command
Quoted 11 lines · Simon Glass
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Simon Glass
Add a simple command to show information about the PMC.
PMC is a part of almost all Intel Atom SoCs. Can you describe how can it be utilized for example in case of Tangier?
Well if the driver is enabled then I expect the 'pmc info' command could be used there?
PMC is unique to a platform / SoC. My question here is to provide some skeleton / Documentation how other (non-APL) SoC drivers can enable pmc info etc.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 35/108 x86: power: Add a 'pmc' command
Hi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Simon Glass
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Simon Glass
Add a simple command to show information about the PMC.
PMC is a part of almost all Intel Atom SoCs. Can you describe how can it be utilized for example in case of Tangier?
Quoted 6 lines
Quoted 2 lines
Well if the driver is enabled then I expect the 'pmc info' command could be used there?
PMC is unique to a platform / SoC. My question here is to provide some skeleton / Documentation how other (non-APL) SoC drivers can enable
pmc infoetc.
OK I see. I suspect that there might be some common fields but also some fields specific to each SoC.
My expectation is that we would print out whatever of these fields seems useful/suitable. Does that sound reasonable?
Regards,
Simon
PATCH v3 36/108 pci: Add support for p2sb uclass
In reply to Simon GlassThe Primary-to-Sideband bus (P2SB) is used to access various peripherals through memory-mapped I/O in a large chunk of PCI space. The space is segmented into different channels and peripherals are accessed by device-specific means within those channels. Devices should be added in the device tree as subnodes of the p2sb.
This adds a uclass and enables it for sandbox.
---
Changes in v3: None
Changes in v2: None
configs/sandbox_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + drivers/misc/Kconfig | 33 ++++++ drivers/misc/Makefile | 1 + drivers/misc/p2sb-uclass.c | 209 ++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/p2sb.h | 127 +++++++++++++++++++++ 7 files changed, 373 insertions(+) create mode 100644 drivers/misc/p2sb-uclass.c create mode 100644 include/p2sb.h
configs/sandbox_defconfig +1 -0
@@ -150,6 +150,7 @@ CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_P2SB=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=y
configs/sandbox_spl_defconfig +1 -0
@@ -135,6 +135,7 @@ CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_P2SB=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=y
drivers/misc/Kconfig +33 -0
@@ -217,6 +217,39 @@ config NUVOTON_NCT6102D disable the legacy UART, the watchdog or other devices in the Nuvoton Super IO chips on X86 platforms. +config P2SB + bool "Intel Primary-to-Sideband Bus" + depends on X86 || SANDBOX + help + This enables support for the Intel Primary-to-Sideband bus, + abbreviated to P2SB. The P2SB is used to access various peripherals + such as eSPI, GPIO, through memory-mapped I/O in a large chunk of PCI + space. The space is segmented into different channels and peripherals + are accessed by device-specific means within those channels. Devices + should be added in the device tree as subnodes of the P2SB. A + Peripheral Channel Register? (PCR) API is provided to access those + devices - see pcr_readl(), etc. + +config SPL_P2SB + bool "Intel Primary-to-Sideband Bus in SPL" + depends on SPL && (X86 || SANDBOX) + help + The Primary-to-Sideband bus is used to access various peripherals + through memory-mapped I/O in a large chunk of PCI space. The space is + segmented into different channels and peripherals are accessed by + device-specific means within those channels. Devices should be added + in the device tree as subnodes of the p2sb. + +config TPL_P2SB + bool "Intel Primary-to-Sideband Bus in TPL" + depends on TPL && (X86 || SANDBOX) + help + The Primary-to-Sideband bus is used to access various peripherals + through memory-mapped I/O in a large chunk of PCI space. The space is + segmented into different channels and peripherals are accessed by + device-specific means within those channels. Devices should be added + in the device tree as subnodes of the p2sb. + config PWRSEQ bool "Enable power-sequencing drivers" depends on DM
drivers/misc/Makefile +1 -0
@@ -49,6 +49,7 @@ obj-$(CONFIG_MXC_OCOTP) += mxc_ocotp.o obj-$(CONFIG_MXS_OCOTP) += mxs_ocotp.o obj-$(CONFIG_NS87308) += ns87308.o obj-$(CONFIG_NUVOTON_NCT6102D) += nuvoton_nct6102d.o +obj-$(CONFIG_P2SB) += p2sb-uclass.o obj-$(CONFIG_PCA9551_LED) += pca9551_led.o obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o obj-$(CONFIG_QFW) += qfw.o
drivers/misc/p2sb-uclass.c new file +209 -0
209 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -70,6 +70,7 @@ enum uclass_id {UCLASS_NOP ,/* No-op devices */ UCLASS_NORTHBRIDGE ,/* Intel Northbridge / SDRAM controller */ UCLASS_NVME ,/* NVM Express device */ +UCLASS_P2SB ,/* (x86) Primary-to-Sideband Bus */ UCLASS_PANEL ,/* Display panel, such as an LCD */ UCLASS_PANEL_BACKLIGHT ,/* Backlight controller for panel */ UCLASS_PCH, /* x86 platform controller hub */
include/p2sb.h new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 36/108 pci: Add support for p2sb uclass
Hi Simon,
Quoted 59 lines · Simon Glass
The Primary-to-Sideband bus (P2SB) is used to access various peripherals through memory-mapped I/O in a large chunk of PCI space. The space is segmented into different channels and peripherals are accessed by device-specific means within those channels. Devices should be added in the device tree as subnodes of the p2sb.
This adds a uclass and enables it for sandbox.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Noneconfigs/sandbox_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + drivers/misc/Kconfig | 33 ++++++ drivers/misc/Makefile | 1 + drivers/misc/p2sb-uclass.c | 209 ++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/p2sb.h | 127 +++++++++++++++++++++ 7 files changed, 373 insertions(+) create mode 100644 drivers/misc/p2sb-uclass.c create mode 100644 include/p2sb.hconfigs/sandbox_defconfig +1
-0@@ -150,6 +150,7 @@ CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_P2SB=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=yconfigs/sandbox_spl_defconfig +1
-0@@ -135,6 +135,7 @@ CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_P2SB=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=ydrivers/misc/Kconfig +1
-0@@ -217,6 +217,39 @@ config NUVOTON_NCT6102D disable the legacy UART, the watchdog or other devices in the Nuvoton Super IO chips on X86 platforms. +config P2SB
drivers/misc/Kconfig config NUVOTON_NCT6102D · line 230
Quoted 10 lines
drivers/misc/Kconfig +10
-0+ bool "Intel Primary-to-Sideband Bus" + depends on X86 || SANDBOX + help + This enables support for the Intel Primary-to-Sideband bus, + abbreviated to P2SB. The P2SB is used to access various peripherals + such as eSPI, GPIO, through memory-mapped I/O in a large chunk of PCI + space. The space is segmented into different channels and peripherals + are accessed by device-specific means within those channels. Devices + should be added in the device tree as subnodes of the P2SB. A + Peripheral Channel Register? (PCR) API is provided to access those
What does the ? mean? We are not sure what PCR stands for?
Quoted 317 lines
drivers/misc/Kconfig +22
-0+ devices - see pcr_readl(), etc. + +config SPL_P2SB + bool "Intel Primary-to-Sideband Bus in SPL" + depends on SPL && (X86 || SANDBOX) + help + The Primary-to-Sideband bus is used to access various peripherals + through memory-mapped I/O in a large chunk of PCI space. The space is + segmented into different channels and peripherals are accessed by + device-specific means within those channels. Devices should be added + in the device tree as subnodes of the p2sb. + +config TPL_P2SB + bool "Intel Primary-to-Sideband Bus in TPL" + depends on TPL && (X86 || SANDBOX) + help + The Primary-to-Sideband bus is used to access various peripherals + through memory-mapped I/O in a large chunk of PCI space. The space is + segmented into different channels and peripherals are accessed by + device-specific means within those channels. Devices should be added + in the device tree as subnodes of the p2sb. + config PWRSEQ bool "Enable power-sequencing drivers" depends on DMdrivers/misc/Makefile +1
-0@@ -49,6 +49,7 @@ obj-$(CONFIG_MXC_OCOTP) += mxc_ocotp.o obj-$(CONFIG_MXS_OCOTP) += mxs_ocotp.o obj-$(CONFIG_NS87308) += ns87308.o obj-$(CONFIG_NUVOTON_NCT6102D) += nuvoton_nct6102d.o +obj-$(CONFIG_P2SB) += p2sb-uclass.o obj-$(CONFIG_PCA9551_LED) += pca9551_led.o obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o obj-$(CONFIG_QFW) += qfw.odrivers/misc/p2sb-uclass.c new file +209
-0@@ -0,0 +1,209 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Uclass for Primary-to-sideband bus, used to access various peripherals +* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#include <common.h> +#include <dm.h> +#include <mapmem.h> +#include <p2sb.h> +#include <spl.h> +#include <asm/io.h> +#include <dm/uclass-internal.h> + +#define PCR_COMMON_IOSF_1_0 1 + +static void *_pcr_reg_address (struct udevice *dev,uint offset) +{ +struct p2sb_child_platdata *pplat =dev_get_parent_platdata (dev); +struct udevice *p2sb =dev_get_parent (dev); +struct p2sb_uc_priv *upriv =dev_get_uclass_priv (p2sb); +uintptr_t reg_addr; + +/* Create an address based off of port id and offset */ + reg_addr = upriv->mmio_base; + reg_addr += pplat->pid <<PCR_PORTID_SHIFT ; + reg_addr += offset; + +return map_sysmem (reg_addr,4 ); +} + +/* +* The mapping of addresses via the SBREG_BAR assumes the IOSF-SB +* agents are using 32-bit aligned accesses for their configuration +* registers. For IOSF versions greater than 1_0, IOSF-SB +* agents can use any access (8/16/32 bit aligned) for their +* configuration registers +*/ +static inline void check_pcr_offset_align (uint offset,uint size) +{ +const size_t align =PCR_COMMON_IOSF_1_0 ?sizeof (uint32_t ) : size; + +assert (IS_ALIGNED (offset, align)); +} + +uint pcr_read32 (struct udevice *dev,uint offset) +{ +void *ptr; +uint val; + +/* Ensure the PCR offset is correctly aligned */ +assert (IS_ALIGNED (offset,sizeof (uint32_t ))); + + ptr =_pcr_reg_address (dev, offset); + val =readl (ptr); +unmap_sysmem (ptr); + +return val; +} + +uint pcr_read16 (struct udevice *dev,uint offset) +{ +/* Ensure the PCR offset is correctly aligned */ +check_pcr_offset_align (offset,sizeof (uint16_t )); + +return readw (_pcr_reg_address (dev, offset)); +} + +uint pcr_read8 (struct udevice *dev,uint offset) +{ +/* Ensure the PCR offset is correctly aligned */ +check_pcr_offset_align (offset,sizeof (uint8_t )); + +return readb (_pcr_reg_address (dev, offset)); +} + +/* +* After every write one needs to perform a read an innocuous register to +* ensure the writes are completed for certain ports. This is done for +* all ports so that the callers don't need the per-port knowledge for +* each transaction. +*/ +static void write_completion (struct udevice *dev,uint offset) +{ +readl (_pcr_reg_address (dev,ALIGN_DOWN (offset,sizeof (uint32_t )))); +} + +void pcr_write32 (struct udevice *dev,uint offset,uint indata) +{ +/* Ensure the PCR offset is correctly aligned */ +assert (IS_ALIGNED (offset,sizeof (indata))); + +writel (indata,_pcr_reg_address (dev, offset)); +/* Ensure the writes complete */ +write_completion (dev, offset); +} + +void pcr_write16 (struct udevice *dev,uint offset,uint indata) +{ +/* Ensure the PCR offset is correctly aligned */ +check_pcr_offset_align (offset,sizeof (uint16_t )); + +writew (indata,_pcr_reg_address (dev, offset)); +/* Ensure the writes complete */ +write_completion (dev, offset); +} + +void pcr_write8 (struct udevice *dev,uint offset,uint indata) +{ +/* Ensure the PCR offset is correctly aligned */ +check_pcr_offset_align (offset,sizeof (uint8_t )); + +writeb (indata,_pcr_reg_address (dev, offset)); +/* Ensure the writes complete */ +write_completion (dev, offset); +} + +void pcr_clrsetbits32 (struct udevice *dev,uint offset,uint clr,uint set) +{ +uint data32; + + data32 =pcr_read32 (dev, offset); + data32 &= ~clr; + data32 |= set; +pcr_write32 (dev, offset, data32); +} + +void pcr_clrsetbits16 (struct udevice *dev,uint offset,uint clr,uint set) +{ +uint data16; + + data16 =pcr_read16 (dev, offset); + data16 &= ~clr; + data16 |= set; +pcr_write16 (dev, offset, data16); +} + +void pcr_clrsetbits8 (struct udevice *dev,uint offset,uint clr,uint set) +{ +uint data8; + + data8 =pcr_read8 (dev, offset); + data8 &= ~clr; + data8 |= set; +pcr_write8 (dev, offset, data8); +} + +int p2sb_set_port_id (struct udevice *dev,int portid) +{ +struct udevice *ps2b; +struct p2sb_child_platdata *pplat; + +if (!CONFIG_IS_ENABLED (OF_PLATDATA )) +return -ENOSYS ; + +uclass_find_first_device (UCLASS_P2SB , &ps2b); +if (!ps2b) +return -EDEADLK ; + dev->parent = ps2b; + +/* +* We must allocate this, since when the device was bound it did not +* have a parent. +* TODO(sjg at chromium.org): Add a parent pointer to child devices in dtoc +*/ + dev->parent_platdata =malloc (sizeof (*pplat)); +if (!dev->parent_platdata) +return -ENOMEM ; + pplat =dev_get_parent_platdata (dev); + pplat->pid = portid; + +return 0 ; +} + +static int p2sb_child_post_bind (struct udevice *dev) +{ +#if !CONFIG_IS_ENABLED (OF_PLATDATA ) +struct p2sb_child_platdata *pplat =dev_get_parent_platdata (dev); +int ret; +u32 pid; + + ret =dev_read_u32 (dev,"intel,p2sb-port-id" , &pid); +if (ret) +return ret; + pplat->pid = pid; +#endif + +return 0 ; +} + +static int p2sb_post_bind (struct udevice *dev) +{ +if (spl_phase () >=PHASE_SPL && !CONFIG_IS_ENABLED (OF_PLATDATA )) +return dm_scan_fdt_dev (dev); + +return 0 ; +} + +UCLASS_DRIVER (p2sb) = { + .id =UCLASS_P2SB , + .name ="p2sb" , + .per_device_auto_alloc_size =sizeof (struct p2sb_uc_priv ), + .post_bind = p2sb_post_bind, + .child_post_bind = p2sb_child_post_bind, + .per_child_platdata_auto_alloc_size = +sizeof (struct p2sb_child_platdata ), +};include/dm/uclass-id.h +1
-0@@ -70,6 +70,7 @@ enum uclass_id {UCLASS_NOP ,/* No-op devices */ UCLASS_NORTHBRIDGE ,/* Intel Northbridge / SDRAM controller */ UCLASS_NVME ,/* NVM Express device */ +UCLASS_P2SB ,/* (x86) Primary-to-Sideband Bus */ UCLASS_PANEL ,/* Display panel, such as an LCD */ UCLASS_PANEL_BACKLIGHT ,/* Backlight controller for panel */ UCLASS_PCH, /* x86 platform controller hub */include/p2sb.h new file +47
-0@@ -0,0 +1,127 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#ifndef __p2sb_h +#define __p2sb_h + +/* Port Id lives in bits 23:16 and register offset lives in 15:0 of address */ +#define PCR_PORTID_SHIFT 16 + +/** +* struct p2sb_child_platdata - Information about each child of a p2sb device +* +* @pid: Port ID for this child +*/ +struct p2sb_child_platdata { +uint pid; +}; + +/** +* struct p2sb_uc_priv - information for the uclass about each device +* +* This must be set up by the driver when it is probed +* +* @mmio_base: Base address of P2SB region +*/ +struct p2sb_uc_priv { +uint mmio_base; +}; + +/** +* struct p2sb_ops - Operations for the P2SB (none at present) +*/ +struct p2sb_ops { +}; + +#define p2sb_get_ops (dev) ((struct p2sb_ops *)(dev)->driver->ops) + +/** +* pcr_read32/16/8() - Read from a PCR device +* +* Reads data from a PCR device within the P2SB +* +* @dev: Device to read from +* @offset: Offset within device to read
include/p2sb.h line 57
Quoted 10 lines
include/p2sb.h new file +10
-0+* @return value read +*/ +uint pcr_read32 (struct udevice *dev,uint offset); +uint pcr_read16 (struct udevice *dev,uint offset); +uint pcr_read8 (struct udevice *dev,uint offset); + +/** +* pcr_read32/16/8() - Write to a PCR device +* +* Writes data to a PCR device within the P2SB
Read data
Quoted 61 lines
include/p2sb.h new file +61
-0+* +* @dev: Device to write to +* @offset: Offset within device to write +* @data: Data to write +*/ +void pcr_write32 (struct udevice *dev,uint offset,uint data); +void pcr_write16 (struct udevice *dev,uint offset,uint data); +void pcr_write8 (struct udevice *dev,uint offset,uint data); + +/** +* pcr_clrsetbits32/16/8() - Update a PCR device +* +* Updates dat in a PCR device within the P2SB +* +* This reads from the device, clears and set bits, then writes back. +* +* new_data = (old_data & ~clr) | set +* +* @dev: Device to update +* @offset: Offset within device to update +* @clr: Bits to clear after reading +* @set: Bits to set before writing +*/ +void pcr_clrsetbits32 (struct udevice *dev,uint offset,uint clr,uint set); +void pcr_clrsetbits16 (struct udevice *dev,uint offset,uint clr,uint set); +void pcr_clrsetbits8 (struct udevice *dev,uint offset,uint clr,uint set); + +static inline void pcr_setbits32 (struct udevice *dev,uint offset,uint set) +{ +return pcr_clrsetbits32 (dev, offset,0 , set); +} + +static inline void pcr_setbits16 (struct udevice *dev,uint offset,uint set) +{ +return pcr_clrsetbits16 (dev, offset,0 , set); +} + +static inline void pcr_setbits8 (struct udevice *dev,uint offset,uint set) +{ +return pcr_clrsetbits8 (dev, offset,0 , set); +} + +static inline void pcr_clrbits32 (struct udevice *dev,uint offset,uint clr) +{ +return pcr_clrsetbits32 (dev, offset, clr,0 ); +} + +static inline void pcr_clrbits16 (struct udevice *dev,uint offset,uint clr) +{ +return pcr_clrsetbits16 (dev, offset, clr,0 ); +} + +static inline void pcr_clrbits8 (struct udevice *dev,uint offset,uint clr) +{ +return pcr_clrsetbits8 (dev, offset, clr,0 ); +} + +/** +* p2sb_set_port_id() - Set the port ID for a p2sb child device +* +* This must be called in a device's bind() method when OF_PLATDATA is used
include/p2sb.h
Quoted 10 lines
include/p2sb.h new file +9
-1+* since the uclass cannot access the device's of-platdata. +* +* @dev: Child device (whose parent is UCLASS_P2SB) +* @portid: Port ID of child device +* @return 0 if OK, -ENODEV is the p2sb device could not be found +*/ +int p2sb_set_port_id (struct udevice *dev,int portid); + +#endif --
I still are not sure P2SB is generic enough to merit a uclass driver.
Regards,
Bin
PATCH v3 36/108 pci: Add support for p2sb uclass
Hi Bin,
Quoted 62 lines · Bin Meng
Hi Simon,
Quoted 58 lines · Simon Glass
The Primary-to-Sideband bus (P2SB) is used to access various peripherals through memory-mapped I/O in a large chunk of PCI space. The space is segmented into different channels and peripherals are accessed by device-specific means within those channels. Devices should be added in the device tree as subnodes of the p2sb.
This adds a uclass and enables it for sandbox.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Noneconfigs/sandbox_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + drivers/misc/Kconfig | 33 ++++++ drivers/misc/Makefile | 1 + drivers/misc/p2sb-uclass.c | 209 ++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/p2sb.h | 127 +++++++++++++++++++++ 7 files changed, 373 insertions(+) create mode 100644 drivers/misc/p2sb-uclass.c create mode 100644 include/p2sb.hconfigs/sandbox_defconfig +1
-0@@ -150,6 +150,7 @@ CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_P2SB=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=yconfigs/sandbox_spl_defconfig +1
-0@@ -135,6 +135,7 @@ CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_P2SB=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=ydrivers/misc/Kconfig +0
-0@@ -217,6 +217,39 @@ config NUVOTON_NCT6102D disable the legacy UART, the watchdog or other devices in the Nuvoton Super IO chips on X86 platforms.
Quoted 13 lines
drivers/misc/Kconfig config NUVOTON_NCT6102D · line 230
Quoted 11 lines
drivers/misc/Kconfig +11
-0+config P2SB + bool "Intel Primary-to-Sideband Bus" + depends on X86 || SANDBOX + help + This enables support for the Intel Primary-to-Sideband bus, + abbreviated to P2SB. The P2SB is used to access various peripherals + such as eSPI, GPIO, through memory-mapped I/O in a large chunk of PCI + space. The space is segmented into different channels and peripherals + are accessed by device-specific means within those channels. Devices + should be added in the device tree as subnodes of the P2SB. A + Peripheral Channel Register? (PCR) API is provided to access thoseWhat does the ? mean? We are not sure what PCR stands for?
That's right. I cannot actually find a reference. The abbreviations for quite a few things seems to be used without a definition.
[..]
Quoted 131 lines
Quoted 53 lines
include/p2sb.h new file +47
-0@@ -0,0 +1,127 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#ifndef __p2sb_h +#define __p2sb_h + +/* Port Id lives in bits 23:16 and register offset lives in 15:0 of address */ +#define PCR_PORTID_SHIFT 16 + +/** +* struct p2sb_child_platdata - Information about each child of a p2sb device +* +* @pid: Port ID for this child +*/ +struct p2sb_child_platdata { +uint pid; +}; + +/** +* struct p2sb_uc_priv - information for the uclass about each device +* +* This must be set up by the driver when it is probed +* +* @mmio_base: Base address of P2SB region +*/ +struct p2sb_uc_priv { +uint mmio_base; +}; + +/** +* struct p2sb_ops - Operations for the P2SB (none at present) +*/ +struct p2sb_ops { +}; + +#define p2sb_get_ops (dev) ((struct p2sb_ops *)(dev)->driver->ops) + +/** +* pcr_read32/16/8() - Read from a PCR device +* +* Reads data from a PCR device within the P2SB +* +* @dev: Device to read from +* @offset: Offset within device to read include/p2sb.h line 57
Quoted 10 lines
include/p2sb.h new file +10
-0+* @return value read +*/ +uint pcr_read32 (struct udevice *dev,uint offset); +uint pcr_read16 (struct udevice *dev,uint offset); +uint pcr_read8 (struct udevice *dev,uint offset); + +/** +* pcr_read32/16/8() - Write to a PCR device +* +* Writes data to a PCR device within the P2SB Read data
Quoted 65 lines
include/p2sb.h new file +65
-0+* +* @dev: Device to write to +* @offset: Offset within device to write +* @data: Data to write +*/ +void pcr_write32 (struct udevice *dev,uint offset,uint data); +void pcr_write16 (struct udevice *dev,uint offset,uint data); +void pcr_write8 (struct udevice *dev,uint offset,uint data); + +/** +* pcr_clrsetbits32/16/8() - Update a PCR device +* +* Updates dat in a PCR device within the P2SB +* +* This reads from the device, clears and set bits, then writes back. +* +* new_data = (old_data & ~clr) | set +* +* @dev: Device to update +* @offset: Offset within device to update +* @clr: Bits to clear after reading +* @set: Bits to set before writing +*/ +void pcr_clrsetbits32 (struct udevice *dev,uint offset,uint clr,uint set); +void pcr_clrsetbits16 (struct udevice *dev,uint offset,uint clr,uint set); +void pcr_clrsetbits8 (struct udevice *dev,uint offset,uint clr,uint set); + +static inline void pcr_setbits32 (struct udevice *dev,uint offset,uint set) +{ +return pcr_clrsetbits32 (dev, offset,0 , set); +} + +static inline void pcr_setbits16 (struct udevice *dev,uint offset,uint set) +{ +return pcr_clrsetbits16 (dev, offset,0 , set); +} + +static inline void pcr_setbits8 (struct udevice *dev,uint offset,uint set) +{ +return pcr_clrsetbits8 (dev, offset,0 , set); +} + +static inline void pcr_clrbits32 (struct udevice *dev,uint offset,uint clr) +{ +return pcr_clrsetbits32 (dev, offset, clr,0 ); +} + +static inline void pcr_clrbits16 (struct udevice *dev,uint offset,uint clr) +{ +return pcr_clrsetbits16 (dev, offset, clr,0 ); +} + +static inline void pcr_clrbits8 (struct udevice *dev,uint offset,uint clr) +{ +return pcr_clrsetbits8 (dev, offset, clr,0 ); +} + +/** +* p2sb_set_port_id() - Set the port ID for a p2sb child device +* +* This must be called in a device's bind() method when OF_PLATDATA is used +* since the uclass cannot access the device's of-platdata. +* +* @dev: Child device (whose parent is UCLASS_P2SB) +* @portid: Port ID of child device
Quoted 8 lines
include/p2sb.h
Quoted 6 lines
include/p2sb.h new file +5
-1+* @return 0 if OK, -ENODEV is the p2sb device could not be found +*/ +int p2sb_set_port_id (struct udevice *dev,int portid); + +#endif --I still are not sure P2SB is generic enough to merit a uclass driver.
If you look at the device tree it works really well. It is a bit similar to a simple-bus but has its own functionality, such as children accessing their memory-mapped regions under control of the uclass. In that it is similar to i2c or PCI, which have uclasses. We have child nodes of the p2sb, and in the case of pinctrl they have grandchild nodes (in my latest update, not v3).
It is true that this is specific to x86, but I don't see a problem with that. We have other uclasses that are arch-specific.
Regards,
Simon
PATCH v3 37/108 sandbox: Add PCI driver and test for p2sb
In reply to Simon GlassAdd a sandbox driver and PCI-device emulator for p2sb. Also add a test which uses a simple 'adder' driver to test the p2sb functionality.
---
Changes in v3:
- Fix build errors in sandbox_spl, etc
Changes in v2: None
arch/sandbox/cpu/state.c | 1 + arch/sandbox/dts/test.dts | 13 ++ arch/sandbox/include/asm/test.h | 10 ++ configs/sandbox64_defconfig | 2 + configs/sandbox_flattree_defconfig | 3 + configs/sandbox_spl_defconfig | 2 + configs/tools-only_defconfig | 2 + drivers/core/uclass.c | 4 +- drivers/misc/Makefile | 2 + drivers/misc/p2sb_emul.c | 272 +++++++++++++++++++++++++++++ drivers/misc/p2sb_sandbox.c | 44 +++++ drivers/misc/sandbox_adder.c | 60 +++++++ test/dm/Makefile | 1 + test/dm/p2sb.c | 28 +++ 14 files changed, 442 insertions(+), 2 deletions(-) create mode 100644 drivers/misc/p2sb_emul.c create mode 100644 drivers/misc/p2sb_sandbox.c create mode 100644 drivers/misc/sandbox_adder.c create mode 100644 test/dm/p2sb.c
arch/sandbox/cpu/state.c +1 -0
@@ -356,6 +356,7 @@ void state_reset_for_test(struct sandbox_state *state)/* No reset yet, so mark it as such. Always allow power reset */ state->last_sysreset =SYSRESET_COUNT ; state->sysreset_allowed[SYSRESET_POWER_OFF ] = true; + state->allow_memio = false;memset (&state->wdt,'\0' ,sizeof (state->wdt));memset (state->spi,'\0' ,sizeof (state->spi));
arch/sandbox/dts/test.dts +13 -0
@@ -467,6 +467,16 @@ 0x01000810 0 0 0 0>; sandbox,emul = <&swap_case_emul0_1>; }; + p2sb-pci at 2,0 { + compatible = "sandbox,p2sb"; + reg = <0x02001010 0 0 0 0>; + sandbox,emul = <&p2sb_emul>; + + adder { + intel,p2sb-port-id = <3>; + compatible = "sandbox,adder"; + }; + }; pci at 1e,0 { compatible = "sandbox,pmc"; reg = <0xf000 0 0 0 0>;
@@ -498,6 +508,9 @@ swap_case_emul0_1f: emul0 at 1f,0 { compatible = "sandbox,swap-case"; }; + p2sb_emul: emul at 2,0 { + compatible = "sandbox,p2sb-emul"; + }; pmc_emul1e: emul at 1e,0 { compatible = "sandbox,pmc-emul"; };
arch/sandbox/include/asm/test.h +10 -0
@@ -14,6 +14,7 @@#define SANDBOX_PCI_VENDOR_ID 0x1234#define SANDBOX_PCI_SWAP_CASE_EMUL_ID 0x5678#define SANDBOX_PCI_PMC_EMUL_ID 0x5677 +#define SANDBOX_PCI_P2SB_EMUL_ID 0x5676#define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM#define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL
@@ -214,4 +215,13 @@ int sandbox_get_pci_ep_irq_count(struct udevice *dev);*/ uint sandbox_pci_read_bar (u32 barval,int type,uint size); +/** +* sandbox_set_enable_memio() - Enable memory-mapped I/O read/write +* +* Normally readl(), writel() and the like are nops on sandbox. If this function +* is called with true, those function do real memory accesses. This is useful +* for certain tests. +*/ +void sandbox_set_enable_memio (bool enable); +#endif
configs/sandbox64_defconfig +2 -0
@@ -81,6 +81,8 @@ CONFIG_DEVRES=y CONFIG_DEBUG_DEVRES=y CONFIG_ADC=y CONFIG_ADC_SANDBOX=y +CONFIG_AXI=y +CONFIG_AXI_SANDBOX=y CONFIG_CLK=y CONFIG_CPU=y CONFIG_DM_DEMO=y
configs/sandbox_flattree_defconfig +3 -0
@@ -65,6 +65,8 @@ CONFIG_DEVRES=y CONFIG_DEBUG_DEVRES=y CONFIG_ADC=y CONFIG_ADC_SANDBOX=y +CONFIG_AXI=y +CONFIG_AXI_SANDBOX=y CONFIG_CLK=y CONFIG_CLK_COMPOSITE_CCF=y CONFIG_SANDBOX_CLK_CCF=y
@@ -116,6 +118,7 @@ CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_P2SB=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=y
configs/sandbox_spl_defconfig +2 -0
@@ -86,6 +86,8 @@ CONFIG_DEBUG_DEVRES=y # CONFIG_SPL_SIMPLE_BUS is not set CONFIG_ADC=y CONFIG_ADC_SANDBOX=y +CONFIG_AXI=y +CONFIG_AXI_SANDBOX=y CONFIG_CLK=y CONFIG_CPU=y CONFIG_DM_DEMO=y
configs/tools-only_defconfig +2 -0
@@ -11,6 +11,8 @@ CONFIG_OF_HOSTFILE=y CONFIG_DEFAULT_DEVICE_TREE="sandbox" CONFIG_IP_DEFRAG=y # CONFIG_UDP_FUNCTION_FASTBOOT is not set +CONFIG_AXI=y +CONFIG_AXI_SANDBOX=y CONFIG_SANDBOX_GPIO=y CONFIG_PCI=y CONFIG_DM_PCI=y
drivers/core/uclass.c +2 -2
@@ -56,8 +56,8 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp) *ucp =NULL ; uc_drv =lists_uclass_lookup (id);if (!uc_drv) { -debug ("Cannot find uclass for id %d: please add the UCLASS_DRIVER() declaration for this UCLASS_... id\n" , - id); +printf ("Cannot find uclass for id %d: please add the UCLASS_DRIVER() declaration for this UCLASS_... id\n" , + id);/* * Use a strange error to make this case easier to find. When * a uclass is not available it can prevent driver model from
drivers/misc/Makefile +2 -0
@@ -10,8 +10,10 @@ obj-$(CONFIG_$(SPL_TPL_)CROS_EC_SANDBOX) += cros_ec_sandbox.o obj-$(CONFIG_$(SPL_TPL_)CROS_EC_LPC) += cros_ec_lpc.o ifndef CONFIG_SPL_BUILD +obj-$(CONFIG_SANDBOX) += sandbox_adder.o obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o +obj-$(CONFIG_SANDBOX) += p2sb_sandbox.o p2sb_emul.o obj-$(CONFIG_SANDBOX) += swap_case.o endif
drivers/misc/p2sb_emul.c new file +272 -0
272 lines not on this page · raw message
drivers/misc/p2sb_sandbox.c new file +44 -0
44 lines not on this page · raw message
drivers/misc/sandbox_adder.c new file +60 -0
60 lines not on this page · raw message
test/dm/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-y += ofnode.o obj-$(CONFIG_OSD) += osd.o obj-$(CONFIG_DM_VIDEO) += panel.o obj-$(CONFIG_DM_PCI) += pci.o +obj-$(CONFIG_P2SB) += p2sb.o obj-$(CONFIG_PCI_ENDPOINT) += pci_ep.o obj-$(CONFIG_PCH) += pch.o obj-$(CONFIG_PHY) += phy.o
test/dm/p2sb.c new file +28 -0
@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Test for Primary-to-Sideband bus (P2SB) +* +* Copyright 2019 Google LLC +*/ + +#include <common.h> +#include <dm.h> +#include <p2sb.h> +#include <asm/test.h> +#include <dm/test.h> +#include <test/ut.h> + +/* Base test of the PMC uclass */ +static int dm_test_p2sb_base (struct unit_test_state *uts) +{ +struct udevice *dev; + +sandbox_set_enable_memio (true); +ut_assertok (uclass_get_device_by_name (UCLASS_AXI ,"adder" , &dev)); +ut_asserteq (0x03000004 ,pcr_read32 (dev,4 )); +ut_asserteq (0x300 ,pcr_read16 (dev,6 )); +ut_asserteq (4 ,pcr_read8 (dev,4 )); + +return 0 ; +} +DM_TEST (dm_test_p2sb_base,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 37/108 sandbox: Add PCI driver and test for p2sb
Hi Simon,
Quoted 37 lines · Simon Glass
Add a sandbox driver and PCI-device emulator for p2sb. Also add a test which uses a simple 'adder' driver to test the p2sb functionality.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Fix build errors insandbox_spl, etcChanges in v2: None
arch/sandbox/cpu/state.c | 1 + arch/sandbox/dts/test.dts | 13 ++ arch/sandbox/include/asm/test.h | 10 ++ configs/sandbox64_defconfig | 2 + configs/sandbox_flattree_defconfig | 3 + configs/sandbox_spl_defconfig | 2 + configs/tools-only_defconfig | 2 + drivers/core/uclass.c | 4 +- drivers/misc/Makefile | 2 + drivers/misc/p2sb_emul.c | 272 +++++++++++++++++++++++++++++ drivers/misc/p2sb_sandbox.c | 44 +++++ drivers/misc/sandbox_adder.c | 60 +++++++ test/dm/Makefile | 1 + test/dm/p2sb.c | 28 +++ 14 files changed, 442 insertions(+), 2 deletions(-) create mode 100644 drivers/misc/p2sb_emul.c create mode 100644 drivers/misc/p2sb_sandbox.c create mode 100644 drivers/misc/sandbox_adder.c create mode 100644 test/dm/p2sb.carch/sandbox/cpu/state.c +0
-0
arch/sandbox/cpu/state.c void state_reset_for_test(struct sandbox_state *state) · line 359
Quoted 4 lines
arch/sandbox/cpu/state.c +1
-0@@ -356,6 +356,7 @@ void state_reset_for_test(struct sandbox_state *state)/* No reset yet, so mark it as such. Always allow power reset */ state->last_sysreset =SYSRESET_COUNT ; state->sysreset_allowed[SYSRESET_POWER_OFF ] = true; + state->allow_memio = false;
A separate patch?
Quoted 49 lines
arch/sandbox/cpu/state.c +0
-0memset (&state->wdt,'\0' ,sizeof (state->wdt));memset (state->spi,'\0' ,sizeof (state->spi));arch/sandbox/dts/test.dts +13
-0@@ -467,6 +467,16 @@ 0x01000810 0 0 0 0>; sandbox,emul = <&swap_case_emul0_1>; }; + p2sb-pci at 2,0 { + compatible = "sandbox,p2sb"; + reg = <0x02001010 0 0 0 0>; + sandbox,emul = <&p2sb_emul>; + + adder { + intel,p2sb-port-id = <3>; + compatible = "sandbox,adder"; + }; + }; pci at 1e,0 { compatible = "sandbox,pmc"; reg = <0xf000 0 0 0 0>;@@ -498,6 +508,9 @@ swap_case_emul0_1f: emul0 at 1f,0 { compatible = "sandbox,swap-case"; }; + p2sb_emul: emul at 2,0 { + compatible = "sandbox,p2sb-emul"; + }; pmc_emul1e: emul at 1e,0 { compatible = "sandbox,pmc-emul"; };arch/sandbox/include/asm/test.h +1
-0@@ -14,6 +14,7 @@#define SANDBOX_PCI_VENDOR_ID 0x1234#define SANDBOX_PCI_SWAP_CASE_EMUL_ID 0x5678#define SANDBOX_PCI_PMC_EMUL_ID 0x5677 +#define SANDBOX_PCI_P2SB_EMUL_ID 0x5676#define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM#define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL@@ -214,4 +215,13 @@ int sandbox_get_pci_ep_irq_count(struct udevice *dev);*/ uint sandbox_pci_read_bar (u32 barval,int type,uint size);
arch/sandbox/include/asm/test.h int sandbox_get_pci_ep_irq_count(struct udevice *dev); · line 226
Quoted 10 lines
arch/sandbox/include/asm/test.h +9
-0+/** +* sandbox_set_enable_memio() - Enable memory-mapped I/O read/write +* +* Normally readl(), writel() and the like are nops on sandbox. If this function +* is called with true, those function do real memory accesses. This is useful +* for certain tests. +*/ +void sandbox_set_enable_memio (bool enable); +
A separate patch?
Quoted 66 lines
arch/sandbox/include/asm/test.h +0
-0#endif configs/sandbox64_defconfig +2
-0@@ -81,6 +81,8 @@ CONFIG_DEVRES=y CONFIG_DEBUG_DEVRES=y CONFIG_ADC=y CONFIG_ADC_SANDBOX=y +CONFIG_AXI=y +CONFIG_AXI_SANDBOX=y CONFIG_CLK=y CONFIG_CPU=y CONFIG_DM_DEMO=yconfigs/sandbox_flattree_defconfig +3
-0@@ -65,6 +65,8 @@ CONFIG_DEVRES=y CONFIG_DEBUG_DEVRES=y CONFIG_ADC=y CONFIG_ADC_SANDBOX=y +CONFIG_AXI=y +CONFIG_AXI_SANDBOX=y CONFIG_CLK=y CONFIG_CLK_COMPOSITE_CCF=y CONFIG_SANDBOX_CLK_CCF=y@@ -116,6 +118,7 @@ CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_P2SB=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=yconfigs/sandbox_spl_defconfig +2
-0@@ -86,6 +86,8 @@ CONFIG_DEBUG_DEVRES=y # CONFIG_SPL_SIMPLE_BUS is not set CONFIG_ADC=y CONFIG_ADC_SANDBOX=y +CONFIG_AXI=y +CONFIG_AXI_SANDBOX=y CONFIG_CLK=y CONFIG_CPU=y CONFIG_DM_DEMO=yconfigs/tools-only_defconfig +2
-0@@ -11,6 +11,8 @@ CONFIG_OF_HOSTFILE=y CONFIG_DEFAULT_DEVICE_TREE="sandbox" CONFIG_IP_DEFRAG=y # CONFIG_UDP_FUNCTION_FASTBOOT is not set +CONFIG_AXI=y +CONFIG_AXI_SANDBOX=y CONFIG_SANDBOX_GPIO=y CONFIG_PCI=y CONFIG_DM_PCI=ydrivers/core/uclass.c +0
-0
drivers/core/uclass.c static int uclass_add(enum uclass_id id, struct uclass **ucp) · line 60
Quoted 7 lines
drivers/core/uclass.c +2
-2@@ -56,8 +56,8 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp) *ucp =NULL ; uc_drv =lists_uclass_lookup (id);if (!uc_drv) { -debug ("Cannot find uclass for id %d: please add the UCLASS_DRIVER() declaration for this UCLASS_... id\n" , - id); +printf ("Cannot find uclass for id %d: please add the UCLASS_DRIVER() declaration for this UCLASS_... id\n" , + id);
Looks unrelated to this patch.
Quoted 322 lines
drivers/core/uclass.c +0
-0/* * Use a strange error to make this case easier to find. When * a uclass is not available it can prevent driver model from drivers/misc/Makefile +2
-0@@ -10,8 +10,10 @@ obj-$(CONFIG_$(SPL_TPL_)CROS_EC_SANDBOX) += cros_ec_sandbox.o obj-$(CONFIG_$(SPL_TPL_)CROS_EC_LPC) += cros_ec_lpc.o ifndef CONFIG_SPL_BUILD +obj-$(CONFIG_SANDBOX) += sandbox_adder.o obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o +obj-$(CONFIG_SANDBOX) += p2sb_sandbox.o p2sb_emul.o obj-$(CONFIG_SANDBOX) += swap_case.o endifdrivers/misc/p2sb_emul.c new file +272
-0@@ -0,0 +1,272 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* PCI emulation device for an x86 Primary-to-Sideband bus +* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#define LOG_CATEGORY UCLASS_MISC +#define LOG_DEBUG + +#include <common.h> +#include <axi.h> +#include <dm.h> +#include <pci.h> +#include <asm/test.h> +#include <p2sb.h> + +/** +* struct p2sb_emul_platdata - platform data for this device +* +* @command: Current PCI command value +* @bar: Current base address values +*/ +struct p2sb_emul_platdata { +u16 command; +u32 bar[6 ]; +}; + +enum { +/* This emulator supports 16 different devices */ +MEMMAP_SIZE =16 <<PCR_PORTID_SHIFT , +}; + +static struct pci_bar { +int type; +u32 size; +} barinfo[] = { + {PCI_BASE_ADDRESS_MEM_TYPE_32 ,MEMMAP_SIZE }, + {0 ,0 }, + {0 ,0 }, + {0 ,0 }, + {0 ,0 }, + {0 ,0 }, +}; + +struct p2sb_emul_priv { +u8 regs[16 ]; +}; + +static int sandbox_p2sb_emul_read_config (struct udevice *emul,uint offset, +ulong *valuep,enum pci_size_t size) +{ +struct p2sb_emul_platdata *plat =dev_get_platdata (emul); + +switch (offset) { +case PCI_COMMAND : + *valuep = plat->command; +break ; +case PCI_HEADER_TYPE : + *valuep =PCI_HEADER_TYPE_NORMAL ; +break ; +case PCI_VENDOR_ID : + *valuep =SANDBOX_PCI_VENDOR_ID ; +break ; +case PCI_DEVICE_ID : + *valuep =SANDBOX_PCI_P2SB_EMUL_ID ; +break ; +case PCI_CLASS_DEVICE : +if (size ==PCI_SIZE_8 ) { + *valuep =SANDBOX_PCI_CLASS_SUB_CODE ; + }else { + *valuep = (SANDBOX_PCI_CLASS_CODE <<8 ) | +SANDBOX_PCI_CLASS_SUB_CODE ; + } +break ; +case PCI_CLASS_CODE : + *valuep =SANDBOX_PCI_CLASS_CODE ; +break ; +case PCI_BASE_ADDRESS_0 : +case PCI_BASE_ADDRESS_1 : +case PCI_BASE_ADDRESS_2 : +case PCI_BASE_ADDRESS_3 : +case PCI_BASE_ADDRESS_4 : +case PCI_BASE_ADDRESS_5 : { +int barnum; +u32 *bar; + + barnum =pci_offset_to_barnum (offset); + bar = &plat->bar[barnum]; + + *valuep =sandbox_pci_read_bar (*bar, barinfo[barnum].type, + barinfo[barnum].size); +break ; + } +case PCI_CAPABILITY_LIST : + *valuep =PCI_CAP_ID_PM_OFFSET ; +break ; + } + +return 0 ; +} + +static int sandbox_p2sb_emul_write_config (struct udevice *emul,uint offset, +ulong value,enum pci_size_t size) +{ +struct p2sb_emul_platdata *plat =dev_get_platdata (emul); + +switch (offset) { +case PCI_COMMAND : + plat->command = value; +break ; +case PCI_BASE_ADDRESS_0 : +case PCI_BASE_ADDRESS_1 : { +int barnum; +u32 *bar; + + barnum =pci_offset_to_barnum (offset); + bar = &plat->bar[barnum]; + +log_debug ("w bar %d=%lx\n" , barnum, value); + *bar = value; +/* space indicator (bit#0) is read-only */ + *bar |= barinfo[barnum].type; +break ; + } + } + +return 0 ; +} + +static int sandbox_p2sb_emul_find_bar (struct udevice *emul,unsigned int addr, +int *barnump,unsigned int *offsetp) +{ +struct p2sb_emul_platdata *plat =dev_get_platdata (emul); +int barnum; + +for (barnum =0 ; barnum <ARRAY_SIZE (barinfo); barnum++) { +unsigned int size = barinfo[barnum].size; +u32 base = plat->bar[barnum] & ~PCI_BASE_ADDRESS_SPACE ; + +if (addr >= base && addr < base + size) { + *barnump = barnum; + *offsetp = addr - base; +return 0 ; + } + } + *barnump =-1 ; + +return -ENOENT ; +} + +static int sandbox_p2sb_emul_read_io (struct udevice *dev,unsigned int addr, +ulong *valuep,enum pci_size_t size) +{ +unsigned int offset; +int barnum; +int ret; + + ret =sandbox_p2sb_emul_find_bar (dev, addr, &barnum, &offset); +if (ret) +return ret; + +if (barnum ==4 ) + *valuep = offset; +else if (barnum ==0 ) + *valuep = offset; + +return 0 ; +} + +static int sandbox_p2sb_emul_write_io (struct udevice *dev,unsigned int addr, +ulong value,enum pci_size_t size) +{ +unsigned int offset; +int barnum; +int ret; + + ret =sandbox_p2sb_emul_find_bar (dev, addr, &barnum, &offset); +if (ret) +return ret; + +return 0 ; +} + +static int find_p2sb_channel (struct udevice *emul,uint offset, +struct udevice **devp) +{ +uint pid = offset >>PCR_PORTID_SHIFT ; +struct udevice *p2sb, *dev; +int ret; + + ret =sandbox_pci_get_client (emul, &p2sb); +if (ret) +return log_msg_ret ("No client" , ret); + + device_foreach_child(dev, p2sb) { +struct p2sb_child_platdata *pplat = +dev_get_parent_platdata (dev); + +log_debug (" - child %s, pid %d, want %d\n" , dev->name, + pplat->pid, pid); +if (pid == pplat->pid) { + *devp = dev; +return 0 ; + } + } + +return -ENOENT ; +} + +static int sandbox_p2sb_emul_map_physmem (struct udevice *dev, +phys_addr_t addr,unsigned long *lenp, +void **ptrp) +{ +struct p2sb_emul_priv *priv =dev_get_priv (dev); +struct udevice *child; +unsigned int offset; +int barnum; +int ret; + +log_debug ("map %x: " , (uint )addr); + ret =sandbox_p2sb_emul_find_bar (dev, addr, &barnum, &offset); +if (ret) +return log_msg_ret ("Cannot find bar" , ret); +log_debug ("bar %d, offset %x\n" , barnum, offset); + +if (barnum !=0 ) +return log_msg_ret ("Unknown BAR" , -EINVAL ); + + ret =find_p2sb_channel (dev, offset, &child); +if (ret) +return log_msg_ret ("Cannot find channel" , ret); + + offset &= ((1 <<PCR_PORTID_SHIFT ) -1 ); + ret =axi_read (child, offset, priv->regs,AXI_SIZE_32 ); +if (ret) +return log_msg_ret ("Child read failed" , ret); + *ptrp = priv->regs + (offset &3 ); + *lenp =4 ; + +return 0 ; +} + +static struct dm_pci_emul_ops sandbox_p2sb_emul_emul_ops = { + .read_config = sandbox_p2sb_emul_read_config, + .write_config = sandbox_p2sb_emul_write_config, + .read_io = sandbox_p2sb_emul_read_io, + .write_io = sandbox_p2sb_emul_write_io, + .map_physmem = sandbox_p2sb_emul_map_physmem, +}; + +static const struct udevice_id sandbox_p2sb_emul_ids[] = { + { .compatible ="sandbox,p2sb-emul" }, + { } +}; + +U_BOOT_DRIVER (sandbox_p2sb_emul_emul) = { + .name ="sandbox_p2sb_emul_emul" , + .id =UCLASS_PCI_EMUL , + .of_match = sandbox_p2sb_emul_ids, + .ops = &sandbox_p2sb_emul_emul_ops, + .priv_auto_alloc_size =sizeof (struct p2sb_emul_priv ), + .platdata_auto_alloc_size =sizeof (struct p2sb_emul_platdata ), +}; + +static struct pci_device_id sandbox_p2sb_emul_supported[] = { + {PCI_VDEVICE (SANDBOX ,SANDBOX_PCI_PMC_EMUL_ID ) }, + {}, +}; + +U_BOOT_PCI_DEVICE (sandbox_p2sb_emul_emul, sandbox_p2sb_emul_supported);drivers/misc/p2sb_sandbox.c new file +20
-0@@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Sandbox P2SB for testing +* +* Copyright 2019 Google LLC +*/ + +#define LOG_CATEGORY UCLASS_P2SB + +#include <common.h> +#include <dm.h> +#include <asm/io.h> +#include <p2sb.h> + +struct sandbox_p2sb_priv { +ulong base; +}; + +static int sandbox_p2sb_probe (struct udevice *dev) +{
drivers/misc/p2sb_sandbox.c line 30
Quoted 10 lines
drivers/misc/p2sb_sandbox.c new file +10
-0+struct p2sb_uc_priv *upriv =dev_get_uclass_priv (dev); + + upriv->mmio_base =dm_pci_read_bar32 (dev,0 ); +printf ("mmio base %x\n" , upriv->mmio_base); + +return 0 ; +} + +static struct p2sb_ops sandbox_p2sb_ops = { +};
Could this be dropped, since it's an empty struct?
drivers/misc/p2sb_sandbox.c line 38
Quoted 8 lines
drivers/misc/p2sb_sandbox.c new file +8
-0+ +static const struct udevice_id sandbox_p2sb_ids[] = { + { .compatible ="sandbox,p2sb" }, + { } +}; + +U_BOOT_DRIVER (p2sb_sandbox) = { + .name ="pmic_pm8916" ,
The name does not look correct.
Quoted 109 lines
drivers/misc/p2sb_sandbox.c new file +6
-0+ .id = UCLASS_P2SB, + .of_match = sandbox_p2sb_ids, + .probe = sandbox_p2sb_probe, + .ops = &sandbox_p2sb_ops, + .priv_auto_alloc_size = sizeof(struct sandbox_p2sb_priv), +};drivers/misc/sandbox_adder.c new file +60
-0@@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Sandbox adder for p2sb testing +* +* Copyright 2019 Google LLC +*/ + +#define LOG_CATEGORY UCLASS_MISC + +#include <common.h> +#include <axi.h> +#include <dm.h> +#include <misc.h> +#include <p2sb.h> +#include <asm/io.h> + +struct sandbox_adder_priv { +ulong base; +}; + +int sandbox_adder_read (struct udevice *dev,ulong address,void *data, +enum axi_size_t size) +{ +struct p2sb_child_platdata *pplat =dev_get_parent_platdata (dev); +u32 *val = data; + + *val = pplat->pid <<24 | address; + +return 0 ; +} + +int sandbox_adder_write (struct udevice *dev,ulong address,void *data, +enum axi_size_t size) +{ +return 0 ; +} + +static int sandbox_adder_probe (struct udevice *dev) +{ +return 0 ; +} + +static struct axi_ops sandbox_adder_ops = { + .read = sandbox_adder_read, + .write = sandbox_adder_write, +}; + +static const struct udevice_id sandbox_adder_ids[] = { + { .compatible ="sandbox,adder" }, + { } +}; + +U_BOOT_DRIVER (adder_sandbox) = { + .name ="sandbox_adder" , + .id =UCLASS_AXI , + .of_match = sandbox_adder_ids, + .probe = sandbox_adder_probe, + .ops = &sandbox_adder_ops, + .priv_auto_alloc_size =sizeof (struct sandbox_adder_priv ), +};test/dm/Makefile +1
-0@@ -32,6 +32,7 @@ obj-y += ofnode.o obj-$(CONFIG_OSD) += osd.o obj-$(CONFIG_DM_VIDEO) += panel.o obj-$(CONFIG_DM_PCI) += pci.o +obj-$(CONFIG_P2SB) += p2sb.o obj-$(CONFIG_PCI_ENDPOINT) += pci_ep.o obj-$(CONFIG_PCH) += pch.o obj-$(CONFIG_PHY) += phy.otest/dm/p2sb.c new file +19
-0@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Test for Primary-to-Sideband bus (P2SB) +* +* Copyright 2019 Google LLC +*/ + +#include <common.h> +#include <dm.h> +#include <p2sb.h> +#include <asm/test.h> +#include <dm/test.h> +#include <test/ut.h> + +/* Base test of the PMC uclass */ +static int dm_test_p2sb_base (struct unit_test_state *uts) +{ +struct udevice *dev; +
test/dm/p2sb.c
Quoted 10 lines
test/dm/p2sb.c new file +9
-1+sandbox_set_enable_memio (true); +ut_assertok (uclass_get_device_by_name (UCLASS_AXI ,"adder" , &dev)); +ut_asserteq (0x03000004 ,pcr_read32 (dev,4 )); +ut_asserteq (0x300 ,pcr_read16 (dev,6 )); +ut_asserteq (4 ,pcr_read8 (dev,4 )); + +return 0 ; +} +DM_TEST (dm_test_p2sb_base,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); --
Regards,
Bin
PATCH v3 38/108 x86: Move UCLASS_IRQ into a separate file
In reply to Simon GlassUpdate this uclass to support the needs of the apollolake ITSS. It supports four operations.
Move the uclass into a separate directory so that sandbox can use it too. Add a new Kconfig to control it and enable this on x86.
---
Changes in v3:
- Add two more operations to IRQ
- Use the IRQ uclass instead of creating a new ITSS uclass
Changes in v2: None
arch/Kconfig | 1 + arch/x86/cpu/irq.c | 5 --- drivers/misc/Kconfig | 9 ++++ drivers/misc/Makefile | 2 + drivers/misc/irq-uclass.c | 53 +++++++++++++++++++++++ include/irq.h | 88 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 drivers/misc/irq-uclass.c create mode 100644 include/irq.h
arch/Kconfig +1 -0
@@ -186,6 +186,7 @@ config X86 imply USB_HOST_ETHER imply PCH imply RTC_MC146818 + imply IRQ # Thing to enable for when SPL/TPL are enabled: SPL imply SPL_DM
arch/x86/cpu/irq.c +0 -5
@@ -370,8 +370,3 @@ U_BOOT_DRIVER(irq_router_drv) = { .probe = irq_router_probe, .priv_auto_alloc_size = sizeof(struct irq_router), }; - -UCLASS_DRIVER (irq) = { - .id =UCLASS_IRQ , - .name ="irq" , -};
drivers/misc/Kconfig +9 -0
@@ -194,6 +194,15 @@ config FSL_SEC_MON Security Monitor can be transitioned on any security failures, like software violations or hardware security violations. +config IRQ + bool "Intel Interrupt controller" + depends on X86 || SANDBOX + help + This enabled support for Intel interrupt controllers, including ITSS. + Some devices have extra features, such as apollolake. The + device has its own uclass since there are several operations + involved. + config JZ4780_EFUSE bool "Ingenic JZ4780 eFUSE support" depends on ARCH_JZ47XX
drivers/misc/Makefile +2 -0
@@ -41,9 +41,11 @@ obj-$(CONFIG_FS_LOADER) += fs_loader.o obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o obj-$(CONFIG_GDSYS_SOC) += gdsys_soc.o +obj-$(CONFIG_IRQ) += irq-uclass.o obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o obj-$(CONFIG_IHS_FPGA) += ihs_fpga.o obj-$(CONFIG_IMX8) += imx8/ +obj-$(CONFIG_ITSS) += itss-uclass.o obj-$(CONFIG_LED_STATUS) += status_led.o obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o obj-$(CONFIG_MPC83XX_SERDES) += mpc83xx_serdes.o
drivers/misc/irq-uclass.c new file +53 -0
53 lines not on this page · raw message
include/irq.h new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 38/108 x86: Move UCLASS_IRQ into a separate file
Hi Simon,
Quoted 56 lines · Simon Glass
Update this uclass to support the needs of the apollolake ITSS. It supports four operations.
Move the uclass into a separate directory so that sandbox can use it too. Add a new
Kconfigto control it and enable this on x86.Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Add two more operations to IRQ
- Use the IRQ uclass instead of creating a new ITSS uclassChanges in v2: None
arch/Kconfig | 1 + arch/x86/cpu/irq.c | 5 --- drivers/misc/Kconfig | 9 ++++ drivers/misc/Makefile | 2 + drivers/misc/irq-uclass.c | 53 +++++++++++++++++++++++ include/irq.h | 88 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 drivers/misc/irq-uclass.c create mode 100644 include/irq.harch/Kconfig +1
-0@@ -186,6 +186,7 @@ config X86 imply USB_HOST_ETHER imply PCH imply RTC_MC146818 + imply IRQ # Thing to enable for when SPL/TPL are enabled: SPL imply SPL_DMarch/x86/cpu/irq.c +0
-5@@ -370,8 +370,3 @@ U_BOOT_DRIVER(irq_router_drv) = { .probe = irq_router_probe, .priv_auto_alloc_size = sizeof(struct irq_router), }; - -UCLASS_DRIVER (irq) = { - .id =UCLASS_IRQ , - .name ="irq" , -};drivers/misc/Kconfig +0
-0
drivers/misc/Kconfig config FSL_SEC_MON · line 201
Quoted 8 lines
drivers/misc/Kconfig +5
-0@@ -194,6 +194,15 @@ config FSL_SEC_MON Security Monitor can be transitioned on any security failures, like software violations or hardware security violations. +config IRQ + bool "Intel Interrupt controller" + depends on X86 || SANDBOX + help + This enabled support for Intel interrupt controllers, including ITSS.
nits: enables
Quoted 12 lines
drivers/misc/Kconfig +4
-0+ Some devices have extra features, such as apollolake. The + device has its own uclass since there are several operations + involved. + config JZ4780_EFUSE bool "Ingenic JZ4780 eFUSE support" depends on ARCH_JZ47XXdrivers/misc/Makefile +0
-0
drivers/misc/Makefile obj-$(CONFIG_FS_LOADER) += fs_loader.o · line 48
Quoted 8 lines
drivers/misc/Makefile +2
-0@@ -41,9 +41,11 @@ obj-$(CONFIG_FS_LOADER) += fs_loader.o obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o obj-$(CONFIG_GDSYS_SOC) += gdsys_soc.o +obj-$(CONFIG_IRQ) += irq-uclass.o obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o obj-$(CONFIG_IHS_FPGA) += ihs_fpga.o obj-$(CONFIG_IMX8) += imx8/ +obj-$(CONFIG_ITSS) += itss-uclass.o
This should be dropped
Quoted 147 lines
drivers/misc/Makefile +0
-0obj-$(CONFIG_LED_STATUS) += status_led.o obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o obj-$(CONFIG_MPC83XX_SERDES) += mpc83xx_serdes.odrivers/misc/irq-uclass.c new file +53
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2015, Bin Meng <[email protected]> +*/ + +#include <common.h> +#include <dm.h> +#include <irq.h> + +int irq_route_pmc_gpio_gpe (struct udevice *dev,uint pmc_gpe_num) +{ +const struct irq_ops *ops =irq_get_ops (dev); + +if (!ops->route_pmc_gpio_gpe) +return -ENOSYS ; + +return ops->route_pmc_gpio_gpe (dev, pmc_gpe_num); +} + +int irq_set_polarity (struct udevice *dev,uint irq,bool active_low) +{ +const struct irq_ops *ops =irq_get_ops (dev); + +if (!ops->set_polarity) +return -ENOSYS ; + +return ops->set_polarity (dev, irq, active_low); +} + +int irq_snapshot_polarities (struct udevice *dev) +{ +const struct irq_ops *ops =irq_get_ops (dev); + +if (!ops->snapshot_polarities) +return -ENOSYS ; + +return ops->snapshot_polarities (dev); +} + +int irq_restore_polarities (struct udevice *dev) +{ +const struct irq_ops *ops =irq_get_ops (dev); + +if (!ops->restore_polarities) +return -ENOSYS ; + +return ops->restore_polarities (dev); +} + +UCLASS_DRIVER (irq) = { + .id =UCLASS_IRQ , + .name ="irq" , +};include/irq.h new file +79
-0@@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* IRQ is a type of interrupt controller used on recent Intel SoC. +* +* Copyright 2019 Google LLC +*/ + +#ifndef __irq_H +#define __irq_H + +/** +* struct irq_ops - Operations for the IRQ +*/ +struct irq_ops { +/** +* route_pmc_gpio_gpe() - Get the GPIO for an event +* +* @dev: IRQ device +* @pmc_gpe_num: Event number to check +* @returns GPIO for the event, or -ENOENT if none +*/ +int (*route_pmc_gpio_gpe)(struct udevice *dev,uint pmc_gpe_num); + +/** +* set_polarity() - Set the IRQ polarity +* +* @dev: IRQ device +* @irq: Interrupt number to set +* @active_low: true if active low, false for active high +* @return 0 if OK, -EINVAL if @irq is invalid +*/ +int (*set_polarity)(struct udevice *dev,uint irq,bool active_low); + +/** +* snapshot_polarities() - record IRQ polarities for later restore +* +* @dev: IRQ device +* @return 0 +*/ +int (*snapshot_polarities)(struct udevice *dev); + +/** +* restore_polarities() - restore IRQ polarities +* +* @dev: IRQ device +* @return 0 +*/ +int (*restore_polarities)(struct udevice *dev); +}; + +#define irq_get_ops (dev) ((struct irq_ops *)(dev)->driver->ops) + +/** +* irq_route_pmc_gpio_gpe() - Get the GPIO for an event +* +* @dev: IRQ device +* @pmc_gpe_num: Event number to check +* @returns GPIO for the event, or -ENOENT if none +*/ +int irq_route_pmc_gpio_gpe (struct udevice *dev,uint pmc_gpe_num); + +/** +* irq_set_polarity() - Set the IRQ polarity +* +* @dev: IRQ device +* @irq: Interrupt number to set +* @active_low: true if active low, false for active high +* @return 0 if OK, -EINVAL if @irq is invalid +*/ +int irq_set_polarity (struct udevice *dev,uint irq,bool active_low); + +/** +* irq_snapshot_polarities() - record IRQ polarities for later restore +* +* @dev: IRQ device +* @return 0 +*/ +int irq_snapshot_polarities (struct udevice *dev); +
include/irq.h
Quoted 10 lines
include/irq.h new file +9
-1+/** +* irq_restore_polarities() - restore IRQ polarities +* +* @dev: IRQ device +* @return 0 +*/ +int irq_restore_polarities (struct udevice *dev); + +#endif --
Regards,
Bin
PATCH v3 39/108 sandbox: Add a test for IRQ
In reply to Simon GlassAdd a simple sandbox test for this uclass.
---
Changes in v3:
- Change the sandbox test from ITSS to IRQ
Changes in v2: None
arch/sandbox/dts/test.dts | 4 +++ configs/sandbox_defconfig | 3 +- configs/sandbox_flattree_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + drivers/misc/Makefile | 2 +- drivers/misc/irq_sandbox.c | 55 ++++++++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/irq.c | 32 +++++++++++++++++ 8 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 drivers/misc/irq_sandbox.c create mode 100644 test/dm/irq.c
arch/sandbox/dts/test.dts +4 -0
@@ -349,6 +349,10 @@ vss-microvolts = <0>; }; + irq { + compatible = "sandbox,irq"; + }; + lcd { u-boot,dm-pre-reloc; compatible = "sandbox,lcd-sdl";
configs/sandbox_defconfig +2 -1
@@ -130,6 +130,8 @@ CONFIG_CROS_EC_I2C=y CONFIG_CROS_EC_LPC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_SPI=y +CONFIG_IRQ=y +CONFIG_P2SB=y CONFIG_PWRSEQ=y CONFIG_SPL_PWRSEQ=y CONFIG_I2C_EEPROM=y
@@ -150,7 +152,6 @@ CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y -CONFIG_P2SB=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=y
configs/sandbox_flattree_defconfig +1 -0
@@ -98,6 +98,7 @@ CONFIG_CROS_EC_I2C=y CONFIG_CROS_EC_LPC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_SPI=y +CONFIG_IRQ=y CONFIG_PWRSEQ=y CONFIG_SPL_PWRSEQ=y CONFIG_I2C_EEPROM=y
configs/sandbox_spl_defconfig +1 -0
@@ -118,6 +118,7 @@ CONFIG_CROS_EC_I2C=y CONFIG_CROS_EC_LPC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_SPI=y +CONFIG_IRQ=y CONFIG_PWRSEQ=y CONFIG_SPL_PWRSEQ=y CONFIG_MMC_SANDBOX=y
drivers/misc/Makefile +1 -1
@@ -42,10 +42,10 @@ obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o obj-$(CONFIG_GDSYS_SOC) += gdsys_soc.o obj-$(CONFIG_IRQ) += irq-uclass.o +obj-$(CONFIG_SANDBOX) += irq_sandbox.o obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o obj-$(CONFIG_IHS_FPGA) += ihs_fpga.o obj-$(CONFIG_IMX8) += imx8/ -obj-$(CONFIG_ITSS) += itss-uclass.o obj-$(CONFIG_LED_STATUS) += status_led.o obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o obj-$(CONFIG_MPC83XX_SERDES) += mpc83xx_serdes.o
drivers/misc/irq_sandbox.c new file +55 -0
55 lines not on this page · raw message
test/dm/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_DM_GPIO) += gpio.o obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o obj-$(CONFIG_DM_I2C) += i2c.o obj-$(CONFIG_SOUND) += i2s.o +obj-y += irq.o obj-$(CONFIG_LED) += led.o obj-$(CONFIG_DM_MAILBOX) += mailbox.o obj-$(CONFIG_DM_MMC) += mmc.o
test/dm/irq.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Test for irq uclass +* +* Copyright 2019 Google LLC +*/ + +#include <common.h> +#include <dm.h> +#include <irq.h> +#include <dm/test.h> +#include <test/ut.h> + +/* Base test of the irq uclass */ +static int dm_test_irq_base (struct unit_test_state *uts) +{ +struct udevice *dev; + +ut_assertok (uclass_first_device_err (UCLASS_IRQ , &dev)); + +ut_asserteq (5 ,irq_route_pmc_gpio_gpe (dev,4 )); +ut_asserteq (-ENOENT ,irq_route_pmc_gpio_gpe (dev,14 )); + +ut_assertok (irq_set_polarity (dev,4 , true)); +ut_asserteq (-EINVAL ,irq_set_polarity (dev,14 , true)); + +ut_assertok (irq_snapshot_polarities (dev)); +ut_assertok (irq_restore_polarities (dev)); + +return 0 ; +} +DM_TEST (dm_test_irq_base,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 39/108 sandbox: Add a test for IRQ
Hi Simon,
Quoted 52 lines · Simon Glass
Add a simple sandbox test for this uclass.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Change the sandbox test from ITSS to IRQChanges in v2: None
arch/sandbox/dts/test.dts | 4 +++ configs/sandbox_defconfig | 3 +- configs/sandbox_flattree_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + drivers/misc/Makefile | 2 +- drivers/misc/irq_sandbox.c | 55 ++++++++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/irq.c | 32 +++++++++++++++++ 8 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 drivers/misc/irq_sandbox.c create mode 100644 test/dm/irq.carch/sandbox/dts/test.dts +4
-0@@ -349,6 +349,10 @@ vss-microvolts = <0>; }; + irq { + compatible = "sandbox,irq"; + }; + lcd { u-boot,dm-pre-reloc; compatible = "sandbox,lcd-sdl";configs/sandbox_defconfig +2
-0@@ -130,6 +130,8 @@ CONFIG_CROS_EC_I2C=y CONFIG_CROS_EC_LPC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_SPI=y +CONFIG_IRQ=y +CONFIG_P2SB=y CONFIG_PWRSEQ=y CONFIG_SPL_PWRSEQ=y CONFIG_I2C_EEPROM=y
configs/sandbox_defconfig CONFIG_PCI=y · line 153
Quoted 4 lines
configs/sandbox_defconfig +0
-1@@ -150,7 +152,6 @@ CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y -CONFIG_P2SB=y
Instead of adjusting P2SB order here, please update previous patch to insert P2SB to the right place, then this patch should only touch CONFIG_IRQ.
Quoted 32 lines
configs/sandbox_defconfig +0
-0CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=yconfigs/sandbox_flattree_defconfig +1
-0@@ -98,6 +98,7 @@ CONFIG_CROS_EC_I2C=y CONFIG_CROS_EC_LPC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_SPI=y +CONFIG_IRQ=y CONFIG_PWRSEQ=y CONFIG_SPL_PWRSEQ=y CONFIG_I2C_EEPROM=yconfigs/sandbox_spl_defconfig +1
-0@@ -118,6 +118,7 @@ CONFIG_CROS_EC_I2C=y CONFIG_CROS_EC_LPC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_SPI=y +CONFIG_IRQ=y CONFIG_PWRSEQ=y CONFIG_SPL_PWRSEQ=y CONFIG_MMC_SANDBOX=ydrivers/misc/Makefile +0
-0
drivers/misc/Makefile obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o · line 48
Quoted 8 lines
drivers/misc/Makefile +1
-1@@ -42,10 +42,10 @@ obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o obj-$(CONFIG_GDSYS_SOC) += gdsys_soc.o obj-$(CONFIG_IRQ) += irq-uclass.o +obj-$(CONFIG_SANDBOX) += irq_sandbox.o obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o obj-$(CONFIG_IHS_FPGA) += ihs_fpga.o obj-$(CONFIG_IMX8) += imx8/ -obj-$(CONFIG_ITSS) += itss-uclass.o
This should be dropped in previous patch.
Quoted 105 lines
drivers/misc/Makefile +0
-0obj-$(CONFIG_LED_STATUS) += status_led.o obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o obj-$(CONFIG_MPC83XX_SERDES) += mpc83xx_serdes.odrivers/misc/irq_sandbox.c new file +55
-0@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Sandbox driver for interrupts +* +* Copyright 2019 Google LLC +*/ + +#include <common.h> +#include <dm.h> +#include <irq.h> + +static int sandbox_set_polarity (struct udevice *dev,uint irq,bool active_low) +{ +if (irq >10 ) +return -EINVAL ; + +return 0 ; +} + +static int sandbox_route_pmc_gpio_gpe (struct udevice *dev,uint pmc_gpe_num) +{ +if (pmc_gpe_num >10 ) +return -ENOENT ; + +return pmc_gpe_num +1 ; +} + +static int sandbox_snapshot_polarities (struct udevice *dev) +{ +return 0 ; +} + +static int sandbox_restore_polarities (struct udevice *dev) +{ +return 0 ; +} + +static const struct irq_ops sandbox_irq_ops = { + .route_pmc_gpio_gpe = sandbox_route_pmc_gpio_gpe, + .set_polarity = sandbox_set_polarity, + .snapshot_polarities = sandbox_snapshot_polarities, + .restore_polarities = sandbox_restore_polarities, +}; + +static const struct udevice_id sandbox_irq_ids[] = { + { .compatible ="sandbox,irq" }, + { } +}; + +U_BOOT_DRIVER (sandbox_irq_drv) = { + .name ="sandbox_irq" , + .id =UCLASS_IRQ , + .of_match = sandbox_irq_ids, + .ops = &sandbox_irq_ops, +};test/dm/Makefile +1
-0@@ -25,6 +25,7 @@ obj-$(CONFIG_DM_GPIO) += gpio.o obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o obj-$(CONFIG_DM_I2C) += i2c.o obj-$(CONFIG_SOUND) += i2s.o +obj-y += irq.o obj-$(CONFIG_LED) += led.o obj-$(CONFIG_DM_MAILBOX) += mailbox.o obj-$(CONFIG_DM_MMC) += mmc.otest/dm/irq.c new file +23
-0@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Test for irq uclass +* +* Copyright 2019 Google LLC +*/ + +#include <common.h> +#include <dm.h> +#include <irq.h> +#include <dm/test.h> +#include <test/ut.h> + +/* Base test of the irq uclass */ +static int dm_test_irq_base (struct unit_test_state *uts) +{ +struct udevice *dev; + +ut_assertok (uclass_first_device_err (UCLASS_IRQ , &dev)); + +ut_asserteq (5 ,irq_route_pmc_gpio_gpe (dev,4 )); +ut_asserteq (-ENOENT ,irq_route_pmc_gpio_gpe (dev,14 )); +
test/dm/irq.c
Quoted 10 lines
test/dm/irq.c new file +9
-1+ut_assertok (irq_set_polarity (dev,4 , true)); +ut_asserteq (-EINVAL ,irq_set_polarity (dev,14 , true)); + +ut_assertok (irq_snapshot_polarities (dev)); +ut_assertok (irq_restore_polarities (dev)); + +return 0 ; +} +DM_TEST (dm_test_irq_base,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); --
Regards,
Bin
PATCH v3 40/108 x86: Define the SPL image start
In reply to Simon GlassDefine this symbol so that we can use binman symbols correctly.
---
Changes in v3: None
Changes in v2: None
arch/x86/cpu/u-boot-spl.lds | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/cpu/u-boot-spl.lds +4 -1
@@ -17,7 +17,10 @@ SECTIONS . = IMAGE_TEXT_BASE; /* Location of bootcode in flash */ __text_start = .; - .text : { *(.text*); } + .text : { + __image_copy_start = .; + *(.text*); + } . = ALIGN(4);
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 40/108 x86: Define the SPL image start
Quoted 12 lines · Simon Glass
Define this symbol so that we can use binman symbols correctly.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/cpu/u-boot-spl.lds | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
PATCH v3 41/108 x86: Reduce mrccache record alignment size
In reply to Simon GlassAt present the records are 4KB in size. This is unnecessarily large when the SPI-flash erase size is 256 bytes. Reduce it so it will be more efficient with Apollolake's 24-byte variable-data record.
---
Changes in v3: None
Changes in v2: None
arch/x86/include/asm/mrccache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/mrccache.h +1 -1
@@ -7,7 +7,7 @@#ifndef _ASM_MRCCACHE_H#define _ASM_MRCCACHE_H -#define MRC_DATA_ALIGN 0x1000 +#define MRC_DATA_ALIGN 0x100#define MRC_DATA_SIGNATURE (('M' << 0) | ('R' << 8) | \ ('C' << 16) | ('D'<<24))
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 41/108 x86: Reduce mrccache record alignment size
Quoted 5 lines · Simon Glass
At present the records are 4KB in size. This is unnecessarily large when the SPI-flash erase size is 256 bytes. Reduce it so it will be more efficient with Apollolake's 24-byte variable-data record.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/include/asm/mrccache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v3 42/108 x86: Correct mrccache find_next_mrc_cache() calculation
In reply to Simon GlassThis should take account of the end of the new cache record since a record cannot extend beyond the end of the flash region. This problem was not seen before due to the alignment of the relatively small amount of MRC data.
But with apollolake the MRC data is about 45KB, even if most of it is zeroes.
Fix this bug and update the parameter name to be less confusing.
---
Changes in v3:
- Add an extra size parameter to the find_next_mrc_cache() function
Changes in v2: None
arch/x86/lib/mrccache.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
arch/x86/lib/mrccache.c +9 -4
@@ -80,21 +80,26 @@ struct mrc_data_container *mrccache_find_current(struct mrc_region *entry)/** * find_next_mrc_cache() - get next cache entry * +* This moves to the next cache entry in the region, making sure it has enough +* space to hold data of size @data_size. +* * @entry: MRC cache flash area * @cache: Entry to start from +* @data_size: Required data size of the new entry * * @return next cache entry if found, NULL if we got to the end */ static struct mrc_data_container *find_next_mrc_cache (struct mrc_region *entry, -struct mrc_data_container *cache) +struct mrc_data_container *prev,int data_size) { +struct mrc_data_container *cache;ulong base_addr, end_addr; base_addr = entry->base + entry->offset; end_addr = base_addr + entry->length; - cache =next_mrc_block (cache); -if ((ulong )cache >= end_addr) { + cache =next_mrc_block (prev); +if ((ulong )cache +mrc_block_size (prev->data_size) > end_addr) {/* Crossed the boundary */ cache =NULL ;debug ("%s: no available entries found\n" , __func__);
@@ -131,7 +136,7 @@ int mrccache_update(struct udevice *sf, struct mrc_region *entry,/* Move to the next block, which will be the first unused block */ if (cache) - cache =find_next_mrc_cache (entry, cache); + cache =find_next_mrc_cache (entry, cache, cur->data_size);/* * If we have got to the end, erase the entire mrc-cache area and start
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 42/108 x86: Correct mrccache find_next_mrc_cache() calculation
Hi Simon,
Quoted 43 lines · Simon Glass
This should take account of the end of the new cache record since a record cannot extend beyond the end of the flash region. This problem was not seen before due to the alignment of the relatively small amount of MRC data.
But with apollolake the MRC data is about 45KB, even if most of it is zeroes.
Fix this bug and update the parameter name to be less confusing.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Add an extra size parameter to thefind_next_mrc_cache()functionChanges in v2: None
arch/x86/lib/mrccache.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)arch/x86/lib/mrccache.c +5
-1@@ -80,21 +80,26 @@ struct mrc_data_container *mrccache_find_current(struct mrc_region *entry)/** * find_next_mrc_cache() - get next cache entry * +* This moves to the next cache entry in the region, making sure it has enough +* space to hold data of size @data_size. +* * @entry: MRC cache flash area * @cache: Entry to start from +* @data_size: Required data size of the new entry * * @return next cache entry if found, NULL if we got to the end */ static struct mrc_data_container *find_next_mrc_cache (struct mrc_region *entry, -struct mrc_data_container *cache) +struct mrc_data_container *prev,int data_size) {
arch/x86/lib/mrccache.c struct mrc_data_container *mrccache_find_current(struct mrc_region *entry) · line 102
Quoted 10 lines
arch/x86/lib/mrccache.c +3
-2+struct mrc_data_container *cache;ulong base_addr, end_addr; base_addr = entry->base + entry->offset; end_addr = base_addr + entry->length; - cache =next_mrc_block (cache); -if ((ulong )cache >= end_addr) { + cache =next_mrc_block (prev); +if ((ulong )cache +mrc_block_size (prev->data_size) > end_addr) {
It takes me another several minutes to understand this, as I was confused by the v2 patch :)
So in v2 we agreed to add some comments here, as we assume the data_size will be the same.
arch/x86/lib/mrccache.c int mrccache_update(struct udevice *sf, struct mrc_region *entry,
Quoted 13 lines
arch/x86/lib/mrccache.c +1
-2/* Crossed the boundary */ cache =NULL ;debug ("%s: no available entries found\n" , __func__);@@ -131,7 +136,7 @@ int mrccache_update(struct udevice *sf, struct mrc_region *entry,/* Move to the next block, which will be the first unused block */ if (cache) - cache =find_next_mrc_cache (entry, cache); + cache =find_next_mrc_cache (entry, cache, cur->data_size);/* * If we have got to the end, erase the entire mrc-cache area and start --
Regards,
Bin
PATCH v3 43/108 x86: Adjust mrccache_get_region() to use livetree
In reply to Simon GlassChange the algorithm to first find the flash device then read the properties using the livetree API. With this change the device is not probed so this needs to be done in mrccache_save().
---
Changes in v3:
- Update mrccache livetree patch to just convert to livetree
Changes in v2: None
arch/x86/lib/mrccache.c | 55 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-)
arch/x86/lib/mrccache.c +26 -29
@@ -14,6 +14,8 @@#include <spi.h> #include <spi_flash.h> #include <asm/mrccache.h> +#include <dm/device-internal.h> +#include <dm/uclass-internal.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -201,45 +203,37 @@ int mrccache_reserve(void)int mrccache_get_region (struct udevice **devp,struct mrc_region *entry) { -const void *blob = gd->fdt_blob; -int node, mrc_node; +struct udevice *dev; +ofnode mrc_node;u32 reg[2 ];int ret; -/* Find the flash chip within the SPI controller node */ - node =fdtdec_next_compatible (blob,0 ,COMPAT_GENERIC_SPI_FLASH ); -if (node <0 ) { -debug ("%s: Cannot find SPI flash\n" , __func__); -return -ENOENT ; - } - -if (fdtdec_get_int_array (blob, node,"memory-map" , reg,2 )) { -debug ("%s: Cannot find memory map\n" , __func__); -return -EINVAL ; - } +/* +* Find the flash chip within the SPI controller node. Avoid probing +* the device here since it may put it into a strange state where the +* memory map cannot be read. +*/ + ret =uclass_find_first_device (UCLASS_SPI_FLASH , &dev); +if (ret) +return log_msg_ret ("Cannot find SPI flash\n" , ret); + ret =dev_read_u32_array (dev,"memory-map" , reg,2 ); +if (ret) +return log_msg_ret ("Cannot find memory map\n" , ret); entry->base = reg[0 ];/* Find the place where we put the MRC cache */ - mrc_node =fdt_subnode_offset (blob, node,"rw-mrc-cache" ); -if (mrc_node <0 ) { -debug ("%s: Cannot find node\n" , __func__); -return -EPERM ; - } + mrc_node =dev_read_subnode (dev,"rw-mrc-cache" ); +if (!ofnode_valid (mrc_node)) +return log_msg_ret ("Cannot find node" , -EPERM ); -if (fdtdec_get_int_array (blob, mrc_node,"reg" , reg,2 )) { -debug ("%s: Cannot find address\n" , __func__); -return -EINVAL ; - } + ret =ofnode_read_u32_array (mrc_node,"reg" , reg,2 ); +if (ret) +return log_msg_ret ("Cannot find address" , ret); entry->offset = reg[0 ]; entry->length = reg[1 ]; -if (devp) { - ret =uclass_get_device_by_of_offset (UCLASS_SPI_FLASH , node, - devp); -debug ("ret = %d\n" , ret); -if (ret) -return ret; - } +if (devp) + *devp = dev;return 0 ; }
@@ -257,6 +251,9 @@ int mrccache_save(void) gd->arch.mrc_output_len); ret =mrccache_get_region (&sf, &entry); +if (ret) + goto err_entry; + ret =device_probe (sf);if (ret) goto err_entry; data = (struct mrc_data_container *)gd->arch.mrc_output;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 43/108 x86: Adjust mrccache_get_region() to use livetree
Hi Simon,
Quoted 47 lines · Simon Glass
Change the algorithm to first find the flash device then read the properties using the livetree API. With this change the device is not probed so this needs to be done in
mrccache_save().Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Update mrccache livetree patch to just convert to livetreeChanges in v2: None
arch/x86/lib/mrccache.c | 55 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-)arch/x86/lib/mrccache.c +4
-9@@ -14,6 +14,8 @@#include <spi.h> #include <spi_flash.h> #include <asm/mrccache.h> +#include <dm/device-internal.h> +#include <dm/uclass-internal.h> DECLARE_GLOBAL_DATA_PTR ;@@ -201,45 +203,37 @@ int mrccache_reserve(void)int mrccache_get_region (struct udevice **devp,struct mrc_region *entry) { -const void *blob = gd->fdt_blob; -int node, mrc_node; +struct udevice *dev; +ofnode mrc_node;u32 reg[2 ];int ret; -/* Find the flash chip within the SPI controller node */ - node =fdtdec_next_compatible (blob,0 ,COMPAT_GENERIC_SPI_FLASH ); -if (node <0 ) { -debug ("%s: Cannot find SPI flash\n" , __func__); -return -ENOENT ; - } -
arch/x86/lib/mrccache.c int mrccache_reserve(void) · line 216
Quoted 10 lines
arch/x86/lib/mrccache.c +6
-4-if (fdtdec_get_int_array (blob, node,"memory-map" , reg,2 )) { -debug ("%s: Cannot find memory map\n" , __func__); -return -EINVAL ; - } +/* +* Find the flash chip within the SPI controller node. Avoid probing +* the device here since it may put it into a strange state where the +* memory map cannot be read. +*/ + ret =uclass_find_first_device (UCLASS_SPI_FLASH , &dev);
Adding probe of UCLASS_SPI_FLASH should be in the next patch:
[U-Boot,v3,044/108] x86: Adjust mrccache_get_region() to support get_mmap()
Quoted 40 lines
arch/x86/lib/mrccache.c +13
-16+if (ret) +return log_msg_ret ("Cannot find SPI flash\n" , ret); + ret =dev_read_u32_array (dev,"memory-map" , reg,2 ); +if (ret) +return log_msg_ret ("Cannot find memory map\n" , ret); entry->base = reg[0 ];/* Find the place where we put the MRC cache */ - mrc_node =fdt_subnode_offset (blob, node,"rw-mrc-cache" ); -if (mrc_node <0 ) { -debug ("%s: Cannot find node\n" , __func__); -return -EPERM ; - } + mrc_node =dev_read_subnode (dev,"rw-mrc-cache" ); +if (!ofnode_valid (mrc_node)) +return log_msg_ret ("Cannot find node" , -EPERM ); -if (fdtdec_get_int_array (blob, mrc_node,"reg" , reg,2 )) { -debug ("%s: Cannot find address\n" , __func__); -return -EINVAL ; - } + ret =ofnode_read_u32_array (mrc_node,"reg" , reg,2 ); +if (ret) +return log_msg_ret ("Cannot find address" , ret); entry->offset = reg[0 ]; entry->length = reg[1 ]; -if (devp) { - ret =uclass_get_device_by_of_offset (UCLASS_SPI_FLASH , node, - devp); -debug ("ret = %d\n" , ret); -if (ret) -return ret; - } +if (devp) + *devp = dev;return 0 ; }
arch/x86/lib/mrccache.c int mrccache_save(void) · line 256
Quoted 6 lines
arch/x86/lib/mrccache.c +3
-0@@ -257,6 +251,9 @@ int mrccache_save(void) gd->arch.mrc_output_len); ret =mrccache_get_region (&sf, &entry); +if (ret) + goto err_entry; + ret =device_probe (sf);
This needs a comment as we discussed in v2, or maybe it should also go into next patch?
arch/x86/lib/mrccache.c int mrccache_save(void)
Quoted 4 lines
arch/x86/lib/mrccache.c +0
-1if (ret) goto err_entry; data = (struct mrc_data_container *)gd->arch.mrc_output; --
Regards,
Bin
PATCH v3 43/108 x86: Adjust mrccache_get_region() to use livetree
Hi Bin,
Quoted 19 lines · Bin Meng
Hi Simon,
Quoted 15 lines · Simon Glass
Change the algorithm to first find the flash device then read the properties using the livetree API. With this change the device is not probed so this needs to be done in
mrccache_save().Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Update mrccache livetree patch to just convert to livetreeChanges in v2: None
arch/x86/lib/mrccache.c | 55 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-)
Just checking if I should send a new series with all these comments, or still hold off?
Regards,
Simon
PATCH v3 43/108 x86: Adjust mrccache_get_region() to use livetree
Hi Simon,
Quoted 19 lines · Simon Glass
Hi Bin,
Quoted 15 lines · Bin Meng
Hi Simon,
Quoted 11 lines · Simon Glass
Change the algorithm to first find the flash device then read the properties using the livetree API. With this change the device is not probed so this needs to be done in
mrccache_save().Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Update mrccache livetree patch to just convert to livetree
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Changes in v2: None
arch/x86/lib/mrccache.c | 55 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-)Just checking if I should send a new series with all these comments, or still hold off?
Sorry I was on travel for the past days and am still traveling. I will be looking the remaining patches during this weekend.
Regards,
Bin
PATCH v3 44/108 x86: Adjust mrccache_get_region() to support get_mmap()
In reply to Simon GlassIt is now possible to obtain the memory map for a SPI controllers instead of having it hard-coded in the device tree. Update the code to support this.
---
Changes in v3: None
Changes in v2:
- Use SPI mmap() instead of SPI flash
arch/x86/lib/mrccache.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
arch/x86/lib/mrccache.c +14 -4
@@ -205,6 +205,9 @@ int mrccache_get_region(struct udevice **devp, struct mrc_region *entry) {struct udevice *dev;ofnode mrc_node; +ulong map_base; +uint map_size; +uint offset;u32 reg[2 ];int ret;
@@ -216,10 +219,15 @@ int mrccache_get_region(struct udevice **devp, struct mrc_region *entry) ret =uclass_find_first_device (UCLASS_SPI_FLASH , &dev);if (ret)return log_msg_ret ("Cannot find SPI flash\n" , ret); - ret =dev_read_u32_array (dev,"memory-map" , reg,2 ); -if (ret) -return log_msg_ret ("Cannot find memory map\n" , ret); - entry->base = reg[0 ]; + ret =dm_spi_get_mmap (dev, &map_base, &map_size, &offset); +if (!ret) { + entry->base = map_base; + }else { + ret =dev_read_u32_array (dev,"memory-map" , reg,2 ); +if (ret) +return log_msg_ret ("Cannot find memory map\n" , ret); + entry->base = reg[0 ]; + }/* Find the place where we put the MRC cache */ mrc_node =dev_read_subnode (dev,"rw-mrc-cache" );
@@ -234,6 +242,8 @@ int mrccache_get_region(struct udevice **devp, struct mrc_region *entry)if (devp) *devp = dev; +debug ("MRC cache in '%s', offset %x, len %x, base %x\n" , + dev->name, entry->offset, entry->length, entry->base);return 0 ; }
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 45/108 x86: Add a new global_data member for the cache record
In reply to Simon GlassAt present we reuse the mrc_output char * to also point to the cache record after it has been set up. This is confusing and doesn't save much data space.
Add a new mrc_cache member instead.
---
Changes in v3: None
Changes in v2: None
arch/x86/include/asm/global_data.h | 2 ++ arch/x86/lib/mrccache.c | 11 +++++------ 2 files changed, 7 insertions(+), 6 deletions(-)
arch/x86/include/asm/global_data.h +2 -0
@@ -10,6 +10,7 @@#ifndef __ASSEMBLY__#include <asm/processor.h> +#include <asm/mrccache.h> enum pei_boot_mode_t { PEI_BOOT_NONE = 0,
@@ -93,6 +94,7 @@ struct arch_global_data {/* MRC training data to save for the next boot */ char *mrc_output;unsigned int mrc_output_len; +struct mrc_data_container *mrc_cache;ulong table;/* Table pointer from previous loader */ int turbo_state;/* Current turbo state */ struct irq_routing_table *pirq_routing_table;
arch/x86/lib/mrccache.c +5 -6
@@ -183,8 +183,7 @@ static void mrccache_setup(void *data) cache->reserved =0 ;memcpy (cache->data, gd->arch.mrc_output, cache->data_size); -/* gd->arch.mrc_output now points to the container */ - gd->arch.mrc_output = (char *)cache; + gd->arch.mrc_cache = cache; }int mrccache_reserve (void )
@@ -250,7 +249,7 @@ int mrccache_get_region(struct udevice **devp, struct mrc_region *entry)int mrccache_save (void ) { -struct mrc_data_container *data; +struct mrc_data_container *cache;struct mrc_region entry;struct udevice *sf;int ret;
@@ -266,10 +265,10 @@ int mrccache_save(void) ret =device_probe (sf);if (ret) goto err_entry; - data = (struct mrc_data_container *)gd->arch.mrc_output; - ret =mrccache_update (sf, &entry, data); + cache = gd->arch.mrc_cache; + ret =mrccache_update (sf, &entry, cache);if (!ret) { -debug ("Saved MRC data with checksum %04x\n" , data->checksum); +debug ("Saved MRC data with checksum %04x\n" , cache->checksum); }else if (ret == -EEXIST ) {debug ("MRC data is the same as last time, skipping save\n" ); ret =0 ;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 46/108 x86: Tidy up error handling in mrccache_save()
In reply to Simon GlassThis function is a bit confusing at present due to the error handling. Update it to remove the goto, returning errors as they happen.
While we are here, use hex for the data size since this is the norm in U-Boot.
---
Changes in v3:
- Move an additional error handling fix from a future patch
Changes in v2: None
arch/x86/lib/mrccache.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
arch/x86/lib/mrccache.c +7 -12
@@ -163,7 +163,7 @@ int mrccache_update(struct udevice *sf, struct mrc_region *entry, cur);if (ret) {debug ("Failed to write to SPI flash\n" ); -return ret; +return log_msg_ret ("Cannot update mrccache" , ret); }return 0 ;
@@ -256,28 +256,23 @@ int mrccache_save(void)if (!gd->arch.mrc_output_len)return 0 ; -debug ("Saving %d bytes of MRC output data to SPI flash\n" , +debug ("Saving %#x bytes of MRC output data to SPI flash\n" , gd->arch.mrc_output_len); ret =mrccache_get_region (&sf, &entry);if (ret) - goto err_entry; +return log_msg_ret ("Cannot get region" , ret); ret =device_probe (sf);if (ret) - goto err_entry; +return log_msg_ret ("Cannot probe device" , ret); cache = gd->arch.mrc_cache; ret =mrccache_update (sf, &entry, cache); -if (!ret) { +if (!ret)debug ("Saved MRC data with checksum %04x\n" , cache->checksum); - }else if (ret == -EEXIST ) { +else if (ret == -EEXIST )debug ("MRC data is the same as last time, skipping save\n" ); - ret =0 ; - } -err_entry: -if (ret) -debug ("%s: Failed: %d\n" , __func__, ret); -return ret; +return 0 ; }int mrccache_spl_save (void )
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 47/108 x86: Update mrccache to support multiple caches
In reply to Simon GlassWith apollolake we need to support a normal cache, which almost never changes and a much smaller 'variable' cache which changes every time.
Update the code to add a cache type, use an array for the caches and use a for loop to iterate over the caches.
---
Changes in v3:
- Move line related to variable-cache into the next patch
Changes in v2: None
arch/x86/cpu/broadwell/sdram.c | 8 ++- arch/x86/cpu/ivybridge/sdram.c | 8 ++- arch/x86/cpu/quark/dram.c | 8 ++- arch/x86/include/asm/global_data.h | 21 +++++-- arch/x86/include/asm/mrccache.h | 11 +++- arch/x86/lib/fsp/fsp_common.c | 2 +- arch/x86/lib/fsp1/fsp_dram.c | 8 ++- arch/x86/lib/mrccache.c | 88 ++++++++++++++++++++---------- 8 files changed, 106 insertions(+), 48 deletions(-)
arch/x86/cpu/broadwell/sdram.c +5 -3
@@ -82,7 +82,7 @@ static int prepare_mrc_cache(struct pei_data *pei_data)struct mrc_region entry;int ret; - ret =mrccache_get_region (NULL , &entry); + ret =mrccache_get_region (MRC_TYPE_NORMAL ,NULL , &entry);if (ret)return ret; mrc_cache =mrccache_find_current (&entry);
@@ -168,12 +168,14 @@ int dram_init(void) pei_data->data_to_save);/* S3 resume: don't save scrambler seed or MRC data */ if (pei_data->boot_mode !=SLEEP_STATE_S3 ) { +struct mrc_output *mrc = &gd->arch.mrc[MRC_TYPE_NORMAL ]; +/* * This will be copied to SDRAM in reserve_arch(), then written * to SPI flash in mrccache_save() */ - gd->arch.mrc_output = (char *)pei_data->data_to_save; - gd->arch.mrc_output_len = pei_data->data_to_save_size; + mrc->buf = (char *)pei_data->data_to_save; + mrc->len = pei_data->data_to_save_size; } gd->arch.pei_meminfo = pei_data->meminfo;
arch/x86/cpu/ivybridge/sdram.c +5 -3
@@ -115,7 +115,7 @@ static int prepare_mrc_cache(struct pei_data *pei_data) ret =read_seed_from_cmos (pei_data);if (ret)return ret; - ret =mrccache_get_region (NULL , &entry); + ret =mrccache_get_region (MRC_TYPE_NORMAL ,NULL , &entry);if (ret)return ret; mrc_cache =mrccache_find_current (&entry);
@@ -537,12 +537,14 @@ int dram_init(void)/* S3 resume: don't save scrambler seed or MRC data */ if (pei_data->boot_mode !=PEI_BOOT_RESUME ) { +struct mrc_output *mrc = &gd->arch.mrc[MRC_TYPE_NORMAL ]; +/* * This will be copied to SDRAM in reserve_arch(), then written * to SPI flash in mrccache_save() */ - gd->arch.mrc_output = (char *)pei_data->mrc_output; - gd->arch.mrc_output_len = pei_data->mrc_output_len; + mrc->buf = (char *)pei_data->mrc_output; + mrc->len = pei_data->mrc_output_len; ret =write_seeds_to_cmos (pei_data);if (ret)debug ("Failed to write seeds to CMOS: %d\n" , ret);
arch/x86/cpu/quark/dram.c +5 -3
@@ -22,7 +22,7 @@ static __maybe_unused int prepare_mrc_cache(struct mrc_params *mrc_params)struct mrc_region entry;int ret; - ret =mrccache_get_region (NULL , &entry); + ret =mrccache_get_region (MRC_TYPE_NORMAL ,NULL , &entry);if (ret)return ret;
@@ -152,9 +152,11 @@ int dram_init(void)#ifdef CONFIG_ENABLE_MRC_CACHE cache =malloc (sizeof (struct mrc_timings ));if (cache) { +struct mrc_output *mrc = &gd->arch.mrc[MRC_TYPE_NORMAL ]; +memcpy (cache, &mrc_params.timings,sizeof (struct mrc_timings )); - gd->arch.mrc_output = cache; - gd->arch.mrc_output_len =sizeof (struct mrc_timings ); + mrc->buf = cache; + mrc->len =sizeof (struct mrc_timings ); }#endif
arch/x86/include/asm/global_data.h +17 -4
@@ -67,6 +67,21 @@ struct mtrr_request {uint64_t size; }; +/** +* struct mrc_output - holds the MRC data +* +* @buf: MRC training data to save for the next boot. This is set to point to +* the raw data after SDRAM init is complete. Then mrccache_setup() +* turns it into a proper cache record with a checksum +* @len: Length of @buf +* @cache: Resulting cache record +*/ +struct mrc_output { +char *buf; +uint len; +struct mrc_data_container *cache; +}; +/* Architecture-specific global data */ struct arch_global_data {u64 gdt[X86_GDT_NUM_ENTRIES ]__aligned(16) ;
@@ -91,10 +106,8 @@ struct arch_global_data {struct mtrr_request mtrr_req[MAX_MTRR_REQUESTS ];int mtrr_req_count;int has_mtrr; -/* MRC training data to save for the next boot */ -char *mrc_output; -unsigned int mrc_output_len; -struct mrc_data_container *mrc_cache; +/* MRC training data */ +struct mrc_output mrc[MRC_TYPE_COUNT ];ulong table;/* Table pointer from previous loader */ int turbo_state;/* Current turbo state */ struct irq_routing_table *pirq_routing_table;
arch/x86/include/asm/mrccache.h +10 -1
@@ -27,6 +27,13 @@ struct mrc_region {u32 length; }; +/* Types of MRC data */ +enum mrc_type_t { +MRC_TYPE_NORMAL , + +MRC_TYPE_COUNT , +}; +struct udevice ;/**
@@ -84,6 +91,7 @@ int mrccache_reserve(void);* triggers PCI bus enumeration during which insufficient memory issue * might be exposed and it causes subsequent SPI flash probe fails). * +* @type: Type of MRC data to use * @devp: Returns pointer to the SPI flash device * @entry: Position and size of MRC cache in SPI flash * @return 0 if success, -ENOENT if SPI flash node does not exist in the
@@ -91,7 +99,8 @@ int mrccache_reserve(void);* tree, -EINVAL if MRC region properties format is incorrect, other error * if SPI flash probe failed. */ -int mrccache_get_region (struct udevice **devp,struct mrc_region *entry); +int mrccache_get_region (enum mrc_type_t type,struct udevice **devp, +struct mrc_region *entry);/** * mrccache_save() - save MRC data to the SPI flash
arch/x86/lib/fsp/fsp_common.c +1 -1
@@ -63,7 +63,7 @@ void *fsp_prepare_mrc_cache(void)struct mrc_region entry;int ret; - ret =mrccache_get_region (NULL , &entry); + ret =mrccache_get_region (MRC_TYPE_NORMAL ,NULL , &entry);if (ret)return NULL ;
arch/x86/lib/fsp1/fsp_dram.c +5 -3
@@ -15,9 +15,11 @@ int dram_init(void)if (ret)return ret; -if (IS_ENABLED (CONFIG_ENABLE_MRC_CACHE )) - gd->arch.mrc_output =fsp_get_nvs_data (gd->arch.hob_list, - &gd->arch.mrc_output_len); +if (IS_ENABLED (CONFIG_ENABLE_MRC_CACHE )) { +struct mrc_output *mrc = &gd->arch.mrc[MRC_TYPE_NORMAL ]; + + mrc->buf =fsp_get_nvs_data (gd->arch.hob_list, &mrc->len); + }return 0 ; }
arch/x86/lib/mrccache.c +58 -30
144 lines not on this page · raw message
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 47/108 x86: Update mrccache to support multiple caches
Quoted 15 lines · Simon Glass
With apollolake we need to support a normal cache, which almost never changes and a much smaller 'variable' cache which changes every time.
Update the code to add a cache type, use an array for the caches and use a for loop to iterate over the caches.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Move line related to variable-cache into the next patchChanges in v2: None
Quoted 10 lines
arch/x86/cpu/broadwell/sdram.c | 8 ++- arch/x86/cpu/ivybridge/sdram.c | 8 ++- arch/x86/cpu/quark/dram.c | 8 ++- arch/x86/include/asm/global_data.h | 21 +++++-- arch/x86/include/asm/mrccache.h | 11 +++- arch/x86/lib/fsp/fsp_common.c | 2 +- arch/x86/lib/fsp1/fsp_dram.c | 8 ++- arch/x86/lib/mrccache.c | 88 ++++++++++++++++++++---------- 8 files changed, 106 insertions(+), 48 deletions(-)
PATCH v3 48/108 x86: Add mrccache support for a 'variable' cache
In reply to Simon GlassAdd support for a second cache type, for apollolake.
---
Changes in v3:
- Move the mrccache_get_region() change into this patch
Changes in v2: None
arch/x86/include/asm/mrccache.h | 1 + arch/x86/lib/mrccache.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/include/asm/mrccache.h +1 -0
@@ -30,6 +30,7 @@ struct mrc_region {/* Types of MRC data */ enum mrc_type_t {MRC_TYPE_NORMAL , +MRC_TYPE_VAR ,MRC_TYPE_COUNT , };
arch/x86/lib/mrccache.c +2 -1
@@ -236,7 +236,8 @@ int mrccache_get_region(enum mrc_type_t type, struct udevice **devp, }/* Find the place where we put the MRC cache */ - mrc_node =dev_read_subnode (dev,"rw-mrc-cache" ); + mrc_node =dev_read_subnode (dev, type ==MRC_TYPE_NORMAL ? +"rw-mrc-cache" :"rw-var-mrc-cache" );if (!ofnode_valid (mrc_node))return log_msg_ret ("Cannot find node" , -EPERM );
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 48/108 x86: Add mrccache support for a 'variable' cache
Quoted 6 lines · Simon Glass
Add support for a second cache type, for apollolake.
Signed-off-by Simon Glass <[email protected]>---
Quoted 9 lines
Changes in v3:
- Move themrccache_get_region()change into this patchChanges in v2: None
arch/x86/include/asm/mrccache.h | 1 + arch/x86/lib/mrccache.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
PATCH v3 49/108 x86: Move fsp_prepare_mrc_cache() to fsp1 directory
In reply to Simon GlassThis function needs to be different for FSP2, so move the existing function into the fsp1 directory. Since it is only called from one file, drop it from the header file.
---
Changes in v3: None
Changes in v2: None
arch/x86/include/asm/fsp/fsp_support.h | 7 ------- arch/x86/lib/fsp/fsp_common.c | 20 -------------------- arch/x86/lib/fsp1/fsp_common.c | 20 ++++++++++++++++++++ 3 files changed, 20 insertions(+), 27 deletions(-)
arch/x86/include/asm/fsp/fsp_support.h +0 -7
@@ -143,13 +143,6 @@ int fsp_init_phase_pci(void);*/ int fsp_scan_for_ram_size (void ); -/** -* fsp_prepare_mrc_cache() - Find the DRAM training data from the MRC cache -* -* @return pointer to data, or NULL if no cache or no data found in the cache -*/ -void *fsp_prepare_mrc_cache (void ); -/** * fsp_notify() - FSP notification wrapper function *
arch/x86/lib/fsp/fsp_common.c +0 -20
@@ -57,26 +57,6 @@ void board_final_cleanup(void)debug ("OK\n" ); } -void *fsp_prepare_mrc_cache (void ) -{ -struct mrc_data_container *cache; -struct mrc_region entry; -int ret; - - ret =mrccache_get_region (MRC_TYPE_NORMAL ,NULL , &entry); -if (ret) -return NULL ; - - cache =mrccache_find_current (&entry); -if (!cache) -return NULL ; - -debug ("%s: mrc cache at %p, size %x checksum %04x\n" , __func__, - cache->data, cache->data_size, cache->checksum); - -return cache->data; -} -#ifdef CONFIG_HAVE_ACPI_RESUME int fsp_save_s3_stack (void ) {
arch/x86/lib/fsp1/fsp_common.c +20 -0
@@ -18,6 +18,26 @@DECLARE_GLOBAL_DATA_PTR ; +static void *fsp_prepare_mrc_cache (void ) +{ +struct mrc_data_container *cache; +struct mrc_region entry; +int ret; + + ret =mrccache_get_region (MRC_TYPE_NORMAL ,NULL , &entry); +if (ret) +return NULL ; + + cache =mrccache_find_current (&entry); +if (!cache) +return NULL ; + +debug ("%s: mrc cache at %p, size %x checksum %04x\n" , __func__, + cache->data, cache->data_size, cache->checksum); + +return cache->data; +} +int arch_fsp_init (void ) {void *nvs;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 50/108 x86: Set the DRAM banks to reflect real location
In reply to Simon GlassAt present with fsp a single DRAM bank is added which extends to the whole size of memory. However there is typically only 2GB of memory available below the 4GB boundary, and this is what is used by U-Boot while running in 32-bit mode.
Scan the tables to set the banks correct. The first bank is set to memory below 4GB, and the rest of memory is put into subsequent banks.
---
Changes in v3:
- Move mtrr_add_request() call to next patch
Changes in v2: None
arch/x86/lib/fsp/fsp_dram.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
arch/x86/lib/fsp/fsp_dram.c +29 -1
@@ -37,8 +37,36 @@ int fsp_scan_for_ram_size(void)int dram_init_banksize (void ) { +const struct hob_header *hdr; +struct hob_res_desc *res_desc; +phys_addr_t low_end; +uint bank; + + low_end =0 ; +for (bank =1 , hdr = gd->arch.hob_list; + bank <CONFIG_NR_DRAM_BANKS && !end_of_hob (hdr); + hdr =get_next_hob (hdr)) { +if (hdr->type !=HOB_TYPE_RES_DESC ) +continue ; + res_desc = (struct hob_res_desc *)hdr; +if (res_desc->type !=RES_SYS_MEM && + res_desc->type !=RES_MEM_RESERVED ) +continue ; +if (res_desc->phys_start < (1ULL <<32 )) { + low_end =max (low_end, + res_desc->phys_start + res_desc->len); +continue ; + } + + gd->bd->bi_dram[bank].start = res_desc->phys_start; + gd->bd->bi_dram[bank].size = res_desc->len; +log_debug ("ram %llx %llx\n" , gd->bd->bi_dram[bank].start, + gd->bd->bi_dram[bank].size); + } + +/* Add the memory below 4GB */ gd->bd->bi_dram[0 ].start =0 ; - gd->bd->bi_dram[0 ].size = gd->ram_size; + gd->bd->bi_dram[0 ].size = low_end;return 0 ; }
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 50/108 x86: Set the DRAM banks to reflect real location
Quoted 12 lines · Simon Glass
At present with fsp a single DRAM bank is added which extends to the whole size of memory. However there is typically only 2GB of memory available below the 4GB boundary, and this is what is used by U-Boot while running in 32-bit mode.
Scan the tables to set the banks correct. The first bank is set to memory below 4GB, and the rest of memory is put into subsequent banks.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v3:
- Movemtrr_add_request()call to next patchChanges in v2: None
arch/x86/lib/fsp/fsp_dram.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
PATCH v3 51/108 x86: Set up the MTRR for SDRAM
In reply to Simon GlassSet up MTRRs for the FST SDRAM regions to improve performance.
---
Changes in v3:
- Move mtrr_add_request() call into this patch
Changes in v2: None
arch/x86/lib/fsp/fsp_dram.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/lib/fsp/fsp_dram.c +5 -0
@@ -8,6 +8,7 @@#include <asm/fsp/fsp_support.h> #include <asm/e820.h> #include <asm/mrccache.h> +#include <asm/mtrr.h> #include <asm/post.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -60,6 +61,8 @@ int dram_init_banksize(void) gd->bd->bi_dram[bank].start = res_desc->phys_start; gd->bd->bi_dram[bank].size = res_desc->len; +mtrr_add_request (MTRR_TYPE_WRBACK , res_desc->phys_start, + res_desc->len);log_debug ("ram %llx %llx\n" , gd->bd->bi_dram[bank].start, gd->bd->bi_dram[bank].size); }
@@ -68,6 +71,8 @@ int dram_init_banksize(void) gd->bd->bi_dram[0 ].start =0 ; gd->bd->bi_dram[0 ].size = low_end; +mtrr_add_request (MTRR_TYPE_WRBACK ,0 , low_end); +return 0 ; }
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 51/108 x86: Set up the MTRR for SDRAM
Quoted 2 lines · Simon Glass
Set up MTRRs for the FST SDRAM regions to improve performance.
typo: FST -> FSP
Quoted 4 lines
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v3:
- Movemtrr_add_request()call into this patchChanges in v2: None
arch/x86/lib/fsp/fsp_dram.c | 5 +++++ 1 file changed, 5 insertions(+)
PATCH v3 52/108 x86: Don't imply libfdt or SPI flash in TPL
In reply to Simon GlassWe don't want to pull in libfdt if of-platdata is being used, since it reduces the available code-size saves. Also, SPI flash is seldom needed in TPL.
Drop these options.
---
Changes in v3:
- Don't imply SPI flash either
- Rewrite commit message
Changes in v2: None
arch/Kconfig | 3 --- 1 file changed, 3 deletions(-)
arch/Kconfig +0 -3
@@ -204,14 +204,11 @@ config X86 imply SPL_SYSCON # TPL imply TPL_DM - imply TPL_OF_LIBFDT imply TPL_DRIVERS_MISC_SUPPORT imply TPL_GPIO_SUPPORT imply TPL_LIBCOMMON_SUPPORT imply TPL_LIBGENERIC_SUPPORT imply TPL_SERIAL_SUPPORT - imply TPL_SPI_FLASH_SUPPORT - imply TPL_SPI_SUPPORT imply TPL_OF_CONTROL imply TPL_TIMER imply TPL_REGMAP
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 52/108 x86: Don't imply libfdt or SPI flash in TPL
Quoted 10 lines · Simon Glass
We don't want to pull in libfdt if of-platdata is being used, since it reduces the available code-size saves. Also, SPI flash is seldom needed in TPL.
Drop these options.
Signed-off-by Simon Glass <[email protected]>---
Quoted 9 lines
Changes in v3:
- Don't imply SPI flash either
- Rewrite commit messageChanges in v2: None
arch/Kconfig | 3 --- 1 file changed, 3 deletions(-)
PATCH v3 53/108 x86: Allow removal of standard PCH drivers
In reply to Simon GlassThese drivers are not needed on all platforms. While they are small, it is useful in TPL to drop then. Add Kconfig control to allow this.
---
Changes in v3: None
Changes in v2:
- Change 'queensbay' to 'baytrail' in help
- Fix 'proides' typo
drivers/pch/Kconfig | 18 ++++++++++++++++++ drivers/pch/Makefile | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-)
drivers/pch/Kconfig +18 -0
@@ -7,3 +7,21 @@ config PCH northbridge / southbridge architecture that was previously used. The PCH allows for higher performance since the memory functions are handled in the CPU. + +config X86_PCH7 + bool "Add support for Intel PCH7" + default y if X86 + help + Enable this if your SoC uses Platform Controller Hub 7 (PCH7). This + dates from about 2011 and is used on baytrail, for example. The + PCH provides access to the GPIO and SPI base addresses, among other + functions. + +config X86_PCH9 + bool "Add support for Intel PCH9" + default y if X86 + help + Enable this if your SoC uses Platform Controller Hub 9 (PCH9). This + dates from about 2015 and is used on baytrail, for example. The + PCH provides access to the GPIO and SPI base addresses, among other + functions.
drivers/pch/Makefile +2 -2
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0+ obj-y += pch-uclass.o -obj-y += pch7.o -obj-y += pch9.o +obj-$(CONFIG_X86_PCH7) += pch7.o +obj-$(CONFIG_X86_PCH9) += pch9.o obj-$(CONFIG_SANDBOX) += sandbox_pch.o
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 54/108 x86: Allow interrupt to happen once
In reply to Simon GlassAt present the interrupt table is included in all phases of U-Boot. Allow it to be omitted, e.g. in TPL, to reduce size.
---
Changes in v3:
- Move write_pirq_routing_table() to avoid 64-bit build error
Changes in v2: None
arch/x86/cpu/Makefile | 2 +- arch/x86/cpu/irq.c | 8 -------- arch/x86/lib/pirq_routing.c | 10 ++++++++++ 3 files changed, 11 insertions(+), 9 deletions(-)
arch/x86/cpu/Makefile +1 -1
@@ -53,7 +53,7 @@ obj-$(CONFIG_INTEL_QUARK) += quark/ obj-$(CONFIG_INTEL_QUEENSBAY) += queensbay/ obj-$(CONFIG_INTEL_TANGIER) += tangier/ obj-$(CONFIG_APIC) += lapic.o ioapic.o -obj-y += irq.o +obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += irq.o ifndef CONFIG_$(SPL_)X86_64 obj-$(CONFIG_SMP) += mp_init.o endif
arch/x86/cpu/irq.c +0 -8
@@ -350,14 +350,6 @@ int irq_router_probe(struct udevice *dev)return 0 ; } -ulong write_pirq_routing_table (ulong addr) -{ -if (!gd->arch.pirq_routing_table) -return addr; - -return copy_pirq_routing_table (addr, gd->arch.pirq_routing_table); -} -static const struct udevice_id irq_router_ids[] = { { .compatible ="intel,irq-router" }, { }
arch/x86/lib/pirq_routing.c +10 -0
@@ -10,6 +10,8 @@#include <asm/pci.h> #include <asm/pirq_routing.h> +DECLARE_GLOBAL_DATA_PTR ; +static u8 pirq_get_next_free_irq (struct udevice *dev,u8 *pirq,u16 bitmap,bool irq_already_routed[]) {
@@ -131,3 +133,11 @@ u32 copy_pirq_routing_table(u32 addr, struct irq_routing_table *rt)return addr + rt->size; } + +ulong write_pirq_routing_table (ulong addr) +{ +if (!gd->arch.pirq_routing_table) +return addr; + +return copy_pirq_routing_table (addr, gd->arch.pirq_routing_table); +}
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 55/108 x86: fsp: Make graphics support common to FSP1/2
In reply to Simon GlassBoth versions of FSP can use the same graphics support, so move it into the common directory.
---
Changes in v3: None
Changes in v2: None
arch/x86/lib/fsp/Makefile | 3 +++
arch/x86/lib/{fsp1 => fsp}/fsp_graphics.c | 2 +-
arch/x86/lib/fsp1/Makefile | 1 -
3 files changed, 4 insertions(+), 2 deletions(-)
rename arch/x86/lib/{fsp1 => fsp}/fsp_graphics.c (98%)arch/x86/lib/fsp/Makefile +3 -0
@@ -4,4 +4,7 @@ obj-y += fsp_common.o obj-y += fsp_dram.o +ifndef CONFIG_SPL_BUILD +obj-$(CONFIG_VIDEO_FSP) += fsp_graphics.o +endif obj-y += fsp_support.o
arch/x86/lib/fsp/fsp_graphics.c renamed from arch/x86/lib/fsp1/fsp_graphics.c +1 -1
@@ -7,7 +7,7 @@#include <dm.h> #include <vbe.h> #include <video.h> -#include <asm/fsp1/fsp_support.h> +#include <asm/fsp/fsp_support.h> DECLARE_GLOBAL_DATA_PTR ;
arch/x86/lib/fsp1/Makefile +0 -1
@@ -5,5 +5,4 @@ obj-y += fsp_car.o obj-y += fsp_common.o obj-y += fsp_dram.o -obj-$(CONFIG_VIDEO_FSP) += fsp_graphics.o obj-y += fsp_support.o
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 55/108 x86: fsp: Make graphics support common to FSP1/2
Quoted 7 lines · Simon Glass
Both versions of FSP can use the same graphics support, so move it into the common directory.
Signed-off-by Simon Glass <[email protected]>---
Quoted 9 lines
Changes in v3: None
Changes in v2: Nonearch/x86/lib/fsp/Makefile | 3 +++ arch/x86/lib/{fsp1 => fsp}/fsp_graphics.c | 2 +- arch/x86/lib/fsp1/Makefile | 1 - 3 files changed, 4 insertions(+), 2 deletions(-) rename arch/x86/lib/{fsp1 => fsp}/fsp_graphics.c (98%)
PATCH v3 56/108 x86: fsp: Correct wrong header inlude in fsp_support.c
In reply to Simon GlassThis generic FSP file should include the generic FSP support header, not the FSP1 version. Fix it.
---
Changes in v3: None
Changes in v2: None
arch/x86/lib/fsp/fsp_support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/lib/fsp/fsp_support.c +1 -1
@@ -5,7 +5,7 @@*/ #include <common.h> -#include <asm/fsp1/fsp_support.h> +#include <asm/fsp/fsp_support.h> #include <asm/post.h> u32 fsp_get_usable_lowmem_top (const void *hob_list)
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 56/108 x86: fsp: Correct wrong header inlude in fsp_support.c
Quoted 4 lines · Simon Glass
This generic FSP file should include the generic FSP support header, not the FSP1 version. Fix it.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/lib/fsp/fsp_support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v3 57/108 x86: fsp: Add FSP2 base support
In reply to Simon GlassAdd support for some important configuration options and FSP memory init. The memory init uses swizzle tables from the device tree.
Support for the FSP_S binary is also included.
Bootstage timing is used for both FSP_M and FSP_M and memory-mapped SPI reads.
---
Changes in v3:
- Add a proper implementation of fsp_notify
- Add an fsp: tag
- Add bootstage timing for memory-mapped reads
- Add fsp_locate_fsp to locate an fsp component
- Add fspm_done() hook
- Add support for FSP-S component and VBT
- Simplify types for fsp_locate_fsp()
- Switch mmap to use SPI instead of SPI flash
Changes in v2: None
arch/x86/Kconfig | 61 ++++++++- arch/x86/include/asm/fsp2/fsp_api.h | 60 +++++++++ arch/x86/include/asm/fsp2/fsp_internal.h | 97 ++++++++++++++ arch/x86/lib/fsp2/Makefile | 10 ++ arch/x86/lib/fsp2/fsp_common.c | 13 ++ arch/x86/lib/fsp2/fsp_dram.c | 77 +++++++++++ arch/x86/lib/fsp2/fsp_init.c | 157 +++++++++++++++++++++++ arch/x86/lib/fsp2/fsp_meminit.c | 97 ++++++++++++++ arch/x86/lib/fsp2/fsp_silicon_init.c | 52 ++++++++ arch/x86/lib/fsp2/fsp_support.c | 129 +++++++++++++++++++ include/bootstage.h | 3 + 11 files changed, 754 insertions(+), 2 deletions(-) create mode 100644 arch/x86/include/asm/fsp2/fsp_api.h create mode 100644 arch/x86/include/asm/fsp2/fsp_internal.h create mode 100644 arch/x86/lib/fsp2/Makefile create mode 100644 arch/x86/lib/fsp2/fsp_common.c create mode 100644 arch/x86/lib/fsp2/fsp_dram.c create mode 100644 arch/x86/lib/fsp2/fsp_init.c create mode 100644 arch/x86/lib/fsp2/fsp_meminit.c create mode 100644 arch/x86/lib/fsp2/fsp_silicon_init.c create mode 100644 arch/x86/lib/fsp2/fsp_support.c
arch/x86/Kconfig +59 -2
@@ -326,7 +326,7 @@ config X86_RAMTEST config FLASH_DESCRIPTOR_FILE string "Flash descriptor binary filename" - depends on HAVE_INTEL_ME + depends on HAVE_INTEL_ME || FSP_VERSION2 default "descriptor.bin" help The filename of the file to use as flash descriptor in the
@@ -411,6 +411,63 @@ config FSP_ADDR The default base address of 0xfffc0000 indicates that the binary must be located at offset 0xc0000 from the beginning of a 1MB flash device. +if FSP_VERSION2 + +config FSP_FILE_T + string "Firmware-Support-Package binary filename (Temp RAM)" + default "fsp_t.bin" + help + The filename of the file to use for the temporary-RAM init phase from + the Firmware-Support-Package binary. Put this in the board directory. + It is used to set up an initial area of RAM which can be used for the + stack and other purposes, while bringing up the main system DRAM. + +config FSP_ADDR_T + hex "Firmware-Support-Package binary location (Temp RAM)" + default 0xffff8000 + help + FSP is not Position-Independent Code (PIC) and FSP components have to + be rebased if placed at a location which is different from the + perferred base address specified during the FSP build. Use Intel's + Binary Configuration Tool (BCT) to do the rebase. + +config FSP_FILE_M + string "Firmware-Support-Package binary filename (Memory Init)" + default "fsp_m.bin" + help + The filename of the file to use for the RAM init phase from the + Firmware Support Package binary. Put this in the board directory. + It is used to set up the main system DRAM and runs in SPL, once + temporary RAM (CAR) is working. + +config FSP_FILE_S + string "Firmware-Support-Package binary filename (Silicon Init)" + default "fsp_s.bin" + help + The filename of the file to use for the Silicon init phase from the + Firmware Support Package binary. Put this in the board directory. + It is used to set up the silicon to work correctly and must be + executed after DRAM is running. + +config FSP_FILE_VBT + string "Firmware-Support-Package Video BIOS Table (VBT)" + default "vbt.bin" + help + The filename of the file to use for the video data needd by the + Silicon init phase from the Firmware Support Package binary. Put this + in the board directory. It is used to set up the video parameters so + that the display can be used. + +config IFWI_INPUT_FILE + string "Filename containing FIT (Firmware Interface Table) with IFWI" + default "fitimage.bin" + help + The IFWI is obtained by running a tool on this file to extract the + IFWI. Put this in the board directory. The IFWI contains U-Boot TPL, + microcode and other internal items. + +endif + config FSP_TEMP_RAM_ADDR hex depends on FSP_VERSION1
@@ -629,7 +686,7 @@ config VBT_ADDR config VIDEO_FSP bool "Enable FSP framebuffer driver support" - depends on HAVE_VBT && DM_VIDEO + depends on (HAVE_VBT || FSP_VERSION2) && DM_VIDEO help Turn on this option to enable a framebuffer driver when U-Boot is using Video BIOS Table (VBT) image for FSP firmware to initialize
arch/x86/include/asm/fsp2/fsp_api.h new file +60 -0
60 lines not on this page · raw message
arch/x86/include/asm/fsp2/fsp_internal.h new file +97 -0
97 lines not on this page · raw message
arch/x86/lib/fsp2/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2019 Google LLC + +obj-y += fsp_common.o +obj-y += fsp_dram.o +obj-y += fsp_init.o +obj-y += fsp_meminit.o +obj-y += fsp_silicon_init.o +obj-y += fsp_support.o
arch/x86/lib/fsp2/fsp_common.c new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#include <common.h> +#include <init.h> + +int arch_fsp_init (void ) +{ +return 0 ; +}
arch/x86/lib/fsp2/fsp_dram.c new file +77 -0
77 lines not on this page · raw message
arch/x86/lib/fsp2/fsp_init.c new file +157 -0
157 lines not on this page · raw message
arch/x86/lib/fsp2/fsp_meminit.c new file +97 -0
97 lines not on this page · raw message
arch/x86/lib/fsp2/fsp_silicon_init.c new file +52 -0
52 lines not on this page · raw message
arch/x86/lib/fsp2/fsp_support.c new file +129 -0
129 lines not on this page · raw message
include/bootstage.h +3 -0
@@ -200,6 +200,9 @@ enum bootstage_id {BOOTSTATE_ID_ACCUM_DM_SPL ,BOOTSTATE_ID_ACCUM_DM_F ,BOOTSTATE_ID_ACCUM_DM_R , +BOOTSTATE_ID_ACCUM_FSP_M , +BOOTSTATE_ID_ACCUM_FSP_S , +BOOTSTAGE_ID_ACCUM_MMAP_SPI ,/* a few spare for the user, from here */ BOOTSTAGE_ID_USER,
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 57/108 x86: fsp: Add FSP2 base support
Hi Simon,
Quoted 7 lines · Simon Glass
Add support for some important configuration options and FSP memory init. The memory init uses swizzle tables from the device tree.
Support for the
FSP_Sbinary is also included.Bootstage timing is used for both
FSP_MandFSP_Mand memory-mapped SPI
FSP_T and FSP_M ?
Quoted 85 lines
reads.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Add a proper implementation offsp_notify
- Add an fsp: tag
- Add bootstage timing for memory-mapped reads
- Addfsp_locate_fspto locate an fsp component
- Addfspm_done()hook
- Add support for FSP-S component and VBT
- Simplify types forfsp_locate_fsp()
- Switch mmap to use SPI instead of SPI flashChanges in v2: None
arch/x86/Kconfig | 61 ++++++++- arch/x86/include/asm/fsp2/fsp_api.h | 60 +++++++++ arch/x86/include/asm/fsp2/fsp_internal.h | 97 ++++++++++++++ arch/x86/lib/fsp2/Makefile | 10 ++ arch/x86/lib/fsp2/fsp_common.c | 13 ++ arch/x86/lib/fsp2/fsp_dram.c | 77 +++++++++++ arch/x86/lib/fsp2/fsp_init.c | 157 +++++++++++++++++++++++ arch/x86/lib/fsp2/fsp_meminit.c | 97 ++++++++++++++ arch/x86/lib/fsp2/fsp_silicon_init.c | 52 ++++++++ arch/x86/lib/fsp2/fsp_support.c | 129 +++++++++++++++++++ include/bootstage.h | 3 + 11 files changed, 754 insertions(+), 2 deletions(-) create mode 100644 arch/x86/include/asm/fsp2/fsp_api.h create mode 100644 arch/x86/include/asm/fsp2/fsp_internal.h create mode 100644 arch/x86/lib/fsp2/Makefile create mode 100644 arch/x86/lib/fsp2/fsp_common.c create mode 100644 arch/x86/lib/fsp2/fsp_dram.c create mode 100644 arch/x86/lib/fsp2/fsp_init.c create mode 100644 arch/x86/lib/fsp2/fsp_meminit.c create mode 100644 arch/x86/lib/fsp2/fsp_silicon_init.c create mode 100644 arch/x86/lib/fsp2/fsp_support.carch/x86/Kconfig +30
-1@@ -326,7 +326,7 @@ config X86_RAMTEST config FLASH_DESCRIPTOR_FILE string "Flash descriptor binary filename" - depends on HAVE_INTEL_ME + depends on HAVE_INTEL_ME || FSP_VERSION2 default "descriptor.bin" help The filename of the file to use as flash descriptor in the@@ -411,6 +411,63 @@ config FSP_ADDR The default base address of 0xfffc0000 indicates that the binary must be located at offset 0xc0000 from the beginning of a 1MB flash device. +if FSP_VERSION2 + +config FSP_FILE_T + string "Firmware-Support-Package binary filename (Temp RAM)" + default "fsp_t.bin" + help + The filename of the file to use for the temporary-RAM init phase from + the Firmware-Support-Package binary. Put this in the board directory. + It is used to set up an initial area of RAM which can be used for the + stack and other purposes, while bringing up the main system DRAM. + +config FSP_ADDR_T + hex "Firmware-Support-Package binary location (Temp RAM)" + default 0xffff8000 + help + FSP is not Position-Independent Code (PIC) and FSP components have to + be rebased if placed at a location which is different from the + perferred base address specified during the FSP build. Use Intel's + Binary Configuration Tool (BCT) to do the rebase. + +config FSP_FILE_M + string "Firmware-Support-Package binary filename (Memory Init)" + default "fsp_m.bin" + help + The filename of the file to use for the RAM init phase from the + Firmware Support Package binary. Put this in the board directory. + It is used to set up the main system DRAM and runs in SPL, once + temporary RAM (CAR) is working. +
arch/x86/Kconfig config FSP_ADDR · line 452
Quoted 10 lines
arch/x86/Kconfig +10
-0+config FSP_FILE_S + string "Firmware-Support-Package binary filename (Silicon Init)" + default "fsp_s.bin" + help + The filename of the file to use for the Silicon init phase from the + Firmware Support Package binary. Put this in the board directory. + It is used to set up the silicon to work correctly and must be + executed after DRAM is running. + +config FSP_FILE_VBT
There is already a VBT_FILE config option for this.
Quoted 79 lines
arch/x86/Kconfig +19
-1+ string "Firmware-Support-Package Video BIOS Table (VBT)" + default "vbt.bin" + help + The filename of the file to use for the video data needd by the + Silicon init phase from the Firmware Support Package binary. Put this + in the board directory. It is used to set up the video parameters so + that the display can be used. + +config IFWI_INPUT_FILE + string "Filename containing FIT (Firmware Interface Table) with IFWI" + default "fitimage.bin" + help + The IFWI is obtained by running a tool on this file to extract the + IFWI. Put this in the board directory. The IFWI contains U-Boot TPL, + microcode and other internal items. + +endif + config FSP_TEMP_RAM_ADDR hex depends on FSP_VERSION1@@ -629,7 +686,7 @@ config VBT_ADDR config VIDEO_FSP bool "Enable FSP framebuffer driver support" - depends on HAVE_VBT && DM_VIDEO + depends on (HAVE_VBT || FSP_VERSION2) && DM_VIDEO help Turn on this option to enable a framebuffer driver when U-Boot is using Video BIOS Table (VBT) image for FSP firmware to initializearch/x86/include/asm/fsp2/fsp_api.h new file +43
-0@@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: Intel */ +/* +* Copyright (C) 2015-2016 Intel Corp. +* (Written by Andrey Petrov <[email protected]> for Intel Corp.) +* (Written by Alexandru Gagniuc <[email protected]> for Intel Corp.) +* Mostly taken from coreboot fsp2_0/memory_init.c +*/ + +#ifndef __ASM_FSP2_API_H +#define __ASM_FSP2_API_H + +#include <asm/fsp/fsp_api.h> + +struct fspm_upd ; +struct fsps_upd ; +struct hob_header ; + +enum fsp_boot_mode { +FSP_BOOT_WITH_FULL_CONFIGURATION =0x00 , +FSP_BOOT_WITH_MINIMAL_CONFIGURATION =0x01 , +FSP_BOOT_ASSUMING_NO_CONFIGURATION_CHANGES =0x02 , +FSP_BOOT_ON_S4_RESUME =0x05 , +FSP_BOOT_ON_S3_RESUME =0x11 , +FSP_BOOT_ON_FLASH_UPDATE =0x12 , +FSP_BOOT_IN_RECOVERY_MODE =0x20 +}; + +struct __packed fsp_upd_header { +u64 signature; +u8 revision; +u8 reserved[23 ]; +}; + +/** +* fsp_memory_init() - Init the SDRAM +* +* @s3wake: true if we are booting from resume, so cannot reinit the mememory +* from scatch since we will lose its contents +* @use_spi_flash: true to use the fast SPI driver to read FSP, otherwise use +* mapped SPI +* @return 0 if OK, -ve on error +*/ +int fsp_memory_init (bool s3wake,bool use_spi_flash);
arch/x86/include/asm/fsp2/fsp_api.h line 53
Quoted 10 lines
arch/x86/include/asm/fsp2/fsp_api.h new file +10
-0+ +typedef asmlinkage int (*fsp_memory_init_func)(struct fspm_upd *params, +struct hob_header **hobp); + +/** +* fsp_silicon_init() - Init the silicon +* +* This calls the FSP's 'silicon init' entry point +* +* @s3wake: true if we are booting from resume
Should have the same descriptions as fsp_memory_init()
Quoted 49 lines
arch/x86/include/asm/fsp2/fsp_api.h new file +7
-0+* @return 0 if OK, -ve on error +*/ +int fsp_silicon_init (bool s3wake,bool use_spi_flash); + +typedef asmlinkage int (*fsp_silicon_init_func)(struct fsps_upd *params); + +#endif arch/x86/include/asm/fsp2/fsp_internal.h new file +36
-0@@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: Intel */ +/* +* Copyright (C) 2015-2016 Intel Corp. +* (Written by Alexandru Gagniuc <[email protected]> for Intel Corp.) +* Mostly taken from coreboot +*/ + +#ifndef __ASM_FSP_INTERNAL_H +#define __ASM_FSP_INTERNAL_H + +struct binman_entry ; +struct fsp_header ; +struct fspm_upd ; +struct fsps_upd ; + +enum fsp_type_t { +FSP_M , +FSP_S , +}; + +int fsp_get_header (ulong offset,ulong size,bool use_spi_flash, +struct fsp_header **fspp); + +/** +* fsp_locate_fsp() - Locate an FSP component +* +* This finds an FSP component by various methods. It is not as general-purpose +* as it looks, since it expects FSP-M to be requested in SPL (only), and FSP-S +* to be requested in U-Boot proper. +* +* @type: Component to locate +* @entry: Returns location of component +* @use_spi_flash: true to read using the Fast SPI driver, false to use +* memory-mapped SPI flash +* @devp: Returns northbridge device +* @hdrp: Returns FSP header
arch/x86/include/asm/fsp2/fsp_internal.h line 46
Quoted 10 lines
arch/x86/include/asm/fsp2/fsp_internal.h new file +10
-0+* @rom_offsetp: If non-NULL, returns the offset to add to any image position to +* find the memory-mapped location of that position. For example, for ROM +* position 0x1000, it will be mapped into 0x1000 + *rom_offsetp. +*/ +int fsp_locate_fsp (enum fsp_type_t type,struct binman_entry *entry, +bool use_spi_flash,struct udevice **devp, +struct fsp_header **hdrp,ulong *rom_offsetp); + +/** +* arch_fsp_s_preinit() - Perform init needed before calling FSP-S
Considering other routines in this file are having fspm_ as the prefix, should we name this function to arch_fsps_preinit()?
Or rename others to fsp_m_ as the prefix?
Quoted 194 lines
arch/x86/include/asm/fsp2/fsp_internal.h new file +51
-0+* +* This allows use of probed drivers and PCI so is a convenient place to do any +* init that is needed before FSP-S is called. After this, U-Boot relocates and +* calls arch_fsp_init_r() before PCI is probed, and that function is not +* allowed to probe PCI before calling FSP-S. +*/ +int arch_fsp_s_preinit (void ); + +/** +* fspm_update_config() - Set up the config structure for FSP-M +* +* @dev: Hostbridge device containing config +* @upd: Config data to fill in +* @return 0 if OK, -ve on error +*/ +int fspm_update_config (struct udevice *dev,struct fspm_upd *upd); + +/** +* fspm_done() - Indicate that memory init is complete +* +* This allows the board to do whatever post-init it needs before things +* continue. +* +* @dev: Hostbridge device +* @return 0 if OK, -ve on error +*/ +int fspm_done (struct udevice *dev); + +/** +* fsps_update_config() - Set up the config structure for FSP-S +* +* @dev: Hostbridge device containing config +* @rom_offset: Value to add to convert from ROM offset to memory-mapped address +* @upd: Config data to fill in +* @return 0 if OK, -ve on error +*/ +int fsps_update_config (struct udevice *dev,ulong rom_offset, +struct fsps_upd *upd); + +/** +* prepare_mrc_cache() - Read the MRC cache into the product-data struct +* +* This looks for cached Memory-reference code (MRC) data and stores it into +* @upd for use by the FSP-M binary. +* +* @return 0 if OK, -ENOENT if no data (whereupon the caller can continue and +* expect a slower boot), other -ve value on other error +*/ +int prepare_mrc_cache (struct fspm_upd *upd); + +#endif arch/x86/lib/fsp2/Makefile new file +10
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2019 Google LLC + +obj-y += fsp_common.o +obj-y += fsp_dram.o +obj-y += fsp_init.o +obj-y += fsp_meminit.o +obj-y += fsp_silicon_init.o +obj-y += fsp_support.oarch/x86/lib/fsp2/fsp_common.c new file +13
-0@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#include <common.h> +#include <init.h> + +int arch_fsp_init (void ) +{ +return 0 ; +}arch/x86/lib/fsp2/fsp_dram.c new file +77
-0@@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#include <common.h> +#include <acpi_s3.h> +#include <handoff.h> +#include <spl.h> +#include <asm/arch/cpu.h> +#include <asm/fsp/fsp_support.h> +#include <asm/fsp2/fsp_api.h> +#include <asm/fsp2/fsp_internal.h> + +int dram_init (void ) +{ +int ret; + +if (spl_phase () ==PHASE_SPL ) { +#ifdef CONFIG_HAVE_ACPI_RESUME +bool s3wake = gd->arch.prev_sleep_state ==ACPI_S3 ; +#else +bool s3wake = false; +#endif + + ret =fsp_memory_init (s3wake,BOOT_FROM_FAST_SPI_FLASH ); +if (ret) { +debug ("Memory init failed (err=%x)\n" , ret); +return ret; + } + +/* The FSP has already set up DRAM, so grab the info we need */ + ret =fsp_scan_for_ram_size (); +if (ret) +return ret; + +#ifdef CONFIG_ENABLE_MRC_CACHE + gd->arch.mrc[MRC_TYPE_NORMAL ].buf = +fsp_get_nvs_data (gd->arch.hob_list, + &gd->arch.mrc[MRC_TYPE_NORMAL ].len); + gd->arch.mrc[MRC_TYPE_VAR ].buf = +fsp_get_var_nvs_data (gd->arch.hob_list, + &gd->arch.mrc[MRC_TYPE_VAR ].len); +log_debug ("normal %x, var %x\n" , + gd->arch.mrc[MRC_TYPE_NORMAL ].len, + gd->arch.mrc[MRC_TYPE_VAR ].len); +#endif + }else { +#if CONFIG_IS_ENABLED (HANDOFF ) +struct spl_handoff *ho = gd->spl_handoff; + +if (!ho) { +debug ("No SPL handoff found\n" ); +return -ESTRPIPE ; + } + gd->ram_size = ho->ram_size; +handoff_load_dram_banks (ho); +#endif + ret =arch_fsp_s_preinit (); +if (ret) +return log_msg_ret ("fsp_s_preinit" , ret); + } + +return 0 ; +} + +ulong board_get_usable_ram_top (ulong total_size) +{ +#if CONFIG_IS_ENABLED (HANDOFF ) +struct spl_handoff *ho = gd->spl_handoff; + +return ho->arch.usable_ram_top; +#endif + +return gd->ram_top; +}arch/x86/lib/fsp2/fsp_init.c new file +19
-0@@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2019 Google LLC +*/ + +#include <common.h> +#include <binman.h> +#include <binman_sym.h> +#include <cbfs.h> +#include <dm.h> +#include <init.h> +#include <spi.h> +#include <spl.h> +#include <spi_flash.h> +#include <asm/arch/gpio.h> +#include <dm/uclass-internal.h> +#include <asm/fsp2/fsp_internal.h> + +int arch_cpu_init_dm (void )
arch/x86/lib/fsp2/fsp_init.c line 29
Quoted 10 lines
arch/x86/lib/fsp2/fsp_init.c new file +10
-0+{ +struct udevice *dev; +ofnode node; +int ret; + +if (spl_phase () !=PHASE_BOARD_F ) +return 0 ; + +/* Probe all GPIO devices to set up the pads */ + ret =uclass_first_device_err (UCLASS_GPIO , &dev);
Why is this GPIO probe needed in the generic FSP support?
Quoted 7 lines
arch/x86/lib/fsp2/fsp_init.c new file +7
-0+if (ret) +return log_msg_ret ("no fsp GPIO" , ret); + node =ofnode_path ("fsp" ); +if (!ofnode_valid (node)) +return log_msg_ret ("no fsp params" , -EINVAL ); + ret =hostbridge_config_pads_for_node (dev, node); +if (ret)
arch/x86/lib/fsp2/fsp_init.c line 46
Quoted 10 lines
arch/x86/lib/fsp2/fsp_init.c new file +10
-0+return log_msg_ret ("pad config" , ret); + +return ret; +} + +#if !defined(CONFIG_TPL_BUILD ) +binman_sym_declare (ulong, intel_fsp_m, image_pos); +binman_sym_declare (ulong, intel_fsp_m, size); + +static int get_coreboot_fsp(enum fsp_type_t type, ulong map_base,
get_uboot_fsp?
arch/x86/lib/fsp2/fsp_init.c line 49
Quoted 3 lines
arch/x86/lib/fsp2/fsp_init.c new file +3
-0+ struct binman_entry *entry) +{ +/* Hard-coded position of CBFS in ROM */
Why hard-coded?
Quoted 55 lines
arch/x86/lib/fsp2/fsp_init.c new file +55
-0+ulong cbfs_base =0x205000 ; +ulong cbfs_size =0x1bb000 ; +struct cbfs_priv *cbfs; +int ret; + + ret =cbfs_init_mem (map_base + cbfs_base, cbfs_size, &cbfs); +if (ret) +return ret; +if (!ret) { +const struct cbfs_cachenode *node; + + node =cbfs_find_file (cbfs,"fspm.bin" ); +if (!node) +return log_msg_ret ("fspm node" , -ENOENT ); + + entry->image_pos = (ulong )node->data; + entry->size = node->data_length; + } + +return 0 ; +} + +int fsp_locate_fsp (enum fsp_type_t type,struct binman_entry *entry, +bool use_spi_flash,struct udevice **devp, +struct fsp_header **hdrp,ulong *rom_offsetp) +{ +ulong mask =CONFIG_ROM_SIZE -1 ; +struct udevice *dev; +ulong rom_offset =0 ; +uint map_size; +ulong map_base; +uint offset; +int ret; + +/* +* Find the devices but don't probe them, since we don't want to +* auto-config PCI before silicon init runs +*/ + ret =uclass_find_first_device (UCLASS_NORTHBRIDGE , &dev); +if (ret) +return log_msg_ret ("Cannot get northbridge" , ret); +if (!use_spi_flash) { +struct udevice *sf; + +/* Just use the SPI driver to get the memory map */ + ret =uclass_find_first_device (UCLASS_SPI_FLASH , &sf); +if (ret) +return log_msg_ret ("Cannot get SPI flash" , ret); + ret =dm_spi_get_mmap (sf, &map_base, &map_size, &offset); +if (ret) +return log_msg_ret ("Could not get flash mmap" , ret); + } + +if (spl_phase () >=PHASE_BOARD_F ) { +if (type !=FSP_S )
arch/x86/lib/fsp2/fsp_init.c line 114
Quoted 10 lines
arch/x86/lib/fsp2/fsp_init.c new file +10
-0+return -EPROTONOSUPPORT ; + ret =binman_entry_find ("intel-fsp-s" , entry); +if (ret) +return log_msg_ret ("binman entry" , ret); +if (!use_spi_flash) + rom_offset = (map_base & mask) -CONFIG_ROM_SIZE ; + }else { + ret = -ENOENT ; +if (false) +/* Support using a hybrid image build by coreboot */
U-Boot?
Quoted 233 lines
arch/x86/lib/fsp2/fsp_init.c new file +43
-0+ ret =get_coreboot_fsp (type, map_base, entry); +if (ret) { +ulong mask =CONFIG_ROM_SIZE -1 ; + +if (type !=FSP_M ) +return -EPROTONOSUPPORT ; + entry->image_pos =binman_sym (ulong, intel_fsp_m, + image_pos); + entry->size =binman_sym (ulong, intel_fsp_m, size); +if (entry->image_pos !=BINMAN_SYM_MISSING ) { + ret =0 ; +if (use_spi_flash) + entry->image_pos &= mask; +else + entry->image_pos += (map_base & mask); + }else { + ret = -ENOENT ; + } + } + } +if (ret) +return log_msg_ret ("Cannot find FSP" , ret); + entry->image_pos += rom_offset; + +/* +* Account for the time taken to read memory-mapped SPI flash since in +* this case we don't use the SPI driver and BOOTSTAGE_ID_ACCUM_SPI. +*/ +if (!use_spi_flash) +bootstage_start (BOOTSTAGE_ID_ACCUM_MMAP_SPI ,"mmap_spi" ); + ret =fsp_get_header (entry->image_pos, entry->size, use_spi_flash, + hdrp); +if (!use_spi_flash) +bootstage_accum (BOOTSTAGE_ID_ACCUM_MMAP_SPI ); +if (ret) +return log_msg_ret ("fsp_get_header" , ret); + *devp = dev; +if (rom_offsetp) + *rom_offsetp = rom_offset; + +return 0 ; +} +#endif arch/x86/lib/fsp2/fsp_meminit.c new file +97
-0@@ -0,0 +1,97 @@ +// SPDX-License-Identifier: Intel +/* +* Copyright (C) 2015-2016 Intel Corp. +* (Written by Andrey Petrov <[email protected]> for Intel Corp.) +* (Written by Alexandru Gagniuc <[email protected]> for Intel Corp.) +* Mostly taken from coreboot fsp2_0/memory_init.c +*/ + +#include <common.h> +#include <binman.h> +#include <asm/mrccache.h> +#include <asm/fsp/fsp_infoheader.h> +#include <asm/fsp2/fsp_api.h> +#include <asm/fsp2/fsp_internal.h> +#include <asm/arch/fsp/fsp_configs.h> +#include <asm/arch/fsp/fsp_m_upd.h> + +static int prepare_mrc_cache_type (enum mrc_type_t type, +struct mrc_data_container **cachep) +{ +struct mrc_data_container *cache; +struct mrc_region entry; +int ret; + + ret =mrccache_get_region (type,NULL , &entry); +if (ret) +return ret; + cache =mrccache_find_current (&entry); +if (!cache) +return -ENOENT ; + +log_debug ("MRC at %x, size %x\n" , (uint )cache->data, cache->data_size); + *cachep = cache; + +return 0 ; +} + +int prepare_mrc_cache (struct fspm_upd *upd) +{ +struct mrc_data_container *cache; +int ret; + + ret =prepare_mrc_cache_type (MRC_TYPE_NORMAL , &cache); +if (ret) +return log_msg_ret ("Cannot get normal cache" , ret); + upd->arch.nvs_buffer_ptr = cache->data; + + ret =prepare_mrc_cache_type (MRC_TYPE_VAR , &cache); +if (ret) +return log_msg_ret ("Cannot get var cache" , ret); + upd->config.variable_nvs_buffer_ptr = cache->data; + +return 0 ; +} + +int fsp_memory_init (bool s3wake,bool use_spi_flash) +{ +struct fspm_upd upd, *fsp_upd; +fsp_memory_init_func func; +struct binman_entry entry; +struct fsp_header *hdr; +struct hob_header *hob; +struct udevice *dev; +int ret; + + ret =fsp_locate_fsp (FSP_M , &entry, use_spi_flash, &dev, &hdr,NULL ); +if (ret) +return log_msg_ret ("locate FSP" , ret); +debug ("Found FSP_M at %x, size %x\n" , hdr->img_base, hdr->img_size); + +/* Copy over the default config */ + fsp_upd = (struct fspm_upd *)(hdr->img_base + hdr->cfg_region_off); +if (fsp_upd->header.signature !=FSPM_UPD_SIGNATURE ) +return log_msg_ret ("Bad UPD signature" , -EPERM ); +memcpy (&upd, fsp_upd,sizeof (upd)); + + ret =fspm_update_config (dev, &upd); +if (ret) +return log_msg_ret ("Could not setup config" , ret); + +debug ("SDRAM init..." ); +bootstage_start (BOOTSTATE_ID_ACCUM_FSP_M ,"fsp-m" ); + func = (fsp_memory_init_func)(hdr->img_base + hdr->fsp_mem_init); + ret =func (&upd, &hob); +bootstage_accum (BOOTSTATE_ID_ACCUM_FSP_M ); +if (ret) +return log_msg_ret ("SDRAM init fail\n" , ret); + + gd->arch.hob_list = hob; +debug ("done\n" ); + + ret =fspm_done (dev); +if (ret) +return log_msg_ret ("fsm_done\n" , ret); + +return 0 ; +}arch/x86/lib/fsp2/fsp_silicon_init.c new file +52
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: Intel +/* +* Copyright (C) 2015-2016 Intel Corp. +* (Written by Andrey Petrov <[email protected]> for Intel Corp.) +* +* Mostly taken from coreboot fsp2_0/silicon_init.c +*/ + +#include <common.h> +#include <binman.h> +#include <dm.h> +#include <asm/arch/fsp/fsp_configs.h> +#include <asm/arch/fsp/fsp_s_upd.h> +#include <asm/fsp/fsp_infoheader.h> +#include <asm/fsp2/fsp_internal.h> + +int fsp_silicon_init (bool s3wake,bool use_spi_flash) +{ +struct fsps_upd upd, *fsp_upd; +fsp_silicon_init_func func; +struct fsp_header *hdr; +struct binman_entry entry; +struct udevice *dev; +ulong rom_offset =0 ; +int ret; + + ret =fsp_locate_fsp (FSP_S , &entry, use_spi_flash, &dev, &hdr, + &rom_offset); +if (ret) +return log_msg_ret ("locate FSP" , ret); + gd->arch.fsp_s_hdr = hdr; + +/* Copy over the default config */ + fsp_upd = (struct fsps_upd *)(hdr->img_base + hdr->cfg_region_off); +if (fsp_upd->header.signature !=FSPS_UPD_SIGNATURE ) +return log_msg_ret ("Bad UPD signature" , -EPERM ); +memcpy (&upd, fsp_upd,sizeof (upd)); + + ret =fsps_update_config (dev, rom_offset, &upd); +if (ret) +return log_msg_ret ("Could not setup config" , ret); +log_debug ("Silicon init..." ); +bootstage_start (BOOTSTATE_ID_ACCUM_FSP_S ,"fsp-s" ); + func = (fsp_silicon_init_func)(hdr->img_base + hdr->fsp_silicon_init); + ret =func (&upd); +bootstage_accum (BOOTSTATE_ID_ACCUM_FSP_S ); +if (ret) +return log_msg_ret ("Silicon init fail\n" , ret); +log_debug ("done\n" ); + +return 0 ; +}arch/x86/lib/fsp2/fsp_support.c new file +23
-0@@ -0,0 +1,129 @@ +// SPDX-License-Identifier: Intel +/* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#include <common.h> +#include <dm.h> +#include <spi_flash.h> +#include <asm/fsp/fsp_support.h> +#include <asm/fsp2/fsp_internal.h> + +/* The amount of the FSP header to probe to obtain what we need */ +#define PROBE_BUF_SIZE 0x180 + +/* Not needed in SPL apparently */ +#define SAFETY_MARGIN 0 + +int fsp_get_header (ulong offset,ulong size,bool use_spi_flash, +struct fsp_header **fspp) +{ +static efi_guid_t guid =FSP_HEADER_GUID ; +struct fv_ext_header *exhdr;
arch/x86/lib/fsp2/fsp_support.c line 33
Quoted 10 lines
arch/x86/lib/fsp2/fsp_support.c new file +10
-0+struct fsp_header *fsp; +struct ffs_file_header *file_hdr; +struct fv_header *fv; +struct raw_section *raw; +void *ptr, *base; +u8 buf[PROBE_BUF_SIZE ]; +struct udevice *dev; +int ret; + +/* You are in a maze of twisty headers all alike */
What does this comment mean?
Quoted 101 lines
arch/x86/lib/fsp2/fsp_support.c new file +96
-0+debug ("offset=%x buf=%x\n" , (uint )offset, (uint )buf); +if (use_spi_flash) { + ret =uclass_first_device_err (UCLASS_SPI_FLASH , &dev); +if (ret) +return log_msg_ret ("Cannot find flash device" , ret); + ret =spi_flash_read_dm (dev, offset,PROBE_BUF_SIZE , buf); +if (ret) +return log_msg_ret ("Cannot read flash" , ret); + }else { +memcpy (buf, (void *)offset,PROBE_BUF_SIZE ); + } + +/* Initalise the FSP base */ + ptr = buf; + fv = ptr; + +/* Check the FV signature, _FVH */ +debug ("offset=%x sign=%x\n" , (uint )offset, (uint )fv->sign); +if (fv->sign !=EFI_FVH_SIGNATURE ) +return log_msg_ret ("Base FV signature" , -EINVAL ); + +/* Go to the end of the FV header and align the address */ +debug ("fv->ext_hdr_off = %x\n" , fv->ext_hdr_off); + ptr += fv->ext_hdr_off; + exhdr = ptr; + ptr +=ALIGN (exhdr->ext_hdr_size,8 ); +debug ("ptr=%x\n" , ptr - (void *)buf); + +/* Check the FFS GUID */ + file_hdr = ptr; +if (memcmp (&file_hdr->name, &guid,sizeof (guid))) +return log_msg_ret ("Base FFS GUID" , -ENXIO ); +/* Add the FFS header size to find the raw section header */ + ptr = file_hdr +1 ; + + raw = ptr; +debug ("raw->type = %x\n" , raw->type); +if (raw->type !=EFI_SECTION_RAW ) +return log_msg_ret ("Section type not RAW" , -ENOEXEC ); + +/* Add the raw section header size to find the FSP header */ + ptr = raw +1 ; + fsp = ptr; + +/* Check the FSPH header */ +debug ("fsp %x\n" , (uint )fsp); +if (fsp->sign !=EFI_FSPH_SIGNATURE ) +return log_msg_ret ("Base FSPH signature" , -EACCES ); + + base = (void *)fsp->img_base; +debug ("Image base %x\n" , (uint )base); +debug ("Image addr %x\n" , (uint )fsp->fsp_mem_init); +if (use_spi_flash) { + ret =spi_flash_read_dm (dev, offset, size +SAFETY_MARGIN , + base); +if (ret) +return log_msg_ret ("Could not read FPS-M" , ret); + }else { +memcpy (base, (void *)offset, size +SAFETY_MARGIN ); + } + ptr = base + (ptr - (void *)buf); + *fspp = ptr; + +return 0 ; +} + +u32 fsp_notify (struct fsp_header *fsp_hdr,u32 phase) +{ +fsp_notify_f notify; +struct fsp_notify_params params; +struct fsp_notify_params *params_ptr; +u32 status; + +if (!fsp_hdr) + fsp_hdr = gd->arch.fsp_s_hdr; + +if (!fsp_hdr) +return log_msg_ret ("no FSP" , -ENOENT ); + + notify = (fsp_notify_f)(fsp_hdr->img_base + fsp_hdr->fsp_notify); + params.phase = phase; + params_ptr = ¶ms; + +/* +* Use ASM code to ensure correct parameter is on the stack for +* FspNotify as U-Boot is using different ABI from FSP +*/ + asmvolatile ( +"pushl %1;" /* push notify phase */ +"call *%%eax;" /* call FspNotify */ +"addl $4, %%esp;" /* clean up the stack */ + :"=a" (status) :"m" (params_ptr),"a" (notify),"m" (*params_ptr) + ); + +return status; +}include/bootstage.h +0
-0
include/bootstage.h enum bootstage_id {
Quoted 10 lines
include/bootstage.h +3
-1@@ -200,6 +200,9 @@ enum bootstage_id {BOOTSTATE_ID_ACCUM_DM_SPL ,BOOTSTATE_ID_ACCUM_DM_F ,BOOTSTATE_ID_ACCUM_DM_R , +BOOTSTATE_ID_ACCUM_FSP_M , +BOOTSTATE_ID_ACCUM_FSP_S , +BOOTSTAGE_ID_ACCUM_MMAP_SPI ,/* a few spare for the user, from here */ BOOTSTAGE_ID_USER, --
Regards,
Bin
PATCH v3 57/108 x86: fsp: Add FSP2 base support
Hi BIn,
Quoted 5 lines · Bin Meng
Hi Simon,
Quoted 1 line · Simon Glass
Quoted 8 lines
Quoted 6 lines
Add support for some important configuration options and FSP memory init. The memory init uses swizzle tables from the device tree.
Support for the
FSP_Sbinary is also included.Bootstage timing is used for both
FSP_MandFSP_Mand memory-mapped SPI
FSP_TandFSP_M?
Will fix
Quoted 90 lines
Quoted 90 lines
reads.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Add a proper implementation offsp_notify
- Add an fsp: tag
- Add bootstage timing for memory-mapped reads
- Addfsp_locate_fspto locate an fsp component
- Addfspm_done()hook
- Add support for FSP-S component and VBT
- Simplify types forfsp_locate_fsp()
- Switch mmap to use SPI instead of SPI flashChanges in v2: None
arch/x86/Kconfig | 61 ++++++++- arch/x86/include/asm/fsp2/fsp_api.h | 60 +++++++++ arch/x86/include/asm/fsp2/fsp_internal.h | 97 ++++++++++++++ arch/x86/lib/fsp2/Makefile | 10 ++ arch/x86/lib/fsp2/fsp_common.c | 13 ++ arch/x86/lib/fsp2/fsp_dram.c | 77 +++++++++++ arch/x86/lib/fsp2/fsp_init.c | 157 +++++++++++++++++++++++ arch/x86/lib/fsp2/fsp_meminit.c | 97 ++++++++++++++ arch/x86/lib/fsp2/fsp_silicon_init.c | 52 ++++++++ arch/x86/lib/fsp2/fsp_support.c | 129 +++++++++++++++++++ include/bootstage.h | 3 + 11 files changed, 754 insertions(+), 2 deletions(-) create mode 100644 arch/x86/include/asm/fsp2/fsp_api.h create mode 100644 arch/x86/include/asm/fsp2/fsp_internal.h create mode 100644 arch/x86/lib/fsp2/Makefile create mode 100644 arch/x86/lib/fsp2/fsp_common.c create mode 100644 arch/x86/lib/fsp2/fsp_dram.c create mode 100644 arch/x86/lib/fsp2/fsp_init.c create mode 100644 arch/x86/lib/fsp2/fsp_meminit.c create mode 100644 arch/x86/lib/fsp2/fsp_silicon_init.c create mode 100644 arch/x86/lib/fsp2/fsp_support.carch/x86/Kconfig +34
-1@@ -326,7 +326,7 @@ config X86_RAMTEST config FLASH_DESCRIPTOR_FILE string "Flash descriptor binary filename" - depends on HAVE_INTEL_ME + depends on HAVE_INTEL_ME || FSP_VERSION2 default "descriptor.bin" help The filename of the file to use as flash descriptor in the@@ -411,6 +411,63 @@ config FSP_ADDR The default base address of 0xfffc0000 indicates that the binary must be located at offset 0xc0000 from the beginning of a 1MB flash device. +if FSP_VERSION2 + +config FSP_FILE_T + string "Firmware-Support-Package binary filename (Temp RAM)" + default "fsp_t.bin" + help + The filename of the file to use for the temporary-RAM init phase from + the Firmware-Support-Package binary. Put this in the board directory. + It is used to set up an initial area of RAM which can be used for the + stack and other purposes, while bringing up the main system DRAM. + +config FSP_ADDR_T + hex "Firmware-Support-Package binary location (Temp RAM)" + default 0xffff8000 + help + FSP is not Position-Independent Code (PIC) and FSP components have to + be rebased if placed at a location which is different from the + perferred base address specified during the FSP build. Use Intel's + Binary Configuration Tool (BCT) to do the rebase. + +config FSP_FILE_M + string "Firmware-Support-Package binary filename (Memory Init)" + default "fsp_m.bin" + help + The filename of the file to use for the RAM init phase from the + Firmware Support Package binary. Put this in the board directory. + It is used to set up the main system DRAM and runs in SPL, once + temporary RAM (CAR) is working. + +config FSP_FILE_S + string "Firmware-Support-Package binary filename (Silicon Init)" + default "fsp_s.bin" + help
Quoted 8 lines
arch/x86/Kconfig config FSP_ADDR · line 452
Quoted 6 lines
arch/x86/Kconfig +6
-0+ The filename of the file to use for the Silicon init phase from the + Firmware Support Package binary. Put this in the board directory. + It is used to set up the silicon to work correctly and must be + executed after DRAM is running. + +config FSP_FILE_VBTThere is already a
VBT_FILEconfig option for this.
Oops, will drop.
One issue here is that we are using hard-coded positions for things that don't need to be in a fixed place (I think). It makes it harder to avoid image overlays.
Now that we have a way to read symbols from binman, perhaps some of the addresses should be left out? Then binman can pack them automatically.
Quoted 147 lines
Quoted 80 lines
arch/x86/Kconfig +19
-1+ string "Firmware-Support-Package Video BIOS Table (VBT)" + default "vbt.bin" + help + The filename of the file to use for the video data needd by the + Silicon init phase from the Firmware Support Package binary. Put this + in the board directory. It is used to set up the video parameters so + that the display can be used. + +config IFWI_INPUT_FILE + string "Filename containing FIT (Firmware Interface Table) with IFWI" + default "fitimage.bin" + help + The IFWI is obtained by running a tool on this file to extract the + IFWI. Put this in the board directory. The IFWI contains U-Boot TPL, + microcode and other internal items. + +endif + config FSP_TEMP_RAM_ADDR hex depends on FSP_VERSION1@@ -629,7 +686,7 @@ config VBT_ADDR config VIDEO_FSP bool "Enable FSP framebuffer driver support" - depends on HAVE_VBT && DM_VIDEO + depends on (HAVE_VBT || FSP_VERSION2) && DM_VIDEO help Turn on this option to enable a framebuffer driver when U-Boot is using Video BIOS Table (VBT) image for FSP firmware to initializearch/x86/include/asm/fsp2/fsp_api.h new file +43
-0@@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: Intel */ +/* +* Copyright (C) 2015-2016 Intel Corp. +* (Written by Andrey Petrov <[email protected]> for Intel Corp.) +* (Written by Alexandru Gagniuc <[email protected]> for Intel Corp.) +* Mostly taken from coreboot fsp2_0/memory_init.c +*/ + +#ifndef __ASM_FSP2_API_H +#define __ASM_FSP2_API_H + +#include <asm/fsp/fsp_api.h> + +struct fspm_upd ; +struct fsps_upd ; +struct hob_header ; + +enum fsp_boot_mode { +FSP_BOOT_WITH_FULL_CONFIGURATION =0x00 , +FSP_BOOT_WITH_MINIMAL_CONFIGURATION =0x01 , +FSP_BOOT_ASSUMING_NO_CONFIGURATION_CHANGES =0x02 , +FSP_BOOT_ON_S4_RESUME =0x05 , +FSP_BOOT_ON_S3_RESUME =0x11 , +FSP_BOOT_ON_FLASH_UPDATE =0x12 , +FSP_BOOT_IN_RECOVERY_MODE =0x20 +}; + +struct __packed fsp_upd_header { +u64 signature; +u8 revision; +u8 reserved[23 ]; +}; + +/** +* fsp_memory_init() - Init the SDRAM +* +* @s3wake: true if we are booting from resume, so cannot reinit the mememory +* from scatch since we will lose its contents +* @use_spi_flash: true to use the fast SPI driver to read FSP, otherwise use +* mapped SPI +* @return 0 if OK, -ve on error +*/ +int fsp_memory_init (bool s3wake,bool use_spi_flash);arch/x86/include/asm/fsp2/fsp_api.h line 53
Quoted 10 lines
arch/x86/include/asm/fsp2/fsp_api.h new file +10
-0+ +typedef asmlinkage int (*fsp_memory_init_func)(struct fspm_upd *params, +struct hob_header **hobp); + +/** +* fsp_silicon_init() - Init the silicon +* +* This calls the FSP's 'silicon init' entry point +* +* @s3wake: true if we are booting from resume Should have the same descriptions as
fsp_memory_init()Quoted 54 lines
arch/x86/include/asm/fsp2/fsp_api.h new file +7
-0+* @return 0 if OK, -ve on error +*/ +int fsp_silicon_init (bool s3wake,bool use_spi_flash); + +typedef asmlinkage int (*fsp_silicon_init_func)(struct fsps_upd *params); + +#endif arch/x86/include/asm/fsp2/fsp_internal.h new file +41
-0@@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: Intel */ +/* +* Copyright (C) 2015-2016 Intel Corp. +* (Written by Alexandru Gagniuc <[email protected]> for Intel Corp.) +* Mostly taken from coreboot +*/ + +#ifndef __ASM_FSP_INTERNAL_H +#define __ASM_FSP_INTERNAL_H + +struct binman_entry ; +struct fsp_header ; +struct fspm_upd ; +struct fsps_upd ; + +enum fsp_type_t { +FSP_M , +FSP_S , +}; + +int fsp_get_header (ulong offset,ulong size,bool use_spi_flash, +struct fsp_header **fspp); + +/** +* fsp_locate_fsp() - Locate an FSP component +* +* This finds an FSP component by various methods. It is not as general-purpose +* as it looks, since it expects FSP-M to be requested in SPL (only), and FSP-S +* to be requested in U-Boot proper. +* +* @type: Component to locate +* @entry: Returns location of component +* @use_spi_flash: true to read using the Fast SPI driver, false to use +* memory-mapped SPI flash +* @devp: Returns northbridge device +* @hdrp: Returns FSP header +* @rom_offsetp: If non-NULL, returns the offset to add to any image position to +* find the memory-mapped location of that position. For example, for ROM +* position 0x1000, it will be mapped into 0x1000 + *rom_offsetp. +*/ +int fsp_locate_fsp(enum fsp_type_t type, struct binman_entry *entry,
Quoted 8 lines
arch/x86/include/asm/fsp2/fsp_internal.h line 46
Quoted 5 lines
arch/x86/include/asm/fsp2/fsp_internal.h new file +5
-0+ bool use_spi_flash, struct udevice **devp, + struct fsp_header **hdrp, ulong *rom_offsetp); + +/** +* arch_fsp_s_preinit() - Perform init needed before calling FSP-S Considering other routines in this file are having
fspm_as the prefix, should we name this function toarch_fsps_preinit()?
Will do.
Quoted 201 lines
Or rename others to
fsp_m_as the prefix?Quoted 198 lines
arch/x86/include/asm/fsp2/fsp_internal.h new file +51
-0+* +* This allows use of probed drivers and PCI so is a convenient place to do any +* init that is needed before FSP-S is called. After this, U-Boot relocates and +* calls arch_fsp_init_r() before PCI is probed, and that function is not +* allowed to probe PCI before calling FSP-S. +*/ +int arch_fsp_s_preinit (void ); + +/** +* fspm_update_config() - Set up the config structure for FSP-M +* +* @dev: Hostbridge device containing config +* @upd: Config data to fill in +* @return 0 if OK, -ve on error +*/ +int fspm_update_config (struct udevice *dev,struct fspm_upd *upd); + +/** +* fspm_done() - Indicate that memory init is complete +* +* This allows the board to do whatever post-init it needs before things +* continue. +* +* @dev: Hostbridge device +* @return 0 if OK, -ve on error +*/ +int fspm_done (struct udevice *dev); + +/** +* fsps_update_config() - Set up the config structure for FSP-S +* +* @dev: Hostbridge device containing config +* @rom_offset: Value to add to convert from ROM offset to memory-mapped address +* @upd: Config data to fill in +* @return 0 if OK, -ve on error +*/ +int fsps_update_config (struct udevice *dev,ulong rom_offset, +struct fsps_upd *upd); + +/** +* prepare_mrc_cache() - Read the MRC cache into the product-data struct +* +* This looks for cached Memory-reference code (MRC) data and stores it into +* @upd for use by the FSP-M binary. +* +* @return 0 if OK, -ENOENT if no data (whereupon the caller can continue and +* expect a slower boot), other -ve value on other error +*/ +int prepare_mrc_cache (struct fspm_upd *upd); + +#endif arch/x86/lib/fsp2/Makefile new file +10
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2019 Google LLC + +obj-y += fsp_common.o +obj-y += fsp_dram.o +obj-y += fsp_init.o +obj-y += fsp_meminit.o +obj-y += fsp_silicon_init.o +obj-y += fsp_support.oarch/x86/lib/fsp2/fsp_common.c new file +13
-0@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#include <common.h> +#include <init.h> + +int arch_fsp_init (void ) +{ +return 0 ; +}arch/x86/lib/fsp2/fsp_dram.c new file +77
-0@@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#include <common.h> +#include <acpi_s3.h> +#include <handoff.h> +#include <spl.h> +#include <asm/arch/cpu.h> +#include <asm/fsp/fsp_support.h> +#include <asm/fsp2/fsp_api.h> +#include <asm/fsp2/fsp_internal.h> + +int dram_init (void ) +{ +int ret; + +if (spl_phase () ==PHASE_SPL ) { +#ifdef CONFIG_HAVE_ACPI_RESUME +bool s3wake = gd->arch.prev_sleep_state ==ACPI_S3 ; +#else +bool s3wake = false; +#endif + + ret =fsp_memory_init (s3wake,BOOT_FROM_FAST_SPI_FLASH ); +if (ret) { +debug ("Memory init failed (err=%x)\n" , ret); +return ret; + } + +/* The FSP has already set up DRAM, so grab the info we need */ + ret =fsp_scan_for_ram_size (); +if (ret) +return ret; + +#ifdef CONFIG_ENABLE_MRC_CACHE + gd->arch.mrc[MRC_TYPE_NORMAL ].buf = +fsp_get_nvs_data (gd->arch.hob_list, + &gd->arch.mrc[MRC_TYPE_NORMAL ].len); + gd->arch.mrc[MRC_TYPE_VAR ].buf = +fsp_get_var_nvs_data (gd->arch.hob_list, + &gd->arch.mrc[MRC_TYPE_VAR ].len); +log_debug ("normal %x, var %x\n" , + gd->arch.mrc[MRC_TYPE_NORMAL ].len, + gd->arch.mrc[MRC_TYPE_VAR ].len); +#endif + }else { +#if CONFIG_IS_ENABLED (HANDOFF ) +struct spl_handoff *ho = gd->spl_handoff; + +if (!ho) { +debug ("No SPL handoff found\n" ); +return -ESTRPIPE ; + } + gd->ram_size = ho->ram_size; +handoff_load_dram_banks (ho); +#endif + ret =arch_fsp_s_preinit (); +if (ret) +return log_msg_ret ("fsp_s_preinit" , ret); + } + +return 0 ; +} + +ulong board_get_usable_ram_top (ulong total_size) +{ +#if CONFIG_IS_ENABLED (HANDOFF ) +struct spl_handoff *ho = gd->spl_handoff; + +return ho->arch.usable_ram_top; +#endif + +return gd->ram_top; +}arch/x86/lib/fsp2/fsp_init.c new file +23
-0@@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2019 Google LLC +*/ + +#include <common.h> +#include <binman.h> +#include <binman_sym.h> +#include <cbfs.h> +#include <dm.h> +#include <init.h> +#include <spi.h> +#include <spl.h> +#include <spi_flash.h> +#include <asm/arch/gpio.h> +#include <dm/uclass-internal.h> +#include <asm/fsp2/fsp_internal.h> + +int arch_cpu_init_dm (void ) +{ +struct udevice *dev; +ofnode node; +int ret;
Quoted 8 lines
arch/x86/lib/fsp2/fsp_init.c line 29
Quoted 6 lines
arch/x86/lib/fsp2/fsp_init.c new file +6
-0+ +if (spl_phase () !=PHASE_BOARD_F ) +return 0 ; + +/* Probe all GPIO devices to set up the pads */ + ret =uclass_first_device_err (UCLASS_GPIO , &dev);Why is this GPIO probe needed in the generic FSP support?
This is for pinctrl, to set up the pads. With v4 I am converting this to use pinctrl so it should be a little bit clearer. We need to set up the pins early on, before calling FSP-S.
I think every board will need to do this, so I think it makes sense to use generate code. What do you think?
Quoted 13 lines
Quoted 13 lines
arch/x86/lib/fsp2/fsp_init.c new file +11
-0+if (ret) +return log_msg_ret ("no fsp GPIO" , ret); + node =ofnode_path ("fsp" ); +if (!ofnode_valid (node)) +return log_msg_ret ("no fsp params" , -EINVAL ); + ret =hostbridge_config_pads_for_node (dev, node); +if (ret) +return log_msg_ret ("pad config" , ret); + +return ret; +}
Quoted 8 lines
arch/x86/lib/fsp2/fsp_init.c line 46
Quoted 6 lines
arch/x86/lib/fsp2/fsp_init.c new file +6
-0+ +#if !defined(CONFIG_TPL_BUILD ) +binman_sym_declare (ulong, intel_fsp_m, image_pos); +binman_sym_declare (ulong, intel_fsp_m, size); + +static int get_coreboot_fsp(enum fsp_type_t type, ulong map_base,
get_uboot_fsp?
Should be cbfs I'll add a comment as this is mostly for development.
Quoted 6 lines
arch/x86/lib/fsp2/fsp_init.c line 49
Quoted 4 lines
arch/x86/lib/fsp2/fsp_init.c new file +3
-0+ struct binman_entry *entry) +{ +/* Hard-coded position of CBFS in ROM */ Why hard-coded?
Just because this is for development and it doesn't seem worth adding code to read the FMAP. Will add a comment.
Quoted 60 lines
Quoted 60 lines
arch/x86/lib/fsp2/fsp_init.c new file +59
-0+ulong cbfs_base =0x205000 ; +ulong cbfs_size =0x1bb000 ; +struct cbfs_priv *cbfs; +int ret; + + ret =cbfs_init_mem (map_base + cbfs_base, cbfs_size, &cbfs); +if (ret) +return ret; +if (!ret) { +const struct cbfs_cachenode *node; + + node =cbfs_find_file (cbfs,"fspm.bin" ); +if (!node) +return log_msg_ret ("fspm node" , -ENOENT ); + + entry->image_pos = (ulong )node->data; + entry->size = node->data_length; + } + +return 0 ; +} + +int fsp_locate_fsp (enum fsp_type_t type,struct binman_entry *entry, +bool use_spi_flash,struct udevice **devp, +struct fsp_header **hdrp,ulong *rom_offsetp) +{ +ulong mask =CONFIG_ROM_SIZE -1 ; +struct udevice *dev; +ulong rom_offset =0 ; +uint map_size; +ulong map_base; +uint offset; +int ret; + +/* +* Find the devices but don't probe them, since we don't want to +* auto-config PCI before silicon init runs +*/ + ret =uclass_find_first_device (UCLASS_NORTHBRIDGE , &dev); +if (ret) +return log_msg_ret ("Cannot get northbridge" , ret); +if (!use_spi_flash) { +struct udevice *sf; + +/* Just use the SPI driver to get the memory map */ + ret =uclass_find_first_device (UCLASS_SPI_FLASH , &sf); +if (ret) +return log_msg_ret ("Cannot get SPI flash" , ret); + ret =dm_spi_get_mmap (sf, &map_base, &map_size, &offset); +if (ret) +return log_msg_ret ("Could not get flash mmap" , ret); + } + +if (spl_phase () >=PHASE_BOARD_F ) { +if (type !=FSP_S ) +return -EPROTONOSUPPORT ; + ret =binman_entry_find ("intel-fsp-s" , entry); +if (ret) +return log_msg_ret ("binman entry" , ret);
Quoted 8 lines
arch/x86/lib/fsp2/fsp_init.c line 114
Quoted 6 lines
arch/x86/lib/fsp2/fsp_init.c new file +6
-0+if (!use_spi_flash) + rom_offset = (map_base & mask) -CONFIG_ROM_SIZE ; + }else { + ret = -ENOENT ; +if (false) +/* Support using a hybrid image build by coreboot */ U-Boot?
No it is actually coreboot. It lets coreboot do the early stages so we can make sure U-Boot is doing the same things it should. See above.
[..]
Quoted 9 lines
Quoted 9 lines
arch/x86/lib/fsp2/fsp_init.c new file +9
-0+int fsp_get_header (ulong offset,ulong size,bool use_spi_flash, +struct fsp_header **fspp) +{ +static efi_guid_t guid =FSP_HEADER_GUID ; +struct fv_ext_header *exhdr; +struct fsp_header *fsp; +struct ffs_file_header *file_hdr; +struct fv_header *fv; +struct raw_section *raw;
Quoted 8 lines
arch/x86/lib/fsp2/fsp_init.c line 129
Quoted 6 lines
arch/x86/lib/fsp2/fsp_init.c new file +6
-0+void *ptr, *base; +u8 buf[PROBE_BUF_SIZE ]; +struct udevice *dev; +int ret; + +/* You are in a maze of twisty headers all alike */ What does this comment mean?
Web search it :-)
I'll expand the comment.
Regards,
Simon
PATCH v3 58/108 x86: fsp: Set up an MTRR for the graphics frame buffer
In reply to Simon GlassThe FSP-S may do this but at least for coral it does not. Set this up so that graphics is not deathly slow.
---
Changes in v3: None
Changes in v2: None
arch/x86/lib/fsp/fsp_graphics.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/lib/fsp/fsp_graphics.c +4 -0
@@ -8,6 +8,7 @@#include <vbe.h> #include <video.h> #include <asm/fsp/fsp_support.h> +#include <asm/mtrr.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -97,6 +98,9 @@ static int fsp_video_probe(struct udevice *dev)if (ret) goto err; +mtrr_add_request (MTRR_TYPE_WRCOMB , vesa->phys_base_ptr,256 <<20 ); +mtrr_commit (true); +printf ("%dx%dx%d\n" , uc_priv->xsize, uc_priv->ysize, vesa->bits_per_pixel);
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 58/108 x86: fsp: Set up an MTRR for the graphics frame buffer
Hi Simon,
Quoted 2 lines · Simon Glass
The FSP-S may do this but at least for coral it does not. Set this up so
This is confusing. Is this bug of the FSP-S on ApolloLake, or the FSP v2 spec does not say anything about it? Guess we need some clarification :)
Quoted 11 lines
that graphics is not deathly slow.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/lib/fsp/fsp_graphics.c | 4 ++++ 1 file changed, 4 insertions(+)
Regards,
Bin
PATCH v3 59/108 x86: fsp: Add a new arch_fsp_init_r() hook
In reply to Simon GlassWith FSP2 we need to run silicon init early after relocation. Add a new hook for this.
---
Changes in v3: None
Changes in v2: None
common/board_r.c | 3 +++ include/init.h | 11 +++++++++++ 2 files changed, 14 insertions(+)
common/board_r.c +3 -0
@@ -703,6 +703,9 @@ static init_fnc_t init_sequence_r[] = { efi_memory_init, #endif initr_binman, +#ifdef CONFIG_FSP_VERSION2 + arch_fsp_init_r, +#endif stdio_init_tables, initr_serial, initr_announce,
include/init.h +11 -0
@@ -65,6 +65,17 @@ int mach_cpu_init(void);*/ int arch_fsp_init (void ); +/** +* arch_fsp_init() - perform post-relocation firmware support package init +* +* Where U-Boot relies on binary blobs to handle part of the system init, this +* function can be used to set up the blobs. This is used on some Intel +* platforms. +* +* Return: 0 +*/ +int arch_fsp_init_r (void ); +int dram_init (void );/**
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 59/108 x86: fsp: Add a new arch_fsp_init_r() hook
Quoted 5 lines · Simon Glass
With FSP2 we need to run silicon init early after relocation. Add a new hook for this.
Signed-off-by Simon Glass <[email protected]>
Quoted 9 lines
---
Changes in v3: None
Changes in v2: Nonecommon/board_r.c | 3 +++ include/init.h | 11 +++++++++++ 2 files changed, 14 insertions(+)
PATCH v3 60/108 x86: fsp: Allow remembering the location of FSP-S
In reply to Simon GlassFSP-S is used by the notify call after it has been used for silicon init. To avoid having to load it again, add a field to store the location.
---
Changes in v3: None
Changes in v2: None
arch/x86/include/asm/global_data.h | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/include/asm/global_data.h +3 -0
@@ -119,6 +119,9 @@ struct arch_global_data {int prev_sleep_state;/* Previous sleep state ACPI_S0/1../5 */ ulong backup_mem;/* Backup memory address for S3 */ #endif +#ifdef CONFIG_FSP_VERSION2 +struct fsp_header *fsp_s_hdr;/* Pointer to FSP-S header */ +#endif };#endif
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 60/108 x86: fsp: Allow remembering the location of FSP-S
Quoted 4 lines · Simon Glass
FSP-S is used by the notify call after it has been used for silicon init. To avoid having to load it again, add a field to store the location.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/include/asm/global_data.h | 3 +++ 1 file changed, 3 insertions(+)
PATCH v3 61/108 x86: fsp: Make the notify API call common
In reply to Simon GlassThe fsp_notify() API is the same for FSP1 and FSP2. Move it into a new common API file.
---
Changes in v3: None
Changes in v2: None
arch/x86/include/asm/fsp/fsp_api.h | 27 +++++++++++++++++++++++++++ arch/x86/include/asm/fsp1/fsp_api.h | 21 +++------------------ 2 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 arch/x86/include/asm/fsp/fsp_api.h
arch/x86/include/asm/fsp/fsp_api.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: Intel */ +/* +* Copyright (C) 2015-2016 Intel Corp. +* (Written by Andrey Petrov <[email protected]> for Intel Corp.) +* (Written by Alexandru Gagniuc <[email protected]> for Intel Corp.) +* Mostly taken from coreboot fsp2_0/memory_init.c +*/ + +#ifndef __ASM_FSP_API_H +#define __ASM_FSP_API_H + +enum fsp_phase { +/* Notification code for post PCI enuermation */ +INIT_PHASE_PCI =0x20 , +/* Notification code before transferring control to the payload */ +INIT_PHASE_BOOT =0x40 +}; + +struct fsp_notify_params { +/* Notification phase used for NotifyPhase API */ +enum fsp_phase phase; +}; + +/* FspNotify API function prototype */ +typedef asmlinkage u32 (*fsp_notify_f)(struct fsp_notify_params *params); + +#endif
arch/x86/include/asm/fsp1/fsp_api.h +3 -18
@@ -4,11 +4,11 @@* Copyright (C) 2014, Bin Meng <[email protected]> */ -#ifndef __FSP_API_H__ -#define __FSP_API_H__ +#ifndef __FSP1_API_H__ +#define __FSP1_API_H__#include <linux/linkage.h> - +#include <asm/fsp/fsp_api.h> /* * FSP common configuration structure. * This needs to be included in the platform-specific struct fsp_config_data.
@@ -46,22 +46,7 @@ struct common_buf {u32 reserved[6 ];/* Reserved */ }; -enum fsp_phase { -/* Notification code for post PCI enuermation */ -INIT_PHASE_PCI =0x20 , -/* Notification code before transfering control to the payload */ -INIT_PHASE_BOOT =0x40 -}; - -struct fsp_notify_params { -/* Notification phase used for NotifyPhase API */ -enum fsp_phase phase; -}; -/* FspInit API function prototype */ typedef asmlinkage u32 (*fsp_init_f)(struct fsp_init_params *params); -/* FspNotify API function prototype */ -typedef asmlinkage u32 (*fsp_notify_f)(struct fsp_notify_params *params); -#endif
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 61/108 x86: fsp: Make the notify API call common
Quoted 21 lines · Simon Glass
The
fsp_notify()API is the same for FSP1 and FSP2. Move it into a new common API file.Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/include/asm/fsp/fsp_api.h | 27 +++++++++++++++++++++++++++ arch/x86/include/asm/fsp1/fsp_api.h | 21 +++------------------ 2 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 arch/x86/include/asm/fsp/fsp_api.harch/x86/include/asm/fsp/fsp_api.h new file +0
-0
arch/x86/include/asm/fsp/fsp_api.h line 6
Quoted 6 lines
arch/x86/include/asm/fsp/fsp_api.h new file +6
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: Intel */ +/* +* Copyright (C) 2015-2016 Intel Corp. +* (Written by Andrey Petrov <[email protected]> for Intel Corp.) +* (Written by Alexandru Gagniuc <[email protected]> for Intel Corp.) +* Mostly taken from coreboot fsp2_0/memory_init.c
nits: is this really from coreboot fsp2_0/memory_init.c?
Quoted 21 lines
arch/x86/include/asm/fsp/fsp_api.h new file +21
-0+*/ + +#ifndef __ASM_FSP_API_H +#define __ASM_FSP_API_H + +enum fsp_phase { +/* Notification code for post PCI enuermation */ +INIT_PHASE_PCI =0x20 , +/* Notification code before transferring control to the payload */ +INIT_PHASE_BOOT =0x40 +}; + +struct fsp_notify_params { +/* Notification phase used for NotifyPhase API */ +enum fsp_phase phase; +}; + +/* FspNotify API function prototype */ +typedef asmlinkage u32 (*fsp_notify_f)(struct fsp_notify_params *params); + +#endif
[snip]
PATCH v3 62/108 x86: Don't include the BIOS emulator in TPL
In reply to Simon GlassWe don't generally have enough space to run this, so don't build it into TPL. This helps reduce the size of TPL.
---
Changes in v3: None
Changes in v2: None
arch/x86/lib/Makefile | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/lib/Makefile +2 -0
@@ -4,9 +4,11 @@ # Wolfgang Denk, DENX Software Engineering, wd at denx.de. ifndef CONFIG_X86_64 +ifndef CONFIG_TPL_BUILD obj-y += bios.o obj-y += bios_asm.o obj-y += bios_interrupts.o +endif obj-y += string.o endif ifndef CONFIG_SPL_BUILD
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 63/108 x86: Add an option to include a FIT
In reply to Simon GlassMany Intel SoCs require a FIT in order to boot properly. Add an option to include this and enable it by default.
---
Changes in v3:
- Add help to CONFIG_FIT and don't make it 'default y'
Changes in v2: None
arch/x86/Kconfig | 9 +++++++++ arch/x86/dts/u-boot.dtsi | 6 ++++++ 2 files changed, 15 insertions(+)
arch/x86/Kconfig +9 -0
@@ -217,6 +217,15 @@ config SYS_X86_START16 depends on X86_RESET_VECTOR default 0xfffff800 +config X86_HAS_FIT + bool + default y + help + Enable inclusion of an Intel Firmware Interface Table (FIT) into the + image. This table is supposed to point to microcode and the like. So + far it is just a fixed table with the minimum set of headers, so that + it is actually present. + config X86_LOAD_FROM_32_BIT bool "Boot from a 32-bit program" help
arch/x86/dts/u-boot.dtsi +6 -0
@@ -82,6 +82,12 @@ u-boot-ucode { align = <16>; }; +#ifdef CONFIG_X86_HAS_FIT + intel-fit { + }; + intel-fit-ptr { + }; +#endif #ifdef CONFIG_HAVE_MRC intel-mrc { offset = <CONFIG_X86_MRC_ADDR>;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 63/108 x86: Add an option to include a FIT
Quoted 9 lines · Simon Glass
Many Intel SoCs require a FIT in order to boot properly. Add an option to include this and enable it by default.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Add help toCONFIG_FITand don't make it 'default y'
The changelog says "dont make it default y", but the commit message and the codes are still "default y".
Quoted 12 lines
Changes in v2: None
arch/x86/Kconfig | 9 +++++++++ arch/x86/dts/u-boot.dtsi | 6 ++++++ 2 files changed, 15 insertions(+)arch/x86/Kconfig +0
-0
arch/x86/Kconfig config SYS_X86_START16 · line 220
Quoted 4 lines
arch/x86/Kconfig +1
-0@@ -217,6 +217,15 @@ config SYS_X86_START16 depends on X86_RESET_VECTOR default 0xfffff800 +config X86_HAS_FIT
Can we rename this to HAVE_FIT? to be in consistent with other options like HAVE_INTEL_ME, HAVE_FSP?
Quoted 19 lines
arch/x86/Kconfig +8
-0+ bool + default y + help + Enable inclusion of an Intel Firmware Interface Table (FIT) into the + image. This table is supposed to point to microcode and the like. So + far it is just a fixed table with the minimum set of headers, so that + it is actually present. + config X86_LOAD_FROM_32_BIT bool "Boot from a 32-bit program" helparch/x86/dts/u-boot.dtsi +0
-0@@ -82,6 +82,12 @@ u-boot-ucode { align = <16>; };
arch/x86/dts/u-boot.dtsi
Quoted 10 lines
arch/x86/dts/u-boot.dtsi +6
-1+#ifdef CONFIG_X86_HAS_FIT + intel-fit { + }; + intel-fit-ptr { + }; +#endif #ifdef CONFIG_HAVE_MRC intel-mrc { offset = <CONFIG_X86_MRC_ADDR>; --
Regards,
Bin
PATCH v3 64/108 x86: Add support for newer CAR schemes
In reply to Simon GlassNewer Intel SoCs have different ways of setting up cache-as-ram (CAR). Add support for these along with suitable configuration options.
---
Changes in v3:
- Drop unneeded Kconfig file
Changes in v2: None
arch/x86/Kconfig | 16 + arch/x86/cpu/intel_common/Makefile | 8 + arch/x86/cpu/intel_common/car2.S | 490 ++++++++++++++++++++++++ arch/x86/cpu/intel_common/car2_uninit.S | 87 +++++ 4 files changed, 601 insertions(+) create mode 100644 arch/x86/cpu/intel_common/car2.S create mode 100644 arch/x86/cpu/intel_common/car2_uninit.S
arch/x86/Kconfig +16 -0
@@ -889,4 +889,20 @@ config HIGH_TABLE_SIZE Increse it if the default size does not fit the board's needs. This is most likely due to a large ACPI DSDT table is used. +config INTEL_CAR_CQOS + bool "Support Intel Cache Quality of Service" + help + Cache Quality of Service allows more fine-grained control of cache + usage. As result, it is possible to set up a portion of L2 cache for + CAR and use the remainder for actual caching. + +# +# Each bit in QOS mask controls this many bytes. This is calculated as: +# (CACHE_WAYS / CACHE_BITS_PER_MASK) * CACHE_LINE_SIZE * CACHE_SETS +# +config CACHE_QOS_SIZE_PER_BIT + hex + depends on INTEL_CAR_CQOS + default 0x20000 # 128 KB + endmenu
arch/x86/cpu/intel_common/Makefile +8 -0
@@ -8,6 +8,14 @@ obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += me_status.o obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += report_platform.o obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += mrc.o endif + +ifdef CONFIG_FSP_VERSION2 +obj-$(CONFIG_TPL_BUILD) += car2.o +ifndef CONFIG_SPL_BUILD +obj-y += car2_uninit.o +endif +endif + obj-y += cpu.o obj-y += fast_spi.o obj-y += lpc.o
arch/x86/cpu/intel_common/car2.S new file +490 -0
490 lines not on this page · raw message
arch/x86/cpu/intel_common/car2_uninit.S new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 64/108 x86: Add support for newer CAR schemes
Quoted 6 lines · Simon Glass
Newer Intel SoCs have different ways of setting up cache-as-ram (CAR). Add support for these along with suitable configuration options.
+#if ((
CONFIG_DCACHE_RAM_SIZE& (CONFIG_DCACHE_RAM_SIZE- 1)) == 0)
Perhaps it would be useful to have a generic macro
#define CONFIG_VALUE_IS_POWER_OF_2(_x) (CONFIG_##_x ...)
Quoted 5 lines
arch/x86/cpu/intel_common/car2.S new file +4
-0+#elif (CONFIG_DCACHE_RAM_SIZE == 768 * KiB) /* 768 KiB */ +#else +#error "DCACHE_RAM_SIZE is not a power of 2 and setup code is missing" +#endif
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 64/108 x86: Add support for newer CAR schemes
In reply to Simon GlassHi Simon,
Quoted 50 lines · Simon Glass
Newer Intel SoCs have different ways of setting up cache-as-ram (CAR). Add support for these along with suitable configuration options.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Drop unneededKconfigfileChanges in v2: None
arch/x86/Kconfig | 16 + arch/x86/cpu/intel_common/Makefile | 8 + arch/x86/cpu/intel_common/car2.S | 490 ++++++++++++++++++++++++ arch/x86/cpu/intel_common/car2_uninit.S | 87 +++++ 4 files changed, 601 insertions(+) create mode 100644 arch/x86/cpu/intel_common/car2.S create mode 100644 arch/x86/cpu/intel_common/car2_uninit.Sarch/x86/Kconfig +16
-0@@ -889,4 +889,20 @@ config HIGH_TABLE_SIZE Increse it if the default size does not fit the board's needs. This is most likely due to a large ACPI DSDT table is used. +config INTEL_CAR_CQOS + bool "Support Intel Cache Quality of Service" + help + Cache Quality of Service allows more fine-grained control of cache + usage. As result, it is possible to set up a portion of L2 cache for + CAR and use the remainder for actual caching. + +# +# Each bit in QOS mask controls this many bytes. This is calculated as: +# (CACHE_WAYS / CACHE_BITS_PER_MASK) * CACHE_LINE_SIZE * CACHE_SETS +# +config CACHE_QOS_SIZE_PER_BIT + hex + depends on INTEL_CAR_CQOS + default 0x20000 # 128 KB + endmenuarch/x86/cpu/intel_common/Makefile +0
-0
arch/x86/cpu/intel_common/Makefile obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += me_status.o · line 12
Quoted 5 lines
arch/x86/cpu/intel_common/Makefile +2
-0@@ -8,6 +8,14 @@ obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += me_status.o obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += report_platform.o obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += mrc.o endif + +ifdef CONFIG_FSP_VERSION2
The new CAR should not be dependent on FSP_VERSION2. It's OK that we implement a native U-Boot port without FSP2. Besides, when FSP2 FSP-T is used, the car2 is not needed too.
Quoted 19 lines
arch/x86/cpu/intel_common/Makefile +6
-0+obj-$(CONFIG_TPL_BUILD) += car2.o +ifndef CONFIG_SPL_BUILD +obj-y += car2_uninit.o +endif +endif + obj-y += cpu.o obj-y += fast_spi.o obj-y += lpc.oarch/x86/cpu/intel_common/car2.S new file +4
-0@@ -0,0 +1,490 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * This file is part of the coreboot project. + *
arch/x86/cpu/intel_common/car2.S line 14
Quoted 10 lines
arch/x86/cpu/intel_common/car2.S new file +10
-0+ * Copyright (C) 2015-2016 Intel Corp. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details.
The above license text is not needed, given SPDX format is already used.
Quoted 4 lines
arch/x86/cpu/intel_common/car2.S new file +4
-0+ * + */ + +#include <config.h>
arch/x86/cpu/intel_common/car2.S line 28
Quoted 10 lines
arch/x86/cpu/intel_common/car2.S new file +10
-0+#include <asm/msr-index.h> +#include <asm/mtrr.h> +#include <asm/post.h> +#include <asm/processor-flags.h> + +#define KiB 1024 + +.global car_init +car_init: + post_code(0x20)
Looks 0x20 is occupied by POST_CAR_SIPI. Can we use a macro, and a different value?
Please fix this globally in this file.
Quoted 4 lines
arch/x86/cpu/intel_common/car2.S new file +4
-0+ + /* + * Use the MTRR default type MSR as a proxy for detecting INIT#. + * Reset the system if any known bits are set in that MSR. That is
arch/x86/cpu/intel_common/car2.S line 42
Quoted 10 lines
arch/x86/cpu/intel_common/car2.S new file +10
-0+ * an indication of the CPU not being properly reset. + */ +check_for_clean_reset: + mov $MTRR_DEF_TYPE_MSR, %ecx + rdmsr + and $(MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN), %eax + cmp $0, %eax + jz no_reset + /* perform warm reset */ + movw $0xcf9, %dx
Use IO_PORT_RESET
arch/x86/cpu/intel_common/car2.S line 43
Quoted 1 line
arch/x86/cpu/intel_common/car2.S new file +1
-0+ movb $0x06, %al
Use (SYS_RST | RST_CPU)
Quoted 7 lines
arch/x86/cpu/intel_common/car2.S new file +7
-0+ outb %al, %dx + +no_reset: + post_code(0x21) + + /* Clear/disable fixed MTRRs */ + mov $fixed_mtrr_list_size, %ebx
arch/x86/cpu/intel_common/car2.S line 60
Quoted 10 lines
arch/x86/cpu/intel_common/car2.S new file +10
-0+ xor %eax, %eax + xor %edx, %edx + +clear_fixed_mtrr: + add $-2, %ebx + movzwl fixed_mtrr_list(%ebx), %ecx + wrmsr + jnz clear_fixed_mtrr + + post_code(0x22)
Ditto
Quoted 18 lines
arch/x86/cpu/intel_common/car2.S new file +18
-0+ + /* Figure put how many MTRRs we have, and clear them out */ + mov $MTRR_CAP_MSR, %ecx + rdmsr + movzb %al, %ebx /* Number of variable MTRRs */ + mov $MTRR_PHYS_BASE_MSR(0), %ecx + xor %eax, %eax + xor %edx, %edx + +clear_var_mtrr: + wrmsr + inc %ecx + wrmsr + inc %ecx + dec %ebx + jnz clear_var_mtrr + + post_code(0x23)
arch/x86/cpu/intel_common/car2.S line 88
Quoted 10 lines
arch/x86/cpu/intel_common/car2.S new file +10
-0+ + /* Configure default memory type to uncacheable (UC) */ + mov $MTRR_DEF_TYPE_MSR, %ecx + rdmsr + /* Clear enable bits and set default type to UC */ + and $~(MTRR_DEF_TYPE_MASK | MTRR_DEF_TYPE_EN | \ + MTRR_DEF_TYPE_FIX_EN), %eax + wrmsr + + /* Configure MTRR_PHYS_MASK_HIGH for proper addressing above 4GB
nits: wrong multi-line comment format
Quoted 80 lines
arch/x86/cpu/intel_common/car2.S new file +80
-0+ * based on the physical address size supported for this processor + * This is based on read from CPUID EAX = 080000008h, EAX bits [7:0] + * + * Examples: + * MTRR_PHYS_MASK_HIGH = 00000000Fh For 36 bit addressing + * MTRR_PHYS_MASK_HIGH = 0000000FFh For 40 bit addressing + */ + + movl $0x80000008, %eax /* Address sizes leaf */ + cpuid + sub $32, %al + movzx %al, %eax + xorl %esi, %esi + bts %eax, %esi + dec %esi /* esi <- MTRR_PHYS_MASK_HIGH */ + + post_code(0x24) + +#if ((CONFIG_DCACHE_RAM_SIZE & (CONFIG_DCACHE_RAM_SIZE - 1)) == 0) + /* Configure CAR region as write-back (WB) */ + mov $MTRR_PHYS_BASE_MSR(0), %ecx + mov $CONFIG_DCACHE_RAM_BASE, %eax + or $MTRR_TYPE_WRBACK, %eax + xor %edx,%edx + wrmsr + + /* Configure the MTRR mask for the size region */ + mov $MTRR_PHYS_MASK(0), %ecx + mov $CONFIG_DCACHE_RAM_SIZE, %eax /* size mask */ + dec %eax + not %eax + or $MTRR_PHYS_MASK_VALID, %eax + movl %esi, %edx /* edx <- MTRR_PHYS_MASK_HIGH */ + wrmsr +#elif (CONFIG_DCACHE_RAM_SIZE == 768 * KiB) /* 768 KiB */ + /* Configure CAR region as write-back (WB) */ + mov $MTRR_PHYS_BASE_MSR(0), %ecx + mov $CONFIG_DCACHE_RAM_BASE, %eax + or $MTRR_TYPE_WRBACK, %eax + xor %edx,%edx + wrmsr + + mov $MTRR_PHYS_MASK_MSR(0), %ecx + mov $(512 * KiB), %eax /* size mask */ + dec %eax + not %eax + or $MTRR_PHYS_MASK_VALID, %eax + movl %esi, %edx /* edx <- MTRR_PHYS_MASK_HIGH */ + wrmsr + + mov $MTRR_PHYS_BASE_MSR(1), %ecx + mov $(CONFIG_DCACHE_RAM_BASE + 512 * KiB), %eax + or $MTRR_TYPE_WRBACK, %eax + xor %edx,%edx + wrmsr + + mov $MTRR_PHYS_MASK_MSR(1), %ecx + mov $(256 * KiB), %eax /* size mask */ + dec %eax + not %eax + or $MTRR_PHYS_MASK_VALID, %eax + movl %esi, %edx /* edx <- MTRR_PHYS_MASK_HIGH */ + wrmsr +#else +#error "DCACHE_RAM_SIZE is not a power of 2 and setup code is missing" +#endif + post_code(0x25) + + /* start */ +/* mov $0xffff80a8, %ebx */ +/* jmp *%ebx */ +.globl _from_bb +_from_bb: +/* jmp car_init_ret */ + /* end */ + + /* Enable variable MTRRs */ + mov $MTRR_DEF_TYPE_MSR, %ecx + rdmsr + or $MTRR_DEF_TYPE_EN, %eax
arch/x86/cpu/intel_common/car2.S line 178
Quoted 10 lines
arch/x86/cpu/intel_common/car2.S new file +10
-0+ wrmsr + + /* Enable caching */ + mov %cr0, %eax + and $~(X86_CR0_CD | X86_CR0_NW), %eax + invd + mov %eax, %cr0 + +#if IS_ENABLED(CONFIG_INTEL_CAR_NEM) + jmp car_nem
nits: indentation of "car_nem" not correct
arch/x86/cpu/intel_common/car2.S line 180
Quoted 2 lines
arch/x86/cpu/intel_common/car2.S new file +2
-0+#elif IS_ENABLED(CONFIG_INTEL_CAR_CQOS) + jmp car_cqos
ditto
arch/x86/cpu/intel_common/car2.S line 182
Quoted 2 lines
arch/x86/cpu/intel_common/car2.S new file +2
-0+#elif IS_ENABLED(CONFIG_INTEL_CAR_NEM_ENHANCED) + jmp car_nem_enhanced
ditto
arch/x86/cpu/intel_common/car2.S line 188
Quoted 6 lines
arch/x86/cpu/intel_common/car2.S new file +6
-0+#else +#error "No CAR mechanism selected: +#endif + jmp car_init_ret + +#if 0
Dead codes? If yes, please remove the whole block in #if 0
arch/x86/cpu/intel_common/car2.S
Quoted 9 lines
arch/x86/cpu/intel_common/car2.S new file +9
-0+.global car_init_done +car_init_done: + + post_code(0x29) + + /* Setup bootblock stack */ + mov $_car_stack_end, %esp + + /* Need to align stack to 16 bytes at call instruction. Account for
nits: wrong multi-line comment format
Quoted 72 lines
arch/x86/cpu/intel_common/car2.S new file +72
-0+ the two pushes below */ + andl $0xfffffff0, %esp + sub $8, %esp + + /*push TSC value to stack*/ + movd %mm2, %eax + pushl %eax /* tsc[63:32] */ + movd %mm1, %eax + pushl %eax /* tsc[31:0] */ + +before_carstage: + post_code(0x2A) + + call bootblock_c_entry + /* Never reached */ +#endif + +fixed_mtrr_list: + .word MTRR_FIX_64K_00000_MSR + .word MTRR_FIX_16K_80000_MSR + .word MTRR_FIX_16K_A0000_MSR + .word MTRR_FIX_4K_C0000_MSR + .word MTRR_FIX_4K_C8000_MSR + .word MTRR_FIX_4K_D0000_MSR + .word MTRR_FIX_4K_D8000_MSR + .word MTRR_FIX_4K_E0000_MSR + .word MTRR_FIX_4K_E8000_MSR + .word MTRR_FIX_4K_F0000_MSR + .word MTRR_FIX_4K_F8000_MSR +fixed_mtrr_list_size = . - fixed_mtrr_list + +#if IS_ENABLED(CONFIG_INTEL_CAR_NEM) +.global car_nem +car_nem: + /* Disable cache eviction (setup stage) */ + mov $MSR_EVICT_CTL, %ecx + rdmsr + or $0x1, %eax + wrmsr + + post_code(0x26) + + /* Clear the cache memory region. This will also fill up the cache */ + movl $CONFIG_DCACHE_RAM_BASE, %edi + movl $CONFIG_DCACHE_RAM_SIZE, %ecx + shr $0x02, %ecx + xor %eax, %eax + cld + rep stosl + + post_code(0x27) + + /* Disable cache eviction (run stage) */ + mov $MSR_EVICT_CTL, %ecx + rdmsr + or $0x2, %eax + wrmsr + + post_code(0x28) + + jmp car_init_done + +#elif IS_ENABLED(CONFIG_INTEL_CAR_CQOS) +.global car_cqos +car_cqos: + /* + * Create CBM_LEN_MASK based on CBM_LEN + * Get CPUID.(EAX=10H, ECX=2H):EAX.CBM_LEN[bits 4:0] + */ + mov $0x10, %eax + mov $0x2, %ecx + cpuid
arch/x86/cpu/intel_common/car2.S line 279
Quoted 10 lines
arch/x86/cpu/intel_common/car2.S new file +10
-0+ and $0x1F, %eax + add $1, %al + + mov $1, %ebx + mov %al, %cl + shl %cl, %ebx + sub $1, %ebx + + /* Store the CBM_LEN_MASK in mm3 for later use */ + movd %ebx, %mm3
The indentation style inside above block is not consistent with others
Quoted 73 lines
arch/x86/cpu/intel_common/car2.S new file +73
-0+ + /* + * Disable both L1 and L2 prefetcher. For yet-to-understood reason, + * prefetchers slow down filling cache with rep stos in CQOS mode. + */ + mov $MSR_PREFETCH_CTL, %ecx + rdmsr + or $(PREFETCH_L1_DISABLE | PREFETCH_L2_DISABLE), %eax + wrmsr + +#if (CONFIG_DCACHE_RAM_SIZE == CONFIG_L2_CACHE_SIZE) +/* + * If CAR size is set to full L2 size, mask is calculated as all-zeros. + * This is not supported by the CPU/uCode. + */ +#error "CQOS CAR may not use whole L2 cache area" +#endif + + /* Calculate how many bits to be used for CAR */ + xor %edx, %edx + mov $CONFIG_DCACHE_RAM_SIZE, %eax /* dividend */ + mov $CONFIG_CACHE_QOS_SIZE_PER_BIT, %ecx /* divisor */ + div %ecx /* result is in eax */ + mov %eax, %ecx /* save to ecx */ + mov $1, %ebx + shl %cl, %ebx + sub $1, %ebx /* resulting mask is is in ebx */ + + /* Set this mask for initial cache fill */ + mov $MSR_L2_QOS_MASK(0), %ecx + rdmsr + mov %ebx, %eax + wrmsr + + /* Set CLOS selector to 0 */ + mov $MSR_IA32_PQR_ASSOC, %ecx + rdmsr + and $~MSR_IA32_PQR_ASSOC_MASK, %edx /* select mask 0 */ + wrmsr + + /* We will need to block CAR region from evicts */ + mov $MSR_L2_QOS_MASK(1), %ecx + rdmsr + /* Invert bits that are to be used for cache */ + mov %ebx, %eax + xor $~0, %eax /* invert 32 bits */ + + /* + * Use CBM_LEN_MASK stored in mm3 to set bits based on Capacity Bit + * Mask Length. + */ + movd %mm3, %ebx + and %ebx, %eax + wrmsr + + post_code(0x26) + + /* Clear the cache memory region. This will also fill up the cache */ + movl $CONFIG_DCACHE_RAM_BASE, %edi + movl $CONFIG_DCACHE_RAM_SIZE, %ecx + shr $0x02, %ecx + xor %eax, %eax + cld + rep stosl + + post_code(0x27) + + /* Cache is populated. Use mask 1 that will block evicts */ + mov $MSR_IA32_PQR_ASSOC, %ecx + rdmsr + and $~MSR_IA32_PQR_ASSOC_MASK, %edx /* clear index bits first */ + or $1, %edx /* select mask 1 */ + wrmsr
arch/x86/cpu/intel_common/car2.S line 362
Quoted 10 lines
arch/x86/cpu/intel_common/car2.S new file +10
-0+ + /* Enable prefetchers */ + mov $MSR_PREFETCH_CTL, %ecx + rdmsr + and $~(PREFETCH_L1_DISABLE | PREFETCH_L2_DISABLE), %eax + wrmsr + + post_code(0x28) + +/* jmp car_init_done */
Is this really not used and commented out?
Quoted 104 lines
arch/x86/cpu/intel_common/car2.S new file +104
-0+ jmp car_init_ret + +#elif IS_ENABLED(CONFIG_INTEL_CAR_NEM_ENHANCED) +.global car_nem_enhanced +car_nem_enhanced: + /* Disable cache eviction (setup stage) */ + mov $MSR_EVICT_CTL, %ecx + rdmsr + or $0x1, %eax + wrmsr + post_code(0x26) + + /* Create n-way set associativity of cache */ + xorl %edi, %edi +find_llc_subleaf: + movl %edi, %ecx + movl $0x04, %eax + cpuid + inc %edi + and $0xe0, %al /* EAX[7:5] = Cache Level */ + cmp $0x60, %al /* Check to see if it is LLC */ + jnz find_llc_subleaf + + /* + * Set MSR 0xC91 IA32_L3_MASK_! = 0xE/0xFE/0xFFE/0xFFFE + * for 4/8/16 way of LLC + */ + shr $22, %ebx + inc %ebx + /* Calculate n-way associativity of LLC */ + mov %bl, %cl + + /* + * Maximizing RO cacheability while locking in the CAR to a + * single way since that particular way won't be victim candidate + * for evictions. + * This has been done after programing LLC_WAY_MASK_1 MSR + * with desired LLC way as mentioned below. + * + * Hence create Code and Data Size as per request + * Code Size (RO) : Up to 16M + * Data Size (RW) : Up to 256K + */ + movl $0x01, %eax + /* + * LLC Ways -> LLC_WAY_MASK_1: + * 4: 0x000E + * 8: 0x00FE + * 12: 0x0FFE + * 16: 0xFFFE + * + * These MSRs contain one bit per each way of LLC + * - If this bit is '0' - the way is protected from eviction + * - If this bit is '1' - the way is not protected from eviction + */ + shl %cl, %eax + subl $0x02, %eax + movl $MSR_IA32_L3_MASK_1, %ecx + xorl %edx, %edx + wrmsr + /* + * Set MSR 0xC92 IA32_L3_MASK_2 = 0x1 + * + * For SKL SOC, data size remains 256K consistently. + * Hence, creating 1-way associative cache for Data + */ + mov $MSR_IA32_L3_MASK_2, %ecx + mov $0x01, %eax + xorl %edx, %edx + wrmsr + /* + * Set MSR_IA32_PQR_ASSOC = 0x02 + * + * Possible values: + * 0: Default value, no way mask should be applied + * 1: Apply way mask 1 to LLC + * 2: Apply way mask 2 to LLC + * 3: Shouldn't be use in NEM Mode + */ + movl $MSR_IA32_PQR_ASSOC, %ecx + movl $0x02, %eax + xorl %edx, %edx + wrmsr + + movl $CONFIG_DCACHE_RAM_BASE, %edi + movl $CONFIG_DCACHE_RAM_SIZE, %ecx + shr $0x02, %ecx + xor %eax, %eax + cld + rep stosl + /* + * Set MSR_IA32_PQR_ASSOC = 0x01 + * At this stage we apply LLC_WAY_MASK_1 to the cache. + * i.e. way 0 is protected from eviction. + */ + movl $MSR_IA32_PQR_ASSOC, %ecx + movl $0x01, %eax + xorl %edx, %edx + wrmsr + + post_code(0x27) + /* + * Enable No-Eviction Mode Run State by setting + * NO_EVICT_MODE MSR 2E0h bit [1] = '1'.
arch/x86/cpu/intel_common/car2.S line 476
Quoted 10 lines
arch/x86/cpu/intel_common/car2.S new file +10
-0+ */ + + movl $MSR_EVICT_CTL, %ecx + rdmsr + orl $0x02, %eax + wrmsr + + post_code(0x28) + + jmp car_init_done
nits: incorrect indentation of car_init_done
Quoted 98 lines
arch/x86/cpu/intel_common/car2.S new file +14
-0+#endif + +#if CONFIG_IS_ENABLED(X86_16BIT_INIT) +_dt_ucode_base_size: + /* These next two fields are filled in by binman */ +.globl ucode_base +ucode_base: /* Declared in microcode.h */ + .long 0 /* microcode base */ +.globl ucode_size +ucode_size: /* Declared in microcode.h */ + .long 0 /* microcode size */ + .long CONFIG_SYS_MONITOR_BASE /* code region base */ + .long CONFIG_SYS_MONITOR_LEN /* code region size */ +#endifarch/x86/cpu/intel_common/car2_uninit.S new file +78
-0@@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright 2017 Intel Corp. + * Copyright 2019 Google LLC + * Taken from coreboot file exit_car.S + */ + +#include <config.h> +#include <asm/msr-index.h> +#include <asm/mtrr.h> + +.text +.global car_uninit +car_uninit: + + /* + * Retrieve return address from stack as it will get trashed below if + * execution is utilizing the cache-as-ram stack. + */ + pop %ebx + + /* Disable MTRRs */ + mov $(MTRR_DEF_TYPE_MSR), %ecx + rdmsr + and $(~(MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN)), %eax + wrmsr + +#ifdef CONFIG_INTEL_CAR_NEM +.global car_nem_teardown +car_nem_teardown: + + /* invalidate cache contents */ + invd + + /* Knock down bit 1 then bit 0 of NEM control not combining steps */ + mov $(MSR_EVICT_CTL), %ecx + rdmsr + and $(~(1 << 1)), %eax + wrmsr + and $(~(1 << 0)), %eax + wrmsr + +#elif IS_ENABLED(CONFIG_INTEL_CAR_CQOS) +.global car_cqos_teardown +car_cqos_teardown: + + /* Go back to all-evicting mode, set both masks to all-1s */ + mov $MSR_L2_QOS_MASK(0), %ecx + rdmsr + mov $~0, %al + wrmsr + + mov $MSR_L2_QOS_MASK(1), %ecx + rdmsr + mov $~0, %al + wrmsr + + /* Reset CLOS selector to 0 */ + mov $MSR_IA32_PQR_ASSOC, %ecx + rdmsr + and $~MSR_IA32_PQR_ASSOC_MASK, %edx + wrmsr + +#elif IS_ENABLED(CONFIG_INTEL_CAR_NEM_ENHANCED) +.global car_nem_enhanced_teardown +car_nem_enhanced_teardown: + + /* invalidate cache contents */ + invd + + /* Knock down bit 1 then bit 0 of NEM control not combining steps */ + mov $(MSR_EVICT_CTL), %ecx + rdmsr + and $(~(1 << 1)), %eax + wrmsr + and $(~(1 << 0)), %eax + wrmsr +
arch/x86/cpu/intel_common/car2_uninit.S
Quoted 10 lines
arch/x86/cpu/intel_common/car2_uninit.S new file +9
-1+ /* Reset CLOS selector to 0 */ + mov $IA32_PQR_ASSOC, %ecx + rdmsr + and $~IA32_PQR_ASSOC_MASK, %edx + wrmsr +#endif + + /* Return to caller */ + jmp *%ebx --
Regards,
Bin
PATCH v3 65/108 x86: Disable microcode section for FSP2
In reply to Simon GlassAt present we don't support loading microcode with FSP2. The correct way to do this is by adding it to the FIT. For now, disable including microcode in the image.
---
Changes in v3:
- Drop unnecessary #else part of CONFIG_HAVE_MICROCODE
Changes in v2: None
arch/x86/Kconfig | 4 ++++ arch/x86/dts/u-boot.dtsi | 7 +++++++ 2 files changed, 11 insertions(+)
arch/x86/Kconfig +4 -0
@@ -598,6 +598,10 @@ config HAVE_REFCODE broadwell) U-Boot will be missing some critical setup steps. Various peripherals may fail to work. +config HAVE_MICROCODE + bool + default y if !FSP_VERSION2 + config SMP bool "Enable Symmetric Multiprocessing" default n
arch/x86/dts/u-boot.dtsi +7 -0
@@ -37,11 +37,13 @@ }; #endif #ifdef CONFIG_TPL +#ifdef CONFIG_HAVE_MICROCODE u-boot-tpl-with-ucode-ptr { offset = <CONFIG_TPL_TEXT_BASE>; }; u-boot-tpl-dtb { }; +#endif u-boot-spl { offset = <CONFIG_SPL_TEXT_BASE>; };
@@ -77,11 +79,16 @@ offset = <CONFIG_SYS_TEXT_BASE>; }; #endif +#ifdef CONFIG_HAVE_MICROCODE u-boot-dtb-with-ucode { }; u-boot-ucode { align = <16>; }; +#else + u-boot-dtb { + }; +#endif #ifdef CONFIG_X86_HAS_FIT intel-fit { };
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 65/108 x86: Disable microcode section for FSP2
Quoted 8 lines · Simon Glass
At present we don't support loading microcode with FSP2. The correct way to do this is by adding it to the FIT. For now, disable including microcode in the image.
Signed-off-by Simon Glass <[email protected]>---
Quoted 9 lines
Changes in v3:
- Drop unnecessary #else part ofCONFIG_HAVE_MICROCODEChanges in v2: None
arch/x86/Kconfig | 4 ++++ arch/x86/dts/u-boot.dtsi | 7 +++++++ 2 files changed, 11 insertions(+)
PATCH v3 66/108 x86: Update the fsp command for FSP2
In reply to Simon GlassThe current 'fsp' command only works with FSP1. Update it to handle FSP2 as well. Convert everything to hex which is what U-Boot uses.
---
Changes in v3:
- Convert code to use hex increased of decimal
- Update the 'fsp' command for FSP2, instead of disabling it
Changes in v2: None
cmd/x86/fsp.c | 59 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 20 deletions(-)
cmd/x86/fsp.c +39 -20
@@ -5,19 +5,30 @@#include <common.h> #include <command.h> -#include <asm/fsp1/fsp_support.h> +#include <asm/fsp/fsp_support.h> DECLARE_GLOBAL_DATA_PTR ;static int do_hdr (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { -struct fsp_header *hdr =fsp_find_header (); -u32 img_addr = hdr->img_base; -char *sign = (char *)&hdr->sign; +struct fsp_header *hdr; +u32 img_addr; +char *sign; +uint addr;int i; -printf ("FSP : binary 0x%08x, header 0x%08x\n" , -CONFIG_FSP_ADDR , (int )hdr); +#ifdef CONFIG_FSP_VERSION2 + hdr = gd->arch.fsp_s_hdr; + img_addr = hdr->img_base; + addr = img_addr; +#else + addr =CONFIG_FSP_ADDR ; + hdr =fsp_find_header (); + img_addr = hdr->img_base; +#endif + sign = (char *)&hdr->sign; + +printf ("FSP : binary %08x, header %08x\n" , addr, (int )hdr);printf ("Header : sign " );for (i =0 ; i <sizeof (hdr->sign); i++)printf ("%c" , *sign++);
@@ -34,24 +45,32 @@ static int do_hdr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])printf (", id " );for (i =0 ; i <ARRAY_SIZE (hdr->img_id); i++)printf ("%c" , hdr->img_id[i]); -printf (", addr 0x%08x, size %d\n" , img_addr, hdr->img_size); -if (hdr->hdr_rev ==FSP_HEADER_REVISION_2 ) { +printf (", addr %08x, size %d\n" , img_addr, hdr->img_size); +if (hdr->hdr_rev >=FSP_HEADER_REVISION_1 ) {printf ("GFX :%ssupported\n" , hdr->img_attr &FSP_ATTR_GRAPHICS_SUPPORT ?" " :" un" ); } -printf ("VPD : addr 0x%08x, size %d\n" , +printf ("VPD : addr %08x, size %x\n" , hdr->cfg_region_off + img_addr, hdr->cfg_region_size); -printf ("\nNumber of APIs Supported : %d\n" , hdr->api_num); -printf ("\tTempRamInit : 0x%08x\n" , hdr->fsp_tempram_init + img_addr); -printf ("\tFspInit : 0x%08x\n" , hdr->fsp_init + img_addr); -printf ("\tFspNotify : 0x%08x\n" , hdr->fsp_notify + img_addr); -if (hdr->hdr_rev ==FSP_HEADER_REVISION_2 ) { -printf ("\tMemoryInit : 0x%08x\n" , - hdr->fsp_mem_init + img_addr); -printf ("\tTempRamExit : 0x%08x\n" , - hdr->fsp_tempram_exit + img_addr); -printf ("\tSiliconInit : 0x%08x\n" , - hdr->fsp_silicon_init + img_addr); +if (hdr->hdr_rev <=FSP_HEADER_REVISION_2 ) +printf ("\nNumber of APIs Supported : %d\n" , hdr->api_num); +if (hdr->fsp_tempram_init) +printf ("\tTempRamInit : %08x\n" , + hdr->fsp_tempram_init + img_addr); +if (hdr->fsp_init) +printf ("\tFspInit : %08x\n" , hdr->fsp_init + img_addr); +if (hdr->fsp_notify) +printf ("\tFspNotify : %08x\n" , hdr->fsp_notify + img_addr); +if (hdr->hdr_rev >=FSP_HEADER_REVISION_1 ) { +if (hdr->fsp_mem_init) +printf ("\tMemoryInit : %08x\n" , + hdr->fsp_mem_init + img_addr); +if (hdr->fsp_tempram_exit) +printf ("\tTempRamExit : %08x\n" , + hdr->fsp_tempram_exit + img_addr); +if (hdr->fsp_silicon_init) +printf ("\tSiliconInit : %08x\n" , + hdr->fsp_silicon_init + img_addr); }return 0 ;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 66/108 x86: Update the fsp command for FSP2
Hi Simon,
Quoted 34 lines · Simon Glass
The current 'fsp' command only works with FSP1. Update it to handle FSP2 as well. Convert everything to hex which is what U-Boot uses.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Convert code to use hex increased of decimal
- Update the 'fsp' command for FSP2, instead of disabling itChanges in v2: None
cmd/x86/fsp.c | 59 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 20 deletions(-)cmd/x86/fsp.c +1
-4@@ -5,19 +5,30 @@#include <common.h> #include <command.h> -#include <asm/fsp1/fsp_support.h> +#include <asm/fsp/fsp_support.h> DECLARE_GLOBAL_DATA_PTR ;static int do_hdr (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { -struct fsp_header *hdr =fsp_find_header (); -u32 img_addr = hdr->img_base; -char *sign = (char *)&hdr->sign;
cmd/x86/fsp.c line 21
Quoted 10 lines
cmd/x86/fsp.c +6
-2+struct fsp_header *hdr; +u32 img_addr; +char *sign; +uint addr;int i; -printf ("FSP : binary 0x%08x, header 0x%08x\n" , -CONFIG_FSP_ADDR , (int )hdr); +#ifdef CONFIG_FSP_VERSION2 + hdr = gd->arch.fsp_s_hdr;
Only FSP-S is displayed?
Quoted 14 lines
cmd/x86/fsp.c +10
-0+ img_addr = hdr->img_base; + addr = img_addr; +#else + addr =CONFIG_FSP_ADDR ; + hdr =fsp_find_header (); + img_addr = hdr->img_base; +#endif + sign = (char *)&hdr->sign; + +printf ("FSP : binary %08x, header %08x\n" , addr, (int )hdr);printf ("Header : sign " );for (i =0 ; i <sizeof (hdr->sign); i++)printf ("%c" , *sign++);
cmd/x86/fsp.c static int do_hdr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 48
Quoted 6 lines
cmd/x86/fsp.c +1
-2@@ -34,24 +45,32 @@ static int do_hdr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])printf (", id " );for (i =0 ; i <ARRAY_SIZE (hdr->img_id); i++)printf ("%c" , hdr->img_id[i]); -printf (", addr 0x%08x, size %d\n" , img_addr, hdr->img_size); -if (hdr->hdr_rev ==FSP_HEADER_REVISION_2 ) { +printf (", addr %08x, size %d\n" , img_addr, hdr->img_size);
size %x? since commit message says: "Convert everything to hex"
Quoted 31 lines
cmd/x86/fsp.c +15
-12+if (hdr->hdr_rev >=FSP_HEADER_REVISION_1 ) {printf ("GFX :%ssupported\n" , hdr->img_attr &FSP_ATTR_GRAPHICS_SUPPORT ?" " :" un" ); } -printf ("VPD : addr 0x%08x, size %d\n" , +printf ("VPD : addr %08x, size %x\n" , hdr->cfg_region_off + img_addr, hdr->cfg_region_size); -printf ("\nNumber of APIs Supported : %d\n" , hdr->api_num); -printf ("\tTempRamInit : 0x%08x\n" , hdr->fsp_tempram_init + img_addr); -printf ("\tFspInit : 0x%08x\n" , hdr->fsp_init + img_addr); -printf ("\tFspNotify : 0x%08x\n" , hdr->fsp_notify + img_addr); -if (hdr->hdr_rev ==FSP_HEADER_REVISION_2 ) { -printf ("\tMemoryInit : 0x%08x\n" , - hdr->fsp_mem_init + img_addr); -printf ("\tTempRamExit : 0x%08x\n" , - hdr->fsp_tempram_exit + img_addr); -printf ("\tSiliconInit : 0x%08x\n" , - hdr->fsp_silicon_init + img_addr); +if (hdr->hdr_rev <=FSP_HEADER_REVISION_2 ) +printf ("\nNumber of APIs Supported : %d\n" , hdr->api_num); +if (hdr->fsp_tempram_init) +printf ("\tTempRamInit : %08x\n" , + hdr->fsp_tempram_init + img_addr); +if (hdr->fsp_init) +printf ("\tFspInit : %08x\n" , hdr->fsp_init + img_addr); +if (hdr->fsp_notify) +printf ("\tFspNotify : %08x\n" , hdr->fsp_notify + img_addr); +if (hdr->hdr_rev >=FSP_HEADER_REVISION_1 ) { +if (hdr->fsp_mem_init) +printf ("\tMemoryInit : %08x\n" , + hdr->fsp_mem_init + img_addr);
cmd/x86/fsp.c static int do_hdr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Quoted 10 lines
cmd/x86/fsp.c +6
-1+if (hdr->fsp_tempram_exit) +printf ("\tTempRamExit : %08x\n" , + hdr->fsp_tempram_exit + img_addr); +if (hdr->fsp_silicon_init) +printf ("\tSiliconInit : %08x\n" , + hdr->fsp_silicon_init + img_addr); }return 0 ; --
Regards,
Bin
PATCH v3 67/108 x86: Update .dtsi file for FSP2
In reply to Simon GlassInclude the IFWI section and the FSP-M binary. The FSP-T binary is not currently used, as CAR is set up manually.
Also drop the FSP binary as this relates only to FSP1.
---
Changes in v3:
- Add FSP-S and VBT also
Changes in v2: None
arch/x86/dts/u-boot.dtsi | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
arch/x86/dts/u-boot.dtsi +34 -1
@@ -100,12 +100,45 @@ offset = <CONFIG_X86_MRC_ADDR>; }; #endif -#ifdef CONFIG_HAVE_FSP +#ifdef CONFIG_FSP_VERSION1 intel-fsp { filename = CONFIG_FSP_FILE; offset = <CONFIG_FSP_ADDR>; }; #endif +#ifdef CONFIG_FSP_VERSION2 + intel-descriptor { + filename = CONFIG_FLASH_DESCRIPTOR_FILE; + }; + intel-ifwi { + filename = CONFIG_IFWI_INPUT_FILE; + convert-fit; + + section { + size = <0x8000>; + ifwi-replace; + ifwi-subpart = "IBBP"; + ifwi-entry = "IBBL"; + u-boot-tpl { + }; + x86-start16-tpl { + offset = <0x7800>; + }; + x86-reset16-tpl { + offset = <0x7ff0>; + }; + }; + }; + intel-fsp-m { + filename = CONFIG_FSP_FILE_M; + }; + intel-fsp-s { + filename = CONFIG_FSP_FILE_S; + }; + intel-vbt { + filename = CONFIG_FSP_FILE_VBT; + }; +#endif #ifdef CONFIG_HAVE_CMC intel-cmc { filename = CONFIG_CMC_FILE;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 67/108 x86: Update .dtsi file for FSP2
Quoted 9 lines · Simon Glass
Include the IFWI section and the FSP-M binary. The FSP-T binary is not currently used, as CAR is set up manually.
Also drop the FSP binary as this relates only to FSP1.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v3:
- Add FSP-S and VBT alsoChanges in v2: None
arch/x86/dts/u-boot.dtsi | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
PATCH v3 68/108 x86: Add an option to control the position of U-Boot
In reply to Simon GlassThe existing work-around for positioning U-Boot in the ROM when it actually runs from RAM still exists and there is not obvious way to change this.
Add a proper Kconfig option to handle this case. This also adds a new bool property to indicate whether CONFIG_SYS_TEXT_BASE exists.
---
Changes in v3: None
Changes in v2: None
Kconfig | 9 ++++++--- arch/x86/Kconfig | 5 +++++ arch/x86/dts/u-boot.dtsi | 18 +++--------------- configs/chromebook_samus_tpl_defconfig | 1 + 4 files changed, 15 insertions(+), 18 deletions(-)
Kconfig +6 -3
@@ -530,9 +530,14 @@ config SYS_EXTRA_OPTIONS configuration to Kconfig. Since this option will be removed sometime, new boards should not use this option. -config SYS_TEXT_BASE +config HAS_SYS_TEXT_BASE + bool depends on !NIOS2 && !XTENSA depends on !EFI_APP + default y + +config SYS_TEXT_BASE + depends on HAS_SYS_TEXT_BASE default 0x80800000 if ARCH_OMAP2PLUS || ARCH_K3 default 0x4a000000 if ARCH_SUNXI && !MACH_SUN9I && !MACH_SUN8I_V3S default 0x2a000000 if ARCH_SUNXI && MACH_SUN9I
@@ -541,8 +546,6 @@ config SYS_TEXT_BASE help The address in memory that U-Boot will be running from, initially. - - config SYS_CLK_FREQ depends on ARC || ARCH_SUNXI || MPC83xx int "CPU clock frequency"
arch/x86/Kconfig +5 -0
@@ -909,4 +909,9 @@ config CACHE_QOS_SIZE_PER_BIT depends on INTEL_CAR_CQOS default 0x20000 # 128 KB +config X86_OFFSET_U_BOOT + hex "Offset of U-Boot in ROM image" + depends on HAS_SYS_TEXT_BASE + default SYS_TEXT_BASE + endmenu
arch/x86/dts/u-boot.dtsi +3 -15
@@ -50,7 +50,7 @@ u-boot-spl-dtb { }; u-boot { - offset = <CONFIG_SYS_TEXT_BASE>; + offset = <CONFIG_X86_OFFSET_U_BOOT>; }; #elif defined(CONFIG_SPL) u-boot-spl-with-ucode-ptr {
@@ -60,23 +60,11 @@ type = "u-boot-dtb-with-ucode"; }; u-boot { - /* - * TODO(sjg at chromium.org): - * Normally we use CONFIG_SYS_TEXT_BASE as the flash offset. But - * for boards with textbase in SDRAM we cannot do this. Just use - * an assumed-valid value (1MB before the end of flash) here so - * that we can actually build an image for coreboot, etc. - * We need a better solution, perhaps a separate Kconfig. - */ -#if CONFIG_SYS_TEXT_BASE == 0x1110000 - offset = <0xfff00000>; -#else - offset = <CONFIG_SYS_TEXT_BASE>; -#endif + offset = <CONFIG_X86_OFFSET_U_BOOT>; }; #else u-boot-with-ucode-ptr { - offset = <CONFIG_SYS_TEXT_BASE>; + offset = <CONFIG_X86_OFFSET_U_BOOT>; }; #endif #ifdef CONFIG_HAVE_MICROCODE
configs/chromebook_samus_tpl_defconfig +1 -0
@@ -13,6 +13,7 @@ CONFIG_HAVE_REFCODE=y CONFIG_SMP=y CONFIG_HAVE_VGA_BIOS=y CONFIG_SPL_TEXT_BASE=0xffe70000 +CONFIG_X86_OFFSET_U_BOOT=0xfff00000 CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y CONFIG_SHOW_BOOT_PROGRESS=y
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 68/108 x86: Add an option to control the position of U-Boot
Hi Simon,
Quoted 25 lines · Simon Glass
The existing work-around for positioning U-Boot in the ROM when it actually runs from RAM still exists and there is not obvious way to change this.
Add a proper
Kconfigoption to handle this case. This also adds a new bool property to indicate whetherCONFIG_SYS_TEXT_BASEexists.Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: NoneKconfig | 9 ++++++--- arch/x86/Kconfig | 5 +++++ arch/x86/dts/u-boot.dtsi | 18 +++--------------- configs/chromebook_samus_tpl_defconfig | 1 + 4 files changed, 15 insertions(+), 18 deletions(-)Kconfig +0
-0
Kconfig config SYS_EXTRA_OPTIONS · line 533
Quoted 5 lines
Kconfig +1
-1@@ -530,9 +530,14 @@ config SYS_EXTRA_OPTIONS configuration to Kconfig. Since this option will be removed sometime, new boards should not use this option. -config SYS_TEXT_BASE +config HAS_SYS_TEXT_BASE
nits: HAVE_SYS_TEXT_BASE for consistent names
Quoted 77 lines
Kconfig +5
-2+ bool depends on !NIOS2 && !XTENSA depends on !EFI_APP + default y + +config SYS_TEXT_BASE + depends on HAS_SYS_TEXT_BASE default 0x80800000 if ARCH_OMAP2PLUS || ARCH_K3 default 0x4a000000 if ARCH_SUNXI && !MACH_SUN9I && !MACH_SUN8I_V3S default 0x2a000000 if ARCH_SUNXI && MACH_SUN9I@@ -541,8 +546,6 @@ config SYS_TEXT_BASE help The address in memory that U-Boot will be running from, initially. - - config SYS_CLK_FREQ depends on ARC || ARCH_SUNXI || MPC83xx int "CPU clock frequency"arch/x86/Kconfig +5
-0@@ -909,4 +909,9 @@ config CACHE_QOS_SIZE_PER_BIT depends on INTEL_CAR_CQOS default 0x20000 # 128 KB +config X86_OFFSET_U_BOOT + hex "Offset of U-Boot in ROM image" + depends on HAS_SYS_TEXT_BASE + default SYS_TEXT_BASE + endmenuarch/x86/dts/u-boot.dtsi +3
-15@@ -50,7 +50,7 @@ u-boot-spl-dtb { }; u-boot { - offset = <CONFIG_SYS_TEXT_BASE>; + offset = <CONFIG_X86_OFFSET_U_BOOT>; }; #elif defined(CONFIG_SPL) u-boot-spl-with-ucode-ptr {@@ -60,23 +60,11 @@ type = "u-boot-dtb-with-ucode"; }; u-boot { - /* - * TODO(sjg at chromium.org): - * Normally we use CONFIG_SYS_TEXT_BASE as the flash offset. But - * for boards with textbase in SDRAM we cannot do this. Just use - * an assumed-valid value (1MB before the end of flash) here so - * that we can actually build an image for coreboot, etc. - * We need a better solution, perhaps a separate Kconfig. - */ -#if CONFIG_SYS_TEXT_BASE == 0x1110000 - offset = <0xfff00000>; -#else - offset = <CONFIG_SYS_TEXT_BASE>; -#endif + offset = <CONFIG_X86_OFFSET_U_BOOT>; }; #else u-boot-with-ucode-ptr { - offset = <CONFIG_SYS_TEXT_BASE>; + offset = <CONFIG_X86_OFFSET_U_BOOT>; }; #endif #ifdef CONFIG_HAVE_MICROCODEconfigs/chromebook_samus_tpl_defconfig +0
-0
configs/chromebook_samus_tpl_defconfig CONFIG_HAVE_REFCODE=y · line 16
Quoted 4 lines
configs/chromebook_samus_tpl_defconfig +1
-0@@ -13,6 +13,7 @@ CONFIG_HAVE_REFCODE=y CONFIG_SMP=y CONFIG_HAVE_VGA_BIOS=y CONFIG_SPL_TEXT_BASE=0xffe70000 +CONFIG_X86_OFFSET_U_BOOT=0xfff00000
Should we update other x86 board defconfig files for this option?
configs/chromebook_samus_tpl_defconfig CONFIG_HAVE_REFCODE=y
Quoted 4 lines
configs/chromebook_samus_tpl_defconfig +0
-1CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y CONFIG_SHOW_BOOT_PROGRESS=y --
Regards,
Bin
PATCH v3 68/108 x86: Add an option to control the position of U-Boot
Hi Bin,
Quoted 24 lines · Bin Meng
Hi Simon,
Quoted 20 lines · Simon Glass
The existing work-around for positioning U-Boot in the ROM when it actually runs from RAM still exists and there is not obvious way to change this.
Add a proper
Kconfigoption to handle this case. This also adds a new bool property to indicate whetherCONFIG_SYS_TEXT_BASEexists.Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: NoneKconfig | 9 ++++++--- arch/x86/Kconfig | 5 +++++ arch/x86/dts/u-boot.dtsi | 18 +++--------------- configs/chromebook_samus_tpl_defconfig | 1 + 4 files changed, 15 insertions(+), 18 deletions(-)
[..]
Quoted 11 lines
configs/chromebook_samus_tpl_defconfig CONFIG_HAVE_REFCODE=y · line 16
Quoted 9 lines
configs/chromebook_samus_tpl_defconfig +1
-0@@ -13,6 +13,7 @@ CONFIG_HAVE_REFCODE=y CONFIG_SMP=y CONFIG_HAVE_VGA_BIOS=y CONFIG_SPL_TEXT_BASE=0xffe70000 +CONFIG_X86_OFFSET_U_BOOT=0xfff00000Should we update other x86 board defconfig files for this option?
It defaults to the same as the text base, which works fine with XIP, so I don't think this is necessary.
Regards,
Simon
PATCH v3 69/108 x86: Add an option to control the position of SPL
In reply to Simon GlassFor apollolake SPL is run from CAR (cache-as-RAM) which is in a different location from where SPL must be placed in ROM. In other words, although SPL runs before SDRAM is set up, it is not execute-in-place (XIP).
Add a Kconfig option for the ROM position.
---
Changes in v3:
- Add SPL condition to the option
Changes in v2: None
arch/x86/Kconfig | 5 +++++ arch/x86/dts/u-boot.dtsi | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-)
arch/x86/Kconfig +5 -0
@@ -914,4 +914,9 @@ config X86_OFFSET_U_BOOT depends on HAS_SYS_TEXT_BASE default SYS_TEXT_BASE +config X86_OFFSET_SPL + hex "Offset of SPL in ROM image" + depends on SPL && X86 + default SPL_TEXT_BASE + endmenu
arch/x86/dts/u-boot.dtsi +2 -2
@@ -45,7 +45,7 @@ }; #endif u-boot-spl { - offset = <CONFIG_SPL_TEXT_BASE>; + offset = <CONFIG_X86_OFFSET_SPL>; }; u-boot-spl-dtb { };
@@ -54,7 +54,7 @@ }; #elif defined(CONFIG_SPL) u-boot-spl-with-ucode-ptr { - offset = <CONFIG_SPL_TEXT_BASE>; + offset = <CONFIG_X86_OFFSET_SPL>; }; u-boot-dtb-with-ucode2 { type = "u-boot-dtb-with-ucode";
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 69/108 x86: Add an option to control the position of SPL
Quoted 10 lines · Simon Glass
For apollolake SPL is run from CAR (cache-as-RAM) which is in a different location from where SPL must be placed in ROM. In other words, although SPL runs before SDRAM is set up, it is not execute-in-place (XIP).
Add a
Kconfigoption for the ROM position.Signed-off-by Simon Glass <[email protected]>---
Quoted 9 lines
Changes in v3:
- Add SPL condition to the optionChanges in v2: None
arch/x86/Kconfig | 5 +++++ arch/x86/dts/u-boot.dtsi | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-)
PATCH v3 70/108 x86: Add an fdtmap and image-header
In reply to Simon GlassAdd these entries to the ROM so that we can list the contents of an image with 'binman ls'. The image-header is not essential but does speed up access.
---
Changes in v3: None
Changes in v2: None
arch/x86/dts/u-boot.dtsi | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/dts/u-boot.dtsi +5 -0
@@ -127,6 +127,8 @@ filename = CONFIG_FSP_FILE_VBT; }; #endif + fdtmap { + }; #ifdef CONFIG_HAVE_CMC intel-cmc { filename = CONFIG_CMC_FILE;
@@ -172,5 +174,8 @@ offset = <CONFIG_RESET_VEC_LOC>; }; #endif + image-header { + location = "end"; + }; }; #endif
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 70/108 x86: Add an fdtmap and image-header
Quoted 5 lines · Simon Glass
Add these entries to the ROM so that we can list the contents of an image with 'binman ls'. The image-header is not essential but does speed up access.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/dts/u-boot.dtsi | 5 +++++ 1 file changed, 5 insertions(+)
PATCH v3 71/108 x86: Don't repeat microcode in U-Boot if not needed
In reply to Simon GlassAt present if SPL sets up the microcode then it is still included in U-Boot as well. This is wasteful as microcode is large. Adjust the logic in the image to prevent this.
---
Changes in v3: None
Changes in v2: None
arch/x86/dts/u-boot.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
arch/x86/dts/u-boot.dtsi +7 -0
@@ -63,9 +63,16 @@ offset = <CONFIG_X86_OFFSET_U_BOOT>; }; #else +# ifdef CONFIG_SPL + u-boot { + offset = <CONFIG_SYS_TEXT_BASE>; + }; +# else + /* If there is no SPL then we need to put microcode in U-Boot */ u-boot-with-ucode-ptr { offset = <CONFIG_X86_OFFSET_U_BOOT>; }; +# endif #endif #ifdef CONFIG_HAVE_MICROCODE u-boot-dtb-with-ucode {
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 71/108 x86: Don't repeat microcode in U-Boot if not needed
Quoted 5 lines · Simon Glass
At present if SPL sets up the microcode then it is still included in U-Boot as well. This is wasteful as microcode is large. Adjust the logic in the image to prevent this.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/dts/u-boot.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
PATCH v3 72/108 x86: Separate out U-Boot and device tree in ROM image
In reply to Simon GlassAt present binman does not support updating a device tree that is part of U-Boot (i.e u-boot.bin). Separate the entries into two so that we can get updated entry information. This makes binman_entry_find() work correctly.
---
Changes in v3: None
Changes in v2: None
arch/x86/dts/u-boot.dtsi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/dts/u-boot.dtsi +3 -1
@@ -49,9 +49,11 @@ }; u-boot-spl-dtb { }; - u-boot { + u-boot-nodtb { offset = <CONFIG_X86_OFFSET_U_BOOT>; }; + u-boot-dtb { + }; #elif defined(CONFIG_SPL) u-boot-spl-with-ucode-ptr { offset = <CONFIG_X86_OFFSET_SPL>;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 72/108 x86: Separate out U-Boot and device tree in ROM image
Quoted 5 lines · Simon Glass
At present binman does not support updating a device tree that is part of U-Boot (i.e u-boot.bin). Separate the entries into two so that we can get updated entry information. This makes
binman_entry_find()work correctly.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/x86/dts/u-boot.dtsi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
PATCH v3 73/108 x86: Make MSR_PKG_POWER_SKU common
In reply to Simon GlassThis is used on several boards so add it to the common file. Also add a useful power-limit value while we are here.
---
Changes in v3: None
Changes in v2: None
arch/x86/include/asm/arch-broadwell/cpu.h | 1 - arch/x86/include/asm/arch-ivybridge/model_206ax.h | 1 - arch/x86/include/asm/msr-index.h | 9 ++++++++- 3 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/include/asm/arch-broadwell/cpu.h +0 -1
@@ -27,7 +27,6 @@#define MSR_VR_CURRENT_CONFIG 0x601#define MSR_VR_MISC_CONFIG 0x603 -#define MSR_PKG_POWER_SKU 0x614#define MSR_DDR_RAPL_LIMIT 0x618#define MSR_VR_MISC_CONFIG2 0x636
arch/x86/include/asm/arch-ivybridge/model_206ax.h +0 -1
@@ -43,7 +43,6 @@#define MSR_PP1_CURRENT_CONFIG 0x602#define PP1_CURRENT_LIMIT_SNB (35 << 3)/* 35 A */ #define PP1_CURRENT_LIMIT_IVB (50 << 3)/* 50 A */ -#define MSR_PKG_POWER_SKU 0x614#define IVB_CONFIG_TDP_MIN_CPUID 0x306a2#define MSR_CONFIG_TDP_LEVEL1 0x649
arch/x86/include/asm/msr-index.h +8 -1
@@ -241,10 +241,17 @@#define PKG_POWER_LIMIT_CLAMP (1 << 16)#define PKG_POWER_LIMIT_TIME_SHIFT 17#define PKG_POWER_LIMIT_TIME_MASK 0x7f +/* +* For Mobile, RAPL default PL1 time window value set to 28 seconds. +* RAPL time window calculation defined as follows: +* Time Window = (float)((1+X/4)*(2*^Y), X Corresponds to [23:22], +* Y to [21:17] in MSR 0x610. 28 sec is equal to 0x6e. +*/ +#define MB_POWER_LIMIT1_TIME_DEFAULT 0x6e#define MSR_PKG_ENERGY_STATUS 0x00000611#define MSR_PKG_PERF_STATUS 0x00000613 -#define MSR_PKG_POWER_INFO 0x00000614 +#define MSR_PKG_POWER_SKU 0x614#define MSR_DRAM_POWER_LIMIT 0x00000618#define MSR_DRAM_ENERGY_STATUS 0x00000619
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 73/108 x86: Make MSR_PKG_POWER_SKU common
Quoted 7 lines · Simon Glass
This is used on several boards so add it to the common file. Also add a useful power-limit value while we are here.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v3: None
Changes in v2: Nonearch/x86/include/asm/arch-broadwell/cpu.h | 1 - arch/x86/include/asm/arch-ivybridge/model_206ax.h | 1 - arch/x86/include/asm/msr-index.h | 9 ++++++++- 3 files changed, 8 insertions(+), 3 deletions(-)
PATCH v3 74/108 spi: Correct operations check in dm_spi_xfer()
In reply to Simon GlassAt present we have to have an xfer() method even if it does nothing. This is not correct, so fix it.
---
Changes in v3: None
Changes in v2: None
drivers/spi/ich.c | 9 +-------- drivers/spi/spi-uclass.c | 5 ++++- include/spi.h | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-)
drivers/spi/ich.c +1 -8
@@ -493,13 +493,6 @@ static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op)return 0 ; } -static int ich_spi_xfer (struct udevice *dev,unsigned int bitlen, -const void *dout,void *din,unsigned long flags) -{ -printf ("ICH SPI: Only supports memory operations\n" ); -return -1 ; -} -static int ich_spi_probe (struct udevice *dev) {struct ich_spi_platdata *plat =dev_get_platdata (dev);
@@ -612,7 +605,7 @@ static const struct spi_controller_mem_ops ich_controller_mem_ops = { };static const struct dm_spi_ops ich_spi_ops = { - .xfer = ich_spi_xfer, +/* xfer is not supported */ .set_speed = ich_spi_set_speed, .set_mode = ich_spi_set_mode, .mem_ops = &ich_controller_mem_ops,
drivers/spi/spi-uclass.c +4 -1
@@ -85,11 +85,14 @@ int dm_spi_xfer(struct udevice *dev, unsigned int bitlen, const void *dout, void *din, unsigned long flags) { struct udevice *bus = dev->parent; +struct dm_spi_ops *ops =spi_get_ops (bus);if (bus->uclass->uc_drv->id !=UCLASS_SPI )return -EOPNOTSUPP ; +if (!ops->xfer) +return -ENOSYS ; -return spi_get_ops (bus)->xfer (dev, bitlen, dout, din, flags); +return ops->xfer (dev, bitlen, dout, din, flags); } int dm_spi_get_mmap(struct udevice *dev, ulong *map_basep, uint *map_sizep,
include/spi.h +1 -1
@@ -224,7 +224,7 @@ void spi_release_bus(struct spi_slave *slave);int spi_set_wordlen (struct spi_slave *slave,unsigned int wordlen);/** -* SPI transfer +* SPI transfer (optional if mem_ops is used) * * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks * "bitlen" bits in the SPI MISO port. That's just the way SPI works.
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 74/108 spi: Correct operations check in dm_spi_xfer()
Quoted 7 lines · Simon Glass
At present we have to have an
xfer()method even if it does nothing. This is not correct, so fix it.Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 9 +-------- drivers/spi/spi-uclass.c | 5 ++++- include/spi.h | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-)
PATCH v3 75/108 x86: spi: Don't enable SPI_FLASH_BAR by default
In reply to Simon GlassWe don't normally need this on x86 unless the size of SPI flash devices is larger than 16MB. This can be enabled by particular SoCs as needed, since it adds to code size.
Drop the default enabling of this option on x86.
---
Changes in v3: None
Changes in v2: None
drivers/spi/Kconfig | 1 - 1 file changed, 1 deletion(-)
drivers/spi/Kconfig +0 -1
@@ -125,7 +125,6 @@ config FSL_DSPI config ICH_SPI bool "Intel ICH SPI driver" - imply SPI_FLASH_BAR help Enable the Intel ICH SPI driver. This driver can be used to access the SPI NOR flash on platforms embedding this Intel
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 75/108 x86: spi: Don't enable SPI_FLASH_BAR by default
+Vignesh
Quoted 21 lines · Simon Glass
We don't normally need this on x86 unless the size of SPI flash devices is larger than 16MB. This can be enabled by particular SoCs as needed, since it adds to code size.
Drop the default enabling of this option on x86.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/Kconfig | 1 - 1 file changed, 1 deletion(-)drivers/spi/Kconfig +0
-0
drivers/spi/Kconfig config FSL_DSPI · line 128
Quoted 4 lines
drivers/spi/Kconfig +0
-1@@ -125,7 +125,6 @@ config FSL_DSPI config ICH_SPI bool "Intel ICH SPI driver" - imply SPI_FLASH_BAR
This was added via:
commit 6d82517836418f984b7b4c05cf1427d7b49b1169
Author: Vignesh R <[email protected]> Date: Tue Feb 5 11:29:28 2019 +0530
configs: Don't use SPI_FLASH_BAR as default
Now that new SPI NOR layer uses stateless 4 byte opcodes by default, don't enable SPI_FLASH_BAR. For SPI controllers that cannot support 4-byte addressing, (stm32_qspi.c, fsl_qspi.c, mtk_qspi.c, ich.c, renesas_rpc_spi.c) add an imply clause to enable SPI_FLASH_BAR so as to not break functionality.
The commit message says: SPI_FLASH_BAR was added so as to not break functionality.
I don't have board to test right now. Vignesh could you please have a review? Thanks!
drivers/spi/Kconfig config FSL_DSPI
Quoted 4 lines
drivers/spi/Kconfig +0
-1help Enable the Intel ICH SPI driver. This driver can be used to access the SPI NOR flash on platforms embedding this Intel --
Regards,
Bin
Vignesh Raghavendra
maintainerPATCH v3 75/108 x86: spi: Don't enable SPI_FLASH_BAR by default
Hi,
Quoted 37 lines · Bin Meng
+Vignesh
Quoted 21 lines · Simon Glass
We don't normally need this on x86 unless the size of SPI flash devices is larger than 16MB. This can be enabled by particular SoCs as needed, since it adds to code size.
Drop the default enabling of this option on x86.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/Kconfig | 1 - 1 file changed, 1 deletion(-)drivers/spi/Kconfig +0
-0drivers/spi/Kconfig config FSL_DSPI · line 128
Quoted 4 lines
drivers/spi/Kconfig +0
-1@@ -125,7 +125,6 @@ config FSL_DSPI config ICH_SPI bool "Intel ICH SPI driver" - imply SPI_FLASH_BARThis was added via:
commit
6d82517836418f984b7b4c05cf1427d7b49b1169Author: Vignesh R <[email protected]> Date: Tue Feb 5 11:29:28 2019 +0530configs: Don't use
SPI_FLASH_BARas default
Quoted 9 lines
Now that new SPI NOR layer uses stateless 4 byte opcodes by default, don't enable
SPI_FLASH_BAR. For SPI controllers that cannot support 4-byte addressing, (stm32_qspi.c,fsl_qspi.c,mtk_qspi.c,ich.c,renesas_rpc_spi.c) add an imply clause to enableSPI_FLASH_BARso as to not break functionality.The commit message says:
SPI_FLASH_BARwas added so as to not break functionality.
At the time of introducing new SPI NOR layer, I found that (by code inspection) ich.c did not support 4 byte addressing. Hence, "imply SPI_FLASH_BAR" was added for ich.c driver.
But if driver has been improved to support 4 byte addressing or if there is no plan to support flashes > 16MiB by default, then it should be okay to remove SPI_FLASH_BAR.
Quoted 11 lines
I don't have board to test right now. Vignesh could you please have a review? Thanks!
drivers/spi/Kconfig config FSL_DSPI
Quoted 4 lines
drivers/spi/Kconfig +0
-1help Enable the Intel ICH SPI driver. This driver can be used to access the SPI NOR flash on platforms embedding this Intel --Regards,
Bin
Signature · 2 lines
Regards Vignesh
PATCH v3 75/108 x86: spi: Don't enable SPI_FLASH_BAR by default
Hi Vignesh,
Quoted 51 lines · Vignesh Raghavendra
Hi,
Quoted 37 lines · Bin Meng
+Vignesh
Quoted 21 lines · Simon Glass
We don't normally need this on x86 unless the size of SPI flash devices is larger than 16MB. This can be enabled by particular SoCs as needed, since it adds to code size.
Drop the default enabling of this option on x86.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/Kconfig | 1 - 1 file changed, 1 deletion(-)drivers/spi/Kconfig +0
-0drivers/spi/Kconfig config FSL_DSPI · line 128
Quoted 4 lines
drivers/spi/Kconfig +0
-1@@ -125,7 +125,6 @@ config FSL_DSPI config ICH_SPI bool "Intel ICH SPI driver" - imply SPI_FLASH_BARThis was added via:
commit
6d82517836418f984b7b4c05cf1427d7b49b1169Author: Vignesh R <[email protected]> Date: Tue Feb 5 11:29:28 2019 +0530configs: Don't use
SPI_FLASH_BARas defaultQuoted 9 lines
Now that new SPI NOR layer uses stateless 4 byte opcodes by default, don't enable
SPI_FLASH_BAR. For SPI controllers that cannot support 4-byte addressing, (stm32_qspi.c,fsl_qspi.c,mtk_qspi.c,ich.c,renesas_rpc_spi.c) add an imply clause to enableSPI_FLASH_BARso as to not break functionality.The commit message says:
SPI_FLASH_BARwas added so as to not break functionality.
Quoted 6 lines
At the time of introducing new SPI NOR layer, I found that (by code inspection)
ich.cdid not support 4 byte addressing. Hence, "implySPI_FLASH_BAR" was added forich.cdriver.
But if driver has been improved to support 4 byte addressing or if there is no plan to support flashes > 16MiB by default, then it should be okay to removeSPI_FLASH_BAR.
Well the problem is that it adds almost 3KB to the code size in TPL, so I think we need the option to turn it off.
Also current platforms supported in U-Boot don't have more than 8 or 16MB of SPI flash, so this should be safe.
Quoted 8 lines
Quoted 8 lines
I don't have board to test right now. Vignesh could you please have a review? Thanks!
Quoted 4 lines
drivers/spi/Kconfig +0
-1help Enable the Intel ICH SPI driver. This driver can be used to access the SPI NOR flash on platforms embedding this Intel --
Regards,
Simon
PATCH v3 76/108 spi: ich: Move init function just above probe()
In reply to Simon GlassIt is annoying to have some of the init code in a different part of the file. Move ich_init_controller() to just above probe() to keep things together.
---
Changes in v3: None
Changes in v2: None
drivers/spi/ich.c | 122 +++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 61 deletions(-)
drivers/spi/ich.c +61 -61
@@ -112,67 +112,6 @@ static int ich9_can_do_33mhz(struct udevice *dev)return speed ==1 ; } -static int ich_init_controller (struct udevice *dev, -struct ich_spi_platdata *plat, -struct ich_spi_priv *ctlr) -{ -ulong sbase_addr; -void *sbase; - -/* SBASE is similar */ -pch_get_spi_base (dev->parent, &sbase_addr); - sbase = (void *)sbase_addr; -debug ("%s: sbase=%p\n" , __func__, sbase); - -if (plat->ich_version ==ICHV_7 ) { -struct ich7_spi_regs *ich7_spi = sbase; - - ctlr->opmenu = offsetof(struct ich7_spi_regs , opmenu); - ctlr->menubytes =sizeof (ich7_spi->opmenu); - ctlr->optype = offsetof(struct ich7_spi_regs , optype); - ctlr->addr = offsetof(struct ich7_spi_regs , spia); - ctlr->data = offsetof(struct ich7_spi_regs , spid); - ctlr->databytes =sizeof (ich7_spi->spid); - ctlr->status = offsetof(struct ich7_spi_regs , spis); - ctlr->control = offsetof(struct ich7_spi_regs , spic); - ctlr->bbar = offsetof(struct ich7_spi_regs , bbar); - ctlr->preop = offsetof(struct ich7_spi_regs , preop); - ctlr->base = ich7_spi; - }else if (plat->ich_version ==ICHV_9 ) { -struct ich9_spi_regs *ich9_spi = sbase; - - ctlr->opmenu = offsetof(struct ich9_spi_regs , opmenu); - ctlr->menubytes =sizeof (ich9_spi->opmenu); - ctlr->optype = offsetof(struct ich9_spi_regs , optype); - ctlr->addr = offsetof(struct ich9_spi_regs , faddr); - ctlr->data = offsetof(struct ich9_spi_regs , fdata); - ctlr->databytes =sizeof (ich9_spi->fdata); - ctlr->status = offsetof(struct ich9_spi_regs , ssfs); - ctlr->control = offsetof(struct ich9_spi_regs , ssfc); - ctlr->speed = ctlr->control +2 ; - ctlr->bbar = offsetof(struct ich9_spi_regs , bbar); - ctlr->preop = offsetof(struct ich9_spi_regs , preop); - ctlr->bcr = offsetof(struct ich9_spi_regs , bcr); - ctlr->pr = &ich9_spi->pr[0 ]; - ctlr->base = ich9_spi; - }else { -debug ("ICH SPI: Unrecognised ICH version %d\n" , - plat->ich_version); -return -EINVAL ; - } - -/* Work out the maximum speed we can support */ - ctlr->max_speed =20000000 ; -if (plat->ich_version ==ICHV_9 &&ich9_can_do_33mhz (dev)) - ctlr->max_speed =33000000 ; -debug ("ICH SPI: Version ID %d detected at %p, speed %ld\n" , - plat->ich_version, ctlr->base, ctlr->max_speed); - -ich_set_bbar (ctlr,0 ); - -return 0 ; -} -static void spi_lock_down (struct ich_spi_platdata *plat,void *sbase) {if (plat->ich_version ==ICHV_7 ) {
@@ -493,6 +432,67 @@ static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op)return 0 ; } +static int ich_init_controller (struct udevice *dev, +struct ich_spi_platdata *plat, +struct ich_spi_priv *ctlr) +{ +ulong sbase_addr; +void *sbase; + +/* SBASE is similar */ +pch_get_spi_base (dev->parent, &sbase_addr); + sbase = (void *)sbase_addr; +debug ("%s: sbase=%p\n" , __func__, sbase); + +if (plat->ich_version ==ICHV_7 ) { +struct ich7_spi_regs *ich7_spi = sbase; + + ctlr->opmenu = offsetof(struct ich7_spi_regs , opmenu); + ctlr->menubytes =sizeof (ich7_spi->opmenu); + ctlr->optype = offsetof(struct ich7_spi_regs , optype); + ctlr->addr = offsetof(struct ich7_spi_regs , spia); + ctlr->data = offsetof(struct ich7_spi_regs , spid); + ctlr->databytes =sizeof (ich7_spi->spid); + ctlr->status = offsetof(struct ich7_spi_regs , spis); + ctlr->control = offsetof(struct ich7_spi_regs , spic); + ctlr->bbar = offsetof(struct ich7_spi_regs , bbar); + ctlr->preop = offsetof(struct ich7_spi_regs , preop); + ctlr->base = ich7_spi; + }else if (plat->ich_version ==ICHV_9 ) { +struct ich9_spi_regs *ich9_spi = sbase; + + ctlr->opmenu = offsetof(struct ich9_spi_regs , opmenu); + ctlr->menubytes =sizeof (ich9_spi->opmenu); + ctlr->optype = offsetof(struct ich9_spi_regs , optype); + ctlr->addr = offsetof(struct ich9_spi_regs , faddr); + ctlr->data = offsetof(struct ich9_spi_regs , fdata); + ctlr->databytes =sizeof (ich9_spi->fdata); + ctlr->status = offsetof(struct ich9_spi_regs , ssfs); + ctlr->control = offsetof(struct ich9_spi_regs , ssfc); + ctlr->speed = ctlr->control +2 ; + ctlr->bbar = offsetof(struct ich9_spi_regs , bbar); + ctlr->preop = offsetof(struct ich9_spi_regs , preop); + ctlr->bcr = offsetof(struct ich9_spi_regs , bcr); + ctlr->pr = &ich9_spi->pr[0 ]; + ctlr->base = ich9_spi; + }else { +debug ("ICH SPI: Unrecognised ICH version %d\n" , + plat->ich_version); +return -EINVAL ; + } + +/* Work out the maximum speed we can support */ + ctlr->max_speed =20000000 ; +if (plat->ich_version ==ICHV_9 &&ich9_can_do_33mhz (dev)) + ctlr->max_speed =33000000 ; +debug ("ICH SPI: Version ID %d detected at %p, speed %ld\n" , + plat->ich_version, ctlr->base, ctlr->max_speed); + +ich_set_bbar (ctlr,0 ); + +return 0 ; +} +static int ich_spi_probe (struct udevice *dev) {struct ich_spi_platdata *plat =dev_get_platdata (dev);
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 76/108 spi: ich: Move init function just above probe()
Quoted 5 lines · Simon Glass
It is annoying to have some of the init code in a different part of the file. Move
ich_init_controller()to just aboveprobe()to keep things together.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 122 +++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 61 deletions(-)
PATCH v3 77/108 spi: ich: Move the protection/lockdown code into a function
In reply to Simon GlassReduce the size of the probe function but putting this code into its own function.
Also remove the assumption that the PCH is always a parent of the SPI controller, as this is not the case APL platforms. Use driver model to find the PCH instead.
---
Changes in v3: None
Changes in v2: None
drivers/spi/ich.c | 55 +++++++++++++++++++++++++++++++---------------- drivers/spi/ich.h | 1 + 2 files changed, 38 insertions(+), 18 deletions(-)
drivers/spi/ich.c +37 -18
@@ -432,6 +432,37 @@ static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op)return 0 ; } +static int ich_protect_lockdown (struct udevice *dev) +{ +struct ich_spi_platdata *plat =dev_get_platdata (dev); +struct ich_spi_priv *priv =dev_get_priv (dev); +int ret = -ENOSYS ; + +/* Disable the BIOS write protect so write commands are allowed */ +if (priv->pch) + ret =pch_set_spi_protect (priv->pch, false); +if (ret == -ENOSYS ) { +u8 bios_cntl; + + bios_cntl =ich_readb (priv, priv->bcr); + bios_cntl &= ~BIT (5 );/* clear Enable InSMM_STS (EISS) */ + bios_cntl |=1 ;/* Write Protect Disable (WPD) */ +ich_writeb (priv, bios_cntl, priv->bcr); + }else if (ret) { +debug ("%s: Failed to disable write-protect: err=%d\n" , + __func__, ret); +return ret; + } + +/* Lock down SPI controller settings if required */ +if (plat->lockdown) { +ich_spi_config_opcode (dev); +spi_lock_down (plat, priv->base); + } + +return 0 ; +} +static int ich_init_controller (struct udevice *dev,struct ich_spi_platdata *plat,struct ich_spi_priv *ctlr)
@@ -497,30 +528,18 @@ static int ich_spi_probe(struct udevice *dev) {struct ich_spi_platdata *plat =dev_get_platdata (dev);struct ich_spi_priv *priv =dev_get_priv (dev); -uint8_t bios_cntl;int ret; +/* Find a PCH if there is one */ +uclass_first_device (UCLASS_PCH , &priv->pch); + ret =ich_init_controller (dev, plat, priv);if (ret)return ret; -/* Disable the BIOS write protect so write commands are allowed */ - ret =pch_set_spi_protect (dev->parent, false); -if (ret == -ENOSYS ) { - bios_cntl =ich_readb (priv, priv->bcr); - bios_cntl &= ~BIT (5 );/* clear Enable InSMM_STS (EISS) */ - bios_cntl |=1 ;/* Write Protect Disable (WPD) */ -ich_writeb (priv, bios_cntl, priv->bcr); - }else if (ret) { -debug ("%s: Failed to disable write-protect: err=%d\n" , - __func__, ret); -return ret; - } -/* Lock down SPI controller settings if required */ -if (plat->lockdown) { -ich_spi_config_opcode (dev); -spi_lock_down (plat, priv->base); - } + ret =ich_protect_lockdown (dev); +if (ret) +return ret; priv->cur_speed = priv->max_speed;
drivers/spi/ich.h +1 -0
@@ -191,6 +191,7 @@ struct ich_spi_priv {ulong max_speed;/* Maximum bus speed in MHz */ ulong cur_speed;/* Current bus speed */ struct spi_trans trans;/* current transaction in progress */ + struct udevice *pch; /* PCH, used to control SPI access */ };#endif /* _ICH_H_ */
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 77/108 spi: ich: Move the protection/lockdown code into a function
Hi Simon,
Quoted 4 lines · Simon Glass
Reduce the size of the probe function but putting this code into its own function.
It's unclear to me why this brings any benefit? The size of the probe function indeed is reduced, but whole file size does not change, no?
Quoted 5 lines
Also remove the assumption that the PCH is always a parent of the SPI controller, as this is not the case APL platforms. Use driver model to find the PCH instead.
Signed-off-by Simon Glass <[email protected]>
Quoted 9 lines
---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 55 +++++++++++++++++++++++++++++++---------------- drivers/spi/ich.h | 1 + 2 files changed, 38 insertions(+), 18 deletions(-)
Regards,
Bin
PATCH v3 77/108 spi: ich: Move the protection/lockdown code into a function
Hi Bin,
Quoted 11 lines · Bin Meng
Hi Simon,
Quoted 4 lines · Simon Glass
Reduce the size of the probe function but putting this code into its own function.
It's unclear to me why this brings any benefit? The size of the probe function indeed is reduced, but whole file size does not change, no?
It's just that it gives the code a name and groups it in a function. It is normally better to have shorter functions and this one seemed to be getting a bit long and unfocussed.
Regards,
Simon
PATCH v3 77/108 spi: ich: Move the protection/lockdown code into a function
Hi Simon,
Quoted 13 lines · Simon Glass
Hi Bin,
Quoted 9 lines · Bin Meng
Hi Simon,
Quoted 4 lines · Simon Glass
Reduce the size of the probe function but putting this code into its own function.
Quoted 7 lines
Quoted 2 lines
It's unclear to me why this brings any benefit? The size of the probe function indeed is reduced, but whole file size does not change, no?
It's just that it gives the code a name and groups it in a function. It is normally better to have shorter functions and this one seemed to be getting a bit long and unfocussed.
OK, I think I misunderstood it. I thought you wanted to reduce the code size for TPL when I saw the commit message, but it didn't reduce code size at all.
Regards,
Bin
PATCH v3 78/108 spi: ich: Convert to livetree
In reply to Simon GlassUse dev_get_driver_data() to obtain the device type. It has the same effect and is shorter.
---
Changes in v3: None
Changes in v2: None
drivers/spi/ich.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-)
drivers/spi/ich.c +5 -17
@@ -598,23 +598,11 @@ static int ich_spi_child_pre_probe(struct udevice *dev)static int ich_spi_ofdata_to_platdata (struct udevice *dev) {struct ich_spi_platdata *plat =dev_get_platdata (dev); -int node =dev_of_offset (dev); -int ret; - ret =fdt_node_check_compatible (gd->fdt_blob, node,"intel,ich7-spi" ); -if (ret ==0 ) { - plat->ich_version =ICHV_7 ; - }else { - ret =fdt_node_check_compatible (gd->fdt_blob, node, -"intel,ich9-spi" ); -if (ret ==0 ) - plat->ich_version =ICHV_9 ; - } + plat->ich_version =dev_get_driver_data (dev); + plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" ); - plat->lockdown =fdtdec_get_bool (gd->fdt_blob, node, -"intel,spi-lock-down" ); - -return ret; +return 0 ; }static const struct spi_controller_mem_ops ich_controller_mem_ops = {
@@ -635,8 +623,8 @@ static const struct dm_spi_ops ich_spi_ops = { };static const struct udevice_id ich_spi_ids[] = { - { .compatible ="intel,ich7-spi" }, - { .compatible ="intel,ich9-spi" }, + { .compatible ="intel,ich7-spi" ,ICHV_7 }, + { .compatible ="intel,ich9-spi" ,ICHV_9 }, { } };
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 78/108 spi: ich: Convert to livetree
Quoted 4 lines · Simon Glass
Use
dev_get_driver_data()to obtain the device type. It has the same effect and is shorter.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-)
PATCH v3 79/108 spi: ich: Fix header order
In reply to Simon GlassMove the header files into the right order.
---
Changes in v3: None
Changes in v2: None
drivers/spi/ich.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/ich.c +2 -2
@@ -6,6 +6,7 @@*/ #include <common.h> +#include <div64.h> #include <dm.h> #include <errno.h> #include <malloc.h>
@@ -13,9 +14,8 @@#include <pci.h> #include <pci_ids.h> #include <spi.h> -#include <asm/io.h> #include <spi-mem.h> -#include <div64.h> +#include <asm/io.h> #include "ich.h"
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 79/108 spi: ich: Fix header order
Quoted 12 lines · Simon Glass
Move the header files into the right order.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
PATCH v3 80/108 spi: ich: Various small tidy-ups
In reply to Simon GlassUse debug() instead of printf() to reduce code size and change a bool return value to the use the 'bool' type. Also drop the global data declaration since it not actually used. Finally, set the log category.
---
Changes in v3: None
Changes in v2: None
drivers/spi/ich.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/spi/ich.c +8 -9
@@ -5,6 +5,8 @@* This file is derived from the flashrom project. */ +#define LOG_CATEGORY UCLASS_SPI +#include <common.h> #include <div64.h> #include <dm.h>
@@ -19,8 +21,6 @@#include "ich.h" -DECLARE_GLOBAL_DATA_PTR ; -#ifdef DEBUG_TRACE #define debug_trace(fmt, args...) debug(fmt, ##args)#else
@@ -96,7 +96,7 @@ static void ich_set_bbar(struct ich_spi_priv *ctlr, uint32_t minaddr) }/* @return 1 if the SPI flash supports the 33MHz speed */ -static int ich9_can_do_33mhz (struct udevice *dev) +static bool ich9_can_do_33mhz (struct udevice *dev) {u32 fdod, speed;
@@ -172,8 +172,7 @@ static int spi_setup_opcode(struct ich_spi_priv *ctlr, struct spi_trans *trans, }if (opcode_index == ctlr->menubytes) { -printf ("ICH SPI: Opcode %x not found\n" , - trans->opcode); +debug ("ICH SPI: Opcode %x not found\n" , trans->opcode);return -EINVAL ; }
@@ -181,8 +180,8 @@ static int spi_setup_opcode(struct ich_spi_priv *ctlr, struct spi_trans *trans, optype = (optypes >> (opcode_index *2 )) &0x3 ;if (optype != trans->type) { -printf ("ICH SPI: Transaction doesn't fit type %d\n" , - optype); +debug ("ICH SPI: Transaction doesn't fit type %d\n" , + optype);return -ENOSPC ; }return opcode_index;
@@ -213,9 +212,9 @@ static int ich_status_poll(struct ich_spi_priv *ctlr, u16 bitmask, }udelay (10 ); } +debug ("ICH SPI: SCIP timeout, read %x, expected %x, wts %x %x\n" , + status, bitmask, wait_til_set, status & bitmask); -printf ("ICH SPI: SCIP timeout, read %x, expected %x\n" , - status, bitmask);return -ETIMEDOUT ; }
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 80/108 spi: ich: Various small tidy-ups
Quoted 5 lines · Simon Glass
Use
debug()instead ofprintf()to reduce code size and change a bool return value to the use the 'bool' type. Also drop the global data declaration since it not actually used. Finally, set the log category.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
PATCH v3 81/108 spi: ich: Add mmio_base to struct ich_spi_platdata
In reply to Simon GlassIt is useful to store the mmio base in platdata. It reduces the amount of casting needed. Update the code and move the struct to the C file at the same time, as we will need to use with of-platdata.
---
Changes in v3: None
Changes in v2: None
drivers/spi/ich.c | 27 +++++++++++++-------------- drivers/spi/ich.h | 5 ----- 2 files changed, 13 insertions(+), 19 deletions(-)
drivers/spi/ich.c +13 -14
@@ -27,6 +27,12 @@ #define debug_trace(x, args...)#endif +struct ich_spi_platdata { +enum ich_version ich_version;/* Controller version, 7 or 9 */ +bool lockdown;/* lock down controller settings? */ +ulong mmio_base;/* Base of MMIO registers */ +}; +static u8 ich_readb (struct ich_spi_priv *priv,int reg) {u8 value =readb (priv->base + reg);
@@ -466,16 +472,9 @@ static int ich_init_controller(struct udevice *dev,struct ich_spi_platdata *plat, struct ich_spi_priv *ctlr) { - ulong sbase_addr; -void *sbase; - -/* SBASE is similar */ -pch_get_spi_base (dev->parent, &sbase_addr); - sbase = (void *)sbase_addr; -debug ("%s: sbase=%p\n" , __func__, sbase); - + ctlr->base = (void *)plat->mmio_base;if (plat->ich_version ==ICHV_7 ) { -struct ich7_spi_regs *ich7_spi = sbase; +struct ich7_spi_regs *ich7_spi = ctlr->base; ctlr->opmenu = offsetof(struct ich7_spi_regs , opmenu); ctlr->menubytes =sizeof (ich7_spi->opmenu);
@@ -487,9 +486,8 @@ static int ich_init_controller(struct udevice *dev, ctlr->control = offsetof(struct ich7_spi_regs , spic); ctlr->bbar = offsetof(struct ich7_spi_regs , bbar); ctlr->preop = offsetof(struct ich7_spi_regs , preop); - ctlr->base = ich7_spi; }else if (plat->ich_version ==ICHV_9 ) { -struct ich9_spi_regs *ich9_spi = sbase; +struct ich9_spi_regs *ich9_spi = ctlr->base; ctlr->opmenu = offsetof(struct ich9_spi_regs , opmenu); ctlr->menubytes =sizeof (ich9_spi->opmenu);
@@ -504,7 +502,6 @@ static int ich_init_controller(struct udevice *dev, ctlr->preop = offsetof(struct ich9_spi_regs , preop); ctlr->bcr = offsetof(struct ich9_spi_regs , bcr); ctlr->pr = &ich9_spi->pr[0 ]; - ctlr->base = ich9_spi; }else {debug ("ICH SPI: Unrecognised ICH version %d\n" , plat->ich_version);
@@ -515,8 +512,8 @@ static int ich_init_controller(struct udevice *dev, ctlr->max_speed =20000000 ;if (plat->ich_version ==ICHV_9 &&ich9_can_do_33mhz (dev)) ctlr->max_speed =33000000 ; -debug ("ICH SPI: Version ID %d detected at %p, speed %ld\n" , - plat->ich_version, ctlr->base, ctlr->max_speed); +debug ("ICH SPI: Version ID %d detected at %lx, speed %ld\n" , + plat->ich_version, plat->mmio_base, ctlr->max_speed);ich_set_bbar (ctlr,0 );
@@ -601,6 +598,8 @@ static int ich_spi_ofdata_to_platdata(struct udevice *dev) plat->ich_version =dev_get_driver_data (dev); plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" ); +pch_get_spi_base (dev->parent, &plat->mmio_base); +return 0 ; }
drivers/spi/ich.h +0 -5
@@ -168,11 +168,6 @@ enum ich_version { ICHV_9, }; -struct ich_spi_platdata { -enum ich_version ich_version;/* Controller version, 7 or 9 */ -bool lockdown;/* lock down controller settings? */ -}; -struct ich_spi_priv {int opmenu;int menubytes;
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 81/108 spi: ich: Add mmio_base to struct ich_spi_platdata
Hi Simon,
Quoted 82 lines · Simon Glass
It is useful to store the mmio base in platdata. It reduces the amount of casting needed. Update the code and move the struct to the C file at the same time, as we will need to use with of-platdata.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 27 +++++++++++++-------------- drivers/spi/ich.h | 5 ----- 2 files changed, 13 insertions(+), 19 deletions(-)drivers/spi/ich.c +11
-14@@ -27,6 +27,12 @@ #define debug_trace(x, args...)#endif +struct ich_spi_platdata { +enum ich_version ich_version;/* Controller version, 7 or 9 */ +bool lockdown;/* lock down controller settings? */ +ulong mmio_base;/* Base of MMIO registers */ +}; +static u8 ich_readb (struct ich_spi_priv *priv,int reg) {u8 value =readb (priv->base + reg);@@ -466,16 +472,9 @@ static int ich_init_controller(struct udevice *dev,struct ich_spi_platdata *plat, struct ich_spi_priv *ctlr) { - ulong sbase_addr; -void *sbase; - -/* SBASE is similar */ -pch_get_spi_base (dev->parent, &sbase_addr); - sbase = (void *)sbase_addr; -debug ("%s: sbase=%p\n" , __func__, sbase); - + ctlr->base = (void *)plat->mmio_base;if (plat->ich_version ==ICHV_7 ) { -struct ich7_spi_regs *ich7_spi = sbase; +struct ich7_spi_regs *ich7_spi = ctlr->base; ctlr->opmenu = offsetof(struct ich7_spi_regs , opmenu); ctlr->menubytes =sizeof (ich7_spi->opmenu);@@ -487,9 +486,8 @@ static int ich_init_controller(struct udevice *dev, ctlr->control = offsetof(struct ich7_spi_regs , spic); ctlr->bbar = offsetof(struct ich7_spi_regs , bbar); ctlr->preop = offsetof(struct ich7_spi_regs , preop); - ctlr->base = ich7_spi; }else if (plat->ich_version ==ICHV_9 ) { -struct ich9_spi_regs *ich9_spi = sbase; +struct ich9_spi_regs *ich9_spi = ctlr->base; ctlr->opmenu = offsetof(struct ich9_spi_regs , opmenu); ctlr->menubytes =sizeof (ich9_spi->opmenu);@@ -504,7 +502,6 @@ static int ich_init_controller(struct udevice *dev, ctlr->preop = offsetof(struct ich9_spi_regs , preop); ctlr->bcr = offsetof(struct ich9_spi_regs , bcr); ctlr->pr = &ich9_spi->pr[0 ]; - ctlr->base = ich9_spi; }else {debug ("ICH SPI: Unrecognised ICH version %d\n" , plat->ich_version);@@ -515,8 +512,8 @@ static int ich_init_controller(struct udevice *dev, ctlr->max_speed =20000000 ;if (plat->ich_version ==ICHV_9 &&ich9_can_do_33mhz (dev)) ctlr->max_speed =33000000 ; -debug ("ICH SPI: Version ID %d detected at %p, speed %ld\n" , - plat->ich_version, ctlr->base, ctlr->max_speed); +debug ("ICH SPI: Version ID %d detected at %lx, speed %ld\n" , + plat->ich_version, plat->mmio_base, ctlr->max_speed);ich_set_bbar (ctlr,0 );
drivers/spi/ich.c static int ich_spi_ofdata_to_platdata(struct udevice *dev) · line 601
Quoted 4 lines
drivers/spi/ich.c +1
-0@@ -601,6 +598,8 @@ static int ich_spi_ofdata_to_platdata(struct udevice *dev) plat->ich_version =dev_get_driver_data (dev); plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" ); +pch_get_spi_base (dev->parent, &plat->mmio_base);
In patch [77], spi: ich: Move the protection/lockdown code into a function, we already removed the assumption of dev->parent, but used priv->pch for the PCH device.
Quoted 9 lines
drivers/spi/ich.c +1
-0+return 0 ; }drivers/spi/ich.h +0
-0
drivers/spi/ich.h enum ich_version { · line 174
Quoted 7 lines
drivers/spi/ich.h +0
-4@@ -168,11 +168,6 @@ enum ich_version { ICHV_9, }; -struct ich_spi_platdata { -enum ich_version ich_version;/* Controller version, 7 or 9 */ -bool lockdown;/* lock down controller settings? */ -};
I don't understand why moving this struct to C file?
drivers/spi/ich.h enum ich_version {
Quoted 5 lines
drivers/spi/ich.h +0
-2-struct ich_spi_priv {int opmenu;int menubytes; --
Regards,
Bin
PATCH v3 81/108 spi: ich: Add mmio_base to struct ich_spi_platdata
Hi Bin,
Quoted 89 lines · Bin Meng
Hi Simon,
Quoted 85 lines · Simon Glass
It is useful to store the mmio base in platdata. It reduces the amount of casting needed. Update the code and move the struct to the C file at the same time, as we will need to use with of-platdata.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 27 +++++++++++++-------------- drivers/spi/ich.h | 5 ----- 2 files changed, 13 insertions(+), 19 deletions(-)drivers/spi/ich.c +11
-14@@ -27,6 +27,12 @@ #define debug_trace(x, args...)#endif +struct ich_spi_platdata { +enum ich_version ich_version;/* Controller version, 7 or 9 */ +bool lockdown;/* lock down controller settings? */ +ulong mmio_base;/* Base of MMIO registers */ +}; +static u8 ich_readb (struct ich_spi_priv *priv,int reg) {u8 value =readb (priv->base + reg);@@ -466,16 +472,9 @@ static int ich_init_controller(struct udevice *dev,struct ich_spi_platdata *plat, struct ich_spi_priv *ctlr) { - ulong sbase_addr; -void *sbase; - -/* SBASE is similar */ -pch_get_spi_base (dev->parent, &sbase_addr); - sbase = (void *)sbase_addr; -debug ("%s: sbase=%p\n" , __func__, sbase); - + ctlr->base = (void *)plat->mmio_base;if (plat->ich_version ==ICHV_7 ) { -struct ich7_spi_regs *ich7_spi = sbase; +struct ich7_spi_regs *ich7_spi = ctlr->base; ctlr->opmenu = offsetof(struct ich7_spi_regs , opmenu); ctlr->menubytes =sizeof (ich7_spi->opmenu);@@ -487,9 +486,8 @@ static int ich_init_controller(struct udevice *dev, ctlr->control = offsetof(struct ich7_spi_regs , spic); ctlr->bbar = offsetof(struct ich7_spi_regs , bbar); ctlr->preop = offsetof(struct ich7_spi_regs , preop); - ctlr->base = ich7_spi; }else if (plat->ich_version ==ICHV_9 ) { -struct ich9_spi_regs *ich9_spi = sbase; +struct ich9_spi_regs *ich9_spi = ctlr->base; ctlr->opmenu = offsetof(struct ich9_spi_regs , opmenu); ctlr->menubytes =sizeof (ich9_spi->opmenu);@@ -504,7 +502,6 @@ static int ich_init_controller(struct udevice *dev, ctlr->preop = offsetof(struct ich9_spi_regs , preop); ctlr->bcr = offsetof(struct ich9_spi_regs , bcr); ctlr->pr = &ich9_spi->pr[0 ]; - ctlr->base = ich9_spi; }else {debug ("ICH SPI: Unrecognised ICH version %d\n" , plat->ich_version);@@ -515,8 +512,8 @@ static int ich_init_controller(struct udevice *dev, ctlr->max_speed =20000000 ;if (plat->ich_version ==ICHV_9 &&ich9_can_do_33mhz (dev)) ctlr->max_speed =33000000 ; -debug ("ICH SPI: Version ID %d detected at %p, speed %ld\n" , - plat->ich_version, ctlr->base, ctlr->max_speed); +debug ("ICH SPI: Version ID %d detected at %lx, speed %ld\n" , + plat->ich_version, plat->mmio_base, ctlr->max_speed);ich_set_bbar (ctlr,0 );@@ -601,6 +598,8 @@ static int ich_spi_ofdata_to_platdata(struct udevice *dev) plat->ich_version =dev_get_driver_data (dev); plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" );
Quoted 5 lines
drivers/spi/ich.c static int ich_spi_ofdata_to_platdata(struct udevice *dev) · line 601
Quoted 1 line
drivers/spi/ich.c +1
-0+pch_get_spi_base (dev->parent, &plat->mmio_base);In patch [77], spi: ich: Move the protection/lockdown code into a function, we already removed the assumption of
dev->parent, but usedpriv->pchfor the PCH device.
Yes, this should use priv->pch, I think.
Quoted 13 lines
Quoted 13 lines
drivers/spi/ich.c +1
-0+return 0 ; }drivers/spi/ich.h +0
-0@@ -168,11 +168,6 @@ enum ich_version { ICHV_9, };
Quoted 6 lines
drivers/spi/ich.h enum ich_version { · line 174
Quoted 4 lines
drivers/spi/ich.h +0
-4-struct ich_spi_platdata { -enum ich_version ich_version;/* Controller version, 7 or 9 */ -bool lockdown;/* lock down controller settings? */ -};I don't understand why moving this struct to C file?
We need to add of-platdata to this struct and don't want to do that in a header file. It ends up begin:
struct ich_spi_platdata {
#if CONFIG_IS_ENABLED(OF_PLATDATA)
struct dtd... ...;
#endif
enum ich_version ich_version; /* Controller version, 7 or 9 */
...
}
All structs that use of-platdata should be in C files, I think.
Quoted 6 lines
drivers/spi/ich.h enum ich_version {
Quoted 6 lines
drivers/spi/ich.h +0
-2-struct ich_spi_priv {int opmenu;int menubytes; --
Regards,
Simon
PATCH v3 81/108 spi: ich: Add mmio_base to struct ich_spi_platdata
Hi Simon,
Quoted 125 lines · Simon Glass
Hi Bin,
Quoted 89 lines · Bin Meng
Hi Simon,
Quoted 85 lines · Simon Glass
It is useful to store the mmio base in platdata. It reduces the amount of casting needed. Update the code and move the struct to the C file at the same time, as we will need to use with of-platdata.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 27 +++++++++++++-------------- drivers/spi/ich.h | 5 ----- 2 files changed, 13 insertions(+), 19 deletions(-)drivers/spi/ich.c +11
-14@@ -27,6 +27,12 @@ #define debug_trace(x, args...)#endif +struct ich_spi_platdata { +enum ich_version ich_version;/* Controller version, 7 or 9 */ +bool lockdown;/* lock down controller settings? */ +ulong mmio_base;/* Base of MMIO registers */ +}; +static u8 ich_readb (struct ich_spi_priv *priv,int reg) {u8 value =readb (priv->base + reg);@@ -466,16 +472,9 @@ static int ich_init_controller(struct udevice *dev,struct ich_spi_platdata *plat, struct ich_spi_priv *ctlr) { - ulong sbase_addr; -void *sbase; - -/* SBASE is similar */ -pch_get_spi_base (dev->parent, &sbase_addr); - sbase = (void *)sbase_addr; -debug ("%s: sbase=%p\n" , __func__, sbase); - + ctlr->base = (void *)plat->mmio_base;if (plat->ich_version ==ICHV_7 ) { -struct ich7_spi_regs *ich7_spi = sbase; +struct ich7_spi_regs *ich7_spi = ctlr->base; ctlr->opmenu = offsetof(struct ich7_spi_regs , opmenu); ctlr->menubytes =sizeof (ich7_spi->opmenu);@@ -487,9 +486,8 @@ static int ich_init_controller(struct udevice *dev, ctlr->control = offsetof(struct ich7_spi_regs , spic); ctlr->bbar = offsetof(struct ich7_spi_regs , bbar); ctlr->preop = offsetof(struct ich7_spi_regs , preop); - ctlr->base = ich7_spi; }else if (plat->ich_version ==ICHV_9 ) { -struct ich9_spi_regs *ich9_spi = sbase; +struct ich9_spi_regs *ich9_spi = ctlr->base; ctlr->opmenu = offsetof(struct ich9_spi_regs , opmenu); ctlr->menubytes =sizeof (ich9_spi->opmenu);@@ -504,7 +502,6 @@ static int ich_init_controller(struct udevice *dev, ctlr->preop = offsetof(struct ich9_spi_regs , preop); ctlr->bcr = offsetof(struct ich9_spi_regs , bcr); ctlr->pr = &ich9_spi->pr[0 ]; - ctlr->base = ich9_spi; }else {debug ("ICH SPI: Unrecognised ICH version %d\n" , plat->ich_version);@@ -515,8 +512,8 @@ static int ich_init_controller(struct udevice *dev, ctlr->max_speed =20000000 ;if (plat->ich_version ==ICHV_9 &&ich9_can_do_33mhz (dev)) ctlr->max_speed =33000000 ; -debug ("ICH SPI: Version ID %d detected at %p, speed %ld\n" , - plat->ich_version, ctlr->base, ctlr->max_speed); +debug ("ICH SPI: Version ID %d detected at %lx, speed %ld\n" , + plat->ich_version, plat->mmio_base, ctlr->max_speed);ich_set_bbar (ctlr,0 );@@ -601,6 +598,8 @@ static int ich_spi_ofdata_to_platdata(struct udevice *dev) plat->ich_version =dev_get_driver_data (dev); plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" );Quoted 5 lines
drivers/spi/ich.c static int ich_spi_ofdata_to_platdata(struct udevice *dev) · line 601
Quoted 1 line
drivers/spi/ich.c +1
-0+pch_get_spi_base (dev->parent, &plat->mmio_base);In patch [77], spi: ich: Move the protection/lockdown code into a function, we already removed the assumption of
dev->parent, but usedpriv->pchfor the PCH device.Yes, this should use
priv->pch, I think.Quoted 13 lines
Quoted 13 lines
drivers/spi/ich.c +1
-0+return 0 ; }drivers/spi/ich.h +0
-0@@ -168,11 +168,6 @@ enum ich_version { ICHV_9, };Quoted 6 lines
drivers/spi/ich.h enum ich_version { · line 174
Quoted 4 lines
drivers/spi/ich.h +0
-4-struct ich_spi_platdata { -enum ich_version ich_version;/* Controller version, 7 or 9 */ -bool lockdown;/* lock down controller settings? */ -};I don't understand why moving this struct to C file?
We need to add of-platdata to this struct and don't want to do that in a header file. It ends up begin:
struct
ich_spi_platdata{
Quoted 9 lines
#if CONFIG_IS_ENABLED(OF_PLATDATA) struct dtd... ...;#endif
enumich_versionich_version; /* Controller version, 7 or 9 */
...
}All structs that use of-platdata should be in C files, I think.
Is this hard requirement for drivers with of-platdata? Maybe we need update of-plat.rst to better document this rule.
Regards,
Bin
PATCH v3 81/108 spi: ich: Add mmio_base to struct ich_spi_platdata
Hi Bin,
Quoted 136 lines · Bin Meng
Hi Simon,
Quoted 132 lines · Simon Glass
Hi Bin,
Quoted 89 lines · Bin Meng
Hi Simon,
Quoted 85 lines · Simon Glass
It is useful to store the mmio base in platdata. It reduces the amount of casting needed. Update the code and move the struct to the C file at the same time, as we will need to use with of-platdata.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 27 +++++++++++++-------------- drivers/spi/ich.h | 5 ----- 2 files changed, 13 insertions(+), 19 deletions(-)drivers/spi/ich.c +11
-14@@ -27,6 +27,12 @@ #define debug_trace(x, args...)#endif +struct ich_spi_platdata { +enum ich_version ich_version;/* Controller version, 7 or 9 */ +bool lockdown;/* lock down controller settings? */ +ulong mmio_base;/* Base of MMIO registers */ +}; +static u8 ich_readb (struct ich_spi_priv *priv,int reg) {u8 value =readb (priv->base + reg);@@ -466,16 +472,9 @@ static int ich_init_controller(struct udevice *dev,struct ich_spi_platdata *plat, struct ich_spi_priv *ctlr) { - ulong sbase_addr; -void *sbase; - -/* SBASE is similar */ -pch_get_spi_base (dev->parent, &sbase_addr); - sbase = (void *)sbase_addr; -debug ("%s: sbase=%p\n" , __func__, sbase); - + ctlr->base = (void *)plat->mmio_base;if (plat->ich_version ==ICHV_7 ) { -struct ich7_spi_regs *ich7_spi = sbase; +struct ich7_spi_regs *ich7_spi = ctlr->base; ctlr->opmenu = offsetof(struct ich7_spi_regs , opmenu); ctlr->menubytes =sizeof (ich7_spi->opmenu);@@ -487,9 +486,8 @@ static int ich_init_controller(struct udevice *dev, ctlr->control = offsetof(struct ich7_spi_regs , spic); ctlr->bbar = offsetof(struct ich7_spi_regs , bbar); ctlr->preop = offsetof(struct ich7_spi_regs , preop); - ctlr->base = ich7_spi; }else if (plat->ich_version ==ICHV_9 ) { -struct ich9_spi_regs *ich9_spi = sbase; +struct ich9_spi_regs *ich9_spi = ctlr->base; ctlr->opmenu = offsetof(struct ich9_spi_regs , opmenu); ctlr->menubytes =sizeof (ich9_spi->opmenu);@@ -504,7 +502,6 @@ static int ich_init_controller(struct udevice *dev, ctlr->preop = offsetof(struct ich9_spi_regs , preop); ctlr->bcr = offsetof(struct ich9_spi_regs , bcr); ctlr->pr = &ich9_spi->pr[0 ]; - ctlr->base = ich9_spi; }else {debug ("ICH SPI: Unrecognised ICH version %d\n" , plat->ich_version);@@ -515,8 +512,8 @@ static int ich_init_controller(struct udevice *dev, ctlr->max_speed =20000000 ;if (plat->ich_version ==ICHV_9 &&ich9_can_do_33mhz (dev)) ctlr->max_speed =33000000 ; -debug ("ICH SPI: Version ID %d detected at %p, speed %ld\n" , - plat->ich_version, ctlr->base, ctlr->max_speed); +debug ("ICH SPI: Version ID %d detected at %lx, speed %ld\n" , + plat->ich_version, plat->mmio_base, ctlr->max_speed);ich_set_bbar (ctlr,0 );@@ -601,6 +598,8 @@ static int ich_spi_ofdata_to_platdata(struct udevice *dev) plat->ich_version =dev_get_driver_data (dev); plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" );Quoted 5 lines
drivers/spi/ich.c static int ich_spi_ofdata_to_platdata(struct udevice *dev) · line 601
Quoted 1 line
drivers/spi/ich.c +1
-0+pch_get_spi_base (dev->parent, &plat->mmio_base);In patch [77], spi: ich: Move the protection/lockdown code into a function, we already removed the assumption of
dev->parent, but usedpriv->pchfor the PCH device.Yes, this should use
priv->pch, I think.Quoted 13 lines
Quoted 13 lines
drivers/spi/ich.c +1
-0+return 0 ; }drivers/spi/ich.h +0
-0@@ -168,11 +168,6 @@ enum ich_version { ICHV_9, };Quoted 6 lines
drivers/spi/ich.h enum ich_version { · line 174
Quoted 4 lines
drivers/spi/ich.h +0
-4-struct ich_spi_platdata { -enum ich_version ich_version;/* Controller version, 7 or 9 */ -bool lockdown;/* lock down controller settings? */ -};I don't understand why moving this struct to C file?
We need to add of-platdata to this struct and don't want to do that in a header file. It ends up begin:
struct
ich_spi_platdata{#if CONFIG_IS_ENABLED(OF_PLATDATA) struct dtd... ...;#endif
enumich_versionich_version; /* Controller version, 7 or 9 */
...
}
Quoted 5 lines
Quoted 2 lines
All structs that use of-platdata should be in C files, I think.
Is this hard requirement for drivers with of-platdata? Maybe we need update
of-plat.rstto better document this rule.
Will add this in a new patch.
Yes I think using of-platdata.h in a header file would be bad.
Regards,
Simon
PATCH v3 82/108 spi: ich: Correct max-size bug in ich_spi_adjust_size()
In reply to Simon GlassThis incorrectly shortens read operations if there is a maximum write size but no maximum read size. Fix it.
---
Changes in v3: None
Changes in v2: None
drivers/spi/ich.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/spi/ich.c +5 -3
@@ -424,9 +424,11 @@ static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op) page_offset =do_div (aux,ICH_BOUNDARY ); } -if (op->data.dir ==SPI_MEM_DATA_IN && slave->max_read_size) { - op->data.nbytes =min (ICH_BOUNDARY - page_offset, - slave->max_read_size); +if (op->data.dir ==SPI_MEM_DATA_IN ) { +if (slave->max_read_size) { + op->data.nbytes =min (ICH_BOUNDARY - page_offset, + slave->max_read_size); + } }else if (slave->max_write_size) { op->data.nbytes =min (ICH_BOUNDARY - page_offset, slave->max_write_size);
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 82/108 spi: ich: Correct max-size bug in ich_spi_adjust_size()
Hi Simon,
Quoted 19 lines · Simon Glass
This incorrectly shortens read operations if there is a maximum write size but no maximum read size. Fix it.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/spi/ich.c +0
-0@@ -424,9 +424,11 @@ static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op) page_offset =do_div (aux,ICH_BOUNDARY );
drivers/spi/ich.c static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op) · line 431
Quoted 10 lines
drivers/spi/ich.c +5
-3} -if (op->data.dir ==SPI_MEM_DATA_IN && slave->max_read_size) { - op->data.nbytes =min (ICH_BOUNDARY - page_offset, - slave->max_read_size); +if (op->data.dir ==SPI_MEM_DATA_IN ) { +if (slave->max_read_size) { + op->data.nbytes =min (ICH_BOUNDARY - page_offset, + slave->max_read_size); + }
Isn't the changed one the same as the old codes?
drivers/spi/ich.c static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op)
Quoted 4 lines
drivers/spi/ich.c +0
-1}else if (slave->max_write_size) { op->data.nbytes =min (ICH_BOUNDARY - page_offset, slave->max_write_size); --
Regards,
Bin
PATCH v3 82/108 spi: ich: Correct max-size bug in ich_spi_adjust_size()
Hi Bin,
Quoted 25 lines · Bin Meng
Hi Simon,
Quoted 21 lines · Simon Glass
This incorrectly shortens read operations if there is a maximum write size but no maximum read size. Fix it.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/spi/ich.c +0
-0@@ -424,9 +424,11 @@ static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op) page_offset =do_div (aux,ICH_BOUNDARY ); }
Quoted 10 lines
drivers/spi/ich.c static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op) · line 431
Quoted 8 lines
drivers/spi/ich.c +5
-3-if (op->data.dir ==SPI_MEM_DATA_IN && slave->max_read_size) { - op->data.nbytes =min (ICH_BOUNDARY - page_offset, - slave->max_read_size); +if (op->data.dir ==SPI_MEM_DATA_IN ) { +if (slave->max_read_size) { + op->data.nbytes =min (ICH_BOUNDARY - page_offset, + slave->max_read_size); + }Isn't the changed one the same as the old codes?
The old code fails if max_read_size is 0 but max_write_size is set. It forgets to take account of max_write_size in that case.
Quoted 5 lines
drivers/spi/ich.c static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op)
Quoted 5 lines
drivers/spi/ich.c +0
-1}else if (slave->max_write_size) { op->data.nbytes =min (ICH_BOUNDARY - page_offset, slave->max_write_size); --
Regards,
Simon
PATCH v3 82/108 spi: ich: Correct max-size bug in ich_spi_adjust_size()
Hi Simon,
Quoted 40 lines · Simon Glass
Hi Bin,
Quoted 25 lines · Bin Meng
Hi Simon,
Quoted 21 lines · Simon Glass
This incorrectly shortens read operations if there is a maximum write size but no maximum read size. Fix it.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/spi/ich.c +0
-0@@ -424,9 +424,11 @@ static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op) page_offset =do_div (aux,ICH_BOUNDARY ); }Quoted 10 lines
drivers/spi/ich.c static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op) · line 431
Quoted 8 lines
drivers/spi/ich.c +5
-3-if (op->data.dir ==SPI_MEM_DATA_IN && slave->max_read_size) { - op->data.nbytes =min (ICH_BOUNDARY - page_offset, - slave->max_read_size); +if (op->data.dir ==SPI_MEM_DATA_IN ) { +if (slave->max_read_size) { + op->data.nbytes =min (ICH_BOUNDARY - page_offset, + slave->max_read_size); + }Isn't the changed one the same as the old codes?
Quoted 3 lines
The old code fails if
max_read_sizeis 0 butmax_write_sizeis set. It forgets to take account ofmax_write_sizein that case.
I still don't get this. Based on your description, it seems that your logic works if we remove the } before the else if
Quoted 7 lines
Quoted 6 lines
drivers/spi/ich.c static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op)
Quoted 6 lines
drivers/spi/ich.c +0
-1}else if (slave->max_write_size) { op->data.nbytes =min (ICH_BOUNDARY - page_offset, slave->max_write_size); --
Regards,
Bin
PATCH v3 83/108 spi: ich: Support of-platdata for fast-spi
In reply to Simon GlassThe Intel Fast SPI interface is similar to ICH. Add of-platdata support for this using the "intel,fast-spi" compatible string.
---
Changes in v3: None
Changes in v2: None
drivers/spi/ich.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/spi/ich.c +14 -3
@@ -10,6 +10,7 @@#include <common.h> #include <div64.h> #include <dm.h> +#include <dt-structs.h> #include <errno.h> #include <malloc.h> #include <pch.h>
@@ -28,9 +29,13 @@#endif struct ich_spi_platdata { +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct dtd_intel_fast_spi dtplat; +#endif enum ich_version ich_version;/* Controller version, 7 or 9 */ bool lockdown;/* lock down controller settings? */ ulong mmio_base;/* Base of MMIO registers */ +pci_dev_t bdf;/* PCI address used by of-platdata */ };static u8 ich_readb (struct ich_spi_priv *priv,int reg)
@@ -597,10 +602,16 @@ static int ich_spi_ofdata_to_platdata(struct udevice *dev) {struct ich_spi_platdata *plat =dev_get_platdata (dev); +#if !CONFIG_IS_ENABLED (OF_PLATDATA ) plat->ich_version =dev_get_driver_data (dev); plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" ); -pch_get_spi_base (dev->parent, &plat->mmio_base); +#else + plat->ich_version =ICHV_APL ; + plat->mmio_base = plat->dtplat.early_regs[0 ]; + plat->bdf =pci_x86_ofplat_get_devfn (plat->dtplat.reg[0 ]); +#endif +debug ("%s: mmio_base=%lx\n" , __func__, plat->mmio_base);return 0 ; }
@@ -628,8 +639,8 @@ static const struct udevice_id ich_spi_ids[] = { { } }; -U_BOOT_DRIVER (ich_spi) = { - .name ="ich_spi" , +U_BOOT_DRIVER (intel_fast_spi) = { + .name ="intel_fast_spi" , .id =UCLASS_SPI , .of_match = ich_spi_ids, .ops = &ich_spi_ops,
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH v3 83/108 spi: ich: Support of-platdata for fast-spi
Hi Simon,
Quoted 40 lines · Simon Glass
The Intel Fast SPI interface is similar to ICH. Add of-platdata support for this using the "intel,fast-spi" compatible string.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/spi/ich.c +5
-0@@ -10,6 +10,7 @@#include <common.h> #include <div64.h> #include <dm.h> +#include <dt-structs.h> #include <errno.h> #include <malloc.h> #include <pch.h> @@ -28,9 +29,13 @@#endif struct ich_spi_platdata { +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct dtd_intel_fast_spi dtplat; +#endif enum ich_version ich_version;/* Controller version, 7 or 9 */ bool lockdown;/* lock down controller settings? */ ulong mmio_base;/* Base of MMIO registers */ +pci_dev_t bdf;/* PCI address used by of-platdata */ };static u8 ich_readb (struct ich_spi_priv *priv,int reg)
drivers/spi/ich.c static int ich_spi_ofdata_to_platdata(struct udevice *dev) · line 610
Quoted 10 lines
drivers/spi/ich.c +3
-1@@ -597,10 +602,16 @@ static int ich_spi_ofdata_to_platdata(struct udevice *dev) {struct ich_spi_platdata *plat =dev_get_platdata (dev); +#if !CONFIG_IS_ENABLED (OF_PLATDATA ) plat->ich_version =dev_get_driver_data (dev); plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" ); -pch_get_spi_base (dev->parent, &plat->mmio_base); +#else + plat->ich_version =ICHV_APL ;
I don't think the ICH_VERSION is something that is controlled via OF_PLATDATA.
Quoted 8 lines
drivers/spi/ich.c +4
-0+ plat->mmio_base = plat->dtplat.early_regs[0 ]; + plat->bdf =pci_x86_ofplat_get_devfn (plat->dtplat.reg[0 ]); +#endif +debug ("%s: mmio_base=%lx\n" , __func__, plat->mmio_base);return 0 ; }
drivers/spi/ich.c static const struct udevice_id ich_spi_ids[] = { · line 642
Quoted 6 lines
drivers/spi/ich.c +1
-2@@ -628,8 +639,8 @@ static const struct udevice_id ich_spi_ids[] = { { } }; -U_BOOT_DRIVER (ich_spi) = { - .name ="ich_spi" , +U_BOOT_DRIVER (intel_fast_spi) = {
Why changing the driver name?
drivers/spi/ich.c static const struct udevice_id ich_spi_ids[] = {
Quoted 5 lines
drivers/spi/ich.c +1
-1+ .name = "intel_fast_spi", .id = UCLASS_SPI, .of_match = ich_spi_ids, .ops = &ich_spi_ops, --
Regards,
Bin
PATCH v3 83/108 spi: ich: Support of-platdata for fast-spi
Hi Bin,
Quoted 47 lines · Bin Meng
Hi Simon,
Quoted 43 lines · Simon Glass
The Intel Fast SPI interface is similar to ICH. Add of-platdata support for this using the "intel,fast-spi" compatible string.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/spi/ich.c +5
-0@@ -10,6 +10,7 @@#include <common.h> #include <div64.h> #include <dm.h> +#include <dt-structs.h> #include <errno.h> #include <malloc.h> #include <pch.h> @@ -28,9 +29,13 @@#endif struct ich_spi_platdata { +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct dtd_intel_fast_spi dtplat; +#endif enum ich_version ich_version;/* Controller version, 7 or 9 */ bool lockdown;/* lock down controller settings? */ ulong mmio_base;/* Base of MMIO registers */ +pci_dev_t bdf;/* PCI address used by of-platdata */ };static u8 ich_readb (struct ich_spi_priv *priv,int reg)@@ -597,10 +602,16 @@ static int ich_spi_ofdata_to_platdata(struct udevice *dev) {struct ich_spi_platdata *plat =dev_get_platdata (dev);
Quoted 9 lines
drivers/spi/ich.c static int ich_spi_ofdata_to_platdata(struct udevice *dev) · line 610
Quoted 7 lines
drivers/spi/ich.c +3
-1+#if !CONFIG_IS_ENABLED (OF_PLATDATA ) plat->ich_version =dev_get_driver_data (dev); plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" ); -pch_get_spi_base (dev->parent, &plat->mmio_base); +#else + plat->ich_version =ICHV_APL ;I don't think the
ICH_VERSIONis something that is controlled viaOF_PLATDATA.
Well, the fact that we are using dtd_intel_fast_spi means that the compatible string is intel,fast-spi, so that's why we set this version variable. The older SPI-controller versions don't actually support of-platdata, so this is safe.
Quoted 12 lines
Quoted 12 lines
drivers/spi/ich.c +4
-0+ plat->mmio_base = plat->dtplat.early_regs[0 ]; + plat->bdf =pci_x86_ofplat_get_devfn (plat->dtplat.reg[0 ]); +#endif +debug ("%s: mmio_base=%lx\n" , __func__, plat->mmio_base);return 0 ; }@@ -628,8 +639,8 @@ static const struct udevice_id ich_spi_ids[] = { { } };
Quoted 5 lines
drivers/spi/ich.c static const struct udevice_id ich_spi_ids[] = { · line 642
Quoted 3 lines
drivers/spi/ich.c +1
-2-U_BOOT_DRIVER (ich_spi) = { - .name ="ich_spi" , +U_BOOT_DRIVER (intel_fast_spi) = {Why changing the driver name?
So that of-platdata will create a U_BOOT_DEVICE() for it and it will be bound. Otherwise the name will not match and the device is ignored.
I will update the commit message.
Quoted 9 lines
drivers/spi/ich.c static const struct udevice_id ich_spi_ids[] = {
Quoted 6 lines
drivers/spi/ich.c +1
-1+ .name = "intel_fast_spi", .id = UCLASS_SPI, .of_match = ich_spi_ids, .ops = &ich_spi_ops, --Regards,
Bin
Regards,
Simon
PATCH v3 83/108 spi: ich: Support of-platdata for fast-spi
Hi Simon,
Quoted 61 lines · Simon Glass
Hi Bin,
Quoted 47 lines · Bin Meng
Hi Simon,
Quoted 43 lines · Simon Glass
The Intel Fast SPI interface is similar to ICH. Add of-platdata support for this using the "intel,fast-spi" compatible string.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/spi/ich.c +5
-0@@ -10,6 +10,7 @@#include <common.h> #include <div64.h> #include <dm.h> +#include <dt-structs.h> #include <errno.h> #include <malloc.h> #include <pch.h> @@ -28,9 +29,13 @@#endif struct ich_spi_platdata { +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct dtd_intel_fast_spi dtplat; +#endif enum ich_version ich_version;/* Controller version, 7 or 9 */ bool lockdown;/* lock down controller settings? */ ulong mmio_base;/* Base of MMIO registers */ +pci_dev_t bdf;/* PCI address used by of-platdata */ };static u8 ich_readb (struct ich_spi_priv *priv,int reg)@@ -597,10 +602,16 @@ static int ich_spi_ofdata_to_platdata(struct udevice *dev) {struct ich_spi_platdata *plat =dev_get_platdata (dev);Quoted 9 lines
drivers/spi/ich.c static int ich_spi_ofdata_to_platdata(struct udevice *dev) · line 610
Quoted 7 lines
drivers/spi/ich.c +3
-1+#if !CONFIG_IS_ENABLED (OF_PLATDATA ) plat->ich_version =dev_get_driver_data (dev); plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" ); -pch_get_spi_base (dev->parent, &plat->mmio_base); +#else + plat->ich_version =ICHV_APL ;I don't think the
ICH_VERSIONis something that is controlled viaOF_PLATDATA.
Quoted 5 lines
Well, the fact that we are using
dtd_intel_fast_spimeans that the compatible string is intel,fast-spi, so that's why we set this version variable. The older SPI-controller versions don't actually support of-platdata, so this is safe.
What if we have another platform that uses OF_PLATDATA but is not ICHV_APL? How do we distinguish that?
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/spi/ich.c +4
-0+ plat->mmio_base = plat->dtplat.early_regs[0 ]; + plat->bdf =pci_x86_ofplat_get_devfn (plat->dtplat.reg[0 ]); +#endif +debug ("%s: mmio_base=%lx\n" , __func__, plat->mmio_base);return 0 ; }@@ -628,8 +639,8 @@ static const struct udevice_id ich_spi_ids[] = { { } };
Quoted 9 lines
Quoted 5 lines
drivers/spi/ich.c static const struct udevice_id ich_spi_ids[] = { · line 642
Quoted 3 lines
drivers/spi/ich.c +1
-2-U_BOOT_DRIVER (ich_spi) = { - .name ="ich_spi" , +U_BOOT_DRIVER (intel_fast_spi) = {Why changing the driver name?
So that of-platdata will create a
U_BOOT_DEVICE()for it and it will be bound. Otherwise the name will not match and the device is ignored.
Could we avoid renaming the driver, ie: reusing the same "ich_spi" name?
Quoted 8 lines
I will update the commit message.
Quoted 6 lines
Quoted 6 lines
drivers/spi/ich.c +1
-1+ .name = "intel_fast_spi", .id = UCLASS_SPI, .of_match = ich_spi_ids, .ops = &ich_spi_ops, --
Regards,
Bin
PATCH v3 83/108 spi: ich: Support of-platdata for fast-spi
Hi Bin,
Quoted 92 lines · Bin Meng
Hi Simon,
Quoted 61 lines · Simon Glass
Hi Bin,
Quoted 47 lines · Bin Meng
Hi Simon,
Quoted 43 lines · Simon Glass
The Intel Fast SPI interface is similar to ICH. Add of-platdata support for this using the "intel,fast-spi" compatible string.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/spi/ich.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/spi/ich.c +5
-0@@ -10,6 +10,7 @@#include <common.h> #include <div64.h> #include <dm.h> +#include <dt-structs.h> #include <errno.h> #include <malloc.h> #include <pch.h> @@ -28,9 +29,13 @@#endif struct ich_spi_platdata { +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct dtd_intel_fast_spi dtplat; +#endif enum ich_version ich_version;/* Controller version, 7 or 9 */ bool lockdown;/* lock down controller settings? */ ulong mmio_base;/* Base of MMIO registers */ +pci_dev_t bdf;/* PCI address used by of-platdata */ };static u8 ich_readb (struct ich_spi_priv *priv,int reg)@@ -597,10 +602,16 @@ static int ich_spi_ofdata_to_platdata(struct udevice *dev) {struct ich_spi_platdata *plat =dev_get_platdata (dev);Quoted 9 lines
drivers/spi/ich.c static int ich_spi_ofdata_to_platdata(struct udevice *dev) · line 610
Quoted 7 lines
drivers/spi/ich.c +3
-1+#if !CONFIG_IS_ENABLED (OF_PLATDATA ) plat->ich_version =dev_get_driver_data (dev); plat->lockdown =dev_read_bool (dev,"intel,spi-lock-down" ); -pch_get_spi_base (dev->parent, &plat->mmio_base); +#else + plat->ich_version =ICHV_APL ;I don't think the
ICH_VERSIONis something that is controlled viaOF_PLATDATA.Quoted 5 lines
Well, the fact that we are using
dtd_intel_fast_spimeans that the compatible string is intel,fast-spi, so that's why we set this version variable. The older SPI-controller versions don't actually support of-platdata, so this is safe.What if we have another platform that uses
OF_PLATDATAbut is notICHV_APL? How do we distinguish that?Quoted 18 lines
Quoted 17 lines
Quoted 9 lines
drivers/spi/ich.c +4
-0+ plat->mmio_base = plat->dtplat.early_regs[0 ]; + plat->bdf =pci_x86_ofplat_get_devfn (plat->dtplat.reg[0 ]); +#endif +debug ("%s: mmio_base=%lx\n" , __func__, plat->mmio_base);return 0 ; }drivers/spi/ich.c static const struct udevice_id ich_spi_ids[] = { · line 642
Quoted 6 lines
drivers/spi/ich.c +1
-2@@ -628,8 +639,8 @@ static const struct udevice_id ich_spi_ids[] = { { } }; -U_BOOT_DRIVER (ich_spi) = { - .name ="ich_spi" , +U_BOOT_DRIVER (intel_fast_spi) = {Why changing the driver name?
Quoted 5 lines
Quoted 3 lines
So that of-platdata will create a
U_BOOT_DEVICE()for it and it will be bound. Otherwise the name will not match and the device is ignored.Could we avoid renaming the driver, ie: reusing the same "
ich_spi" name?
Yes, but that would mean we'd have to use a compatible string of "ich-spi' which breaks the rule of using 'vendor,device'.
Quoted 9 lines
Quoted 9 lines
I will update the commit message.
Quoted 6 lines
Quoted 6 lines
drivers/spi/ich.c +1
-1+ .name = "intel_fast_spi", .id = UCLASS_SPI, .of_match = ich_spi_ids, .ops = &ich_spi_ops, --
Regards,
Simon