1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel MIC Platform Software Stack (MPSS)
5 * Copyright(c) 2014 Intel Corporation.
7 * Intel MIC X100 DMA Driver.
9 * Adapted from IOAT dma driver.
11 #include <linux/module.h>
13 #include <linux/seq_file.h>
14 #include <linux/vmalloc.h>
16 #include "mic_x100_dma.h"
18 #define MIC_DMA_MAX_XFER_SIZE_CARD (1 * 1024 * 1024 -\
20 #define MIC_DMA_MAX_XFER_SIZE_HOST (1 * 1024 * 1024 >> 1)
21 #define MIC_DMA_DESC_TYPE_SHIFT 60
22 #define MIC_DMA_MEMCPY_LEN_SHIFT 46
23 #define MIC_DMA_STAT_INTR_SHIFT 59
25 /* high-water mark for pushing dma descriptors */
26 static int mic_dma_pending_level
= 4;
28 /* Status descriptor is used to write a 64 bit value to a memory location */
29 enum mic_dma_desc_format_type
{
34 static inline u32
mic_dma_hw_ring_inc(u32 val
)
36 return (val
+ 1) % MIC_DMA_DESC_RX_SIZE
;
39 static inline u32
mic_dma_hw_ring_dec(u32 val
)
41 return val
? val
- 1 : MIC_DMA_DESC_RX_SIZE
- 1;
44 static inline void mic_dma_hw_ring_inc_head(struct mic_dma_chan
*ch
)
46 ch
->head
= mic_dma_hw_ring_inc(ch
->head
);
49 /* Prepare a memcpy desc */
50 static inline void mic_dma_memcpy_desc(struct mic_dma_desc
*desc
,
51 dma_addr_t src_phys
, dma_addr_t dst_phys
, u64 size
)
56 qw0
|= (size
>> MIC_DMA_ALIGN_SHIFT
) << MIC_DMA_MEMCPY_LEN_SHIFT
;
58 qw1
<<= MIC_DMA_DESC_TYPE_SHIFT
;
64 /* Prepare a status desc. with @data to be written at @dst_phys */
65 static inline void mic_dma_prep_status_desc(struct mic_dma_desc
*desc
, u64 data
,
66 dma_addr_t dst_phys
, bool generate_intr
)
71 qw1
= (u64
) MIC_DMA_STATUS
<< MIC_DMA_DESC_TYPE_SHIFT
| dst_phys
;
73 qw1
|= (1ULL << MIC_DMA_STAT_INTR_SHIFT
);
78 static void mic_dma_cleanup(struct mic_dma_chan
*ch
)
80 struct dma_async_tx_descriptor
*tx
;
84 spin_lock(&ch
->cleanup_lock
);
85 tail
= mic_dma_read_cmp_cnt(ch
);
87 * This is the barrier pair for smp_wmb() in fn.
88 * mic_dma_tx_submit_unlock. It's required so that we read the
89 * updated cookie value from tx->cookie.
92 for (last_tail
= ch
->last_tail
; tail
!= last_tail
;) {
93 tx
= &ch
->tx_array
[last_tail
];
95 dma_cookie_complete(tx
);
96 dmaengine_desc_get_callback_invoke(tx
, NULL
);
99 last_tail
= mic_dma_hw_ring_inc(last_tail
);
101 /* finish all completion callbacks before incrementing tail */
103 ch
->last_tail
= last_tail
;
104 spin_unlock(&ch
->cleanup_lock
);
107 static u32
mic_dma_ring_count(u32 head
, u32 tail
)
112 count
= (tail
- 0) + (MIC_DMA_DESC_RX_SIZE
- head
);
118 /* Returns the num. of free descriptors on success, -ENOMEM on failure */
119 static int mic_dma_avail_desc_ring_space(struct mic_dma_chan
*ch
, int required
)
121 struct device
*dev
= mic_dma_ch_to_device(ch
);
124 count
= mic_dma_ring_count(ch
->head
, ch
->last_tail
);
125 if (count
< required
) {
127 count
= mic_dma_ring_count(ch
->head
, ch
->last_tail
);
130 if (count
< required
) {
131 dev_dbg(dev
, "Not enough desc space");
132 dev_dbg(dev
, "%s %d required=%u, avail=%u\n",
133 __func__
, __LINE__
, required
, count
);
140 /* Program memcpy descriptors into the descriptor ring and update s/w head ptr*/
141 static int mic_dma_prog_memcpy_desc(struct mic_dma_chan
*ch
, dma_addr_t src
,
142 dma_addr_t dst
, size_t len
)
144 size_t current_transfer_len
;
145 size_t max_xfer_size
= to_mic_dma_dev(ch
)->max_xfer_size
;
146 /* 3 is added to make sure we have enough space for status desc */
147 int num_desc
= len
/ max_xfer_size
+ 3;
150 if (len
% max_xfer_size
)
153 ret
= mic_dma_avail_desc_ring_space(ch
, num_desc
);
157 current_transfer_len
= min(len
, max_xfer_size
);
158 mic_dma_memcpy_desc(&ch
->desc_ring
[ch
->head
],
159 src
, dst
, current_transfer_len
);
160 mic_dma_hw_ring_inc_head(ch
);
161 len
-= current_transfer_len
;
162 dst
= dst
+ current_transfer_len
;
163 src
= src
+ current_transfer_len
;
168 /* It's a h/w quirk and h/w needs 2 status descriptors for every status desc */
169 static void mic_dma_prog_intr(struct mic_dma_chan
*ch
)
171 mic_dma_prep_status_desc(&ch
->desc_ring
[ch
->head
], 0,
172 ch
->status_dest_micpa
, false);
173 mic_dma_hw_ring_inc_head(ch
);
174 mic_dma_prep_status_desc(&ch
->desc_ring
[ch
->head
], 0,
175 ch
->status_dest_micpa
, true);
176 mic_dma_hw_ring_inc_head(ch
);
179 /* Wrapper function to program memcpy descriptors/status descriptors */
180 static int mic_dma_do_dma(struct mic_dma_chan
*ch
, int flags
, dma_addr_t src
,
181 dma_addr_t dst
, size_t len
)
183 if (len
&& -ENOMEM
== mic_dma_prog_memcpy_desc(ch
, src
, dst
, len
)) {
186 /* 3 is the maximum number of status descriptors */
187 int ret
= mic_dma_avail_desc_ring_space(ch
, 3);
193 /* Above mic_dma_prog_memcpy_desc() makes sure we have enough space */
194 if (flags
& DMA_PREP_FENCE
) {
195 mic_dma_prep_status_desc(&ch
->desc_ring
[ch
->head
], 0,
196 ch
->status_dest_micpa
, false);
197 mic_dma_hw_ring_inc_head(ch
);
200 if (flags
& DMA_PREP_INTERRUPT
)
201 mic_dma_prog_intr(ch
);
206 static inline void mic_dma_issue_pending(struct dma_chan
*ch
)
208 struct mic_dma_chan
*mic_ch
= to_mic_dma_chan(ch
);
210 spin_lock(&mic_ch
->issue_lock
);
212 * Write to head triggers h/w to act on the descriptors.
213 * On MIC, writing the same head value twice causes
214 * a h/w error. On second write, h/w assumes we filled
215 * the entire ring & overwrote some of the descriptors.
217 if (mic_ch
->issued
== mic_ch
->submitted
)
219 mic_ch
->issued
= mic_ch
->submitted
;
221 * make descriptor updates visible before advancing head,
222 * this is purposefully not smp_wmb() since we are also
223 * publishing the descriptor updates to a dma device
226 mic_dma_write_reg(mic_ch
, MIC_DMA_REG_DHPR
, mic_ch
->issued
);
228 spin_unlock(&mic_ch
->issue_lock
);
231 static inline void mic_dma_update_pending(struct mic_dma_chan
*ch
)
233 if (mic_dma_ring_count(ch
->issued
, ch
->submitted
)
234 > mic_dma_pending_level
)
235 mic_dma_issue_pending(&ch
->api_ch
);
238 static dma_cookie_t
mic_dma_tx_submit_unlock(struct dma_async_tx_descriptor
*tx
)
240 struct mic_dma_chan
*mic_ch
= to_mic_dma_chan(tx
->chan
);
243 dma_cookie_assign(tx
);
246 * We need an smp write barrier here because another CPU might see
247 * an update to submitted and update h/w head even before we
248 * assigned a cookie to this tx.
251 mic_ch
->submitted
= mic_ch
->head
;
252 spin_unlock(&mic_ch
->prep_lock
);
253 mic_dma_update_pending(mic_ch
);
257 static inline struct dma_async_tx_descriptor
*
258 allocate_tx(struct mic_dma_chan
*ch
)
260 u32 idx
= mic_dma_hw_ring_dec(ch
->head
);
261 struct dma_async_tx_descriptor
*tx
= &ch
->tx_array
[idx
];
263 dma_async_tx_descriptor_init(tx
, &ch
->api_ch
);
264 tx
->tx_submit
= mic_dma_tx_submit_unlock
;
268 /* Program a status descriptor with dst as address and value to be written */
269 static struct dma_async_tx_descriptor
*
270 mic_dma_prep_status_lock(struct dma_chan
*ch
, dma_addr_t dst
, u64 src_val
,
273 struct mic_dma_chan
*mic_ch
= to_mic_dma_chan(ch
);
276 spin_lock(&mic_ch
->prep_lock
);
277 result
= mic_dma_avail_desc_ring_space(mic_ch
, 4);
280 mic_dma_prep_status_desc(&mic_ch
->desc_ring
[mic_ch
->head
], src_val
, dst
,
282 mic_dma_hw_ring_inc_head(mic_ch
);
283 result
= mic_dma_do_dma(mic_ch
, flags
, 0, 0, 0);
287 return allocate_tx(mic_ch
);
289 dev_err(mic_dma_ch_to_device(mic_ch
),
290 "Error enqueueing dma status descriptor, error=%d\n", result
);
291 spin_unlock(&mic_ch
->prep_lock
);
296 * Prepare a memcpy descriptor to be added to the ring.
297 * Note that the temporary descriptor adds an extra overhead of copying the
298 * descriptor to ring. So, we copy directly to the descriptor ring
300 static struct dma_async_tx_descriptor
*
301 mic_dma_prep_memcpy_lock(struct dma_chan
*ch
, dma_addr_t dma_dest
,
302 dma_addr_t dma_src
, size_t len
, unsigned long flags
)
304 struct mic_dma_chan
*mic_ch
= to_mic_dma_chan(ch
);
305 struct device
*dev
= mic_dma_ch_to_device(mic_ch
);
311 spin_lock(&mic_ch
->prep_lock
);
312 result
= mic_dma_do_dma(mic_ch
, flags
, dma_src
, dma_dest
, len
);
314 return allocate_tx(mic_ch
);
315 dev_err(dev
, "Error enqueueing dma, error=%d\n", result
);
316 spin_unlock(&mic_ch
->prep_lock
);
320 static struct dma_async_tx_descriptor
*
321 mic_dma_prep_interrupt_lock(struct dma_chan
*ch
, unsigned long flags
)
323 struct mic_dma_chan
*mic_ch
= to_mic_dma_chan(ch
);
326 spin_lock(&mic_ch
->prep_lock
);
327 ret
= mic_dma_do_dma(mic_ch
, flags
, 0, 0, 0);
329 return allocate_tx(mic_ch
);
330 spin_unlock(&mic_ch
->prep_lock
);
334 /* Return the status of the transaction */
335 static enum dma_status
336 mic_dma_tx_status(struct dma_chan
*ch
, dma_cookie_t cookie
,
337 struct dma_tx_state
*txstate
)
339 struct mic_dma_chan
*mic_ch
= to_mic_dma_chan(ch
);
341 if (DMA_COMPLETE
!= dma_cookie_status(ch
, cookie
, txstate
))
342 mic_dma_cleanup(mic_ch
);
344 return dma_cookie_status(ch
, cookie
, txstate
);
347 static irqreturn_t
mic_dma_thread_fn(int irq
, void *data
)
349 mic_dma_cleanup((struct mic_dma_chan
*)data
);
353 static irqreturn_t
mic_dma_intr_handler(int irq
, void *data
)
355 struct mic_dma_chan
*ch
= ((struct mic_dma_chan
*)data
);
357 mic_dma_ack_interrupt(ch
);
358 return IRQ_WAKE_THREAD
;
361 static int mic_dma_alloc_desc_ring(struct mic_dma_chan
*ch
)
363 u64 desc_ring_size
= MIC_DMA_DESC_RX_SIZE
* sizeof(*ch
->desc_ring
);
364 struct device
*dev
= &to_mbus_device(ch
)->dev
;
366 desc_ring_size
= ALIGN(desc_ring_size
, MIC_DMA_ALIGN_BYTES
);
367 ch
->desc_ring
= kzalloc(desc_ring_size
, GFP_KERNEL
);
372 ch
->desc_ring_micpa
= dma_map_single(dev
, ch
->desc_ring
,
373 desc_ring_size
, DMA_BIDIRECTIONAL
);
374 if (dma_mapping_error(dev
, ch
->desc_ring_micpa
))
377 ch
->tx_array
= vzalloc(array_size(MIC_DMA_DESC_RX_SIZE
,
378 sizeof(*ch
->tx_array
)));
383 dma_unmap_single(dev
, ch
->desc_ring_micpa
, desc_ring_size
,
386 kfree(ch
->desc_ring
);
390 static void mic_dma_free_desc_ring(struct mic_dma_chan
*ch
)
392 u64 desc_ring_size
= MIC_DMA_DESC_RX_SIZE
* sizeof(*ch
->desc_ring
);
395 desc_ring_size
= ALIGN(desc_ring_size
, MIC_DMA_ALIGN_BYTES
);
396 dma_unmap_single(&to_mbus_device(ch
)->dev
, ch
->desc_ring_micpa
,
397 desc_ring_size
, DMA_BIDIRECTIONAL
);
398 kfree(ch
->desc_ring
);
399 ch
->desc_ring
= NULL
;
402 static void mic_dma_free_status_dest(struct mic_dma_chan
*ch
)
404 dma_unmap_single(&to_mbus_device(ch
)->dev
, ch
->status_dest_micpa
,
405 L1_CACHE_BYTES
, DMA_BIDIRECTIONAL
);
406 kfree(ch
->status_dest
);
409 static int mic_dma_alloc_status_dest(struct mic_dma_chan
*ch
)
411 struct device
*dev
= &to_mbus_device(ch
)->dev
;
413 ch
->status_dest
= kzalloc(L1_CACHE_BYTES
, GFP_KERNEL
);
414 if (!ch
->status_dest
)
416 ch
->status_dest_micpa
= dma_map_single(dev
, ch
->status_dest
,
417 L1_CACHE_BYTES
, DMA_BIDIRECTIONAL
);
418 if (dma_mapping_error(dev
, ch
->status_dest_micpa
)) {
419 kfree(ch
->status_dest
);
420 ch
->status_dest
= NULL
;
426 static int mic_dma_check_chan(struct mic_dma_chan
*ch
)
428 if (mic_dma_read_reg(ch
, MIC_DMA_REG_DCHERR
) ||
429 mic_dma_read_reg(ch
, MIC_DMA_REG_DSTAT
) & MIC_DMA_CHAN_QUIESCE
) {
430 mic_dma_disable_chan(ch
);
431 mic_dma_chan_mask_intr(ch
);
432 dev_err(mic_dma_ch_to_device(ch
),
433 "%s %d error setting up mic dma chan %d\n",
434 __func__
, __LINE__
, ch
->ch_num
);
440 static int mic_dma_chan_setup(struct mic_dma_chan
*ch
)
442 if (MIC_DMA_CHAN_MIC
== ch
->owner
)
443 mic_dma_chan_set_owner(ch
);
444 mic_dma_disable_chan(ch
);
445 mic_dma_chan_mask_intr(ch
);
446 mic_dma_write_reg(ch
, MIC_DMA_REG_DCHERRMSK
, 0);
447 mic_dma_chan_set_desc_ring(ch
);
448 ch
->last_tail
= mic_dma_read_reg(ch
, MIC_DMA_REG_DTPR
);
449 ch
->head
= ch
->last_tail
;
451 mic_dma_chan_unmask_intr(ch
);
452 mic_dma_enable_chan(ch
);
453 return mic_dma_check_chan(ch
);
456 static void mic_dma_chan_destroy(struct mic_dma_chan
*ch
)
458 mic_dma_disable_chan(ch
);
459 mic_dma_chan_mask_intr(ch
);
462 static int mic_dma_setup_irq(struct mic_dma_chan
*ch
)
465 to_mbus_hw_ops(ch
)->request_threaded_irq(to_mbus_device(ch
),
466 mic_dma_intr_handler
, mic_dma_thread_fn
,
467 "mic dma_channel", ch
, ch
->ch_num
);
468 return PTR_ERR_OR_ZERO(ch
->cookie
);
471 static inline void mic_dma_free_irq(struct mic_dma_chan
*ch
)
473 to_mbus_hw_ops(ch
)->free_irq(to_mbus_device(ch
), ch
->cookie
, ch
);
476 static int mic_dma_chan_init(struct mic_dma_chan
*ch
)
478 int ret
= mic_dma_alloc_desc_ring(ch
);
482 ret
= mic_dma_alloc_status_dest(ch
);
485 ret
= mic_dma_chan_setup(ch
);
490 mic_dma_free_status_dest(ch
);
492 mic_dma_free_desc_ring(ch
);
497 static int mic_dma_drain_chan(struct mic_dma_chan
*ch
)
499 struct dma_async_tx_descriptor
*tx
;
503 tx
= mic_dma_prep_memcpy_lock(&ch
->api_ch
, 0, 0, 0, DMA_PREP_FENCE
);
509 cookie
= tx
->tx_submit(tx
);
510 if (dma_submit_error(cookie
))
513 err
= dma_sync_wait(&ch
->api_ch
, cookie
);
515 dev_err(mic_dma_ch_to_device(ch
), "%s %d TO chan 0x%x\n",
516 __func__
, __LINE__
, ch
->ch_num
);
524 static inline void mic_dma_chan_uninit(struct mic_dma_chan
*ch
)
526 mic_dma_chan_destroy(ch
);
528 mic_dma_free_status_dest(ch
);
529 mic_dma_free_desc_ring(ch
);
532 static int mic_dma_init(struct mic_dma_device
*mic_dma_dev
,
533 enum mic_dma_chan_owner owner
)
535 int i
, first_chan
= mic_dma_dev
->start_ch
;
536 struct mic_dma_chan
*ch
;
539 for (i
= first_chan
; i
< first_chan
+ MIC_DMA_NUM_CHAN
; i
++) {
540 ch
= &mic_dma_dev
->mic_ch
[i
];
543 spin_lock_init(&ch
->cleanup_lock
);
544 spin_lock_init(&ch
->prep_lock
);
545 spin_lock_init(&ch
->issue_lock
);
546 ret
= mic_dma_setup_irq(ch
);
552 for (i
= i
- 1; i
>= first_chan
; i
--)
553 mic_dma_free_irq(ch
);
557 static void mic_dma_uninit(struct mic_dma_device
*mic_dma_dev
)
559 int i
, first_chan
= mic_dma_dev
->start_ch
;
560 struct mic_dma_chan
*ch
;
562 for (i
= first_chan
; i
< first_chan
+ MIC_DMA_NUM_CHAN
; i
++) {
563 ch
= &mic_dma_dev
->mic_ch
[i
];
564 mic_dma_free_irq(ch
);
568 static int mic_dma_alloc_chan_resources(struct dma_chan
*ch
)
570 int ret
= mic_dma_chan_init(to_mic_dma_chan(ch
));
573 return MIC_DMA_DESC_RX_SIZE
;
576 static void mic_dma_free_chan_resources(struct dma_chan
*ch
)
578 struct mic_dma_chan
*mic_ch
= to_mic_dma_chan(ch
);
579 mic_dma_drain_chan(mic_ch
);
580 mic_dma_chan_uninit(mic_ch
);
583 /* Set the fn. handlers and register the dma device with dma api */
584 static int mic_dma_register_dma_device(struct mic_dma_device
*mic_dma_dev
,
585 enum mic_dma_chan_owner owner
)
587 int i
, first_chan
= mic_dma_dev
->start_ch
;
589 dma_cap_zero(mic_dma_dev
->dma_dev
.cap_mask
);
591 * This dma engine is not capable of host memory to host memory
594 dma_cap_set(DMA_MEMCPY
, mic_dma_dev
->dma_dev
.cap_mask
);
596 if (MIC_DMA_CHAN_HOST
== owner
)
597 dma_cap_set(DMA_PRIVATE
, mic_dma_dev
->dma_dev
.cap_mask
);
598 mic_dma_dev
->dma_dev
.device_alloc_chan_resources
=
599 mic_dma_alloc_chan_resources
;
600 mic_dma_dev
->dma_dev
.device_free_chan_resources
=
601 mic_dma_free_chan_resources
;
602 mic_dma_dev
->dma_dev
.device_tx_status
= mic_dma_tx_status
;
603 mic_dma_dev
->dma_dev
.device_prep_dma_memcpy
= mic_dma_prep_memcpy_lock
;
604 mic_dma_dev
->dma_dev
.device_prep_dma_imm_data
=
605 mic_dma_prep_status_lock
;
606 mic_dma_dev
->dma_dev
.device_prep_dma_interrupt
=
607 mic_dma_prep_interrupt_lock
;
608 mic_dma_dev
->dma_dev
.device_issue_pending
= mic_dma_issue_pending
;
609 mic_dma_dev
->dma_dev
.copy_align
= MIC_DMA_ALIGN_SHIFT
;
610 INIT_LIST_HEAD(&mic_dma_dev
->dma_dev
.channels
);
611 for (i
= first_chan
; i
< first_chan
+ MIC_DMA_NUM_CHAN
; i
++) {
612 mic_dma_dev
->mic_ch
[i
].api_ch
.device
= &mic_dma_dev
->dma_dev
;
613 dma_cookie_init(&mic_dma_dev
->mic_ch
[i
].api_ch
);
614 list_add_tail(&mic_dma_dev
->mic_ch
[i
].api_ch
.device_node
,
615 &mic_dma_dev
->dma_dev
.channels
);
617 return dmaenginem_async_device_register(&mic_dma_dev
->dma_dev
);
621 * Initializes dma channels and registers the dma device with the
624 static struct mic_dma_device
*mic_dma_dev_reg(struct mbus_device
*mbdev
,
625 enum mic_dma_chan_owner owner
)
627 struct mic_dma_device
*mic_dma_dev
;
629 struct device
*dev
= &mbdev
->dev
;
631 mic_dma_dev
= devm_kzalloc(dev
, sizeof(*mic_dma_dev
), GFP_KERNEL
);
636 mic_dma_dev
->mbdev
= mbdev
;
637 mic_dma_dev
->dma_dev
.dev
= dev
;
638 mic_dma_dev
->mmio
= mbdev
->mmio_va
;
639 if (MIC_DMA_CHAN_HOST
== owner
) {
640 mic_dma_dev
->start_ch
= 0;
641 mic_dma_dev
->max_xfer_size
= MIC_DMA_MAX_XFER_SIZE_HOST
;
643 mic_dma_dev
->start_ch
= 4;
644 mic_dma_dev
->max_xfer_size
= MIC_DMA_MAX_XFER_SIZE_CARD
;
646 ret
= mic_dma_init(mic_dma_dev
, owner
);
649 ret
= mic_dma_register_dma_device(mic_dma_dev
, owner
);
654 mic_dma_uninit(mic_dma_dev
);
658 dev_err(dev
, "Error at %s %d ret=%d\n", __func__
, __LINE__
, ret
);
662 static void mic_dma_dev_unreg(struct mic_dma_device
*mic_dma_dev
)
664 mic_dma_uninit(mic_dma_dev
);
668 static int mic_dma_reg_show(struct seq_file
*s
, void *pos
)
670 struct mic_dma_device
*mic_dma_dev
= s
->private;
671 int i
, chan_num
, first_chan
= mic_dma_dev
->start_ch
;
672 struct mic_dma_chan
*ch
;
674 seq_printf(s
, "SBOX_DCR: %#x\n",
675 mic_dma_mmio_read(&mic_dma_dev
->mic_ch
[first_chan
],
676 MIC_DMA_SBOX_BASE
+ MIC_DMA_SBOX_DCR
));
677 seq_puts(s
, "DMA Channel Registers\n");
678 seq_printf(s
, "%-10s| %-10s %-10s %-10s %-10s %-10s",
679 "Channel", "DCAR", "DTPR", "DHPR", "DRAR_HI", "DRAR_LO");
680 seq_printf(s
, " %-11s %-14s %-10s\n", "DCHERR", "DCHERRMSK", "DSTAT");
681 for (i
= first_chan
; i
< first_chan
+ MIC_DMA_NUM_CHAN
; i
++) {
682 ch
= &mic_dma_dev
->mic_ch
[i
];
683 chan_num
= ch
->ch_num
;
684 seq_printf(s
, "%-10i| %-#10x %-#10x %-#10x %-#10x",
686 mic_dma_read_reg(ch
, MIC_DMA_REG_DCAR
),
687 mic_dma_read_reg(ch
, MIC_DMA_REG_DTPR
),
688 mic_dma_read_reg(ch
, MIC_DMA_REG_DHPR
),
689 mic_dma_read_reg(ch
, MIC_DMA_REG_DRAR_HI
));
690 seq_printf(s
, " %-#10x %-#10x %-#14x %-#10x\n",
691 mic_dma_read_reg(ch
, MIC_DMA_REG_DRAR_LO
),
692 mic_dma_read_reg(ch
, MIC_DMA_REG_DCHERR
),
693 mic_dma_read_reg(ch
, MIC_DMA_REG_DCHERRMSK
),
694 mic_dma_read_reg(ch
, MIC_DMA_REG_DSTAT
));
699 DEFINE_SHOW_ATTRIBUTE(mic_dma_reg
);
701 /* Debugfs parent dir */
702 static struct dentry
*mic_dma_dbg
;
704 static int mic_dma_driver_probe(struct mbus_device
*mbdev
)
706 struct mic_dma_device
*mic_dma_dev
;
707 enum mic_dma_chan_owner owner
;
709 if (MBUS_DEV_DMA_MIC
== mbdev
->id
.device
)
710 owner
= MIC_DMA_CHAN_MIC
;
712 owner
= MIC_DMA_CHAN_HOST
;
714 mic_dma_dev
= mic_dma_dev_reg(mbdev
, owner
);
715 dev_set_drvdata(&mbdev
->dev
, mic_dma_dev
);
718 mic_dma_dev
->dbg_dir
= debugfs_create_dir(dev_name(&mbdev
->dev
),
720 debugfs_create_file("mic_dma_reg", 0444, mic_dma_dev
->dbg_dir
,
721 mic_dma_dev
, &mic_dma_reg_fops
);
726 static void mic_dma_driver_remove(struct mbus_device
*mbdev
)
728 struct mic_dma_device
*mic_dma_dev
;
730 mic_dma_dev
= dev_get_drvdata(&mbdev
->dev
);
731 debugfs_remove_recursive(mic_dma_dev
->dbg_dir
);
732 mic_dma_dev_unreg(mic_dma_dev
);
735 static struct mbus_device_id id_table
[] = {
736 {MBUS_DEV_DMA_MIC
, MBUS_DEV_ANY_ID
},
737 {MBUS_DEV_DMA_HOST
, MBUS_DEV_ANY_ID
},
741 static struct mbus_driver mic_dma_driver
= {
742 .driver
.name
= KBUILD_MODNAME
,
743 .driver
.owner
= THIS_MODULE
,
744 .id_table
= id_table
,
745 .probe
= mic_dma_driver_probe
,
746 .remove
= mic_dma_driver_remove
,
749 static int __init
mic_x100_dma_init(void)
751 int rc
= mbus_register_driver(&mic_dma_driver
);
754 mic_dma_dbg
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
758 static void __exit
mic_x100_dma_exit(void)
760 debugfs_remove_recursive(mic_dma_dbg
);
761 mbus_unregister_driver(&mic_dma_driver
);
764 module_init(mic_x100_dma_init
);
765 module_exit(mic_x100_dma_exit
);
767 MODULE_DEVICE_TABLE(mbus
, id_table
);
768 MODULE_AUTHOR("Intel Corporation");
769 MODULE_DESCRIPTION("Intel(R) MIC X100 DMA Driver");
770 MODULE_LICENSE("GPL v2");