^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2017-2018, Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/genalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kfifo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/firmware/intel/stratix10-smc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/firmware/intel/stratix10-svc-client.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * SVC_NUM_DATA_IN_FIFO - number of struct stratix10_svc_data in the FIFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * SVC_NUM_CHANNEL - number of channel supported by service layer driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * FPGA_CONFIG_DATA_CLAIM_TIMEOUT_MS - claim back the submitted buffer(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * from the secure world for FPGA manager to reuse, or to free the buffer(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * when all bit-stream data had be send.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * FPGA_CONFIG_STATUS_TIMEOUT_SEC - poll the FPGA configuration status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * service layer will return error to FPGA manager when timeout occurs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * timeout is set to 30 seconds (30 * 1000) at Intel Stratix10 SoC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define SVC_NUM_DATA_IN_FIFO 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define SVC_NUM_CHANNEL 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define FPGA_CONFIG_DATA_CLAIM_TIMEOUT_MS 200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define FPGA_CONFIG_STATUS_TIMEOUT_SEC 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* stratix10 service layer clients */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define STRATIX10_RSU "stratix10-rsu"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) typedef void (svc_invoke_fn)(unsigned long, unsigned long, unsigned long,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned long, unsigned long, unsigned long,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned long, unsigned long,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct arm_smccc_res *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct stratix10_svc_chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * struct stratix10_svc - svc private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @stratix10_svc_rsu: pointer to stratix10 RSU device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct stratix10_svc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct platform_device *stratix10_svc_rsu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * struct stratix10_svc_sh_memory - service shared memory structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @sync_complete: state for a completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @addr: physical address of shared memory block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * @size: size of shared memory block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * @invoke_fn: function to issue secure monitor or hypervisor call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * This struct is used to save physical address and size of shared memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * block. The shared memory blocked is allocated by secure monitor software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * at secure world.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * Service layer driver uses the physical address and size to create a memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * pool, then allocates data buffer from that memory pool for service client.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct stratix10_svc_sh_memory {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct completion sync_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) svc_invoke_fn *invoke_fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * struct stratix10_svc_data_mem - service memory structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * @vaddr: virtual address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * @paddr: physical address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * @size: size of memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * @node: link list head node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * This struct is used in a list that keeps track of buffers which have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * been allocated or freed from the memory pool. Service layer driver also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * uses this struct to transfer physical address to virtual address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct stratix10_svc_data_mem {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) void *vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) phys_addr_t paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct list_head node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * struct stratix10_svc_data - service data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * @chan: service channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * @paddr: playload physical address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * @size: playload size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * @command: service command requested by client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * @flag: configuration type (full or partial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @arg: args to be passed via registers and not physically mapped buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * This struct is used in service FIFO for inter-process communication.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct stratix10_svc_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct stratix10_svc_chan *chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) phys_addr_t paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) u32 command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u32 flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u64 arg[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * struct stratix10_svc_controller - service controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * @dev: device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * @chans: array of service channels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * @num_chans: number of channels in 'chans' array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * @num_active_client: number of active service client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * @node: list management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * @genpool: memory pool pointing to the memory region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * @task: pointer to the thread task which handles SMC or HVC call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * @svc_fifo: a queue for storing service message data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * @complete_status: state for completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * @svc_fifo_lock: protect access to service message data queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * @invoke_fn: function to issue secure monitor call or hypervisor call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * This struct is used to create communication channels for service clients, to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * handle secure monitor or hypervisor call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct stratix10_svc_controller {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct stratix10_svc_chan *chans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int num_chans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int num_active_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct list_head node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct gen_pool *genpool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct task_struct *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct kfifo svc_fifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct completion complete_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) spinlock_t svc_fifo_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) svc_invoke_fn *invoke_fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * struct stratix10_svc_chan - service communication channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * @ctrl: pointer to service controller which is the provider of this channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * @scl: pointer to service client which owns the channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * @name: service client name associated with the channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * @lock: protect access to the channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * This struct is used by service client to communicate with service layer, each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * service client has its own channel created by service controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct stratix10_svc_chan {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct stratix10_svc_controller *ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct stratix10_svc_client *scl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static LIST_HEAD(svc_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static LIST_HEAD(svc_data_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * svc_pa_to_va() - translate physical address to virtual address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * @addr: to be translated physical address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * Return: valid virtual address or NULL if the provided physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * address doesn't exist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static void *svc_pa_to_va(unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct stratix10_svc_data_mem *pmem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) pr_debug("claim back P-addr=0x%016x\n", (unsigned int)addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) list_for_each_entry(pmem, &svc_data_mem, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (pmem->paddr == addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return pmem->vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* physical address is not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * svc_thread_cmd_data_claim() - claim back buffer from the secure world
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * @ctrl: pointer to service layer controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * @p_data: pointer to service data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * @cb_data: pointer to callback data structure to service client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * Claim back the submitted buffers from the secure world and pass buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * back to service client (FPGA manager, etc) for reuse.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static void svc_thread_cmd_data_claim(struct stratix10_svc_controller *ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct stratix10_svc_data *p_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct stratix10_svc_cb_data *cb_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct arm_smccc_res res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) reinit_completion(&ctrl->complete_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) timeout = msecs_to_jiffies(FPGA_CONFIG_DATA_CLAIM_TIMEOUT_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) pr_debug("%s: claim back the submitted buffer\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ctrl->invoke_fn(INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 0, 0, 0, 0, 0, 0, 0, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (res.a0 == INTEL_SIP_SMC_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!res.a1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) complete(&ctrl->complete_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) cb_data->status = BIT(SVC_STATUS_BUFFER_DONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) cb_data->kaddr1 = svc_pa_to_va(res.a1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) cb_data->kaddr2 = (res.a2) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) svc_pa_to_va(res.a2) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) cb_data->kaddr3 = (res.a3) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) svc_pa_to_va(res.a3) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) p_data->chan->scl->receive_cb(p_data->chan->scl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) cb_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) pr_debug("%s: secure world busy, polling again\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) } while (res.a0 == INTEL_SIP_SMC_STATUS_OK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) res.a0 == INTEL_SIP_SMC_STATUS_BUSY ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) wait_for_completion_timeout(&ctrl->complete_status, timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * svc_thread_cmd_config_status() - check configuration status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * @ctrl: pointer to service layer controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * @p_data: pointer to service data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * @cb_data: pointer to callback data structure to service client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * Check whether the secure firmware at secure world has finished the FPGA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * configuration, and then inform FPGA manager the configuration status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static void svc_thread_cmd_config_status(struct stratix10_svc_controller *ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct stratix10_svc_data *p_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct stratix10_svc_cb_data *cb_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct arm_smccc_res res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) int count_in_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) cb_data->kaddr1 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) cb_data->kaddr2 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) cb_data->kaddr3 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) cb_data->status = BIT(SVC_STATUS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) pr_debug("%s: polling config status\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) count_in_sec = FPGA_CONFIG_STATUS_TIMEOUT_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) while (count_in_sec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) ctrl->invoke_fn(INTEL_SIP_SMC_FPGA_CONFIG_ISDONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 0, 0, 0, 0, 0, 0, 0, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if ((res.a0 == INTEL_SIP_SMC_STATUS_OK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) (res.a0 == INTEL_SIP_SMC_STATUS_ERROR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * configuration is still in progress, wait one second then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * poll again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) count_in_sec--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (res.a0 == INTEL_SIP_SMC_STATUS_OK && count_in_sec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) cb_data->status = BIT(SVC_STATUS_COMPLETED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) p_data->chan->scl->receive_cb(p_data->chan->scl, cb_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * svc_thread_recv_status_ok() - handle the successful status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * @p_data: pointer to service data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * @cb_data: pointer to callback data structure to service client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * @res: result from SMC or HVC call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * Send back the correspond status to the service clients.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static void svc_thread_recv_status_ok(struct stratix10_svc_data *p_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct stratix10_svc_cb_data *cb_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct arm_smccc_res res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) cb_data->kaddr1 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) cb_data->kaddr2 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) cb_data->kaddr3 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) switch (p_data->command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) case COMMAND_RECONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) case COMMAND_RSU_UPDATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) case COMMAND_RSU_NOTIFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) cb_data->status = BIT(SVC_STATUS_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) case COMMAND_RECONFIG_DATA_SUBMIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) cb_data->status = BIT(SVC_STATUS_BUFFER_SUBMITTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) case COMMAND_RECONFIG_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) cb_data->status = BIT(SVC_STATUS_COMPLETED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) case COMMAND_RSU_RETRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) case COMMAND_RSU_MAX_RETRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) cb_data->status = BIT(SVC_STATUS_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) cb_data->kaddr1 = &res.a1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) case COMMAND_RSU_DCMF_VERSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) cb_data->status = BIT(SVC_STATUS_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) cb_data->kaddr1 = &res.a1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) cb_data->kaddr2 = &res.a2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) pr_warn("it shouldn't happen\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) pr_debug("%s: call receive_cb\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) p_data->chan->scl->receive_cb(p_data->chan->scl, cb_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * svc_normal_to_secure_thread() - the function to run in the kthread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * @data: data pointer for kthread function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * Service layer driver creates stratix10_svc_smc_hvc_call kthread on CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * node 0, its function stratix10_svc_secure_call_thread is used to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * SMC or HVC calls between kernel driver and secure monitor software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * Return: 0 for success or -ENOMEM on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static int svc_normal_to_secure_thread(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct stratix10_svc_controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) *ctrl = (struct stratix10_svc_controller *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct stratix10_svc_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct stratix10_svc_cb_data *cbdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct arm_smccc_res res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) unsigned long a0, a1, a2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) int ret_fifo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) pdata = kmalloc(sizeof(*pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) cbdata = kmalloc(sizeof(*cbdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (!cbdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) kfree(pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /* default set, to remove build warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) a0 = INTEL_SIP_SMC_FPGA_CONFIG_LOOPBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) a1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) a2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) pr_debug("smc_hvc_shm_thread is running\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) ret_fifo = kfifo_out_spinlocked(&ctrl->svc_fifo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) pdata, sizeof(*pdata),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) &ctrl->svc_fifo_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (!ret_fifo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) pr_debug("get from FIFO pa=0x%016x, command=%u, size=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) (unsigned int)pdata->paddr, pdata->command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) (unsigned int)pdata->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) switch (pdata->command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) case COMMAND_RECONFIG_DATA_CLAIM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) svc_thread_cmd_data_claim(ctrl, pdata, cbdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) case COMMAND_RECONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) a0 = INTEL_SIP_SMC_FPGA_CONFIG_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) pr_debug("conf_type=%u\n", (unsigned int)pdata->flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) a1 = pdata->flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) a2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) case COMMAND_RECONFIG_DATA_SUBMIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) a0 = INTEL_SIP_SMC_FPGA_CONFIG_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) a1 = (unsigned long)pdata->paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) a2 = (unsigned long)pdata->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) case COMMAND_RECONFIG_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) a0 = INTEL_SIP_SMC_FPGA_CONFIG_ISDONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) a1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) a2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) case COMMAND_RSU_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) a0 = INTEL_SIP_SMC_RSU_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) a1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) a2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) case COMMAND_RSU_UPDATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) a0 = INTEL_SIP_SMC_RSU_UPDATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) a1 = pdata->arg[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) a2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) case COMMAND_RSU_NOTIFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) a0 = INTEL_SIP_SMC_RSU_NOTIFY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) a1 = pdata->arg[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) a2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) case COMMAND_RSU_RETRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) a0 = INTEL_SIP_SMC_RSU_RETRY_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) a1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) a2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) case COMMAND_RSU_MAX_RETRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) a0 = INTEL_SIP_SMC_RSU_MAX_RETRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) a1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) a2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) case COMMAND_RSU_DCMF_VERSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) a0 = INTEL_SIP_SMC_RSU_DCMF_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) a1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) a2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) pr_warn("it shouldn't happen\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) pr_debug("%s: before SMC call -- a0=0x%016x a1=0x%016x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) __func__, (unsigned int)a0, (unsigned int)a1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) pr_debug(" a2=0x%016x\n", (unsigned int)a2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) ctrl->invoke_fn(a0, a1, a2, 0, 0, 0, 0, 0, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) pr_debug("%s: after SMC call -- res.a0=0x%016x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) __func__, (unsigned int)res.a0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) pr_debug(" res.a1=0x%016x, res.a2=0x%016x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) (unsigned int)res.a1, (unsigned int)res.a2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) pr_debug(" res.a3=0x%016x\n", (unsigned int)res.a3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (pdata->command == COMMAND_RSU_STATUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (res.a0 == INTEL_SIP_SMC_RSU_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) cbdata->status = BIT(SVC_STATUS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) cbdata->status = BIT(SVC_STATUS_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) cbdata->kaddr1 = &res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) cbdata->kaddr2 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) cbdata->kaddr3 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) pdata->chan->scl->receive_cb(pdata->chan->scl, cbdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) switch (res.a0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) case INTEL_SIP_SMC_STATUS_OK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) svc_thread_recv_status_ok(pdata, cbdata, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) case INTEL_SIP_SMC_STATUS_BUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) switch (pdata->command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) case COMMAND_RECONFIG_DATA_SUBMIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) svc_thread_cmd_data_claim(ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) pdata, cbdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) case COMMAND_RECONFIG_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) svc_thread_cmd_config_status(ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) pdata, cbdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) pr_warn("it shouldn't happen\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) case INTEL_SIP_SMC_STATUS_REJECTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) pr_debug("%s: STATUS_REJECTED\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) case INTEL_SIP_SMC_STATUS_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) case INTEL_SIP_SMC_RSU_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) pr_err("%s: STATUS_ERROR\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) cbdata->status = BIT(SVC_STATUS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) cbdata->kaddr1 = &res.a1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) cbdata->kaddr2 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) cbdata->kaddr3 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) pdata->chan->scl->receive_cb(pdata->chan->scl, cbdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) pr_warn("Secure firmware doesn't support...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * be compatible with older version firmware which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * doesn't support RSU notify or retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if ((pdata->command == COMMAND_RSU_RETRY) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) (pdata->command == COMMAND_RSU_MAX_RETRY) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) (pdata->command == COMMAND_RSU_NOTIFY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) cbdata->status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) BIT(SVC_STATUS_NO_SUPPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) cbdata->kaddr1 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) cbdata->kaddr2 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) cbdata->kaddr3 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) pdata->chan->scl->receive_cb(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) pdata->chan->scl, cbdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) kfree(cbdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) kfree(pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * svc_normal_to_secure_shm_thread() - the function to run in the kthread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * @data: data pointer for kthread function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * Service layer driver creates stratix10_svc_smc_hvc_shm kthread on CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * node 0, its function stratix10_svc_secure_shm_thread is used to query the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * physical address of memory block reserved by secure monitor software at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * secure world.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * svc_normal_to_secure_shm_thread() calls do_exit() directly since it is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * standlone thread for which no one will call kthread_stop() or return when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * 'kthread_should_stop()' is true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) static int svc_normal_to_secure_shm_thread(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct stratix10_svc_sh_memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) *sh_mem = (struct stratix10_svc_sh_memory *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) struct arm_smccc_res res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) /* SMC or HVC call to get shared memory info from secure world */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) sh_mem->invoke_fn(INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 0, 0, 0, 0, 0, 0, 0, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (res.a0 == INTEL_SIP_SMC_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) sh_mem->addr = res.a1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) sh_mem->size = res.a2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) pr_err("%s: after SMC call -- res.a0=0x%016x", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) (unsigned int)res.a0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) sh_mem->addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) sh_mem->size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) complete(&sh_mem->sync_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) do_exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * svc_get_sh_memory() - get memory block reserved by secure monitor SW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * @pdev: pointer to service layer device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * @sh_memory: pointer to service shared memory structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * Return: zero for successfully getting the physical address of memory block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * reserved by secure monitor software, or negative value on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static int svc_get_sh_memory(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct stratix10_svc_sh_memory *sh_memory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct task_struct *sh_memory_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) unsigned int cpu = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) init_completion(&sh_memory->sync_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /* smc or hvc call happens on cpu 0 bound kthread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) sh_memory_task = kthread_create_on_node(svc_normal_to_secure_shm_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) (void *)sh_memory,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) cpu_to_node(cpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) "svc_smc_hvc_shm_thread");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (IS_ERR(sh_memory_task)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) dev_err(dev, "fail to create stratix10_svc_smc_shm_thread\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) wake_up_process(sh_memory_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (!wait_for_completion_timeout(&sh_memory->sync_complete, 10 * HZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) "timeout to get sh-memory paras from secure world\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (!sh_memory->addr || !sh_memory->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) "failed to get shared memory info from secure world\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) dev_dbg(dev, "SM software provides paddr: 0x%016x, size: 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) (unsigned int)sh_memory->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) (unsigned int)sh_memory->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) * svc_create_memory_pool() - create a memory pool from reserved memory block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) * @pdev: pointer to service layer device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) * @sh_memory: pointer to service shared memory structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) * Return: pool allocated from reserved memory block or ERR_PTR() on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static struct gen_pool *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) svc_create_memory_pool(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) struct stratix10_svc_sh_memory *sh_memory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct gen_pool *genpool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) unsigned long vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) phys_addr_t paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) phys_addr_t begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) phys_addr_t end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) void *va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) size_t page_mask = PAGE_SIZE - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) int min_alloc_order = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) begin = roundup(sh_memory->addr, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) end = rounddown(sh_memory->addr + sh_memory->size, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) paddr = begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) size = end - begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) va = memremap(paddr, size, MEMREMAP_WC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (!va) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) dev_err(dev, "fail to remap shared memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) vaddr = (unsigned long)va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) dev_dbg(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) "reserved memory vaddr: %p, paddr: 0x%16x size: 0x%8x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) va, (unsigned int)paddr, (unsigned int)size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if ((vaddr & page_mask) || (paddr & page_mask) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) (size & page_mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) dev_err(dev, "page is not aligned\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) genpool = gen_pool_create(min_alloc_order, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (!genpool) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) dev_err(dev, "fail to create genpool\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) gen_pool_set_algo(genpool, gen_pool_best_fit, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) ret = gen_pool_add_virt(genpool, vaddr, paddr, size, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) dev_err(dev, "fail to add memory chunk to the pool\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) gen_pool_destroy(genpool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) return genpool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) * svc_smccc_smc() - secure monitor call between normal and secure world
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * @a0: argument passed in registers 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * @a1: argument passed in registers 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) * @a2: argument passed in registers 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) * @a3: argument passed in registers 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) * @a4: argument passed in registers 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) * @a5: argument passed in registers 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * @a6: argument passed in registers 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * @a7: argument passed in registers 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * @res: result values from register 0 to 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) static void svc_smccc_smc(unsigned long a0, unsigned long a1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) unsigned long a2, unsigned long a3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) unsigned long a4, unsigned long a5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) unsigned long a6, unsigned long a7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) struct arm_smccc_res *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) arm_smccc_smc(a0, a1, a2, a3, a4, a5, a6, a7, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) * svc_smccc_hvc() - hypervisor call between normal and secure world
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * @a0: argument passed in registers 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) * @a1: argument passed in registers 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) * @a2: argument passed in registers 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) * @a3: argument passed in registers 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) * @a4: argument passed in registers 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) * @a5: argument passed in registers 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) * @a6: argument passed in registers 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) * @a7: argument passed in registers 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) * @res: result values from register 0 to 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) static void svc_smccc_hvc(unsigned long a0, unsigned long a1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) unsigned long a2, unsigned long a3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) unsigned long a4, unsigned long a5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) unsigned long a6, unsigned long a7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) struct arm_smccc_res *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) * get_invoke_func() - invoke SMC or HVC call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) * @dev: pointer to device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * Return: function pointer to svc_smccc_smc or svc_smccc_hvc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) static svc_invoke_fn *get_invoke_func(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) const char *method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) if (of_property_read_string(dev->of_node, "method", &method)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) dev_warn(dev, "missing \"method\" property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) return ERR_PTR(-ENXIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if (!strcmp(method, "smc"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) return svc_smccc_smc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (!strcmp(method, "hvc"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return svc_smccc_hvc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) dev_warn(dev, "invalid \"method\" property: %s\n", method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * stratix10_svc_request_channel_byname() - request a service channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) * @client: pointer to service client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) * @name: service client name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) * This function is used by service client to request a service channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) * Return: a pointer to channel assigned to the client on success,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * or ERR_PTR() on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) struct stratix10_svc_chan *stratix10_svc_request_channel_byname(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) struct stratix10_svc_client *client, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) struct device *dev = client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) struct stratix10_svc_controller *controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) struct stratix10_svc_chan *chan = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) unsigned long flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) /* if probe was called after client's, or error on probe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (list_empty(&svc_ctrl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) return ERR_PTR(-EPROBE_DEFER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) controller = list_first_entry(&svc_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) struct stratix10_svc_controller, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) for (i = 0; i < SVC_NUM_CHANNEL; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (!strcmp(controller->chans[i].name, name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) chan = &controller->chans[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) /* if there was no channel match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) if (i == SVC_NUM_CHANNEL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) dev_err(dev, "%s: channel not allocated\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) if (chan->scl || !try_module_get(controller->dev->driver->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) dev_dbg(dev, "%s: svc not free\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) return ERR_PTR(-EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) spin_lock_irqsave(&chan->lock, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) chan->scl = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) chan->ctrl->num_active_client++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) spin_unlock_irqrestore(&chan->lock, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) EXPORT_SYMBOL_GPL(stratix10_svc_request_channel_byname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) * stratix10_svc_free_channel() - free service channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * @chan: service channel to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * This function is used by service client to free a service channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) void stratix10_svc_free_channel(struct stratix10_svc_chan *chan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) unsigned long flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) spin_lock_irqsave(&chan->lock, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) chan->scl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) chan->ctrl->num_active_client--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) module_put(chan->ctrl->dev->driver->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) spin_unlock_irqrestore(&chan->lock, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) EXPORT_SYMBOL_GPL(stratix10_svc_free_channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * stratix10_svc_send() - send a message data to the remote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) * @chan: service channel assigned to the client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) * @msg: message data to be sent, in the format of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) * "struct stratix10_svc_client_msg"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) * This function is used by service client to add a message to the service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * layer driver's queue for being sent to the secure world.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * Return: 0 for success, -ENOMEM or -ENOBUFS on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) struct stratix10_svc_client_msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) *p_msg = (struct stratix10_svc_client_msg *)msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) struct stratix10_svc_data_mem *p_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) struct stratix10_svc_data *p_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) unsigned int cpu = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) p_data = kzalloc(sizeof(*p_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (!p_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) /* first client will create kernel thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) if (!chan->ctrl->task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) chan->ctrl->task =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) kthread_create_on_node(svc_normal_to_secure_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) (void *)chan->ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) cpu_to_node(cpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) "svc_smc_hvc_thread");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (IS_ERR(chan->ctrl->task)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) dev_err(chan->ctrl->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) "failed to create svc_smc_hvc_thread\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) kfree(p_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) kthread_bind(chan->ctrl->task, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) wake_up_process(chan->ctrl->task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) pr_debug("%s: sent P-va=%p, P-com=%x, P-size=%u\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) p_msg->payload, p_msg->command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) (unsigned int)p_msg->payload_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (list_empty(&svc_data_mem)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (p_msg->command == COMMAND_RECONFIG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) struct stratix10_svc_command_config_type *ct =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) (struct stratix10_svc_command_config_type *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) p_msg->payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) p_data->flag = ct->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) list_for_each_entry(p_mem, &svc_data_mem, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) if (p_mem->vaddr == p_msg->payload) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) p_data->paddr = p_mem->paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) p_data->command = p_msg->command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) p_data->arg[0] = p_msg->arg[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) p_data->arg[1] = p_msg->arg[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) p_data->arg[2] = p_msg->arg[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) p_data->size = p_msg->payload_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) p_data->chan = chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) pr_debug("%s: put to FIFO pa=0x%016x, cmd=%x, size=%u\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) (unsigned int)p_data->paddr, p_data->command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) (unsigned int)p_data->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) ret = kfifo_in_spinlocked(&chan->ctrl->svc_fifo, p_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) sizeof(*p_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) &chan->ctrl->svc_fifo_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) kfree(p_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) EXPORT_SYMBOL_GPL(stratix10_svc_send);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) * stratix10_svc_done() - complete service request transactions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) * @chan: service channel assigned to the client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * This function should be called when client has finished its request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) * or there is an error in the request process. It allows the service layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) * to stop the running thread to have maximize savings in kernel resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) void stratix10_svc_done(struct stratix10_svc_chan *chan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) /* stop thread when thread is running AND only one active client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) if (chan->ctrl->task && chan->ctrl->num_active_client <= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) pr_debug("svc_smc_hvc_shm_thread is stopped\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) kthread_stop(chan->ctrl->task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) chan->ctrl->task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) EXPORT_SYMBOL_GPL(stratix10_svc_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) * stratix10_svc_allocate_memory() - allocate memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) * @chan: service channel assigned to the client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) * @size: memory size requested by a specific service client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) * Service layer allocates the requested number of bytes buffer from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) * memory pool, service client uses this function to get allocated buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) * Return: address of allocated memory on success, or ERR_PTR() on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) struct stratix10_svc_data_mem *pmem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) unsigned long va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) phys_addr_t pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) struct gen_pool *genpool = chan->ctrl->genpool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) size_t s = roundup(size, 1 << genpool->min_alloc_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) pmem = devm_kzalloc(chan->ctrl->dev, sizeof(*pmem), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) if (!pmem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) va = gen_pool_alloc(genpool, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (!va)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) memset((void *)va, 0, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) pa = gen_pool_virt_to_phys(genpool, va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) pmem->vaddr = (void *)va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) pmem->paddr = pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) pmem->size = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) list_add_tail(&pmem->node, &svc_data_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) pr_debug("%s: va=%p, pa=0x%016x\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) pmem->vaddr, (unsigned int)pmem->paddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) return (void *)va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) * stratix10_svc_free_memory() - free allocated memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) * @chan: service channel assigned to the client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) * @kaddr: memory to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) * This function is used by service client to free allocated buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) struct stratix10_svc_data_mem *pmem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) size_t size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) list_for_each_entry(pmem, &svc_data_mem, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) if (pmem->vaddr == kaddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) size = pmem->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) gen_pool_free(chan->ctrl->genpool, (unsigned long)kaddr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) pmem->vaddr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) list_del(&pmem->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) EXPORT_SYMBOL_GPL(stratix10_svc_free_memory);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) static const struct of_device_id stratix10_svc_drv_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) {.compatible = "intel,stratix10-svc"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) {.compatible = "intel,agilex-svc"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) static int stratix10_svc_drv_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) struct stratix10_svc_controller *controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) struct stratix10_svc_chan *chans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) struct gen_pool *genpool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) struct stratix10_svc_sh_memory *sh_memory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) struct stratix10_svc *svc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) svc_invoke_fn *invoke_fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) size_t fifo_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) /* get SMC or HVC function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) invoke_fn = get_invoke_func(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) if (IS_ERR(invoke_fn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) sh_memory = devm_kzalloc(dev, sizeof(*sh_memory), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) if (!sh_memory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) sh_memory->invoke_fn = invoke_fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) ret = svc_get_sh_memory(pdev, sh_memory);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) genpool = svc_create_memory_pool(pdev, sh_memory);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) if (!genpool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) /* allocate service controller and supporting channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) if (!controller)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) chans = devm_kmalloc_array(dev, SVC_NUM_CHANNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) sizeof(*chans), GFP_KERNEL | __GFP_ZERO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (!chans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) controller->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) controller->num_chans = SVC_NUM_CHANNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) controller->num_active_client = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) controller->chans = chans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) controller->genpool = genpool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) controller->task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) controller->invoke_fn = invoke_fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) init_completion(&controller->complete_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) fifo_size = sizeof(struct stratix10_svc_data) * SVC_NUM_DATA_IN_FIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) ret = kfifo_alloc(&controller->svc_fifo, fifo_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) dev_err(dev, "failed to allocate FIFO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) spin_lock_init(&controller->svc_fifo_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) chans[0].scl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) chans[0].ctrl = controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) chans[0].name = SVC_CLIENT_FPGA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) spin_lock_init(&chans[0].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) chans[1].scl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) chans[1].ctrl = controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) chans[1].name = SVC_CLIENT_RSU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) spin_lock_init(&chans[1].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) list_add_tail(&controller->node, &svc_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) platform_set_drvdata(pdev, controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) /* add svc client device(s) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) svc = devm_kzalloc(dev, sizeof(*svc), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (!svc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) goto err_free_kfifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) svc->stratix10_svc_rsu = platform_device_alloc(STRATIX10_RSU, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (!svc->stratix10_svc_rsu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) dev_err(dev, "failed to allocate %s device\n", STRATIX10_RSU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) goto err_free_kfifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) ret = platform_device_add(svc->stratix10_svc_rsu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) goto err_put_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) dev_set_drvdata(dev, svc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) pr_info("Intel Service Layer Driver Initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) err_put_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) platform_device_put(svc->stratix10_svc_rsu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) err_free_kfifo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) kfifo_free(&controller->svc_fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) static int stratix10_svc_drv_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) struct stratix10_svc *svc = dev_get_drvdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) struct stratix10_svc_controller *ctrl = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) platform_device_unregister(svc->stratix10_svc_rsu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) kfifo_free(&ctrl->svc_fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) if (ctrl->task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) kthread_stop(ctrl->task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) ctrl->task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) if (ctrl->genpool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) gen_pool_destroy(ctrl->genpool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) list_del(&ctrl->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) static struct platform_driver stratix10_svc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) .probe = stratix10_svc_drv_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) .remove = stratix10_svc_drv_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) .name = "stratix10-svc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) .of_match_table = stratix10_svc_drv_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) static int __init stratix10_svc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) struct device_node *fw_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) fw_np = of_find_node_by_name(NULL, "firmware");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) if (!fw_np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) np = of_find_matching_node(fw_np, stratix10_svc_drv_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) ret = of_platform_populate(fw_np, stratix10_svc_drv_match, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) return platform_driver_register(&stratix10_svc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) static void __exit stratix10_svc_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) return platform_driver_unregister(&stratix10_svc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) subsys_initcall(stratix10_svc_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) module_exit(stratix10_svc_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) MODULE_DESCRIPTION("Intel Stratix10 Service Layer Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) MODULE_AUTHOR("Richard Gong <richard.gong@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) MODULE_ALIAS("platform:stratix10-svc");