flinkLinux
flink Linux Kernel Modules
 All Data Structures Files Functions Variables Macros Pages
flink_core.c File Reference

Core module for flink. More...

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include "flink.h"
Include dependency graph for flink_core.c:

Macros

#define MODULE_NAME   THIS_MODULE->name
 
#define SYSFS_CLASS_NAME   "flink"
 
#define MAX_DEV_NAME_LENGTH   15
 

Functions

 MODULE_AUTHOR ("Martin Zueger <martin@zueger.eu>")
 
 MODULE_DESCRIPTION ("fLink core module")
 
 MODULE_SUPPORTED_DEVICE ("none")
 
 MODULE_LICENSE ("Dual BSD/GPL")
 
int flink_open (struct inode *i, struct file *f)
 
int flink_relase (struct inode *i, struct file *f)
 
ssize_t flink_read (struct file *f, char __user *data, size_t size, loff_t *offset)
 
ssize_t flink_write (struct file *f, const char __user *data, size_t size, loff_t *offset)
 
long flink_ioctl (struct file *f, unsigned int cmd, unsigned long arg)
 
loff_t flink_llseek (struct file *f, loff_t off, int whence)
 
 module_init (flink_init)
 
 module_exit (flink_exit)
 
struct flink_deviceflink_device_alloc (void)
 Allocate a flink_device structure. More...
 
void flink_device_init (struct flink_device *fdev, struct flink_bus_ops *bus_ops, struct module *mod)
 Initialize a flink_device structure. More...
 
int flink_device_add (struct flink_device *fdev)
 Add a flink device to the system, making it live immediately. More...
 
int flink_device_remove (struct flink_device *fdev)
 Remove a flink device from the system. More...
 
int flink_device_delete (struct flink_device *fdev)
 Deletes a flink device and frees the allocated memory. All subdevices will be deleted, using flink_subdevice_remove() and flink_subdevice_delete(). More...
 
struct flink_deviceflink_get_device_by_id (u8 id)
 Get a flink device by its id. More...
 
struct flink_deviceflink_get_device_by_cdev (struct cdev *char_device)
 Get a flink device by cdev. More...
 
struct list_head * flink_get_device_list ()
 Get a list with all devices. More...
 
struct flink_subdeviceflink_subdevice_alloc (void)
 Allocate a flink_subdevice structure. More...
 
void flink_subdevice_init (struct flink_subdevice *fsubdev)
 Initialize a flink_subdevice structure, making it ready to add to a flink_device with flink_subdevice_add() More...
 
int flink_subdevice_add (struct flink_device *fdev, struct flink_subdevice *fsubdev)
 Add a flink subdevice to flink device. More...
 
int flink_subdevice_remove (struct flink_subdevice *fsubdev)
 Remove a flink subdevice from the parent device. More...
 
int flink_subdevice_delete (struct flink_subdevice *fsubdev)
 Deletes a flink subdevice and frees the allocated memory. More...
 
struct flink_subdeviceflink_get_subdevice_by_id (struct flink_device *fdev, u8 id)
 Get a flink subdevice by its id. More...
 
struct class * flink_get_sysfs_class (void)
 Get a flink sysfs class. More...
 
int flink_select_subdevice (struct file *f, u8 subdevice, bool excl)
 Select a subdevice for exclusive access. More...
 
 EXPORT_SYMBOL (flink_device_alloc)
 
 EXPORT_SYMBOL (flink_device_init)
 
 EXPORT_SYMBOL (flink_device_add)
 
 EXPORT_SYMBOL (flink_device_remove)
 
 EXPORT_SYMBOL (flink_device_delete)
 
 EXPORT_SYMBOL (flink_get_device_by_id)
 
 EXPORT_SYMBOL (flink_get_device_list)
 
 EXPORT_SYMBOL (flink_subdevice_alloc)
 
 EXPORT_SYMBOL (flink_subdevice_init)
 
 EXPORT_SYMBOL (flink_subdevice_add)
 
 EXPORT_SYMBOL (flink_subdevice_remove)
 
 EXPORT_SYMBOL (flink_subdevice_delete)
 
 EXPORT_SYMBOL (flink_get_subdevice_by_id)
 
 EXPORT_SYMBOL (flink_select_subdevice)
 
 EXPORT_SYMBOL (flink_get_sysfs_class)
 

Variables

struct file_operations flink_fops
 

Detailed Description

Core module for flink.

Contains functions to initialize, add and remove flink devices and subdevices

Author
Martin Züger
Urs Graf

Macro Definition Documentation

#define MAX_DEV_NAME_LENGTH   15
#define MODULE_NAME   THIS_MODULE->name
#define SYSFS_CLASS_NAME   "flink"

Function Documentation

EXPORT_SYMBOL ( flink_device_alloc  )
EXPORT_SYMBOL ( flink_device_init  )
EXPORT_SYMBOL ( flink_device_add  )
EXPORT_SYMBOL ( flink_device_remove  )
EXPORT_SYMBOL ( flink_device_delete  )
EXPORT_SYMBOL ( flink_get_device_by_id  )
EXPORT_SYMBOL ( flink_get_device_list  )
EXPORT_SYMBOL ( flink_subdevice_alloc  )
EXPORT_SYMBOL ( flink_subdevice_init  )
EXPORT_SYMBOL ( flink_subdevice_add  )
EXPORT_SYMBOL ( flink_subdevice_remove  )
EXPORT_SYMBOL ( flink_subdevice_delete  )
EXPORT_SYMBOL ( flink_get_subdevice_by_id  )
EXPORT_SYMBOL ( flink_select_subdevice  )
EXPORT_SYMBOL ( flink_get_sysfs_class  )
int flink_device_add ( struct flink_device fdev)

Add a flink device to the system, making it live immediately.

Parameters
fdevThe flink device to add.
Returns
int: A negative error code is returned on failure.
struct flink_device* flink_device_alloc ( void  )

Allocate a flink_device structure.

Returns
flink_device*: Pointer to the new flink_device structure, or NULL on failure.
int flink_device_delete ( struct flink_device fdev)

Deletes a flink device and frees the allocated memory. All subdevices will be deleted, using flink_subdevice_remove() and flink_subdevice_delete().

Parameters
fdevThe flink_device structure to delete.
Returns
int: A negative error code is returned on failure.

Here is the call graph for this function:

void flink_device_init ( struct flink_device fdev,
struct flink_bus_ops bus_ops,
struct module *  mod 
)

Initialize a flink_device structure.

Parameters
fdevThe structure to initialize
bus_opsThe flink_bus_ops for this device, remember them when adding them to system with flink_device_add().
modThe kernel module this flink uses for hardware access.
int flink_device_remove ( struct flink_device fdev)

Remove a flink device from the system.

Parameters
fdevThe flink device to remove.
Returns
int: A negative error code is returned on failure.
struct flink_device* flink_get_device_by_cdev ( struct cdev *  char_device)

Get a flink device by cdev.

Parameters
char_devicePointer to the cdev struct of a flink device.
Returns
flink_device*: Returns the flink device structure associated with the given cdev. NULL is returned if no suitable device is found.

Here is the caller graph for this function:

struct flink_device* flink_get_device_by_id ( u8  id)

Get a flink device by its id.

Parameters
idThe id of the flink device.
Returns
flink_device*: Returns the flink device structure with the given id. NULL is returned if no device is found with the given id.
struct list_head* flink_get_device_list ( void  )

Get a list with all devices.

Returns
list_head*: Returns a pointer to a list containing all flink devices. The list could be empty.
struct flink_subdevice* flink_get_subdevice_by_id ( struct flink_device fdev,
u8  id 
)

Get a flink subdevice by its id.

Parameters
fdevThe flink device containing the desired flink_subdevice.
idThe id of the flink device.
Returns
flink_subdevice*: Returns the flink_subdevice structure with the given id. NULL is returned if no subdevice is found with the given id.

Here is the caller graph for this function:

struct class* flink_get_sysfs_class ( void  )

Get a flink sysfs class.

Returns
class*: Pointer to the flink sysfs class structure.
long flink_ioctl ( struct file *  f,
unsigned int  cmd,
unsigned long  arg 
)

Here is the call graph for this function:

loff_t flink_llseek ( struct file *  f,
loff_t  off,
int  whence 
)
int flink_open ( struct inode *  i,
struct file *  f 
)

Here is the call graph for this function:

ssize_t flink_read ( struct file *  f,
char __user *  data,
size_t  size,
loff_t *  offset 
)
int flink_relase ( struct inode *  i,
struct file *  f 
)
int flink_select_subdevice ( struct file *  f,
u8  subdevice,
bool  excl 
)

Select a subdevice for exclusive access.

Parameters
f
subdevice
excl
Returns
int: A negative error code is returned on failure.

Here is the call graph for this function:

Here is the caller graph for this function:

int flink_subdevice_add ( struct flink_device fdev,
struct flink_subdevice fsubdev 
)

Add a flink subdevice to flink device.

Parameters
fdevThe flink device to which the subdevice is added.
@fsubdevThe flink subdevice to add.
Returns
int: A negative error code is returned on failure.
struct flink_subdevice* flink_subdevice_alloc ( void  )

Allocate a flink_subdevice structure.

Returns
flink_subdevice*: Pointer to the new flink_subdevice structure, or NULL on failure.
int flink_subdevice_delete ( struct flink_subdevice fsubdev)

Deletes a flink subdevice and frees the allocated memory.

Parameters
fsubdevThe flink_subdevice structure to delete.
Returns
int: A negative error code is returned on failure.

Here is the caller graph for this function:

void flink_subdevice_init ( struct flink_subdevice fsubdev)

Initialize a flink_subdevice structure, making it ready to add to a flink_device with flink_subdevice_add()

Parameters
fsubdevThe structure to initialize
int flink_subdevice_remove ( struct flink_subdevice fsubdev)

Remove a flink subdevice from the parent device.

Parameters
fsubdevThe flink subdevice to remove.
Returns
int: A negative error code is returned on failure.

Here is the caller graph for this function:

ssize_t flink_write ( struct file *  f,
const char __user *  data,
size_t  size,
loff_t *  offset 
)
MODULE_AUTHOR ( "Martin Zueger <martin@zueger.eu>"  )
MODULE_DESCRIPTION ( "fLink core module"  )
module_exit ( flink_exit  )
module_init ( flink_init  )
MODULE_LICENSE ( "Dual BSD/GPL"  )
MODULE_SUPPORTED_DEVICE ( "none"  )

Variable Documentation

struct file_operations flink_fops
Initial value:
= {
.owner = THIS_MODULE,
.open = flink_open,
.release = flink_relase,
.read = flink_read,
.write = flink_write,
.unlocked_ioctl = flink_ioctl,
.llseek = flink_llseek
}