mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-08-19 01:22:36 +08:00
更新了CFS调度器类的学习实例和博客信息...
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile for the LDD-LinuxDeviceDrivers.
|
||||
#
|
||||
# Author: gatieme
|
||||
# Create: 2016-07-29 15:50:46
|
||||
# Last modified: 2016-07-29 16:10:29
|
||||
# Description:
|
||||
# This program is loaded as a kernel(v2.6.18 or later) module.
|
||||
# Use "make install" to load it into kernel.
|
||||
# Use "make remove" to remove the module out of kernel.
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
ROOT=..
|
||||
#PLATFORM=$(shell $(ROOT)/systype.sh)
|
||||
#include $(ROOT)/Make.defines.$(PLATFORM)
|
||||
|
||||
MODULE_NAME := globalmem
|
||||
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
#CFG_FLAGS += -O2 -I./
|
||||
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
|
||||
|
||||
|
||||
|
||||
obj-m := $(MODULE_NAME).o #globalmem.o
|
||||
|
||||
else
|
||||
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
modules:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
modules_install:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules_install
|
||||
|
||||
|
||||
|
||||
insmod:
|
||||
sudo insmod $(MODULE_NAME).ko
|
||||
|
||||
reinsmod:
|
||||
sudo rmmod $(MODULE_NAME)
|
||||
sudo insmod $(MODULE_NAME).ko
|
||||
|
||||
github:
|
||||
cd $(ROOT) && make github
|
||||
|
||||
rmmod:
|
||||
sudo rmmod $(MODULE_NAME)
|
||||
|
||||
test :
|
||||
sudo ../injector/memInjector -l stack -m random -t word_0 --time 1 --timeout 3 -p 1
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
rm -f modules.order Module.symvers Module.markers
|
||||
|
||||
.PHNOY:
|
||||
modules modules_install clean
|
||||
|
||||
|
||||
|
||||
endif
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
<author@linuxdriver.cn>. All Rights Reserved.
|
||||
======================================================================*/
|
||||
|
||||
|
||||
|
||||
#include <linux/version.h>
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/fs.h>
|
||||
@@ -14,14 +18,25 @@
|
||||
#include <linux/init.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <asm/io.h>
|
||||
|
||||
// error: implicit declaration of function `kfree`
|
||||
#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 19, 0)
|
||||
#include <asm/system.h>
|
||||
#else
|
||||
#include <linux/slab.h>
|
||||
#endif
|
||||
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#define GLOBALMEM_SIZE 0x1000 /* 全局内存最大4K字节 */
|
||||
#define MEM_CLEAR 0x1 /* 清0全局内存 */
|
||||
#define GLOBALMEM_MAJOR 254 /* 预设的globalmem的主设备号 */
|
||||
#define GLOBALMEM_MAJOR 300 /* 预设的globalmem的主设备号 */
|
||||
|
||||
|
||||
/* globalmem的设备号 */
|
||||
static int globalmem_major = GLOBALMEM_MAJOR;
|
||||
module_param(globalmem_major, int, S_IRUGO);
|
||||
|
||||
static globalmem_major = GLOBALMEM_MAJOR;
|
||||
|
||||
/* globalmem设备结构体 */
|
||||
struct globalmem_dev
|
||||
@@ -34,6 +49,7 @@ struct globalmem_dev
|
||||
|
||||
struct globalmem_dev *globalmem_devp; /* 设备结构体指针 */
|
||||
|
||||
|
||||
/* 文件打开函数 */
|
||||
int globalmem_open(struct inode *inode, struct file *filp)
|
||||
{
|
||||
@@ -64,8 +80,8 @@ static int globalmem_ioctl(
|
||||
{
|
||||
memset(dev->mem, 0, GLOBALMEM_SIZE);
|
||||
printk(KERN_INFO "globalmem is set to zero\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
@@ -218,7 +234,14 @@ static const struct file_operations globalmem_fops =
|
||||
.llseek = globalmem_llseek,
|
||||
.read = globalmem_read,
|
||||
.write = globalmem_write,
|
||||
|
||||
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 36)
|
||||
.ioctl = globalmem_ioctl,
|
||||
#else
|
||||
.unlocked_ioctl = globalmem_ioctl,
|
||||
.compat_ioctl = globalmem_ioctl,
|
||||
#endif
|
||||
|
||||
.open = globalmem_open,
|
||||
.release = globalmem_release,
|
||||
};
|
||||
@@ -246,15 +269,17 @@ int globalmem_init(void)
|
||||
int result;
|
||||
dev_t devno = MKDEV(globalmem_major, 0);
|
||||
|
||||
/* 申请设备号*/
|
||||
if (globalmem_major)
|
||||
/* 申请设备号 */
|
||||
if (globalmem_major != 0)
|
||||
{
|
||||
result = register_chrdev_region(devno, 1, "globalmem");
|
||||
printk(KERN_INFO "register char device drivers [globalmem], MAJOR = %d\n", globalmem_major);
|
||||
}
|
||||
else /* 动态申请设备号 */
|
||||
{
|
||||
result = alloc_chrdev_region(&devno, 0, 1, "globalmem");
|
||||
globalmem_major = MAJOR(devno);
|
||||
printk(KERN_INFO "alloc char device drivers [globalmem], MAJOR = %d\n", globalmem_major);
|
||||
}
|
||||
|
||||
if (result < 0)
|
||||
@@ -288,10 +313,19 @@ void globalmem_exit(void)
|
||||
unregister_chrdev_region(MKDEV(globalmem_major, 0), 1); /*释放设备号*/
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Song Baohua");
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
|
||||
module_param(globalmem_major, int, S_IRUGO);
|
||||
//Driver Information
|
||||
#define DRIVER_VERSION "1.0.0"
|
||||
#define DRIVER_AUTHOR "Gatieme @ AderStep Inc..."
|
||||
#define DRIVER_DESC "Linux input module for Elo MultiTouch(MT) devices"
|
||||
#define DRIVER_LICENSE "Dual BSD/GPL"
|
||||
|
||||
// Kernel Module Information
|
||||
MODULE_VERSION(DRIVER_VERSION);
|
||||
MODULE_AUTHOR(DRIVER_AUTHOR);
|
||||
MODULE_DESCRIPTION(DRIVER_DESC);
|
||||
MODULE_LICENSE(DRIVER_LICENSE);
|
||||
|
||||
|
||||
module_init(globalmem_init);
|
||||
module_exit(globalmem_exit);
|
||||
|
||||
@@ -17,6 +17,14 @@ ROOT=..
|
||||
#PLATFORM=$(shell $(ROOT)/systype.sh)
|
||||
#include $(ROOT)/Make.defines.$(PLATFORM)
|
||||
|
||||
# my driver description
|
||||
DRIVER_VERSION := "1.0.0"
|
||||
DRIVER_AUTHOR := "Gatieme @ AderStep Inc..."
|
||||
DRIVER_DESC := "Linux input module for Elo MultiTouch(MT) devices"
|
||||
DRIVER_LICENSE := "Dual BSD/GPL"
|
||||
|
||||
|
||||
|
||||
MODULE_NAME := memory-engine
|
||||
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
obj-m := hello.o
|
||||
|
||||
else
|
||||
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
all:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,112 @@
|
||||
#include <linux/fs.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/module.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
|
||||
static ssize_t hello_read(struct file * file, char * buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
char *hello_str = "Hello, world!\n";
|
||||
|
||||
int len = strlen(hello_str); /* Don't include the null byte. */
|
||||
|
||||
/* * We only support reading the whole string at once. */
|
||||
if (count < len)
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* If file position is non-zero, then assume the string has
|
||||
* been read and indicate there is no more data to be read.
|
||||
*/
|
||||
if (*ppos != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Besides copying the string to the user provided buffer,
|
||||
* this function also checks that the user has permission to
|
||||
* write to the buffer, that it is mapped, etc.
|
||||
*/
|
||||
if (copy_to_user(buf, hello_str, len))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tell the user how much data we wrote.
|
||||
*/
|
||||
*ppos = len;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
static const struct file_operations hello_fops =
|
||||
{
|
||||
.owner = THIS_MODULE,
|
||||
.read = hello_read,
|
||||
};
|
||||
|
||||
|
||||
static struct miscdevice hello_dev =
|
||||
{
|
||||
/*
|
||||
* We don't care what minor number we end up with, so tell the
|
||||
* kernel to just pick one.
|
||||
*/
|
||||
MISC_DYNAMIC_MINOR,
|
||||
/*
|
||||
* Name ourselves /dev/hello.
|
||||
*/
|
||||
"hello",
|
||||
/*
|
||||
* What functions to call when a program performs file
|
||||
* operations on the device.
|
||||
*/
|
||||
&hello_fops
|
||||
};
|
||||
|
||||
|
||||
static int __init hello_init(void)
|
||||
{
|
||||
int ret;
|
||||
/*
|
||||
* Create the "hello" device in the /sys/class/misc directory.
|
||||
* Udev will automatically create the /dev/hello device using
|
||||
* the default rules.
|
||||
*/
|
||||
ret = misc_register(&hello_dev);
|
||||
if (ret != 0)
|
||||
{
|
||||
printk(KERN_ERR
|
||||
"Unable to register \"Hello, world!\" misc devicen");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
module_init(hello_init);
|
||||
|
||||
|
||||
static void __exit hello_exit(void)
|
||||
{
|
||||
misc_deregister(&hello_dev);
|
||||
}
|
||||
module_exit(hello_exit);
|
||||
|
||||
|
||||
/* Driver Information */
|
||||
#define DRIVER_VERSION "1.0.0"
|
||||
#define DRIVER_AUTHOR "Gatieme @ AderStep Inc..."
|
||||
#define DRIVER_DESC "Linux input module for Elo MultiTouch(MT) devices"
|
||||
#define DRIVER_LICENSE "Dual BSD/GPL"
|
||||
|
||||
/* Kernel Module Information */
|
||||
MODULE_VERSION(DRIVER_VERSION);
|
||||
MODULE_AUTHOR(DRIVER_AUTHOR);
|
||||
MODULE_DESCRIPTION(DRIVER_DESC);
|
||||
MODULE_LICENSE(DRIVER_LICENSE);
|
||||
|
||||
|
||||
module_init(globalmem_init);
|
||||
module_exit(globalmem_exit);
|
||||
@@ -0,0 +1 @@
|
||||
cmd_/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.ko := aarch64-linux-gnu-ld -EL -r -T /usr/src/linux-headers-3.14.0/scripts/module-common.lds --build-id -o /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.ko /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.o /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.mod.o
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.ko
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.o
|
||||
@@ -0,0 +1,19 @@
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
obj-m := hello.o
|
||||
|
||||
else
|
||||
|
||||
#KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
KERNELDIR ?= /usr/src/linux-headers-3.14.0
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
all:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,43 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
|
||||
/*
|
||||
* print the module information
|
||||
*/
|
||||
static void print_module(void)
|
||||
{
|
||||
struct module *mod;
|
||||
|
||||
printk(KERN_ALERT "this module: %p==%p\n", &__this_module, THIS_MODULE);
|
||||
printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state);
|
||||
printk(KERN_ALERT "module name: %s\n", THIS_MODULE->name);
|
||||
|
||||
list_for_each_entry(mod, *(&THIS_MODULE->list.prev), list);
|
||||
printk(KERN_ALERT "module name: %s\n", mod->name);
|
||||
printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state);
|
||||
}
|
||||
|
||||
|
||||
static int hello_init(void)
|
||||
{
|
||||
print_module( );
|
||||
|
||||
printk(KERN_ALERT "run in cpu %d\n", get_cpu());
|
||||
|
||||
printk(KERN_ALERT "PAGE_OFFSET : 0x%lx, TASK_SIZE : 0x%lx", PAGE_OFFSET, TASK_SIZE);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void hello_exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
module_init(hello_init);
|
||||
module_exit(hello_exit);
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/vermagic.h>
|
||||
#include <linux/compiler.h>
|
||||
|
||||
MODULE_INFO(vermagic, VERMAGIC_STRING);
|
||||
|
||||
__visible struct module __this_module
|
||||
__attribute__((section(".gnu.linkonce.this_module"))) = {
|
||||
.name = KBUILD_MODNAME,
|
||||
.init = init_module,
|
||||
#ifdef CONFIG_MODULE_UNLOAD
|
||||
.exit = cleanup_module,
|
||||
#endif
|
||||
.arch = MODULE_ARCH_INIT,
|
||||
};
|
||||
|
||||
static const struct modversion_info ____versions[]
|
||||
__used
|
||||
__attribute__((section("__versions"))) = {
|
||||
{ 0x846a1dd9, __VMLINUX_SYMBOL_STR(module_layout) },
|
||||
{ 0x27e1a049, __VMLINUX_SYMBOL_STR(printk) },
|
||||
};
|
||||
|
||||
static const char __module_depends[]
|
||||
__used
|
||||
__attribute__((section(".modinfo"))) =
|
||||
"depends=";
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
kernel//home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.ko
|
||||
Reference in New Issue
Block a user