diff mbox series

[v7,11/26] cvc: allow BE cvc code to be called from LE context

Message ID 20191111054918.7188-12-npiggin@gmail.com
State Changes Requested
Headers show
Series little endian skiboot | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch warning Failed to apply on branch master (d75e82dbfbb9443efeb3f9a5921ac23605aab469)
snowpatch_ozlabs/apply_patch fail Failed to apply to any branch

Commit Message

Nicholas Piggin Nov. 11, 2019, 5:49 a.m. UTC
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 asm/cvc_entry.S | 42 ++++++++++++++++++------------------------
 libstb/cvc.c    | 16 +++++++++++-----
 libstb/cvc.h    |  2 +-
 3 files changed, 30 insertions(+), 30 deletions(-)
diff mbox series

Patch

diff --git a/asm/cvc_entry.S b/asm/cvc_entry.S
index 3e8b3fdad..94cd1aec1 100644
--- a/asm/cvc_entry.S
+++ b/asm/cvc_entry.S
@@ -1,28 +1,9 @@ 
 # SPDX-License-Identifier: Apache-2.0
-# IBM_PROLOG_BEGIN_TAG
-# This is an automatically generated prolog.
-#
-# $Source: src/usr/secureboot/base/rom_entry.S $
-#
-# OpenPOWER HostBoot Project
-#
-# COPYRIGHT International Business Machines Corp. 2013,2016
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied. See the License for the specific language governing
-# permissions and limitations under the License.
-#
-# IBM_PROLOG_END_TAG
-
-#.include "kernel/ppcconsts.S"
+
+# Derived from automatically generated HostBoot rom_entry.S
+
+#include <asm-utils.h>
+#include <processor.h>
 
 # Updated hostboot location is src/securerom/rom_entry.S.
 # This also has a fix for TOC save frame pointer.
@@ -49,7 +30,20 @@  call_rom_entry:
     mr %r5, %r6
     mr %r6, %r7
     mr %r7, %r8
+#if HAVE_BIG_ENDIAN
     bctrl
+#else
+    bl $+4
+1:  mflr %r9
+    addi %r9,%r9,2f - 1b
+    mtspr SPR_HSRR0, %r9
+    mfmsr %r9
+    xori %r9,%r9,MSR_LE
+    mtspr SPR_HSRR1, %r9
+    hrfid
+2:  .long 0x2104804e /* bctrl */
+    FIXUP_ENDIAN
+#endif
     ld %r2, STACK_TOC_OFFSET(%r1)
     addi %r1, %r1, 128
     ld %r0, 16(%r1)
diff --git a/libstb/cvc.c b/libstb/cvc.c
index dca4ac857..4fc29c08d 100644
--- a/libstb/cvc.c
+++ b/libstb/cvc.c
@@ -305,16 +305,19 @@  int call_cvc_sha512(const uint8_t *data, size_t data_len, uint8_t *digest,
 	if (!service)
 		return OPAL_UNSUPPORTED;
 
-	if (service->version == 1)
+	if (service->version == 1) {
+		unsigned long msr = mfmsr();
 		__cvc_sha512_v1((void*) service->addr, data, data_len, digest);
-	else
+		assert(msr == mfmsr());
+	} else {
 		return OPAL_UNSUPPORTED;
+	}
 
 	return OPAL_SUCCESS;
 }
 
 int call_cvc_verify(void *container, size_t len, const void *hw_key_hash,
-		    size_t hw_key_hash_size, uint64_t *log)
+		    size_t hw_key_hash_size, __be64 *log)
 {
 	ROM_hw_params hw_params;
 	ROM_response rc;
@@ -335,12 +338,15 @@  int call_cvc_verify(void *container, size_t len, const void *hw_key_hash,
 	memset(&hw_params, 0, sizeof(ROM_hw_params));
 	memcpy(&hw_params.hw_key_hash, hw_key_hash, hw_key_hash_size);
 
-	if (service->version == 1)
+	if (service->version == 1) {
+		unsigned long msr = mfmsr();
 		rc = __cvc_verify_v1((void*) service->addr,
 				   (ROM_container_raw*) container,
 				   &hw_params);
-	else
+		assert(msr == mfmsr());
+	} else {
 		return OPAL_UNSUPPORTED;
+	}
 
 	if (log)
 		*log = hw_params.log;
diff --git a/libstb/cvc.h b/libstb/cvc.h
index 6d8546fb2..ef105f76d 100644
--- a/libstb/cvc.h
+++ b/libstb/cvc.h
@@ -30,7 +30,7 @@  int cvc_init(void);
  *
  */
 int call_cvc_verify(void *buf, size_t size, const void *hw_key_hash,
-		    size_t hw_key_hash_size, uint64_t *log);
+		    size_t hw_key_hash_size, __be64 *log);
 
 /*
  * call_cvc_sha512 - Call the CVC-sha512 service to calculate a sha512 hash.