diff --git a/doc/build/device-drivers.md b/doc/build/device-drivers.md index 332ce54..76558bd 100644 --- a/doc/build/device-drivers.md +++ b/doc/build/device-drivers.md @@ -18,8 +18,8 @@ shell$ git clone https://github.com/ikwzm/PTTY_AXI4 ```console shell$ git archive --remote dtbocfg --prefix=dtbocfg/ --format=tar v0.0.3 | tar xf - -C drivers -shell$ git archive --remote fclkcfg --prefix=fclkcfg/ --format=tar v0.0.3 | tar xf - -C drivers -shell$ git archive --remote udmabuf --prefix=udmabuf/ --format=tar v0.10.0 | tar xf - -C drivers +shell$ git archive --remote fclkcfg --prefix=fclkcfg/ --format=tar v1.0.0 | tar xf - -C drivers +shell$ git archive --remote udmabuf --prefix=udmabuf/ --format=tar v1.1.0 | tar xf - -C drivers shell$ cd PTTY_AXI4; git checkout v1.0.0; cp -r src/drivers/zptty ../drivers; cd .. ``` diff --git a/doc/install/de0-nano-soc.md b/doc/install/de0-nano-soc.md index 9fab9e4..67fa500 100644 --- a/doc/install/de0-nano-soc.md +++ b/doc/install/de0-nano-soc.md @@ -5,7 +5,7 @@ ```console shell$ git clone git://github.com/ikwzm/FPGA-SoC-Linux shell$ cd FPGA-SoC-Linux -shell$ git checkout v0.7.1 +shell$ git checkout v0.7.2 shell$ git lfs pull ``` @@ -25,7 +25,7 @@ shell$ git lfs pull * debian9-rootfs-vanilla.tgz : Debian9 Root File System (use Git LFS) * linux-image-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb : Linux Image Package (use Git LFS) * linux-headers-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb : Linux Headers Package (use Git LFS) - * fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb : Device Drivers Package (use Git LFS) + * fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb : Device Drivers Package (use Git LFS) * fpga-soc-linux-services_0.0.9-1_armhf.deb : Device Services Package (use Git LFS) #### Format SD-Card @@ -51,7 +51,7 @@ shell# tar xfz debian9-rootfs-vanilla.tgz -C /mnt/u shell# mkdir /mnt/usb2/home/fpga/debian shell# cp linux-image-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb /mnt/usb2/home/fpga/debian shell# cp linux-headers-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb /mnt/usb2/home/fpga/debian -shell# cp fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb /mnt/usb2/home/fpga/debian +shell# cp fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb /mnt/usb2/home/fpga/debian shell# cp fpga-soc-linux-services_0.0.9-1_armhf.deb /mnt/usb2/home/fpga/debian shell$ cp -r target/de0-nano-soc/examples /mnt/usb2/home/fpga shell# umount mnt/usb1 diff --git a/doc/install/device-drivers.md b/doc/install/device-drivers.md index c7537ef..2706883 100644 --- a/doc/install/device-drivers.md +++ b/doc/install/device-drivers.md @@ -33,12 +33,12 @@ Setting up linux-image-4.14.21-armv7-fpga (4.14.21-armv7-fpga-2) ... ```console fpga@debian-fpga:~$ cd /home/fpga/debian -fpga@debian-fpga:~/debian$ sudo dpkg -i fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb +fpga@debian-fpga:~/debian$ sudo dpkg -i fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb Selecting previously unselected package fpga-soc-linux-drivers-4.14.21-armv7-fpga. -(Reading database ... 62106 files and directories currently installed.) -Preparing to unpack fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb ... -Unpacking fpga-soc-linux-drivers-4.14.21-armv7-fpga (0.1.1-1) ... -Setting up fpga-soc-linux-drivers-4.14.21-armv7-fpga (0.1.1-1) ... +(Reading database ... 81599 files and directories currently installed.) +Preparing to unpack fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb ... +Unpacking fpga-soc-linux-drivers-4.14.21-armv7-fpga (0.1.2-1) ... +Setting up fpga-soc-linux-drivers-4.14.21-armv7-fpga (0.1.2-1) ... ``` ```console @@ -70,10 +70,10 @@ Created symlink /etc/systemd/system/multi-user.target.wants/zptty.service → /e ```console fpga@debian-fpga:~$ sudo lsmod Module Size Used by -zptty 16384 0 fclkcfg 16384 0 udmabuf 20480 0 dtbocfg 16384 0 +zptty 16384 0 ``` ```console @@ -85,7 +85,8 @@ fpga@debian-fpga:~/debian$ sudo systemctl status device-tree-overlay.service Main PID: 1665 (code=exited, status=0/SUCCESS) CGroup: /system.slice/device-tree-overlay.service -Feb 21 23:03:05 debian-fpga systemd[1]: Started Device Tree Overlay Service.. +Mar 14 06:41:05 debian-fpga systemd[1]: Starting Device Tree Overlay Service.. +Mar 14 06:41:05 debian-fpga systemd[1]: Started Device Tree Overlay Service.. ``` ```console @@ -97,8 +98,8 @@ fpga@debian-fpga:~/debian$ sudo systemctl status udmabuf.service Main PID: 1687 (code=exited, status=0/SUCCESS) CGroup: /system.slice/udmabuf.service -Feb 21 23:03:06 debian-fpga systemd[1]: Started User space mappable DMA Buff.... -Hint: Some lines were ellipsized, use -l to show in full. +Mar 14 06:41:06 debian-fpga systemd[1]: Starting User space mappable DMA Buff.... +Mar 14 06:41:06 debian-fpga systemd[1]: Started User space mappable DMA Buff.... ``` ```console @@ -109,7 +110,20 @@ fpga@debian-fpga:~/debian$ sudo systemctl status zptty.service Process: 1694 ExecStart=/sbin/modprobe zptty (code=exited, status=0/SUCCESS) Main PID: 1694 (code=exited, status=0/SUCCESS) -Feb 21 23:03:06 debian-fpga systemd[1]: Started Pseudo TTY Driver for commun.... -Hint: Some lines were ellipsized, use -l to show in full. +Mar 14 06:42:06 debian-fpga systemd[1]: Starting Pseudo TTY Driver for commun.... +Mar 14 06:42:06 debian-fpga systemd[1]: Started Pseudo TTY Driver for commun.... +``` + +```console +fpga@debian-fpga:~/debian$ sudo systemctl status fpga-clock.service +● fpga-clock.service - FPGA Clock Service. + Loaded: loaded (/etc/systemd/system/fpga-clock.service; enabled; vendor prese + Active: active (exited) since Fri 2016-11-04 02:16:45 JST; 1 years 4 months a + Process: 1365 ExecStart=/sbin/modprobe fclkcfg (code=exited, status=0/SUCCESS) + Main PID: 1365 (code=exited, status=0/SUCCESS) + CGroup: /system.slice/fpga-clock.service + +Mar 14 06:42:06 debian-fpga systemd[1]: Starting FPGA Clock Service.... +Mar 14 06:42:06 debian-fpga systemd[1]: Started FPGA Clock Service.... ``` diff --git a/doc/install/zynq-pynqz1.md b/doc/install/zynq-pynqz1.md index 5e2ffb9..1ccad04 100644 --- a/doc/install/zynq-pynqz1.md +++ b/doc/install/zynq-pynqz1.md @@ -5,7 +5,7 @@ ```console shell$ git clone git://github.com/ikwzm/FPGA-SoC-Linux shell$ cd FPGA-SoC-Linux -shell$ git checkout v0.7.1 +shell$ git checkout v0.7.2 shell$ git lfs pull ``` @@ -23,7 +23,7 @@ shell$ git lfs pull * debian9-rootfs-vanilla.tgz : Debian9 Root File System (use Git LFS) * linux-image-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb : Linux Image Package (use Git LFS) * linux-headers-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb : Linux Headers Package (use Git LFS) - * fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb : Device Drivers Package (use Git LFS) + * fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb : Device Drivers Package (use Git LFS) * fpga-soc-linux-services_0.0.9-1_armhf.deb : Device Services Package (use Git LFS) #### Format SD-Card @@ -47,7 +47,7 @@ shell# tar xfz debian9-rootfs-vanilla.tgz -C /mnt/u shell# mkdir /mnt/usb2/home/fpga/debian shell# cp linux-image-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb /mnt/usb2/home/fpga/debian shell# cp linux-headers-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb /mnt/usb2/home/fpga/debian -shell# cp fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb /mnt/usb2/home/fpga/debian +shell# cp fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb /mnt/usb2/home/fpga/debian shell# cp fpga-soc-linux-services_0.0.9-1_armhf.deb /mnt/usb2/home/fpga/debian shell$ cp -r target/zynq-pynqz1/examples /mnt/usb2/home/fpga shell# umount mnt/usb1 diff --git a/doc/install/zynq-zybo-de0-nano-soc.md b/doc/install/zynq-zybo-de0-nano-soc.md index b989ac0..0888af6 100644 --- a/doc/install/zynq-zybo-de0-nano-soc.md +++ b/doc/install/zynq-zybo-de0-nano-soc.md @@ -7,7 +7,7 @@ It corresponds to boot of both ZYBO and DE0-Nano-SoC in one SD-Card. ```console shell$ git clone git://github.com/ikwzm/FPGA-SoC-Linux shell$ cd FPGA-SoC-Linux -shell$ git checkout v0.7.1 +shell$ git checkout v0.7.2 shell$ git lfs pull ``` #### Build boot files @@ -59,7 +59,7 @@ cp ../de0-nano-soc/u-boot/u-boot.img u-boot/u-boot.img * debian9-rootfs-vanilla.tgz : Debian9 Root File System (use Git LFS) * linux-image-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb : Linux Image Package (use Git LFS) * linux-headers-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb : Linux Headers Package (use Git LFS) - * fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb : Device Drivers Package (use Git LFS) + * fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb : Device Drivers Package (use Git LFS) * fpga-soc-linux-services_0.0.9-1_armhf.deb : Device Services Package (use Git LFS) #### Format SD-Card @@ -85,7 +85,7 @@ shell# tar xfz debian9-rootfs-vanilla.tgz -C /mnt/u shell# mkdir /mnt/usb2/home/fpga/debian shell# cp linux-image-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb /mnt/usb2/home/fpga/debian shell# cp linux-headers-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb /mnt/usb2/home/fpga/debian -shell# cp fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb /mnt/usb2/home/fpga/debian +shell# cp fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb /mnt/usb2/home/fpga/debian shell# cp fpga-soc-linux-services_0.0.9-1_armhf.deb /mnt/usb2/home/fpga/debian shell# umount mnt/usb1 shell# umount mnt/usb2 diff --git a/doc/install/zynq-zybo-z7.md b/doc/install/zynq-zybo-z7.md index 186550e..8793f2f 100644 --- a/doc/install/zynq-zybo-z7.md +++ b/doc/install/zynq-zybo-z7.md @@ -5,7 +5,7 @@ ```console shell$ git clone git://github.com/ikwzm/FPGA-SoC-Linux shell$ cd FPGA-SoC-Linux -shell$ git checkout v0.7.1 +shell$ git checkout v0.7.2 shell$ git lfs pull ``` @@ -22,7 +22,7 @@ shell$ git lfs pull * debian9-rootfs-vanilla.tgz : Debian9 Root File System (use Git LFS) * linux-image-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb : Linux Image Package (use Git LFS) * linux-headers-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb : Linux Headers Package (use Git LFS) - * fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb : Device Drivers Package (use Git LFS) + * fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb : Device Drivers Package (use Git LFS) * fpga-soc-linux-services_0.0.9-1_armhf.deb : Device Services Package (use Git LFS) #### Format SD-Card @@ -46,7 +46,7 @@ shell# tar xfz debian9-rootfs-vanilla.tgz -C /mnt/u shell# mkdir /mnt/usb2/home/fpga/debian shell# cp linux-image-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb /mnt/usb2/home/fpga/debian shell# cp linux-headers-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb /mnt/usb2/home/fpga/debian -shell# cp fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb /mnt/usb2/home/fpga/debian +shell# cp fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb /mnt/usb2/home/fpga/debian shell# cp fpga-soc-linux-services_0.0.9-1_armhf.deb /mnt/usb2/home/fpga/debian shell# umount mnt/usb1 shell# umount mnt/usb2 diff --git a/doc/install/zynq-zybo.md b/doc/install/zynq-zybo.md index a2c9126..aaddf24 100644 --- a/doc/install/zynq-zybo.md +++ b/doc/install/zynq-zybo.md @@ -5,7 +5,7 @@ ```console shell$ git clone git://github.com/ikwzm/FPGA-SoC-Linux shell$ cd FPGA-SoC-Linux -shell$ git checkout v0.7.1 +shell$ git checkout v0.7.2 shell$ git lfs pull ``` @@ -24,7 +24,7 @@ shell$ git lfs pull * debian9-rootfs-vanilla.tgz : Debian9 Root File System (use Git LFS) * linux-image-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb : Linux Image Package (use Git LFS) * linux-headers-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb : Linux Headers Package (use Git LFS) - * fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb : Device Drivers Package (use Git LFS) + * fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb : Device Drivers Package (use Git LFS) * fpga-soc-linux-services_0.0.9-1_armhf.deb : Device Services Package (use Git LFS) #### Format SD-Card @@ -48,7 +48,7 @@ shell# tar xfz debian9-rootfs-vanilla.tgz -C /mnt/u shell# mkdir /mnt/usb2/home/fpga/debian shell# cp linux-image-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb /mnt/usb2/home/fpga/debian shell# cp linux-headers-4.14.21-armv7-fpga_4.14.21-armv7-fpga-2_armhf.deb /mnt/usb2/home/fpga/debian -shell# cp fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb /mnt/usb2/home/fpga/debian +shell# cp fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb /mnt/usb2/home/fpga/debian shell# cp fpga-soc-linux-services_0.0.9-1_armhf.deb /mnt/usb2/home/fpga/debian shell# cp -r target/zynq-zybo/examples /mnt/usb2/home/fpga shell# umount mnt/usb1 diff --git a/drivers/debian/changelog b/drivers/debian/changelog index 3458d46..f8f482a 100644 --- a/drivers/debian/changelog +++ b/drivers/debian/changelog @@ -1,3 +1,8 @@ +fpga-soc-linux-drivers (0.1.2-1) unstable; urgency=low + + * Update udmabuf v1.1.0 + * Update fclkcfg v1.0.0 + fpga-soc-linux-drivers (0.1.1-1) unstable; urgency=low * Update udmabuf v0.10.0 diff --git a/drivers/fclkcfg/fclkcfg.c b/drivers/fclkcfg/fclkcfg.c index b5f5130..3c87938 100644 --- a/drivers/fclkcfg/fclkcfg.c +++ b/drivers/fclkcfg/fclkcfg.c @@ -1,6 +1,6 @@ /********************************************************************************* * - * Copyright (C) 2016-2017 Ichiro Kawazome + * Copyright (C) 2016-2018 Ichiro Kawazome * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,9 +44,9 @@ #include #include #include -#include "minor_number_allocator.h" #define DRIVER_NAME "fclkcfg" +#define DEVICE_MAX_NUM 32 #if (LINUX_VERSION_CODE >= 0x030B00) #define USE_DEV_GROUPS 1 @@ -56,6 +56,7 @@ static struct class* fclkcfg_sys_class = NULL; static dev_t fclkcfg_device_number = 0; +static DEFINE_IDA( fclkcfg_device_ida ); /** * struct fclk_driver_data - Device driver structure @@ -226,11 +227,6 @@ static const struct attribute_group* fclkcfg_attr_groups[] = { #define SET_SYS_CLASS_ATTRIBUTES(sys_class) {(sys_class)->dev_attrs = fclkcfg_device_attrs;} #endif -/** - * fclkcfg_device_minor_number_bitmap - */ -DECLARE_MINOR_NUMBER_ALLOCATOR(fclkcfg_device, 64); - /** * fclkcfg_platform_driver_probe() - Probe call for the device. * @@ -265,7 +261,7 @@ static int fclkcfg_platform_driver_probe(struct platform_device *pdev) */ dev_dbg(&pdev->dev, "get device_number start.\n"); { - int minor_number = fclkcfg_device_minor_number_new(); + int minor_number = ida_simple_get(&fclkcfg_device_ida, 0, DEVICE_MAX_NUM, GFP_KERNEL); if (minor_number < 0) { dev_err(&pdev->dev, "invalid or conflict minor number %d.\n", minor_number); retval = -ENODEV; @@ -282,7 +278,7 @@ static int fclkcfg_platform_driver_probe(struct platform_device *pdev) { this->clk = of_clk_get(pdev->dev.of_node, 0); if (IS_ERR_OR_NULL(this->clk)) { - dev_err(&pdev->dev, "clk_get failed for fclk0.\n"); + dev_err(&pdev->dev, "of_clk_get() failed.\n"); retval = PTR_ERR(this->clk); this->clk = NULL; goto failed; @@ -428,7 +424,7 @@ static int fclkcfg_platform_driver_probe(struct platform_device *pdev) this->device = NULL; } if (this->device_number){ - fclkcfg_device_minor_number_free(MINOR(this->device_number)); + ida_simple_remove(&fclkcfg_device_ida, MINOR(this->device_number)); this->device_number = 0; } kfree(this); @@ -468,7 +464,7 @@ static int fclkcfg_platform_driver_remove(struct platform_device *pdev) this->device = NULL; } if (this->device_number){ - fclkcfg_device_minor_number_free(MINOR(this->device_number)); + ida_simple_remove(&fclkcfg_device_ida, MINOR(this->device_number)); this->device_number = 0; } kfree(this); @@ -508,6 +504,7 @@ static void __exit fclkcfg_module_exit(void) if (fclkcfg_platform_driver_done ){platform_driver_unregister(&fclkcfg_platform_driver);} if (fclkcfg_sys_class != NULL){class_destroy(fclkcfg_sys_class);} if (fclkcfg_device_number != 0 ){unregister_chrdev_region(fclkcfg_device_number, 0);} + ida_destroy(&fclkcfg_device_ida); } /** @@ -517,7 +514,7 @@ static int __init fclkcfg_module_init(void) { int retval = 0; - fclkcfg_device_minor_number_allocator_initilize(); + ida_init(&fclkcfg_device_ida); retval = alloc_chrdev_region(&fclkcfg_device_number, 0, 0, DRIVER_NAME); if (retval != 0) { diff --git a/drivers/fclkcfg/minor_number_allocator.h b/drivers/fclkcfg/minor_number_allocator.h deleted file mode 100644 index 9bbc79b..0000000 --- a/drivers/fclkcfg/minor_number_allocator.h +++ /dev/null @@ -1,74 +0,0 @@ -/********************************************************************************* - * - * Copyright (C) 2016 Ichiro Kawazome - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ********************************************************************************/ -/* - * minor_number_allocator - */ -#ifndef _MINOR_NUMBER_ALLOCATOR_H_ -#define _MINOR_NUMBER_ALLOCATOR_H_ - -#include - -#define DECLARE_MINOR_NUMBER_ALLOCATOR(__name, __max_num) \ -DECLARE_BITMAP( __name ## _minor_number_bitmap, __max_num); \ -struct mutex __name ## _minor_number_bitmap_mutex; \ -static inline void __name ## _minor_number_allocator_initilize(void) \ -{ \ - mutex_init(&(__name ## _minor_number_bitmap_mutex)); \ - memset(&(__name ## _minor_number_bitmap), 0, sizeof(__name ## _minor_number_bitmap));\ -} \ -static inline int __name ## _minor_number_allocate(int num) \ -{ int status; \ - mutex_lock(&(__name ## _minor_number_bitmap_mutex)); \ - status = (0 == test_and_set_bit(num, __name ## _minor_number_bitmap)) ? 0 : -1; \ - mutex_unlock(&(__name ## _minor_number_bitmap_mutex)); \ - return status; \ -} \ -static inline int __name ## _minor_number_new(void) \ -{ \ - int num; \ - mutex_lock(&(__name ## _minor_number_bitmap_mutex)); \ - num = find_first_zero_bit(__name ## _minor_number_bitmap, __max_num); \ - if ((0 <= num) && (num < __max_num)) { \ - set_bit(num, __name ## _minor_number_bitmap); \ - } else { \ - num = -1; \ - } \ - mutex_unlock(&(__name ## _minor_number_bitmap_mutex)); \ - return num; \ -} \ -static inline void __name ## _minor_number_free(int num) \ -{ \ - mutex_lock(&(__name ## _minor_number_bitmap_mutex)); \ - clear_bit(num, __name ## _minor_number_bitmap); \ - mutex_unlock(&(__name ## _minor_number_bitmap_mutex)); \ -} \ - -#endif diff --git a/drivers/udmabuf/Readme.md b/drivers/udmabuf/Readme.md index 343385a..09a9d25 100644 --- a/drivers/udmabuf/Readme.md +++ b/drivers/udmabuf/Readme.md @@ -25,13 +25,12 @@ Figure 1. Architecture ## Supported platforms -* OS : Linux Kernel Version 3.6 - 3.8, 3.18, 4.4, 4.8, 4.12 (the author tested on 3.18, 4.4, 4.8 and 4.12). +* OS : Linux Kernel Version 3.6 - 3.8, 3.18, 4.4, 4.8, 4.12, 4.14 (the author tested on 3.18, 4.4, 4.8, 4.12, 4.14). * CPU: ARM Cortex-A9 (Xilinx ZYNQ / Altera CycloneV SoC) * CPU: ARM64 Cortex-A53 (Xilinx ZYNQ UltraScale+ MPSoC) * CPU: x86(64bit) However, verification is not enough. I hope the results from everyone. In addition, there is a limit to the following feature at the moment. - Can not control of the CPU cache by O_SYNC flag . Always CPU cache is valid. - - Can not control of the CPU cache of manually by sync_for_device or sync_for_cpu. - Can not various settings by the device tree. # Usage @@ -68,7 +67,7 @@ clean: ## Install -Load the udmabuf kernel driver using `insmod`. The size of a DMA buffer should be provided as an argument as follows. The device driver is created, and allocates a DMA buffer with the specified size. The maximum number of DMA buffers that can be allocated using `insmod` is 4 (udmabuf0/1/2/3). +Load the udmabuf kernel driver using `insmod`. The size of a DMA buffer should be provided as an argument as follows. The device driver is created, and allocates a DMA buffer with the specified size. The maximum number of DMA buffers that can be allocated using `insmod` is 8 (udmabuf0/1/2/3/4/5/6/7). ```Shell zynq$ insmod udmabuf.ko udmabuf0=1048576 diff --git a/drivers/udmabuf/minor_number_allocator.h b/drivers/udmabuf/minor_number_allocator.h deleted file mode 100644 index 9bbc79b..0000000 --- a/drivers/udmabuf/minor_number_allocator.h +++ /dev/null @@ -1,74 +0,0 @@ -/********************************************************************************* - * - * Copyright (C) 2016 Ichiro Kawazome - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ********************************************************************************/ -/* - * minor_number_allocator - */ -#ifndef _MINOR_NUMBER_ALLOCATOR_H_ -#define _MINOR_NUMBER_ALLOCATOR_H_ - -#include - -#define DECLARE_MINOR_NUMBER_ALLOCATOR(__name, __max_num) \ -DECLARE_BITMAP( __name ## _minor_number_bitmap, __max_num); \ -struct mutex __name ## _minor_number_bitmap_mutex; \ -static inline void __name ## _minor_number_allocator_initilize(void) \ -{ \ - mutex_init(&(__name ## _minor_number_bitmap_mutex)); \ - memset(&(__name ## _minor_number_bitmap), 0, sizeof(__name ## _minor_number_bitmap));\ -} \ -static inline int __name ## _minor_number_allocate(int num) \ -{ int status; \ - mutex_lock(&(__name ## _minor_number_bitmap_mutex)); \ - status = (0 == test_and_set_bit(num, __name ## _minor_number_bitmap)) ? 0 : -1; \ - mutex_unlock(&(__name ## _minor_number_bitmap_mutex)); \ - return status; \ -} \ -static inline int __name ## _minor_number_new(void) \ -{ \ - int num; \ - mutex_lock(&(__name ## _minor_number_bitmap_mutex)); \ - num = find_first_zero_bit(__name ## _minor_number_bitmap, __max_num); \ - if ((0 <= num) && (num < __max_num)) { \ - set_bit(num, __name ## _minor_number_bitmap); \ - } else { \ - num = -1; \ - } \ - mutex_unlock(&(__name ## _minor_number_bitmap_mutex)); \ - return num; \ -} \ -static inline void __name ## _minor_number_free(int num) \ -{ \ - mutex_lock(&(__name ## _minor_number_bitmap_mutex)); \ - clear_bit(num, __name ## _minor_number_bitmap); \ - mutex_unlock(&(__name ## _minor_number_bitmap_mutex)); \ -} \ - -#endif diff --git a/drivers/udmabuf/udmabuf.c b/drivers/udmabuf/udmabuf.c index e009318..d59f5c7 100644 --- a/drivers/udmabuf/udmabuf.c +++ b/drivers/udmabuf/udmabuf.c @@ -56,35 +56,18 @@ #include #include #include -#include "minor_number_allocator.h" #define DRIVER_NAME "udmabuf" #define DEVICE_NAME_FORMAT "udmabuf%d" #define DEVICE_MAX_NUM 256 #define UDMABUF_DEBUG 1 -#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) -#define SYNC_ENABLE 1 -#else -#define SYNC_ENABLE 0 -#endif - #if defined(CONFIG_ARM) || defined(CONFIG_ARM64) #define USE_VMA_FAULT 1 #else #define USE_VMA_FAULT 0 #endif -#if defined(CONFIG_ARM) -#define _PGPROT_NONCACHED(vm_page_prot) pgprot_noncached(vm_page_prot) -#define _PGPROT_WRITECOMBINE(vm_page_prot) pgprot_writecombine(vm_page_prot) -#define _PGPROT_DMACOHERENT(vm_page_prot) pgprot_dmacoherent(vm_page_prot) -#else -#define _PGPROT_NONCACHED(vm_page_prot) pgprot_writecombine(vm_page_prot) -#define _PGPROT_WRITECOMBINE(vm_page_prot) pgprot_writecombine(vm_page_prot) -#define _PGPROT_DMACOHERENT(vm_page_prot) pgprot_writecombine(vm_page_prot) -#endif - #if (LINUX_VERSION_CODE >= 0x030B00) #define USE_DEV_GROUPS 1 #else @@ -113,13 +96,43 @@ #include #endif +/** + * sync_mode(synchronous mode) value + */ +#define SYNC_MODE_INVALID (0x00) +#define SYNC_MODE_NONCACHED (0x01) +#define SYNC_MODE_WRITECOMBINE (0x02) +#define SYNC_MODE_DMACOHERENT (0x03) +#define SYNC_MODE_MASK (0x03) +#define SYNC_ALWAYS (0x04) + +/** + * _PGPROT_NONCACHED : vm_page_prot value when ((sync_mode & SYNC_MODE_MASK) == SYNC_MODE_NONCACHED ) + * _PGPROT_WRITECOMBINE : vm_page_prot value when ((sync_mode & SYNC_MODE_MASK) == SYNC_MODE_WRITECOMBINE) + * _PGPROT_DMACOHERENT : vm_page_prot value when ((sync_mode & SYNC_MODE_MASK) == SYNC_MODE_DMACOHERENT ) + */ +#if defined(CONFIG_ARM) +#define _PGPROT_NONCACHED(vm_page_prot) pgprot_noncached(vm_page_prot) +#define _PGPROT_WRITECOMBINE(vm_page_prot) pgprot_writecombine(vm_page_prot) +#define _PGPROT_DMACOHERENT(vm_page_prot) pgprot_dmacoherent(vm_page_prot) +#elif defined(CONFIG_ARM64) +#define _PGPROT_NONCACHED(vm_page_prot) pgprot_writecombine(vm_page_prot) +#define _PGPROT_WRITECOMBINE(vm_page_prot) pgprot_writecombine(vm_page_prot) +#define _PGPROT_DMACOHERENT(vm_page_prot) pgprot_writecombine(vm_page_prot) +#else +#define _PGPROT_NONCACHED(vm_page_prot) pgprot_noncached(vm_page_prot) +#define _PGPROT_WRITECOMBINE(vm_page_prot) pgprot_writecombine(vm_page_prot) +#define _PGPROT_DMACOHERENT(vm_page_prot) pgprot_writecombine(vm_page_prot) +#endif + static struct class* udmabuf_sys_class = NULL; +static DEFINE_IDA( udmabuf_device_ida ); static dev_t udmabuf_device_number = 0; static int dma_mask_bit = 32; static int msg_enable = 1; /** - * struct udmabuf_driver_data - Device driver structure + * struct udmabuf_driver_data - Udmabuf driver data structure */ struct udmabuf_driver_data { struct device* sys_dev; @@ -132,7 +145,6 @@ struct udmabuf_driver_data { size_t alloc_size; void* virt_addr; dma_addr_t phys_addr; -#if (SYNC_ENABLE == 1) int sync_mode; int sync_offset; size_t sync_size; @@ -140,7 +152,6 @@ struct udmabuf_driver_data { bool sync_owner; int sync_for_cpu; int sync_for_device; -#endif #if (USE_OF_RESERVED_MEM == 1) bool of_reserved_mem; #endif @@ -150,19 +161,9 @@ struct udmabuf_driver_data { }; /** - * - */ -#define SYNC_INVALID (0x00) -#define SYNC_NONCACHED (0x01) -#define SYNC_WRITECOMBINE (0x02) -#define SYNC_DMACOHERENT (0x03) -#define SYNC_MODE_MASK (0x03) -#define SYNC_ALWAYS (0x04) - -#if (SYNC_ENABLE == 1) -/** - * udmabuf_sync_for_cpu() - call dma_sync_single_for_cpu() - * returns: Success(0) + * udmabuf_sync_for_cpu() - call dma_sync_single_for_cpu() when (sync_for_cpu != 0) + * @this: Pointer to the udmabuf driver data structure. + * Return: Success(0) */ static int udmabuf_sync_for_cpu(struct udmabuf_driver_data* this) { @@ -180,11 +181,11 @@ static int udmabuf_sync_for_cpu(struct udmabuf_driver_data* this) } return 0; } -#endif -#if (SYNC_ENABLE == 1) + /** - * udmabuf_sync_for_device() - call dma_sync_single_for_device() - * returns: Success(0) + * udmabuf_sync_for_device() - call dma_sync_single_for_device() when (sync_for_device != 0) + * @this: Pointer to the udmabuf driver data structure. + * Return: Success(0) */ static int udmabuf_sync_for_device(struct udmabuf_driver_data* this) { @@ -202,7 +203,6 @@ static int udmabuf_sync_for_device(struct udmabuf_driver_data* this) } return 0; } -#endif #define DEF_ATTR_SHOW(__attr_name, __format, __value) \ static ssize_t udmabuf_show_ ## __attr_name(struct device *dev, struct device_attribute *attr, char *buf) \ @@ -238,7 +238,6 @@ static ssize_t udmabuf_set_ ## __attr_name(struct device *dev, struct device_att DEF_ATTR_SHOW(size , "%d\n" , this->size ); DEF_ATTR_SHOW(phys_addr , "%pad\n" , &this->phys_addr ); -#if (SYNC_ENABLE == 1) DEF_ATTR_SHOW(sync_mode , "%d\n" , this->sync_mode ); DEF_ATTR_SET( sync_mode , 0, 7, NO_ACTION, NO_ACTION ); DEF_ATTR_SHOW(sync_offset , "0x%lx\n", (long unsigned int)this->sync_offset ); @@ -252,7 +251,6 @@ DEF_ATTR_SHOW(sync_for_cpu , "%d\n" , this->sync_for_cpu DEF_ATTR_SET( sync_for_cpu , 0, 1, NO_ACTION, udmabuf_sync_for_cpu ); DEF_ATTR_SHOW(sync_for_device, "%d\n" , this->sync_for_device ); DEF_ATTR_SET( sync_for_device , 0, 1, NO_ACTION, udmabuf_sync_for_device); -#endif #if ((UDMABUF_DEBUG == 1) && (USE_VMA_FAULT == 1)) DEF_ATTR_SHOW(debug_vma , "%d\n" , this->debug_vma ); DEF_ATTR_SET( debug_vma , 0, 1, NO_ACTION, NO_ACTION ); @@ -261,7 +259,6 @@ DEF_ATTR_SET( debug_vma , 0, 1, NO_ACTION, NO_ACTION static struct device_attribute udmabuf_device_attrs[] = { __ATTR(size , 0444, udmabuf_show_size , NULL ), __ATTR(phys_addr , 0444, udmabuf_show_phys_addr , NULL ), -#if (SYNC_ENABLE == 1) __ATTR(sync_mode , 0664, udmabuf_show_sync_mode , udmabuf_set_sync_mode ), __ATTR(sync_offset , 0664, udmabuf_show_sync_offset , udmabuf_set_sync_offset ), __ATTR(sync_size , 0664, udmabuf_show_sync_size , udmabuf_set_sync_size ), @@ -269,7 +266,6 @@ static struct device_attribute udmabuf_device_attrs[] = { __ATTR(sync_owner , 0664, udmabuf_show_sync_owner , NULL ), __ATTR(sync_for_cpu , 0664, udmabuf_show_sync_for_cpu , udmabuf_set_sync_for_cpu ), __ATTR(sync_for_device, 0664, udmabuf_show_sync_for_device , udmabuf_set_sync_for_device), -#endif #if ((UDMABUF_DEBUG == 1) && (USE_VMA_FAULT == 1)) __ATTR(debug_vma , 0664, udmabuf_show_debug_vma , udmabuf_set_debug_vma ), #endif @@ -281,7 +277,6 @@ static struct device_attribute udmabuf_device_attrs[] = { static struct attribute *udmabuf_attrs[] = { &(udmabuf_device_attrs[0].attr), &(udmabuf_device_attrs[1].attr), -#if (SYNC_ENABLE == 1) &(udmabuf_device_attrs[2].attr), &(udmabuf_device_attrs[3].attr), &(udmabuf_device_attrs[4].attr), @@ -289,7 +284,6 @@ static struct attribute *udmabuf_attrs[] = { &(udmabuf_device_attrs[6].attr), &(udmabuf_device_attrs[7].attr), &(udmabuf_device_attrs[8].attr), -#endif #if ((UDMABUF_DEBUG == 1) && (USE_VMA_FAULT == 1)) &(udmabuf_device_attrs[9].attr), #endif @@ -312,7 +306,7 @@ static const struct attribute_group* udmabuf_attr_groups[] = { /** * udmabuf_driver_vma_open() - This is the driver open function. * @vma: Pointer to the vm area structure. - * returns: Success or error status. + * Return: None */ static void udmabuf_driver_vma_open(struct vm_area_struct* vma) { @@ -326,7 +320,7 @@ static void udmabuf_driver_vma_open(struct vm_area_struct* vma) /** * udmabuf_driver_vma_close() - This is the driver close function. * @vma: Pointer to the vm area structure. - * returns: Success or error status. + * Return: None */ static void udmabuf_driver_vma_close(struct vm_area_struct* vma) { @@ -341,7 +335,7 @@ static void udmabuf_driver_vma_close(struct vm_area_struct* vma) * _udmabuf_driver_vma_fault() - This is the driver nopage inline function. * @vma: Pointer to the vm area structure. * @vfm: Pointer to the vm fault structure. - * returns: Success or error status. + * Return: Success(=0) or error status(<0). */ static inline int _udmabuf_driver_vma_fault(struct vm_area_struct* vma, struct vm_fault* vmf) { @@ -385,7 +379,7 @@ static inline int _udmabuf_driver_vma_fault(struct vm_area_struct* vma, struct v /** * udmabuf_driver_vma_fault() - This is the driver nopage function. * @vfm: Pointer to the vm fault structure. - * returns: Success or error status. + * Return: Success(=0) or error status(<0). */ static int udmabuf_driver_vma_fault(struct vm_fault* vmf) { @@ -396,7 +390,7 @@ static int udmabuf_driver_vma_fault(struct vm_fault* vmf) * udmabuf_driver_vma_fault() - This is the driver nopage function. * @vma: Pointer to the vm area structure. * @vfm: Pointer to the vm fault structure. - * returns: Success or error status. + * Return: Success(=0) or error status(<0). */ static int udmabuf_driver_vma_fault(struct vm_area_struct* vma, struct vm_fault* vmf) { @@ -421,7 +415,7 @@ static const struct vm_operations_struct udmabuf_driver_vm_ops = { * udmabuf_driver_file_open() - This is the driver open function. * @inode: Pointer to the inode structure of this device. * @file: Pointer to the file structure. - * returns: Success or error status. + * Return: Success(=0) or error status(<0). */ static int udmabuf_driver_file_open(struct inode *inode, struct file *file) { @@ -439,7 +433,7 @@ static int udmabuf_driver_file_open(struct inode *inode, struct file *file) * udmabuf_driver_file_release() - This is the driver release function. * @inode: Pointer to the inode structure of this device. * @file: Pointer to the file structure. - * returns: Success. + * Return: Success(=0) or error status(<0). */ static int udmabuf_driver_file_release(struct inode *inode, struct file *file) { @@ -454,25 +448,23 @@ static int udmabuf_driver_file_release(struct inode *inode, struct file *file) * udmabuf_driver_file_mmap() - This is the driver memory map function. * @file: Pointer to the file structure. * @vma: Pointer to the vm area structure. - * returns: Success. + * Return: Success(=0) or error status(<0). */ static int udmabuf_driver_file_mmap(struct file *file, struct vm_area_struct* vma) { struct udmabuf_driver_data* this = file->private_data; -#if (USE_VMA_FAULT == 1) -#if (SYNC_ENABLE == 1) if ((file->f_flags & O_SYNC) | (this->sync_mode & SYNC_ALWAYS)) { switch (this->sync_mode & SYNC_MODE_MASK) { - case SYNC_NONCACHED : + case SYNC_MODE_NONCACHED : vma->vm_flags |= VM_IO; vma->vm_page_prot = _PGPROT_NONCACHED(vma->vm_page_prot); break; - case SYNC_WRITECOMBINE : + case SYNC_MODE_WRITECOMBINE : vma->vm_flags |= VM_IO; vma->vm_page_prot = _PGPROT_WRITECOMBINE(vma->vm_page_prot); break; - case SYNC_DMACOHERENT : + case SYNC_MODE_DMACOHERENT : vma->vm_flags |= VM_IO; vma->vm_page_prot = _PGPROT_DMACOHERENT(vma->vm_page_prot); break; @@ -480,14 +472,14 @@ static int udmabuf_driver_file_mmap(struct file *file, struct vm_area_struct* vm break; } } -#endif /* #if (SYNC_ENABLE == 1) */ - vma->vm_ops = &udmabuf_driver_vm_ops; vma->vm_private_data = this; vma->vm_pgoff = 0; + +#if (USE_VMA_FAULT == 1) + vma->vm_ops = &udmabuf_driver_vm_ops; udmabuf_driver_vma_open(vma); return 0; #else - vma->vm_pgoff = 0; return dma_mmap_coherent(this->dma_dev, vma, this->virt_addr, this->phys_addr, this->alloc_size); #endif } @@ -497,8 +489,8 @@ static int udmabuf_driver_file_mmap(struct file *file, struct vm_area_struct* vm * @file: Pointer to the file structure. * @buff: Pointer to the user buffer. * @count: The number of bytes to be written. - * @ppos: Pointer to the offset value - * returns: Success or error status. + * @ppos: Pointer to the offset value. + * Return: Transferd size. */ static ssize_t udmabuf_driver_file_read(struct file* file, char __user* buff, size_t count, loff_t* ppos) { @@ -521,20 +513,16 @@ static ssize_t udmabuf_driver_file_read(struct file* file, char __user* buff, si virt_addr = this->virt_addr + *ppos; xfer_size = (*ppos + count >= this->size) ? this->size - *ppos : count; -#if (SYNC_ENABLE == 1) if ((file->f_flags & O_SYNC) | (this->sync_mode & SYNC_ALWAYS)) dma_sync_single_for_cpu(this->dma_dev, phys_addr, xfer_size, DMA_FROM_DEVICE); -#endif if ((remain_size = copy_to_user(buff, virt_addr, xfer_size)) != 0) { result = 0; goto return_unlock; } -#if (SYNC_ENABLE == 1) if ((file->f_flags & O_SYNC) | (this->sync_mode & SYNC_ALWAYS)) dma_sync_single_for_device(this->dma_dev, phys_addr, xfer_size, DMA_FROM_DEVICE); -#endif *ppos += xfer_size; result = xfer_size; @@ -549,7 +537,7 @@ static ssize_t udmabuf_driver_file_read(struct file* file, char __user* buff, si * @buff: Pointer to the user buffer. * @count: The number of bytes to be written. * @ppos: Pointer to the offset value - * returns: Success or error status. + * Return: Transferd size. */ static ssize_t udmabuf_driver_file_write(struct file* file, const char __user* buff, size_t count, loff_t* ppos) { @@ -572,20 +560,16 @@ static ssize_t udmabuf_driver_file_write(struct file* file, const char __user* b virt_addr = this->virt_addr + *ppos; xfer_size = (*ppos + count >= this->size) ? this->size - *ppos : count; -#if (SYNC_ENABLE == 1) if ((file->f_flags & O_SYNC) | (this->sync_mode & SYNC_ALWAYS)) dma_sync_single_for_cpu(this->dma_dev, phys_addr, xfer_size, DMA_TO_DEVICE); -#endif if ((remain_size = copy_from_user(virt_addr, buff, xfer_size)) != 0) { result = 0; goto return_unlock; } -#if (SYNC_ENABLE == 1) if ((file->f_flags & O_SYNC) | (this->sync_mode & SYNC_ALWAYS)) dma_sync_single_for_device(this->dma_dev, phys_addr, xfer_size, DMA_TO_DEVICE); -#endif *ppos += xfer_size; result = xfer_size; @@ -599,7 +583,7 @@ static ssize_t udmabuf_driver_file_write(struct file* file, const char __user* b * @file: Pointer to the file structure. * @offset: File offset to seek. * @whence: Type of seek. - * returns: The new position. + * Return: The new position. */ static loff_t udmabuf_driver_file_llseek(struct file* file, loff_t offset, int whence) { @@ -640,18 +624,12 @@ static const struct file_operations udmabuf_driver_file_ops = { }; /** - * udmabuf_device_minor_number_allocator - */ -DECLARE_MINOR_NUMBER_ALLOCATOR(udmabuf_device, DEVICE_MAX_NUM); - -/** - * udmabuf_driver_create() - Create call for the device. - * - * @name: device name or NULL - * @parent: parent device or NULL - * @minor: minor_number or -1 - * @size: buffer size - * Returns device driver strcutre pointer + * udmabuf_driver_create() - Create udmabuf driver data structure. + * @name: device name or NULL. + * @parent: parent device or NULL. + * @minor: minor_number or -1. + * @size: buffer size. + * Return: Pointer to the udmabuf driver data structure or NULL. * * It does all the memory allocation and registration for the device. */ @@ -663,21 +641,26 @@ static struct udmabuf_driver_data* udmabuf_driver_create(const char* name, struc const unsigned int DONE_CHRDEV_ADD = (1 << 1); const unsigned int DONE_ALLOC_CMA = (1 << 2); const unsigned int DONE_DEVICE_CREATE = (1 << 3); +#if (USE_OF_RESERVED_MEM == 1) const unsigned int DONE_RESERVED_MEM = (1 << 4); +#endif /* - * alloc device_minor_number + * allocate device minor number */ { if ((0 <= minor) && (minor < DEVICE_MAX_NUM)) { - if (udmabuf_device_minor_number_allocate(minor) < 0) { - printk(KERN_ERR "invalid or conflict minor number %d.\n", minor); + if (ida_simple_get(&udmabuf_device_ida, minor, minor+1, GFP_KERNEL) < 0) { + printk(KERN_ERR "couldn't allocate minor number(=%d).\n", minor); goto failed; } - } else { - if ((minor = udmabuf_device_minor_number_new()) < 0) { - printk(KERN_ERR "couldn't allocate minor number.\n"); + } else if(minor == -1) { + if ((minor = ida_simple_get(&udmabuf_device_ida, 0, DEVICE_MAX_NUM, GFP_KERNEL)) < 0) { + printk(KERN_ERR "couldn't allocate new minor number.\n"); goto failed; } + } else { + printk(KERN_ERR "invalid minor number(=%d), valid range is 0 to %d\n", minor, DEVICE_MAX_NUM-1); + goto failed; } done |= DONE_ALLOC_MINOR; } @@ -697,10 +680,7 @@ static struct udmabuf_driver_data* udmabuf_driver_create(const char* name, struc this->device_number = MKDEV(MAJOR(udmabuf_device_number), minor); this->size = size; this->alloc_size = ((size + ((1 << PAGE_SHIFT) - 1)) >> PAGE_SHIFT) << PAGE_SHIFT; - } -#if (SYNC_ENABLE == 1) - { - this->sync_mode = SYNC_NONCACHED; + this->sync_mode = SYNC_MODE_NONCACHED; this->sync_offset = 0; this->sync_size = size; this->sync_direction = 0; @@ -708,7 +688,6 @@ static struct udmabuf_driver_data* udmabuf_driver_create(const char* name, struc this->sync_for_cpu = 0; this->sync_for_device = 0; } -#endif #if (USE_OF_RESERVED_MEM == 1) { this->of_reserved_mem = 0; @@ -831,16 +810,15 @@ static struct udmabuf_driver_data* udmabuf_driver_create(const char* name, struc if (done & DONE_RESERVED_MEM ) { of_reserved_mem_device_release(parent); } #endif if (done & DONE_DEVICE_CREATE) { device_destroy(udmabuf_sys_class, this->device_number);} - if (done & DONE_ALLOC_MINOR ) { udmabuf_device_minor_number_free(minor);} + if (done & DONE_ALLOC_MINOR ) { ida_simple_remove(&udmabuf_device_ida, minor);} if (this != NULL) { kfree(this); } return NULL; } /** - * udmabuf_driver_destroy() - Remove call for the device. - * - * @this: udmabuf driver data strcutre pointer - * Returns 0 or error status. + * udmabuf_driver_destroy() - Remove the udmabuf driver data structure. + * @this: Pointer to the udmabuf driver data structure. + * Return: Success(=0) or error status(<0). * * Unregister the device after releasing the resources. */ @@ -849,7 +827,7 @@ static int udmabuf_driver_destroy(struct udmabuf_driver_data* this) if (!this) return -ENODEV; - udmabuf_device_minor_number_free(MINOR(this->device_number)); + ida_simple_remove(&udmabuf_device_ida, MINOR(this->device_number)); if (msg_enable) { dev_info(this->sys_dev, "driver uninstalled\n"); } @@ -867,9 +845,8 @@ static int udmabuf_driver_destroy(struct udmabuf_driver_data* this) /** * udmabuf_platform_driver_probe() - Probe call for the device. - * * @pdev: handle to the platform device structure. - * Returns 0 on success, negative error otherwise. + * Return: Success(=0) or error status(<0). * * It does all the memory allocation and registration for the device. */ @@ -936,9 +913,8 @@ static int udmabuf_platform_driver_probe(struct platform_device *pdev) /** * udmabuf_platform_driver_remove() - Remove call for the device. - * - * @pdev: handle to the platform device structure. - * Returns 0 or error status. + * @pdev: Handle to the platform device structure. + * Return: Success(=0) or error status(<0). * * Unregister the device after releasing the resources. */ @@ -978,50 +954,80 @@ static struct platform_driver udmabuf_platform_driver = { static bool udmabuf_platform_driver_done = 0; /** - * + * static udmabuf driver description and functions. */ -static int udmabuf0 = 0; -static int udmabuf1 = 0; -static int udmabuf2 = 0; -static int udmabuf3 = 0; -module_param( udmabuf0, int, S_IRUGO); -module_param( udmabuf1, int, S_IRUGO); -module_param( udmabuf2, int, S_IRUGO); -module_param( udmabuf3, int, S_IRUGO); -MODULE_PARM_DESC( udmabuf0, "udmabuf0 buffer size"); -MODULE_PARM_DESC( udmabuf1, "udmabuf1 buffer size"); -MODULE_PARM_DESC( udmabuf2, "udmabuf2 buffer size"); -MODULE_PARM_DESC( udmabuf3, "udmabuf3 buffer size"); - -module_param( msg_enable , int, S_IRUGO); -MODULE_PARM_DESC( msg_enable , "udmabuf install/uninstall message enable"); +#define DEFINE_STATIC_UDMABUF_DRIVER(__num) \ + static int udmabuf ## __num = 0; \ + module_param( udmabuf ## __num, int, S_IRUGO); \ + MODULE_PARM_DESC(udmabuf ## __num, "udmabuf" #__num " buffer size"); \ + static struct udmabuf_driver_data* udmabuf_driver_ ## __num = NULL; + +#define CREATE_STATIC_UDMABUF_DRIVER(__num,parent) \ + if (udmabuf ## __num > 0) { \ + udmabuf_driver_ ## __num = udmabuf_driver_create(NULL, parent, __num, udmabuf ## __num);\ + if (IS_ERR_OR_NULL(udmabuf_driver_ ## __num)) { \ + udmabuf_driver_ ## __num = NULL; \ + printk(KERN_ERR "%s: couldn't create udmabuf%d driver\n", DRIVER_NAME, __num); \ + } \ + } -module_param( dma_mask_bit, int, S_IRUGO); -MODULE_PARM_DESC( dma_mask_bit, "udmabuf dma mask bit(default=32)"); +#define DESTROY_STATIC_UDMABUF_DRIVER(__num) \ + if (udmabuf_driver_ ## __num != NULL) { \ + udmabuf_driver_destroy(udmabuf_driver_ ## __num); \ + } -struct udmabuf_driver_data* udmabuf_driver[4] = {NULL,NULL,NULL,NULL}; +DEFINE_STATIC_UDMABUF_DRIVER(0); +DEFINE_STATIC_UDMABUF_DRIVER(1); +DEFINE_STATIC_UDMABUF_DRIVER(2); +DEFINE_STATIC_UDMABUF_DRIVER(3); +DEFINE_STATIC_UDMABUF_DRIVER(4); +DEFINE_STATIC_UDMABUF_DRIVER(5); +DEFINE_STATIC_UDMABUF_DRIVER(6); +DEFINE_STATIC_UDMABUF_DRIVER(7); -#define CREATE_UDMABUF_DRIVER(__num,parent) \ - if (udmabuf ## __num > 0) { \ - udmabuf_driver[__num] = udmabuf_driver_create(NULL, parent, __num, udmabuf ## __num);\ - if (IS_ERR_OR_NULL(udmabuf_driver[__num])) { \ - udmabuf_driver[__num] = NULL; \ - printk(KERN_ERR "%s: couldn't create udmabuf%d driver\n", DRIVER_NAME, __num); \ - } \ - } +static void create_static_udmabuf_drivers(struct device* parent) +{ + CREATE_STATIC_UDMABUF_DRIVER(0, parent); + CREATE_STATIC_UDMABUF_DRIVER(1, parent); + CREATE_STATIC_UDMABUF_DRIVER(2, parent); + CREATE_STATIC_UDMABUF_DRIVER(3, parent); + CREATE_STATIC_UDMABUF_DRIVER(4, parent); + CREATE_STATIC_UDMABUF_DRIVER(5, parent); + CREATE_STATIC_UDMABUF_DRIVER(6, parent); + CREATE_STATIC_UDMABUF_DRIVER(7, parent); +} + +static void destory_static_udmabuf_drivers(void) +{ + DESTROY_STATIC_UDMABUF_DRIVER(0); + DESTROY_STATIC_UDMABUF_DRIVER(1); + DESTROY_STATIC_UDMABUF_DRIVER(2); + DESTROY_STATIC_UDMABUF_DRIVER(3); + DESTROY_STATIC_UDMABUF_DRIVER(4); + DESTROY_STATIC_UDMABUF_DRIVER(5); + DESTROY_STATIC_UDMABUF_DRIVER(6); + DESTROY_STATIC_UDMABUF_DRIVER(7); +} + +/** + * other module parameters + */ +module_param( msg_enable , int, S_IRUGO); +MODULE_PARM_DESC( msg_enable , "udmabuf install/uninstall message enable"); + +module_param( dma_mask_bit, int, S_IRUGO); +MODULE_PARM_DESC( dma_mask_bit, "udmabuf dma mask bit(default=32)"); /** * udmabuf_module_exit() */ static void __exit udmabuf_module_exit(void) { - if (udmabuf_driver[3] != NULL){udmabuf_driver_destroy(udmabuf_driver[3]);} - if (udmabuf_driver[2] != NULL){udmabuf_driver_destroy(udmabuf_driver[2]);} - if (udmabuf_driver[1] != NULL){udmabuf_driver_destroy(udmabuf_driver[1]);} - if (udmabuf_driver[0] != NULL){udmabuf_driver_destroy(udmabuf_driver[0]);} + destory_static_udmabuf_drivers(); if (udmabuf_platform_driver_done ){platform_driver_unregister(&udmabuf_platform_driver);} if (udmabuf_sys_class != NULL){class_destroy(udmabuf_sys_class);} if (udmabuf_device_number != 0 ){unregister_chrdev_region(udmabuf_device_number, 0);} + ida_destroy(&udmabuf_device_ida); } /** @@ -1031,7 +1037,7 @@ static int __init udmabuf_module_init(void) { int retval = 0; - udmabuf_device_minor_number_allocator_initilize(); + ida_init(&udmabuf_device_ida); retval = alloc_chrdev_region(&udmabuf_device_number, 0, 0, DRIVER_NAME); if (retval != 0) { @@ -1049,10 +1055,7 @@ static int __init udmabuf_module_init(void) } SET_SYS_CLASS_ATTRIBUTES(udmabuf_sys_class); - CREATE_UDMABUF_DRIVER(0, NULL); - CREATE_UDMABUF_DRIVER(1, NULL); - CREATE_UDMABUF_DRIVER(2, NULL); - CREATE_UDMABUF_DRIVER(3, NULL); + create_static_udmabuf_drivers(NULL); retval = platform_driver_register(&udmabuf_platform_driver); if (retval) { diff --git a/fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb b/fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb deleted file mode 100644 index 955ac47..0000000 --- a/fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.1-1_armhf.deb +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:4cdaed074bd4fd8c447d50bc13f86e211ac8e4a134d4c369d8ca83ea715c969b -size 145858 diff --git a/fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb b/fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb new file mode 100644 index 0000000..59d0c04 --- /dev/null +++ b/fpga-soc-linux-drivers-4.14.21-armv7-fpga_0.1.2-1_armhf.deb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7715ee6876bd3a51f037ad3d3543ab0154411ec7bccdfc3f291c1d6a91ad30f4 +size 145962