2 * MPC85xx RapidIO support
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 #include <linux/config.h>
14 #include <linux/init.h>
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/interrupt.h>
19 #include <linux/rio.h>
20 #include <linux/rio_drv.h>
24 #define RIO_REGS_BASE (CCSRBAR + 0xc0000)
25 #define RIO_ATMU_REGS_OFFSET 0x10c00
26 #define RIO_MSG_REGS_OFFSET 0x11000
27 #define RIO_MAINT_WIN_SIZE 0x400000
28 #define RIO_DBELL_WIN_SIZE 0x1000
30 #define RIO_MSG_OMR_MUI 0x00000002
31 #define RIO_MSG_OSR_TE 0x00000080
32 #define RIO_MSG_OSR_QOI 0x00000020
33 #define RIO_MSG_OSR_QFI 0x00000010
34 #define RIO_MSG_OSR_MUB 0x00000004
35 #define RIO_MSG_OSR_EOMI 0x00000002
36 #define RIO_MSG_OSR_QEI 0x00000001
38 #define RIO_MSG_IMR_MI 0x00000002
39 #define RIO_MSG_ISR_TE 0x00000080
40 #define RIO_MSG_ISR_QFI 0x00000010
41 #define RIO_MSG_ISR_DIQI 0x00000001
43 #define RIO_MSG_DESC_SIZE 32
44 #define RIO_MSG_BUFFER_SIZE 4096
45 #define RIO_MIN_TX_RING_SIZE 2
46 #define RIO_MAX_TX_RING_SIZE 2048
47 #define RIO_MIN_RX_RING_SIZE 2
48 #define RIO_MAX_RX_RING_SIZE 2048
50 #define DOORBELL_DMR_DI 0x00000002
51 #define DOORBELL_DSR_TE 0x00000080
52 #define DOORBELL_DSR_QFI 0x00000010
53 #define DOORBELL_DSR_DIQI 0x00000001
54 #define DOORBELL_TID_OFFSET 0x03
55 #define DOORBELL_SID_OFFSET 0x05
56 #define DOORBELL_INFO_OFFSET 0x06
58 #define DOORBELL_MESSAGE_SIZE 0x08
59 #define DBELL_SID(x) (*(u8 *)(x + DOORBELL_SID_OFFSET))
60 #define DBELL_TID(x) (*(u8 *)(x + DOORBELL_TID_OFFSET))
61 #define DBELL_INF(x) (*(u16 *)(x + DOORBELL_INFO_OFFSET))
63 #define is_power_of_2(x) (((x) & ((x) - 1)) == 0)
65 struct rio_atmu_regs
{
119 static struct rio_atmu_regs
*atmu_regs
;
120 static struct rio_atmu_regs
*maint_atmu_regs
;
121 static struct rio_atmu_regs
*dbell_atmu_regs
;
122 static u32 dbell_win
;
123 static u32 maint_win
;
124 static struct rio_msg_regs
*msg_regs
;
126 static struct rio_dbell_ring
{
131 static struct rio_msg_tx_ring
{
134 void *virt_buffer
[RIO_MAX_TX_RING_SIZE
];
135 dma_addr_t phys_buffer
[RIO_MAX_TX_RING_SIZE
];
141 static struct rio_msg_rx_ring
{
144 void *virt_buffer
[RIO_MAX_RX_RING_SIZE
];
151 * mpc85xx_rio_doorbell_send - Send a MPC85xx doorbell message
152 * @index: ID of RapidIO interface
153 * @destid: Destination ID of target device
154 * @data: 16-bit info field of RapidIO doorbell message
156 * Sends a MPC85xx doorbell message. Returns %0 on success or
157 * %-EINVAL on failure.
159 static int mpc85xx_rio_doorbell_send(int index
, u16 destid
, u16 data
)
161 pr_debug("mpc85xx_doorbell_send: index %d destid %4.4x data %4.4x\n",
162 index
, destid
, data
);
163 out_be32((void *)&dbell_atmu_regs
->rowtar
, destid
<< 22);
164 out_be16((void *)(dbell_win
), data
);
170 * mpc85xx_local_config_read - Generate a MPC85xx local config space read
171 * @index: ID of RapdiIO interface
172 * @offset: Offset into configuration space
173 * @len: Length (in bytes) of the maintenance transaction
174 * @data: Value to be read into
176 * Generates a MPC85xx local configuration space read. Returns %0 on
177 * success or %-EINVAL on failure.
179 static int mpc85xx_local_config_read(int index
, u32 offset
, int len
, u32
* data
)
181 pr_debug("mpc85xx_local_config_read: index %d offset %8.8x\n", index
,
183 *data
= in_be32((void *)(regs_win
+ offset
));
189 * mpc85xx_local_config_write - Generate a MPC85xx local config space write
190 * @index: ID of RapdiIO interface
191 * @offset: Offset into configuration space
192 * @len: Length (in bytes) of the maintenance transaction
193 * @data: Value to be written
195 * Generates a MPC85xx local configuration space write. Returns %0 on
196 * success or %-EINVAL on failure.
198 static int mpc85xx_local_config_write(int index
, u32 offset
, int len
, u32 data
)
201 ("mpc85xx_local_config_write: index %d offset %8.8x data %8.8x\n",
202 index
, offset
, data
);
203 out_be32((void *)(regs_win
+ offset
), data
);
209 * mpc85xx_rio_config_read - Generate a MPC85xx read maintenance transaction
210 * @index: ID of RapdiIO interface
211 * @destid: Destination ID of transaction
212 * @hopcount: Number of hops to target device
213 * @offset: Offset into configuration space
214 * @len: Length (in bytes) of the maintenance transaction
215 * @val: Location to be read into
217 * Generates a MPC85xx read maintenance transaction. Returns %0 on
218 * success or %-EINVAL on failure.
221 mpc85xx_rio_config_read(int index
, u16 destid
, u8 hopcount
, u32 offset
, int len
,
227 ("mpc85xx_rio_config_read: index %d destid %d hopcount %d offset %8.8x len %d\n",
228 index
, destid
, hopcount
, offset
, len
);
229 out_be32((void *)&maint_atmu_regs
->rowtar
,
230 (destid
<< 22) | (hopcount
<< 12) | ((offset
& ~0x3) >> 9));
232 data
= (u8
*) maint_win
+ offset
;
235 *val
= in_8((u8
*) data
);
238 *val
= in_be16((u16
*) data
);
241 *val
= in_be32((u32
*) data
);
249 * mpc85xx_rio_config_write - Generate a MPC85xx write maintenance transaction
250 * @index: ID of RapdiIO interface
251 * @destid: Destination ID of transaction
252 * @hopcount: Number of hops to target device
253 * @offset: Offset into configuration space
254 * @len: Length (in bytes) of the maintenance transaction
255 * @val: Value to be written
257 * Generates an MPC85xx write maintenance transaction. Returns %0 on
258 * success or %-EINVAL on failure.
261 mpc85xx_rio_config_write(int index
, u16 destid
, u8 hopcount
, u32 offset
,
266 ("mpc85xx_rio_config_write: index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
267 index
, destid
, hopcount
, offset
, len
, val
);
268 out_be32((void *)&maint_atmu_regs
->rowtar
,
269 (destid
<< 22) | (hopcount
<< 12) | ((offset
& ~0x3) >> 9));
271 data
= (u8
*) maint_win
+ offset
;
274 out_8((u8
*) data
, val
);
277 out_be16((u16
*) data
, val
);
280 out_be32((u32
*) data
, val
);
288 * rio_hw_add_outb_message - Add message to the MPC85xx outbound message queue
289 * @mport: Master port with outbound message queue
290 * @rdev: Target of outbound message
291 * @mbox: Outbound mailbox
292 * @buffer: Message to add to outbound queue
293 * @len: Length of message
295 * Adds the @buffer message to the MPC85xx outbound message queue. Returns
296 * %0 on success or %-EINVAL on failure.
299 rio_hw_add_outb_message(struct rio_mport
*mport
, struct rio_dev
*rdev
, int mbox
,
300 void *buffer
, size_t len
)
303 struct rio_tx_desc
*desc
=
304 (struct rio_tx_desc
*)msg_tx_ring
.virt
+ msg_tx_ring
.tx_slot
;
308 ("RIO: rio_hw_add_outb_message(): destid %4.4x mbox %d buffer %8.8x len %8.8x\n",
309 rdev
->destid
, mbox
, (int)buffer
, len
);
311 if ((len
< 8) || (len
> RIO_MAX_MSG_SIZE
)) {
316 /* Copy and clear rest of buffer */
317 memcpy(msg_tx_ring
.virt_buffer
[msg_tx_ring
.tx_slot
], buffer
, len
);
318 if (len
< (RIO_MAX_MSG_SIZE
- 4))
319 memset((void *)((u32
) msg_tx_ring
.
320 virt_buffer
[msg_tx_ring
.tx_slot
] + len
), 0,
321 RIO_MAX_MSG_SIZE
- len
);
323 /* Set mbox field for message */
324 desc
->dport
= mbox
& 0x3;
326 /* Enable EOMI interrupt, set priority, and set destid */
327 desc
->dattr
= 0x28000000 | (rdev
->destid
<< 2);
329 /* Set transfer size aligned to next power of 2 (in double words) */
330 desc
->dwcnt
= is_power_of_2(len
) ? len
: 1 << get_bitmask_order(len
);
332 /* Set snooping and source buffer address */
333 desc
->saddr
= 0x00000004 | msg_tx_ring
.phys_buffer
[msg_tx_ring
.tx_slot
];
335 /* Increment enqueue pointer */
336 omr
= in_be32((void *)&msg_regs
->omr
);
337 out_be32((void *)&msg_regs
->omr
, omr
| RIO_MSG_OMR_MUI
);
339 /* Go to next descriptor */
340 if (++msg_tx_ring
.tx_slot
== msg_tx_ring
.size
)
341 msg_tx_ring
.tx_slot
= 0;
347 EXPORT_SYMBOL_GPL(rio_hw_add_outb_message
);
350 * mpc85xx_rio_tx_handler - MPC85xx outbound message interrupt handler
351 * @irq: Linux interrupt number
352 * @dev_instance: Pointer to interrupt-specific data
353 * @regs: Register context
355 * Handles outbound message interrupts. Executes a register outbound
356 * mailbox event handler and acks the interrupt occurence.
359 mpc85xx_rio_tx_handler(int irq
, void *dev_instance
, struct pt_regs
*regs
)
362 struct rio_mport
*port
= (struct rio_mport
*)dev_instance
;
364 osr
= in_be32((void *)&msg_regs
->osr
);
366 if (osr
& RIO_MSG_OSR_TE
) {
367 pr_info("RIO: outbound message transmission error\n");
368 out_be32((void *)&msg_regs
->osr
, RIO_MSG_OSR_TE
);
372 if (osr
& RIO_MSG_OSR_QOI
) {
373 pr_info("RIO: outbound message queue overflow\n");
374 out_be32((void *)&msg_regs
->osr
, RIO_MSG_OSR_QOI
);
378 if (osr
& RIO_MSG_OSR_EOMI
) {
379 u32 dqp
= in_be32((void *)&msg_regs
->odqdpar
);
380 int slot
= (dqp
- msg_tx_ring
.phys
) >> 5;
381 port
->outb_msg
[0].mcback(port
, msg_tx_ring
.dev_id
, -1, slot
);
383 /* Ack the end-of-message interrupt */
384 out_be32((void *)&msg_regs
->osr
, RIO_MSG_OSR_EOMI
);
392 * rio_open_outb_mbox - Initialize MPC85xx outbound mailbox
393 * @mport: Master port implementing the outbound message unit
394 * @dev_id: Device specific pointer to pass on event
395 * @mbox: Mailbox to open
396 * @entries: Number of entries in the outbound mailbox ring
398 * Initializes buffer ring, request the outbound message interrupt,
399 * and enables the outbound message unit. Returns %0 on success and
400 * %-EINVAL or %-ENOMEM on failure.
402 int rio_open_outb_mbox(struct rio_mport
*mport
, void *dev_id
, int mbox
, int entries
)
406 if ((entries
< RIO_MIN_TX_RING_SIZE
) ||
407 (entries
> RIO_MAX_TX_RING_SIZE
) || (!is_power_of_2(entries
))) {
412 /* Initialize shadow copy ring */
413 msg_tx_ring
.dev_id
= dev_id
;
414 msg_tx_ring
.size
= entries
;
416 for (i
= 0; i
< msg_tx_ring
.size
; i
++) {
418 (msg_tx_ring
.virt_buffer
[i
] =
419 dma_alloc_coherent(NULL
, RIO_MSG_BUFFER_SIZE
,
420 &msg_tx_ring
.phys_buffer
[i
],
423 for (j
= 0; j
< msg_tx_ring
.size
; j
++)
424 if (msg_tx_ring
.virt_buffer
[j
])
425 dma_free_coherent(NULL
,
435 /* Initialize outbound message descriptor ring */
436 if (!(msg_tx_ring
.virt
= dma_alloc_coherent(NULL
,
444 memset(msg_tx_ring
.virt
, 0, msg_tx_ring
.size
* RIO_MSG_DESC_SIZE
);
445 msg_tx_ring
.tx_slot
= 0;
447 /* Point dequeue/enqueue pointers at first entry in ring */
448 out_be32((void *)&msg_regs
->odqdpar
, msg_tx_ring
.phys
);
449 out_be32((void *)&msg_regs
->odqepar
, msg_tx_ring
.phys
);
451 /* Configure for snooping */
452 out_be32((void *)&msg_regs
->osar
, 0x00000004);
454 /* Clear interrupt status */
455 out_be32((void *)&msg_regs
->osr
, 0x000000b3);
457 /* Hook up outbound message handler */
459 request_irq(MPC85xx_IRQ_RIO_TX
, mpc85xx_rio_tx_handler
, 0,
460 "msg_tx", (void *)mport
)) < 0)
464 * Configure outbound message unit
466 * Interrupts (all enabled, except QEIE)
470 out_be32((void *)&msg_regs
->omr
, 0x00100220);
472 /* Set number of entries */
473 out_be32((void *)&msg_regs
->omr
,
474 in_be32((void *)&msg_regs
->omr
) |
475 ((get_bitmask_order(entries
) - 2) << 12));
477 /* Now enable the unit */
478 out_be32((void *)&msg_regs
->omr
, in_be32((void *)&msg_regs
->omr
) | 0x1);
484 dma_free_coherent(NULL
, msg_tx_ring
.size
* RIO_MSG_DESC_SIZE
,
485 msg_tx_ring
.virt
, msg_tx_ring
.phys
);
488 for (i
= 0; i
< msg_tx_ring
.size
; i
++)
489 dma_free_coherent(NULL
, RIO_MSG_BUFFER_SIZE
,
490 msg_tx_ring
.virt_buffer
[i
],
491 msg_tx_ring
.phys_buffer
[i
]);
497 * rio_close_outb_mbox - Shut down MPC85xx outbound mailbox
498 * @mport: Master port implementing the outbound message unit
499 * @mbox: Mailbox to close
501 * Disables the outbound message unit, free all buffers, and
502 * frees the outbound message interrupt.
504 void rio_close_outb_mbox(struct rio_mport
*mport
, int mbox
)
506 /* Disable inbound message unit */
507 out_be32((void *)&msg_regs
->omr
, 0);
510 dma_free_coherent(NULL
, msg_tx_ring
.size
* RIO_MSG_DESC_SIZE
,
511 msg_tx_ring
.virt
, msg_tx_ring
.phys
);
514 free_irq(MPC85xx_IRQ_RIO_TX
, (void *)mport
);
518 * mpc85xx_rio_rx_handler - MPC85xx inbound message interrupt handler
519 * @irq: Linux interrupt number
520 * @dev_instance: Pointer to interrupt-specific data
521 * @regs: Register context
523 * Handles inbound message interrupts. Executes a registered inbound
524 * mailbox event handler and acks the interrupt occurence.
527 mpc85xx_rio_rx_handler(int irq
, void *dev_instance
, struct pt_regs
*regs
)
530 struct rio_mport
*port
= (struct rio_mport
*)dev_instance
;
532 isr
= in_be32((void *)&msg_regs
->isr
);
534 if (isr
& RIO_MSG_ISR_TE
) {
535 pr_info("RIO: inbound message reception error\n");
536 out_be32((void *)&msg_regs
->isr
, RIO_MSG_ISR_TE
);
540 /* XXX Need to check/dispatch until queue empty */
541 if (isr
& RIO_MSG_ISR_DIQI
) {
543 * We implement *only* mailbox 0, but can receive messages
544 * for any mailbox/letter to that mailbox destination. So,
545 * make the callback with an unknown/invalid mailbox number
548 port
->inb_msg
[0].mcback(port
, msg_rx_ring
.dev_id
, -1, -1);
550 /* Ack the queueing interrupt */
551 out_be32((void *)&msg_regs
->isr
, RIO_MSG_ISR_DIQI
);
559 * rio_open_inb_mbox - Initialize MPC85xx inbound mailbox
560 * @mport: Master port implementing the inbound message unit
561 * @dev_id: Device specific pointer to pass on event
562 * @mbox: Mailbox to open
563 * @entries: Number of entries in the inbound mailbox ring
565 * Initializes buffer ring, request the inbound message interrupt,
566 * and enables the inbound message unit. Returns %0 on success
567 * and %-EINVAL or %-ENOMEM on failure.
569 int rio_open_inb_mbox(struct rio_mport
*mport
, void *dev_id
, int mbox
, int entries
)
573 if ((entries
< RIO_MIN_RX_RING_SIZE
) ||
574 (entries
> RIO_MAX_RX_RING_SIZE
) || (!is_power_of_2(entries
))) {
579 /* Initialize client buffer ring */
580 msg_rx_ring
.dev_id
= dev_id
;
581 msg_rx_ring
.size
= entries
;
582 msg_rx_ring
.rx_slot
= 0;
583 for (i
= 0; i
< msg_rx_ring
.size
; i
++)
584 msg_rx_ring
.virt_buffer
[i
] = NULL
;
586 /* Initialize inbound message ring */
587 if (!(msg_rx_ring
.virt
= dma_alloc_coherent(NULL
,
596 /* Point dequeue/enqueue pointers at first entry in ring */
597 out_be32((void *)&msg_regs
->ifqdpar
, (u32
) msg_rx_ring
.phys
);
598 out_be32((void *)&msg_regs
->ifqepar
, (u32
) msg_rx_ring
.phys
);
600 /* Clear interrupt status */
601 out_be32((void *)&msg_regs
->isr
, 0x00000091);
603 /* Hook up inbound message handler */
605 request_irq(MPC85xx_IRQ_RIO_RX
, mpc85xx_rio_rx_handler
, 0,
606 "msg_rx", (void *)mport
)) < 0) {
607 dma_free_coherent(NULL
, RIO_MSG_BUFFER_SIZE
,
608 msg_tx_ring
.virt_buffer
[i
],
609 msg_tx_ring
.phys_buffer
[i
]);
614 * Configure inbound message unit:
616 * 4KB max message size
617 * Unmask all interrupt sources
620 out_be32((void *)&msg_regs
->imr
, 0x001b0060);
622 /* Set number of queue entries */
623 out_be32((void *)&msg_regs
->imr
,
624 in_be32((void *)&msg_regs
->imr
) |
625 ((get_bitmask_order(entries
) - 2) << 12));
627 /* Now enable the unit */
628 out_be32((void *)&msg_regs
->imr
, in_be32((void *)&msg_regs
->imr
) | 0x1);
635 * rio_close_inb_mbox - Shut down MPC85xx inbound mailbox
636 * @mport: Master port implementing the inbound message unit
637 * @mbox: Mailbox to close
639 * Disables the inbound message unit, free all buffers, and
640 * frees the inbound message interrupt.
642 void rio_close_inb_mbox(struct rio_mport
*mport
, int mbox
)
644 /* Disable inbound message unit */
645 out_be32((void *)&msg_regs
->imr
, 0);
648 dma_free_coherent(NULL
, msg_rx_ring
.size
* RIO_MAX_MSG_SIZE
,
649 msg_rx_ring
.virt
, msg_rx_ring
.phys
);
652 free_irq(MPC85xx_IRQ_RIO_RX
, (void *)mport
);
656 * rio_hw_add_inb_buffer - Add buffer to the MPC85xx inbound message queue
657 * @mport: Master port implementing the inbound message unit
658 * @mbox: Inbound mailbox number
659 * @buf: Buffer to add to inbound queue
661 * Adds the @buf buffer to the MPC85xx inbound message queue. Returns
662 * %0 on success or %-EINVAL on failure.
664 int rio_hw_add_inb_buffer(struct rio_mport
*mport
, int mbox
, void *buf
)
668 pr_debug("RIO: rio_hw_add_inb_buffer(), msg_rx_ring.rx_slot %d\n",
669 msg_rx_ring
.rx_slot
);
671 if (msg_rx_ring
.virt_buffer
[msg_rx_ring
.rx_slot
]) {
673 "RIO: error adding inbound buffer %d, buffer exists\n",
674 msg_rx_ring
.rx_slot
);
679 msg_rx_ring
.virt_buffer
[msg_rx_ring
.rx_slot
] = buf
;
680 if (++msg_rx_ring
.rx_slot
== msg_rx_ring
.size
)
681 msg_rx_ring
.rx_slot
= 0;
687 EXPORT_SYMBOL_GPL(rio_hw_add_inb_buffer
);
690 * rio_hw_get_inb_message - Fetch inbound message from the MPC85xx message unit
691 * @mport: Master port implementing the inbound message unit
692 * @mbox: Inbound mailbox number
694 * Gets the next available inbound message from the inbound message queue.
695 * A pointer to the message is returned on success or NULL on failure.
697 void *rio_hw_get_inb_message(struct rio_mport
*mport
, int mbox
)
700 u32 phys_buf
, virt_buf
;
704 phys_buf
= in_be32((void *)&msg_regs
->ifqdpar
);
706 /* If no more messages, then bail out */
707 if (phys_buf
== in_be32((void *)&msg_regs
->ifqepar
))
710 virt_buf
= (u32
) msg_rx_ring
.virt
+ (phys_buf
- msg_rx_ring
.phys
);
711 buf_idx
= (phys_buf
- msg_rx_ring
.phys
) / RIO_MAX_MSG_SIZE
;
712 buf
= msg_rx_ring
.virt_buffer
[buf_idx
];
716 "RIO: inbound message copy failed, no buffers\n");
720 /* Copy max message size, caller is expected to allocate that big */
721 memcpy(buf
, (void *)virt_buf
, RIO_MAX_MSG_SIZE
);
723 /* Clear the available buffer */
724 msg_rx_ring
.virt_buffer
[buf_idx
] = NULL
;
727 imr
= in_be32((void *)&msg_regs
->imr
);
728 out_be32((void *)&msg_regs
->imr
, imr
| RIO_MSG_IMR_MI
);
734 EXPORT_SYMBOL_GPL(rio_hw_get_inb_message
);
737 * mpc85xx_rio_dbell_handler - MPC85xx doorbell interrupt handler
738 * @irq: Linux interrupt number
739 * @dev_instance: Pointer to interrupt-specific data
740 * @regs: Register context
742 * Handles doorbell interrupts. Parses a list of registered
743 * doorbell event handlers and executes a matching event handler.
746 mpc85xx_rio_dbell_handler(int irq
, void *dev_instance
, struct pt_regs
*regs
)
749 struct rio_mport
*port
= (struct rio_mport
*)dev_instance
;
751 dsr
= in_be32((void *)&msg_regs
->dsr
);
753 if (dsr
& DOORBELL_DSR_TE
) {
754 pr_info("RIO: doorbell reception error\n");
755 out_be32((void *)&msg_regs
->dsr
, DOORBELL_DSR_TE
);
759 if (dsr
& DOORBELL_DSR_QFI
) {
760 pr_info("RIO: doorbell queue full\n");
761 out_be32((void *)&msg_regs
->dsr
, DOORBELL_DSR_QFI
);
765 /* XXX Need to check/dispatch until queue empty */
766 if (dsr
& DOORBELL_DSR_DIQI
) {
768 (u32
) dbell_ring
.virt
+
769 (in_be32((void *)&msg_regs
->dqdpar
) & 0xfff);
771 struct rio_dbell
*dbell
;
775 ("RIO: processing doorbell, sid %2.2x tid %2.2x info %4.4x\n",
776 DBELL_SID(dmsg
), DBELL_TID(dmsg
), DBELL_INF(dmsg
));
778 list_for_each_entry(dbell
, &port
->dbells
, node
) {
779 if ((dbell
->res
->start
<= DBELL_INF(dmsg
)) &&
780 (dbell
->res
->end
>= DBELL_INF(dmsg
))) {
786 dbell
->dinb(port
, dbell
->dev_id
, DBELL_SID(dmsg
), DBELL_TID(dmsg
),
790 ("RIO: spurious doorbell, sid %2.2x tid %2.2x info %4.4x\n",
791 DBELL_SID(dmsg
), DBELL_TID(dmsg
), DBELL_INF(dmsg
));
793 dmr
= in_be32((void *)&msg_regs
->dmr
);
794 out_be32((void *)&msg_regs
->dmr
, dmr
| DOORBELL_DMR_DI
);
795 out_be32((void *)&msg_regs
->dsr
, DOORBELL_DSR_DIQI
);
803 * mpc85xx_rio_doorbell_init - MPC85xx doorbell interface init
804 * @mport: Master port implementing the inbound doorbell unit
806 * Initializes doorbell unit hardware and inbound DMA buffer
807 * ring. Called from mpc85xx_rio_setup(). Returns %0 on success
808 * or %-ENOMEM on failure.
810 static int mpc85xx_rio_doorbell_init(struct rio_mport
*mport
)
814 /* Map outbound doorbell window immediately after maintenance window */
816 (u32
) ioremap(mport
->iores
.start
+ RIO_MAINT_WIN_SIZE
,
817 RIO_DBELL_WIN_SIZE
))) {
819 "RIO: unable to map outbound doorbell window\n");
824 /* Initialize inbound doorbells */
825 if (!(dbell_ring
.virt
= dma_alloc_coherent(NULL
,
826 512 * DOORBELL_MESSAGE_SIZE
,
829 printk(KERN_ERR
"RIO: unable allocate inbound doorbell ring\n");
831 iounmap((void *)dbell_win
);
835 /* Point dequeue/enqueue pointers at first entry in ring */
836 out_be32((void *)&msg_regs
->dqdpar
, (u32
) dbell_ring
.phys
);
837 out_be32((void *)&msg_regs
->dqepar
, (u32
) dbell_ring
.phys
);
839 /* Clear interrupt status */
840 out_be32((void *)&msg_regs
->dsr
, 0x00000091);
842 /* Hook up doorbell handler */
844 request_irq(MPC85xx_IRQ_RIO_BELL
, mpc85xx_rio_dbell_handler
, 0,
845 "dbell_rx", (void *)mport
) < 0)) {
846 iounmap((void *)dbell_win
);
847 dma_free_coherent(NULL
, 512 * DOORBELL_MESSAGE_SIZE
,
848 dbell_ring
.virt
, dbell_ring
.phys
);
850 "MPC85xx RIO: unable to request inbound doorbell irq");
854 /* Configure doorbells for snooping, 512 entries, and enable */
855 out_be32((void *)&msg_regs
->dmr
, 0x00108161);
861 static char *cmdline
= NULL
;
863 static int mpc85xx_rio_get_hdid(int index
)
865 /* XXX Need to parse multiple entries in some format */
869 return simple_strtol(cmdline
, NULL
, 0);
872 static int mpc85xx_rio_get_cmdline(char *s
)
881 __setup("riohdid=", mpc85xx_rio_get_cmdline
);
884 * mpc85xx_rio_setup - Setup MPC85xx RapidIO interface
885 * @law_start: Starting physical address of RapidIO LAW
886 * @law_size: Size of RapidIO LAW
888 * Initializes MPC85xx RapidIO hardware interface, configures
889 * master port with system-specific info, and registers the
890 * master port with the RapidIO subsystem.
892 void mpc85xx_rio_setup(int law_start
, int law_size
)
895 struct rio_mport
*port
;
897 ops
= kmalloc(sizeof(struct rio_ops
), GFP_KERNEL
);
898 ops
->lcread
= mpc85xx_local_config_read
;
899 ops
->lcwrite
= mpc85xx_local_config_write
;
900 ops
->cread
= mpc85xx_rio_config_read
;
901 ops
->cwrite
= mpc85xx_rio_config_write
;
902 ops
->dsend
= mpc85xx_rio_doorbell_send
;
904 port
= kmalloc(sizeof(struct rio_mport
), GFP_KERNEL
);
907 INIT_LIST_HEAD(&port
->dbells
);
908 port
->iores
.start
= law_start
;
909 port
->iores
.end
= law_start
+ law_size
;
910 port
->iores
.flags
= IORESOURCE_MEM
;
912 rio_init_dbell_res(&port
->riores
[RIO_DOORBELL_RESOURCE
], 0, 0xffff);
913 rio_init_mbox_res(&port
->riores
[RIO_INB_MBOX_RESOURCE
], 0, 0);
914 rio_init_mbox_res(&port
->riores
[RIO_OUTB_MBOX_RESOURCE
], 0, 0);
915 strcpy(port
->name
, "RIO0 mport");
918 port
->host_deviceid
= mpc85xx_rio_get_hdid(port
->id
);
920 rio_register_mport(port
);
922 regs_win
= (u32
) ioremap(RIO_REGS_BASE
, 0x20000);
923 atmu_regs
= (struct rio_atmu_regs
*)(regs_win
+ RIO_ATMU_REGS_OFFSET
);
924 maint_atmu_regs
= atmu_regs
+ 1;
925 dbell_atmu_regs
= atmu_regs
+ 2;
926 msg_regs
= (struct rio_msg_regs
*)(regs_win
+ RIO_MSG_REGS_OFFSET
);
928 /* Configure maintenance transaction window */
929 out_be32((void *)&maint_atmu_regs
->rowbar
, 0x000c0000);
930 out_be32((void *)&maint_atmu_regs
->rowar
, 0x80077015);
932 maint_win
= (u32
) ioremap(law_start
, RIO_MAINT_WIN_SIZE
);
934 /* Configure outbound doorbell window */
935 out_be32((void *)&dbell_atmu_regs
->rowbar
, 0x000c0400);
936 out_be32((void *)&dbell_atmu_regs
->rowar
, 0x8004200b);
937 mpc85xx_rio_doorbell_init(port
);