/home/hillier_g/checkout/most4linux/most-kernel/most-base.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright(c) Siemens AG, Muenchen, Germany, 2005, 2006, 2007
00003  *                           Bernhard Walle <bernhard.walle@gmx.de>
00004  *                           Gernot Hillier <gernot.hillier@siemens.com>
00005  *
00006  * ----------------------------------------------------------------------------
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License version 2 as 
00009  * published by the Free Software Foundation;
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  * ----------------------------------------------------------------------------
00020  */
00021 #ifdef HAVE_CONFIG_H
00022 #include "config/config.h"
00023 #endif
00024 #ifndef MOST_BASE
00025 #define MOST_BASE
00026 
00027 #ifdef __KERNEL__
00028 
00037 #include <linux/interrupt.h>
00038 #include <linux/spinlock.h>
00039 #include <linux/seq_file.h>
00040 
00041 #ifdef RT_RTDM
00042 #   include <rtdm/rtdm_driver.h>
00043 #endif
00044 
00045 #include "most-common.h"
00046 #include "most-constants.h" 
00047 
00048 
00049 /*
00050  * Forward declarations -------------------------------------------------------
00051  */
00052 struct most_dev;
00053 
00054 /*
00055  * Typedefs -------------------------------------------------------------------
00056  */
00057 
00065 typedef u32 (*readreg_func) (struct most_dev* dev, u32 addr);
00066 
00074 typedef void (*writereg_func) (struct most_dev* dev, u32 val, u32 addr);
00075 
00086 typedef void (*changereg_func) (struct most_dev     *dev, 
00087                                 u32                 address, 
00088                                 u32                 value, 
00089                                 u32                 mask);
00090 
00102 typedef int (*read_os8104_func) (struct most_dev*   dev,
00103                                  unsigned char      *dest, 
00104                                  size_t             len, 
00105                                  u32                addr);
00106 
00117 typedef int (*write_os8104_func) (struct most_dev*  dev,
00118                                   unsigned char     *src,
00119                                   size_t            len,
00120                                   u32               addr);
00121 
00139 typedef void (*intset_func) (struct most_dev      *dev,
00140                              unsigned int         interrupts, 
00141                              unsigned int         mask,
00142                              unsigned int         *oldmask);
00143 
00147 typedef void (*intclear_func) (struct most_dev    *dev,
00148                                unsigned int        interrupts);
00149 
00156 typedef void (*reset_func) (struct most_dev *dev);
00157 
00161 struct dma_buffer 
00162 {
00163     dma_addr_t      addr_bus;           
00164     void            *addr_virt;         
00166     unsigned int    size;               
00167 };
00168 
00176 typedef int (*dma_alloc_fun) (struct most_dev *dev, struct dma_buffer *buf);
00177 
00185 typedef void (*dma_dealloc_fun) (struct most_dev *dev, struct dma_buffer *buf);
00186 
00194 typedef int (*probe_func)(struct most_dev *dev);
00195 
00201 typedef int (*remove_func)(struct most_dev *dev);
00202 
00209 typedef void (*irq_func)(struct most_dev *dev, unsigned int intstatus);
00210 
00216 typedef void (*proc_show_func)(struct seq_file *file);
00217 
00221 typedef int (*feature_fun)(struct most_dev *dev);
00222 
00233 typedef void (*usage_fun)(struct most_dev *dev, int change);
00234 
00235 /*
00236  * Types ----------------------------------------------------------------------
00237  */
00238 
00242 struct most_ops {
00243     readreg_func       readreg;        
00244     writereg_func      writereg;       
00245     changereg_func     changereg;      
00246     read_os8104_func   readreg8104;    
00247     write_os8104_func  writereg8104;   
00248     intset_func        intset;         
00249     intclear_func      intclear;       
00250     reset_func         reset;          
00251     dma_alloc_fun      dma_allocate;   
00252     dma_dealloc_fun    dma_deallocate; 
00253     feature_fun        features;       
00254 };
00255 
00259 struct most_ops_rt {
00260     readreg_func       readreg;        
00261     writereg_func      writereg;       
00262 };
00263 
00264 
00273 struct most_dev {
00274     spinlock_t         lock;           
00278     struct list_head   list;           
00279     int                major_device_no;
00283     int                card_number;    
00285     char               name[20];       
00288     u64                serial_number;  
00289     unsigned char      product_id;     
00290     void               *impl;          
00292     usage_fun          manage_usage;   
00293     struct most_ops    ops;            
00294 #ifdef RT_RTDM
00295     struct most_ops_rt rt_ops;         
00296 #endif
00297 };
00298 
00302 #define most_readreg(dev, addr)                             \
00303     (dev)->ops.readreg((dev), addr)
00304 
00308 #define most_writereg(dev, value, addr)                     \
00309     (dev)->ops.writereg((dev), (value), (addr))
00310 
00314 #define most_changereg(dev, addr, value, mask)              \
00315     (dev)->ops.changereg((dev), (addr), (value), (mask))
00316 
00320 #define most_readreg8104(dev, dest, len, addr)              \
00321     (dev)->ops.readreg8104((dev), (dest), (len), (addr))
00322 
00326 #define most_writereg8104(dev, src, len, addr)              \
00327     (dev)->ops.writereg8104((dev), (src), (len), (addr))
00328 
00332 #define most_intset(dev, interrupts, mask, oldmask)         \
00333     (dev)->ops.intset((dev), (interrupts), (mask), (oldmask))
00334 
00338 #define most_intclear(dev, interrupts)                      \
00339     (dev)->ops.intclear((dev), (interrupts))
00340 
00344 #define most_dma_allocate(dev, dma_buffer)                  \
00345     (dev)->ops.dma_allocate(dev, dma_buffer)
00346 
00350 #define most_dma_deallocate(dev, dma_buffer)                \
00351     (dev)->ops.dma_deallocate(dev, dma_buffer)
00352 
00356 #define most_reset(dev)                                     \
00357     (dev)->ops.reset((dev))
00358 
00362 #define most_features(dev)                                  \
00363     (dev)->ops.features(dev)
00364 
00368 #define most_readreg_rt(dev, addr)                          \
00369     (dev)->rt_ops.readreg((dev), addr)
00370 
00374 #define most_writereg_rt(dev, value, addr)                  \
00375     (dev)->rt_ops.writereg((dev), (value), (addr))
00376 
00380 #define most_manage_usage(dev, change)                      \
00381     (dev)->manage_usage((dev), (change))
00382 
00389 #define MOST_DEV_MAJOR(most_device)                 \
00390         ((most_device)->major_device_no)
00391 
00397 #define MOST_DEV_CARDNUMBER(most_device)            \
00398         ((most_device)->card_number)
00399 
00400 
00405 struct most_high_driver {
00406     const char         *name;          
00407     struct list_head   sema_list;      
00408     struct list_head   spin_list;      
00409     probe_func         probe;          
00413     remove_func        remove;         
00414     u8                 interrupt_mask; 
00421     irq_func           int_handler;    
00423 };
00424 
00430 struct most_low_driver {
00431     const char*      name;             
00432     struct list_head list;             
00433     void (*high_driver_registered)(struct most_high_driver *high_drv);
00435     void (*high_driver_deregistered)(struct most_high_driver *high_drv);
00437     proc_show_func   proc_show;        
00438 };
00439 
00440 /*
00441  * Function prototypes * ------------------------------------------------------
00442  */
00443 
00450 int most_register_high_driver(struct most_high_driver *driver);
00451 
00459 void most_deregister_high_driver(struct most_high_driver *driver);
00460 
00467 void most_register_low_driver(struct most_low_driver *low_driver);
00468 
00474 void most_deregister_low_driver(struct most_low_driver *low_driver);
00475 
00489 struct most_dev *most_dev_new(void);
00490 
00500 void most_dev_free(struct most_dev* dev);
00501 
00505 extern struct rwsema_locked_list most_base_low_drivers;
00506 
00510 extern struct rwsema_locked_list most_base_high_drivers_sema;
00511 
00515 extern struct spin_locked_list most_base_high_drivers_spin;
00516 
00517 
00518 #endif /* __KERNEL__ */
00519 #endif /* MOST_BASE */
00520 
00521 /* vim: set ts=4 et sw=4: */

Generated on Fri Mar 9 14:48:57 2007 for MOST Linux Drivers (Linux and RTAI) by  doxygen 1.5.0