[PATCH 1/9] x86: Do full rtc synchronization with ntp

2014-06-26 Thread Jason Luan
From: Prarit Bhargava pra...@redhat.com

Every 11 minutes ntp attempts to update the x86 rtc with the current
system time.  Currently, the x86 code only updates the rtc if the system
time is within +/-15 minutes of the current value of the rtc. This
was done originally to avoid setting the RTC if the RTC was in localtime
mode (common with Windows dualbooting).  Other architectures do a full
synchronization and now that we have better infrastructure to detect
when the RTC is in localtime, there is no reason that x86 should be
software limited to a 30 minute window.

This patch changes the behavior of the kernel to do a full synchronization
(year, month, day, hour, minute, and second) of the rtc when ntp requests
a synchronization between the system time and the rtc.

I've used the RTC library functions in this patchset as they do all the
required bounds checking.

Cc: Thomas Gleixner t...@linutronix.de
Cc: John Stultz john.stu...@linaro.org
Cc: x...@kernel.org
Cc: Matt Fleming matt.flem...@intel.com
Cc: David Vrabel david.vra...@citrix.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andi Kleen a...@linux.intel.com
Cc: linux-efi@vger.kernel.org
Signed-off-by: Prarit Bhargava pra...@redhat.com
[jstultz: Tweak commit message, fold in build fix found by fengguang
Also add select RTC_LIB to X86, per new dependency, as found by prarit]
Signed-off-by: John Stultz john.stu...@linaro.org

(cherry picked from commit 3195ef59cb42cda3aeeb24a7fd2ba1b900c4a3cc)
Signed-off-by: Jason Luan jianhai.l...@oracle.com

Conflicts:
arch/x86/Kconfig

Signed-off-by: Jason Luan jianhai.l...@oracle.com
---
 arch/x86/Kconfig  |  1 +
 arch/x86/kernel/rtc.c | 69 ---
 arch/x86/platform/efi/efi.c   | 24 ++-
 arch/x86/platform/mrst/vrtc.c | 44 ---
 4 files changed, 55 insertions(+), 83 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 2c64e6e..4b830d4 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -114,6 +114,7 @@ config X86
select MODULES_USE_ELF_RELA if X86_64
select CLONE_BACKWARDS if X86_32
select GENERIC_SIGALTSTACK
+   select RTC_LIB
 
 config INSTRUCTION_DECODER
def_bool y
diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
index 801602b..44e6c3a 100644
--- a/arch/x86/kernel/rtc.c
+++ b/arch/x86/kernel/rtc.c
@@ -13,6 +13,7 @@
 #include asm/x86_init.h
 #include asm/time.h
 #include asm/mrst.h
+#include asm/rtc.h
 
 #ifdef CONFIG_X86_32
 /*
@@ -36,70 +37,24 @@ EXPORT_SYMBOL(rtc_lock);
  * nowtime is written into the registers of the CMOS clock, it will
  * jump to the next second precisely 500 ms later. Check the Motorola
  * MC146818A or Dallas DS12887 data sheet for details.
- *
- * BUG: This routine does not handle hour overflow properly; it just
- *  sets the minutes. Usually you'll only notice that after reboot!
  */
 int mach_set_rtc_mmss(unsigned long nowtime)
 {
-   int real_seconds, real_minutes, cmos_minutes;
-   unsigned char save_control, save_freq_select;
-   unsigned long flags;
+   struct rtc_time tm;
int retval = 0;
 
-   spin_lock_irqsave(rtc_lock, flags);
-
-/* tell the clock it's being set */
-   save_control = CMOS_READ(RTC_CONTROL);
-   CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL);
-
-   /* stop and reset prescaler */
-   save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
-   CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT);
-
-   cmos_minutes = CMOS_READ(RTC_MINUTES);
-   if (!(save_control  RTC_DM_BINARY) || RTC_ALWAYS_BCD)
-   cmos_minutes = bcd2bin(cmos_minutes);
-
-   /*
-* since we're only adjusting minutes and seconds,
-* don't interfere with hour overflow. This avoids
-* messing with unknown time zones but requires your
-* RTC not to be off by more than 15 minutes
-*/
-   real_seconds = nowtime % 60;
-   real_minutes = nowtime / 60;
-   /* correct for half hour time zone */
-   if (((abs(real_minutes - cmos_minutes) + 15)/30)  1)
-   real_minutes += 30;
-   real_minutes %= 60;
-
-   if (abs(real_minutes - cmos_minutes)  30) {
-   if (!(save_control  RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
-   real_seconds = bin2bcd(real_seconds);
-   real_minutes = bin2bcd(real_minutes);
-   }
-   CMOS_WRITE(real_seconds, RTC_SECONDS);
-   CMOS_WRITE(real_minutes, RTC_MINUTES);
+   rtc_time_to_tm(nowtime, tm);
+   if (!rtc_valid_tm(tm)) {
+   retval = set_rtc_time(tm);
+   if (retval)
+   printk(KERN_ERR %s: RTC write failed with error %d\n,
+  __FUNCTION__, retval);
} else {
-   printk_once(KERN_NOTICE
-  set_rtc_mmss: can't update from %d to %d\n,
-  

[PATCH v2 2/2] efi/arm64: preserve FP/SIMD registers on UEFI runtime services calls

2014-06-26 Thread Ard Biesheuvel
According to the UEFI spec section 2.3.6.4, the use of FP/SIMD instructions is
allowed, and should adhere to the AAPCS64 calling convention, which states that
'only the bottom 64 bits of each value stored in registers v8-v15 need to be
preserved' (section 5.1.2).

This applies equally to UEFI Runtime Services called by the kernel, so make sure
the FP/SIMD register file is preserved in this case.

Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
---
 arch/arm64/Kconfig   |  1 +
 arch/arm64/include/asm/efi.h | 21 +
 arch/arm64/kernel/efi.c  | 14 +-
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index a474de346be6..93e11f4d9513 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -299,6 +299,7 @@ config EFI
select LIBFDT
select UCS2_STRING
select EFI_PARAMS_FROM_FDT
+   select EFI_RUNTIME_WRAPPERS
default y
help
  This option provides support for runtime services provided
diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h
index 5a46c4e7f539..375ba342dca6 100644
--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -2,6 +2,7 @@
 #define _ASM_EFI_H
 
 #include asm/io.h
+#include asm/neon.h
 
 #ifdef CONFIG_EFI
 extern void efi_init(void);
@@ -11,4 +12,24 @@ extern void efi_idmap_init(void);
 #define efi_idmap_init()
 #endif
 
+#define efi_call_virt(f, ...)  \
+({ \
+   efi_##f##_t *__f = efi.systab-runtime-f;  \
+   efi_status_t __s;   \
+   \
+   kernel_neon_begin();\
+   __s = __f(__VA_ARGS__); \
+   kernel_neon_end();  \
+   __s;\
+})
+
+#define __efi_call_virt(f, ...)
\
+({ \
+   efi_##f##_t *__f = efi.systab-runtime-f;  \
+   \
+   kernel_neon_begin();\
+   __f(__VA_ARGS__);   \
+   kernel_neon_end();  \
+})
+
 #endif /* _ASM_EFI_H */
diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
index 14db1f6e8d7f..56c3327bbf79 100644
--- a/arch/arm64/kernel/efi.c
+++ b/arch/arm64/kernel/efi.c
@@ -449,19 +449,7 @@ static int __init arm64_enter_virtual_mode(void)
 
/* Set up runtime services function pointers */
runtime = efi.systab-runtime;
-   efi.get_time = runtime-get_time;
-   efi.set_time = runtime-set_time;
-   efi.get_wakeup_time = runtime-get_wakeup_time;
-   efi.set_wakeup_time = runtime-set_wakeup_time;
-   efi.get_variable = runtime-get_variable;
-   efi.get_next_variable = runtime-get_next_variable;
-   efi.set_variable = runtime-set_variable;
-   efi.query_variable_info = runtime-query_variable_info;
-   efi.update_capsule = runtime-update_capsule;
-   efi.query_capsule_caps = runtime-query_capsule_caps;
-   efi.get_next_high_mono_count = runtime-get_next_high_mono_count;
-   efi.reset_system = runtime-reset_system;
-
+   efi_native_runtime_setup();
set_bit(EFI_RUNTIME_SERVICES, efi.flags);
 
return 0;
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-efi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/2] efi/x86: move UEFI Runtime Services wrappers to generic code

2014-06-26 Thread Ard Biesheuvel
In order for other archs (such as arm64) to be able to reuse the virtual mode
function call wrappers, move them to drivers/firmware/efi/runtime-wrappers.c.

Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
---
 arch/x86/Kconfig|   1 +
 arch/x86/platform/efi/efi.c | 144 +---
 drivers/firmware/efi/Kconfig|   7 ++
 drivers/firmware/efi/Makefile   |   1 +
 drivers/firmware/efi/runtime-wrappers.c | 161 
 include/linux/efi.h |   2 +
 6 files changed, 174 insertions(+), 142 deletions(-)
 create mode 100644 drivers/firmware/efi/runtime-wrappers.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index a8f749ef0fdc..4c3f026aa5ce 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1522,6 +1522,7 @@ config EFI
bool EFI runtime service support
depends on ACPI
select UCS2_STRING
+   select EFI_RUNTIME_WRAPPERS
---help---
  This enables the kernel to use EFI runtime services that are
  available (such as the EFI variable services).
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 87fc96bcc13c..36d0835210c3 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -104,130 +104,6 @@ static int __init setup_storage_paranoia(char *arg)
 }
 early_param(efi_no_storage_paranoia, setup_storage_paranoia);
 
-static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
-{
-   unsigned long flags;
-   efi_status_t status;
-
-   spin_lock_irqsave(rtc_lock, flags);
-   status = efi_call_virt(get_time, tm, tc);
-   spin_unlock_irqrestore(rtc_lock, flags);
-   return status;
-}
-
-static efi_status_t virt_efi_set_time(efi_time_t *tm)
-{
-   unsigned long flags;
-   efi_status_t status;
-
-   spin_lock_irqsave(rtc_lock, flags);
-   status = efi_call_virt(set_time, tm);
-   spin_unlock_irqrestore(rtc_lock, flags);
-   return status;
-}
-
-static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
-efi_bool_t *pending,
-efi_time_t *tm)
-{
-   unsigned long flags;
-   efi_status_t status;
-
-   spin_lock_irqsave(rtc_lock, flags);
-   status = efi_call_virt(get_wakeup_time, enabled, pending, tm);
-   spin_unlock_irqrestore(rtc_lock, flags);
-   return status;
-}
-
-static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t 
*tm)
-{
-   unsigned long flags;
-   efi_status_t status;
-
-   spin_lock_irqsave(rtc_lock, flags);
-   status = efi_call_virt(set_wakeup_time, enabled, tm);
-   spin_unlock_irqrestore(rtc_lock, flags);
-   return status;
-}
-
-static efi_status_t virt_efi_get_variable(efi_char16_t *name,
- efi_guid_t *vendor,
- u32 *attr,
- unsigned long *data_size,
- void *data)
-{
-   return efi_call_virt(get_variable,
-name, vendor, attr,
-data_size, data);
-}
-
-static efi_status_t virt_efi_get_next_variable(unsigned long *name_size,
-  efi_char16_t *name,
-  efi_guid_t *vendor)
-{
-   return efi_call_virt(get_next_variable,
-name_size, name, vendor);
-}
-
-static efi_status_t virt_efi_set_variable(efi_char16_t *name,
- efi_guid_t *vendor,
- u32 attr,
- unsigned long data_size,
- void *data)
-{
-   return efi_call_virt(set_variable,
-name, vendor, attr,
-data_size, data);
-}
-
-static efi_status_t virt_efi_query_variable_info(u32 attr,
-u64 *storage_space,
-u64 *remaining_space,
-u64 *max_variable_size)
-{
-   if (efi.runtime_version  EFI_2_00_SYSTEM_TABLE_REVISION)
-   return EFI_UNSUPPORTED;
-
-   return efi_call_virt(query_variable_info, attr, storage_space,
-remaining_space, max_variable_size);
-}
-
-static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
-{
-   return efi_call_virt(get_next_high_mono_count, count);
-}
-
-static void virt_efi_reset_system(int reset_type,
- efi_status_t status,
- unsigned long data_size,
- efi_char16_t *data)
-{
-   __efi_call_virt(reset_system, reset_type, status,
-   

[PATCH v2 0/2] efi: preserve NEON registers on UEFI services calls

2014-06-26 Thread Ard Biesheuvel
The current UEFI implementation for arm64 fails to preserve/restore the contents
of the NEON register file, which may result in data corruption, especially now
that those contents are lazily restored for user processes.

This series proposes to fix this by wrapping all runtime services calls, and
adding kernel_neon_begin()/kernel_neon_end() pairs to the wrappers.

The first patch moves the existing x86 versions of those wrappers to generic
code, so that the second patch can easily enable them by supplying a definition
for efi_call_virt and adding a call to efi_native_runtime_setup().

Changes since v1:
- rename runtime.c - runtime-wrappers.c
- make build depend on new Kconfig symbol EFI_RUNTIME_WRAPPERS to fix ia64
  breakage
- remove default #defines for efi_call_virt()/__efi_call_virt(), they are not
  needed anymore now that it is built conditionally
- add references to applicable UEFI/AAPCS spec sections

Ard Biesheuvel (2):
  efi/x86: move UEFI Runtime Services wrappers to generic code
  efi/arm64: preserve FP/SIMD registers on UEFI runtime services calls

 arch/arm64/Kconfig  |   1 +
 arch/arm64/include/asm/efi.h|  21 +
 arch/arm64/kernel/efi.c |  14 +--
 arch/x86/Kconfig|   1 +
 arch/x86/platform/efi/efi.c | 144 +---
 drivers/firmware/efi/Kconfig|   7 ++
 drivers/firmware/efi/Makefile   |   1 +
 drivers/firmware/efi/runtime-wrappers.c | 161 
 include/linux/efi.h |   2 +
 9 files changed, 197 insertions(+), 155 deletions(-)
 create mode 100644 drivers/firmware/efi/runtime-wrappers.c

-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-efi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 0/2] efi: preserve NEON registers on UEFI services calls

2014-06-26 Thread Mark Salter
On Thu, 2014-06-26 at 12:09 +0200, Ard Biesheuvel wrote:
 The current UEFI implementation for arm64 fails to preserve/restore the 
 contents
 of the NEON register file,

Does the current implementation actually use NEON registers?
I know there are some at least, which build with -mgeneral-regs-only
to keep gcc from using NEON registers.

Not that that means we don't need this. Just curious.


--
To unsubscribe from this list: send the line unsubscribe linux-efi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 0/2] efi: preserve NEON registers on UEFI services calls

2014-06-26 Thread Ard Biesheuvel
On 26 June 2014 15:58, Mark Salter msal...@redhat.com wrote:
 On Thu, 2014-06-26 at 12:09 +0200, Ard Biesheuvel wrote:
 The current UEFI implementation for arm64 fails to preserve/restore the 
 contents
 of the NEON register file,

 Does the current implementation actually use NEON registers?
 I know there are some at least, which build with -mgeneral-regs-only
 to keep gcc from using NEON registers.


Tianocore/EDK2 does not use -mgeneral-regs-only when building for
AArch64, and my current build shows that, for instance, GCC starts
spilling to FP registers when compiling the LZMA decoder, and it is
likely to do the same for the crypto bits once I start enabling them
(although, interestingly enough, the OpenSSL SHA-1 C implementation
runs 60% faster with -mgeneral-regs-only set)

 Not that that means we don't need this. Just curious.


The spec does not forbid it, so we will need it anyhow ...

-- 
Ard.
--
To unsubscribe from this list: send the line unsubscribe linux-efi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/5] efi/x86: efistub: move shared dependencies to asm/efi.h

2014-06-26 Thread Ard Biesheuvel
This moves definitions depended upon both by code under arch/x86/boot and
under drivers/firmware/efi to asm/efi.h. This is in preparation of turning
the stub code under drivers/firmware/efi into a static library.

Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
---
 arch/x86/boot/compressed/eboot.c |  5 +
 arch/x86/boot/compressed/eboot.h | 16 
 arch/x86/include/asm/efi.h   | 25 +
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 0331d765c2bb..2fd5e2643623 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -19,10 +19,7 @@
 
 static efi_system_table_t *sys_table;
 
-static struct efi_config *efi_early;
-
-#define efi_call_early(f, ...) \
-   efi_early-call(efi_early-f, __VA_ARGS__);
+struct efi_config *efi_early;
 
 #define BOOT_SERVICES(bits)\
 static void setup_boot_services##bits(struct efi_config *c)\
diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h
index c88c31ecad12..d487e727f1ec 100644
--- a/arch/x86/boot/compressed/eboot.h
+++ b/arch/x86/boot/compressed/eboot.h
@@ -103,20 +103,4 @@ struct efi_uga_draw_protocol {
void *blt;
 };
 
-struct efi_config {
-   u64 image_handle;
-   u64 table;
-   u64 allocate_pool;
-   u64 allocate_pages;
-   u64 get_memory_map;
-   u64 free_pool;
-   u64 free_pages;
-   u64 locate_handle;
-   u64 handle_protocol;
-   u64 exit_boot_services;
-   u64 text_output;
-   efi_status_t (*call)(unsigned long, ...);
-   bool is64;
-} __packed;
-
 #endif /* BOOT_COMPRESSED_EBOOT_H */
diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 1eb5f6433ad8..55059a50a01f 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -156,6 +156,31 @@ static inline efi_status_t 
efi_thunk_set_virtual_address_map(
return EFI_SUCCESS;
 }
 #endif /* CONFIG_EFI_MIXED */
+
+
+/* arch specific definitions used by the stub code */
+
+struct efi_config {
+   u64 image_handle;
+   u64 table;
+   u64 allocate_pool;
+   u64 allocate_pages;
+   u64 get_memory_map;
+   u64 free_pool;
+   u64 free_pages;
+   u64 locate_handle;
+   u64 handle_protocol;
+   u64 exit_boot_services;
+   u64 text_output;
+   efi_status_t (*call)(unsigned long, ...);
+   bool is64;
+} __packed;
+
+extern struct efi_config *efi_early;
+
+#define efi_call_early(f, ...) \
+   efi_early-call(efi_early-f, __VA_ARGS__);
+
 #else
 /*
  * IF EFI is not configured, have the EFI calls return -ENOSYS.
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-efi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/5] efi/arm64: avoid EFI_ERROR as a generic return code

2014-06-26 Thread Ard Biesheuvel
As EFI_ERROR is not a UEFI result code but a local invention only intended to
allow get_dram_base() to signal failure, we should not use it elsewhere.

Replace with EFI_LOAD_ERROR.

Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
---
 arch/arm64/kernel/efi-stub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index e786e6cdc400..7aa7155a9740 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -69,7 +69,7 @@ static efi_status_t handle_kernel_image(efi_system_table_t 
*sys_table,
if (*image_addr != (dram_base + TEXT_OFFSET)) {
pr_efi_err(sys_table, Failed to alloc kernel 
memory\n);
efi_free(sys_table, kernel_memsize, *image_addr);
-   return EFI_ERROR;
+   return EFI_LOAD_ERROR;
}
*image_size = kernel_memsize;
}
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-efi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/5] efi/arm64: efistub: move shared dependencies to asm/efi.h

2014-06-26 Thread Ard Biesheuvel
This moves definitions depended upon both by code under arch/arm64/boot and
under drivers/firmware/efi to asm/efi.h. This is in preparation of turning
the stub code under drivers/firmware/efi into a static library.

Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
---
 arch/arm64/include/asm/efi.h | 12 
 arch/arm64/kernel/efi-stub.c | 11 +--
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h
index 375ba342dca6..a34fd3b12e2b 100644
--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -32,4 +32,16 @@ extern void efi_idmap_init(void);
kernel_neon_end();  \
 })
 
+/* arch specific definitions used by the stub code */
+
+/*
+ * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
+ * start of kernel and may not cross a 2MiB boundary. We set alignment to
+ * 2MiB so we know it won't cross a 2MiB boundary.
+ */
+#define EFI_FDT_ALIGN  SZ_2M   /* used by allocate_new_fdt_and_exit_boot() */
+#define MAX_FDT_OFFSET SZ_512M
+
+#define efi_call_early(f, ...) sys_table_arg-boottime-f(__VA_ARGS__)
+
 #endif /* _ASM_EFI_H */
diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index 7aa7155a9740..23cbde4324b1 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -10,19 +10,10 @@
  *
  */
 #include linux/efi.h
+#include asm/efi.h
 #include linux/libfdt.h
 #include asm/sections.h
 
-/*
- * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
- * start of kernel and may not cross a 2MiB boundary. We set alignment to
- * 2MiB so we know it won't cross a 2MiB boundary.
- */
-#define EFI_FDT_ALIGN  SZ_2M   /* used by allocate_new_fdt_and_exit_boot() */
-#define MAX_FDT_OFFSET SZ_512M
-
-#define efi_call_early(f, ...) sys_table_arg-boottime-f(__VA_ARGS__)
-
 static void efi_char16_printk(efi_system_table_t *sys_table_arg,
  efi_char16_t *str);
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-efi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 4/5] efi: efistub: refactor stub components

2014-06-26 Thread Ard Biesheuvel
In order to move from the #include ../../../x.c anti-pattern used by
both the x86 and arm64 versions of the stub to a static library linked into
either the kernel proper (arm64) or a separate boot executable (x86), there
is some prepatory work required.

This patch does the following:
- move forward declarations of functions shared between the arch specific and
  the generic parts of the stub to include/linux/efi.h
- move forward declarations of functions shared between various .c files of the
  generic stub code to a new local header file called efistub.h
- add #includes to all .c files which were formerly relying on the #includor to
  include the correct header files
- remove all static modifiers from functions which will need to be externally
  visible once we move to a static library

Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
---
 arch/arm64/kernel/efi-stub.c   | 29 -
 arch/x86/boot/compressed/eboot.c   | 13 +++---
 drivers/firmware/efi/arm-stub.c| 18 ++---
 drivers/firmware/efi/efi-stub-helper.c | 74 +-
 drivers/firmware/efi/efistub.h | 42 +++
 drivers/firmware/efi/fdt.c | 20 +
 include/linux/efi.h| 42 +++
 7 files changed, 157 insertions(+), 81 deletions(-)
 create mode 100644 drivers/firmware/efi/efistub.h

diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index 23cbde4324b1..e4999021b07d 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -11,36 +11,21 @@
  */
 #include linux/efi.h
 #include asm/efi.h
-#include linux/libfdt.h
 #include asm/sections.h
 
-static void efi_char16_printk(efi_system_table_t *sys_table_arg,
- efi_char16_t *str);
-
-static efi_status_t efi_open_volume(efi_system_table_t *sys_table,
-   void *__image, void **__fh);
-static efi_status_t efi_file_close(void *handle);
-
-static efi_status_t
-efi_file_read(void *handle, unsigned long *size, void *addr);
-
-static efi_status_t
-efi_file_size(efi_system_table_t *sys_table, void *__fh,
- efi_char16_t *filename_16, void **handle, u64 *file_sz);
-
 /* Include shared EFI stub code */
 #include ../../../drivers/firmware/efi/efi-stub-helper.c
 #include ../../../drivers/firmware/efi/fdt.c
 #include ../../../drivers/firmware/efi/arm-stub.c
 
 
-static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
-   unsigned long *image_addr,
-   unsigned long *image_size,
-   unsigned long *reserve_addr,
-   unsigned long *reserve_size,
-   unsigned long dram_base,
-   efi_loaded_image_t *image)
+efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
+unsigned long *image_addr,
+unsigned long *image_size,
+unsigned long *reserve_addr,
+unsigned long *reserve_size,
+unsigned long dram_base,
+efi_loaded_image_t *image)
 {
efi_status_t status;
unsigned long kernel_size, kernel_memsize = 0;
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 2fd5e2643623..d338c134c659 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -45,8 +45,7 @@ static void setup_boot_services##bits(struct efi_config *c)   
\
 BOOT_SERVICES(32);
 BOOT_SERVICES(64);
 
-static void efi_printk(efi_system_table_t *, char *);
-static void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
+void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
 
 static efi_status_t
 __file_size32(void *__fh, efi_char16_t *filename_16,
@@ -153,7 +152,7 @@ grow:
 
return status;
 }
-static efi_status_t
+efi_status_t
 efi_file_size(efi_system_table_t *sys_table, void *__fh,
  efi_char16_t *filename_16, void **handle, u64 *file_sz)
 {
@@ -163,7 +162,7 @@ efi_file_size(efi_system_table_t *sys_table, void *__fh,
return __file_size32(__fh, filename_16, handle, file_sz);
 }
 
-static inline efi_status_t
+efi_status_t
 efi_file_read(void *handle, unsigned long *size, void *addr)
 {
unsigned long func;
@@ -181,7 +180,7 @@ efi_file_read(void *handle, unsigned long *size, void *addr)
}
 }
 
-static inline efi_status_t efi_file_close(void *handle)
+efi_status_t efi_file_close(void *handle)
 {
if (efi_early-is64) {
efi_file_handle_64_t *fh = handle;
@@ -246,7 +245,7 @@ static inline efi_status_t __open_volume64(void *__image, 
void **__fh)
return status;
 }
 
-static inline efi_status_t
+efi_status_t
 

[PATCH v2 0/5] efistub: convert into static library

2014-06-26 Thread Ard Biesheuvel
This is v2 of the series to change the #include ../../../../xxx.c pattern
into a static library linked into either the kernel (arm64) or a separate boot
decompressor (x86, ARM).

Changes since v1:
- added patch #1 to change EFI_ERROR, it is not a result code defined by UEFI so
  it should only be returned by get_dram_base() and efi_entry()
- added a section to libstub Makefile to clean CFLAGS of stack protecter and 
  other options that are inappropriate for the stub
- rebased onto the UEFI Runtime Services NEON patches (re)posted earlier today

Ard Biesheuvel (5):
  efi/arm64: avoid EFI_ERROR as a generic return code
  efi/x86: efistub: move shared dependencies to asm/efi.h
  efi/arm64: efistub: move shared dependencies to asm/efi.h
  efi: efistub: refactor stub components
  efi: efistub: convert into static library

 arch/arm64/Kconfig |  1 +
 arch/arm64/Makefile|  1 +
 arch/arm64/include/asm/efi.h   | 12 
 arch/arm64/kernel/efi-stub.c   | 47 +++---
 arch/x86/boot/compressed/Makefile  |  3 +-
 arch/x86/boot/compressed/eboot.c   | 20 ++
 arch/x86/boot/compressed/eboot.h   | 16 -
 arch/x86/include/asm/efi.h | 25 
 drivers/firmware/efi/Kconfig   |  3 +
 drivers/firmware/efi/Makefile  |  2 +-
 drivers/firmware/efi/libstub/Makefile  | 26 
 drivers/firmware/efi/{ = libstub}/arm-stub.c  | 32 ++
 .../firmware/efi/{ = libstub}/efi-stub-helper.c   | 74 +++---
 drivers/firmware/efi/libstub/efistub.h | 42 
 drivers/firmware/efi/{ = libstub}/fdt.c   | 20 +++---
 include/linux/efi.h| 42 
 16 files changed, 238 insertions(+), 128 deletions(-)
 create mode 100644 drivers/firmware/efi/libstub/Makefile
 rename drivers/firmware/efi/{ = libstub}/arm-stub.c (93%)
 rename drivers/firmware/efi/{ = libstub}/efi-stub-helper.c (88%)
 create mode 100644 drivers/firmware/efi/libstub/efistub.h
 rename drivers/firmware/efi/{ = libstub}/fdt.c (94%)

-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-efi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 5/5] efi: efistub: convert into static library

2014-06-26 Thread Ard Biesheuvel
This patch changes both x86 and arm64 efistub implementations from #including
shared .c files under drivers/firmware/efi to building the shared code as a
static library.

The x86 code uses a stub built into the boot executable which uncompresses the
kernel at boot time. In this case, the library is linked into the decompressor.

In the arm64 case, the stub is part of the kernel proper so the library is
linked into the kernel proper as well.

Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
---
 arch/arm64/Kconfig |  1 +
 arch/arm64/Makefile|  1 +
 arch/arm64/kernel/efi-stub.c   |  5 -
 arch/x86/boot/compressed/Makefile  |  3 ++-
 arch/x86/boot/compressed/eboot.c   |  2 --
 drivers/firmware/efi/Kconfig   |  3 +++
 drivers/firmware/efi/Makefile  |  2 +-
 drivers/firmware/efi/libstub/Makefile  | 26 ++
 drivers/firmware/efi/{ = libstub}/arm-stub.c  | 14 ++--
 .../firmware/efi/{ = libstub}/efi-stub-helper.c   |  0
 drivers/firmware/efi/{ = libstub}/efistub.h   |  0
 drivers/firmware/efi/{ = libstub}/fdt.c   |  0
 12 files changed, 41 insertions(+), 16 deletions(-)
 create mode 100644 drivers/firmware/efi/libstub/Makefile
 rename drivers/firmware/efi/{ = libstub}/arm-stub.c (96%)
 rename drivers/firmware/efi/{ = libstub}/efi-stub-helper.c (100%)
 rename drivers/firmware/efi/{ = libstub}/efistub.h (100%)
 rename drivers/firmware/efi/{ = libstub}/fdt.c (100%)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 93e11f4d9513..f766f346022d 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -300,6 +300,7 @@ config EFI
select UCS2_STRING
select EFI_PARAMS_FROM_FDT
select EFI_RUNTIME_WRAPPERS
+   select EFI_ARMSTUB
default y
help
  This option provides support for runtime services provided
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 8185a913c5ed..bb8f21a626c0 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -48,6 +48,7 @@ core-$(CONFIG_XEN) += arch/arm64/xen/
 core-$(CONFIG_CRYPTO) += arch/arm64/crypto/
 libs-y := arch/arm64/lib/ $(libs-y)
 libs-y += $(LIBGCC)
+libs-$(CONFIG_EFI) += drivers/firmware/efi/libstub/
 
 # Default target when executing plain make
 KBUILD_IMAGE   := Image.gz
diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index e4999021b07d..12456a7d3fa2 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -13,11 +13,6 @@
 #include asm/efi.h
 #include asm/sections.h
 
-/* Include shared EFI stub code */
-#include ../../../drivers/firmware/efi/efi-stub-helper.c
-#include ../../../drivers/firmware/efi/fdt.c
-#include ../../../drivers/firmware/efi/arm-stub.c
-
 
 efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
 unsigned long *image_addr,
diff --git a/arch/x86/boot/compressed/Makefile 
b/arch/x86/boot/compressed/Makefile
index 0fcd9133790c..7a801a310e37 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -33,7 +33,8 @@ VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o 
$(obj)/misc.o \
 $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
 
 ifeq ($(CONFIG_EFI_STUB), y)
-   VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o
+   VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \
+   $(objtree)/drivers/firmware/efi/libstub/lib.a
 endif
 
 $(obj)/vmlinux: $(VMLINUX_OBJS) FORCE
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index d338c134c659..d4d865438a0c 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -280,8 +280,6 @@ void efi_char16_printk(efi_system_table_t *table, 
efi_char16_t *str)
}
 }
 
-#include ../../../../drivers/firmware/efi/efi-stub-helper.c
-
 static void find_bits(unsigned long mask, u8 *pos, u8 *size)
 {
u8 first, len;
diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig
index 04a7af46736a..395e76d9a1b5 100644
--- a/drivers/firmware/efi/Kconfig
+++ b/drivers/firmware/efi/Kconfig
@@ -61,6 +61,9 @@ config EFI_RUNTIME_WRAPPERS
  in which case it needs to provide #definitions of efi_call_virt and
  __efi_call_virt in asm/efi.h
 
+config EFI_ARMSTUB
+   bool
+
 endmenu
 
 config UEFI_CPER
diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
index e1096539eedb..d9abdbc962f1 100644
--- a/drivers/firmware/efi/Makefile
+++ b/drivers/firmware/efi/Makefile
@@ -1,7 +1,7 @@
 #
 # Makefile for linux kernel
 #
-obj-$(CONFIG_EFI)  += efi.o vars.o
+obj-$(CONFIG_EFI)  += efi.o vars.o libstub/
 obj-$(CONFIG_EFI_VARS) += efivars.o
 obj-$(CONFIG_EFI_VARS_PSTORE)  += efi-pstore.o
 

[PATCH 15/15] kexec: Support kexec/kdump on EFI systems

2014-06-26 Thread Vivek Goyal
This patch does two thigns. It passes EFI run time mappings to second
kernel in bootparams efi_info. Second kernel parse this info and create
new mappings in second kernel. That means mappings in first and second
kernel will be same. This paves the way to enable EFI in kexec kernel.

This patch also prepares and passes EFI setup data through bootparams.
This contains bunch of information about various tables and their
addresses.

These information gathering and passing has been written along the lines
of what current kexec-tools is doing to make kexec work with UEFI.

Signed-off-by: Vivek Goyal vgo...@redhat.com
CC: linux-efi@vger.kernel.org
---
 arch/x86/kernel/kexec-bzimage64.c  | 146 ++---
 drivers/firmware/efi/runtime-map.c |  21 ++
 include/linux/efi.h|  19 +
 3 files changed, 174 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/kexec-bzimage64.c 
b/arch/x86/kernel/kexec-bzimage64.c
index 61e4306..9487845 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -18,10 +18,12 @@
 #include linux/kexec.h
 #include linux/kernel.h
 #include linux/mm.h
+#include linux/efi.h
 
 #include asm/bootparam.h
 #include asm/setup.h
 #include asm/crash.h
+#include asm/efi.h
 
 #define MAX_ELFCOREHDR_STR_LEN 30  /* elfcorehdr=0x64bit-value */
 
@@ -90,7 +92,7 @@ static int setup_cmdline(struct kimage *image, struct 
boot_params *params,
return 0;
 }
 
-static int setup_memory_map_entries(struct boot_params *params)
+static int setup_e820_entries(struct boot_params *params)
 {
unsigned int nr_e820_entries;
 
@@ -107,8 +109,93 @@ static int setup_memory_map_entries(struct boot_params 
*params)
return 0;
 }
 
-static int setup_boot_parameters(struct kimage *image,
-struct boot_params *params)
+#ifdef CONFIG_EFI
+static int setup_efi_info_memmap(struct boot_params *params,
+ unsigned long params_load_addr,
+ unsigned int efi_map_offset,
+ unsigned int efi_map_sz)
+{
+   void *efi_map = (void *)params + efi_map_offset;
+   unsigned long efi_map_phys_addr = params_load_addr + efi_map_offset;
+   struct efi_info *ei = params-efi_info;
+
+   if (!efi_map_sz)
+   return 0;
+
+   efi_runtime_map_copy(efi_map, efi_map_sz);
+
+   ei-efi_memmap = efi_map_phys_addr  0x;
+   ei-efi_memmap_hi = efi_map_phys_addr  32;
+   ei-efi_memmap_size = efi_map_sz;
+
+   return 0;
+}
+
+static int
+prepare_add_efi_setup_data(struct boot_params *params,
+  unsigned long params_load_addr,
+  unsigned int efi_setup_data_offset)
+{
+   unsigned long setup_data_phys;
+   struct setup_data *sd = (void *)params + efi_setup_data_offset;
+   struct efi_setup_data *esd = (void *)sd + sizeof(struct setup_data);
+
+   esd-fw_vendor = efi.fw_vendor;
+   esd-runtime = efi.runtime;
+   esd-tables = efi.config_table;
+   esd-smbios = efi.smbios;
+
+   sd-type = SETUP_EFI;
+   sd-len = sizeof(struct efi_setup_data);
+
+   /* Add setup data */
+   setup_data_phys = params_load_addr + efi_setup_data_offset;
+   sd-next = params-hdr.setup_data;
+   params-hdr.setup_data = setup_data_phys;
+
+   return 0;
+}
+
+static int
+setup_efi_state(struct boot_params *params, unsigned long params_load_addr,
+   unsigned int efi_map_offset, unsigned int efi_map_sz,
+   unsigned int efi_setup_data_offset)
+{
+   struct efi_info *current_ei = boot_params.efi_info;
+   struct efi_info *ei = params-efi_info;
+
+   if (!current_ei-efi_memmap_size)
+   return 0;
+
+   /*
+* If 1:1 mapping is not enabled, second kernel can not setup EFI
+* and use EFI run time services. User space will have to pass
+* acpi_rsdp=addr on kernel command line to make second kernel boot
+* without efi.
+*/
+   if (efi_enabled(EFI_OLD_MEMMAP))
+   return 0;
+
+   ei-efi_loader_signature = current_ei-efi_loader_signature;
+   ei-efi_systab = current_ei-efi_systab;
+   ei-efi_systab_hi = current_ei-efi_systab_hi;
+
+   ei-efi_memdesc_version = current_ei-efi_memdesc_version;
+   ei-efi_memdesc_size = get_efi_runtime_map_desc_size();
+
+   setup_efi_info_memmap(params, params_load_addr, efi_map_offset,
+ efi_map_sz);
+   prepare_add_efi_setup_data(params, params_load_addr,
+  efi_setup_data_offset);
+   return 0;
+}
+#endif /* CONFIG_EFI */
+
+static int
+setup_boot_parameters(struct kimage *image, struct boot_params *params,
+ unsigned long params_load_addr,
+ unsigned int efi_map_offset, unsigned int efi_map_sz,
+ unsigned int efi_setup_data_offset)