Skip to content

Kernel module to easily create or delete u-dma-bufUser space mappable DMA Buffer)

License

Notifications You must be signed in to change notification settings

ikwzm/u-dma-buf-mgr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

u-dma-buf-mgr

Overview

Introduction

This repository provides kernel module to easily create or delete u-dma-buf. Once this device driver is loaded into your system, you will be able to access /dev/u-dma-buf-mgr. u-dma-buf can be created/deleted by writing the command to /dev/u-dma-buf-mgr as a string.

Udmabuf is a Linux device driver that allocates contiguous memory blocks in the kernel space as DMA buffers and makes them available from the user space.

For details of udmabuf, please refer to following URL.

https://github.com/ikwzm/udmabuf

Usage

Create u-dma-buf

Example

shell$ sudo sh -c "echo 'create udmabuf8 0x10000' > /dev/u-dma-buf-mgr"
[16463.308265] u-dma-buf-mgr: create udmabuf8 size=65536
[16463.311147] u-dma-buf udmabuf8: driver version = 4.6.1
[16463.311148] u-dma-buf udmabuf8: major number   = 238
[16463.311149] u-dma-buf udmabuf8: minor number   = 0
[16463.311149] u-dma-buf udmabuf8: phys address   = 0x000000007b410000
[16463.311150] u-dma-buf udmabuf8: buffer size    = 65536
[16463.311150] u-dma-buf udmabuf8: dma device     = u-dma-buf.1.auto
[16463.311151] u-dma-buf udmabuf8: dma bus        = platform
[16463.311151] u-dma-buf udmabuf8: dma coherent   = 1
[16463.311152] u-dma-buf udmabuf8: dma mask       = 0x00000000ffffffff
[16463.311152] u-dma-buf udmabuf8: mmap mode      = 2
[16463.311152] u-dma-buf udmabuf8: mmap           = quirk-mmap
[16463.311152] u-dma-buf udmabuf8: mmap pages     = NONE
[16463.311152] u-dma-buf u-dma-buf.1.auto: driver installed.
shell$ sudo sh -c "echo 'create udmabuf9 0x10000 bus=pci device=0000:00:18.7' > /dev/u-dma-buf-mgr"
[18758.896248] u-dma-buf-mgr: create udmabuf9 size=65536
[18758.899611] u-dma-buf udmabuf0: driver version = 4.6.1
[18758.899612] u-dma-buf udmabuf0: major number   = 238
[18758.899613] u-dma-buf udmabuf0: minor number   = 0
[18758.899614] u-dma-buf udmabuf0: phys address   = 0x000000007b410000
[18758.899614] u-dma-buf udmabuf0: buffer size    = 65536
[18758.899615] u-dma-buf udmabuf0: dma device     = 0000:00:18.7
[18758.899615] u-dma-buf udmabuf0: dma bus        = pci
[18758.899626] u-dma-buf udmabuf0: dma coherent   = 1
[18758.899628] u-dma-buf udmabuf0: dma mask       = 0x00000000ffffffff
[18758.899628] u-dma-buf udmabuf0: mmap mode      = 3
[18758.899628] u-dma-buf udmabuf0: mmap           = dma_mmap_coherent
[18758.899628] u-dma-buf: driver installed.

Synopsis for writing /dev/u-dma-buf-mgr

create <device-name> <size> [bus=<bus>] [device=<device>] [dma-mask=<dma-mask-size>]

device-name

The device-name argument is used to set the name of device. The device-name argument is mandatory.

size

The size argument is used to set the capacity of DMA buffer in bytes. The size argment is mandatory.

device option

The device option specifies the parent device of u-dma-buf. If the device option is omitted, it creates its own platform device.

bus option

The bus option specifies the bus to search for the device specified by the device option. If the bus option is omitted, the platform bus is searched.

dma-mask option

The dma-mask option specifies the number of bits in the dma mask value. If the parent device is specified by the device option, the dma-mask option is ignored because the dma-mask set for the parent device takes precedence.

quirk-mmap-on option

The quirk-mmap-on option specifies use u-dma-buf's own quirk mmap(). If this option is omitted, quirk-mmap-mode follows the u-dma-buf default.

quirk-mmap-off option

The quirk-mmap-off option specifies u-dma-buf's own quirk mmap() is prohibited. If this option is omitted, quirk-mmap-mode follows the u-dma-buf default.

quirk-mmap-auto option

The quirk-mmap-auto option specifies the automatically selects whether or not to use u-dma-buf's own quirk mmap(). If this option is omitted, quirk-mmap-mode follows the u-dma-buf default.

Delete u-dma-buf

Example

shell$ sudo sh -c "echo 'delete udmabuf8' > /dev/u-dma-buf-mgr"
[16528.506714] u-dma-buf-mgr: delete udmabuf8
[16528.508506] u-dma-buf u-dma-buf.1.auto: driver removed.

Synopsis for writing /dev/u-dma-buf-mgr

delete <device-name>

device-name

The device-name argument is used to set the name of device. The device-name argument is mandatory. The device-name argument must be the device name created by the create command.

Install

Installation with command

Before installing u-dma-buf-mgr, u-dma-buf must be installed beforehand.

Load the u-dma-buf-mgr using insmod.

shell$ sudo insmod u-dma-buf-mgr.ko

or load the u-dma-buf-mgr using modprobe.

shell$ sudo modprobe u-dma-buf-mgr

The module can be uninstalled by the rmmod command.

shell$ sudo rmmod  u-dma-buf-mgr

Installation with the Debian Package

For details, refer to the following URL.

Compile

Makefile

This repository contains a Makefie. Makefile has the following Parameters:

Parameter Name Description Default Value
ARCH Architecture Name $(shell uname -m | sed -e s/arm.*/arm/ -e s/aarch64.*/arm64/)
KERNEL_SRC Kernel Source Directory /lib/modules/$(shell uname -r)/build
KBUILD_EXTRA_SYMBOLS u-dma-buf Module.symvers none

Symbol information of functions/variables exported by u-dma-buf is required to compile u-dma-buf-mgr. Therefore, either of the following two is required.

Set KBUILD_EXTRA_SYMBOLS variable to Module.symvers created by u-dma-buf

Cross Compile

If you have a cross-compilation environment for target system, you can compile with:

shell$ make ARCH=arm KERNEL_SRC=/home/fpga/src/linux-5.0.21-armv7-fpga KBUILD_EXTRA_SYMBOLS=/home/fpga/src/udmabuf/Module.symvers all

The ARCH variable specifies the architecture name.
The KERNEL_SRC variable specifies the Linux Kernel source code path. The KBUILD_EXTRA_SYMBOLS variable sepcifies the u-dma-buf Module.symbers file.

Self Compile

If your target system is capable of self-compiling the Linux Kernel module, you can compile it with:

shell$ make KBUILD_EXTRA_SYMBOLS=/home/fpga/src/u-dma-buf/Module.symvers all

You need the kernel source code in /lib/modules/$(shell uname -r)/build to compile.

Build in Linux Source Tree

It can also be compiled into the Linux Kernel Source Tree.

Make directory in Linux Kernel Source Tree.

shell$ mkdir <linux-source-tree>/drivers/staging/u-dma-buf-mgr

Copy files to Linux Kernel Source Tree.

shell$ cp Kconfig Makefile u-dma-buf.c <linux-source-tree>/drivers/staging/u-dma-buf-mgr

Add u-dma-buf-mgr to Kconfig

shell$ diff <linux-source-tree>/drivers/staging/Kconfig
  :
 source "drivers/staging/u-dma-buf/Kconfig"
+source "drivers/staging/u-dma-buf-mgr/Kconfig"
+

Add u-dma-buf to Makefile

shell$ diff <linux-source-tree>/drivers/staging/Makefile
  :
 obj-$(CONFIG_U_DMA_BUF)     += u-dma-buf/
+obj-$(CONFIG_U_DMA_BUF_MGR) += u-dma-buf-mgr/

Set CONFIG_U_DMA_BUF

For make menuconfig, set the following:

Device Drivers --->
  Staging drivers --->
    <M> u-dma-buf(User space mappable DMA Buffer) --->

Set CONFIG_U_DMA_BUF_MGR

--- u-dma-buf(User space mappable DMA Buffer) 
<M> u-dma-buf-mgr(User space mappable DMA Buffer Manager)
```console


If you write it directly in defconfig:

```console
shell$ diff <linux-source-tree>/arch/arm64/configs/xilinx_zynqmp_defconfig
   :
+CONFIG_U_DMA_BUF=m
+CONFIG_U_DMA_BUF_MGR=m

About

Kernel module to easily create or delete u-dma-bufUser space mappable DMA Buffer)

Resources

License

Stars

Watchers

Forks

Packages

No packages published