/*******************************************************************************
*
* Copyright (c) 2008 Loc Ho <lho@amcc.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* Detail Description:
* This file defines ioctl structures for the Linux CryptoAPI interface. It
* provides user space applications accesss into the Linux CryptoAPI
* functionalities.
*
* @file pka4xx.c
*
* This file provides access and implementation of the high layer API to the
* PKA registers.
*
*******************************************************************************
*/
#include <asm/delay.h>
#include <asm/dcr-native.h>
#include <linux/irq.h>
#include "pka_4xx_access.h"
#include <crypto/pka_4xx.h>
#include "pka_4xx_firmware.h"
/**
* PKA Functions
*
*/
/* # of time to poll for synchronous operation */
#define PKA4XX_POLL_DONE_MAX_CNT 5000
#define PKA4XX_CSR_WRITE_RETURN(a, v) \
do { \
rc = pka4xx_csr_hw_write32((a), (v)); \
if (rc != RC_OK) \
return rc; \
} while(0);
#define PKA4XX_CSR_READ_RETURN(a, v) \
do { \
rc = pka4xx_csr_hw_read32((a), (v)); \
if (rc != RC_OK) \
return rc; \
} while(0);
#define PKA_ALIGN(x, a) do { \
(x) += ((a)-1); \
(x) &= ~((a)-1); \
} while(0);
#define PKA_ALIGN_RVAL(x, a) (((x) + ((a)-1)) & (~((a)-1)))
static u32 pkt_firmware_sizedw = PKA_FIRMWARE_1_3_SIZEDW;
static const u32 *pka_firmware = pka_firmware_1_3;
u32 msg_buf[20][10];
int msg_idx;
u32 pka4xx_pkcp_set_vec(u32 vecA_cnt,
u32 *vecA,
u32 vecB_cnt,
u32 *vecB)
{
u32 addr;
int rc, i;
u32 val32;
addr = PKA_RAM_ADDR;
/* Set PKA RAM address and load input A - multiplicand */
PKA4XX_CSR_WRITE_RETURN(PKA_ALENGTH_ADDR, vecA_cnt);
PKA4XX_CSR_WRITE_RETURN(PKA_APTR_ADDR, addr >> 2);
PKA4XX_CSR_READ_RETURN(PKA_APTR_ADDR, &val32);
PKA4XX_CSR_READ_RETURN(PKA_ALENGTH_ADDR, &val32);
for(i = 0; i < vecA_cnt; i++, addr += 4) {
PKA4XX_CSR_WRITE_RETURN(addr, vecA[i]);
PKA4XX_CSR_READ_RETURN(addr, &val32);
LPRINTF(LL_INFO, "addr %08X val %08X", addr, val32);
}
PKA_ALIGN(addr, 8); /* Align 8-byte */
/* Align 8-byte but use 2 as it is DWORD */
/* Set PKA RAM address and load for input B - multiplier */
PKA4XX_CSR_WRITE_RETURN(PKA_BLENGTH_ADDR, vecB_cnt);
PKA4XX_CSR_WRITE_RETURN(PKA_BPTR_ADDR, addr >> 2);
PKA4XX_CSR_READ_RETURN(PKA_BPTR_ADDR, &val32);
PKA4XX_CSR_READ_RETURN(PKA_BLENGTH_ADDR, &val32);
for(i = 0; i < vecB_cnt; i++, addr