mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/9] add generic EFI timer
@ 2017-03-03 12:32 Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:33 ` [PATCH 1/9] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-03 12:32 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 delivery/efi-cs

for you to fetch changes up to f14af7444ad9d8ce674382f222119f5fcd3f2576:

  efi: add veriable to report secure boot support and status (2017-02-28 23:05:31 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (9):
      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
      clocksource: move dummy clock source to init_clock
      efi: move x86 clocksource to device/driver
      efi: clocksoure: add EFI event 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                  |  44 +++++++++++++++++++++++++++++++++++---------
 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, 290 insertions(+), 51 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] 11+ messages in thread

* [PATCH 1/9] efi: add prototype and definition for creating and closing event
  2017-03-03 12:32 [PATCH 0/9] add generic EFI timer Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-03 12:33 ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:33   ` [PATCH 2/9] efi: add prototype and definition for setting timer Jean-Christophe PLAGNIOL-VILLARD
                     ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-03 12:33 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] 11+ messages in thread

* [PATCH 2/9] efi: add prototype and definition for setting timer
  2017-03-03 12:33 ` [PATCH 1/9] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-03 12:33   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:33   ` [PATCH 3/9] efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall Jean-Christophe PLAGNIOL-VILLARD
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-03 12:33 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] 11+ messages in thread

* [PATCH 3/9] efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall
  2017-03-03 12:33 ` [PATCH 1/9] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:33   ` [PATCH 2/9] efi: add prototype and definition for setting timer Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-03 12:33   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:34   ` [PATCH 4/9] efi: move x86 clocksource init at core initcall level Jean-Christophe PLAGNIOL-VILLARD
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-03 12:33 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] 11+ messages in thread

* [PATCH 4/9] efi: move x86 clocksource init at core initcall level
  2017-03-03 12:33 ` [PATCH 1/9] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:33   ` [PATCH 2/9] efi: add prototype and definition for setting timer Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:33   ` [PATCH 3/9] efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-03 12:34   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:34   ` [PATCH 5/9] clocksource: allow to have multiple device from clock source Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-03 12:34 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] 11+ messages in thread

* [PATCH 5/9] clocksource: allow to have multiple device from clock source
  2017-03-03 12:33 ` [PATCH 1/9] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 preceding siblings ...)
  2017-03-03 12:34   ` [PATCH 4/9] efi: move x86 clocksource init at core initcall level Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-03 12:34   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:34   ` [PATCH 6/9] clocksource: move dummy clock source to init_clock Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-03 12:34 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..1090b605f 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 0;
+
+	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] 11+ messages in thread

* [PATCH 6/9] clocksource: move dummy clock source to init_clock
  2017-03-03 12:33 ` [PATCH 1/9] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 preceding siblings ...)
  2017-03-03 12:34   ` [PATCH 5/9] clocksource: allow to have multiple device from clock source Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-03 12:34   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:34   ` [PATCH 7/9] efi: move x86 clocksource to device/driver Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-03 12:34 UTC (permalink / raw)
  To: barebox

And registered it as soon as possible (at pure initcall).
So we not need to check the cs all the time.
As get_time_ns() is one of the most called function of barebox at runtime.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/clock.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/common/clock.c b/common/clock.c
index 1090b605f..0d581c2c7 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -36,9 +36,32 @@ static uint64_t time_ns;
  */
 uint64_t time_beginning;
 
+static uint64_t dummy_read(void)
+{
+	static uint64_t dummy_counter;
+
+	dummy_counter += CONFIG_CLOCKSOURCE_DUMMY_RATE;
+
+	return dummy_counter;
+}
+
+static struct clocksource dummy_cs = {
+	.shift = 0,
+	.mult = 1,
+	.read = dummy_read,
+	.mask = CLOCKSOURCE_MASK(64),
+	.priority = -1,
+};
+
+static int dummy_csrc_init(void)
+{
+	return init_clock(&dummy_cs);
+}
+pure_initcall(dummy_csrc_init);
+
 static int dummy_csrc_warn(void)
 {
-	if (!current_clock) {
+	if (current_clock == &dummy_cs) {
 		pr_warn("Warning: Using dummy clocksource\n");
 	}
 
@@ -55,14 +78,6 @@ uint64_t get_time_ns(void)
 	uint64_t cycle_now, cycle_delta;
 	uint64_t ns_offset;
 
-	if (!cs) {
-		static uint64_t dummy_counter;
-
-		dummy_counter += CONFIG_CLOCKSOURCE_DUMMY_RATE;
-
-		return dummy_counter;
-	}
-
 	/* read clocksource: */
 	cycle_now = cs->read() & cs->mask;
 
-- 
2.11.0


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

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

* [PATCH 7/9] efi: move x86 clocksource to device/driver
  2017-03-03 12:33 ` [PATCH 1/9] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 preceding siblings ...)
  2017-03-03 12:34   ` [PATCH 6/9] clocksource: move dummy clock source to init_clock Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-03 12:34   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:34   ` [PATCH 8/9] efi: clocksoure: add EFI event timer Jean-Christophe PLAGNIOL-VILLARD
  2017-03-03 12:34   ` [PATCH 9/9] efi: add veriable to report secure boot support and status Jean-Christophe PLAGNIOL-VILLARD
  7 siblings, 0 replies; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-03 12:34 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] 11+ messages in thread

* [PATCH 8/9] efi: clocksoure: add EFI event timer
  2017-03-03 12:33 ` [PATCH 1/9] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
                     ` (5 preceding siblings ...)
  2017-03-03 12:34   ` [PATCH 7/9] efi: move x86 clocksource to device/driver Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-03 12:34   ` Jean-Christophe PLAGNIOL-VILLARD
  2017-03-07  7:41     ` Sascha Hauer
  2017-03-03 12:34   ` [PATCH 9/9] efi: add veriable to report secure boot support and status Jean-Christophe PLAGNIOL-VILLARD
  7 siblings, 1 reply; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-03 12:34 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..89906c452
--- /dev/null
+++ b/drivers/clocksource/efi.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2017 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 */
+core_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] 11+ messages in thread

* [PATCH 9/9] efi: add veriable to report secure boot support and status
  2017-03-03 12:33 ` [PATCH 1/9] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
                     ` (6 preceding siblings ...)
  2017-03-03 12:34   ` [PATCH 8/9] efi: clocksoure: add EFI event timer Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-03 12:34   ` Jean-Christophe PLAGNIOL-VILLARD
  7 siblings, 0 replies; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2017-03-03 12:34 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] 11+ messages in thread

* Re: [PATCH 8/9] efi: clocksoure: add EFI event timer
  2017-03-03 12:34   ` [PATCH 8/9] efi: clocksoure: add EFI event timer Jean-Christophe PLAGNIOL-VILLARD
@ 2017-03-07  7:41     ` Sascha Hauer
  0 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2017-03-07  7:41 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Fri, Mar 03, 2017 at 01:34:04PM +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>
> ---
> +	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);

Applied this series for now. I weakened this message somewhat:

		pr_warn("EFI Event timer slow, freq = %lluHz\n", freq);

As this is not really an error, only an information one might want to
know.

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] 11+ messages in thread

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

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-03 12:32 [PATCH 0/9] add generic EFI timer Jean-Christophe PLAGNIOL-VILLARD
2017-03-03 12:33 ` [PATCH 1/9] efi: add prototype and definition for creating and closing event Jean-Christophe PLAGNIOL-VILLARD
2017-03-03 12:33   ` [PATCH 2/9] efi: add prototype and definition for setting timer Jean-Christophe PLAGNIOL-VILLARD
2017-03-03 12:33   ` [PATCH 3/9] efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall Jean-Christophe PLAGNIOL-VILLARD
2017-03-03 12:34   ` [PATCH 4/9] efi: move x86 clocksource init at core initcall level Jean-Christophe PLAGNIOL-VILLARD
2017-03-03 12:34   ` [PATCH 5/9] clocksource: allow to have multiple device from clock source Jean-Christophe PLAGNIOL-VILLARD
2017-03-03 12:34   ` [PATCH 6/9] clocksource: move dummy clock source to init_clock Jean-Christophe PLAGNIOL-VILLARD
2017-03-03 12:34   ` [PATCH 7/9] efi: move x86 clocksource to device/driver Jean-Christophe PLAGNIOL-VILLARD
2017-03-03 12:34   ` [PATCH 8/9] efi: clocksoure: add EFI event timer Jean-Christophe PLAGNIOL-VILLARD
2017-03-07  7:41     ` Sascha Hauer
2017-03-03 12:34   ` [PATCH 9/9] 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