blob: f30f2035b2fce1740680c992c1ade0966e37bc6c [file] [log] [blame]
Ghanim Fodi859783a2018-10-28 18:26:33 +02001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
4 */
5
6#ifndef IPA_MHI_H_
7#define IPA_MHI_H_
8
9#include <linux/ipa.h>
10#include <linux/types.h>
11
12/**
13 * enum ipa_mhi_event_type - event type for mhi callback
14 *
15 * @IPA_MHI_EVENT_READY: IPA MHI is ready and IPA uC is loaded. After getting
16 * this event MHI client is expected to call to ipa_mhi_start() API
17 * @IPA_MHI_EVENT_DATA_AVAILABLE: downlink data available on MHI channel
18 */
19enum ipa_mhi_event_type {
20 IPA_MHI_EVENT_READY,
21 IPA_MHI_EVENT_DATA_AVAILABLE,
22 IPA_MHI_EVENT_MAX,
23};
24
25typedef void (*mhi_client_cb)(void *priv, enum ipa_mhi_event_type event,
26 unsigned long data);
27
28/**
29 * struct ipa_mhi_msi_info - parameters for MSI (Message Signaled Interrupts)
30 * @addr_low: MSI lower base physical address
31 * @addr_hi: MSI higher base physical address
32 * @data: Data Pattern to use when generating the MSI
33 * @mask: Mask indicating number of messages assigned by the host to device
34 *
35 * msi value is written according to this formula:
36 * ((data & ~mask) | (mmio.msiVec & mask))
37 */
38struct ipa_mhi_msi_info {
39 u32 addr_low;
40 u32 addr_hi;
41 u32 data;
42 u32 mask;
43};
44
45/**
46 * struct ipa_mhi_init_params - parameters for IPA MHI initialization API
47 *
48 * @msi: MSI (Message Signaled Interrupts) parameters
49 * @mmio_addr: MHI MMIO physical address
50 * @first_ch_idx: First channel ID for hardware accelerated channels.
51 * @first_er_idx: First event ring ID for hardware accelerated channels.
52 * @assert_bit40: should assert bit 40 in order to access host space.
53 * if PCIe iATU is configured then not need to assert bit40
54 * @notify: client callback
55 * @priv: client private data to be provided in client callback
56 * @test_mode: flag to indicate if IPA MHI is in unit test mode
57 */
58struct ipa_mhi_init_params {
59 struct ipa_mhi_msi_info msi;
60 u32 mmio_addr;
61 u32 first_ch_idx;
62 u32 first_er_idx;
63 bool assert_bit40;
64 mhi_client_cb notify;
65 void *priv;
66 bool test_mode;
67};
68
69/**
70 * struct ipa_mhi_start_params - parameters for IPA MHI start API
71 *
72 * @host_ctrl_addr: Base address of MHI control data structures
73 * @host_data_addr: Base address of MHI data buffers
74 * @channel_context_addr: channel context array address in host address space
75 * @event_context_addr: event context array address in host address space
76 */
77struct ipa_mhi_start_params {
78 u32 host_ctrl_addr;
79 u32 host_data_addr;
80 u64 channel_context_array_addr;
81 u64 event_context_array_addr;
82};
83
84/**
85 * struct ipa_mhi_connect_params - parameters for IPA MHI channel connect API
86 *
87 * @sys: IPA EP configuration info
88 * @channel_id: MHI channel id
89 */
90struct ipa_mhi_connect_params {
91 struct ipa_sys_connect_params sys;
92 u8 channel_id;
93};
94
95/* bit #40 in address should be asserted for MHI transfers over pcie */
96#define IPA_MHI_HOST_ADDR(addr) ((addr) | BIT_ULL(40))
97
98#if defined CONFIG_IPA || defined CONFIG_IPA3
99
100int ipa_mhi_init(struct ipa_mhi_init_params *params);
101
102int ipa_mhi_start(struct ipa_mhi_start_params *params);
103
104int ipa_mhi_connect_pipe(struct ipa_mhi_connect_params *in, u32 *clnt_hdl);
105
106int ipa_mhi_disconnect_pipe(u32 clnt_hdl);
107
108int ipa_mhi_suspend(bool force);
109
110int ipa_mhi_resume(void);
111
112void ipa_mhi_destroy(void);
113
114#else /* (CONFIG_IPA || CONFIG_IPA3) */
115
116static inline int ipa_mhi_init(struct ipa_mhi_init_params *params)
117{
118 return -EPERM;
119}
120
121static inline int ipa_mhi_start(struct ipa_mhi_start_params *params)
122{
123 return -EPERM;
124}
125
126static inline int ipa_mhi_connect_pipe(struct ipa_mhi_connect_params *in,
127 u32 *clnt_hdl)
128{
129 return -EPERM;
130}
131
132static inline int ipa_mhi_disconnect_pipe(u32 clnt_hdl)
133{
134 return -EPERM;
135}
136
137static inline int ipa_mhi_suspend(bool force)
138{
139 return -EPERM;
140}
141
142static inline int ipa_mhi_resume(void)
143{
144 return -EPERM;
145}
146
147static inline void ipa_mhi_destroy(void)
148{
149
150}
151
152#endif /* (CONFIG_IPA || CONFIG_IPA3) */
153
154#endif /* IPA_MHI_H_ */