#include #include "rwproc.h"
//
struct platform_device * test_uio_device;
u8 test_uio_driver_flag = 0;
static struct ctl_table_header * test_sysctl_header = NULL;
//
u32 debug_flag = 1;
static ctl_table test_sysctl_table[] =
{
{
.ctl_name = 1,
.procname = "debug_flag",
.data = &debug_flag,
.maxlen = sizeof(debug_flag),
.mode = 0644,
.proc_handler = &proc_dointvec
},
{ .ctl_name = 0 }
};
static ctl_table test_ipv4_table[] =
{
{
.ctl_name = 5002,
.procname = "test_server",
.mode = 0555,
.child = test_sysctl_table
},
{ .ctl_name = 0 }
};
static ctl_table test_net_table[] =
{
{
.ctl_name = NET_IPV4,
.procname = "ipv4",
.mode = 0555,
.child = test_ipv4_table
},
{ .ctl_name = 0 }
};
static ctl_table test_root_table[] =
{
{
.ctl_name = CTL_NET,
.procname = "net",
.mode = 0555,
.child = test_net_table
},
{ .ctl_name = 0 }
};
struct uio_info test_uio_info =
{
.name = "test_update_uio",
.version = "1.0",
.irq = UIO_IRQ_NONE,
};
int test_drv_probe(struct device * dev)
{
test_uio_info.mem[0].addr = (unsigned long)kmalloc(4096, GFP_KERNEL);
if((void *)test_uio_info.mem[0].addr == NULL)
{
printk(KERN_DEBUG"test_drv_probe fail 1.");
return 501;
}
test_uio_info.mem[0].memtype = UIO_MEM_LOGICAL;
test_uio_info.mem[0].size = 4096;
if( uio_register_device(dev, &test_uio_info) )
{
printk(KERN_DEBUG"test_drv_probe fail 2.");
return 502;
}
return 0;
}
int test_drv_remove(struct device * dev)
{
uio_unregister_device(&test_uio_info);
return 0;
}
struct device_driver test_uio_driver =
{
.name = "test_update_uio",
.bus = &platform_bus_type,
.probe = test_drv_probe,
.remove = test_drv_remove,
};
int config_init(void)
{
int ret;
//
test_uio_device = platform_device_register_simple("test_update_uio", -1, NULL, 0);
//
ret = driver_register(&test_uio_driver);
if(ret)
{
printk(KERN_DEBUG"config_init fail 1.");
return 503;
}
test_uio_driver_flag = 1;
//
test_sysctl_header = register_sysctl_table(test_root_table);
if( test_sysctl_header == NULL )
{
printk(KERN_DEBUG"config_init fail 2.");
return 504;
}
return 0;
}
int config_exit(void)
{
//
if(test_uio_driver_flag)
{
driver_unregister(&test_uio_driver);
}
//
platform_device_unregister(test_uio_device);
//
if(test_sysctl_header)
{
unregister_sysctl_table(test_sysctl_header);
}
return 0;
}