#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pci_smccc.c,v 1.1 2021/08/07 21:23:37 jmcneill Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
#include <arm/arm/smccc.h>
#include <arm/pci/pci_smccc.h>
#define SMCCC_VERSION_1_1 0x10001
#define PCI_VERSION 0x84000130
#define PCI_FEATURES 0x84000131
#define PCI_READ 0x84000132
#define PCI_WRITE 0x84000133
#define PCI_GET_SEG_INFO 0x84000134
#define GET_SEG_INFO_BUS_START __BITS(7,0)
#define GET_SEG_INFO_BUS_END __BITS(15,8)
static int
pci_smccc_call(uint32_t fid,
register_t arg1, register_t arg2, register_t arg3, register_t arg4,
register_t *res0, register_t *res1, register_t *res2, register_t *res3)
{
static int smccc_ver;
if (smccc_ver == 0) {
smccc_ver = smccc_version();
}
if (smccc_ver < SMCCC_VERSION_1_1) {
return SMCCC_NOT_SUPPORTED;
}
return smccc_call(fid, arg1, arg2, arg3, arg4,
res0, res1, res2, res3);
}
int
pci_smccc_version(void)
{
return pci_smccc_call(PCI_VERSION, 0, 0, 0, 0,
NULL, NULL, NULL, NULL);
}
int
pci_smccc_features(uint32_t fid)
{
return pci_smccc_call(PCI_FEATURES, fid, 0, 0, 0,
NULL, NULL, NULL, NULL);
}
int
pci_smccc_read(uint32_t sbdf, uint32_t offset, uint32_t access_size,
uint32_t *data)
{
register_t value;
int status;
status = pci_smccc_call(PCI_READ, sbdf, offset, access_size, 0,
NULL, &value, NULL, NULL);
if (status == SMCCC_SUCCESS) {
*data = value;
}
return status;
}
int
pci_smccc_write(uint32_t sbdf, uint32_t offset, uint32_t access_size,
uint32_t data)
{
return pci_smccc_call(PCI_WRITE, sbdf, offset, access_size, data,
NULL, NULL, NULL, NULL);
}
int
pci_smccc_get_seg_info(uint16_t seg, uint8_t *bus_start, uint8_t *bus_end,
uint16_t *next_seg)
{
register_t res1, res2;
int status;
status = pci_smccc_call(PCI_GET_SEG_INFO, seg, 0, 0, 0,
NULL, &res1, &res2, NULL);
if (status == SMCCC_SUCCESS) {
*bus_start = __SHIFTOUT(res1, GET_SEG_INFO_BUS_START);
*bus_end = __SHIFTOUT(res1, GET_SEG_INFO_BUS_END);
*next_seg = (uint16_t)res2;
}
return status;
}