master/cdev.c
changeset 1268 d9599395e89b
parent 1264 e7882f246d7a
child 1272 288c982acd23
equal deleted inserted replaced
1267:75900030f0c3 1268:d9599395e89b
    48 #include "voe_handler.h"
    48 #include "voe_handler.h"
    49 #include "ioctl.h"
    49 #include "ioctl.h"
    50 
    50 
    51 /*****************************************************************************/
    51 /*****************************************************************************/
    52 
    52 
    53 /** \cond */
    53 static int eccdev_open(struct inode *, struct file *);
    54 
    54 static int eccdev_release(struct inode *, struct file *);
    55 int eccdev_open(struct inode *, struct file *);
    55 static long eccdev_ioctl(struct file *, unsigned int, unsigned long);
    56 int eccdev_release(struct inode *, struct file *);
    56 static int eccdev_mmap(struct file *, struct vm_area_struct *);
    57 long eccdev_ioctl(struct file *, unsigned int, unsigned long);
       
    58 int eccdev_mmap(struct file *, struct vm_area_struct *);
       
    59 
    57 
    60 static struct page *eccdev_vma_nopage(
    58 static struct page *eccdev_vma_nopage(
    61         struct vm_area_struct *, unsigned long, int *);
    59         struct vm_area_struct *, unsigned long, int *);
    62 
    60 
    63 /*****************************************************************************/
    61 /*****************************************************************************/
    64 
    62 
       
    63 /** File operation callbacks for the EtherCAT character device.
       
    64  */
    65 static struct file_operations eccdev_fops = {
    65 static struct file_operations eccdev_fops = {
    66     .owner          = THIS_MODULE,
    66     .owner          = THIS_MODULE,
    67     .open           = eccdev_open,
    67     .open           = eccdev_open,
    68     .release        = eccdev_release,
    68     .release        = eccdev_release,
    69     .unlocked_ioctl = eccdev_ioctl,
    69     .unlocked_ioctl = eccdev_ioctl,
    70     .mmap           = eccdev_mmap
    70     .mmap           = eccdev_mmap
    71 };
    71 };
    72 
    72 
       
    73 /** Callbacks for a virtual memory area retrieved with ecdevc_mmap().
       
    74  */
    73 struct vm_operations_struct eccdev_vm_ops = {
    75 struct vm_operations_struct eccdev_vm_ops = {
    74     .nopage = eccdev_vma_nopage
    76     .nopage = eccdev_vma_nopage
    75 };
    77 };
    76 
    78 
    77 /** \endcond */
       
    78 
       
    79 /*****************************************************************************/
    79 /*****************************************************************************/
    80 
    80 
    81 /** Private data structure for file handles.
    81 /** Private data structure for file handles.
    82  */
    82  */
    83 typedef struct {
    83 typedef struct {
    84     ec_cdev_t *cdev;
    84     ec_cdev_t *cdev; /**< Character device. */
    85     unsigned int requested;
    85     unsigned int requested; /**< Master wac requested via this file handle. */
    86     uint8_t *process_data;
    86     uint8_t *process_data; /**< Total process data area. */
    87     size_t process_data_size;
    87     size_t process_data_size; /**< Size of the \a process_data. */
    88 } ec_cdev_priv_t;
    88 } ec_cdev_priv_t;
    89 
    89 
    90 /*****************************************************************************/
    90 /*****************************************************************************/
    91 
    91 
    92 /** Constructor.
    92 /** Constructor.
  2561     }
  2561     }
  2562 }
  2562 }
  2563 
  2563 
  2564 /*****************************************************************************/
  2564 /*****************************************************************************/
  2565 
  2565 
       
  2566 /** Memory-map callback for the EtherCAT character device.
       
  2567  *
       
  2568  * The actual mapping will be done in the eccdev_vma_nopage() callback of the
       
  2569  * virtual memory area.
       
  2570  */
  2566 int eccdev_mmap(
  2571 int eccdev_mmap(
  2567         struct file *filp,
  2572         struct file *filp,
  2568         struct vm_area_struct *vma
  2573         struct vm_area_struct *vma
  2569         )
  2574         )
  2570 {
  2575 {
  2580     return 0;
  2585     return 0;
  2581 }
  2586 }
  2582 
  2587 
  2583 /*****************************************************************************/
  2588 /*****************************************************************************/
  2584 
  2589 
       
  2590 /** Page fault callback for a virtual memory area.
       
  2591  *
       
  2592  * Called at the first access on a virtual-memory area retrieved with
       
  2593  * ecdev_mmap().
       
  2594  */
  2585 struct page *eccdev_vma_nopage(
  2595 struct page *eccdev_vma_nopage(
  2586         struct vm_area_struct *vma,
  2596         struct vm_area_struct *vma, /**< Virtual memory area initialized by
  2587         unsigned long address,
  2597                                       the kernel. */
  2588         int *type
  2598         unsigned long address, /**< Requested virtual address. */
       
  2599         int *type /**< Type output parameter. */
  2589         )
  2600         )
  2590 {
  2601 {
  2591     unsigned long offset;
  2602     unsigned long offset;
  2592     struct page *page = NOPAGE_SIGBUS;
  2603     struct page *page = NOPAGE_SIGBUS;
  2593     ec_cdev_priv_t *priv = (ec_cdev_priv_t *) vma->vm_private_data;
  2604     ec_cdev_priv_t *priv = (ec_cdev_priv_t *) vma->vm_private_data;