4141#define RPM_GLINK_CID_MIN 1
4242#define RPM_GLINK_CID_MAX 65536
4343
44+ #define to_rpm_pipe (p ) container_of(p, struct glink_rpm_pipe, native)
45+
4446struct rpm_toc_entry {
4547 __le32 id ;
4648 __le32 offset ;
4749 __le32 size ;
4850} __packed ;
4951
52+ struct qcom_glink ;
53+
54+ struct qcom_glink_pipe {
55+ size_t length ;
56+
57+ size_t (* avail )(struct qcom_glink_pipe * glink_pipe );
58+ void (* peak )(struct qcom_glink_pipe * glink_pipe , void * data ,
59+ size_t count );
60+ void (* advance )(struct qcom_glink_pipe * glink_pipe , size_t count );
61+ void (* write )(struct qcom_glink_pipe * glink_pipe ,
62+ const void * hdr , size_t hlen ,
63+ const void * data , size_t dlen );
64+ };
65+
5066struct rpm_toc {
5167 __le32 magic ;
5268 __le32 count ;
@@ -62,12 +78,12 @@ struct glink_msg {
6278} __packed ;
6379
6480struct glink_rpm_pipe {
81+ struct qcom_glink_pipe native ;
82+
6583 void __iomem * tail ;
6684 void __iomem * head ;
6785
6886 void __iomem * fifo ;
69-
70- size_t length ;
7187};
7288
7389/**
@@ -107,8 +123,8 @@ struct qcom_glink {
107123 struct mbox_client mbox_client ;
108124 struct mbox_chan * mbox_chan ;
109125
110- struct glink_rpm_pipe rx_pipe ;
111- struct glink_rpm_pipe tx_pipe ;
126+ struct qcom_glink_pipe * rx_pipe ;
127+ struct qcom_glink_pipe * tx_pipe ;
112128
113129 int irq ;
114130
@@ -215,31 +231,36 @@ static void qcom_glink_channel_release(struct kref *ref)
215231 kfree (channel );
216232}
217233
218- static size_t qcom_glink_rx_avail (struct qcom_glink * glink )
234+ static size_t glink_rpm_rx_avail (struct qcom_glink_pipe * glink_pipe )
219235{
220- struct glink_rpm_pipe * pipe = & glink -> rx_pipe ;
236+ struct glink_rpm_pipe * pipe = to_rpm_pipe ( glink_pipe ) ;
221237 unsigned int head ;
222238 unsigned int tail ;
223239
224240 head = readl (pipe -> head );
225241 tail = readl (pipe -> tail );
226242
227243 if (head < tail )
228- return pipe -> length - tail + head ;
244+ return pipe -> native . length - tail + head ;
229245 else
230246 return head - tail ;
231247}
232248
233- static void qcom_glink_rx_peak (struct qcom_glink * glink ,
234- void * data , size_t count )
249+ static size_t qcom_glink_rx_avail (struct qcom_glink * glink )
250+ {
251+ return glink -> rx_pipe -> avail (glink -> rx_pipe );
252+ }
253+
254+ static void glink_rpm_rx_peak (struct qcom_glink_pipe * glink_pipe ,
255+ void * data , size_t count )
235256{
236- struct glink_rpm_pipe * pipe = & glink -> rx_pipe ;
257+ struct glink_rpm_pipe * pipe = to_rpm_pipe ( glink_pipe ) ;
237258 unsigned int tail ;
238259 size_t len ;
239260
240261 tail = readl (pipe -> tail );
241262
242- len = min_t (size_t , count , pipe -> length - tail );
263+ len = min_t (size_t , count , pipe -> native . length - tail );
243264 if (len ) {
244265 __ioread32_copy (data , pipe -> fifo + tail ,
245266 len / sizeof (u32 ));
@@ -251,44 +272,59 @@ static void qcom_glink_rx_peak(struct qcom_glink *glink,
251272 }
252273}
253274
254- static void qcom_glink_rx_advance (struct qcom_glink * glink ,
255- size_t count )
275+ static void qcom_glink_rx_peak (struct qcom_glink * glink ,
276+ void * data , size_t count )
256277{
257- struct glink_rpm_pipe * pipe = & glink -> rx_pipe ;
278+ glink -> rx_pipe -> peak (glink -> rx_pipe , data , count );
279+ }
280+
281+ static void glink_rpm_rx_advance (struct qcom_glink_pipe * glink_pipe ,
282+ size_t count )
283+ {
284+ struct glink_rpm_pipe * pipe = to_rpm_pipe (glink_pipe );
258285 unsigned int tail ;
259286
260287 tail = readl (pipe -> tail );
261288
262289 tail += count ;
263- if (tail >= pipe -> length )
264- tail -= pipe -> length ;
290+ if (tail >= pipe -> native . length )
291+ tail -= pipe -> native . length ;
265292
266293 writel (tail , pipe -> tail );
267294}
268295
269- static size_t qcom_glink_tx_avail (struct qcom_glink * glink )
296+ static void qcom_glink_rx_advance (struct qcom_glink * glink , size_t count )
297+ {
298+ glink -> rx_pipe -> advance (glink -> rx_pipe , count );
299+ }
300+
301+ static size_t glink_rpm_tx_avail (struct qcom_glink_pipe * glink_pipe )
270302{
271- struct glink_rpm_pipe * pipe = & glink -> tx_pipe ;
303+ struct glink_rpm_pipe * pipe = to_rpm_pipe ( glink_pipe ) ;
272304 unsigned int head ;
273305 unsigned int tail ;
274306
275307 head = readl (pipe -> head );
276308 tail = readl (pipe -> tail );
277309
278310 if (tail <= head )
279- return pipe -> length - head + tail ;
311+ return pipe -> native . length - head + tail ;
280312 else
281313 return tail - head ;
282314}
283315
284- static unsigned int qcom_glink_tx_write (struct qcom_glink * glink ,
285- unsigned int head ,
286- const void * data , size_t count )
316+ static size_t qcom_glink_tx_avail (struct qcom_glink * glink )
317+ {
318+ return glink -> tx_pipe -> avail (glink -> tx_pipe );
319+ }
320+
321+ static unsigned int glink_rpm_tx_write_one (struct glink_rpm_pipe * pipe ,
322+ unsigned int head ,
323+ const void * data , size_t count )
287324{
288- struct glink_rpm_pipe * pipe = & glink -> tx_pipe ;
289325 size_t len ;
290326
291- len = min_t (size_t , count , pipe -> length - head );
327+ len = min_t (size_t , count , pipe -> native . length - head );
292328 if (len ) {
293329 __iowrite32_copy (pipe -> fifo + head , data ,
294330 len / sizeof (u32 ));
@@ -300,23 +336,41 @@ static unsigned int qcom_glink_tx_write(struct qcom_glink *glink,
300336 }
301337
302338 head += count ;
303- if (head >= pipe -> length )
304- head -= pipe -> length ;
339+ if (head >= pipe -> native . length )
340+ head -= pipe -> native . length ;
305341
306342 return head ;
307343}
308344
345+ static void glink_rpm_tx_write (struct qcom_glink_pipe * glink_pipe ,
346+ const void * hdr , size_t hlen ,
347+ const void * data , size_t dlen )
348+ {
349+ struct glink_rpm_pipe * pipe = to_rpm_pipe (glink_pipe );
350+ unsigned int head ;
351+
352+ head = readl (pipe -> head );
353+ head = glink_rpm_tx_write_one (pipe , head , hdr , hlen );
354+ head = glink_rpm_tx_write_one (pipe , head , data , dlen );
355+ writel (head , pipe -> head );
356+ }
357+
358+ static void qcom_glink_tx_write (struct qcom_glink * glink ,
359+ const void * hdr , size_t hlen ,
360+ const void * data , size_t dlen )
361+ {
362+ glink -> tx_pipe -> write (glink -> tx_pipe , hdr , hlen , data , dlen );
363+ }
364+
309365static int qcom_glink_tx (struct qcom_glink * glink ,
310366 const void * hdr , size_t hlen ,
311367 const void * data , size_t dlen , bool wait )
312368{
313- struct glink_rpm_pipe * pipe = & glink -> tx_pipe ;
314- unsigned int head ;
315369 unsigned int tlen = hlen + dlen ;
316370 int ret ;
317371
318372 /* Reject packets that are too big */
319- if (tlen >= glink -> tx_pipe . length )
373+ if (tlen >= glink -> tx_pipe -> length )
320374 return - EINVAL ;
321375
322376 if (WARN (tlen % 8 , "Unaligned TX request" ))
@@ -335,10 +389,7 @@ static int qcom_glink_tx(struct qcom_glink *glink,
335389 msleep (10 );
336390 }
337391
338- head = readl (pipe -> head );
339- head = qcom_glink_tx_write (glink , head , hdr , hlen );
340- head = qcom_glink_tx_write (glink , head , data , dlen );
341- writel (head , pipe -> head );
392+ qcom_glink_tx_write (glink , hdr , hlen , data , dlen );
342393
343394 mbox_send_message (glink -> mbox_chan , NULL );
344395 mbox_client_txdone (glink -> mbox_chan , 0 );
@@ -1075,14 +1126,14 @@ static int glink_rpm_parse_toc(struct device *dev,
10751126
10761127 switch (id ) {
10771128 case RPM_RX_FIFO_ID :
1078- rx -> length = size ;
1129+ rx -> native . length = size ;
10791130
10801131 rx -> tail = msg_ram + offset ;
10811132 rx -> head = msg_ram + offset + sizeof (u32 );
10821133 rx -> fifo = msg_ram + offset + 2 * sizeof (u32 );
10831134 break ;
10841135 case RPM_TX_FIFO_ID :
1085- tx -> length = size ;
1136+ tx -> native . length = size ;
10861137
10871138 tx -> tail = msg_ram + offset ;
10881139 tx -> head = msg_ram + offset + sizeof (u32 );
@@ -1107,6 +1158,8 @@ static int glink_rpm_parse_toc(struct device *dev,
11071158static int glink_rpm_probe (struct platform_device * pdev )
11081159{
11091160 struct qcom_glink * glink ;
1161+ struct glink_rpm_pipe * rx_pipe ;
1162+ struct glink_rpm_pipe * tx_pipe ;
11101163 struct device_node * np ;
11111164 void __iomem * msg_ram ;
11121165 size_t msg_ram_size ;
@@ -1121,6 +1174,11 @@ static int glink_rpm_probe(struct platform_device *pdev)
11211174
11221175 glink -> dev = dev ;
11231176
1177+ rx_pipe = devm_kzalloc (& pdev -> dev , sizeof (* rx_pipe ), GFP_KERNEL );
1178+ tx_pipe = devm_kzalloc (& pdev -> dev , sizeof (* tx_pipe ), GFP_KERNEL );
1179+ if (!rx_pipe || !tx_pipe )
1180+ return - ENOMEM ;
1181+
11241182 mutex_init (& glink -> tx_lock );
11251183 spin_lock_init (& glink -> rx_lock );
11261184 INIT_LIST_HEAD (& glink -> rx_queue );
@@ -1150,12 +1208,22 @@ static int glink_rpm_probe(struct platform_device *pdev)
11501208 return - ENOMEM ;
11511209
11521210 ret = glink_rpm_parse_toc (dev , msg_ram , msg_ram_size ,
1153- & glink -> rx_pipe , & glink -> tx_pipe );
1211+ rx_pipe , tx_pipe );
11541212 if (ret )
11551213 return ret ;
11561214
1157- writel (0 , glink -> tx_pipe .head );
1158- writel (0 , glink -> rx_pipe .tail );
1215+ /* Pipe specific accessors */
1216+ rx_pipe -> native .avail = glink_rpm_rx_avail ;
1217+ rx_pipe -> native .peak = glink_rpm_rx_peak ;
1218+ rx_pipe -> native .advance = glink_rpm_rx_advance ;
1219+ tx_pipe -> native .avail = glink_rpm_tx_avail ;
1220+ tx_pipe -> native .write = glink_rpm_tx_write ;
1221+
1222+ glink -> tx_pipe = & tx_pipe -> native ;
1223+ glink -> rx_pipe = & rx_pipe -> native ;
1224+
1225+ writel (0 , tx_pipe -> head );
1226+ writel (0 , rx_pipe -> tail );
11591227
11601228 irq = platform_get_irq (pdev , 0 );
11611229 ret = devm_request_irq (dev , irq ,
0 commit comments