1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef _MIC_DEVICE_H_
22#define _MIC_DEVICE_H_
23
24#include <linux/cdev.h>
25#include <linux/idr.h>
26#include <linux/notifier.h>
27#include <linux/irqreturn.h>
28#include <linux/dmaengine.h>
29#include <linux/mic_bus.h>
30
31#include "mic_intr.h"
32
33
34#define MIC_MAX_NUM_DEVS 256
35
36
37
38
39enum mic_hw_family {
40 MIC_FAMILY_X100 = 0,
41 MIC_FAMILY_UNKNOWN
42};
43
44
45
46
47enum mic_stepping {
48 MIC_A0_STEP = 0x0,
49 MIC_B0_STEP = 0x10,
50 MIC_B1_STEP = 0x11,
51 MIC_C0_STEP = 0x20,
52};
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95struct mic_device {
96 struct mic_mw mmio;
97 struct mic_mw aper;
98 enum mic_hw_family family;
99 struct mic_hw_ops *ops;
100 int id;
101 enum mic_stepping stepping;
102 const struct attribute_group **attr_group;
103 struct device *sdev;
104 struct mutex mic_mutex;
105 struct mic_hw_intr_ops *intr_ops;
106 struct mic_smpt_ops *smpt_ops;
107 struct mic_smpt_info *smpt;
108 struct mic_intr_info *intr_info;
109 struct mic_irq_info irq_info;
110 struct dentry *dbg_dir;
111 char *cmdline;
112 char *firmware;
113 char *ramdisk;
114 char *bootmode;
115 u32 bootaddr;
116 struct work_struct reset_trigger_work;
117 struct work_struct shutdown_work;
118 u8 state;
119 u8 shutdown_status;
120 struct kernfs_node *state_sysfs;
121 struct completion reset_wait;
122 void *log_buf_addr;
123 int *log_buf_len;
124 void *dp;
125 dma_addr_t dp_dma_addr;
126 int shutdown_db;
127 struct mic_irq *shutdown_cookie;
128 struct cdev cdev;
129 struct list_head vdev_list;
130 struct notifier_block pm_notifier;
131 struct mbus_device *dma_mbdev;
132 struct dma_chan *dma_ch;
133};
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155struct mic_hw_ops {
156 u8 aper_bar;
157 u8 mmio_bar;
158 u32 (*read_spad)(struct mic_device *mdev, unsigned int idx);
159 void (*write_spad)(struct mic_device *mdev, unsigned int idx, u32 val);
160 void (*send_intr)(struct mic_device *mdev, int doorbell);
161 u32 (*ack_interrupt)(struct mic_device *mdev);
162 void (*intr_workarounds)(struct mic_device *mdev);
163 void (*reset)(struct mic_device *mdev);
164 void (*reset_fw_ready)(struct mic_device *mdev);
165 bool (*is_fw_ready)(struct mic_device *mdev);
166 void (*send_firmware_intr)(struct mic_device *mdev);
167 int (*load_mic_fw)(struct mic_device *mdev, const char *buf);
168 u32 (*get_postcode)(struct mic_device *mdev);
169 bool (*dma_filter)(struct dma_chan *chan, void *param);
170};
171
172
173
174
175
176
177
178
179static inline u32 mic_mmio_read(struct mic_mw *mw, u32 offset)
180{
181 return ioread32(mw->va + offset);
182}
183
184
185
186
187
188
189
190
191
192static inline void
193mic_mmio_write(struct mic_mw *mw, u32 val, u32 offset)
194{
195 iowrite32(val, mw->va + offset);
196}
197
198static inline struct dma_chan *mic_request_dma_chan(struct mic_device *mdev)
199{
200 dma_cap_mask_t mask;
201 struct dma_chan *chan;
202
203 dma_cap_zero(mask);
204 dma_cap_set(DMA_MEMCPY, mask);
205 chan = dma_request_channel(mask, mdev->ops->dma_filter,
206 mdev->sdev->parent);
207 if (chan)
208 return chan;
209 dev_err(mdev->sdev->parent, "%s %d unable to acquire channel\n",
210 __func__, __LINE__);
211 return NULL;
212}
213
214void mic_sysfs_init(struct mic_device *mdev);
215int mic_start(struct mic_device *mdev, const char *buf);
216void mic_stop(struct mic_device *mdev, bool force);
217void mic_shutdown(struct mic_device *mdev);
218void mic_reset_delayed_work(struct work_struct *work);
219void mic_reset_trigger_work(struct work_struct *work);
220void mic_shutdown_work(struct work_struct *work);
221void mic_bootparam_init(struct mic_device *mdev);
222void mic_set_state(struct mic_device *mdev, u8 state);
223void mic_set_shutdown_status(struct mic_device *mdev, u8 status);
224void mic_create_debug_dir(struct mic_device *dev);
225void mic_delete_debug_dir(struct mic_device *dev);
226void __init mic_init_debugfs(void);
227void mic_exit_debugfs(void);
228void mic_prepare_suspend(struct mic_device *mdev);
229void mic_complete_resume(struct mic_device *mdev);
230void mic_suspend(struct mic_device *mdev);
231#endif
232