mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/8] add generic EFI timer
@ 2017-02-27 10:14 Jean-Christophe PLAGNIOL-VILLARD
  2017-02-27 10:19 ` [PATCH 1/8] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-02-27 10:14 UTC (permalink / raw)
  To: barebox

Hi,

	On EFI you have 3 ways to get to do "timer"

	1: Simply by waiting X us and calling Boot Service udelay

	2: By using event

	3: By use the Timestamp GUID

	for barebox this would be the best but even on EDK II this is never
	ever compiled on any target.

	So we have 2 choice, use a Hardware specific timer or implement the
	timer using timestamp

	This pull request allow you to enable 2 timers and use the best one at
	runtime.

	EFI x86 (HW specific)
	EFI Generic (based on Event)

please pull
The following changes since commit d92ed454107b4d6f0d30fa0271da191ae5911d18:

  Merge branch 'for-next/video' into next (2017-02-27 08:51:08 +0100)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git

for you to fetch changes up to 169af081c48d6739a3727f07a4b8dbfb7ab48ebb:

  efi: add veriable to report secure boot support and status (2017-02-27 18:20:37 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (8):
      efi: add prototype and definition for creating and closing event
      efi: add prototype and definition for setting timer
      efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall
      efi: move x86 clocksource init at core initcall level
      clocksource: allow to have multiple device from clock source
      efi: move x86 clocksource to device/driver
      efi: clocksoure: use event for timer
      efi: add veriable to report secure boot support and status

 arch/x86/Kconfig                |   2 +-
 arch/x86/mach-efi/Makefile      |   1 +
 arch/x86/mach-efi/clocksource.c |  11 +++++++++++
 common/clock.c                  |  11 +++++++++++
 common/efi/efi.c                |  24 +++++++++++++++++++-----
 drivers/clocksource/Kconfig     |   6 +++++-
 drivers/clocksource/Makefile    |   1 +
 drivers/clocksource/efi.c       | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
 drivers/clocksource/efi_x86.c   |  79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/efi/efi-device.c        |  33 +++++++++++++++++++++++++++++++++
 include/clock.h                 |   3 ++-
 include/efi.h                   |  25 ++++++++++++++++++++++---
 include/efi/efi.h               |   2 --
 13 files changed, 266 insertions(+), 42 deletions(-)
 create mode 100644 arch/x86/mach-efi/clocksource.c
 create mode 100644 drivers/clocksource/efi_x86.c

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/8] efi: add prototype and definition for creating and closing event
  2017-02-27 10:14 [PATCH 0/8] add generic EFI timer Jean-Christophe PLAGNIOL-VILLARD
@ 2017-02-27 10:19 ` Jean-Christophe PLAGNIOL-VILLARD
  2017-02-27 10:19   ` [PATCH 2/8] efi: add prototype and definition for setting timer Jean-Christophe PLAGNIOL-VILLARD
                     ` (6 more replies)
  0 siblings, 7 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-02-27 10:19 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/efi.h | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/include/efi.h b/include/efi.h
index 5691f4e8f..f65980687 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -185,12 +185,25 @@ typedef struct {
 				       unsigned long *, u32 *);
 	efi_status_t (EFIAPI *allocate_pool)(int, unsigned long, void **);
 	efi_status_t (EFIAPI *free_pool)(void *);
-	void *create_event;
+#define EFI_EVT_TIMER				0x80000000
+#define EFI_EVT_RUNTIME				0x40000000
+#define EFI_EVT_NOTIFY_WAIT			0x00000100
+#define EFI_EVT_NOTIFY_SIGNAL			0x00000200
+#define EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES	0x00000201
+#define EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE	0x60000202
+
+#define EFI_TPL_APPLICATION	4
+#define EFI_TPL_CALLBACK	8
+#define EFI_TPL_NOTIFY		16
+#define EFI_TPL_HIGH_LEVEL	31
+	efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
+			void (*fn) (void *event, void *ctx),
+			void *ctx, void **event);
 	void *set_timer;
 	efi_status_t(EFIAPI *wait_for_event)(unsigned long number_of_events, void *event,
 			unsigned long *index);
 	void *signal_event;
-	void *close_event;
+	efi_status_t(EFIAPI *close_event)(void *event);
 	void *check_event;
 	void *install_protocol_interface;
 	void *reinstall_protocol_interface;
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/8] efi: add prototype and definition for setting timer
  2017-02-27 10:19 ` [PATCH 1/8] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
@ 2017-02-27 10:19   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-02-27 10:19   ` [PATCH 3/8] efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall Jean-Christophe PLAGNIOL-VILLARD
                     ` (5 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-02-27 10:19 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/efi.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/efi.h b/include/efi.h
index f65980687..e1fc134ee 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -171,6 +171,12 @@ struct efi_open_protocol_information_entry {
 	u32 open_count;
 };
 
+typedef enum {
+	EFI_TIMER_CANCEL = 0,
+	EFI_TIMER_PERIODIC = 1,
+	EFI_TIMER_RELATIVE = 2
+} efi_timer_delay_t;
+
 /*
  * EFI Boot Services table
  */
@@ -199,7 +205,7 @@ typedef struct {
 	efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
 			void (*fn) (void *event, void *ctx),
 			void *ctx, void **event);
-	void *set_timer;
+	efi_status_t(EFIAPI *set_timer)(void *event, efi_timer_delay_t type, uint64_t time);
 	efi_status_t(EFIAPI *wait_for_event)(unsigned long number_of_events, void *event,
 			unsigned long *index);
 	void *signal_event;
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 3/8] efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall
  2017-02-27 10:19 ` [PATCH 1/8] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
  2017-02-27 10:19   ` [PATCH 2/8] efi: add prototype and definition for setting timer Jean-Christophe PLAGNIOL-VILLARD
@ 2017-02-27 10:19   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-02-27 10:19   ` [PATCH 4/8] efi: move x86 clocksource init at core initcall level Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-02-27 10:19 UTC (permalink / raw)
  To: barebox

so we can use device/driver for the timer

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/efi/efi.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/common/efi/efi.c b/common/efi/efi.c
index 217a6bea8..1c7aee872 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -314,7 +314,6 @@ efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
 	efi_physical_addr_t mem;
 	size_t memsize;
 	efi_status_t efiret;
-	char *uuid;
 
 #ifdef DEBUG
 	sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
@@ -350,6 +349,15 @@ efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
 	mem_malloc_init((void *)mem, (void *)mem + memsize);
 
 	efi_clocksource_init();
+	start_barebox();
+
+	return EFI_SUCCESS;
+}
+
+static int efi_postcore_init(void)
+{
+	char *uuid;
+
 	efi_set_variable_usec("LoaderTimeInitUSec", &efi_systemd_vendor_guid,
 			      get_time_ns()/1000);
 
@@ -366,10 +374,9 @@ efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
 		free(uuid16);
 	}
 
-	start_barebox();
-
-	return EFI_SUCCESS;
+	return 0;
 }
+postcore_initcall(efi_postcore_init);
 
 static int do_efiexit(int argc, char *argv[])
 {
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/8] efi: move x86 clocksource init at core initcall level
  2017-02-27 10:19 ` [PATCH 1/8] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
  2017-02-27 10:19   ` [PATCH 2/8] efi: add prototype and definition for setting timer Jean-Christophe PLAGNIOL-VILLARD
  2017-02-27 10:19   ` [PATCH 3/8] efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall Jean-Christophe PLAGNIOL-VILLARD
@ 2017-02-27 10:19   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-02-27 10:19   ` [PATCH 5/8] clocksource: allow to have multiple device from clock source Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-02-27 10:19 UTC (permalink / raw)
  To: barebox

so we can use device/driver model

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/efi/efi.c          | 1 -
 drivers/clocksource/efi.c | 5 ++++-
 include/efi/efi.h         | 2 --
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/efi/efi.c b/common/efi/efi.c
index 1c7aee872..4b589b600 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -348,7 +348,6 @@ efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
 		      efi_strerror(efiret));
 	mem_malloc_init((void *)mem, (void *)mem + memsize);
 
-	efi_clocksource_init();
 	start_barebox();
 
 	return EFI_SUCCESS;
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
index 59fd9918a..6d2fee8eb 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi.c
@@ -1,4 +1,5 @@
 #include <common.h>
+#include <init.h>
 #include <efi.h>
 #include <efi/efi.h>
 #include <clock.h>
@@ -48,7 +49,7 @@ static struct clocksource cs = {
 	.shift  = 0,
 };
 
-int efi_clocksource_init(void)
+static int efi_clocksource_init(void)
 {
 	cs.mult = clocksource_hz2mult(1000 * 1000, cs.shift);
 
@@ -56,3 +57,5 @@ int efi_clocksource_init(void)
 
 	return init_clock(&cs);
 }
+/* for efi the time must be init at core initcall level */
+core_initcall(efi_clocksource_init);
diff --git a/include/efi/efi.h b/include/efi/efi.h
index 2b25cf186..648afb9ec 100644
--- a/include/efi/efi.h
+++ b/include/efi/efi.h
@@ -12,8 +12,6 @@ extern efi_loaded_image_t *efi_loaded_image;
 
 int efi_errno(efi_status_t err);
 
-int efi_clocksource_init(void);
-
 void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size);
 
 static inline void *efi_get_global_var(char *name, int *var_size)
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 5/8] clocksource: allow to have multiple device from clock source
  2017-02-27 10:19 ` [PATCH 1/8] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 preceding siblings ...)
  2017-02-27 10:19   ` [PATCH 4/8] efi: move x86 clocksource init at core initcall level Jean-Christophe PLAGNIOL-VILLARD
@ 2017-02-27 10:19   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-02-28  7:09     ` Sascha Hauer
  2017-02-27 10:19   ` [PATCH 6/8] efi: move x86 clocksource to device/driver Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-02-27 10:19 UTC (permalink / raw)
  To: barebox

use the one with the most priority.

We can not select the clocksource at user level.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/clock.c  | 11 +++++++++++
 include/clock.h |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/common/clock.c b/common/clock.c
index 2c5dd91cc..d99d06853 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -213,6 +213,17 @@ EXPORT_SYMBOL(mdelay_non_interruptible);
 
 int init_clock(struct clocksource *cs)
 {
+	if (current_clock && cs->priority < current_clock->priority)
+		return -EBUSY;
+
+	if (cs->init) {
+		int ret;
+
+		ret = cs->init(cs);
+		if (ret)
+			return ret;
+	}
+
 	current_clock = cs;
 	time_beginning = get_time_ns();
 
diff --git a/include/clock.h b/include/clock.h
index d65e404e8..5f2f53ab6 100644
--- a/include/clock.h
+++ b/include/clock.h
@@ -12,7 +12,8 @@ struct clocksource {
 	uint64_t	(*read)(void);
 	uint64_t	cycle_last;
 	uint64_t	mask;
-
+	int		priority;
+	int		(*init)(struct clocksource*);
 };
 
 static inline uint32_t cyc2ns(struct clocksource *cs, uint64_t cycles)
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 6/8] efi: move x86 clocksource to device/driver
  2017-02-27 10:19 ` [PATCH 1/8] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 preceding siblings ...)
  2017-02-27 10:19   ` [PATCH 5/8] clocksource: allow to have multiple device from clock source Jean-Christophe PLAGNIOL-VILLARD
@ 2017-02-27 10:19   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-02-27 10:19   ` [PATCH 7/8] efi: clocksoure: use event for timer Jean-Christophe PLAGNIOL-VILLARD
  2017-02-27 10:19   ` [PATCH 8/8] efi: add veriable to report secure boot support and status Jean-Christophe PLAGNIOL-VILLARD
  6 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-02-27 10:19 UTC (permalink / raw)
  To: barebox

so we can dynamicly register the device

As we may need to use HW IP for clocksource.

As on EFI we could use Timestamp GUID if present (Not often the case as it's
not even enabled by default on any Target on EDK II not even OVMF)

Or if we choose we could use a Simulated Timestamp driver that work on Event
(Add Later)

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/x86/Kconfig                         |  2 +-
 arch/x86/mach-efi/Makefile               |  1 +
 arch/x86/mach-efi/clocksource.c          | 11 +++++++++++
 drivers/clocksource/Kconfig              |  6 +++---
 drivers/clocksource/Makefile             |  2 +-
 drivers/clocksource/{efi.c => efi_x86.c} | 34 ++++++++++++++++++++++++--------
 6 files changed, 43 insertions(+), 13 deletions(-)
 create mode 100644 arch/x86/mach-efi/clocksource.c
 rename drivers/clocksource/{efi.c => efi_x86.c} (56%)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 9803f3f95..52ccf4894 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -77,7 +77,7 @@ choice
 		select EFI_GUID
 		select EFI_DEVICEPATH
 		select PRINTF_UUID
-		select CLOCKSOURCE_EFI
+		select CLOCKSOURCE_EFI_X86
 
 	config X86_BIOS_BRINGUP
 		bool "16 bit BIOS"
diff --git a/arch/x86/mach-efi/Makefile b/arch/x86/mach-efi/Makefile
index c8a97bae0..f633e7c7e 100644
--- a/arch/x86/mach-efi/Makefile
+++ b/arch/x86/mach-efi/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_X86_64) += reloc_x86_64.o crt0-efi-x86_64.o
 obj-$(CONFIG_X86_32) += reloc_ia32.o crt0-efi-ia32.o
+obj-y += clocksource.o
 extra-$(CONFIG_X86_32) += elf_ia32_efi.lds
 extra-$(CONFIG_X86_64) += elf_x86_64_efi.lds
diff --git a/arch/x86/mach-efi/clocksource.c b/arch/x86/mach-efi/clocksource.c
new file mode 100644
index 000000000..2023fa19a
--- /dev/null
+++ b/arch/x86/mach-efi/clocksource.c
@@ -0,0 +1,11 @@
+#include <common.h>
+#include <init.h>
+#include <driver.h>
+
+static int efi_x86_pure_init(void)
+{
+	struct device_d *dev = device_alloc("efi-cs-x86", DEVICE_ID_SINGLE);
+
+	return platform_device_register(dev);
+}
+core_initcall(efi_x86_pure_init);
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 54b05bbf3..9b7f0a9d7 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -34,9 +34,9 @@ config CLOCKSOURCE_DUMMY_RATE
 	  The option CONFIG_CLOCKSOURCE_DUMMY_RATE is used to adjust this clocksource.
 	  The bigger rate valuest makes clocksource "faster".
 
-config CLOCKSOURCE_EFI
-	bool
-	depends on EFI_BOOTUP
+config CLOCKSOURCE_EFI_X86
+	bool "EFI X86 HW driver"
+	depends on EFI_BOOTUP && X86
 
 config CLOCKSOURCE_MVEBU
 	bool
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index e83fdeeec..1fd18296e 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -3,7 +3,7 @@ obj-$(CONFIG_ARM_SMP_TWD) += arm_smp_twd.o
 obj-$(CONFIG_CLOCKSOURCE_BCM283X) += bcm2835.o
 obj-$(CONFIG_CLOCKSOURCE_CLPS711X) += clps711x.o
 obj-$(CONFIG_CLOCKSOURCE_DIGIC)   += digic.o
-obj-$(CONFIG_CLOCKSOURCE_EFI) += efi.o
+obj-$(CONFIG_CLOCKSOURCE_EFI_X86) += efi_x86.o
 obj-$(CONFIG_CLOCKSOURCE_MVEBU)   += mvebu.o
 obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o
 obj-$(CONFIG_CLOCKSOURCE_ORION)   += orion.o
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi_x86.c
similarity index 56%
rename from drivers/clocksource/efi.c
rename to drivers/clocksource/efi_x86.c
index 6d2fee8eb..4d2657ea1 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi_x86.c
@@ -1,5 +1,6 @@
 #include <common.h>
 #include <init.h>
+#include <driver.h>
 #include <efi.h>
 #include <efi/efi.h>
 #include <clock.h>
@@ -38,24 +39,41 @@ static uint64_t ticks_freq(void)
 	return (ticks_end - ticks_start) * 1000;
 }
 
-static uint64_t efi_clocksource_read(void)
+static uint64_t efi_x86_cs_read(void)
 {
 	return 1000 * 1000 * ticks_read() / freq;
 }
 
-static struct clocksource cs = {
-	.read   = efi_clocksource_read,
+static int efi_x86_cs_init(struct clocksource *cs)
+{
+	cs->mult = clocksource_hz2mult(1000 * 1000, cs->shift);
+
+	freq = ticks_freq();
+
+	return 0;
+}
+
+static struct clocksource efi_x86_cs = {
+	.read   = efi_x86_cs_read,
 	.mask   = CLOCKSOURCE_MASK(64),
 	.shift  = 0,
+	.priority = 100,
+	.init   = efi_x86_cs_init,
 };
 
-static int efi_clocksource_init(void)
+static int efi_x86_cs_probe(struct device_d *dev)
 {
-	cs.mult = clocksource_hz2mult(1000 * 1000, cs.shift);
+	return init_clock(&efi_x86_cs);
+}
 
-	freq = ticks_freq();
+static struct driver_d efi_x86_cs_driver = {
+	.name = "efi-cs-x86",
+	.probe = efi_x86_cs_probe,
+};
 
-	return init_clock(&cs);
+static int efi_x86_cs_initcall(void)
+{
+	return platform_driver_register(&efi_x86_cs_driver);
 }
 /* for efi the time must be init at core initcall level */
-core_initcall(efi_clocksource_init);
+core_initcall(efi_x86_cs_initcall);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 7/8] efi: clocksoure: use event for timer
  2017-02-27 10:19 ` [PATCH 1/8] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 preceding siblings ...)
  2017-02-27 10:19   ` [PATCH 6/8] efi: move x86 clocksource to device/driver Jean-Christophe PLAGNIOL-VILLARD
@ 2017-02-27 10:19   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-13 10:30     ` Michael Olbrich
  2017-02-27 10:19   ` [PATCH 8/8] efi: add veriable to report secure boot support and status Jean-Christophe PLAGNIOL-VILLARD
  6 siblings, 1 reply; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-02-27 10:19 UTC (permalink / raw)
  To: barebox

with this we can be hw generic

If the EFI implement timestamp protocol we could use instead of event
but even EDK2 Never Ever compile it for any target.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/efi/efi.c             |   8 ++++
 drivers/clocksource/Kconfig  |   4 ++
 drivers/clocksource/Makefile |   1 +
 drivers/clocksource/efi.c    | 110 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 123 insertions(+)
 create mode 100644 drivers/clocksource/efi.c

diff --git a/common/efi/efi.c b/common/efi/efi.c
index 4b589b600..05c58250f 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -353,6 +353,14 @@ efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
 	return EFI_SUCCESS;
 }
 
+static int efi_core_init(void)
+{
+	struct device_d *dev = device_alloc("efi-cs", DEVICE_ID_SINGLE);
+
+	return platform_device_register(dev);
+}
+core_initcall(efi_core_init);
+
 static int efi_postcore_init(void)
 {
 	char *uuid;
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 9b7f0a9d7..b12a85403 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -34,6 +34,10 @@ config CLOCKSOURCE_DUMMY_RATE
 	  The option CONFIG_CLOCKSOURCE_DUMMY_RATE is used to adjust this clocksource.
 	  The bigger rate valuest makes clocksource "faster".
 
+config CLOCKSOURCE_EFI
+	bool "Generic EFI Driver"
+	depends on EFI_BOOTUP
+
 config CLOCKSOURCE_EFI_X86
 	bool "EFI X86 HW driver"
 	depends on EFI_BOOTUP && X86
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 1fd18296e..f69b33d0b 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_ARM_SMP_TWD) += arm_smp_twd.o
 obj-$(CONFIG_CLOCKSOURCE_BCM283X) += bcm2835.o
 obj-$(CONFIG_CLOCKSOURCE_CLPS711X) += clps711x.o
 obj-$(CONFIG_CLOCKSOURCE_DIGIC)   += digic.o
+obj-$(CONFIG_CLOCKSOURCE_EFI) += efi.o
 obj-$(CONFIG_CLOCKSOURCE_EFI_X86) += efi_x86.o
 obj-$(CONFIG_CLOCKSOURCE_MVEBU)   += mvebu.o
 obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
new file mode 100644
index 000000000..df65dd86c
--- /dev/null
+++ b/drivers/clocksource/efi.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnio@jcrosoft.com>
+ *
+ * Under GPL v2
+ */
+#include <common.h>
+#include <init.h>
+#include <driver.h>
+#include <clock.h>
+#include <efi.h>
+#include <efi/efi.h>
+#include <efi/efi-device.h>
+#include <linux/err.h>
+
+static uint64_t ticks = 1;
+static void *efi_cs_evt;
+
+static uint64_t efi_cs_read(void)
+{
+	return ticks;
+}
+
+static void efi_cs_inc(void *event, void *ctx)
+{
+	ticks++;
+}
+
+/* count ticks during a 1dms */
+static uint64_t ticks_freq(void)
+{
+	uint64_t ticks_start, ticks_end;
+
+	ticks_start = ticks;
+	BS->stall(1000);
+	ticks_end = ticks;
+
+	return (ticks_end - ticks_start) * 1000;
+}
+
+/* count ticks during a 20ms delay as on qemu x86_64 the max is 100Hz */
+static uint64_t ticks_freq_x86(void)
+{
+	uint64_t ticks_start, ticks_end;
+
+	ticks_start = ticks;
+	BS->stall(20 * 1000);
+	ticks_end = ticks;
+
+	return (ticks_end - ticks_start) * 50;
+}
+
+static int efi_cs_init(struct clocksource *cs)
+{
+	efi_status_t efiret;
+	uint64_t freq;
+
+	efiret = BS->create_event(EFI_EVT_TIMER | EFI_EVT_NOTIFY_SIGNAL,
+			EFI_TPL_CALLBACK, efi_cs_inc, NULL, &efi_cs_evt);
+
+	if (EFI_ERROR(efiret))
+		return -efi_errno(efiret);
+
+	efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, 10);
+	if (EFI_ERROR(efiret)) {
+		BS->close_event(efi_cs_evt);
+		return -efi_errno(efiret);
+	}
+
+	freq = 1000 * 1000;
+	if (ticks_freq() < 800 * 1000) {
+		uint64_t nb_100ns;
+
+		freq = ticks_freq_x86();
+		nb_100ns = 10 * 1000 * 1000 / freq;
+		pr_warn("EFI Event timer too slow freq = %llu Hz\n", freq);
+		efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, nb_100ns);
+		if (EFI_ERROR(efiret)) {
+			BS->close_event(efi_cs_evt);
+			return -efi_errno(efiret);
+		}
+	}
+
+	cs->mult = clocksource_hz2mult(freq, cs->shift);
+
+	return 0;
+}
+
+static struct clocksource efi_cs = {
+	.read   = efi_cs_read,
+	.mask   = CLOCKSOURCE_MASK(64),
+	.shift  = 0,
+	.init   = efi_cs_init,
+};
+
+static int efi_cs_probe(struct device_d *dev)
+{
+	return init_clock(&efi_cs);
+}
+
+static struct driver_d efi_cs_driver = {
+	.name = "efi-cs",
+	.probe = efi_cs_probe,
+};
+
+static int efi_cs_initcall(void)
+{
+	return platform_driver_register(&efi_cs_driver);
+}
+/* for efi the time must be init at core initcall level */
+late_initcall(efi_cs_initcall);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 8/8] efi: add veriable to report secure boot support and status
  2017-02-27 10:19 ` [PATCH 1/8] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
                     ` (5 preceding siblings ...)
  2017-02-27 10:19   ` [PATCH 7/8] efi: clocksoure: use event for timer Jean-Christophe PLAGNIOL-VILLARD
@ 2017-02-27 10:19   ` Jean-Christophe PLAGNIOL-VILLARD
  6 siblings, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-02-27 10:19 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/efi/efi-device.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index db8b25147..6ed7f12b3 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -354,11 +354,41 @@ static void efi_businfo(struct device_d *dev)
 	}
 }
 
+static int efi_is_secure_boot(void)
+{
+	uint8_t *val;
+	int ret = 0;
+
+	val = efi_get_variable("SecureBoot", &efi_global_variable_guid, NULL);
+	if (!IS_ERR(val)) {
+		ret = *val;
+		free(val);
+	}
+
+	return ret != 1;
+}
+
+static int efi_is_setup_mode(void)
+{
+	uint8_t *val;
+	int ret = 0;
+
+	val = efi_get_variable("SetupMode", &efi_global_variable_guid, NULL);
+	if (!IS_ERR(val)) {
+		ret = *val;
+		free(val);
+	}
+
+	return ret != 1;
+}
+
 static int efi_init_devices(void)
 {
 	char *fw_vendor = NULL;
 	u16 sys_major = efi_sys_table->hdr.revision >> 16;
 	u16 sys_minor = efi_sys_table->hdr.revision & 0xffff;
+	int secure_boot = efi_is_secure_boot();
+	int setup_mode = efi_is_setup_mode();
 
 	fw_vendor = strdup_wchar_to_char((const wchar_t *)efi_sys_table->fw_vendor);
 
@@ -374,6 +404,9 @@ static int efi_init_devices(void)
 	dev_add_param_int_ro(efi_bus.dev, "major", sys_major, "%u");
 	dev_add_param_int_ro(efi_bus.dev, "minor", sys_minor, "%u");
 	dev_add_param_int_ro(efi_bus.dev, "fw_revision", efi_sys_table->fw_revision, "%u");
+	dev_add_param_int_ro(efi_bus.dev, "secure_boot", secure_boot, "%d");
+	dev_add_param_int_ro(efi_bus.dev, "secure_mode",
+			     secure_boot & setup_mode, "%u");
 
 	efi_bus.dev->info = efi_businfo;
 
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/8] clocksource: allow to have multiple device from clock source
  2017-02-27 10:19   ` [PATCH 5/8] clocksource: allow to have multiple device from clock source Jean-Christophe PLAGNIOL-VILLARD
@ 2017-02-28  7:09     ` Sascha Hauer
  2017-03-01 15:52       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 17+ messages in thread
From: Sascha Hauer @ 2017-02-28  7:09 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Mon, Feb 27, 2017 at 11:19:27AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> use the one with the most priority.
> 
> We can not select the clocksource at user level.
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  common/clock.c  | 11 +++++++++++
>  include/clock.h |  3 ++-
>  2 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/common/clock.c b/common/clock.c
> index 2c5dd91cc..d99d06853 100644
> --- a/common/clock.c
> +++ b/common/clock.c
> @@ -213,6 +213,17 @@ EXPORT_SYMBOL(mdelay_non_interruptible);
>  
>  int init_clock(struct clocksource *cs)
>  {
> +	if (current_clock && cs->priority < current_clock->priority)
> +		return -EBUSY;

You should return successfully here. Otherwise driver probe functions
return -EBUSY for something which is not the drivers fault. In fact,
it's not an error, it's just that we currently don't have any use for an
additional clock. Also consider testing for <= current_clock->priority
instead of <. All current clocks have priority 0 and we want to
initialize only the first one.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/8] clocksource: allow to have multiple device from clock source
  2017-02-28  7:09     ` Sascha Hauer
@ 2017-03-01 15:52       ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-02  7:36         ` Sascha Hauer
  0 siblings, 1 reply; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-01 15:52 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 08:09 Tue 28 Feb     , Sascha Hauer wrote:
> On Mon, Feb 27, 2017 at 11:19:27AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > use the one with the most priority.
> > 
> > We can not select the clocksource at user level.
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> >  common/clock.c  | 11 +++++++++++
> >  include/clock.h |  3 ++-
> >  2 files changed, 13 insertions(+), 1 deletion(-)
> > 
> > diff --git a/common/clock.c b/common/clock.c
> > index 2c5dd91cc..d99d06853 100644
> > --- a/common/clock.c
> > +++ b/common/clock.c
> > @@ -213,6 +213,17 @@ EXPORT_SYMBOL(mdelay_non_interruptible);
> >  
> >  int init_clock(struct clocksource *cs)
> >  {
> > +	if (current_clock && cs->priority < current_clock->priority)
> > +		return -EBUSY;
> 
> You should return successfully here. Otherwise driver probe functions
> return -EBUSY for something which is not the drivers fault. In fact,
> it's not an error, it's just that we currently don't have any use for an
> additional clock.
my issue is that we will report in barebox that the device is in use but in
fact is not as we exit the init_clock without doing event the init.

That's why I choosed to return -EBUSY instead of 0
> Also consider testing for <= current_clock->priority
> instead of <. All current clocks have priority 0 and we want to
> initialize only the first one.
ok

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/8] clocksource: allow to have multiple device from clock source
  2017-03-01 15:52       ` Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-02  7:36         ` Sascha Hauer
  0 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2017-03-02  7:36 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Wed, Mar 01, 2017 at 04:52:05PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 08:09 Tue 28 Feb     , Sascha Hauer wrote:
> > On Mon, Feb 27, 2017 at 11:19:27AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > use the one with the most priority.
> > > 
> > > We can not select the clocksource at user level.
> > > 
> > > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > > ---
> > >  common/clock.c  | 11 +++++++++++
> > >  include/clock.h |  3 ++-
> > >  2 files changed, 13 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/common/clock.c b/common/clock.c
> > > index 2c5dd91cc..d99d06853 100644
> > > --- a/common/clock.c
> > > +++ b/common/clock.c
> > > @@ -213,6 +213,17 @@ EXPORT_SYMBOL(mdelay_non_interruptible);
> > >  
> > >  int init_clock(struct clocksource *cs)
> > >  {
> > > +	if (current_clock && cs->priority < current_clock->priority)
> > > +		return -EBUSY;
> > 
> > You should return successfully here. Otherwise driver probe functions
> > return -EBUSY for something which is not the drivers fault. In fact,
> > it's not an error, it's just that we currently don't have any use for an
> > additional clock.
> my issue is that we will report in barebox that the device is in use but in
> fact is not as we exit the init_clock without doing event the init.

What's the matter? We call init_clock() on a clocksource and barebox
could decide to use it. It just happens that we only use the clocksource
with the highest priority, but this shouldn't interest the driver.

BTW the same as you describe also happens with a low priority
clocksource when it's registered before a high priority clocksource: It
ends up being unused, though registered.

> 
> That's why I choosed to return -EBUSY instead of 0

As a clocksource driver I can only loose in this situation. I haven't
done anything wrong and I can only forward the error, in which case we
see it in the console or I can ignore it in which case I suppress
potential real errors.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 7/8] efi: clocksoure: use event for timer
  2017-02-27 10:19   ` [PATCH 7/8] efi: clocksoure: use event for timer Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-13 10:30     ` Michael Olbrich
  2017-03-13 10:52       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 17+ messages in thread
From: Michael Olbrich @ 2017-03-13 10:30 UTC (permalink / raw)
  To: barebox

On Mon, Feb 27, 2017 at 11:19:29AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> with this we can be hw generic
> 
> If the EFI implement timestamp protocol we could use instead of event
> but even EDK2 Never Ever compile it for any target.
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  common/efi/efi.c             |   8 ++++
>  drivers/clocksource/Kconfig  |   4 ++
>  drivers/clocksource/Makefile |   1 +
>  drivers/clocksource/efi.c    | 110 +++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 123 insertions(+)
>  create mode 100644 drivers/clocksource/efi.c
> 
> diff --git a/common/efi/efi.c b/common/efi/efi.c
> index 4b589b600..05c58250f 100644
> --- a/common/efi/efi.c
> +++ b/common/efi/efi.c
> @@ -353,6 +353,14 @@ efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
>  	return EFI_SUCCESS;
>  }
>  
> +static int efi_core_init(void)
> +{
> +	struct device_d *dev = device_alloc("efi-cs", DEVICE_ID_SINGLE);
> +
> +	return platform_device_register(dev);
> +}
> +core_initcall(efi_core_init);
> +
>  static int efi_postcore_init(void)
>  {
>  	char *uuid;
> diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
> index 9b7f0a9d7..b12a85403 100644
> --- a/drivers/clocksource/Kconfig
> +++ b/drivers/clocksource/Kconfig
> @@ -34,6 +34,10 @@ config CLOCKSOURCE_DUMMY_RATE
>  	  The option CONFIG_CLOCKSOURCE_DUMMY_RATE is used to adjust this clocksource.
>  	  The bigger rate valuest makes clocksource "faster".
>  
> +config CLOCKSOURCE_EFI
> +	bool "Generic EFI Driver"
> +	depends on EFI_BOOTUP
> +
>  config CLOCKSOURCE_EFI_X86
>  	bool "EFI X86 HW driver"
>  	depends on EFI_BOOTUP && X86
> diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
> index 1fd18296e..f69b33d0b 100644
> --- a/drivers/clocksource/Makefile
> +++ b/drivers/clocksource/Makefile
> @@ -3,6 +3,7 @@ obj-$(CONFIG_ARM_SMP_TWD) += arm_smp_twd.o
>  obj-$(CONFIG_CLOCKSOURCE_BCM283X) += bcm2835.o
>  obj-$(CONFIG_CLOCKSOURCE_CLPS711X) += clps711x.o
>  obj-$(CONFIG_CLOCKSOURCE_DIGIC)   += digic.o
> +obj-$(CONFIG_CLOCKSOURCE_EFI) += efi.o
>  obj-$(CONFIG_CLOCKSOURCE_EFI_X86) += efi_x86.o
>  obj-$(CONFIG_CLOCKSOURCE_MVEBU)   += mvebu.o
>  obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o
> diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
> new file mode 100644
> index 000000000..df65dd86c
> --- /dev/null
> +++ b/drivers/clocksource/efi.c
> @@ -0,0 +1,110 @@
> +/*
> + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnio@jcrosoft.com>
> + *
> + * Under GPL v2
> + */
> +#include <common.h>
> +#include <init.h>
> +#include <driver.h>
> +#include <clock.h>
> +#include <efi.h>
> +#include <efi/efi.h>
> +#include <efi/efi-device.h>
> +#include <linux/err.h>
> +
> +static uint64_t ticks = 1;
> +static void *efi_cs_evt;
> +
> +static uint64_t efi_cs_read(void)
> +{
> +	return ticks;
> +}
> +
> +static void efi_cs_inc(void *event, void *ctx)
> +{
> +	ticks++;
> +}
> +
> +/* count ticks during a 1dms */
> +static uint64_t ticks_freq(void)
> +{
> +	uint64_t ticks_start, ticks_end;
> +
> +	ticks_start = ticks;
> +	BS->stall(1000);
> +	ticks_end = ticks;
> +
> +	return (ticks_end - ticks_start) * 1000;
> +}
> +
> +/* count ticks during a 20ms delay as on qemu x86_64 the max is 100Hz */
> +static uint64_t ticks_freq_x86(void)
> +{
> +	uint64_t ticks_start, ticks_end;
> +
> +	ticks_start = ticks;
> +	BS->stall(20 * 1000);
> +	ticks_end = ticks;
> +
> +	return (ticks_end - ticks_start) * 50;
> +}
> +
> +static int efi_cs_init(struct clocksource *cs)
> +{
> +	efi_status_t efiret;
> +	uint64_t freq;
> +
> +	efiret = BS->create_event(EFI_EVT_TIMER | EFI_EVT_NOTIFY_SIGNAL,
> +			EFI_TPL_CALLBACK, efi_cs_inc, NULL, &efi_cs_evt);
> +
> +	if (EFI_ERROR(efiret))
> +		return -efi_errno(efiret);
> +
> +	efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, 10);
> +	if (EFI_ERROR(efiret)) {
> +		BS->close_event(efi_cs_evt);
> +		return -efi_errno(efiret);
> +	}
> +
> +	freq = 1000 * 1000;
> +	if (ticks_freq() < 800 * 1000) {
> +		uint64_t nb_100ns;
> +
> +		freq = ticks_freq_x86();

This needs a sanity ckeck. On one hardware that I have here 'freq' is often
(but not always) zero.

Michael

> +		nb_100ns = 10 * 1000 * 1000 / freq;
> +		pr_warn("EFI Event timer too slow freq = %llu Hz\n", freq);
> +		efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, nb_100ns);
> +		if (EFI_ERROR(efiret)) {
> +			BS->close_event(efi_cs_evt);
> +			return -efi_errno(efiret);
> +		}
> +	}
> +
> +	cs->mult = clocksource_hz2mult(freq, cs->shift);
> +
> +	return 0;
> +}
> +
> +static struct clocksource efi_cs = {
> +	.read   = efi_cs_read,
> +	.mask   = CLOCKSOURCE_MASK(64),
> +	.shift  = 0,
> +	.init   = efi_cs_init,
> +};
> +
> +static int efi_cs_probe(struct device_d *dev)
> +{
> +	return init_clock(&efi_cs);
> +}
> +
> +static struct driver_d efi_cs_driver = {
> +	.name = "efi-cs",
> +	.probe = efi_cs_probe,
> +};
> +
> +static int efi_cs_initcall(void)
> +{
> +	return platform_driver_register(&efi_cs_driver);
> +}
> +/* for efi the time must be init at core initcall level */
> +late_initcall(efi_cs_initcall);
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 7/8] efi: clocksoure: use event for timer
  2017-03-13 10:30     ` Michael Olbrich
@ 2017-03-13 10:52       ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-13 13:16         ` [PATCH] fixup! efi: clocksoure: add EFI event timer Michael Olbrich
  0 siblings, 1 reply; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-13 10:52 UTC (permalink / raw)
  To: Michael Olbrich; +Cc: barebox


> On 13 Mar 2017, at 6:30 PM, Michael Olbrich <m.olbrich@pengutronix.de> wrote:
> 
> On Mon, Feb 27, 2017 at 11:19:29AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
>> with this we can be hw generic
>> 
>> If the EFI implement timestamp protocol we could use instead of event
>> but even EDK2 Never Ever compile it for any target.
>> 
>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
>> ---
>> common/efi/efi.c             |   8 ++++
>> drivers/clocksource/Kconfig  |   4 ++
>> drivers/clocksource/Makefile |   1 +
>> drivers/clocksource/efi.c    | 110 +++++++++++++++++++++++++++++++++++++++++++
>> 4 files changed, 123 insertions(+)
>> create mode 100644 drivers/clocksource/efi.c
>> 
>> diff --git a/common/efi/efi.c b/common/efi/efi.c
>> index 4b589b600..05c58250f 100644
>> --- a/common/efi/efi.c
>> +++ b/common/efi/efi.c
>> @@ -353,6 +353,14 @@ efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
>> 	return EFI_SUCCESS;
>> }
>> 
>> +static int efi_core_init(void)
>> +{
>> +	struct device_d *dev = device_alloc("efi-cs", DEVICE_ID_SINGLE);
>> +
>> +	return platform_device_register(dev);
>> +}
>> +core_initcall(efi_core_init);
>> +
>> static int efi_postcore_init(void)
>> {
>> 	char *uuid;
>> diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
>> index 9b7f0a9d7..b12a85403 100644
>> --- a/drivers/clocksource/Kconfig
>> +++ b/drivers/clocksource/Kconfig
>> @@ -34,6 +34,10 @@ config CLOCKSOURCE_DUMMY_RATE
>> 	  The option CONFIG_CLOCKSOURCE_DUMMY_RATE is used to adjust this clocksource.
>> 	  The bigger rate valuest makes clocksource "faster".
>> 
>> +config CLOCKSOURCE_EFI
>> +	bool "Generic EFI Driver"
>> +	depends on EFI_BOOTUP
>> +
>> config CLOCKSOURCE_EFI_X86
>> 	bool "EFI X86 HW driver"
>> 	depends on EFI_BOOTUP && X86
>> diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
>> index 1fd18296e..f69b33d0b 100644
>> --- a/drivers/clocksource/Makefile
>> +++ b/drivers/clocksource/Makefile
>> @@ -3,6 +3,7 @@ obj-$(CONFIG_ARM_SMP_TWD) += arm_smp_twd.o
>> obj-$(CONFIG_CLOCKSOURCE_BCM283X) += bcm2835.o
>> obj-$(CONFIG_CLOCKSOURCE_CLPS711X) += clps711x.o
>> obj-$(CONFIG_CLOCKSOURCE_DIGIC)   += digic.o
>> +obj-$(CONFIG_CLOCKSOURCE_EFI) += efi.o
>> obj-$(CONFIG_CLOCKSOURCE_EFI_X86) += efi_x86.o
>> obj-$(CONFIG_CLOCKSOURCE_MVEBU)   += mvebu.o
>> obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o
>> diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
>> new file mode 100644
>> index 000000000..df65dd86c
>> --- /dev/null
>> +++ b/drivers/clocksource/efi.c
>> @@ -0,0 +1,110 @@
>> +/*
>> + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnio@jcrosoft.com>
>> + *
>> + * Under GPL v2
>> + */
>> +#include <common.h>
>> +#include <init.h>
>> +#include <driver.h>
>> +#include <clock.h>
>> +#include <efi.h>
>> +#include <efi/efi.h>
>> +#include <efi/efi-device.h>
>> +#include <linux/err.h>
>> +
>> +static uint64_t ticks = 1;
>> +static void *efi_cs_evt;
>> +
>> +static uint64_t efi_cs_read(void)
>> +{
>> +	return ticks;
>> +}
>> +
>> +static void efi_cs_inc(void *event, void *ctx)
>> +{
>> +	ticks++;
>> +}
>> +
>> +/* count ticks during a 1dms */
>> +static uint64_t ticks_freq(void)
>> +{
>> +	uint64_t ticks_start, ticks_end;
>> +
>> +	ticks_start = ticks;
>> +	BS->stall(1000);
>> +	ticks_end = ticks;
>> +
>> +	return (ticks_end - ticks_start) * 1000;
>> +}
>> +
>> +/* count ticks during a 20ms delay as on qemu x86_64 the max is 100Hz */
>> +static uint64_t ticks_freq_x86(void)
>> +{
>> +	uint64_t ticks_start, ticks_end;
>> +
>> +	ticks_start = ticks;
>> +	BS->stall(20 * 1000);
>> +	ticks_end = ticks;
>> +
>> +	return (ticks_end - ticks_start) * 50;
>> +}
>> +
>> +static int efi_cs_init(struct clocksource *cs)
>> +{
>> +	efi_status_t efiret;
>> +	uint64_t freq;
>> +
>> +	efiret = BS->create_event(EFI_EVT_TIMER | EFI_EVT_NOTIFY_SIGNAL,
>> +			EFI_TPL_CALLBACK, efi_cs_inc, NULL, &efi_cs_evt);
>> +
>> +	if (EFI_ERROR(efiret))
>> +		return -efi_errno(efiret);
>> +
>> +	efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, 10);
>> +	if (EFI_ERROR(efiret)) {
>> +		BS->close_event(efi_cs_evt);
>> +		return -efi_errno(efiret);
>> +	}
>> +
>> +	freq = 1000 * 1000;
>> +	if (ticks_freq() < 800 * 1000) {
>> +		uint64_t nb_100ns;
>> +
>> +		freq = ticks_freq_x86();
> 
> This needs a sanity ckeck. On one hardware that I have here 'freq' is often
> (but not always) zero.
> 

Really :(

please send a patch

FYI on x86 this generic Timer will replace at runtime by the efi_x86 that use HW IP
directly

Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH] fixup! efi: clocksoure: add EFI event timer
  2017-03-13 10:52       ` Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-13 13:16         ` Michael Olbrich
  2017-03-13 15:55           ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-14  7:16           ` Sascha Hauer
  0 siblings, 2 replies; 17+ messages in thread
From: Michael Olbrich @ 2017-03-13 13:16 UTC (permalink / raw)
  To: barebox; +Cc: Michael Olbrich

---

I played with the numbers a bit. This hardware has a 18 Hz tick :-/.
That's not really useful so just skipping the clocksource is probably the
best solution.

Michael

 drivers/clocksource/efi.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
index 89906c452eb7..fb5b7ca63de9 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi.c
@@ -71,6 +71,10 @@ static int efi_cs_init(struct clocksource *cs)
 		uint64_t nb_100ns;
 
 		freq = ticks_freq_x86();
+		if (freq == 0) {
+			BS->close_event(efi_cs_evt);
+			return -ENODEV;
+		}
 		nb_100ns = 10 * 1000 * 1000 / freq;
 		pr_warn("EFI Event timer too slow freq = %llu Hz\n", freq);
 		efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, nb_100ns);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] fixup! efi: clocksoure: add EFI event timer
  2017-03-13 13:16         ` [PATCH] fixup! efi: clocksoure: add EFI event timer Michael Olbrich
@ 2017-03-13 15:55           ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-14  7:16           ` Sascha Hauer
  1 sibling, 0 replies; 17+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-13 15:55 UTC (permalink / raw)
  To: Michael Olbrich; +Cc: barebox


> On 13 Mar 2017, at 9:16 PM, Michael Olbrich <m.olbrich@pengutronix.de> wrote:
> 
> ---
> 
> I played with the numbers a bit. This hardware has a 18 Hz tick :-/.
18Hz wow it’s unusable

how can they implement this

> That's not really useful so just skipping the clocksource is probably the
> best solution.
> 

Acked-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] fixup! efi: clocksoure: add EFI event timer
  2017-03-13 13:16         ` [PATCH] fixup! efi: clocksoure: add EFI event timer Michael Olbrich
  2017-03-13 15:55           ` Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-14  7:16           ` Sascha Hauer
  1 sibling, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2017-03-14  7:16 UTC (permalink / raw)
  To: Michael Olbrich; +Cc: barebox

On Mon, Mar 13, 2017 at 02:16:06PM +0100, Michael Olbrich wrote:
> ---
> 
> I played with the numbers a bit. This hardware has a 18 Hz tick :-/.
> That's not really useful so just skipping the clocksource is probably the
> best solution.
> 
> Michael
> 
>  drivers/clocksource/efi.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
> index 89906c452eb7..fb5b7ca63de9 100644
> --- a/drivers/clocksource/efi.c
> +++ b/drivers/clocksource/efi.c
> @@ -71,6 +71,10 @@ static int efi_cs_init(struct clocksource *cs)
>  		uint64_t nb_100ns;
>  
>  		freq = ticks_freq_x86();
> +		if (freq == 0) {
> +			BS->close_event(efi_cs_evt);
> +			return -ENODEV;
> +		}
>  		nb_100ns = 10 * 1000 * 1000 / freq;
>  		pr_warn("EFI Event timer too slow freq = %llu Hz\n", freq);
>  		efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, nb_100ns);

Since the patch this fixup is for is already in master: Can you provide
a proper, non-fixup patch?

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-03-14  7:17 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-27 10:14 [PATCH 0/8] add generic EFI timer Jean-Christophe PLAGNIOL-VILLARD
2017-02-27 10:19 ` [PATCH 1/8] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
2017-02-27 10:19   ` [PATCH 2/8] efi: add prototype and definition for setting timer Jean-Christophe PLAGNIOL-VILLARD
2017-02-27 10:19   ` [PATCH 3/8] efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall Jean-Christophe PLAGNIOL-VILLARD
2017-02-27 10:19   ` [PATCH 4/8] efi: move x86 clocksource init at core initcall level Jean-Christophe PLAGNIOL-VILLARD
2017-02-27 10:19   ` [PATCH 5/8] clocksource: allow to have multiple device from clock source Jean-Christophe PLAGNIOL-VILLARD
2017-02-28  7:09     ` Sascha Hauer
2017-03-01 15:52       ` Jean-Christophe PLAGNIOL-VILLARD
2017-03-02  7:36         ` Sascha Hauer
2017-02-27 10:19   ` [PATCH 6/8] efi: move x86 clocksource to device/driver Jean-Christophe PLAGNIOL-VILLARD
2017-02-27 10:19   ` [PATCH 7/8] efi: clocksoure: use event for timer Jean-Christophe PLAGNIOL-VILLARD
2017-03-13 10:30     ` Michael Olbrich
2017-03-13 10:52       ` Jean-Christophe PLAGNIOL-VILLARD
2017-03-13 13:16         ` [PATCH] fixup! efi: clocksoure: add EFI event timer Michael Olbrich
2017-03-13 15:55           ` Jean-Christophe PLAGNIOL-VILLARD
2017-03-14  7:16           ` Sascha Hauer
2017-02-27 10:19   ` [PATCH 8/8] efi: add veriable to report secure boot support and status Jean-Christophe PLAGNIOL-VILLARD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox