1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */ 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. 4*4882a593Smuzhiyun * Copyright (C) 2018-2020 Linaro Ltd. 5*4882a593Smuzhiyun */ 6*4882a593Smuzhiyun #ifndef _IPA_H_ 7*4882a593Smuzhiyun #define _IPA_H_ 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun #include <linux/types.h> 10*4882a593Smuzhiyun #include <linux/device.h> 11*4882a593Smuzhiyun #include <linux/notifier.h> 12*4882a593Smuzhiyun #include <linux/pm_wakeup.h> 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun #include "ipa_version.h" 15*4882a593Smuzhiyun #include "gsi.h" 16*4882a593Smuzhiyun #include "ipa_mem.h" 17*4882a593Smuzhiyun #include "ipa_qmi.h" 18*4882a593Smuzhiyun #include "ipa_endpoint.h" 19*4882a593Smuzhiyun #include "ipa_interrupt.h" 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun struct clk; 22*4882a593Smuzhiyun struct icc_path; 23*4882a593Smuzhiyun struct net_device; 24*4882a593Smuzhiyun struct platform_device; 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun struct ipa_clock; 27*4882a593Smuzhiyun struct ipa_smp2p; 28*4882a593Smuzhiyun struct ipa_interrupt; 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun /** 31*4882a593Smuzhiyun * enum ipa_flag - IPA state flags 32*4882a593Smuzhiyun * @IPA_FLAG_RESUMED: Whether resume from suspend has been signaled 33*4882a593Smuzhiyun * @IPA_FLAG_COUNT: Number of defined IPA flags 34*4882a593Smuzhiyun */ 35*4882a593Smuzhiyun enum ipa_flag { 36*4882a593Smuzhiyun IPA_FLAG_RESUMED, 37*4882a593Smuzhiyun IPA_FLAG_COUNT, /* Last; not a flag */ 38*4882a593Smuzhiyun }; 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun /** 41*4882a593Smuzhiyun * struct ipa - IPA information 42*4882a593Smuzhiyun * @gsi: Embedded GSI structure 43*4882a593Smuzhiyun * @flags: Boolean state flags 44*4882a593Smuzhiyun * @version: IPA hardware version 45*4882a593Smuzhiyun * @pdev: Platform device 46*4882a593Smuzhiyun * @modem_rproc: Remoteproc handle for modem subsystem 47*4882a593Smuzhiyun * @smp2p: SMP2P information 48*4882a593Smuzhiyun * @clock: IPA clocking information 49*4882a593Smuzhiyun * @table_addr: DMA address of filter/route table content 50*4882a593Smuzhiyun * @table_virt: Virtual address of filter/route table content 51*4882a593Smuzhiyun * @interrupt: IPA Interrupt information 52*4882a593Smuzhiyun * @uc_loaded: true after microcontroller has reported it's ready 53*4882a593Smuzhiyun * @reg_addr: DMA address used for IPA register access 54*4882a593Smuzhiyun * @reg_virt: Virtual address used for IPA register access 55*4882a593Smuzhiyun * @mem_addr: DMA address of IPA-local memory space 56*4882a593Smuzhiyun * @mem_virt: Virtual address of IPA-local memory space 57*4882a593Smuzhiyun * @mem_offset: Offset from @mem_virt used for access to IPA memory 58*4882a593Smuzhiyun * @mem_size: Total size (bytes) of memory at @mem_virt 59*4882a593Smuzhiyun * @mem_count: Number of entries in the mem array 60*4882a593Smuzhiyun * @mem: Array of IPA-local memory region descriptors 61*4882a593Smuzhiyun * @imem_iova: I/O virtual address of IPA region in IMEM 62*4882a593Smuzhiyun * @imem_size; Size of IMEM region 63*4882a593Smuzhiyun * @smem_iova: I/O virtual address of IPA region in SMEM 64*4882a593Smuzhiyun * @smem_size; Size of SMEM region 65*4882a593Smuzhiyun * @zero_addr: DMA address of preallocated zero-filled memory 66*4882a593Smuzhiyun * @zero_virt: Virtual address of preallocated zero-filled memory 67*4882a593Smuzhiyun * @zero_size: Size (bytes) of preallocated zero-filled memory 68*4882a593Smuzhiyun * @wakeup_source: Wakeup source information 69*4882a593Smuzhiyun * @available: Bit mask indicating endpoints hardware supports 70*4882a593Smuzhiyun * @filter_map: Bit mask indicating endpoints that support filtering 71*4882a593Smuzhiyun * @initialized: Bit mask indicating endpoints initialized 72*4882a593Smuzhiyun * @set_up: Bit mask indicating endpoints set up 73*4882a593Smuzhiyun * @enabled: Bit mask indicating endpoints enabled 74*4882a593Smuzhiyun * @endpoint: Array of endpoint information 75*4882a593Smuzhiyun * @channel_map: Mapping of GSI channel to IPA endpoint 76*4882a593Smuzhiyun * @name_map: Mapping of IPA endpoint name to IPA endpoint 77*4882a593Smuzhiyun * @setup_complete: Flag indicating whether setup stage has completed 78*4882a593Smuzhiyun * @modem_state: State of modem (stopped, running) 79*4882a593Smuzhiyun * @modem_netdev: Network device structure used for modem 80*4882a593Smuzhiyun * @qmi: QMI information 81*4882a593Smuzhiyun */ 82*4882a593Smuzhiyun struct ipa { 83*4882a593Smuzhiyun struct gsi gsi; 84*4882a593Smuzhiyun DECLARE_BITMAP(flags, IPA_FLAG_COUNT); 85*4882a593Smuzhiyun enum ipa_version version; 86*4882a593Smuzhiyun struct platform_device *pdev; 87*4882a593Smuzhiyun struct rproc *modem_rproc; 88*4882a593Smuzhiyun struct notifier_block nb; 89*4882a593Smuzhiyun void *notifier; 90*4882a593Smuzhiyun struct ipa_smp2p *smp2p; 91*4882a593Smuzhiyun struct ipa_clock *clock; 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun dma_addr_t table_addr; 94*4882a593Smuzhiyun __le64 *table_virt; 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun struct ipa_interrupt *interrupt; 97*4882a593Smuzhiyun bool uc_loaded; 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun dma_addr_t reg_addr; 100*4882a593Smuzhiyun void __iomem *reg_virt; 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun dma_addr_t mem_addr; 103*4882a593Smuzhiyun void *mem_virt; 104*4882a593Smuzhiyun u32 mem_offset; 105*4882a593Smuzhiyun u32 mem_size; 106*4882a593Smuzhiyun u32 mem_count; 107*4882a593Smuzhiyun const struct ipa_mem *mem; 108*4882a593Smuzhiyun 109*4882a593Smuzhiyun unsigned long imem_iova; 110*4882a593Smuzhiyun size_t imem_size; 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun unsigned long smem_iova; 113*4882a593Smuzhiyun size_t smem_size; 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun dma_addr_t zero_addr; 116*4882a593Smuzhiyun void *zero_virt; 117*4882a593Smuzhiyun size_t zero_size; 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun /* Bit masks indicating endpoint state */ 120*4882a593Smuzhiyun u32 available; /* supported by hardware */ 121*4882a593Smuzhiyun u32 filter_map; 122*4882a593Smuzhiyun u32 initialized; 123*4882a593Smuzhiyun u32 set_up; 124*4882a593Smuzhiyun u32 enabled; 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun struct ipa_endpoint endpoint[IPA_ENDPOINT_MAX]; 127*4882a593Smuzhiyun struct ipa_endpoint *channel_map[GSI_CHANNEL_COUNT_MAX]; 128*4882a593Smuzhiyun struct ipa_endpoint *name_map[IPA_ENDPOINT_COUNT]; 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun bool setup_complete; 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun atomic_t modem_state; /* enum ipa_modem_state */ 133*4882a593Smuzhiyun struct net_device *modem_netdev; 134*4882a593Smuzhiyun struct ipa_qmi qmi; 135*4882a593Smuzhiyun }; 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun /** 138*4882a593Smuzhiyun * ipa_setup() - Perform IPA setup 139*4882a593Smuzhiyun * @ipa: IPA pointer 140*4882a593Smuzhiyun * 141*4882a593Smuzhiyun * IPA initialization is broken into stages: init; config; and setup. 142*4882a593Smuzhiyun * (These have inverses exit, deconfig, and teardown.) 143*4882a593Smuzhiyun * 144*4882a593Smuzhiyun * Activities performed at the init stage can be done without requiring 145*4882a593Smuzhiyun * any access to IPA hardware. Activities performed at the config stage 146*4882a593Smuzhiyun * require the IPA clock to be running, because they involve access 147*4882a593Smuzhiyun * to IPA registers. The setup stage is performed only after the GSI 148*4882a593Smuzhiyun * hardware is ready (more on this below). The setup stage allows 149*4882a593Smuzhiyun * the AP to perform more complex initialization by issuing "immediate 150*4882a593Smuzhiyun * commands" using a special interface to the IPA. 151*4882a593Smuzhiyun * 152*4882a593Smuzhiyun * This function, @ipa_setup(), starts the setup stage. 153*4882a593Smuzhiyun * 154*4882a593Smuzhiyun * In order for the GSI hardware to be functional it needs firmware to be 155*4882a593Smuzhiyun * loaded (in addition to some other low-level initialization). This early 156*4882a593Smuzhiyun * GSI initialization can be done either by Trust Zone on the AP or by the 157*4882a593Smuzhiyun * modem. 158*4882a593Smuzhiyun * 159*4882a593Smuzhiyun * If it's done by Trust Zone, the AP loads the GSI firmware and supplies 160*4882a593Smuzhiyun * it to Trust Zone to verify and install. When this completes, if 161*4882a593Smuzhiyun * verification was successful, the GSI layer is ready and ipa_setup() 162*4882a593Smuzhiyun * implements the setup phase of initialization. 163*4882a593Smuzhiyun * 164*4882a593Smuzhiyun * If the modem performs early GSI initialization, the AP needs to know 165*4882a593Smuzhiyun * when this has occurred. An SMP2P interrupt is used for this purpose, 166*4882a593Smuzhiyun * and receipt of that interrupt triggers the call to ipa_setup(). 167*4882a593Smuzhiyun */ 168*4882a593Smuzhiyun int ipa_setup(struct ipa *ipa); 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun #endif /* _IPA_H_ */ 171