Skip to content

Commit da1589f

Browse files
Alexandre Bouninetorvalds
authored andcommitted
rapidio: add inbound memory mapping interface
Add common inbound memory mapping/unmapping interface. This allows to make local memory space accessible from the RapidIO side using hardware mapping capabilities of RapidIO bridging devices. The new interface is intended to enable data transfers between RapidIO devices in combination with DMA engine support. This patch is based on patch submitted by Li Yang <leoli@freescale.com> (https://lists.ozlabs.org/pipermail/linuxppc-dev/2009-April/071210.html) Signed-off-by: Alexandre Bounine <alexandre.bounine@idt.com> Cc: Matt Porter <mporter@kernel.crashing.org> Cc: Li Yang <leoli@freescale.com> Cc: Kumar Gala <galak@kernel.crashing.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 18f6287 commit da1589f

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎drivers/rapidio/rio.c‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
static LIST_HEAD(rio_mports);
3535
static unsigned char next_portid;
36+
static DEFINE_SPINLOCK(rio_mmap_lock);
3637

3738
/**
3839
* rio_local_get_device_id - Get the base/extended device id for a port
@@ -397,6 +398,49 @@ int rio_release_inb_pwrite(struct rio_dev *rdev)
397398
}
398399
EXPORT_SYMBOL_GPL(rio_release_inb_pwrite);
399400

401+
/**
402+
* rio_map_inb_region -- Map inbound memory region.
403+
* @mport: Master port.
404+
* @lstart: physical address of memory region to be mapped
405+
* @rbase: RIO base address assigned to this window
406+
* @size: Size of the memory region
407+
* @rflags: Flags for mapping.
408+
*
409+
* Return: 0 -- Success.
410+
*
411+
* This function will create the mapping from RIO space to local memory.
412+
*/
413+
int rio_map_inb_region(struct rio_mport *mport, dma_addr_t local,
414+
u64 rbase, u32 size, u32 rflags)
415+
{
416+
int rc = 0;
417+
unsigned long flags;
418+
419+
if (!mport->ops->map_inb)
420+
return -1;
421+
spin_lock_irqsave(&rio_mmap_lock, flags);
422+
rc = mport->ops->map_inb(mport, local, rbase, size, rflags);
423+
spin_unlock_irqrestore(&rio_mmap_lock, flags);
424+
return rc;
425+
}
426+
EXPORT_SYMBOL_GPL(rio_map_inb_region);
427+
428+
/**
429+
* rio_unmap_inb_region -- Unmap the inbound memory region
430+
* @mport: Master port
431+
* @lstart: physical address of memory region to be unmapped
432+
*/
433+
void rio_unmap_inb_region(struct rio_mport *mport, dma_addr_t lstart)
434+
{
435+
unsigned long flags;
436+
if (!mport->ops->unmap_inb)
437+
return;
438+
spin_lock_irqsave(&rio_mmap_lock, flags);
439+
mport->ops->unmap_inb(mport, lstart);
440+
spin_unlock_irqrestore(&rio_mmap_lock, flags);
441+
}
442+
EXPORT_SYMBOL_GPL(rio_unmap_inb_region);
443+
400444
/**
401445
* rio_mport_get_physefb - Helper function that returns register offset
402446
* for Physical Layer Extended Features Block.

‎include/linux/rio.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ struct rio_net {
301301
* @add_outb_message: Callback to add a message to an outbound mailbox queue.
302302
* @add_inb_buffer: Callback to add a buffer to an inbound mailbox queue.
303303
* @get_inb_message: Callback to get a message from an inbound mailbox queue.
304+
* @map_inb: Callback to map RapidIO address region into local memory space.
305+
* @unmap_inb: Callback to unmap RapidIO address region mapped with map_inb().
304306
*/
305307
struct rio_ops {
306308
int (*lcread) (struct rio_mport *mport, int index, u32 offset, int len,
@@ -323,6 +325,9 @@ struct rio_ops {
323325
int mbox, void *buffer, size_t len);
324326
int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
325327
void *(*get_inb_message)(struct rio_mport *mport, int mbox);
328+
int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
329+
u64 rstart, u32 size, u32 flags);
330+
void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
326331
};
327332

328333
#define RIO_RESOURCE_MEM 0x00000100

‎include/linux/rio_drv.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ void rio_release_regions(struct rio_dev *);
365365
int rio_request_region(struct rio_dev *, int, char *);
366366
void rio_release_region(struct rio_dev *, int);
367367

368+
/* Memory mapping functions */
369+
extern int rio_map_inb_region(struct rio_mport *mport, dma_addr_t local,
370+
u64 rbase, u32 size, u32 rflags);
371+
extern void rio_unmap_inb_region(struct rio_mport *mport, dma_addr_t lstart);
372+
368373
/* Port-Write management */
369374
extern int rio_request_inb_pwrite(struct rio_dev *,
370375
int (*)(struct rio_dev *, union rio_pw_msg*, int));

0 commit comments

Comments
 (0)