-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
whitespaces to tab. Adding header and comments.
- Loading branch information
Showing
2 changed files
with
122 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* UIO demonstration driver catching keyboard events | ||
* | ||
* Copyright (C) 2024 Smile | ||
* Author: Antoine Bax de keating <[email protected]> | ||
*/ | ||
|
||
#include <linux/kernel.h> /* printk() */ | ||
#include <linux/module.h> /* modules */ | ||
#include <linux/init.h> /* module_{init,exit}() */ | ||
#include <linux/uio_driver.h> | ||
#include <linux/device.h> | ||
#include <linux/device.h> | ||
#include <linux/slab.h> /* kzalloc */ | ||
|
||
MODULE_LICENSE("GPL"); | ||
|
@@ -22,12 +30,13 @@ char *mem_area; | |
|
||
static irqreturn_t uio_handler(int irq, struct uio_info *dev_info) | ||
{ | ||
static unsigned int irq_count = 0; | ||
static unsigned int irq_count; | ||
|
||
pr_info("UIO handler"); | ||
irq_count++; | ||
memcpy(mem_area, &irq_count, sizeof(irq_count)); | ||
|
||
irq_count++; | ||
memcpy(mem_area, &irq_count, sizeof(irq_count)); | ||
|
||
return IRQ_HANDLED; | ||
} | ||
|
||
|
@@ -41,60 +50,57 @@ static void uio_release(struct device *dev) | |
*/ | ||
static int __init uio_kbd_init(void) | ||
{ | ||
int ret; | ||
|
||
dev = kzalloc(sizeof(struct device), GFP_KERNEL); | ||
dev_set_name(dev, "uio_kbd_device"); | ||
dev->release = uio_release; | ||
ret = device_register(dev); | ||
if (ret < 0){ | ||
kfree(dev); | ||
pr_warn("Failing to register uio_kbd device\n"); | ||
return ret; | ||
} | ||
|
||
|
||
|
||
mem_area = kzalloc(PAGE_SIZE, GFP_KERNEL); | ||
|
||
info = kzalloc(sizeof(struct uio_info), GFP_KERNEL); | ||
info->name = "uio_kbd_device"; | ||
info->version = "0.0.1"; | ||
info->irq = irq; | ||
info->irq_flags = IRQF_SHARED; | ||
info->handler = uio_handler; | ||
|
||
info->mem[0].name = "basic_mem_map"; | ||
info->mem[0].memtype = UIO_MEM_LOGICAL; | ||
info->mem[0].addr = (phys_addr_t) mem_area; | ||
info->mem[0].size = sizeof(mem_area); | ||
|
||
|
||
ret = uio_register_device(dev, info); | ||
if (ret < 0) { | ||
device_unregister(dev); | ||
kfree(dev); | ||
kfree(info); | ||
kfree(mem_area); | ||
pr_warn("Failing to register uio_kbd UIO device\n"); | ||
return ret; | ||
} | ||
|
||
pr_info( "Registered UIO handler for IRQ=%d\n", irq); | ||
return 0; | ||
|
||
int ret; | ||
|
||
dev = kzalloc(sizeof(struct device), GFP_KERNEL); | ||
dev_set_name(dev, "uio_kbd_device"); | ||
dev->release = uio_release; | ||
ret = device_register(dev); | ||
if (ret < 0) { | ||
kfree(dev); | ||
pr_warn("Failing to register uio_kbd device\n"); | ||
return ret; | ||
} | ||
|
||
|
||
|
||
mem_area = kzalloc(PAGE_SIZE, GFP_KERNEL); | ||
|
||
info = kzalloc(sizeof(struct uio_info), GFP_KERNEL); | ||
info->name = "uio_kbd_device"; | ||
info->version = "0.0.1"; | ||
info->irq = irq; | ||
info->irq_flags = IRQF_SHARED; | ||
info->handler = uio_handler; | ||
|
||
info->mem[0].name = "basic_mem_map"; | ||
info->mem[0].memtype = UIO_MEM_LOGICAL; | ||
info->mem[0].addr = (phys_addr_t) mem_area; | ||
info->mem[0].size = sizeof(mem_area); | ||
|
||
ret = uio_register_device(dev, info); | ||
if (ret < 0) { | ||
device_unregister(dev); | ||
kfree(dev); | ||
kfree(info); | ||
kfree(mem_area); | ||
pr_warn("Failing to register uio_kbd UIO device\n"); | ||
return ret; | ||
} | ||
|
||
pr_info("Registered UIO handler for IRQ=%d\n", irq); | ||
return 0; | ||
} | ||
|
||
static void __exit uio_kbd_exit(void) | ||
{ | ||
uio_unregister_device(info); | ||
device_unregister(dev); | ||
pr_info("Un-Registered UIO handler for IRQ=%d\n", irq); | ||
kfree(info); | ||
kfree(dev); | ||
kfree(mem_area); | ||
uio_unregister_device(info); | ||
device_unregister(dev); | ||
pr_info("Un-Registered UIO handler for IRQ=%d\n", irq); | ||
kfree(info); | ||
kfree(dev); | ||
kfree(mem_area); | ||
} | ||
|
||
module_init(uio_kbd_init); | ||
module_exit(uio_kbd_exit); | ||
|