Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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