Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
share.c File Reference
#include <linux/module.h>
#include <linux/string.h>
#include <linux/threads.h>
#include <linux/parport.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/kmod.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <asm/irq.h>

Go to the source code of this file.

Macros

#define PARPORT_DEFAULT_TIMESLICE   (HZ/5)
 

Functions

int parport_register_driver (struct parport_driver *drv)
 
void parport_unregister_driver (struct parport_driver *drv)
 
struct parportparport_get_port (struct parport *port)
 
void parport_put_port (struct parport *port)
 
struct parportparport_register_port (unsigned long base, int irq, int dma, struct parport_operations *ops)
 
void parport_announce_port (struct parport *port)
 
void parport_remove_port (struct parport *port)
 
is allocated by the caller and must not be

deallocated until the caller calls for that device.

The preemption callback function, , is called when this device driver has claimed access to the port but another device driver wants to use it. It is given as its parameter, and should return zero if it is willing for the system to release the port to another driver on its behalf. If it wants to keep control of the port it should return non-zero, and no action will be taken. It is good manners for the driver to try to release the port at the earliest opportunity after its preemption callback rejects a preemption attempt. Note that if a preemption callback is happy for preemption to go ahead, there is no need to release the port; it is done automatically. This function may not block, as it may be called from interrupt context. If the device driver does not support preemption, can be NULL.

The wake-up ("kick") callback function, , is called when the port is available to be claimed for exclusive access; that is, parport_claim() is guaranteed to succeed when called from inside the wake-up callback function. If the driver wants to claim the port it should do so; otherwise, it need not take any action. This function may not block, as it may be called from interrupt context. If the device driver does not want to be explicitly invited to claim the port in this way, can be NULL.

The interrupt handler, , is called when an interrupt arrives from the parallel port. Note that if a device driver wants to use interrupts it should use parport_enable_irq(), and can also check the irq member of the parport structure representing the port.

The parallel port (lowlevel) driver is the one that has called request_irq() and whose interrupt handler is called first. This handler does whatever needs to be done to the hardware to acknowledge the interrupt (for PC-style ports there is nothing special to be done). It then tells the IEEE 1284 code about the interrupt, which may involve reacting to an IEEE 1284 event depending on the current IEEE 1284 phase. After this, it calls . Needless to say, will be called from interrupt context, and may not block.

The PARPORT_DEV_EXCL flag is for preventing port sharing, and so should only be used when sharing the port with other device drivers is impossible and would lead to incorrect behaviour. Use it sparingly! Normally, will be zero.

This function returns a pointer to a structure that represents the device on the port, or NULL if there is not enough memory to allocate space for that structure.

struct pardeviceparport_register_device (struct parport *port, const char *name, int(*pf)(void *), void(*kf)(void *), void(*irq_func)(void *), int flags, void *handle)
 
void parport_unregister_device (struct pardevice *dev)
 
struct parportparport_find_number (int number)
 
struct parportparport_find_base (unsigned long base)
 
int parport_claim (struct pardevice *dev)
 
int parport_claim_or_block (struct pardevice *dev)
 
void parport_release (struct pardevice *dev)
 
irqreturn_t parport_irq_handler (int irq, void *dev_id)
 
 EXPORT_SYMBOL (parport_claim)
 
 EXPORT_SYMBOL (parport_claim_or_block)
 
 EXPORT_SYMBOL (parport_release)
 
 EXPORT_SYMBOL (parport_register_port)
 
 EXPORT_SYMBOL (parport_announce_port)
 
 EXPORT_SYMBOL (parport_remove_port)
 
 EXPORT_SYMBOL (parport_register_driver)
 
 EXPORT_SYMBOL (parport_unregister_driver)
 
 EXPORT_SYMBOL (parport_register_device)
 
 EXPORT_SYMBOL (parport_unregister_device)
 
 EXPORT_SYMBOL (parport_get_port)
 
 EXPORT_SYMBOL (parport_put_port)
 
 EXPORT_SYMBOL (parport_find_number)
 
 EXPORT_SYMBOL (parport_find_base)
 
 EXPORT_SYMBOL (parport_irq_handler)
 
 MODULE_LICENSE ("GPL")
 

Variables

unsigned long parport_default_timeslice = PARPORT_DEFAULT_TIMESLICE
 
int parport_default_spintime = DEFAULT_SPIN_TIME
 

Macro Definition Documentation

#define PARPORT_DEFAULT_TIMESLICE   (HZ/5)

Definition at line 39 of file share.c.

Function Documentation

EXPORT_SYMBOL ( parport_claim  )
EXPORT_SYMBOL ( parport_claim_or_block  )
EXPORT_SYMBOL ( parport_release  )
EXPORT_SYMBOL ( parport_register_port  )
EXPORT_SYMBOL ( parport_announce_port  )
EXPORT_SYMBOL ( parport_remove_port  )
EXPORT_SYMBOL ( parport_register_driver  )
EXPORT_SYMBOL ( parport_unregister_driver  )
EXPORT_SYMBOL ( parport_register_device  )
EXPORT_SYMBOL ( parport_unregister_device  )
EXPORT_SYMBOL ( parport_get_port  )
EXPORT_SYMBOL ( parport_put_port  )
EXPORT_SYMBOL ( parport_find_number  )
EXPORT_SYMBOL ( parport_find_base  )
EXPORT_SYMBOL ( parport_irq_handler  )
MODULE_LICENSE ( "GPL"  )
void parport_announce_port ( struct parport port)

parport_announce_port - tell device drivers about a parallel port : parallel port to announce

After a port driver has registered a parallel port with parport_register_port, and performed any necessary initialisation or adjustments, it should call parport_announce_port() in order to notify all device drivers that have called parport_register_driver(). Their attach() functions will be called, with as the parameter.

Definition at line 359 of file share.c.

int parport_claim ( struct pardevice dev)

parport_claim - claim access to a parallel port device : pointer to structure representing a device on the port

This function will not block and so can be used from interrupt context. If parport_claim() succeeds in claiming access to the port it returns zero and the port is available to use. It may fail (returning non-zero) if the port is in use by another driver and that driver is not willing to relinquish control of the port.

Definition at line 773 of file share.c.

int parport_claim_or_block ( struct pardevice dev)

parport_claim_or_block - claim access to a parallel port device : pointer to structure representing a device on the port

This behaves like parport_claim(), but will block if necessary to wait for the port to be free. A return value of 1 indicates that it slept; 0 means that it succeeded without needing to sleep. A negative error code indicates failure.

Definition at line 883 of file share.c.

struct parport* parport_find_base ( unsigned long  base)
read

parport_find_base - find a parallel port by base address : base I/O address

This returns the parallel port with the specified base address, or NULL if there is none.

There is an implicit parport_get_port() done already; to throw away the reference to the port that parport_find_base() gives you, use parport_put_port().

Definition at line 743 of file share.c.

struct parport* parport_find_number ( int  number)
read

parport_find_number - find a parallel port by number : parallel port number

This returns the parallel port with the specified number, or NULL if there is none.

There is an implicit parport_get_port() done already; to throw away the reference to the port that parport_find_number() gives you, use parport_put_port().

Definition at line 713 of file share.c.

struct parport* parport_get_port ( struct parport port)
read

parport_get_port - increment a port's reference count : the port

This ensures that a struct parport pointer remains valid until the matching parport_put_port() call.

Definition at line 224 of file share.c.

irqreturn_t parport_irq_handler ( int  irq,
void dev_id 
)

Definition at line 1005 of file share.c.

void parport_put_port ( struct parport port)

parport_put_port - decrement a port's reference count : the port

This should be called once for each call to parport_get_port(), once the port is no longer needed.

Definition at line 238 of file share.c.

struct pardevice* parport_register_device ( struct parport port,
const char name,
int(*)(void *)  pf,
void(*)(void *)  kf,
void(*)(void *)  irq_func,
int  flags,
void handle 
)
read

Definition at line 525 of file share.c.

int parport_register_driver ( struct parport_driver drv)

parport_register_driver - register a parallel port device driver : structure describing the driver

This can be called by a parallel port device driver in order to receive notifications about ports being found in the system, as well as ports no longer available.

The structure is allocated by the caller and must not be deallocated until after calling parport_unregister_driver().

The driver's attach() function may block. The port that attach() is given will be valid for the duration of the callback, but if the driver wants to take a copy of the pointer it must call parport_get_port() to do so. Calling parport_register_device() on that port will do this for you.

The driver's detach() function may block. The port that detach() is given will be valid for the duration of the callback, but if the driver wants to take a copy of the pointer it must call parport_get_port() to do so.

Returns 0 on success. Currently it always succeeds.

Definition at line 154 of file share.c.

struct parport* parport_register_port ( unsigned long  base,
int  irq,
int  dma,
struct parport_operations ops 
)
read

parport_register_port - register a parallel port : base I/O address : IRQ line : DMA channel : pointer to the port driver's port operations structure

When a parallel port (lowlevel) driver finds a port that should be made available to parallel port device drivers, it should call parport_register_port(). The , , and parameters are for the convenience of port drivers, and for ports where they aren't meaningful needn't be set to anything special. They can be altered afterwards by adjusting the relevant members of the parport structure that is returned and represents the port. They should not be tampered with after calling parport_announce_port, however.

If there are parallel port device drivers in the system that have registered themselves using parport_register_driver(), they are not told about the port at this time; that is done by parport_announce_port().

The structure is allocated by the caller, and must not be deallocated before calling parport_remove_port().

If there is no memory to allocate a new parport structure, this function will return NULL.

Definition at line 276 of file share.c.

void parport_release ( struct pardevice dev)

parport_release - give up access to a parallel port device : pointer to structure representing parallel port device

This function cannot fail, but it should not be called without the port claimed. Similarly, if the port is already claimed you should not try claiming it again.

Definition at line 943 of file share.c.

void parport_remove_port ( struct parport port)

parport_remove_port - deregister a parallel port : parallel port to deregister

When a parallel port driver is forcibly unloaded, or a parallel port becomes inaccessible, the port driver must call this function in order to deal with device drivers that still want to use it.

The parport structure associated with the port has its operations structure replaced with one containing 'null' operations that return errors or just don't do anything.

Any drivers that have registered themselves using parport_register_driver() are notified that the port is no longer accessible by having their detach() routines called with as the parameter.

Definition at line 413 of file share.c.

void parport_unregister_device ( struct pardevice dev)

parport_unregister_device - deregister a device on a parallel port : pointer to structure representing device

This undoes the effect of parport_register_device().

Definition at line 641 of file share.c.

void parport_unregister_driver ( struct parport_driver drv)

parport_unregister_driver - deregister a parallel port device driver : structure describing the driver that was given to parport_register_driver()

This should be called by a parallel port device driver that has registered itself using parport_register_driver() when it is about to be unloaded.

When it returns, the driver's attach() routine will no longer be called, and for each port that attach() was called for, the detach() routine will have been called.

All the driver's attach() and detach() calls are guaranteed to have finished by the time this function returns.

Definition at line 187 of file share.c.

Variable Documentation

int parport_default_spintime = DEFAULT_SPIN_TIME

Definition at line 42 of file share.c.

unsigned long parport_default_timeslice = PARPORT_DEFAULT_TIMESLICE

Definition at line 41 of file share.c.