comparison driver/pt1_pci.c @ 137:4303bbfd5d37

Support Linux-3.x kernel delete asm/system.h
author Naoya OYAMA <naoya.oyama@gmail.com>
date Thu, 28 Jun 2012 00:16:47 +0900
parents c8cfd684fee8
children ac23a9b417a2
comparison
equal deleted inserted replaced
136:2a9ac5ce2c7e 137:4303bbfd5d37
8 #include <linux/errno.h> 8 #include <linux/errno.h>
9 #include <linux/pci.h> 9 #include <linux/pci.h>
10 #include <linux/init.h> 10 #include <linux/init.h>
11 #include <linux/interrupt.h> 11 #include <linux/interrupt.h>
12 12
13 #include <asm/system.h>
14 #include <asm/io.h> 13 #include <asm/io.h>
15 #include <asm/irq.h> 14 #include <asm/irq.h>
16 #include <asm/uaccess.h> 15 #include <asm/uaccess.h>
17 #include <linux/version.h> 16 #include <linux/version.h>
18 #include <linux/mutex.h> 17 #include <linux/mutex.h>
19 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) 18 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
20 #include <linux/freezer.h> 19 #include <linux/freezer.h>
20 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
21 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
22 #include <linux/smp_lock.h>
23 #endif
24 #endif
21 #else 25 #else
22 #define set_freezable() 26 #define set_freezable()
23 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) 27 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
24 typedef struct pm_message { 28 typedef struct pm_message {
25 int event; 29 int event;
74 #define MAX_READ_BLOCK 4 // 1度に読み出す最大DMAバッファ数 78 #define MAX_READ_BLOCK 4 // 1度に読み出す最大DMAバッファ数
75 #define MAX_PCI_DEVICE 128 // 最大64枚 79 #define MAX_PCI_DEVICE 128 // 最大64枚
76 #define DMA_SIZE 4096 // DMAバッファサイズ 80 #define DMA_SIZE 4096 // DMAバッファサイズ
77 #define DMA_RING_SIZE 128 // RINGサイズ 81 #define DMA_RING_SIZE 128 // RINGサイズ
78 #define DMA_RING_MAX 511 // 1RINGにいくつ詰めるか(1023はNGで511まで) 82 #define DMA_RING_MAX 511 // 1RINGにいくつ詰めるか(1023はNGで511まで)
83 #define MAX_READ_SIZE (1024 * 4)
79 #define CHANEL_DMA_SIZE (2*1024*1024) // 地デジ用(16Mbps) 84 #define CHANEL_DMA_SIZE (2*1024*1024) // 地デジ用(16Mbps)
80 #define BS_CHANEL_DMA_SIZE (4*1024*1024) // BS用(32Mbps) 85 #define BS_CHANEL_DMA_SIZE (4*1024*1024) // BS用(32Mbps)
81 86
82 typedef struct _DMA_CONTROL{ 87 typedef struct _DMA_CONTROL{
83 dma_addr_t ring_dma[DMA_RING_MAX] ; // DMA情報 88 dma_addr_t ring_dma[DMA_RING_MAX] ; // DMA情報
142 static struct class *pt1video_class; 147 static struct class *pt1video_class;
143 148
144 #define PT1MAJOR 251 149 #define PT1MAJOR 251
145 #define DRIVERNAME "pt1video" 150 #define DRIVERNAME "pt1video"
146 151
152 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
153 static DEFINE_MUTEX(pt1_ioctl_mutex);
154 #endif
155
147 static void reset_dma(PT1_DEVICE *dev_conf) 156 static void reset_dma(PT1_DEVICE *dev_conf)
148 { 157 {
149 158
150 int lp ; 159 int lp ;
151 __u32 addr ; 160 __u32 addr ;
307 } 316 }
308 317
309 // 頻度を落す(4Kで起動させる) 318 // 頻度を落す(4Kで起動させる)
310 for(lp = 0 ; lp < MAX_CHANNEL ; lp++){ 319 for(lp = 0 ; lp < MAX_CHANNEL ; lp++){
311 channel = dev_conf->channel[real_channel[lp]] ; 320 channel = dev_conf->channel[real_channel[lp]] ;
312 if((channel->size >= DMA_SIZE) && (channel->valid == TRUE)){ 321 if((channel->size >= MAX_READ_SIZE ) && (channel->valid == TRUE)){
313 wake_up(&channel->wait_q); 322 wake_up(&channel->wait_q);
314 } 323 }
315 } 324 }
316 } 325 }
317 schedule_timeout_interruptible(msecs_to_jiffies(1)); 326 schedule_timeout_interruptible(msecs_to_jiffies(10));
318 } 327 }
319 return 0 ; 328 return 0 ;
320 } 329 }
321 static int pt1_open(struct inode *inode, struct file *file) 330 static int pt1_open(struct inode *inode, struct file *file)
322 { 331 {
401 { 410 {
402 PT1_CHANNEL *channel = file->private_data; 411 PT1_CHANNEL *channel = file->private_data;
403 __u32 size ; 412 __u32 size ;
404 unsigned long dummy; 413 unsigned long dummy;
405 414
406 // 4K単位で起こされるのを待つ(CPU負荷対策) 415 // 128K単位で起こされるのを待つ(CPU負荷対策)
407 if(channel->size < DMA_SIZE){ 416 if(channel->size < MAX_READ_SIZE){
408 wait_event_timeout(channel->wait_q, (channel->size >= DMA_SIZE), 417 wait_event_timeout(channel->wait_q, (channel->size >= MAX_READ_SIZE),
409 msecs_to_jiffies(500)); 418 msecs_to_jiffies(500));
410 } 419 }
411 mutex_lock(&channel->lock); 420 mutex_lock(&channel->lock);
412 if(!channel->size){ 421 if(!channel->size){
413 size = 0 ; 422 size = 0 ;
531 case START_REC: 540 case START_REC:
532 SetStream(channel->ptr->regs, channel->channel, TRUE); 541 SetStream(channel->ptr->regs, channel->channel, TRUE);
533 return 0 ; 542 return 0 ;
534 case STOP_REC: 543 case STOP_REC:
535 SetStream(channel->ptr->regs, channel->channel, FALSE); 544 SetStream(channel->ptr->regs, channel->channel, FALSE);
545 schedule_timeout_interruptible(msecs_to_jiffies(100));
536 return 0 ; 546 return 0 ;
537 case GET_SIGNAL_STRENGTH: 547 case GET_SIGNAL_STRENGTH:
538 switch(channel->type){ 548 switch(channel->type){
539 case CHANNEL_TYPE_ISDB_S: 549 case CHANNEL_TYPE_ISDB_S:
540 signal = isdb_s_read_signal_strength(channel->ptr->regs, 550 signal = isdb_s_read_signal_strength(channel->ptr->regs,
566 return 0 ; 576 return 0 ;
567 } 577 }
568 return -EINVAL; 578 return -EINVAL;
569 } 579 }
570 580
581 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
582 static long pt1_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
583 {
584 long rc;
585
586 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
587 if(mutex_lock_interruptible(&pt1_ioctl_mutex))
588 return -EINTR;
589 rc = pt1_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
590 mutex_unlock(&pt1_ioctl_mutex);
591 #else
592 lock_kernel();
593 rc = pt1_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
594 unlock_kernel();
595 #endif
596 return rc;
597 }
598 #endif
599
571 /* 600 /*
572 */ 601 */
573 static const struct file_operations pt1_fops = { 602 static const struct file_operations pt1_fops = {
574 .owner = THIS_MODULE, 603 .owner = THIS_MODULE,
575 .open = pt1_open, 604 .open = pt1_open,
576 .release = pt1_release, 605 .release = pt1_release,
577 .read = pt1_read, 606 .read = pt1_read,
607 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
608 .unlocked_ioctl = pt1_unlocked_ioctl,
609 #else
578 .ioctl = pt1_ioctl, 610 .ioctl = pt1_ioctl,
611 #endif
579 .llseek = no_llseek, 612 .llseek = no_llseek,
580 }; 613 };
581 614
582 int pt1_makering(struct pci_dev *pdev, PT1_DEVICE *dev_conf) 615 int pt1_makering(struct pci_dev *pdev, PT1_DEVICE *dev_conf)
583 { 616 {
968 } 1001 }
969 1002
970 1003
971 static void __exit pt1_pci_cleanup(void) 1004 static void __exit pt1_pci_cleanup(void)
972 { 1005 {
1006 pci_unregister_driver(&pt1_driver);
973 class_destroy(pt1video_class); 1007 class_destroy(pt1video_class);
974 pci_unregister_driver(&pt1_driver);
975 } 1008 }
976 1009
977 module_init(pt1_pci_init); 1010 module_init(pt1_pci_init);
978 module_exit(pt1_pci_cleanup); 1011 module_exit(pt1_pci_cleanup);