static DEFINE_SPINLOCK(storage_lock);
static unsigned long lockflags;
+static int storage_init_status;
+
static uint64_t storage_smc_ops(uint64_t func)
{
register unsigned long x0 asm("x0") = func;
uint64_t ret;
spin_lock_irqsave(&storage_lock, lockflags);
- namelen = strlen((const char *)keyname);
- input = (uint32_t *)storage_in_base;
- *input++ = namelen;
- *input++ = keylen;
- *input++ = keyattr;
- name = (uint8_t *)input;
- memcpy(name, keyname, namelen);
- keydata = name + namelen;
- memcpy(keydata, keybuf, keylen);
- ret = storage_smc_ops(storage_write_func);
+ if (storage_init_status == 1) {
+ namelen = strlen((const char *)keyname);
+ input = (uint32_t *)storage_in_base;
+ *input++ = namelen;
+ *input++ = keylen;
+ *input++ = keyattr;
+ name = (uint8_t *)input;
+ memcpy(name, keyname, namelen);
+ keydata = name + namelen;
+ memcpy(keydata, keybuf, keylen);
+ ret = storage_smc_ops(storage_write_func);
+ } else
+ ret = RET_EUND;
spin_unlock_irqrestore(&storage_lock, lockflags);
return smc_to_linux_errno(ret);
}
uint64_t ret;
spin_lock_irqsave(&storage_lock, lockflags);
- namelen = strlen((const char *)keyname);
- *input++ = namelen;
- *input++ = keylen;
- name = (uint8_t *)input;
- memcpy(name, keyname, namelen);
- ret = storage_smc_ops(storage_read_func);
- if (ret == RET_OK) {
- *readlen = *output;
- buf = (uint8_t *)(output + 1);
- memcpy(keybuf, buf, *readlen);
- }
+ if (storage_init_status == 1) {
+ namelen = strlen((const char *)keyname);
+ *input++ = namelen;
+ *input++ = keylen;
+ name = (uint8_t *)input;
+ memcpy(name, keyname, namelen);
+ ret = storage_smc_ops(storage_read_func);
+ if (ret == RET_OK) {
+ *readlen = *output;
+ buf = (uint8_t *)(output + 1);
+ memcpy(keybuf, buf, *readlen);
+ }
+ } else
+ ret = RET_EUND;
spin_unlock_irqrestore(&storage_lock, lockflags);
return smc_to_linux_errno(ret);
}
uint64_t ret;
spin_lock_irqsave(&storage_lock, lockflags);
- namelen = strlen((const char *)keyname);
- *input++ = namelen;
- name = (uint8_t *)input;
- memcpy(name, keyname, namelen);
- ret = storage_smc_ops(storage_verify_func);
- if (ret == RET_OK)
- memcpy(hashbuf, (uint8_t *)output, 32);
+ if (storage_init_status == 1) {
+ namelen = strlen((const char *)keyname);
+ *input++ = namelen;
+ name = (uint8_t *)input;
+ memcpy(name, keyname, namelen);
+ ret = storage_smc_ops(storage_verify_func);
+ if (ret == RET_OK)
+ memcpy(hashbuf, (uint8_t *)output, 32);
+ } else
+ ret = RET_EUND;
spin_unlock_irqrestore(&storage_lock, lockflags);
return smc_to_linux_errno(ret);
uint64_t ret;
spin_lock_irqsave(&storage_lock, lockflags);
- namelen = strlen((const char *)keyname);
- *input++ = namelen;
- name = (uint8_t *)input;
- memcpy(name, keyname, namelen);
- ret = storage_smc_ops(storage_query_func);
- if (ret == RET_OK)
- *retval = *output;
+ if (storage_init_status == 1) {
+ namelen = strlen((const char *)keyname);
+ *input++ = namelen;
+ name = (uint8_t *)input;
+ memcpy(name, keyname, namelen);
+ ret = storage_smc_ops(storage_query_func);
+ if (ret == RET_OK)
+ *retval = *output;
+ } else
+ ret = RET_EUND;
spin_unlock_irqrestore(&storage_lock, lockflags);
return smc_to_linux_errno(ret);
uint64_t ret;
spin_lock_irqsave(&storage_lock, lockflags);
- namelen = strlen((const char *)keyname);
- *input++ = namelen;
- name = (uint8_t *)input;
- memcpy(name, keyname, namelen);
- ret = storage_smc_ops(storage_tell_func);
- if (ret == RET_OK)
- *retval = *output;
+ if (storage_init_status == 1) {
+ namelen = strlen((const char *)keyname);
+ *input++ = namelen;
+ name = (uint8_t *)input;
+ memcpy(name, keyname, namelen);
+ ret = storage_smc_ops(storage_tell_func);
+ if (ret == RET_OK)
+ *retval = *output;
+ } else
+ ret = RET_EUND;
spin_unlock_irqrestore(&storage_lock, lockflags);
return smc_to_linux_errno(ret);
}
uint64_t ret;
spin_lock_irqsave(&storage_lock, lockflags);
- namelen = strlen((const char *)keyname);
- *input++ = namelen;
- name = (uint8_t *)input;
- memcpy(name, keyname, namelen);
- ret = storage_smc_ops(storage_status_func);
- if (ret == RET_OK)
- *retval = *output;
+ if (storage_init_status == 1) {
+ namelen = strlen((const char *)keyname);
+ *input++ = namelen;
+ name = (uint8_t *)input;
+ memcpy(name, keyname, namelen);
+ ret = storage_smc_ops(storage_status_func);
+ if (ret == RET_OK)
+ *retval = *output;
+ } else
+ ret = RET_EUND;
spin_unlock_irqrestore(&storage_lock, lockflags);
return smc_to_linux_errno(ret);
}
uint64_t ret;
spin_lock_irqsave(&storage_lock, lockflags);
- ret = storage_smc_ops(storage_list_func);
- if (ret == RET_OK) {
- if (*output > buflen)
- *readlen = buflen;
- else
- *readlen = *output;
- memcpy(listbuf, (uint8_t *)(output+1), *readlen);
- }
+ if (storage_init_status == 1) {
+ ret = storage_smc_ops(storage_list_func);
+ if (ret == RET_OK) {
+ if (*output > buflen)
+ *readlen = buflen;
+ else
+ *readlen = *output;
+ memcpy(listbuf, (uint8_t *)(output+1), *readlen);
+ }
+ } else
+ ret = RET_EUND;
spin_unlock_irqrestore(&storage_lock, lockflags);
return smc_to_linux_errno(ret);
}
uint64_t ret;
spin_lock_irqsave(&storage_lock, lockflags);
- namelen = strlen((const char *)keyname);
- *input++ = namelen;
- name = (uint8_t *)input;
- memcpy(name, keyname, namelen);
- ret = storage_smc_ops(storage_remove_func);
+ if (storage_init_status == 1) {
+ namelen = strlen((const char *)keyname);
+ *input++ = namelen;
+ name = (uint8_t *)input;
+ memcpy(name, keyname, namelen);
+ ret = storage_smc_ops(storage_remove_func);
+ } else
+ ret = RET_EUND;
spin_unlock_irqrestore(&storage_lock, lockflags);
return smc_to_linux_errno(ret);
}
return -1;
}
- storage_in_base = ioremap_cache(phy_storage_in_base,
- storage_block_size);
- storage_out_base = ioremap_cache(phy_storage_out_base,
- storage_block_size);
- storage_block_base = ioremap_cache(phy_storage_block_base,
- storage_block_size);
+ if (phy_storage_in_base == SMC_UNK
+ || phy_storage_out_base == SMC_UNK
+ || phy_storage_block_base == SMC_UNK
+ || storage_block_size == SMC_UNK) {
+ storage_in_base = NULL;
+ storage_out_base = NULL;
+ storage_block_base = NULL;
+ } else {
+ storage_in_base = ioremap_cache(phy_storage_in_base,
+ storage_block_size);
+ storage_out_base = ioremap_cache(phy_storage_out_base,
+ storage_block_size);
+ storage_block_base = ioremap_cache(phy_storage_block_base,
+ storage_block_size);
+ }
+
pr_info("storage in base: 0x%lx\n", (long)storage_in_base);
pr_info("storage out base: 0x%lx\n", (long)storage_out_base);
pr_info("storage block base: 0x%lx\n", (long)storage_block_base);
ret = 0;
if (!storage_in_base || !storage_out_base || !storage_block_base)
ret = -1;
+ if (ret == 0)
+ storage_init_status = 1;
+ else
+ storage_init_status = -1;
+
pr_info("probe done!\n");
return ret;
}