Changeset 9058


Ignore:
Timestamp:
02/15/08 00:52:51 (5 years ago)
Author:
BrainSlayer
Message:

update

Location:
src/linux/ar531x/linux-2.6.23
Files:
91 edited

Legend:

Unmodified
Added
Removed
  • src/linux/ar531x/linux-2.6.23/.config_generic

    r8960 r9058  
    170170# CONFIG_KALLSYMS is not set 
    171171# CONFIG_HOTPLUG is not set 
    172 # CONFIG_PRINTK is not set 
     172# CONFIG_PRINTK=y 
    173173# CONFIG_BUG is not set 
    174174# CONFIG_ELF_CORE is not set 
  • src/linux/ar531x/linux-2.6.23/Makefile

    r8960 r9058  
    22PATCHLEVEL = 6 
    33SUBLEVEL = 23 
    4 EXTRAVERSION = .14 
     4EXTRAVERSION = .15 
    55NAME = Arr Matey! A Hairy Bilge Rat! 
    66 
  • src/linux/ar531x/linux-2.6.23/arch/i386/kernel/apm.c

    r8169 r9058  
    22572257                return -ENODEV; 
    22582258        } 
    2259         if (PM_IS_ACTIVE()) { 
     2259        if (pm_flags & PM_ACPI) { 
    22602260                printk(KERN_NOTICE "apm: overridden by ACPI.\n"); 
    22612261                apm_info.disabled = 1; 
    22622262                return -ENODEV; 
    22632263        } 
    2264 #ifdef CONFIG_PM_LEGACY 
    2265         pm_active = 1; 
    2266 #endif 
     2264        pm_flags |= PM_APM; 
    22672265 
    22682266        /* 
     
    23672365                kapmd_task = NULL; 
    23682366        } 
    2369 #ifdef CONFIG_PM_LEGACY 
    2370         pm_active = 0; 
    2371 #endif 
     2367        pm_flags &= ~PM_APM; 
    23722368} 
    23732369 
  • src/linux/ar531x/linux-2.6.23/arch/ia64/kernel/unaligned.c

    r8169 r9058  
    14881488              case LDFCCLR_OP: 
    14891489              case LDFCNC_OP: 
     1490                if (u.insn.x) 
     1491                        ret = emulate_load_floatpair(ifa, u.insn, regs); 
     1492                else 
     1493                        ret = emulate_load_float(ifa, u.insn, regs); 
     1494                break; 
     1495 
    14901496              case LDF_IMM_OP: 
    14911497              case LDFA_IMM_OP: 
    14921498              case LDFCCLR_IMM_OP: 
    14931499              case LDFCNC_IMM_OP: 
    1494                 if (u.insn.x) 
    1495                         ret = emulate_load_floatpair(ifa, u.insn, regs); 
    1496                 else 
    1497                         ret = emulate_load_float(ifa, u.insn, regs); 
     1500                ret = emulate_load_float(ifa, u.insn, regs); 
    14981501                break; 
    14991502 
  • src/linux/ar531x/linux-2.6.23/arch/mips/Makefile

    r8960 r9058  
    650650        +@$(call makeboot,$@) 
    651651 
     652zImage: $(vmlinux-32) 
     653        +@$(call makeboot,zImage) 
     654 
     655 
    652656CLEAN_FILES += vmlinux.ecoff \ 
    653657               vmlinux.srec 
  • src/linux/ar531x/linux-2.6.23/arch/mips/atheros/board.c

    r8181 r9058  
    121121 
    122122        radio_config = board_config + 0x100 + ((rcfg - bcfg) & 0xfff); 
     123        printk("Found board config at 0x%x\n",bcfg); 
    123124        printk("Radio config found at offset 0x%x(0x%x)\n", rcfg - bcfg, radio_config - board_config); 
    124125        rcfg_size = BOARD_CONFIG_BUFSZ - ((rcfg - bcfg) & (BOARD_CONFIG_BUFSZ - 1)); 
     
    147148void __init plat_mem_setup(void) 
    148149{ 
     150printk(KERN_EMERG "mem setup\n"); 
     151 
    149152        DO_AR5312(ar5312_plat_setup();) 
    150153        DO_AR5315(ar5315_plat_setup();) 
     
    258261        clear_c0_status(ST0_IM); 
    259262        mips_cpu_irq_init(); 
    260  
    261263        /* Initialize interrupt controllers */ 
    262264        DO_AR5312(ar5312_misc_intr_init(AR531X_MISC_IRQ_BASE);) 
     
    264266 
    265267        /* Default "spurious interrupt" handlers */ 
    266         setup_irq(AR531X_IRQ_NONE, &spurious_irq); 
    267         setup_irq(AR531X_MISC_IRQ_NONE, &spurious_misc); 
     268//      setup_irq(AR531X_IRQ_NONE, &spurious_irq); 
     269//      setup_irq(AR531X_MISC_IRQ_NONE, &spurious_misc); 
    268270 
    269271} 
  • src/linux/ar531x/linux-2.6.23/arch/mips/boot/Makefile

    r8169 r9058  
    1111# Some DECstations need all possible sections of an ECOFF executable 
    1212# 
     13USE_STANDARD_AS_RULE := true 
     14 
     15OBJCOPYFLAGS := -O binary -R .note -R .comment -S 
     16 
     17SYSTEM = $(VMLINUX) 
     18 
     19 
     20export SYSTEM ZTEXTADDR ZBSSADDR ZRELADDR  
     21 
     22 
    1323ifdef CONFIG_MACH_DECSTATION 
    1424  E2EFLAGS = -a 
     
    4050        $(OBJCOPY) -S -O srec $(strip-flags) $(VMLINUX) $(obj)/vmlinux.srec 
    4151 
     52zImage: $(obj)/compressed/vmlinuz 
     53        $(OBJCOPY) $(strip-flags) $< $@ 
     54 
     55$(obj)/compressed/vmlinuz: $(VMLINUX) 
     56        $(Q)$(MAKE) $(build)=$(obj)/compressed vmlinuz 
     57 
    4258$(obj)/addinitrd: $(obj)/addinitrd.c 
    4359        $(HOSTCC) -o $@ $^ 
  • src/linux/ar531x/linux-2.6.23/arch/sparc64/kernel/chmc.c

    r8169 r9058  
    1 /* $Id: chmc.c,v 1.4 2002/01/08 16:00:14 davem Exp $ 
    2  * memctrlr.c: Driver for UltraSPARC-III memory controller. 
     1/* memctrlr.c: Driver for UltraSPARC-III memory controller. 
    32 * 
    4  * Copyright (C) 2001 David S. Miller (davem@redhat.com) 
     3 * Copyright (C) 2001, 2007 David S. Miller (davem@davemloft.net) 
    54 */ 
    65 
     
    1716#include <asm/spitfire.h> 
    1817#include <asm/chmctrl.h> 
     18#include <asm/cpudata.h> 
    1919#include <asm/oplib.h> 
    2020#include <asm/prom.h> 
     
    243243static u64 read_mcreg(struct mctrl_info *mp, unsigned long offset) 
    244244{ 
    245         unsigned long ret; 
    246         int this_cpu = get_cpu(); 
     245        unsigned long ret, this_cpu; 
     246 
     247        preempt_disable(); 
     248 
     249        this_cpu = real_hard_smp_processor_id(); 
    247250 
    248251        if (mp->portid == this_cpu) { 
     
    256259                                       "i" (ASI_PHYS_BYPASS_EC_E)); 
    257260        } 
    258         put_cpu(); 
     261 
     262        preempt_enable(); 
    259263 
    260264        return ret; 
  • src/linux/ar531x/linux-2.6.23/arch/sparc64/kernel/entry.S

    r8169 r9058  
    25942594         nop 
    25952595        .size   sun4v_mmustat_info, .-sun4v_mmustat_info 
     2596 
     2597        .globl  sun4v_mmu_demap_all 
     2598        .type   sun4v_mmu_demap_all,#function 
     2599sun4v_mmu_demap_all: 
     2600        clr     %o0 
     2601        clr     %o1 
     2602        mov     HV_MMU_ALL, %o2 
     2603        mov     HV_FAST_MMU_DEMAP_ALL, %o5 
     2604        ta      HV_FAST_TRAP 
     2605        retl 
     2606         nop 
     2607        .size   sun4v_mmu_demap_all, .-sun4v_mmu_demap_all 
  • src/linux/ar531x/linux-2.6.23/arch/sparc64/kernel/pci.c

    r8169 r9058  
    12771277} 
    12781278 
     1279void pci_resource_to_user(const struct pci_dev *pdev, int bar, 
     1280                          const struct resource *rp, resource_size_t *start, 
     1281                          resource_size_t *end) 
     1282{ 
     1283        struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller; 
     1284        unsigned long offset; 
     1285 
     1286        if (rp->flags & IORESOURCE_IO) 
     1287                offset = pbm->io_space.start; 
     1288        else 
     1289                offset = pbm->mem_space.start; 
     1290 
     1291        *start = rp->start - offset; 
     1292        *end = rp->end - offset; 
     1293} 
     1294 
    12791295#endif /* !(CONFIG_PCI) */ 
  • src/linux/ar531x/linux-2.6.23/arch/sparc64/kernel/smp.c

    r8169 r9058  
    477477static void cheetah_xcall_deliver(u64 data0, u64 data1, u64 data2, cpumask_t mask) 
    478478{ 
    479         u64 pstate, ver; 
     479        u64 pstate, ver, busy_mask; 
    480480        int nack_busy_id, is_jbus, need_more; 
    481481 
     
    509509 
    510510        nack_busy_id = 0; 
     511        busy_mask = 0; 
    511512        { 
    512513                int i; 
     
    515516                        u64 target = (i << 14) | 0x70; 
    516517 
    517                         if (!is_jbus) 
     518                        if (is_jbus) { 
     519                                busy_mask |= (0x1UL << (i * 2)); 
     520                        } else { 
    518521                                target |= (nack_busy_id << 24); 
     522                                busy_mask |= (0x1UL << 
     523                                              (nack_busy_id * 2)); 
     524                        } 
    519525                        __asm__ __volatile__( 
    520526                                "stxa   %%g0, [%0] %1\n\t" 
     
    532538        /* Now, poll for completion. */ 
    533539        { 
    534                 u64 dispatch_stat; 
     540                u64 dispatch_stat, nack_mask; 
    535541                long stuck; 
    536542 
    537543                stuck = 100000 * nack_busy_id; 
     544                nack_mask = busy_mask << 1; 
    538545                do { 
    539546                        __asm__ __volatile__("ldxa      [%%g0] %1, %0" 
    540547                                             : "=r" (dispatch_stat) 
    541548                                             : "i" (ASI_INTR_DISPATCH_STAT)); 
    542                         if (dispatch_stat == 0UL) { 
     549                        if (!(dispatch_stat & (busy_mask | nack_mask))) { 
    543550                                __asm__ __volatile__("wrpr %0, 0x0, %%pstate" 
    544551                                                     : : "r" (pstate)); 
     
    557564                        if (!--stuck) 
    558565                                break; 
    559                 } while (dispatch_stat & 0x5555555555555555UL); 
     566                } while (dispatch_stat & busy_mask); 
    560567 
    561568                __asm__ __volatile__("wrpr %0, 0x0, %%pstate" 
    562569                                     : : "r" (pstate)); 
    563570 
    564                 if ((dispatch_stat & ~(0x5555555555555555UL)) == 0) { 
     571                if (dispatch_stat & busy_mask) { 
    565572                        /* Busy bits will not clear, continue instead 
    566573                         * of freezing up on this cpu. 
  • src/linux/ar531x/linux-2.6.23/arch/sparc64/mm/init.c

    r8169 r9058  
    11361136} 
    11371137 
    1138 static void __init kernel_physical_mapping_init(void) 
     1138static void __init init_kpte_bitmap(void) 
    11391139{ 
    11401140        unsigned long i; 
    1141 #ifdef CONFIG_DEBUG_PAGEALLOC 
    1142         unsigned long mem_alloced = 0UL; 
    1143 #endif 
    1144  
    1145         read_obp_memory("reg", &pall[0], &pall_ents); 
    11461141 
    11471142        for (i = 0; i < pall_ents; i++) { 
     
    11521147 
    11531148                mark_kpte_bitmap(phys_start, phys_end); 
    1154  
     1149        } 
     1150} 
     1151 
     1152static void __init kernel_physical_mapping_init(void) 
     1153{ 
    11551154#ifdef CONFIG_DEBUG_PAGEALLOC 
     1155        unsigned long i, mem_alloced = 0UL; 
     1156 
     1157        for (i = 0; i < pall_ents; i++) { 
     1158                unsigned long phys_start, phys_end; 
     1159 
     1160                phys_start = pall[i].phys_addr; 
     1161                phys_end = phys_start + pall[i].reg_size; 
     1162 
    11561163                mem_alloced += kernel_map_range(phys_start, phys_end, 
    11571164                                                PAGE_KERNEL); 
    1158 #endif 
    1159         } 
    1160  
    1161 #ifdef CONFIG_DEBUG_PAGEALLOC 
     1165        } 
     1166 
    11621167        printk("Allocated %ld bytes for kernel page tables.\n", 
    11631168               mem_alloced); 
     
    14011406        inherit_prom_mappings(); 
    14021407         
     1408        read_obp_memory("reg", &pall[0], &pall_ents); 
     1409 
     1410        init_kpte_bitmap(); 
     1411 
    14031412        /* Ok, we can use our TLB miss and window trap handlers safely.  */ 
    14041413        setup_tba(); 
     
    18551864                             : "=r" (pstate) 
    18561865                             : "i" (PSTATE_IE)); 
    1857         if (tlb_type == spitfire) { 
     1866        if (tlb_type == hypervisor) { 
     1867                sun4v_mmu_demap_all(); 
     1868        } else if (tlb_type == spitfire) { 
    18581869                for (i = 0; i < 64; i++) { 
    18591870                        /* Spitfire Errata #32 workaround */ 
  • src/linux/ar531x/linux-2.6.23/drivers/acpi/blacklist.c

    r8169 r9058  
    44 *  Check to see if the given machine has a known bad ACPI BIOS 
    55 *  or if the BIOS is too old. 
     6 *  Check given machine against acpi_osi_dmi_table[]. 
    67 * 
    78 *  Copyright (C) 2004 Len Brown <len.brown@intel.com> 
     
    5051        u32 is_critical_error; 
    5152}; 
     53 
     54static struct dmi_system_id acpi_osi_dmi_table[] __initdata; 
    5255 
    5356/* 
     
    6871        {"IBM   ", "TP600E  ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal, 
    6972         "Incorrect _ADR", 1}, 
    70         {"ASUS\0\0", "P2B-S   ", 0, ACPI_SIG_DSDT, all_versions, 
    71          "Bogus PCI routing", 1}, 
    7273 
    7374        {""} 
     
    166167        blacklisted += blacklist_by_year(); 
    167168 
     169        dmi_check_system(acpi_osi_dmi_table); 
     170 
    168171        return blacklisted; 
    169172} 
     173#ifdef CONFIG_DMI 
     174static int __init dmi_enable_osi_linux(struct dmi_system_id *d) 
     175{ 
     176        acpi_dmi_osi_linux(1, d);       /* enable */ 
     177        return 0; 
     178} 
     179static int __init dmi_disable_osi_linux(struct dmi_system_id *d) 
     180{ 
     181        acpi_dmi_osi_linux(0, d);       /* disable */ 
     182        return 0; 
     183} 
     184static int __init dmi_unknown_osi_linux(struct dmi_system_id *d) 
     185{ 
     186        acpi_dmi_osi_linux(-1, d);      /* unknown */ 
     187        return 0; 
     188} 
     189 
     190/* 
     191 * Most BIOS that invoke OSI(Linux) do nothing with it. 
     192 * But some cause Linux to break. 
     193 * Only a couple use it to make Linux run better. 
     194 * 
     195 * Thus, Linux should continue to disable OSI(Linux) by default, 
     196 * should continue to discourage BIOS writers from using it, and 
     197 * should whitelist the few existing systems that require it. 
     198 * 
     199 * If it appears clear a vendor isn't using OSI(Linux) 
     200 * for anything constructive, blacklist them by name to disable 
     201 * unnecessary dmesg warnings on all of their products. 
     202 */ 
     203 
     204static struct dmi_system_id acpi_osi_dmi_table[] __initdata = { 
     205        /* 
     206         * Disable OSI(Linux) warnings on all "Acer, inc." 
     207         * 
     208         * _OSI(Linux) disables the latest Windows BIOS code: 
     209         * DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"), 
     210         * DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5050"), 
     211         * DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"), 
     212         * DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5580"), 
     213         * DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 3010"), 
     214         * _OSI(Linux) effect unknown: 
     215         * DMI_MATCH(DMI_PRODUCT_NAME, "Ferrari 5000"), 
     216         */ 
     217        /* 
     218         * note that dmi_check_system() uses strstr() 
     219         * to match sub-strings rather than !strcmp(), 
     220         * so "Acer" below matches "Acer, inc." above. 
     221         */ 
     222        /* 
     223         * Disable OSI(Linux) warnings on all "Acer" 
     224         * 
     225         * _OSI(Linux) effect unknown: 
     226         * DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5315"), 
     227         * DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"), 
     228         * DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7720Z"), 
     229         * DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5520"), 
     230         * DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 6460"), 
     231         * DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 7510"), 
     232         * DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5220"), 
     233         */ 
     234        { 
     235        .callback = dmi_unknown_osi_linux, 
     236        .ident = "Acer", 
     237        .matches = { 
     238                     DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 
     239                }, 
     240        }, 
     241        /* 
     242         * Disable OSI(Linux) warnings on all "Apple Computer, Inc." 
     243         * 
     244         * _OSI(Linux) confirmed to be a NOP: 
     245         * DMI_MATCH(DMI_PRODUCT_NAME, "MacBook1,1"), 
     246         * DMI_MATCH(DMI_PRODUCT_NAME, "MacBook2,1"), 
     247         * DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro2,2"), 
     248         * _OSI(Linux) effect unknown: 
     249         * DMI_MATCH(DMI_PRODUCT_NAME, "MacPro2,1"), 
     250         * DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro1,1"), 
     251         * DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3,1"), 
     252         */ 
     253        { 
     254        .callback = dmi_disable_osi_linux, 
     255        .ident = "Apple", 
     256        .matches = { 
     257                     DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."), 
     258                }, 
     259        }, 
     260        /* 
     261         * Disable OSI(Linux) warnings on all "BenQ" 
     262         * 
     263         * _OSI(Linux) confirmed to be a NOP: 
     264         * DMI_MATCH(DMI_PRODUCT_NAME, "Joybook S31"), 
     265         */ 
     266        { 
     267        .callback = dmi_disable_osi_linux, 
     268        .ident = "BenQ", 
     269        .matches = { 
     270                     DMI_MATCH(DMI_SYS_VENDOR, "BenQ"), 
     271                }, 
     272        }, 
     273        /* 
     274         * Disable OSI(Linux) warnings on all "Clevo Co." 
     275         * 
     276         * _OSI(Linux) confirmed to be a NOP: 
     277         * DMI_MATCH(DMI_PRODUCT_NAME, "M570RU"), 
     278         */ 
     279        { 
     280        .callback = dmi_disable_osi_linux, 
     281        .ident = "Clevo", 
     282        .matches = { 
     283                     DMI_MATCH(DMI_SYS_VENDOR, "Clevo Co."), 
     284                }, 
     285        }, 
     286        /* 
     287         * Disable OSI(Linux) warnings on all "COMPAL" 
     288         * 
     289         * _OSI(Linux) confirmed to be a NOP: 
     290         * DMI_MATCH(DMI_BOARD_NAME, "HEL8X"), 
     291         * _OSI(Linux) unknown effect: 
     292         * DMI_MATCH(DMI_BOARD_NAME, "IFL91"), 
     293         */ 
     294        { 
     295        .callback = dmi_unknown_osi_linux, 
     296        .ident = "Compal", 
     297        .matches = { 
     298                     DMI_MATCH(DMI_BIOS_VENDOR, "COMPAL"), 
     299                }, 
     300        }, 
     301        { /* OSI(Linux) touches USB, unknown side-effect */ 
     302        .callback = dmi_disable_osi_linux, 
     303        .ident = "Dell Dimension 5150", 
     304        .matches = { 
     305                     DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 
     306                     DMI_MATCH(DMI_PRODUCT_NAME, "Dell DM051"), 
     307                }, 
     308        }, 
     309        { /* OSI(Linux) is a NOP */ 
     310        .callback = dmi_disable_osi_linux, 
     311        .ident = "Dell", 
     312        .matches = { 
     313                     DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 
     314                     DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1501"), 
     315                }, 
     316        }, 
     317        { /* OSI(Linux) effect unknown */ 
     318        .callback = dmi_unknown_osi_linux, 
     319        .ident = "Dell", 
     320        .matches = { 
     321                     DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 
     322                     DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D830"), 
     323                }, 
     324        }, 
     325        { /* OSI(Linux) effect unknown */ 
     326        .callback = dmi_unknown_osi_linux, 
     327        .ident = "Dell", 
     328        .matches = { 
     329                     DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 
     330                     DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex GX620"), 
     331                }, 
     332        }, 
     333        { /* OSI(Linux) effect unknown */ 
     334        .callback = dmi_unknown_osi_linux, 
     335        .ident = "Dell", 
     336        .matches = { 
     337                     DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 
     338                     DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1900"), 
     339                }, 
     340        }, 
     341        { /* OSI(Linux) touches USB */ 
     342        .callback = dmi_disable_osi_linux, 
     343        .ident = "Dell", 
     344        .matches = { 
     345                     DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 
     346                     DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation 390"), 
     347                }, 
     348        }, 
     349        { /* OSI(Linux) is a NOP */ 
     350        .callback = dmi_disable_osi_linux, 
     351        .ident = "Dell Vostro 1000", 
     352        .matches = { 
     353                     DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 
     354                     DMI_MATCH(DMI_PRODUCT_NAME, "Vostro   1000"), 
     355                }, 
     356        }, 
     357        { /* OSI(Linux) effect unknown */ 
     358        .callback = dmi_unknown_osi_linux, 
     359        .ident = "Dell", 
     360        .matches = { 
     361                     DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 
     362                     DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge SC440"), 
     363                }, 
     364        }, 
     365        { /* OSI(Linux) effect unknown */ 
     366        .callback = dmi_unknown_osi_linux, 
     367        .ident = "Dialogue Flybook V5", 
     368        .matches = { 
     369                     DMI_MATCH(DMI_SYS_VENDOR, "Dialogue Technology Corporation"), 
     370                     DMI_MATCH(DMI_PRODUCT_NAME, "Flybook V5"), 
     371                }, 
     372        }, 
     373        /* 
     374         * Disable OSI(Linux) warnings on all "FUJITSU SIEMENS" 
     375         * 
     376         * _OSI(Linux) disables latest Windows BIOS code: 
     377         * DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pa 2510"), 
     378         * _OSI(Linux) confirmed to be a NOP: 
     379         * DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pi 1536"), 
     380         * DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pi 1556"), 
     381         * DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xi 1546"), 
     382         * _OSI(Linux) unknown effect: 
     383         * DMI_MATCH(DMI_PRODUCT_NAME, "Amilo M1425"), 
     384         * DMI_MATCH(DMI_PRODUCT_NAME, "Amilo Si 1520"), 
     385         * DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Mobile V5505"), 
     386         */ 
     387        { 
     388        .callback = dmi_disable_osi_linux, 
     389        .ident = "Fujitsu Siemens", 
     390        .matches = { 
     391                     DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), 
     392                }, 
     393        }, 
     394        /* 
     395         * Disable OSI(Linux) warnings on all "Hewlett-Packard" 
     396         * 
     397         * _OSI(Linux) confirmed to be a NOP: 
     398         * .ident = "HP Pavilion tx 1000" 
     399         * DMI_MATCH(DMI_BOARD_NAME, "30BF"), 
     400         * .ident = "HP Pavilion dv2000" 
     401         * DMI_MATCH(DMI_BOARD_NAME, "30B5"), 
     402         * .ident = "HP Pavilion dv5000", 
     403         * DMI_MATCH(DMI_BOARD_NAME, "30A7"), 
     404         * .ident = "HP Pavilion dv6300 30BC", 
     405         * DMI_MATCH(DMI_BOARD_NAME, "30BC"), 
     406         * .ident = "HP Pavilion dv6000", 
     407         * DMI_MATCH(DMI_BOARD_NAME, "30B7"), 
     408         * DMI_MATCH(DMI_BOARD_NAME, "30B8"), 
     409         * .ident = "HP Pavilion dv9000", 
     410         * DMI_MATCH(DMI_BOARD_NAME, "30B9"), 
     411         * .ident = "HP Pavilion dv9500", 
     412         * DMI_MATCH(DMI_BOARD_NAME, "30CB"), 
     413         * .ident = "HP/Compaq Presario C500", 
     414         * DMI_MATCH(DMI_BOARD_NAME, "30C6"), 
     415         * .ident = "HP/Compaq Presario F500", 
     416         * DMI_MATCH(DMI_BOARD_NAME, "30D3"), 
     417         * _OSI(Linux) unknown effect: 
     418         * .ident = "HP Pavilion dv6500", 
     419         * DMI_MATCH(DMI_BOARD_NAME, "30D0"), 
     420         */ 
     421        { 
     422        .callback = dmi_disable_osi_linux, 
     423        .ident = "Hewlett-Packard", 
     424        .matches = { 
     425                     DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 
     426                }, 
     427        }, 
     428        /* 
     429         * Lenovo has a mix of systems OSI(Linux) situations 
     430         * and thus we can not wildcard the vendor. 
     431         * 
     432         * _OSI(Linux) helps sound 
     433         * DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad R61"), 
     434         * DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T61"), 
     435         * _OSI(Linux) is a NOP: 
     436         * DMI_MATCH(DMI_PRODUCT_VERSION, "3000 N100"), 
     437         */ 
     438        { 
     439        .callback = dmi_enable_osi_linux, 
     440        .ident = "Lenovo ThinkPad R61", 
     441        .matches = { 
     442                     DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 
     443                     DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad R61"), 
     444                }, 
     445        }, 
     446        { 
     447        .callback = dmi_enable_osi_linux, 
     448        .ident = "Lenovo ThinkPad T61", 
     449        .matches = { 
     450                     DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 
     451                     DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T61"), 
     452                }, 
     453        }, 
     454        { 
     455        .callback = dmi_unknown_osi_linux, 
     456        .ident = "Lenovo 3000 V100", 
     457        .matches = { 
     458                     DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 
     459                     DMI_MATCH(DMI_PRODUCT_VERSION, "LENOVO3000 V100"), 
     460                }, 
     461        }, 
     462        { 
     463        .callback = dmi_disable_osi_linux, 
     464        .ident = "Lenovo 3000 N100", 
     465        .matches = { 
     466                     DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 
     467                     DMI_MATCH(DMI_PRODUCT_VERSION, "3000 N100"), 
     468                }, 
     469        }, 
     470        /* 
     471         * Disable OSI(Linux) warnings on all "LG Electronics" 
     472         * 
     473         * _OSI(Linux) confirmed to be a NOP: 
     474         * DMI_MATCH(DMI_PRODUCT_NAME, "P1-J150B"), 
     475         * with DMI_MATCH(DMI_BOARD_NAME, "ROCKY"), 
     476         * 
     477         * unknown: 
     478         * DMI_MATCH(DMI_PRODUCT_NAME, "S1-MDGDG"), 
     479         * with DMI_MATCH(DMI_BOARD_NAME, "ROCKY"), 
     480         */ 
     481        { 
     482        .callback = dmi_disable_osi_linux, 
     483        .ident = "LG", 
     484        .matches = { 
     485                     DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"), 
     486                }, 
     487        }, 
     488        /* NEC - OSI(Linux) effect unknown */ 
     489        { 
     490        .callback = dmi_unknown_osi_linux, 
     491        .ident = "NEC VERSA M360", 
     492        .matches = { 
     493                     DMI_MATCH(DMI_SYS_VENDOR, "NEC Computers SAS"), 
     494                     DMI_MATCH(DMI_PRODUCT_NAME, "NEC VERSA M360"), 
     495                }, 
     496        }, 
     497        /* 
     498         * Disable OSI(Linux) warnings on all "Samsung Electronics" 
     499         * 
     500         * OSI(Linux) disables PNP0C32 and other BIOS code for Windows: 
     501         * DMI_MATCH(DMI_PRODUCT_NAME, "R40P/R41P"), 
     502         * DMI_MATCH(DMI_PRODUCT_NAME, "R59P/R60P/R61P"), 
     503         */ 
     504        { 
     505        .callback = dmi_disable_osi_linux, 
     506        .ident = "Samsung", 
     507        .matches = { 
     508                     DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), 
     509                }, 
     510        }, 
     511        /* 
     512         * Disable OSI(Linux) warnings on all "Sony Corporation" 
     513         * 
     514         * _OSI(Linux) is a NOP: 
     515         * DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SZ650N"), 
     516         * DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SZ38GP_C"), 
     517         * DMI_MATCH(DMI_PRODUCT_NAME, "VGN-TZ21MN_N"), 
     518         * _OSI(Linux) unknown effect: 
     519         * DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FZ11M"), 
     520         */ 
     521        { 
     522        .callback = dmi_unknown_osi_linux, 
     523        .ident = "Sony", 
     524        .matches = { 
     525                     DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), 
     526                }, 
     527        }, 
     528        /* 
     529         * Disable OSI(Linux) warnings on all "TOSHIBA" 
     530         * 
     531         * _OSI(Linux) breaks sound (bugzilla 7787): 
     532         * DMI_MATCH(DMI_PRODUCT_NAME, "Satellite P100"), 
     533         * DMI_MATCH(DMI_PRODUCT_NAME, "Satellite P105"), 
     534         * _OSI(Linux) is a NOP: 
     535         * DMI_MATCH(DMI_PRODUCT_NAME, "Satellite A100"), 
     536         * DMI_MATCH(DMI_PRODUCT_NAME, "Satellite A210"), 
     537         * _OSI(Linux) unknown effect: 
     538         * DMI_MATCH(DMI_PRODUCT_NAME, "Satellite A135"), 
     539         * DMI_MATCH(DMI_PRODUCT_NAME, "Satellite A200"), 
     540         * DMI_MATCH(DMI_PRODUCT_NAME, "Satellite P205"), 
     541         * DMI_MATCH(DMI_PRODUCT_NAME, "Satellite U305"), 
     542         */ 
     543        { 
     544        .callback = dmi_disable_osi_linux, 
     545        .ident = "Toshiba", 
     546        .matches = { 
     547                     DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 
     548                }, 
     549        }, 
     550        {} 
     551}; 
     552 
     553#endif /* CONFIG_DMI */ 
  • src/linux/ar531x/linux-2.6.23/drivers/acpi/bus.c

    r8169 r9058  
    3030#include <linux/sched.h> 
    3131#include <linux/pm.h> 
    32 #include <linux/pm_legacy.h> 
    3332#include <linux/device.h> 
    3433#include <linux/proc_fs.h> 
     
    758757 
    759758        if (!result) { 
    760 #ifdef CONFIG_PM_LEGACY 
    761                 if (!PM_IS_ACTIVE()) 
    762                         pm_active = 1; 
     759                if (!(pm_flags & PM_APM)) 
     760                        pm_flags |= PM_ACPI; 
    763761                else { 
    764762                        printk(KERN_INFO PREFIX 
     
    767765                        result = -ENODEV; 
    768766                } 
    769 #endif 
    770767        } else 
    771768                disable_acpi(); 
  • src/linux/ar531x/linux-2.6.23/drivers/acpi/dispatcher/dsobject.c

    r8169 r9058  
    138138                        } 
    139139                } 
     140 
     141                /* Special object resolution for elements of a package */ 
     142 
     143                if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) || 
     144                    (op->common.parent->common.aml_opcode == 
     145                     AML_VAR_PACKAGE_OP)) { 
     146                        /* 
     147                         * Attempt to resolve the node to a value before we insert it into 
     148                         * the package. If this is a reference to a common data type, 
     149                         * resolve it immediately. According to the ACPI spec, package 
     150                         * elements can only be "data objects" or method references. 
     151                         * Attempt to resolve to an Integer, Buffer, String or Package. 
     152                         * If cannot, return the named reference (for things like Devices, 
     153                         * Methods, etc.) Buffer Fields and Fields will resolve to simple 
     154                         * objects (int/buf/str/pkg). 
     155                         * 
     156                         * NOTE: References to things like Devices, Methods, Mutexes, etc. 
     157                         * will remain as named references. This behavior is not described 
     158                         * in the ACPI spec, but it appears to be an oversight. 
     159                         */ 
     160                        obj_desc = (union acpi_operand_object *)op->common.node; 
     161 
     162                        status = 
     163                            acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR 
     164                                                          (struct 
     165                                                           acpi_namespace_node, 
     166                                                           &obj_desc), 
     167                                                          walk_state); 
     168                        if (ACPI_FAILURE(status)) { 
     169                                return_ACPI_STATUS(status); 
     170                        } 
     171 
     172                        switch (op->common.node->type) { 
     173                                /* 
     174                                 * For these types, we need the actual node, not the subobject. 
     175                                 * However, the subobject got an extra reference count above. 
     176                                 */ 
     177                        case ACPI_TYPE_MUTEX: 
     178                        case ACPI_TYPE_METHOD: 
     179                        case ACPI_TYPE_POWER: 
     180                        case ACPI_TYPE_PROCESSOR: 
     181                        case ACPI_TYPE_EVENT: 
     182                        case ACPI_TYPE_REGION: 
     183                        case ACPI_TYPE_DEVICE: 
     184                        case ACPI_TYPE_THERMAL: 
     185 
     186                                obj_desc = 
     187                                    (union acpi_operand_object *)op->common. 
     188                                    node; 
     189                                break; 
     190 
     191                        default: 
     192                                break; 
     193                        } 
     194 
     195                        /* 
     196                         * If above resolved to an operand object, we are done. Otherwise, 
     197                         * we have a NS node, we must create the package entry as a named 
     198                         * reference. 
     199                         */ 
     200                        if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != 
     201                            ACPI_DESC_TYPE_NAMED) { 
     202                                goto exit; 
     203                        } 
     204                } 
    140205        } 
    141206 
     
    157222        } 
    158223 
     224      exit: 
    159225        *obj_desc_ptr = obj_desc; 
    160226        return_ACPI_STATUS(AE_OK); 
     
    357423        for (i = 0; arg && (i < element_count); i++) { 
    358424                if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { 
    359  
    360                         /* This package element is already built, just get it */ 
    361  
    362                         obj_desc->package.elements[i] = 
    363                             ACPI_CAST_PTR(union acpi_operand_object, 
    364                                           arg->common.node); 
     425                        if (arg->common.node->type == ACPI_TYPE_METHOD) { 
     426                                /* 
     427                                 * A method reference "looks" to the parser to be a method 
     428                                 * invocation, so we special case it here 
     429                                 */ 
     430                                arg->common.aml_opcode = AML_INT_NAMEPATH_OP; 
     431                                status = 
     432                                    acpi_ds_build_internal_object(walk_state, 
     433                                                                  arg, 
     434                                                                  &obj_desc-> 
     435                                                                  package. 
     436                                                                  elements[i]); 
     437                        } else { 
     438                                /* This package element is already built, just get it */ 
     439 
     440                                obj_desc->package.elements[i] = 
     441                                    ACPI_CAST_PTR(union acpi_operand_object, 
     442                                                  arg->common.node); 
     443                        } 
    365444                } else { 
    366445                        status = acpi_ds_build_internal_object(walk_state, arg, 
  • src/linux/ar531x/linux-2.6.23/drivers/acpi/events/evregion.c

    r8169 r9058  
    345345                 * (e.g., _REG method for this region) 
    346346                 */ 
    347                 acpi_ex_relinquish_interpreter(); 
     347                acpi_ex_exit_interpreter(); 
    348348 
    349349                status = region_setup(region_obj, ACPI_REGION_ACTIVATE, 
     
    353353                /* Re-enter the interpreter */ 
    354354 
    355                 acpi_ex_reacquire_interpreter(); 
     355                acpi_ex_enter_interpreter(); 
    356356 
    357357                /* Check for failure of the Region Setup */ 
     
    406406                 * know what it will do, so we can't hold the lock on the intepreter. 
    407407                 */ 
    408                 acpi_ex_relinquish_interpreter(); 
     408                acpi_ex_exit_interpreter(); 
    409409        } 
    410410 
     
    427427                 * interpreter 
    428428                 */ 
    429                 acpi_ex_reacquire_interpreter(); 
     429                acpi_ex_enter_interpreter(); 
    430430        } 
    431431 
  • src/linux/ar531x/linux-2.6.23/drivers/acpi/osl.c

    r8169 r9058  
    7878static char osi_additional_string[OSI_STRING_LENGTH_MAX]; 
    7979 
    80 static int osi_linux;           /* disable _OSI(Linux) by default */ 
    81  
    82 #ifdef CONFIG_DMI 
    83 static struct __initdata dmi_system_id acpi_osl_dmi_table[]; 
    84 #endif 
     80/* 
     81 * "Ode to _OSI(Linux)" 
     82 * 
     83 * osi_linux -- Control response to BIOS _OSI(Linux) query. 
     84 * 
     85 * As Linux evolves, the features that it supports change. 
     86 * So an OSI string such as "Linux" is not specific enough 
     87 * to be useful across multiple versions of Linux.  It 
     88 * doesn't identify any particular feature, interface, 
     89 * or even any particular version of Linux... 
     90 * 
     91 * Unfortunately, Linux-2.6.22 and earlier responded "yes" 
     92 * to a BIOS _OSI(Linux) query.  When 
     93 * a reference mobile BIOS started using it, its use 
     94 * started to spread to many vendor platforms. 
     95 * As it is not supportable, we need to halt that spread. 
     96 * 
     97 * Today, most BIOS references to _OSI(Linux) are noise -- 
     98 * they have no functional effect and are just dead code 
     99 * carried over from the reference BIOS. 
     100 * 
     101 * The next most common case is that _OSI(Linux) harms Linux, 
     102 * usually by causing the BIOS to follow paths that are 
     103 * not tested during Windows validation. 
     104 * 
     105 * Finally, there is a short list of platforms 
     106 * where OSI(Linux) benefits Linux. 
     107 * 
     108 * In Linux-2.6.23, OSI(Linux) is first disabled by default. 
     109 * DMI is used to disable the dmesg warning about OSI(Linux) 
     110 * on platforms where it is known to have no effect. 
     111 * But a dmesg warning remains for systems where 
     112 * we do not know if OSI(Linux) is good or bad for the system. 
     113 * DMI is also used to enable OSI(Linux) for the machines 
     114 * that are known to need it. 
     115 * 
     116 * BIOS writers should NOT query _OSI(Linux) on future systems. 
     117 * It will be ignored by default, and to get Linux to 
     118 * not ignore it will require a kernel source update to 
     119 * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation. 
     120 */ 
     121#define OSI_LINUX_ENABLE 0 
     122 
     123static struct osi_linux { 
     124        unsigned int    enable:1; 
     125        unsigned int    dmi:1; 
     126        unsigned int    cmdline:1; 
     127        unsigned int    known:1; 
     128} osi_linux = { OSI_LINUX_ENABLE, 0, 0, 0}; 
    85129 
    86130static void __init acpi_request_region (struct acpi_generic_address *addr, 
     
    134178acpi_status __init acpi_os_initialize(void) 
    135179{ 
    136         dmi_check_system(acpi_osl_dmi_table); 
    137180        return AE_OK; 
    138181} 
     
    9721015__setup("acpi_os_name=", acpi_os_name_setup); 
    9731016 
    974 static void enable_osi_linux(int enable) { 
    975  
    976         if (osi_linux != enable) 
    977                 printk(KERN_INFO PREFIX "%sabled _OSI(Linux)\n", 
    978                         enable ? "En": "Dis"); 
    979  
    980         osi_linux = enable; 
     1017static void __init set_osi_linux(unsigned int enable) 
     1018{ 
     1019        if (osi_linux.enable != enable) { 
     1020                osi_linux.enable = enable; 
     1021                printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n", 
     1022                        enable ? "Add": "Delet"); 
     1023        } 
     1024        return; 
     1025} 
     1026 
     1027static void __init acpi_cmdline_osi_linux(unsigned int enable) 
     1028{ 
     1029        osi_linux.cmdline = 1;  /* cmdline set the default */ 
     1030        set_osi_linux(enable); 
     1031 
     1032        return; 
     1033} 
     1034 
     1035void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d) 
     1036{ 
     1037        osi_linux.dmi = 1;      /* DMI knows that this box asks OSI(Linux) */ 
     1038 
     1039        printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident); 
     1040 
     1041        if (enable == -1) 
     1042                return; 
     1043 
     1044        osi_linux.known = 1;    /* DMI knows which OSI(Linux) default needed */ 
     1045 
     1046        set_osi_linux(enable); 
     1047 
    9811048        return; 
    9821049} 
     
    9951062                acpi_gbl_create_osi_method = FALSE; 
    9961063        } else if (!strcmp("!Linux", str)) { 
    997                 enable_osi_linux(0); 
     1064                acpi_cmdline_osi_linux(0);      /* !enable */ 
    9981065        } else if (*str == '!') { 
    9991066                if (acpi_osi_invalidate(++str) == AE_OK) 
    10001067                        printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str); 
    10011068        } else if (!strcmp("Linux", str)) { 
    1002                 enable_osi_linux(1); 
     1069                acpi_cmdline_osi_linux(1);      /* enable */ 
    10031070        } else if (*osi_additional_string == '\0') { 
    10041071                strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX); 
     
    11571224} 
    11581225 
     1226/** 
     1227 *      acpi_dmi_dump - dump DMI slots needed for blacklist entry 
     1228 * 
     1229 *      Returns 0 on success 
     1230 */ 
     1231static int acpi_dmi_dump(void) 
     1232{ 
     1233 
     1234        if (!dmi_available) 
     1235                return -1; 
     1236 
     1237        printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n", 
     1238                dmi_get_system_info(DMI_SYS_VENDOR)); 
     1239        printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n", 
     1240                dmi_get_system_info(DMI_PRODUCT_NAME)); 
     1241        printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n", 
     1242                dmi_get_system_info(DMI_PRODUCT_VERSION)); 
     1243        printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n", 
     1244                dmi_get_system_info(DMI_BOARD_NAME)); 
     1245        printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n", 
     1246                dmi_get_system_info(DMI_BIOS_VENDOR)); 
     1247        printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n", 
     1248                dmi_get_system_info(DMI_BIOS_DATE)); 
     1249 
     1250        return 0; 
     1251} 
     1252 
     1253 
    11591254/****************************************************************************** 
    11601255 * 
     
    11761271                return AE_OK; 
    11771272        if (!strcmp("Linux", interface)) { 
    1178                 printk(KERN_WARNING PREFIX 
    1179                         "System BIOS is requesting _OSI(Linux)\n"); 
    1180                 printk(KERN_WARNING PREFIX 
    1181                         "If \"acpi_osi=Linux\" works better,\n" 
    1182                         "Please send dmidecode " 
    1183                         "to linux-acpi@vger.kernel.org\n"); 
    1184                 if(osi_linux) 
     1273 
     1274                printk(KERN_NOTICE PREFIX 
     1275                        "BIOS _OSI(Linux) query %s%s\n", 
     1276                        osi_linux.enable ? "honored" : "ignored", 
     1277                        osi_linux.cmdline ? " via cmdline" : 
     1278                        osi_linux.dmi ? " via DMI" : ""); 
     1279 
     1280                if (!osi_linux.dmi) { 
     1281                        if (acpi_dmi_dump()) 
     1282                                printk(KERN_NOTICE PREFIX 
     1283                                        "[please extract dmidecode output]\n"); 
     1284                        printk(KERN_NOTICE PREFIX 
     1285                                "Please send DMI info above to " 
     1286                                "linux-acpi@vger.kernel.org\n"); 
     1287                } 
     1288                if (!osi_linux.known && !osi_linux.cmdline) { 
     1289                        printk(KERN_NOTICE PREFIX 
     1290                                "If \"acpi_osi=%sLinux\" works better, " 
     1291                                "please notify linux-acpi@vger.kernel.org\n", 
     1292                                osi_linux.enable ? "!" : ""); 
     1293                } 
     1294 
     1295                if (osi_linux.enable) 
    11851296                        return AE_OK; 
    11861297        } 
     
    12141325} 
    12151326 
    1216 #ifdef CONFIG_DMI 
    1217 static int dmi_osi_linux(struct dmi_system_id *d) 
    1218 { 
    1219         printk(KERN_NOTICE "%s detected: enabling _OSI(Linux)\n", d->ident); 
    1220         enable_osi_linux(1); 
    1221         return 0; 
    1222 } 
    1223  
    1224 static struct dmi_system_id acpi_osl_dmi_table[] __initdata = { 
    1225         /* 
    1226          * Boxes that need _OSI(Linux) 
    1227          */ 
    1228         { 
    1229          .callback = dmi_osi_linux, 
    1230          .ident = "Intel Napa CRB", 
    1231          .matches = { 
    1232                      DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"), 
    1233                      DMI_MATCH(DMI_BOARD_NAME, "MPAD-MSAE Customer Reference Boards"), 
    1234                      }, 
    1235          }, 
    1236         {} 
    1237 }; 
    1238 #endif /* CONFIG_DMI */ 
    1239  
    12401327#endif 
  • src/linux/ar531x/linux-2.6.23/drivers/acpi/pci_irq.c

    r8169 r9058  
    430430                                          acpi_pci_allocate_irq); 
    431431 
     432        if (irq < 0) { 
     433                /* 
     434                 * IDE legacy mode controller IRQs are magic. Why do compat 
     435                 * extensions always make such a nasty mess. 
     436                 */ 
     437                if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE && 
     438                                (dev->class & 0x05) == 0) 
     439                        return 0; 
     440        } 
    432441        /* 
    433442         * No IRQ known to the ACPI subsystem - maybe the BIOS /  
  • src/linux/ar531x/linux-2.6.23/drivers/acpi/video.c

    r8539 r9058  
    574574 
    575575 
    576         memset(&device->cap, 0, 4); 
     576        memset(&device->cap, 0, sizeof(device->cap)); 
    577577 
    578578        if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) { 
     
    694694        acpi_handle h_dummy1; 
    695695 
    696         memset(&video->cap, 0, 4); 
     696        memset(&video->cap, 0, sizeof(video->cap)); 
    697697        if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) { 
    698698                video->cap._DOS = 1; 
  • src/linux/ar531x/linux-2.6.23/drivers/ata/libata-core.c

    r8641 r9058  
    61226122                        continue; 
    61236123 
    6124                 if ((host->flags & ATA_HOST_STARTED) && ap->ops->port_stop) 
    6125                         ap->ops->port_stop(ap); 
    6126         } 
    6127  
    6128         if ((host->flags & ATA_HOST_STARTED) && host->ops->host_stop) 
    6129                 host->ops->host_stop(host); 
    6130  
    6131         for (i = 0; i < host->n_ports; i++) { 
    6132                 struct ata_port *ap = host->ports[i]; 
    6133  
    6134                 if (!ap) 
    6135                         continue; 
    6136  
    61376124                if (ap->scsi_host) 
    61386125                        scsi_host_put(ap->scsi_host); 
     
    62596246} 
    62606247 
     6248static void ata_host_stop(struct device *gendev, void *res) 
     6249{ 
     6250        struct ata_host *host = dev_get_drvdata(gendev); 
     6251        int i; 
     6252 
     6253        WARN_ON(!(host->flags & ATA_HOST_STARTED)); 
     6254 
     6255        for (i = 0; i < host->n_ports; i++) { 
     6256                struct ata_port *ap = host->ports[i]; 
     6257 
     6258                if (ap->ops->port_stop) 
     6259                        ap->ops->port_stop(ap); 
     6260        } 
     6261 
     6262        if (host->ops->host_stop) 
     6263                host->ops->host_stop(host); 
     6264} 
     6265 
    62616266/** 
    62626267 *      ata_host_start - start and freeze ports of an ATA host 
     
    62776282int ata_host_start(struct ata_host *host) 
    62786283{ 
     6284        int have_stop = 0; 
     6285        void *start_dr = NULL; 
    62796286        int i, rc; 
    62806287 
     
    62876294                if (!host->ops && !ata_port_is_dummy(ap)) 
    62886295                        host->ops = ap->ops; 
     6296 
     6297                if (ap->ops->port_stop) 
     6298                        have_stop = 1; 
     6299        } 
     6300 
     6301        if (host->ops->host_stop) 
     6302                have_stop = 1; 
     6303 
     6304        if (have_stop) { 
     6305                start_dr = devres_alloc(ata_host_stop, 0, GFP_KERNEL); 
     6306                if (!start_dr) 
     6307                        return -ENOMEM; 
     6308        } 
     6309 
     6310        for (i = 0; i < host->n_ports; i++) { 
     6311                struct ata_port *ap = host->ports[i]; 
    62896312 
    62906313                if (ap->ops->port_start) { 
     
    63006323        } 
    63016324 
     6325        if (start_dr) 
     6326                devres_add(host->dev, start_dr); 
    63026327        host->flags |= ATA_HOST_STARTED; 
    63036328        return 0; 
     
    63106335                        ap->ops->port_stop(ap); 
    63116336        } 
     6337        devres_free(start_dr); 
    63126338        return rc; 
    63136339} 
  • src/linux/ar531x/linux-2.6.23/drivers/ata/sata_promise.c

    r8169 r9058  
    5151        PDC_MAX_PORTS           = 4, 
    5252        PDC_MMIO_BAR            = 3, 
     53        PDC_MAX_PRD             = LIBATA_MAX_PRD - 1, /* -1 for ASIC PRD bug workaround */ 
    5354 
    5455        /* register offsets */ 
     
    156157        .can_queue              = ATA_DEF_QUEUE, 
    157158        .this_id                = ATA_SHT_THIS_ID, 
    158         .sg_tablesize           = LIBATA_MAX_PRD, 
     159        .sg_tablesize           = PDC_MAX_PRD, 
    159160        .cmd_per_lun            = ATA_SHT_CMD_PER_LUN, 
    160161        .emulated               = ATA_SHT_EMULATED, 
     
    528529} 
    529530 
     531/** 
     532 *      pdc_fill_sg - Fill PCI IDE PRD table 
     533 *      @qc: Metadata associated with taskfile to be transferred 
     534 * 
     535 *      Fill PCI IDE PRD (scatter-gather) table with segments 
     536 *      associated with the current disk command. 
     537 *      Make sure hardware does not choke on it. 
     538 * 
     539 *      LOCKING: 
     540 *      spin_lock_irqsave(host lock) 
     541 * 
     542 */ 
     543static void pdc_fill_sg(struct ata_queued_cmd *qc) 
     544{ 
     545        struct ata_port *ap = qc->ap; 
     546        struct scatterlist *sg; 
     547        unsigned int idx; 
     548        const u32 SG_COUNT_ASIC_BUG = 41*4; 
     549 
     550        if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 
     551                return; 
     552 
     553        WARN_ON(qc->__sg == NULL); 
     554        WARN_ON(qc->n_elem == 0 && qc->pad_len == 0); 
     555 
     556        idx = 0; 
     557        ata_for_each_sg(sg, qc) { 
     558                u32 addr, offset; 
     559                u32 sg_len, len; 
     560 
     561                /* determine if physical DMA addr spans 64K boundary. 
     562                 * Note h/w doesn't support 64-bit, so we unconditionally 
     563                 * truncate dma_addr_t to u32. 
     564                 */ 
     565                addr = (u32) sg_dma_address(sg); 
     566                sg_len = sg_dma_len(sg); 
     567 
     568                while (sg_len) { 
     569                        offset = addr & 0xffff; 
     570                        len = sg_len; 
     571                        if ((offset + sg_len) > 0x10000) 
     572                                len = 0x10000 - offset; 
     573 
     574                        ap->prd[idx].addr = cpu_to_le32(addr); 
     575                        ap->prd[idx].flags_len = cpu_to_le32(len & 0xffff); 
     576                        VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len); 
     577 
     578                        idx++; 
     579                        sg_len -= len; 
     580                        addr += len; 
     581                } 
     582        } 
     583 
     584        if (idx) { 
     585                u32 len = le32_to_cpu(ap->prd[idx - 1].flags_len); 
     586 
     587                if (len > SG_COUNT_ASIC_BUG) { 
     588                        u32 addr; 
     589 
     590                        VPRINTK("Splitting last PRD.\n"); 
     591 
     592                        addr = le32_to_cpu(ap->prd[idx - 1].addr); 
     593                        ap->prd[idx - 1].flags_len = cpu_to_le32(len - SG_COUNT_ASIC_BUG); 
     594                        VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx - 1, addr, SG_COUNT_ASIC_BUG); 
     595 
     596                        addr = addr + len - SG_COUNT_ASIC_BUG; 
     597                        len = SG_COUNT_ASIC_BUG; 
     598                        ap->prd[idx].addr = cpu_to_le32(addr); 
     599                        ap->prd[idx].flags_len = cpu_to_le32(len); 
     600                        VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len); 
     601 
     602                        idx++; 
     603                } 
     604 
     605                ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); 
     606        } 
     607} 
     608 
    530609static void pdc_qc_prep(struct ata_queued_cmd *qc) 
    531610{ 
     
    537616        switch (qc->tf.protocol) { 
    538617        case ATA_PROT_DMA: 
    539                 ata_qc_prep(qc); 
     618                pdc_fill_sg(qc); 
    540619                /* fall through */ 
    541620 
     
    553632 
    554633        case ATA_PROT_ATAPI: 
    555                 ata_qc_prep(qc); 
     634                pdc_fill_sg(qc); 
    556635                break; 
    557636 
    558637        case ATA_PROT_ATAPI_DMA: 
    559                 ata_qc_prep(qc); 
     638                pdc_fill_sg(qc); 
    560639                /*FALLTHROUGH*/ 
    561640        case ATA_PROT_ATAPI_NODATA: 
  • src/linux/ar531x/linux-2.6.23/drivers/atm/nicstar.c

    r8169 r9058  
    626626      nicstar_init_eprom(card->membase); 
    627627 
    628    if (request_irq(pcidev->irq, &ns_irq_handler, IRQF_DISABLED | IRQF_SHARED, "nicstar", card) != 0) 
    629    { 
    630       printk("nicstar%d: can't allocate IRQ %d.\n", i, pcidev->irq); 
    631       error = 9; 
    632       ns_init_card_error(card, error); 
    633       return error; 
    634    } 
    635  
    636628   /* Set the VPI/VCI MSb mask to zero so we can receive OAM cells */ 
    637629   writel(0x00000000, card->membase + VPM); 
     
    859851   } 
    860852 
    861    card->intcnt = 0; 
    862  
    863853   /* Configure NICStAR */ 
    864854   if (card->rct_size == 4096) 
     
    868858 
    869859   card->efbie = 1; 
     860 
     861   card->intcnt = 0; 
     862   if (request_irq(pcidev->irq, &ns_irq_handler, IRQF_DISABLED | IRQF_SHARED, "nicstar", card) != 0) 
     863   { 
     864      printk("nicstar%d: can't allocate IRQ %d.\n", i, pcidev->irq); 
     865      error = 9; 
     866      ns_init_card_error(card, error); 
     867      return error; 
     868   } 
    870869 
    871870   /* Register device */ 
  • src/linux/ar531x/linux-2.6.23/drivers/char/apm-emulation.c

    r8169 r9058  
    296296{ 
    297297        struct apm_user *as = filp->private_data; 
    298         unsigned long flags; 
    299298        int err = -EINVAL; 
    300299 
     
    332331                         * are pending acknowledges, we wait here for them. 
    333332                         */ 
    334                         flags = current->flags; 
     333                        freezer_do_not_count(); 
    335334 
    336335                        wait_event(apm_suspend_waitqueue, 
    337336                                   as->suspend_state == SUSPEND_DONE); 
     337 
     338                        /* 
     339                         * Since we are waiting until the suspend is done, the 
     340                         * try_to_freeze() in freezer_count() will not trigger 
     341                         */ 
     342                        freezer_count(); 
    338343                } else { 
    339344                        as->suspend_state = SUSPEND_WAIT; 
     
    363368                         * are pending acknowledges, we wait here for them. 
    364369                         */ 
    365                         flags = current->flags; 
    366  
    367                         wait_event_interruptible(apm_suspend_waitqueue, 
     370                        wait_event_freezable(apm_suspend_waitqueue, 
    368371                                         as->suspend_state == SUSPEND_DONE); 
    369372                } 
    370  
    371                 current->flags = flags; 
    372373 
    373374                mutex_lock(&state_lock); 
  • src/linux/ar531x/linux-2.6.23/drivers/char/drm/drm_vm.c

    r8169 r9058  
    507507 
    508508        vma->vm_flags |= VM_RESERVED;   /* Don't swap */ 
     509        vma->vm_flags |= VM_DONTEXPAND; 
    509510 
    510511        vma->vm_file = filp;    /* Needed for drm_vm_open() */ 
     
    656657        } 
    657658        vma->vm_flags |= VM_RESERVED;   /* Don't swap */ 
     659        vma->vm_flags |= VM_DONTEXPAND; 
    658660 
    659661        vma->vm_file = filp;    /* Needed for drm_vm_open() */ 
  • src/linux/ar531x/linux-2.6.23/drivers/char/mspec.c

    r8169 r9058  
    284284        vma->vm_private_data = vdata; 
    285285 
    286         vma->vm_flags |= (VM_IO | VM_RESERVED | VM_PFNMAP); 
     286        vma->vm_flags |= (VM_IO | VM_RESERVED | VM_PFNMAP | VM_DONTEXPAND); 
    287287        if (vdata->type == MSPEC_FETCHOP || vdata->type == MSPEC_UNCACHED) 
    288288                vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 
  • src/linux/ar531x/linux-2.6.23/drivers/char/tty_ioctl.c

    r8169 r9058  
    6363                timeout = MAX_SCHEDULE_TIMEOUT; 
    6464        if (wait_event_interruptible_timeout(tty->write_wait, 
    65                         !tty->driver->chars_in_buffer(tty), timeout)) 
     65                        !tty->driver->chars_in_buffer(tty), timeout) < 0) 
    6666                return; 
    6767        if (tty->driver->wait_until_sent) 
  • src/linux/ar531x/linux-2.6.23/drivers/char/watchdog/ar2315_wdt.c

    r8967 r9058  
    7979extern const char *get_arch_type (void); 
    8080 
    81 static int ar2315_wdt_print_info(void) 
     81static void ar2315_wdt_print_info(void) 
    8282{ 
    8383        printk("watchdog hb: %d", heartbeat); 
  • src/linux/ar531x/linux-2.6.23/drivers/connector/cn_queue.c

    r8169 r9058  
    100100 
    101101        if (found) { 
     102                cn_queue_free_callback(cbq); 
    102103                atomic_dec(&dev->refcnt); 
    103                 cn_queue_free_callback(cbq); 
    104104                return -EINVAL; 
    105105        } 
  • src/linux/ar531x/linux-2.6.23/drivers/crypto/padlock-aes.c

    r8169 r9058  
    420420 
    421421/* These are the real call to PadLock. */ 
     422static inline void padlock_xcrypt(const u8 *input, u8 *output, void *key, 
     423                                  void *control_word) 
     424{ 
     425        asm volatile (".byte 0xf3,0x0f,0xa7,0xc8"       /* rep xcryptecb */ 
     426                      : "+S"(input), "+D"(output) 
     427                      : "d"(control_word), "b"(key), "c"(1)); 
     428} 
     429 
     430static void aes_crypt_copy(const u8 *in, u8 *out, u32 *key, struct cword *cword) 
     431{ 
     432        u8 buf[AES_BLOCK_SIZE * 2 + PADLOCK_ALIGNMENT - 1]; 
     433        u8 *tmp = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT); 
     434 
     435        memcpy(tmp, in, AES_BLOCK_SIZE); 
     436        padlock_xcrypt(tmp, out, key, cword); 
     437} 
     438 
     439static inline void aes_crypt(const u8 *in, u8 *out, u32 *key, 
     440                             struct cword *cword) 
     441{ 
     442        asm volatile ("pushfl; popfl"); 
     443 
     444        /* padlock_xcrypt requires at least two blocks of data. */ 
     445        if (unlikely(!(((unsigned long)in ^ (PAGE_SIZE - AES_BLOCK_SIZE)) & 
     446                       (PAGE_SIZE - 1)))) { 
     447                aes_crypt_copy(in, out, key, cword); 
     448                return; 
     449        } 
     450 
     451        padlock_xcrypt(in, out, key, cword); 
     452} 
     453 
    422454static inline void padlock_xcrypt_ecb(const u8 *input, u8 *output, void *key, 
    423455                                      void *control_word, u32 count) 
    424456{ 
     457        if (count == 1) { 
     458                aes_crypt(input, output, key, control_word); 
     459                return; 
     460        } 
     461 
    425462        asm volatile ("pushfl; popfl");         /* enforce key reload. */ 
    426         asm volatile (".byte 0xf3,0x0f,0xa7,0xc8"       /* rep xcryptecb */ 
     463        asm volatile ("test $1, %%cl;" 
     464                      "je 1f;" 
     465                      "lea -1(%%ecx), %%eax;" 
     466                      "mov $1, %%ecx;" 
     467                      ".byte 0xf3,0x0f,0xa7,0xc8;"      /* rep xcryptecb */ 
     468                      "mov %%eax, %%ecx;" 
     469                      "1:" 
     470                      ".byte 0xf3,0x0f,0xa7,0xc8"       /* rep xcryptecb */ 
    427471                      : "+S"(input), "+D"(output) 
    428                       : "d"(control_word), "b"(key), "c"(count)); 
     472                      : "d"(control_word), "b"(key), "c"(count) 
     473                      : "ax"); 
    429474} 
    430475 
     
    444489{ 
    445490        struct aes_ctx *ctx = aes_ctx(tfm); 
    446         padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt, 1); 
     491        aes_crypt(in, out, ctx->E, &ctx->cword.encrypt); 
    447492} 
    448493 
     
    450495{ 
    451496        struct aes_ctx *ctx = aes_ctx(tfm); 
    452         padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt, 1); 
     497        aes_crypt(in, out, ctx->D, &ctx->cword.decrypt); 
    453498} 
    454499 
  • src/linux/ar531x/linux-2.6.23/drivers/firmware/dmi-id.c

    r8169 r9058  
    159159        if (dmi_get_system_info(_field)) \ 
    160160                sys_dmi_attributes[i++] = & sys_dmi_##_name##_attr.attr; 
    161  
    162 extern int dmi_available; 
    163161 
    164162static int __init dmi_id_init(void) 
  • src/linux/ar531x/linux-2.6.23/drivers/input/evdev.c

    r8169 r9058  
    3131        struct evdev_client *grab; 
    3232        struct list_head client_list; 
     33        spinlock_t client_lock; /* protects client_list */ 
     34        struct mutex mutex; 
    3335        struct device dev; 
    3436}; 
     
    3840        int head; 
    3941        int tail; 
     42        spinlock_t buffer_lock; /* protects access to buffer, head and tail */ 
    4043        struct fasync_struct *fasync; 
    4144        struct evdev *evdev; 
     
    4447 
    4548static struct evdev *evdev_table[EVDEV_MINORS]; 
    46  
    47 static void evdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) 
     49static DEFINE_MUTEX(evdev_table_mutex); 
     50 
     51static void evdev_pass_event(struct evdev_client *client, 
     52                             struct input_event *event) 
     53{ 
     54        /* 
     55         * Interrupts are disabled, just acquire the lock 
     56         */ 
     57        spin_lock(&client->buffer_lock); 
     58        client->buffer[client->head++] = *event; 
     59        client->head &= EVDEV_BUFFER_SIZE - 1; 
     60        spin_unlock(&client->buffer_lock); 
     61 
     62        kill_fasync(&client->fasync, SIGIO, POLL_IN); 
     63} 
     64 
     65/* 
     66 * Pass incoming event to all connected clients. Note that we are 
     67 * caleld under a spinlock with interrupts off so we don't need 
     68 * to use rcu_read_lock() here. Writers will be using syncronize_sched() 
     69 * instead of synchrnoize_rcu(). 
     70 */ 
     71static void evdev_event(struct input_handle *handle, 
     72                        unsigned int type, unsigned int code, int value) 
    4873{ 
    4974        struct evdev *evdev = handle->private; 
    5075        struct evdev_client *client; 
    51  
    52         if (evdev->grab) { 
    53                 client = evdev->grab; 
    54  
    55                 do_gettimeofday(&client->buffer[client->head].time); 
    56                 client->buffer[client->head].type = type; 
    57                 client->buffer[client->head].code = code; 
    58                 client->buffer[client->head].value = value; 
    59                 client->head = (client->head + 1) & (EVDEV_BUFFER_SIZE - 1); 
    60  
    61                 kill_fasync(&client->fasync, SIGIO, POLL_IN); 
    62         } else 
    63                 list_for_each_entry(client, &evdev->client_list, node) { 
    64  
    65                         do_gettimeofday(&client->buffer[client->head].time); 
    66                         client->buffer[client->head].type = type; 
    67                         client->buffer[client->head].code = code; 
    68                         client->buffer[client->head].value = value; 
    69                         client->head = (client->head + 1) & (EVDEV_BUFFER_SIZE - 1); 
    70  
    71                         kill_fasync(&client->fasync, SIGIO, POLL_IN); 
    72                 } 
     76        struct input_event event; 
     77 
     78        do_gettimeofday(&event.time); 
     79        event.type = type; 
     80        event.code = code; 
     81        event.value = value; 
     82 
     83        client = rcu_dereference(evdev->grab); 
     84        if (client) 
     85                evdev_pass_event(client, &event); 
     86        else 
     87                list_for_each_entry_rcu(client, &evdev->client_list, node) 
     88                        evdev_pass_event(client, &event); 
    7389 
    7490        wake_up_interruptible(&evdev->wait); 
     
    89105        struct evdev_client *client = file->private_data; 
    90106        struct evdev *evdev = client->evdev; 
     107        int retval; 
     108 
     109        retval = mutex_lock_interruptible(&evdev->mutex); 
     110        if (retval) 
     111                return retval; 
    91112 
    92113        if (!evdev->exist) 
    93                 return -ENODEV; 
    94  
    95         return input_flush_device(&evdev->handle, file); 
     114                retval = -ENODEV; 
     115        else 
     116                retval = input_flush_device(&evdev->handle, file); 
     117 
     118        mutex_unlock(&evdev->mutex); 
     119        return retval; 
    96120} 
    97121 
     
    100124        struct evdev *evdev = container_of(dev, struct evdev, dev); 
    101125 
    102         evdev_table[evdev->minor] = NULL; 
    103126        kfree(evdev); 
     127} 
     128 
     129/* 
     130 * Grabs an event device (along with underlying input device). 
     131 * This function is called with evdev->mutex taken. 
     132 */ 
     133static int evdev_grab(struct evdev *evdev, struct evdev_client *client) 
     134{ 
     135        int error; 
     136 
     137        if (evdev->grab) 
     138                return -EBUSY; 
     139 
     140        error = input_grab_device(&evdev->handle); 
     141        if (error) 
     142                return error; 
     143 
     144        rcu_assign_pointer(evdev->grab, client); 
     145        /* 
     146         * We don't use synchronize_rcu() here because read-side 
     147         * critical section is protected by a spinlock instead 
     148         * of rcu_read_lock(). 
     149         */ 
     150        synchronize_sched(); 
     151 
     152        return 0; 
     153} 
     154 
     155static int evdev_ungrab(struct evdev *evdev, struct evdev_client *client) 
     156{ 
     157        if (evdev->grab != client) 
     158                return  -EINVAL; 
     159 
     160        rcu_assign_pointer(evdev->grab, NULL); 
     161        synchronize_sched(); 
     162        input_release_device(&evdev->handle); 
     163 
     164        return 0; 
     165} 
     166 
     167static void evdev_attach_client(struct evdev *evdev, 
     168                                struct evdev_client *client) 
     169{ 
     170        spin_lock(&evdev->client_lock); 
     171        list_add_tail_rcu(&client->node, &evdev->client_list); 
     172        spin_unlock(&evdev->client_lock); 
     173        synchronize_sched(); 
     174} 
     175 
     176static void evdev_detach_client(struct evdev *evdev, 
     177                                struct evdev_client *client) 
     178{ 
     179        spin_lock(&evdev->client_lock); 
     180        list_del_rcu(&client->node); 
     181        spin_unlock(&evdev->client_lock); 
     182        synchronize_sched(); 
     183} 
     184 
     185static int evdev_open_device(struct evdev *evdev) 
     186{ 
     187        int retval; 
     188 
     189        retval = mutex_lock_interruptible(&evdev->mutex); 
     190        if (retval) 
     191                return retval; 
     192 
     193        if (!evdev->exist) 
     194                retval = -ENODEV; 
     195        else if (!evdev->open++) { 
     196                retval = input_open_device(&evdev->handle); 
     197                if (retval) 
     198                        evdev->open--; 
     199        } 
     200 
     201        mutex_unlock(&evdev->mutex); 
     202        return retval; 
     203} 
     204 
     205static void evdev_close_device(struct evdev *evdev) 
     206{ 
     207        mutex_lock(&evdev->mutex); 
     208 
     209        if (evdev->exist && !--evdev->open) 
     210                input_close_device(&evdev->handle); 
     211 
     212        mutex_unlock(&evdev->mutex); 
     213} 
     214 
     215/* 
     216 * Wake up users waiting for IO so they can disconnect from 
     217 * dead device. 
     218 */ 
     219static void evdev_hangup(struct evdev *evdev) 
     220{ 
     221        struct evdev_client *client; 
     222 
     223        spin_lock(&evdev->client_lock); 
     224        list_for_each_entry(client, &evdev->client_list, node) 
     225                kill_fasync(&client->fasync, SIGIO, POLL_HUP); 
     226        spin_unlock(&evdev->client_lock); 
     227 
     228        wake_up_interruptible(&evdev->wait); 
    104229} 
    105230 
     
    109234        struct evdev *evdev = client->evdev; 
    110235 
    111         if (evdev->grab == client) { 
    112                 input_release_device(&evdev->handle); 
    113                 evdev->grab = NULL; 
    114         } 
     236        mutex_lock(&evdev->mutex); 
     237        if (evdev->grab == client) 
     238                evdev_ungrab(evdev, client); 
     239        mutex_unlock(&evdev->mutex); 
    115240 
    116241        evdev_fasync(-1, file, 0); 
    117         list_del(&client->node); 
     242        evdev_detach_client(evdev, client); 
    118243        kfree(client); 
    119244 
    120         if (!--evdev->open && evdev->exist) 
    121                 input_close_device(&evdev->handle); 
    122  
     245        evdev_close_device(evdev); 
    123246        put_device(&evdev->dev); 
    124247 
     
    128251static int evdev_open(struct inode *inode, struct file *file) 
    129252{ 
     253        struct evdev *evdev; 
    130254        struct evdev_client *client; 
    131         struct evdev *evdev; 
    132255        int i = iminor(inode) - EVDEV_MINOR_BASE; 
    133256        int error; 
     
    136259                return -ENODEV; 
    137260 
     261        error = mutex_lock_interruptible(&evdev_table_mutex); 
     262        if (error) 
     263                return error; 
    138264        evdev = evdev_table[i]; 
    139  
    140         if (!evdev || !evdev->exist) 
     265        if (evdev) 
     266                get_device(&evdev->dev); 
     267        mutex_unlock(&evdev_table_mutex); 
     268 
     269        if (!evdev) 
    141270                return -ENODEV; 
    142  
    143         get_device(&evdev->dev); 
    144271 
    145272        client = kzalloc(sizeof(struct evdev_client), GFP_KERNEL); 
     
    149276        } 
    150277 
     278        spin_lock_init(&client->buffer_lock); 
    151279        client->evdev = evdev; 
    152         list_add_tail(&client->node, &evdev->client_list); 
    153  
    154         if (!evdev->open++ && evdev->exist) { 
    155                 error = input_open_device(&evdev->handle); 
    156                 if (error) 
    157                         goto err_free_client; 
    158         } 
     280        evdev_attach_client(evdev, client); 
     281 
     282        error = evdev_open_device(evdev); 
     283        if (error) 
     284                goto err_free_client; 
    159285 
    160286        file->private_data = client; 
     
    162288 
    163289 err_free_client: 
    164         list_del(&client->node); 
     290        evdev_detach_client(evdev, client); 
    165291        kfree(client); 
    166292 err_put_evdev: 
     
    198324} 
    199325 
    200 static int evdev_event_from_user(const char __user *buffer, struct input_event *event) 
     326static int evdev_event_from_user(const char __user *buffer, 
     327                                 struct input_event *event) 
    201328{ 
    202329        if (COMPAT_TEST) { 
    203330                struct input_event_compat compat_event; 
    204331 
    205                 if (copy_from_user(&compat_event, buffer, sizeof(struct input_event_compat))) 
     332                if (copy_from_user(&compat_event, buffer, 
     333                                   sizeof(struct input_event_compat))) 
    206334                        return -EFAULT; 
    207335 
     
    220348} 
    221349 
    222 static int evdev_event_to_user(char __user *buffer, const struct input_event *event) 
     350static int evdev_event_to_user(char __user *buffer, 
     351                                const struct input_event *event) 
    223352{ 
    224353        if (COMPAT_TEST) { 
     
    231360                compat_event.value = event->value; 
    232361 
    233                 if (copy_to_user(buffer, &compat_event, sizeof(struct input_event_compat))) 
     362                if (copy_to_user(buffer, &compat_event, 
     363                                 sizeof(struct input_event_compat))) 
    234364                        return -EFAULT; 
    235365 
     
    249379} 
    250380 
    251 static int evdev_event_from_user(const char __user *buffer, struct input_event *event) 
     381static int evdev_event_from_user(const char __user *buffer, 
     382                                 struct input_event *event) 
    252383{ 
    253384        if (copy_from_user(event, buffer, sizeof(struct input_event))) 
     
    257388} 
    258389 
    259 static int evdev_event_to_user(char __user *buffer, const struct input_event *event) 
     390static int evdev_event_to_user(char __user *buffer, 
     391                                const struct input_event *event) 
    260392{ 
    261393        if (copy_to_user(buffer, event, sizeof(struct input_event))) 
     
    267399#endif /* CONFIG_COMPAT */ 
    268400 
    269 static ssize_t evdev_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) 
     401static ssize_t evdev_write(struct file *file, const char __user *buffer, 
     402                           size_t count, loff_t *ppos) 
    270403{ 
    271404        struct evdev_client *client = file->private_data; 
    272405        struct evdev *evdev = client->evdev; 
    273406        struct input_event event; 
    274         int retval = 0; 
    275  
    276         if (!evdev->exist) 
    277                 return -ENODEV; 
     407        int retval; 
     408 
     409        retval = mutex_lock_interruptible(&evdev->mutex); 
     410        if (retval) 
     411                return retval; 
     412 
     413        if (!evdev->exist) { 
     414                retval = -ENODEV; 
     415                goto out; 
     416        } 
    278417 
    279418        while (retval < count) { 
    280419 
    281                 if (evdev_event_from_user(buffer + retval, &event)) 
    282                         return -EFAULT; 
    283                 input_inject_event(&evdev->handle, event.type, event.code, event.value); 
     420                if (evdev_event_from_user(buffer + retval, &event)) { 
     421                        retval = -EFAULT; 
     422                        goto out; 
     423                } 
     424 
     425                input_inject_event(&evdev->handle, 
     426                                   event.type, event.code, event.value); 
    284427                retval += evdev_event_size(); 
    285428        } 
    286429 
     430 out: 
     431        mutex_unlock(&evdev->mutex); 
    287432        return retval; 
    288433} 
    289434 
    290 static ssize_t evdev_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) 
     435static int evdev_fetch_next_event(struct evdev_client *client, 
     436                                  struct input_event *event) 
     437{ 
     438        int have_event; 
     439 
     440        spin_lock_irq(&client->buffer_lock); 
     441 
     442        have_event = client->head != client->tail; 
     443        if (have_event) { 
     444                *event = client->buffer[client->tail++]; 
     445                client->tail &= EVDEV_BUFFER_SIZE - 1; 
     446        } 
     447 
     448        spin_unlock_irq(&client->buffer_lock); 
     449 
     450        return have_event; 
     451} 
     452 
     453static ssize_t evdev_read(struct file *file, char __user *buffer, 
     454                          size_t count, loff_t *ppos) 
    291455{ 
    292456        struct evdev_client *client = file->private_data; 
    293457        struct evdev *evdev = client->evdev; 
     458        struct input_event event; 
    294459        int retval; 
    295460 
     
    297462                return -EINVAL; 
    298463 
    299         if (client->head == client->tail && evdev->exist && (file->f_flags & O_NONBLOCK)) 
     464        if (client->head == client->tail && evdev->exist && 
     465            (file->f_flags & O_NONBLOCK)) 
    300466                return -EAGAIN; 
    301467 
     
    308474                return -ENODEV; 
    309475 
    310         while (client->head != client->tail && retval + evdev_event_size() <= count) { 
    311  
    312                 struct input_event *event = (struct input_event *) client->buffer + client->tail; 
    313  
    314                 if (evdev_event_to_user(buffer + retval, event)) 
    315                         return -EFAULT; 
    316  
    317                 client->tail = (client->tail + 1) & (EVDEV_BUFFER_SIZE - 1); 
     476        while (retval + evdev_event_size() <= count && 
     477               evdev_fetch_next_event(client, &event)) { 
     478 
     479                if (evdev_event_to_user(buffer + retval, &event)) 
     480                        return -EFAULT; 
     481 
    318482                retval += evdev_event_size(); 
    319483        } 
     
    410574} 
    411575 
    412 static long evdev_ioctl_handler(struct file *file, unsigned int cmd, 
    413                                 void __user *p, int compat_mode) 
     576static long evdev_do_ioctl(struct file *file, unsigned int cmd, 
     577                           void __user *p, int compat_mode) 
    414578{ 
    415579        struct evdev_client *client = file->private_data; 
     
    422586        int error; 
    423587 
    424         if (!evdev->exist) 
    425                 return -ENODEV; 
    426  
    427588        switch (cmd) { 
    428589 
    429                 case EVIOCGVERSION: 
    430                         return put_user(EV_VERSION, ip); 
    431  
    432                 case EVIOCGID: 
    433                         if (copy_to_user(p, &dev->id, sizeof(struct input_id))) 
    434                                 return -EFAULT; 
    435                         return 0; 
    436  
    437                 case EVIOCGREP: 
    438                         if (!test_bit(EV_REP, dev->evbit)) 
    439                                 return -ENOSYS; 
    440                         if (put_user(dev->rep[REP_DELAY], ip)) 
    441                                 return -EFAULT; 
    442                         if (put_user(dev->rep[REP_PERIOD], ip + 1)) 
    443                                 return -EFAULT; 
    444                         return 0; 
    445  
    446                 case EVIOCSREP: 
    447                         if (!test_bit(EV_REP, dev->evbit)) 
    448                                 return -ENOSYS; 
    449                         if (get_user(u, ip)) 
    450                                 return -EFAULT; 
    451                         if (get_user(v, ip + 1)) 
    452                                 return -EFAULT; 
    453  
    454                         input_inject_event(&evdev->handle, EV_REP, REP_DELAY, u); 
    455                         input_inject_event(&evdev->handle, EV_REP, REP_PERIOD, v); 
    456  
    457                         return 0; 
    458  
    459                 case EVIOCGKEYCODE: 
    460                         if (get_user(t, ip)) 
    461                                 return -EFAULT; 
    462  
    463                         error = dev->getkeycode(dev, t, &v); 
    464                         if (error) 
    465                                 return error; 
    466  
    467                         if (put_user(v, ip + 1)) 
    468                                 return -EFAULT; 
    469  
    470                         return 0; 
    471  
    472                 case EVIOCSKEYCODE: 
    473                         if (get_user(t, ip) || get_user(v, ip + 1)) 
    474                                 return -EFAULT; 
    475  
    476                         return dev->setkeycode(dev, t, v); 
    477  
    478                 case EVIOCSFF: 
    479                         if (copy_from_user(&effect, p, sizeof(effect))) 
    480                                 return -EFAULT; 
    481  
    482                         error = input_ff_upload(dev, &effect, file); 
    483  
    484                         if (put_user(effect.id, &(((struct ff_effect __user *)p)->id))) 
    485                                 return -EFAULT; 
    486  
     590        case EVIOCGVERSION: 
     591                return put_user(EV_VERSION, ip); 
     592 
     593        case EVIOCGID: 
     594                if (copy_to_user(p, &dev->id, sizeof(struct input_id))) 
     595                        return -EFAULT; 
     596                return 0; 
     597 
     598        case EVIOCGREP: 
     599                if (!test_bit(EV_REP, dev->evbit)) 
     600                        return -ENOSYS; 
     601                if (put_user(dev->rep[REP_DELAY], ip)) 
     602                        return -EFAULT; 
     603                if (put_user(dev->rep[REP_PERIOD], ip + 1)) 
     604                        return -EFAULT; 
     605                return 0; 
     606 
     607        case EVIOCSREP: 
     608                if (!test_bit(EV_REP, dev->evbit)) 
     609                        return -ENOSYS; 
     610                if (get_user(u, ip)) 
     611                        return -EFAULT; 
     612                if (get_user(v, ip + 1)) 
     613                        return -EFAULT; 
     614 
     615                input_inject_event(&evdev->handle, EV_REP, REP_DELAY, u); 
     616                input_inject_event(&evdev->handle, EV_REP, REP_PERIOD, v); 
     617 
     618                return 0; 
     619 
     620        case EVIOCGKEYCODE: 
     621                if (get_user(t, ip)) 
     622                        return -EFAULT; 
     623 
     624                error = dev->getkeycode(dev, t, &v); 
     625                if (error) 
    487626                        return error; 
    488627 
    489                 case EVIOCRMFF: 
    490                         return input_ff_erase(dev, (int)(unsigned long) p, file); 
    491  
    492                 case EVIOCGEFFECTS: 
    493                         i = test_bit(EV_FF, dev->evbit) ? dev->ff->max_effects : 0; 
    494                         if (put_user(i, ip)) 
    495                                 return -EFAULT; 
    496                         return 0; 
    497  
    498                 case EVIOCGRAB: 
    499                         if (p) { 
    500                                 if (evdev->grab) 
    501                                         return -EBUSY; 
    502                                 if (input_grab_device(&evdev->handle)) 
    503                                         return -EBUSY; 
    504                                 evdev->grab = client; 
    505                                 return 0; 
    506                         } else { 
    507                                 if (evdev->grab != client) 
    508                                         return -EINVAL; 
    509                                 input_release_device(&evdev->handle); 
    510                                 evdev->grab = NULL; 
     628                if (put_user(v, ip + 1)) 
     629                        return -EFAULT; 
     630 
     631                return 0; 
     632 
     633        case EVIOCSKEYCODE: 
     634                if (get_user(t, ip) || get_user(v, ip + 1)) 
     635                        return -EFAULT; 
     636 
     637                return dev->setkeycode(dev, t, v); 
     638 
     639        case EVIOCSFF: 
     640                if (copy_from_user(&effect, p, sizeof(effect))) 
     641                        return -EFAULT; 
     642 
     643                error = input_ff_upload(dev, &effect, file); 
     644 
     645                if (put_user(effect.id, &(((struct ff_effect __user *)p)->id))) 
     646                        return -EFAULT; 
     647 
     648                return error; 
     649 
     650        case EVIOCRMFF: 
     651                return input_ff_erase(dev, (int)(unsigned long) p, file); 
     652 
     653        case EVIOCGEFFECTS: 
     654                i = test_bit(EV_FF, dev->evbit) ? 
     655                                dev->ff->max_effects : 0; 
     656                if (put_user(i, ip)) 
     657                        return -EFAULT; 
     658                return 0; 
     659 
     660        case EVIOCGRAB: 
     661                if (p) 
     662                        return evdev_grab(evdev, client); 
     663                else 
     664                        return evdev_ungrab(evdev, client); 
     665 
     666        default: 
     667 
     668                if (_IOC_TYPE(cmd) != 'E') 
     669                        return -EINVAL; 
     670 
     671                if (_IOC_DIR(cmd) == _IOC_READ) { 
     672 
     673                        if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0))) { 
     674 
     675                                unsigned long *bits; 
     676                                int len; 
     677 
     678                                switch (_IOC_NR(cmd) & EV_MAX) { 
     679 
     680                                case      0: bits = dev->evbit;  len = EV_MAX;  break; 
     681                                case EV_KEY: bits = dev->keybit; len = KEY_MAX; break; 
     682                                case EV_REL: bits = dev->relbit; len = REL_MAX; break; 
     683                                case EV_ABS: bits = dev->absbit; len = ABS_MAX; break; 
     684                                case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break; 
     685                                case EV_LED: bits = dev->ledbit; len = LED_MAX; break; 
     686                                case EV_SND: bits = dev->sndbit; len = SND_MAX; break; 
     687                                case EV_FF:  bits = dev->ffbit;  len = FF_MAX;  break; 
     688                                case EV_SW:  bits = dev->swbit;  len = SW_MAX;  break; 
     689                                default: return -EINVAL; 
     690                        } 
     691                                return bits_to_user(bits, len, _IOC_SIZE(cmd), p, compat_mode); 
     692                        } 
     693 
     694                        if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) 
     695                                return bits_to_user(dev->key, KEY_MAX, _IOC_SIZE(cmd), 
     696                                                    p, compat_mode); 
     697 
     698                        if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) 
     699                                return bits_to_user(dev->led, LED_MAX, _IOC_SIZE(cmd), 
     700                                                    p, compat_mode); 
     701 
     702                        if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) 
     703                                return bits_to_user(dev->snd, SND_MAX, _IOC_SIZE(cmd), 
     704                                                    p, compat_mode); 
     705 
     706                        if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0))) 
     707                                return bits_to_user(dev->sw, SW_MAX, _IOC_SIZE(cmd), 
     708                                                    p, compat_mode); 
     709 
     710                        if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) 
     711                                return str_to_user(dev->name, _IOC_SIZE(cmd), p); 
     712 
     713                        if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) 
     714                                return str_to_user(dev->phys, _IOC_SIZE(cmd), p); 
     715 
     716                        if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) 
     717                                return str_to_user(dev->uniq, _IOC_SIZE(cmd), p); 
     718 
     719                        if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { 
     720 
     721                                t = _IOC_NR(cmd) & ABS_MAX; 
     722 
     723                                abs.value = dev->abs[t]; 
     724                                abs.minimum = dev->absmin[t]; 
     725                                abs.maximum = dev->absmax[t]; 
     726                                abs.fuzz = dev->absfuzz[t]; 
     727                                abs.flat = dev->absflat[t]; 
     728 
     729                                if (copy_to_user(p, &abs, sizeof(struct input_absinfo))) 
     730                                        return -EFAULT; 
     731 
    511732                                return 0; 
    512733                        } 
    513734 
    514                 default: 
    515  
    516                         if (_IOC_TYPE(cmd) != 'E') 
    517                                 return -EINVAL; 
    518  
    519                         if (_IOC_DIR(cmd) == _IOC_READ) { 
    520  
    521                                 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) { 
    522  
    523                                         unsigned long *bits; 
    524                                         int len; 
    525  
    526                                         switch (_IOC_NR(cmd) & EV_MAX) { 
    527                                                 case      0: bits = dev->evbit;  len = EV_MAX;  break; 
    528                                                 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break; 
    529                                                 case EV_REL: bits = dev->relbit; len = REL_MAX; break; 
    530                                                 case EV_ABS: bits = dev->absbit; len = ABS_MAX; break; 
    531                                                 case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break; 
    532                                                 case EV_LED: bits = dev->ledbit; len = LED_MAX; break; 
    533                                                 case EV_SND: bits = dev->sndbit; len = SND_MAX; break; 
    534                                                 case EV_FF:  bits = dev->ffbit;  len = FF_MAX;  break; 
    535                                                 case EV_SW:  bits = dev->swbit;  len = SW_MAX;  break; 
    536                                                 default: return -EINVAL; 
    537                                         } 
    538                                         return bits_to_user(bits, len, _IOC_SIZE(cmd), p, compat_mode); 
    539                                 } 
    540  
    541                                 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) 
    542                                         return bits_to_user(dev->key, KEY_MAX, _IOC_SIZE(cmd), 
    543                                                             p, compat_mode); 
    544  
    545                                 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) 
    546                                         return bits_to_user(dev->led, LED_MAX, _IOC_SIZE(cmd), 
    547                                                             p, compat_mode); 
    548  
    549                                 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) 
    550                                         return bits_to_user(dev->snd, SND_MAX, _IOC_SIZE(cmd), 
    551                                                             p, compat_mode); 
    552  
    553                                 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0))) 
    554                                         return bits_to_user(dev->sw, SW_MAX, _IOC_SIZE(cmd), 
    555                                                             p, compat_mode); 
    556  
    557                                 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) 
    558                                         return str_to_user(dev->name, _IOC_SIZE(cmd), p); 
    559  
    560                                 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) 
    561                                         return str_to_user(dev->phys, _IOC_SIZE(cmd), p); 
    562  
    563                                 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) 
    564                                         return str_to_user(dev->uniq, _IOC_SIZE(cmd), p); 
    565  
    566                                 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { 
    567  
    568                                         t = _IOC_NR(cmd) & ABS_MAX; 
    569  
    570                                         abs.value = dev->abs[t]; 
    571                                         abs.minimum = dev->absmin[t]; 
    572                                         abs.maximum = dev->absmax[t]; 
    573                                         abs.fuzz = dev->absfuzz[t]; 
    574                                         abs.flat = dev->absflat[t]; 
    575  
    576                                         if (copy_to_user(p, &abs, sizeof(struct input_absinfo))) 
    577                                                 return -EFAULT; 
    578  
    579                                         return 0; 
    580                                 } 
    581  
     735                } 
     736 
     737                if (_IOC_DIR(cmd) == _IOC_WRITE) { 
     738 
     739                        if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) { 
     740 
     741                                t = _IOC_NR(cmd) & ABS_MAX; 
     742 
     743                                if (copy_from_user(&abs, p, 
     744                                                sizeof(struct input_absinfo))) 
     745                                        return -EFAULT; 
     746 
     747                                /* 
     748                                 * Take event lock to ensure that we are not 
     749                                 * changing device parameters in the middle 
     750                                 * of event. 
     751                                 */ 
     752                                spin_lock_irq(&dev->event_lock); 
     753 
     754                                dev->abs[t] = abs.value; 
     755                                dev->absmin[t] = abs.minimum; 
     756                                dev->absmax[t] = abs.maximum; 
     757                                dev->absfuzz[t] = abs.fuzz; 
     758                                dev->absflat[t] = abs.flat; 
     759 
     760                                spin_unlock_irq(&dev->event_lock); 
     761 
     762                                return 0; 
    582763                        } 
    583  
    584                         if (_IOC_DIR(cmd) == _IOC_WRITE) { 
    585  
    586                                 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) { 
    587  
    588                                         t = _IOC_NR(cmd) & ABS_MAX; 
    589  
    590                                         if (copy_from_user(&abs, p, sizeof(struct input_absinfo))) 
    591                                                 return -EFAULT; 
    592  
    593                                         dev->abs[t] = abs.value; 
    594                                         dev->absmin[t] = abs.minimum; 
    595                                         dev->absmax[t] = abs.maximum; 
    596                                         dev->absfuzz[t] = abs.fuzz; 
    597                                         dev->absflat[t] = abs.flat; 
    598  
    599                                         return 0; 
    600                                 } 
    601                         } 
     764                } 
    602765        } 
    603766        return -EINVAL; 
    604767} 
    605768 
     769static long evdev_ioctl_handler(struct file *file, unsigned int cmd, 
     770                                void __user *p, int compat_mode) 
     771{ 
     772        struct evdev_client *client = file->private_data; 
     773        struct evdev *evdev = client->evdev; 
     774        int retval; 
     775 
     776        retval = mutex_lock_interruptible(&evdev->mutex); 
     777        if (retval) 
     778                return retval; 
     779 
     780        if (!evdev->exist) { 
     781                retval = -ENODEV; 
     782                goto out; 
     783        } 
     784 
     785        retval = evdev_do_ioctl(file, cmd, p, compat_mode); 
     786 
     787 out: 
     788        mutex_unlock(&evdev->mutex); 
     789        return retval; 
     790} 
     791 
    606792static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 
    607793{ 
     
    610796 
    611797#ifdef CONFIG_COMPAT 
    612 static long evdev_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) 
     798static long evdev_ioctl_compat(struct file *file, 
     799                                unsigned int cmd, unsigned long arg) 
    613800{ 
    614801        return evdev_ioctl_handler(file, cmd, compat_ptr(arg), 1); 
     
    617804 
    618805static const struct file_operations evdev_fops = { 
    619         .owner =        THIS_MODULE, 
    620         .read =         evdev_read, 
    621         .write =        evdev_write, 
    622         .poll =         evdev_poll, 
    623         .open =         evdev_open, 
    624         .release =      evdev_release, 
    625         .unlocked_ioctl = evdev_ioctl, 
     806        .owner          = THIS_MODULE, 
     807        .read           = evdev_read, 
     808        .write          = evdev_write, 
     809        .poll           = evdev_poll, 
     810        .open           = evdev_open, 
     811        .release        = evdev_release, 
     812        .unlocked_ioctl = evdev_ioctl, 
    626813#ifdef CONFIG_COMPAT 
    627         .compat_ioctl = evdev_ioctl_compat, 
     814        .compat_ioctl   = evdev_ioctl_compat, 
    628815#endif 
    629         .fasync =       evdev_fasync, 
    630         .flush =        evdev_flush 
     816        .fasync         = evdev_fasync, 
     817        .flush          = evdev_flush 
    631818}; 
    632819 
     820static int evdev_install_chrdev(struct evdev *evdev) 
     821{ 
     822        /* 
     823         * No need to do any locking here as calls to connect and 
     824         * disconnect are serialized by the input core 
     825         */ 
     826        evdev_table[evdev->minor] = evdev; 
     827        return 0; 
     828} 
     829 
     830static void evdev_remove_chrdev(struct evdev *evdev) 
     831{ 
     832        /* 
     833         * Lock evdev table to prevent race with evdev_open() 
     834         */ 
     835        mutex_lock(&evdev_table_mutex); 
     836        evdev_table[evdev->minor] = NULL; 
     837        mutex_unlock(&evdev_table_mutex); 
     838} 
     839 
     840/* 
     841 * Mark device non-existent. This disables writes, ioctls and 
     842 * prevents new users from opening the device. Already posted 
     843 * blocking reads will stay, however new ones will fail. 
     844 */ 
     845static void evdev_mark_dead(struct evdev *evdev) 
     846{ 
     847        mutex_lock(&evdev->mutex); 
     848        evdev->exist = 0; 
     849        mutex_unlock(&evdev->mutex); 
     850} 
     851 
     852static void evdev_cleanup(struct evdev *evdev) 
     853{ 
     854        struct input_handle *handle = &evdev->handle; 
     855 
     856        evdev_mark_dead(evdev); 
     857        evdev_hangup(evdev); 
     858        evdev_remove_chrdev(evdev); 
     859 
     860        /* evdev is marked dead so no one else accesses evdev->open */ 
     861        if (evdev->open) { 
     862                input_flush_device(handle, NULL); 
     863                input_close_device(handle); 
     864        } 
     865} 
     866 
     867/* 
     868 * Create new evdev device. Note that input core serializes calls 
     869 * to connect and disconnect so we don't need to lock evdev_table here. 
     870 */ 
    633871static int evdev_connect(struct input_handler *handler, struct input_dev *dev, 
    634872                         const struct input_device_id *id) 
     
    638876        int error; 
    639877 
    640         for (minor = 0; minor < EVDEV_MINORS && evdev_table[minor]; minor++); 
     878        for (minor = 0; minor < EVDEV_MINORS; minor++) 
     879                if (!evdev_table[minor]) 
     880                        break; 
     881 
    641882        if (minor == EVDEV_MINORS) { 
    642883                printk(KERN_ERR "evdev: no more free evdev devices\n"); 
     
    649890 
    650891        INIT_LIST_HEAD(&evdev->client_list); 
     892        spin_lock_init(&evdev->client_lock); 
     893        mutex_init(&evdev->mutex); 
    651894        init_waitqueue_head(&evdev->wait); 
    652895 
     896        snprintf(evdev->name, sizeof(evdev->name), "event%d", minor); 
    653897        evdev->exist = 1; 
    654898        evdev->minor = minor; 
     899 
    655900        evdev->handle.dev = dev; 
    656901        evdev->handle.name = evdev->name; 
    657902        evdev->handle.handler = handler; 
    658903        evdev->handle.private = evdev; 
    659         snprintf(evdev->name, sizeof(evdev->name), "event%d", minor); 
    660  
    661         snprintf(evdev->dev.bus_id, sizeof(evdev->dev.bus_id), 
    662                  "event%d", minor); 
     904 
     905        strlcpy(evdev->dev.bus_id, evdev->name, sizeof(evdev->dev.bus_id)); 
     906        evdev->dev.devt = MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor); 
    663907        evdev->dev.class = &input_class; 
    664908        evdev->dev.parent = &dev->dev; 
    665         evdev->dev.devt = MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor); 
    666909        evdev->dev.release = evdev_free; 
    667910        device_initialize(&evdev->dev); 
    668911 
    669         evdev_table[minor] = evdev; 
     912        error = input_register_handle(&evdev->handle); 
     913        if (error) 
     914                goto err_free_evdev; 
     915 
     916        error = evdev_install_chrdev(evdev); 
     917        if (error) 
     918                goto err_unregister_handle; 
    670919 
    671920        error = device_add(&evdev->dev); 
    672921        if (error) 
    673                 goto err_free_evdev; 
    674  
    675         error = input_register_handle(&evdev->handle); 
    676         if (error) 
    677                 goto err_delete_evdev; 
     922                goto err_cleanup_evdev; 
    678923 
    679924        return 0; 
    680925 
    681  err_delete_evdev: 
    682         device_del(&evdev->dev); 
     926 err_cleanup_evdev: 
     927        evdev_cleanup(evdev); 
     928 err_unregister_handle: 
     929        input_unregister_handle(&evdev->handle); 
    683930 err_free_evdev: 
    684931        put_device(&evdev->dev); 
     
    689936{ 
    690937        struct evdev *evdev = handle->private; 
    691         struct evdev_client *client; 
    692  
     938 
     939        device_del(&evdev->dev); 
     940        evdev_cleanup(evdev); 
    693941        input_unregister_handle(handle); 
    694         device_del(&evdev->dev); 
    695  
    696         evdev->exist = 0; 
    697  
    698         if (evdev->open) { 
    699                 input_flush_device(handle, NULL); 
    700                 input_close_device(handle); 
    701                 list_for_each_entry(client, &evdev->client_list, node) 
    702                         kill_fasync(&client->fasync, SIGIO, POLL_HUP); 
    703                 wake_up_interruptible(&evdev->wait); 
    704         } 
    705  
    706942        put_device(&evdev->dev); 
    707943} 
     
    715951 
    716952static struct input_handler evdev_handler = { 
    717         .event =        evdev_event, 
    718         .connect =      evdev_connect, 
    719         .disconnect =   evdev_disconnect, 
    720         .fops =         &evdev_fops, 
    721         .minor =        EVDEV_MINOR_BASE, 
    722         .name =         "evdev", 
    723         .id_table =     evdev_ids, 
     953        .event          = evdev_event, 
     954        .connect        = evdev_connect, 
     955        .disconnect     = evdev_disconnect, 
     956        .fops           = &evdev_fops, 
     957        .minor          = EVDEV_MINOR_BASE, 
     958        .name           = "evdev", 
     959        .id_table       = evdev_ids, 
    724960}; 
    725961 
  • src/linux/ar531x/linux-2.6.23/drivers/input/input.c

    r8169 r9058  
    1818#include <linux/proc_fs.h> 
    1919#include <linux/seq_file.h> 
    20 #include <linux/interrupt.h> 
    2120#include <linux/poll.h> 
    2221#include <linux/device.h> 
    2322#include <linux/mutex.h> 
     23#include <linux/rcupdate.h> 
    2424 
    2525MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); 
     
    3232static LIST_HEAD(input_handler_list); 
    3333 
     34/* 
     35 * input_mutex protects access to both input_dev_list and input_handler_list. 
     36 * This also causes input_[un]register_device and input_[un]register_handler 
     37 * be mutually exclusive which simplifies locking in drivers implementing 
     38 * input handlers. 
     39 */ 
     40static DEFINE_MUTEX(input_mutex); 
     41 
    3442static struct input_handler *input_table[8]; 
     43 
     44static inline int is_event_supported(unsigned int code, 
     45                                     unsigned long *bm, unsigned int max) 
     46{ 
     47        return code <= max && test_bit(code, bm); 
     48} 
     49 
     50static int input_defuzz_abs_event(int value, int old_val, int fuzz) 
     51{ 
     52        if (fuzz) { 
     53                if (value > old_val - fuzz / 2 && value < old_val + fuzz / 2) 
     54                        return old_val; 
     55 
     56                if (value > old_val - fuzz && value < old_val + fuzz) 
     57                        return (old_val * 3 + value) / 4; 
     58 
     59                if (value > old_val - fuzz * 2 && value < old_val + fuzz * 2) 
     60                        return (old_val + value) / 2; 
     61        } 
     62 
     63        return value; 
     64} 
     65 
     66/* 
     67 * Pass event through all open handles. This function is called with 
     68 * dev->event_lock held and interrupts disabled. Because of that we 
     69 * do not need to use rcu_read_lock() here although we are using RCU 
     70 * to access handle list. Note that because of that write-side uses 
     71 * synchronize_sched() instead of synchronize_ru(). 
     72 */ 
     73static void input_pass_event(struct input_dev *dev, 
     74                             unsigned int type, unsigned int code, int value) 
     75{ 
     76        struct input_handle *handle = rcu_dereference(dev->grab); 
     77 
     78        if (handle) 
     79                handle->handler->event(handle, type, code, value); 
     80        else 
     81                list_for_each_entry_rcu(handle, &dev->h_list, d_node) 
     82                        if (handle->open) 
     83                                handle->handler->event(handle, 
     84                                                        type, code, value); 
     85} 
     86 
     87/* 
     88 * Generate software autorepeat event. Note that we take 
     89 * dev->event_lock here to avoid racing with input_event 
     90 * which may cause keys get "stuck". 
     91 */ 
     92static void input_repeat_key(unsigned long data) 
     93{ 
     94        struct input_dev *dev = (void *) data; 
     95        unsigned long flags; 
     96 
     97        spin_lock_irqsave(&dev->event_lock, flags); 
     98 
     99        if (test_bit(dev->repeat_key, dev->key) && 
     100            is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { 
     101 
     102                input_pass_event(dev, EV_KEY, dev->repeat_key, 2); 
     103 
     104                if (dev->sync) { 
     105                        /* 
     106                         * Only send SYN_REPORT if we are not in a middle 
     107                         * of driver parsing a new hardware packet. 
     108                         * Otherwise assume that the driver will send 
     109                         * SYN_REPORT once it's done. 
     110                         */ 
     111                        input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 
     112                } 
     113 
     114                if (dev->rep[REP_PERIOD]) 
     115                        mod_timer(&dev->timer, jiffies + 
     116                                        msecs_to_jiffies(dev->rep[REP_PERIOD])); 
     117        } 
     118 
     119        spin_unlock_irqrestore(&dev->event_lock, flags); 
     120} 
     121 
     122static void input_start_autorepeat(struct input_dev *dev, int code) 
     123{ 
     124        if (test_bit(EV_REP, dev->evbit) && 
     125            dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] && 
     126            dev->timer.data) { 
     127                dev->repeat_key = code; 
     128                mod_timer(&dev->timer, 
     129                          jiffies + msecs_to_jiffies(dev->rep[REP_DELAY])); 
     130        } 
     131} 
     132 
     133#define INPUT_IGNORE_EVENT      0 
     134#define INPUT_PASS_TO_HANDLERS  1 
     135#define INPUT_PASS_TO_DEVICE    2 
     136#define INPUT_PASS_TO_ALL       (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) 
     137 
     138static void input_handle_event(struct input_dev *dev, 
     139                               unsigned int type, unsigned int code, int value) 
     140{ 
     141        int disposition = INPUT_IGNORE_EVENT; 
     142 
     143        switch (type) { 
     144 
     145        case EV_SYN: 
     146                switch (code) { 
     147                case SYN_CONFIG: 
     148                        disposition = INPUT_PASS_TO_ALL; 
     149                        break; 
     150 
     151                case SYN_REPORT: 
     152                        if (!dev->sync) { 
     153                                dev->sync = 1; 
     154                                disposition = INPUT_PASS_TO_HANDLERS; 
     155                        } 
     156                        break; 
     157                } 
     158                break; 
     159 
     160        case EV_KEY: 
     161                if (is_event_supported(code, dev->keybit, KEY_MAX) && 
     162                    !!test_bit(code, dev->key) != value) { 
     163 
     164                        if (value != 2) { 
     165                                __change_bit(code, dev->key); 
     166                                if (value) 
     167                                        input_start_autorepeat(dev, code); 
     168                        } 
     169 
     170                        disposition = INPUT_PASS_TO_HANDLERS; 
     171                } 
     172                break; 
     173 
     174        case EV_SW: 
     175                if (is_event_supported(code, dev->swbit, SW_MAX) && 
     176                    !!test_bit(code, dev->sw) != value) { 
     177 
     178                        __change_bit(code, dev->sw); 
     179                        disposition = INPUT_PASS_TO_HANDLERS; 
     180                } 
     181                break; 
     182 
     183        case EV_ABS: 
     184                if (is_event_supported(code, dev->absbit, ABS_MAX)) { 
     185 
     186                        value = input_defuzz_abs_event(value, 
     187                                        dev->abs[code], dev->absfuzz[code]); 
     188 
     189                        if (dev->abs[code] != value) { 
     190                                dev->abs[code] = value; 
     191                                disposition = INPUT_PASS_TO_HANDLERS; 
     192                        } 
     193                } 
     194                break; 
     195 
     196        case EV_REL: 
     197                if (is_event_supported(code, dev->relbit, REL_MAX) && value) 
     198                        disposition = INPUT_PASS_TO_HANDLERS; 
     199 
     200                break; 
     201 
     202        case EV_MSC: 
     203                if (is_event_supported(code, dev->mscbit, MSC_MAX)) 
     204                        disposition = INPUT_PASS_TO_ALL; 
     205 
     206                break; 
     207 
     208        case EV_LED: 
     209                if (is_event_supported(code, dev->ledbit, LED_MAX) && 
     210                    !!test_bit(code, dev->led) != value) { 
     211 
     212                        __change_bit(code, dev->led); 
     213                        disposition = INPUT_PASS_TO_ALL; 
     214                } 
     215                break; 
     216 
     217        case EV_SND: 
     218                if (is_event_supported(code, dev->sndbit, SND_MAX)) { 
     219 
     220                        if (!!test_bit(code, dev->snd) != !!value) 
     221                                __change_bit(code, dev->snd); 
     222                        disposition = INPUT_PASS_TO_ALL; 
     223                } 
     224                break; 
     225 
     226        case EV_REP: 
     227                if (code <= REP_MAX && value >= 0 && dev->rep[code] != value) { 
     228                        dev->rep[code] = value; 
     229                        disposition = INPUT_PASS_TO_ALL; 
     230                } 
     231                break; 
     232 
     233        case EV_FF: 
     234                if (value >= 0) 
     235                        disposition = INPUT_PASS_TO_ALL; 
     236                break; 
     237        } 
     238 
     239        if (type != EV_SYN) 
     240                dev->sync = 0; 
     241 
     242        if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) 
     243                dev->event(dev, type, code, value); 
     244 
     245        if (disposition & INPUT_PASS_TO_HANDLERS) 
     246                input_pass_event(dev, type, code, value); 
     247} 
    35248 
    36249/** 
     
    41254 * @value: value of the event 
    42255 * 
    43  * This function should be used by drivers implementing various input devices 
    44  * See also input_inject_event() 
    45  */ 
    46 void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 
    47 { 
    48         struct input_handle *handle; 
    49  
    50         if (type > EV_MAX || !test_bit(type, dev->evbit)) 
    51                 return; 
    52  
    53         add_input_randomness(type, code, value); 
    54  
    55         switch (type) { 
    56  
    57                 case EV_SYN: 
    58                         switch (code) { 
    59                                 case SYN_CONFIG: 
    60                                         if (dev->event) 
    61                                                 dev->event(dev, type, code, value); 
    62                                         break; 
    63  
    64                                 case SYN_REPORT: 
    65                                         if (dev->sync) 
    66                                                 return; 
    67                                         dev->sync = 1; 
    68                                         break; 
    69                         } 
    70                         break; 
    71  
    72                 case EV_KEY: 
    73  
    74                         if (code > KEY_MAX || !test_bit(code, dev->keybit) || !!test_bit(code, dev->key) == value) 
    75                                 return; 
    76  
    77                         if (value == 2) 
    78                                 break; 
    79  
    80                         change_bit(code, dev->key); 
    81  
    82                         if (test_bit(EV_REP, dev->evbit) && dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] && dev->timer.data && value) { 
    83                                 dev->repeat_key = code; 
    84                                 mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_DELAY])); 
    85                         } 
    86  
    87                         break; 
    88  
    89                 case EV_SW: 
    90  
    91                         if (code > SW_MAX || !test_bit(code, dev->swbit) || !!test_bit(code, dev->sw) == value) 
    92                                 return; 
    93  
    94                         change_bit(code, dev->sw); 
    95  
    96                         break; 
    97  
    98                 case EV_ABS: 
    99  
    100                         if (code > ABS_MAX || !test_bit(code, dev->absbit)) 
    101                                 return; 
    102  
    103                         if (dev->absfuzz[code]) { 
    104                                 if ((value > dev->abs[code] - (dev->absfuzz[code] >> 1)) && 
    105                                     (value < dev->abs[code] + (dev->absfuzz[code] >> 1))) 
    106                                         return; 
    107  
    108                                 if ((value > dev->abs[code] - dev->absfuzz[code]) && 
    109                                     (value < dev->abs[code] + dev->absfuzz[code])) 
    110                                         value = (dev->abs[code] * 3 + value) >> 2; 
    111  
    112                                 if ((value > dev->abs[code] - (dev->absfuzz[code] << 1)) && 
    113                                     (value < dev->abs[code] + (dev->absfuzz[code] << 1))) 
    114                                         value = (dev->abs[code] + value) >> 1; 
    115                         } 
    116  
    117                         if (dev->abs[code] == value) 
    118                                 return; 
    119  
    120                         dev->abs[code] = value; 
    121                         break; 
    122  
    123                 case EV_REL: 
    124  
    125                         if (code > REL_MAX || !test_bit(code, dev->relbit) || (value == 0)) 
    126                                 return; 
    127  
    128                         break; 
    129  
    130                 case EV_MSC: 
    131  
    132                         if (code > MSC_MAX || !test_bit(code, dev->mscbit)) 
    133                                 return; 
    134  
    135                         if (dev->event) 
    136                                 dev->event(dev, type, code, value); 
    137  
    138                         break; 
    139  
    140                 case EV_LED: 
    141  
    142                         if (code > LED_MAX || !test_bit(code, dev->ledbit) || !!test_bit(code, dev->led) == value) 
    143                                 return; 
    144  
    145                         change_bit(code, dev->led); 
    146  
    147                         if (dev->event) 
    148                                 dev->event(dev, type, code, value); 
    149  
    150                         break; 
    151  
    152                 case EV_SND: 
    153  
    154                         if (code > SND_MAX || !test_bit(code, dev->sndbit)) 
    155                                 return; 
    156  
    157                         if (!!test_bit(code, dev->snd) != !!value) 
    158                                 change_bit(code, dev->snd); 
    159  
    160                         if (dev->event) 
    161                                 dev->event(dev, type, code, value); 
    162  
    163                         break; 
    164  
    165                 case EV_REP: 
    166  
    167                         if (code > REP_MAX || value < 0 || dev->rep[code] == value) 
    168                                 return; 
    169  
    170                         dev->rep[code] = value; 
    171                         if (dev->event) 
    172                                 dev->event(dev, type, code, value); 
    173  
    174                         break; 
    175  
    176                 case EV_FF: 
    177  
    178                         if (value < 0) 
    179                                 return; 
    180  
    181                         if (dev->event) 
    182                                 dev->event(dev, type, code, value); 
    183                         break; 
    184         } 
    185  
    186         if (type != EV_SYN) 
    187                 dev->sync = 0; 
    188  
    189         if (dev->grab) 
    190                 dev->grab->handler->event(dev->grab, type, code, value); 
    191         else 
    192                 list_for_each_entry(handle, &dev->h_list, d_node) 
    193                         if (handle->open) 
    194                                 handle->handler->event(handle, type, code, value); 
     256 * This function should be used by drivers implementing various input 
     257 * devices. See also input_inject_event(). 
     258 */ 
     259 
     260void input_event(struct input_dev *dev, 
     261                 unsigned int type, unsigned int code, int value) 
     262{ 
     263        unsigned long flags; 
     264 
     265        if (is_event_supported(type, dev->evbit, EV_MAX)) { 
     266 
     267                spin_lock_irqsave(&dev->event_lock, flags); 
     268                add_input_randomness(type, code, value); 
     269                input_handle_event(dev, type, code, value); 
     270                spin_unlock_irqrestore(&dev->event_lock, flags); 
     271        } 
    195272} 
    196273EXPORT_SYMBOL(input_event); 
     
    203280 * @value: value of the event 
    204281 * 
    205  * Similar to input_event() but will ignore event if device is "grabbed" and handle 
    206  * injecting event is not the one that owns the device. 
    207  */ 
    208 void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) 
    209 { 
    210         if (!handle->dev->grab || handle->dev->grab == handle) 
    211                 input_event(handle->dev, type, code, value); 
     282 * Similar to input_event() but will ignore event if device is 
     283 * "grabbed" and handle injecting event is not the one that owns 
     284 * the device. 
     285 */ 
     286void input_inject_event(struct input_handle *handle, 
     287                        unsigned int type, unsigned int code, int value) 
     288{ 
     289        struct input_dev *dev = handle->dev; 
     290        struct input_handle *grab; 
     291        unsigned long flags; 
     292 
     293        if (is_event_supported(type, dev->evbit, EV_MAX)) { 
     294                spin_lock_irqsave(&dev->event_lock, flags); 
     295 
     296                grab = rcu_dereference(dev->grab); 
     297                if (!grab || grab == handle) 
     298                        input_handle_event(dev, type, code, value); 
     299 
     300                spin_unlock_irqrestore(&dev->event_lock, flags); 
     301        } 
    212302} 
    213303EXPORT_SYMBOL(input_inject_event); 
    214304 
    215 static void input_repeat_key(unsigned long data) 
    216 { 
    217         struct input_dev *dev = (void *) data; 
    218  
    219         if (!test_bit(dev->repeat_key, dev->key)) 
    220                 return; 
    221  
    222         input_event(dev, EV_KEY, dev->repeat_key, 2); 
    223         input_sync(dev); 
    224  
    225         if (dev->rep[REP_PERIOD]) 
    226                 mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_PERIOD])); 
    227 } 
    228  
     305/** 
     306 * input_grab_device - grabs device for exclusive use 
     307 * @handle: input handle that wants to own the device 
     308 * 
     309 * When a device is grabbed by an input handle all events generated by 
     310 * the device are delivered only to this handle. Also events injected 
     311 * by other input handles are ignored while device is grabbed. 
     312 */ 
    229313int input_grab_device(struct input_handle *handle) 
    230314{ 
    231         if (handle->dev->grab) 
    232                 return -EBUSY; 
    233  
    234         handle->dev->grab = handle; 
    235         return 0; 
     315        struct input_dev *dev = handle->dev; 
     316        int retval; 
     317 
     318        retval = mutex_lock_interruptible(&dev->mutex); 
     319        if (retval) 
     320                return retval; 
     321 
     322        if (dev->grab) { 
     323                retval = -EBUSY; 
     324                goto out; 
     325        } 
     326 
     327        rcu_assign_pointer(dev->grab, handle); 
     328        /* 
     329         * Not using synchronize_rcu() because read-side is protected 
     330         * by a spinlock with interrupts off instead of rcu_read_lock(). 
     331         */ 
     332        synchronize_sched(); 
     333 
     334 out: 
     335        mutex_unlock(&dev->mutex); 
     336        return retval; 
    236337} 
    237338EXPORT_SYMBOL(input_grab_device); 
    238339 
     340static void __input_release_device(struct input_handle *handle) 
     341{ 
     342        struct input_dev *dev = handle->dev; 
     343 
     344        if (dev->grab == handle) { 
     345                rcu_assign_pointer(dev->grab, NULL); 
     346                /* Make sure input_pass_event() notices that grab is gone */ 
     347                synchronize_sched(); 
     348 
     349                list_for_each_entry(handle, &dev->h_list, d_node) 
     350                        if (handle->open && handle->handler->start) 
     351                                handle->handler->start(handle); 
     352        } 
     353} 
     354 
     355/** 
     356 * input_release_device - release previously grabbed device 
     357 * @handle: input handle that owns the device 
     358 * 
     359 * Releases previously grabbed device so that other input handles can 
     360 * start receiving input events. Upon release all handlers attached 
     361 * to the device have their start() method called so they have a change 
     362 * to synchronize device state with the rest of the system. 
     363 */ 
    239364void input_release_device(struct input_handle *handle) 
    240365{ 
    241366        struct input_dev *dev = handle->dev; 
    242367 
    243         if (dev->grab == handle) { 
    244                 dev->grab = NULL; 
    245  
    246                 list_for_each_entry(handle, &dev->h_list, d_node) 
    247                         if (handle->handler->start) 
    248                                 handle->handler->start(handle); 
    249         } 
     368        mutex_lock(&dev->mutex); 
     369        __input_release_device(handle); 
     370        mutex_unlock(&dev->mutex); 
    250371} 
    251372EXPORT_SYMBOL(input_release_device); 
    252373 
     374/** 
     375 * input_open_device - open input device 
     376 * @handle: handle through which device is being accessed 
     377 * 
     378 * This function should be called by input handlers when they 
     379 * want to start receive events from given input device. 
     380 */ 
    253381int input_open_device(struct input_handle *handle) 
    254382{ 
    255383        struct input_dev *dev = handle->dev; 
    256         int err; 
    257  
    258         err = mutex_lock_interruptible(&dev->mutex); 
    259         if (err) 
    260                 return err; 
     384        int retval; 
     385 
     386        retval = mutex_lock_interruptible(&dev->mutex); 
     387        if (retval) 
     388                return retval; 
     389 
     390        if (dev->going_away) { 
     391                retval = -ENODEV; 
     392                goto out; 
     393        } 
    261394 
    262395        handle->open++; 
    263396 
    264397        if (!dev->users++ && dev->open) 
    265                 err = dev->open(dev); 
    266  
    267         if (err) 
    268                 handle->open--; 
    269  
     398                retval = dev->open(dev); 
     399 
     400        if (retval) { 
     401                dev->users--; 
     402                if (!--handle->open) { 
     403                        /* 
     404                         * Make sure we are not delivering any more events 
     405                         * through this handle 
     406                         */ 
     407                        synchronize_sched(); 
     408                } 
     409        } 
     410 
     411 out: 
    270412        mutex_unlock(&dev->mutex); 
    271  
    272         return err; 
     413        return retval; 
    273414} 
    274415EXPORT_SYMBOL(input_open_device); 
    275416 
    276 int input_flush_device(struct input_handle* handle, struct file* file) 
    277 { 
    278         if (handle->dev->flush) 
    279                 return handle->dev->flush(handle->dev, file); 
    280  
    281         return 0; 
     417int input_flush_device(struct input_handle *handle, struct file *file) 
     418{ 
     419        struct input_dev *dev = handle->dev; 
     420        int retval; 
     421 
     422        retval = mutex_lock_interruptible(&dev->mutex); 
     423        if (retval) 
     424                return retval; 
     425 
     426        if (dev->flush) 
     427                retval = dev->flush(dev, file); 
     428 
     429        mutex_unlock(&dev->mutex); 
     430        return retval; 
    282431} 
    283432EXPORT_SYMBOL(input_flush_device); 
    284433 
     434/** 
     435 * input_close_device - close input device 
     436 * @handle: handle through which device is being accessed 
     437 * 
     438 * This function should be called by input handlers when they 
     439 * want to stop receive events from given input device. 
     440 */ 
    285441void input_close_device(struct input_handle *handle) 
    286442{ 
    287443        struct input_dev *dev = handle->dev; 
    288444 
    289         input_release_device(handle); 
    290  
    291445        mutex_lock(&dev->mutex); 
     446 
     447        __input_release_device(handle); 
    292448 
    293449        if (!--dev->users && dev->close) 
    294450                dev->close(dev); 
    295         handle->open--; 
     451 
     452        if (!--handle->open) { 
     453                /* 
     454                 * synchronize_sched() makes sure that input_pass_event() 
     455                 * completed and that no more input events are delivered 
     456                 * through this handle 
     457                 */ 
     458                synchronize_sched(); 
     459        } 
    296460 
    297461        mutex_unlock(&dev->mutex); 
    298462} 
    299463EXPORT_SYMBOL(input_close_device); 
     464 
     465/* 
     466 * Prepare device for unregistering 
     467 */ 
     468static void input_disconnect_device(struct input_dev *dev) 
     469{ 
     470        struct input_handle *handle; 
     471        int code; 
     472 
     473        /* 
     474         * Mark device as going away. Note that we take dev->mutex here 
     475         * not to protect access to dev->going_away but rather to ensure 
     476         * that there are no threads in the middle of input_open_device() 
     477         */ 
     478        mutex_lock(&dev->mutex); 
     479        dev->going_away = 1; 
     480        mutex_unlock(&dev->mutex); 
     481 
     482        spin_lock_irq(&dev->event_lock); 
     483 
     484        /* 
     485         * Simulate keyup events for all pressed keys so that handlers 
     486         * are not left with "stuck" keys. The driver may continue 
     487         * generate events even after we done here but they will not 
     488         * reach any handlers. 
     489         */ 
     490        if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { 
     491                for (code = 0; code <= KEY_MAX; code++) { 
     492                        if (is_event_supported(code, dev->keybit, KEY_MAX) && 
     493                            test_bit(code, dev->key)) { 
     494                                input_pass_event(dev, EV_KEY, code, 0); 
     495                        } 
     496                } 
     497                input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 
     498        } 
     499 
     500        list_for_each_entry(handle, &dev->h_list, d_node) 
     501                handle->open = 0; 
     502 
     503        spin_unlock_irq(&dev->event_lock); 
     504} 
    300505 
    301506static int input_fetch_keycode(struct input_dev *dev, int scancode) 
     
    474679static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos) 
    475680{ 
    476         /* acquire lock here ... Yes, we do need locking, I knowi, I know... */ 
     681        if (mutex_lock_interruptible(&input_mutex)) 
     682                return NULL; 
    477683 
    478684        return seq_list_start(&input_dev_list, *pos); 
     
    486692static void input_devices_seq_stop(struct seq_file *seq, void *v) 
    487693{ 
    488         /* release lock here */ 
     694        mutex_unlock(&input_mutex); 
    489695} 
    490696 
     
    570776static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos) 
    571777{ 
    572         /* acquire lock here ... Yes, we do need locking, I knowi, I know... */ 
     778        if (mutex_lock_interruptible(&input_mutex)) 
     779                return NULL; 
     780 
    573781        seq->private = (void *)(unsigned long)*pos; 
    574782        return seq_list_start(&input_handler_list, *pos); 
     
    583791static void input_handlers_seq_stop(struct seq_file *seq, void *v) 
    584792{ 
    585         /* release lock here */ 
     793        mutex_unlock(&input_mutex); 
    586794} 
    587795 
     
    10061214                device_initialize(&dev->dev); 
    10071215                mutex_init(&dev->mutex); 
     1216                spin_lock_init(&dev->event_lock); 
    10081217                INIT_LIST_HEAD(&dev->h_list); 
    10091218                INIT_LIST_HEAD(&dev->node); 
     
    10231232 * was not called yet or if it failed. Once device was registered 
    10241233 * use input_unregister_device() and memory will be freed once last 
    1025  * refrence to the device is dropped. 
     1234 * reference to the device is dropped. 
    10261235 * 
    10271236 * Device should be allocated by input_allocate_device(). 
     
    10931302EXPORT_SYMBOL(input_set_capability); 
    10941303 
     1304/** 
     1305 * input_register_device - register device with input core 
     1306 * @dev: device to be registered 
     1307 * 
     1308 * This function registers device with input core. The device must be 
     1309 * allocated with input_allocate_device() and all it's capabilities 
     1310 * set up before registering. 
     1311 * If function fails the device must be freed with input_free_device(). 
     1312 * Once device has been successfully registered it can be unregistered 
     1313 * with input_unregister_device(); input_free_device() should not be 
     1314 * called in this case. 
     1315 */ 
    10951316int input_register_device(struct input_dev *dev) 
    10961317{ 
     
    11001321        int error; 
    11011322 
    1102         set_bit(EV_SYN, dev->evbit); 
     1323        __set_bit(EV_SYN, dev->evbit); 
    11031324 
    11041325        /* 
     
    11211342                dev->setkeycode = input_default_setkeycode; 
    11221343 
    1123         list_add_tail(&dev->node, &input_dev_list); 
    1124  
    11251344        snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id), 
    11261345                 "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1); 
     
    11381357        kfree(path); 
    11391358 
     1359        error = mutex_lock_interruptible(&input_mutex); 
     1360        if (error) { 
     1361                device_del(&dev->dev); 
     1362                return error; 
     1363        } 
     1364 
     1365        list_add_tail(&dev->node, &input_dev_list); 
     1366 
    11401367        list_for_each_entry(handler, &input_handler_list, node) 
    11411368                input_attach_handler(dev, handler); 
     
    11431370        input_wakeup_procfs_readers(); 
    11441371 
     1372        mutex_unlock(&input_mutex); 
     1373 
    11451374        return 0; 
    11461375} 
    11471376EXPORT_SYMBOL(input_register_device); 
    11481377 
     1378/** 
     1379 * input_unregister_device - unregister previously registered device 
     1380 * @dev: device to be unregistered 
     1381 * 
     1382 * This function unregisters an input device. Once device is unregistered 
     1383 * the caller should not try to access it as it may get freed at any moment. 
     1384 */ 
    11491385void input_unregister_device(struct input_dev *dev) 
    11501386{ 
    11511387        struct input_handle *handle, *next; 
    1152         int code; 
    1153  
    1154         for (code = 0; code <= KEY_MAX; code++) 
    1155                 if (test_bit(code, dev->key)) 
    1156                         input_report_key(dev, code, 0); 
    1157         input_sync(dev); 
    1158  
    1159         del_timer_sync(&dev->timer); 
     1388 
     1389        input_disconnect_device(dev); 
     1390 
     1391        mutex_lock(&input_mutex); 
    11601392 
    11611393        list_for_each_entry_safe(handle, next, &dev->h_list, d_node) 
     
    11631395        WARN_ON(!list_empty(&dev->h_list)); 
    11641396 
     1397        del_timer_sync(&dev->timer); 
    11651398        list_del_init(&dev->node); 
    11661399 
     1400        input_wakeup_procfs_readers(); 
     1401 
     1402        mutex_unlock(&input_mutex); 
     1403 
    11671404        device_unregister(&dev->dev); 
    1168  
    1169         input_wakeup_procfs_readers(); 
    11701405} 
    11711406EXPORT_SYMBOL(input_unregister_device); 
    11721407 
     1408/** 
     1409 * input_register_handler - register a new input handler 
     1410 * @handler: handler to be registered 
     1411 * 
     1412 * This function registers a new input handler (interface) for input 
     1413 * devices in the system and attaches it to all input devices that 
     1414 * are compatible with the handler. 
     1415 */ 
    11731416int input_register_handler(struct input_handler *handler) 
    11741417{ 
    11751418        struct input_dev *dev; 
     1419        int retval; 
     1420 
     1421        retval = mutex_lock_interruptible(&input_mutex); 
     1422        if (retval) 
     1423                return retval; 
    11761424 
    11771425        INIT_LIST_HEAD(&handler->h_list); 
    11781426 
    11791427        if (handler->fops != NULL) { 
    1180                 if (input_table[handler->minor >> 5]) 
    1181                         return -EBUSY; 
    1182  
     1428                if (input_table[handler->minor >> 5]) { 
     1429                        retval = -EBUSY; 
     1430                        goto out; 
     1431                } 
    11831432                input_table[handler->minor >> 5] = handler; 
    11841433        } 
     
    11901439 
    11911440        input_wakeup_procfs_readers(); 
    1192         return 0; 
     1441 
     1442 out: 
     1443        mutex_unlock(&input_mutex); 
     1444        return retval; 
    11931445} 
    11941446EXPORT_SYMBOL(input_register_handler); 
    11951447 
     1448/** 
     1449 * input_unregister_handler - unregisters an input handler 
     1450 * @handler: handler to be unregistered 
     1451 * 
     1452 * This function disconnects a handler from its input devices and 
     1453 * removes it from lists of known handlers. 
     1454 */ 
    11961455void input_unregister_handler(struct input_handler *handler) 
    11971456{ 
    11981457        struct input_handle *handle, *next; 
     1458 
     1459        mutex_lock(&input_mutex); 
    11991460 
    12001461        list_for_each_entry_safe(handle, next, &handler->h_list, h_node) 
     
    12081469 
    12091470        input_wakeup_procfs_readers(); 
     1471 
     1472        mutex_unlock(&input_mutex); 
    12101473} 
    12111474EXPORT_SYMBOL(input_unregister_handler); 
    12121475 
     1476/** 
     1477 * input_register_handle - register a new input handle 
     1478 * @handle: handle to register 
     1479 * 
     1480 * This function puts a new input handle onto device's 
     1481 * and handler's lists so that events can flow through 
     1482 * it once it is opened using input_open_device(). 
     1483 * 
     1484 * This function is supposed to be called from handler's 
     1485 * connect() method. 
     1486 */ 
    12131487int input_register_handle(struct input_handle *handle) 
    12141488{ 
    12151489        struct input_handler *handler = handle->handler; 
    1216  
    1217         list_add_tail(&handle->d_node, &handle->dev->h_list); 
     1490        struct input_dev *dev = handle->dev; 
     1491        int error; 
     1492 
     1493        /* 
     1494         * We take dev->mutex here to prevent race with 
     1495         * input_release_device(). 
     1496         */ 
     1497        error = mutex_lock_interruptible(&dev->mutex); 
     1498        if (error) 
     1499                return error; 
     1500        list_add_tail_rcu(&handle->d_node, &dev->h_list); 
     1501        mutex_unlock(&dev->mutex); 
     1502        /* 
     1503         * We don't use synchronize_rcu() here because we rely 
     1504         * on dev->event_lock to protect read-side critical 
     1505         * section in input_pass_event(). 
     1506         */ 
     1507        synchronize_sched(); 
     1508 
     1509        /* 
     1510         * Since we are supposed to be called from ->connect() 
     1511         * which is mutually exclusive with ->disconnect() 
     1512         * we can't be racing with input_unregister_handle() 
     1513         * and so separate lock is not needed here. 
     1514         */ 
    12181515        list_add_tail(&handle->h_node, &handler->h_list); 
    12191516 
     
    12251522EXPORT_SYMBOL(input_register_handle); 
    12261523 
     1524/** 
     1525 * input_unregister_handle - unregister an input handle 
     1526 * @handle: handle to unregister 
     1527 * 
     1528 * This function removes input handle from device's 
     1529 * and handler's lists. 
     1530 * 
     1531 * This function is supposed to be called from handler's 
     1532 * disconnect() method. 
     1533 */ 
    12271534void input_unregister_handle(struct input_handle *handle) 
    12281535{ 
     1536        struct input_dev *dev = handle->dev; 
     1537 
    12291538        list_del_init(&handle->h_node); 
    1230         list_del_init(&handle->d_node); 
     1539 
     1540        /* 
     1541         * Take dev->mutex to prevent race with input_release_device(). 
     1542         */ 
     1543        mutex_lock(&dev->mutex); 
     1544        list_del_rcu(&handle->d_node); 
     1545        mutex_unlock(&dev->mutex); 
     1546        synchronize_sched(); 
    12311547} 
    12321548EXPORT_SYMBOL(input_unregister_handle); 
  • src/linux/ar531x/linux-2.6.23/drivers/input/joydev.c

    r8169 r9058  
    4444        wait_queue_head_t wait; 
    4545        struct list_head client_list; 
     46        spinlock_t client_lock; /* protects client_list */ 
     47        struct mutex mutex; 
    4648        struct device dev; 
    4749 
     
    6264        int tail; 
    6365        int startup; 
     66        spinlock_t buffer_lock; /* protects access to buffer, head and tail */ 
    6467        struct fasync_struct *fasync; 
    6568        struct joydev *joydev; 
     
    6871 
    6972static struct joydev *joydev_table[JOYDEV_MINORS]; 
     73static DEFINE_MUTEX(joydev_table_mutex); 
    7074 
    7175static int joydev_correct(int value, struct js_corr *corr) 
    7276{ 
    7377        switch (corr->type) { 
    74                 case JS_CORR_NONE: 
    75                         break; 
    76                 case JS_CORR_BROKEN: 
    77                         value = value > corr->coef[0] ? (value < corr->coef[1] ? 0 : 
    78                                 ((corr->coef[3] * (value - corr->coef[1])) >> 14)) : 
    79                                 ((corr->coef[2] * (value - corr->coef[0])) >> 14); 
    80                         break; 
    81                 default: 
    82                         return 0; 
     78 
     79        case JS_CORR_NONE: 
     80                break; 
     81 
     82        case JS_CORR_BROKEN: 
     83                value = value > corr->coef[0] ? (value < corr->coef[1] ? 0 : 
     84                        ((corr->coef[3] * (value - corr->coef[1])) >> 14)) : 
     85                        ((corr->coef[2] * (value - corr->coef[0])) >> 14); 
     86                break; 
     87 
     88        default: 
     89                return 0; 
    8390        } 
    8491 
     
    8693} 
    8794 
    88 static void joydev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) 
     95static void joydev_pass_event(struct joydev_client *client, 
     96                              struct js_event *event) 
     97{ 
     98        struct joydev *joydev = client->joydev; 
     99 
     100        /* 
     101         * IRQs already disabled, just acquire the lock 
     102         */ 
     103        spin_lock(&client->buffer_lock); 
     104 
     105        client->buffer[client->head] = *event; 
     106 
     107        if (client->startup == joydev->nabs + joydev->nkey) { 
     108                client->head++; 
     109                client->head &= JOYDEV_BUFFER_SIZE - 1; 
     110                if (client->tail == client->head) 
     111                        client->startup = 0; 
     112        } 
     113 
     114        spin_unlock(&client->buffer_lock); 
     115 
     116        kill_fasync(&client->fasync, SIGIO, POLL_IN); 
     117} 
     118 
     119static void joydev_event(struct input_handle *handle, 
     120                         unsigned int type, unsigned int code, int value) 
    89121{ 
    90122        struct joydev *joydev = handle->private; 
     
    94126        switch (type) { 
    95127 
    96                 case EV_KEY: 
    97                         if (code < BTN_MISC || value == 2) 
    98                                 return; 
    99                         event.type = JS_EVENT_BUTTON; 
    100                         event.number = joydev->keymap[code - BTN_MISC]; 
    101                         event.value = value; 
    102                         break; 
    103  
    104                 case EV_ABS: 
    105                         event.type = JS_EVENT_AXIS; 
    106                         event.number = joydev->absmap[code]; 
    107                         event.value = joydev_correct(value, joydev->corr + event.number); 
    108                         if (event.value == joydev->abs[event.number]) 
    109                                 return; 
    110                         joydev->abs[event.number] = event.value; 
    111                         break; 
    112  
    113                 default: 
     128        case EV_KEY: 
     129                if (code < BTN_MISC || value == 2) 
    114130                        return; 
     131                event.type = JS_EVENT_BUTTON; 
     132                event.number = joydev->keymap[code - BTN_MISC]; 
     133                event.value = value; 
     134                break; 
     135 
     136        case EV_ABS: 
     137                event.type = JS_EVENT_AXIS; 
     138                event.number = joydev->absmap[code]; 
     139                event.value = joydev_correct(value, 
     140                                        &joydev->corr[event.number]); 
     141                if (event.value == joydev->abs[event.number]) 
     142                        return; 
     143                joydev->abs[event.number] = event.value; 
     144                break; 
     145 
     146        default: 
     147                return; 
    115148        } 
    116149 
    117150        event.time = jiffies_to_msecs(jiffies); 
    118151 
    119         list_for_each_entry(client, &joydev->client_list, node) { 
    120  
    121                 memcpy(client->buffer + client->head, &event, sizeof(struct js_event)); 
    122  
    123                 if (client->startup == joydev->nabs + joydev->nkey) 
    124                         if (client->tail == (client->head = (client->head + 1) & (JOYDEV_BUFFER_SIZE - 1))) 
    125                                 client->startup = 0; 
    126  
    127                 kill_fasync(&client->fasync, SIGIO, POLL_IN); 
    128         } 
     152        list_for_each_entry_rcu(client, &joydev->client_list, node) 
     153                joydev_pass_event(client, &event); 
    129154 
    130155        wake_up_interruptible(&joydev->wait); 
     
    145170        struct joydev *joydev = container_of(dev, struct joydev, dev); 
    146171 
    147         joydev_table[joydev->minor] = NULL; 
    148172        kfree(joydev); 
     173} 
     174 
     175static void joydev_attach_client(struct joydev *joydev, 
     176                                 struct joydev_client *client) 
     177{ 
     178        spin_lock(&joydev->client_lock); 
     179        list_add_tail_rcu(&client->node, &joydev->client_list); 
     180        spin_unlock(&joydev->client_lock); 
     181        /* 
     182         * We don't use synchronize_rcu() here because read-side 
     183         * critical section is protected by a spinlock (dev->event_lock) 
     184         * instead of rcu_read_lock(). 
     185         */ 
     186        synchronize_sched(); 
     187} 
     188 
     189static void joydev_detach_client(struct joydev *joydev, 
     190                                 struct joydev_client *client) 
     191{ 
     192        spin_lock(&joydev->client_lock); 
     193        list_del_rcu(&client->node); 
     194        spin_unlock(&joydev->client_lock); 
     195        synchronize_sched(); 
     196} 
     197 
     198static int joydev_open_device(struct joydev *joydev) 
     199{ 
     200        int retval; 
     201 
     202        retval = mutex_lock_interruptible(&joydev->mutex); 
     203        if (retval) 
     204                return retval; 
     205 
     206        if (!joydev->exist) 
     207                retval = -ENODEV; 
     208        else if (!joydev->open++) { 
     209                retval = input_open_device(&joydev->handle); 
     210                if (retval) 
     211                        joydev->open--; 
     212        } 
     213 
     214        mutex_unlock(&joydev->mutex); 
     215        return retval; 
     216} 
     217 
     218static void joydev_close_device(struct joydev *joydev) 
     219{ 
     220        mutex_lock(&joydev->mutex); 
     221 
     222        if (joydev->exist && !--joydev->open) 
     223                input_close_device(&joydev->handle); 
     224 
     225        mutex_unlock(&joydev->mutex); 
     226} 
     227 
     228/* 
     229 * Wake up users waiting for IO so they can disconnect from 
     230 * dead device. 
     231 */ 
     232static void joydev_hangup(struct joydev *joydev) 
     233{ 
     234        struct joydev_client *client; 
     235 
     236        spin_lock(&joydev->client_lock); 
     237        list_for_each_entry(client, &joydev->client_list, node) 
     238                kill_fasync(&client->fasync, SIGIO, POLL_HUP); 
     239        spin_unlock(&joydev->client_lock); 
     240 
     241        wake_up_interruptible(&joydev->wait); 
    149242} 
    150243 
     
    155248 
    156249        joydev_fasync(-1, file, 0); 
    157  
    158         list_del(&client->node); 
     250        joydev_detach_client(joydev, client); 
    159251        kfree(client); 
    160252 
    161         if (!--joydev->open && joydev->exist) 
    162                 input_close_device(&joydev->handle); 
    163  
     253        joydev_close_device(joydev); 
    164254        put_device(&joydev->dev); 
    165255 
     
    177267                return -ENODEV; 
    178268 
     269        error = mutex_lock_interruptible(&joydev_table_mutex); 
     270        if (error) 
     271                return error; 
    179272        joydev = joydev_table[i]; 
    180         if (!joydev || !joydev->exist) 
     273        if (joydev) 
     274                get_device(&joydev->dev); 
     275        mutex_unlock(&joydev_table_mutex); 
     276 
     277        if (!joydev) 
    181278                return -ENODEV; 
    182  
    183         get_device(&joydev->dev); 
    184279 
    185280        client = kzalloc(sizeof(struct joydev_client), GFP_KERNEL); 
     
    189284        } 
    190285 
     286        spin_lock_init(&client->buffer_lock); 
    191287        client->joydev = joydev; 
    192         list_add_tail(&client->node, &joydev->client_list); 
    193  
    194         if (!joydev->open++ && joydev->exist) { 
    195                 error = input_open_device(&joydev->handle); 
    196                 if (error) 
    197                         goto err_free_client; 
    198         } 
     288        joydev_attach_client(joydev, client); 
     289 
     290        error = joydev_open_device(joydev); 
     291        if (error) 
     292                goto err_free_client; 
    199293 
    200294        file->private_data = client; 
     
    202296 
    203297 err_free_client: 
    204         list_del(&client->node); 
     298        joydev_detach_client(joydev, client); 
    205299        kfree(client); 
    206300 err_put_joydev: 
     
    209303} 
    210304 
    211 static ssize_t joydev_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) 
    212 { 
    213         return -EINVAL; 
    214 } 
    215  
    216 static ssize_t joydev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 
     305static int joydev_generate_startup_event(struct joydev_client *client, 
     306                                         struct input_dev *input, 
     307                                         struct js_event *event) 
     308{ 
     309        struct joydev *joydev = client->joydev; 
     310        int have_event; 
     311 
     312        spin_lock_irq(&client->buffer_lock); 
     313 
     314        have_event = client->startup < joydev->nabs + joydev->nkey; 
     315 
     316        if (have_event) { 
     317 
     318                event->time = jiffies_to_msecs(jiffies); 
     319                if (client->startup < joydev->nkey) { 
     320                        event->type = JS_EVENT_BUTTON | JS_EVENT_INIT; 
     321                        event->number = client->startup; 
     322                        event->value = !!test_bit(joydev->keypam[event->number], 
     323                                                  input->key); 
     324                } else { 
     325                        event->type = JS_EVENT_AXIS | JS_EVENT_INIT; 
     326                        event->number = client->startup - joydev->nkey; 
     327                        event->value = joydev->abs[event->number]; 
     328                } 
     329                client->startup++; 
     330        } 
     331 
     332        spin_unlock_irq(&client->buffer_lock); 
     333 
     334        return have_event; 
     335} 
     336 
     337static int joydev_fetch_next_event(struct joydev_client *client, 
     338                                   struct js_event *event) 
     339{ 
     340        int have_event; 
     341 
     342        spin_lock_irq(&client->buffer_lock); 
     343 
     344        have_event = client->head != client->tail; 
     345        if (have_event) { 
     346                *event = client->buffer[client->tail++]; 
     347                client->tail &= JOYDEV_BUFFER_SIZE - 1; 
     348        } 
     349 
     350        spin_unlock_irq(&client->buffer_lock); 
     351 
     352        return have_event; 
     353} 
     354 
     355/* 
     356 * Old joystick interface 
     357 */ 
     358static ssize_t joydev_0x_read(struct joydev_client *client, 
     359                              struct input_dev *input, 
     360                              char __user *buf) 
     361{ 
     362        struct joydev *joydev = client->joydev; 
     363        struct JS_DATA_TYPE data; 
     364        int i; 
     365 
     366        spin_lock_irq(&input->event_lock); 
     367 
     368        /* 
     369         * Get device state 
     370         */ 
     371        for (data.buttons = i = 0; i < 32 && i < joydev->nkey; i++) 
     372                data.buttons |= 
     373                        test_bit(joydev->keypam[i], input->key) ? (1 << i) : 0; 
     374        data.x = (joydev->abs[0] / 256 + 128) >> joydev->glue.JS_CORR.x; 
     375        data.y = (joydev->abs[1] / 256 + 128) >> joydev->glue.JS_CORR.y; 
     376 
     377        /* 
     378         * Reset reader's event queue 
     379         */ 
     380        spin_lock(&client->buffer_lock); 
     381        client->startup = 0; 
     382        client->tail = client->head; 
     383        spin_unlock(&client->buffer_lock); 
     384 
     385        spin_unlock_irq(&input->event_lock); 
     386 
     387        if (copy_to_user(buf, &data, sizeof(struct JS_DATA_TYPE))) 
     388                return -EFAULT; 
     389 
     390        return sizeof(struct JS_DATA_TYPE); 
     391} 
     392 
     393static inline int joydev_data_pending(struct joydev_client *client) 
     394{ 
     395        struct joydev *joydev = client->joydev; 
     396 
     397        return client->startup < joydev->nabs + joydev->nkey || 
     398                client->head != client->tail; 
     399} 
     400 
     401static ssize_t joydev_read(struct file *file, char __user *buf, 
     402                           size_t count, loff_t *ppos) 
    217403{ 
    218404        struct joydev_client *client = file->private_data; 
    219405        struct joydev *joydev = client->joydev; 
    220406        struct input_dev *input = joydev->handle.dev; 
    221         int retval = 0; 
     407        struct js_event event; 
     408        int retval; 
    222409 
    223410        if (!joydev->exist) 
     
    227414                return -EINVAL; 
    228415 
    229         if (count == sizeof(struct JS_DATA_TYPE)) { 
    230  
    231                 struct JS_DATA_TYPE data; 
    232                 int i; 
    233  
    234                 for (data.buttons = i = 0; i < 32 && i < joydev->nkey; i++) 
    235                         data.buttons |= test_bit(joydev->keypam[i], input->key) ? (1 << i) : 0; 
    236                 data.x = (joydev->abs[0] / 256 + 128) >> joydev->glue.JS_CORR.x; 
    237                 data.y = (joydev->abs[1] / 256 + 128) >> joydev->glue.JS_CORR.y; 
    238  
    239                 if (copy_to_user(buf, &data, sizeof(struct JS_DATA_TYPE))) 
    240                         return -EFAULT; 
    241  
    242                 client->startup = 0; 
    243                 client->tail = client->head; 
    244  
    245                 return sizeof(struct JS_DATA_TYPE); 
    246         } 
    247  
    248         if (client->startup == joydev->nabs + joydev->nkey && 
    249             client->head == client->tail && (file->f_flags & O_NONBLOCK)) 
     416        if (count == sizeof(struct JS_DATA_TYPE)) 
     417                return joydev_0x_read(client, input, buf); 
     418 
     419        if (!joydev_data_pending(client) && (file->f_flags & O_NONBLOCK)) 
    250420                return -EAGAIN; 
    251421 
    252422        retval = wait_event_interruptible(joydev->wait, 
    253                                           !joydev->exist || 
    254                                           client->startup < joydev->nabs + joydev->nkey || 
    255                                           client->head != client->tail); 
     423                        !joydev->exist || joydev_data_pending(client)); 
    256424        if (retval) 
    257425                return retval; 
     
    260428                return -ENODEV; 
    261429 
    262         while (client->startup < joydev->nabs + joydev->nkey && retval + sizeof(struct js_event) <= count) { 
    263  
    264                 struct js_event event; 
    265  
    266                 event.time = jiffies_to_msecs(jiffies); 
    267  
    268                 if (client->startup < joydev->nkey) { 
    269                         event.type = JS_EVENT_BUTTON | JS_EVENT_INIT; 
    270                         event.number = client->startup; 
    271                         event.value = !!test_bit(joydev->keypam[event.number], input->key); 
    272                 } else { 
    273                         event.type = JS_EVENT_AXIS | JS_EVENT_INIT; 
    274                         event.number = client->startup - joydev->nkey; 
    275                         event.value = joydev->abs[event.number]; 
    276                 } 
     430        while (retval + sizeof(struct js_event) <= count && 
     431               joydev_generate_startup_event(client, input, &event)) { 
    277432 
    278433                if (copy_to_user(buf + retval, &event, sizeof(struct js_event))) 
    279434                        return -EFAULT; 
    280435 
    281                 client->startup++; 
    282436                retval += sizeof(struct js_event); 
    283437        } 
    284438 
    285         while (client->head != client->tail && retval + sizeof(struct js_event) <= count) { 
    286  
    287                 if (copy_to_user(buf + retval, client->buffer + client->tail, sizeof(struct js_event))) 
     439        while (retval + sizeof(struct js_event) <= count && 
     440               joydev_fetch_next_event(client, &event)) { 
     441 
     442                if (copy_to_user(buf + retval, &event, sizeof(struct js_event))) 
    288443                        return -EFAULT; 
    289444 
    290                 client->tail = (client->tail + 1) & (JOYDEV_BUFFER_SIZE - 1); 
    291445                retval += sizeof(struct js_event); 
    292446        } 
     
    302456 
    303457        poll_wait(file, &joydev->wait, wait); 
    304         return ((client->head != client->tail || client->startup < joydev->nabs + joydev->nkey) ? 
    305                 (POLLIN | POLLRDNORM) : 0) | (joydev->exist ? 0 : (POLLHUP | POLLERR)); 
    306 } 
    307  
    308 static int joydev_ioctl_common(struct joydev *joydev, unsigned int cmd, void __user *argp) 
     458        return (joydev_data_pending(client) ? (POLLIN | POLLRDNORM) : 0) | 
     459                (joydev->exist ?  0 : (POLLHUP | POLLERR)); 
     460} 
     461 
     462static int joydev_ioctl_common(struct joydev *joydev, 
     463                                unsigned int cmd, void __user *argp) 
    309464{ 
    310465        struct input_dev *dev = joydev->handle.dev; 
     
    313468        switch (cmd) { 
    314469 
    315                 case JS_SET_CAL: 
    316                         return copy_from_user(&joydev->glue.JS_CORR, argp, 
     470        case JS_SET_CAL: 
     471                return copy_from_user(&joydev->glue.JS_CORR, argp, 
    317472                                sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0; 
    318473 
    319                 case JS_GET_CAL: 
    320                         return copy_to_user(argp, &joydev->glue.JS_CORR, 
     474        case JS_GET_CAL: 
     475                return copy_to_user(argp, &joydev->glue.JS_CORR, 
    321476                                sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0; 
    322477 
    323                 case JS_SET_TIMEOUT: 
    324                         return get_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp); 
    325  
    326                 case JS_GET_TIMEOUT: 
    327                         return put_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp); 
    328  
    329                 case JSIOCGVERSION: 
    330                         return put_user(JS_VERSION, (__u32 __user *) argp); 
    331  
    332                 case JSIOCGAXES: 
    333                         return put_user(joydev->nabs, (__u8 __user *) argp); 
    334  
    335                 case JSIOCGBUTTONS: 
    336                         return put_user(joydev->nkey, (__u8 __user *) argp); 
    337  
    338                 case JSIOCSCORR: 
    339                         if (copy_from_user(joydev->corr, argp, 
    340                                       sizeof(joydev->corr[0]) * joydev->nabs)) 
    341                             return -EFAULT; 
    342                         for (i = 0; i < joydev->nabs; i++) { 
    343                                 j = joydev->abspam[i]; 
    344                                 joydev->abs[i] = joydev_correct(dev->abs[j], joydev->corr + i); 
    345                         } 
    346                         return 0; 
    347  
    348                 case JSIOCGCORR: 
    349                         return copy_to_user(argp, joydev->corr, 
    350                                                 sizeof(joydev->corr[0]) * joydev->nabs) ? -EFAULT : 0; 
    351  
    352                 case JSIOCSAXMAP: 
    353                         if (copy_from_user(joydev->abspam, argp, sizeof(__u8) * (ABS_MAX + 1))) 
     478        case JS_SET_TIMEOUT: 
     479                return get_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp); 
     480 
     481        case JS_GET_TIMEOUT: 
     482                return put_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp); 
     483 
     484        case JSIOCGVERSION: 
     485                return put_user(JS_VERSION, (__u32 __user *) argp); 
     486 
     487        case JSIOCGAXES: 
     488                return put_user(joydev->nabs, (__u8 __user *) argp); 
     489 
     490        case JSIOCGBUTTONS: 
     491                return put_user(joydev->nkey, (__u8 __user *) argp); 
     492 
     493        case JSIOCSCORR: 
     494                if (copy_from_user(joydev->corr, argp, 
     495                              sizeof(joydev->corr[0]) * joydev->nabs)) 
     496                    return -EFAULT; 
     497 
     498                for (i = 0; i < joydev->nabs; i++) { 
     499                        j = joydev->abspam[i]; 
     500                        joydev->abs[i] = joydev_correct(dev->abs[j], 
     501                                                        &joydev->corr[i]); 
     502                } 
     503                return 0; 
     504 
     505        case JSIOCGCORR: 
     506                return copy_to_user(argp, joydev->corr, 
     507                        sizeof(joydev->corr[0]) * joydev->nabs) ? -EFAULT : 0; 
     508 
     509        case JSIOCSAXMAP: 
     510                if (copy_from_user(joydev->abspam, argp, 
     511                                   sizeof(__u8) * (ABS_MAX + 1))) 
     512                        return -EFAULT; 
     513 
     514                for (i = 0; i < joydev->nabs; i++) { 
     515                        if (joydev->abspam[i] > ABS_MAX) 
     516                                return -EINVAL; 
     517                        joydev->absmap[joydev->abspam[i]] = i; 
     518                } 
     519                return 0; 
     520 
     521        case JSIOCGAXMAP: 
     522                return copy_to_user(argp, joydev->abspam, 
     523                        sizeof(__u8) * (ABS_MAX + 1)) ? -EFAULT : 0; 
     524 
     525        case JSIOCSBTNMAP: 
     526                if (copy_from_user(joydev->keypam, argp, 
     527                                   sizeof(__u16) * (KEY_MAX - BTN_MISC + 1))) 
     528                        return -EFAULT; 
     529 
     530                for (i = 0; i < joydev->nkey; i++) { 
     531                        if (joydev->keypam[i] > KEY_MAX || 
     532                            joydev->keypam[i] < BTN_MISC) 
     533                                return -EINVAL; 
     534                        joydev->keymap[joydev->keypam[i] - BTN_MISC] = i; 
     535                } 
     536 
     537                return 0; 
     538 
     539        case JSIOCGBTNMAP: 
     540                return copy_to_user(argp, joydev->keypam, 
     541                        sizeof(__u16) * (KEY_MAX - BTN_MISC + 1)) ? -EFAULT : 0; 
     542 
     543        default: 
     544                if ((cmd & ~IOCSIZE_MASK) == JSIOCGNAME(0)) { 
     545                        int len; 
     546                        if (!dev->name) 
     547                                return 0; 
     548                        len = strlen(dev->name) + 1; 
     549                        if (len > _IOC_SIZE(cmd)) 
     550                                len = _IOC_SIZE(cmd); 
     551                        if (copy_to_user(argp, dev->name, len)) 
    354552                                return -EFAULT; 
    355                         for (i = 0; i < joydev->nabs; i++) { 
    356                                 if (joydev->abspam[i] > ABS_MAX) 
    357                                         return -EINVAL; 
    358                                 joydev->absmap[joydev->abspam[i]] = i; 
    359                         } 
    360                         return 0; 
    361  
    362                 case JSIOCGAXMAP: 
    363                         return copy_to_user(argp, joydev->abspam, 
    364                                                 sizeof(__u8) * (ABS_MAX + 1)) ? -EFAULT : 0; 
    365  
    366                 case JSIOCSBTNMAP: 
    367                         if (copy_from_user(joydev->keypam, argp, sizeof(__u16) * (KEY_MAX - BTN_MISC + 1))) 
    368                                 return -EFAULT; 
    369                         for (i = 0; i < joydev->nkey; i++) { 
    370                                 if (joydev->keypam[i] > KEY_MAX || joydev->keypam[i] < BTN_MISC) 
    371                                         return -EINVAL; 
    372                                 joydev->keymap[joydev->keypam[i] - BTN_MISC] = i; 
    373                         } 
    374                         return 0; 
    375  
    376                 case JSIOCGBTNMAP: 
    377                         return copy_to_user(argp, joydev->keypam, 
    378                                                 sizeof(__u16) * (KEY_MAX - BTN_MISC + 1)) ? -EFAULT : 0; 
    379  
    380                 default: 
    381                         if ((cmd & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT)) == JSIOCGNAME(0)) { 
    382                                 int len; 
    383                                 if (!dev->name) 
    384                                         return 0; 
    385                                 len = strlen(dev->name) + 1; 
    386                                 if (len > _IOC_SIZE(cmd)) 
    387                                         len = _IOC_SIZE(cmd); 
    388                                 if (copy_to_user(argp, dev->name, len)) 
    389                                         return -EFAULT; 
    390                                 return len; 
    391                         } 
     553                        return len; 
     554                } 
    392555        } 
    393556        return -EINVAL; 
     
    395558 
    396559#ifdef CONFIG_COMPAT 
    397 static long joydev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 
     560static long joydev_compat_ioctl(struct file *file, 
     561                                unsigned int cmd, unsigned long arg) 
    398562{ 
    399563        struct joydev_client *client = file->private_data; 
     
    402566        s32 tmp32; 
    403567        struct JS_DATA_SAVE_TYPE_32 ds32; 
    404         int err; 
    405  
    406         if (!joydev->exist) 
    407                 return -ENODEV; 
    408  
    409         switch(cmd) { 
     568        int retval; 
     569 
     570        retval = mutex_lock_interruptible(&joydev->mutex); 
     571        if (retval) 
     572                return retval; 
     573 
     574        if (!joydev->exist) { 
     575                retval = -ENODEV; 
     576                goto out; 
     577        } 
     578 
     579        switch (cmd) { 
     580 
    410581        case JS_SET_TIMELIMIT: 
    411                 err = get_user(tmp32, (s32 __user *) arg); 
    412                 if (err == 0) 
     582                retval = get_user(tmp32, (s32 __user *) arg); 
     583                if (retval == 0) 
    413584                        joydev->glue.JS_TIMELIMIT = tmp32; 
    414585                break; 
     586 
    415587        case JS_GET_TIMELIMIT: 
    416588                tmp32 = joydev->glue.JS_TIMELIMIT; 
    417                 err = put_user(tmp32, (s32 __user *) arg); 
     589                retval = put_user(tmp32, (s32 __user *) arg); 
    418590                break; 
    419591 
    420592        case JS_SET_ALL: 
    421                 err = copy_from_user(&ds32, argp, 
    422                                      sizeof(ds32)) ? -EFAULT : 0; 
    423                 if (err == 0) { 
     593                retval = copy_from_user(&ds32, argp, 
     594                                        sizeof(ds32)) ? -EFAULT : 0; 
     595                if (retval == 0) { 
    424596                        joydev->glue.JS_TIMEOUT    = ds32.JS_TIMEOUT; 
    425597                        joydev->glue.BUSY          = ds32.BUSY; 
     
    439611                ds32.JS_CORR       = joydev->glue.JS_CORR; 
    440612 
    441                 err = copy_to_user(argp, &ds32, sizeof(ds32)) ? -EFAULT : 0; 
     613                retval = copy_to_user(argp, &ds32, sizeof(ds32)) ? -EFAULT : 0; 
    442614                break; 
    443615 
    444616        default: 
    445                 err = joydev_ioctl_common(joydev, cmd, argp); 
    446         } 
    447         return err; 
     617                retval = joydev_ioctl_common(joydev, cmd, argp); 
     618                break; 
     619        } 
     620 
     621 out: 
     622        mutex_unlock(&joydev->mutex); 
     623        return retval; 
    448624} 
    449625#endif /* CONFIG_COMPAT */ 
    450626 
    451 static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 
     627static long joydev_ioctl(struct file *file, 
     628                         unsigned int cmd, unsigned long arg) 
    452629{ 
    453630        struct joydev_client *client = file->private_data; 
    454631        struct joydev *joydev = client->joydev; 
    455632        void __user *argp = (void __user *)arg; 
    456  
    457         if (!joydev->exist) 
    458                 return -ENODEV; 
    459  
    460         switch(cmd) { 
    461                 case JS_SET_TIMELIMIT: 
    462                         return get_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg); 
    463                 case JS_GET_TIMELIMIT: 
    464                         return put_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg); 
    465                 case JS_SET_ALL: 
    466                         return copy_from_user(&joydev->glue, argp, 
    467                                                 sizeof(joydev->glue)) ? -EFAULT : 0; 
    468                 case JS_GET_ALL: 
    469                         return copy_to_user(argp, &joydev->glue, 
    470                                                 sizeof(joydev->glue)) ? -EFAULT : 0; 
    471                 default: 
    472                         return joydev_ioctl_common(joydev, cmd, argp); 
    473         } 
     633        int retval; 
     634 
     635        retval = mutex_lock_interruptible(&joydev->mutex); 
     636        if (retval) 
     637                return retval; 
     638 
     639        if (!joydev->exist) { 
     640                retval = -ENODEV; 
     641                goto out; 
     642        } 
     643 
     644        switch (cmd) { 
     645 
     646        case JS_SET_TIMELIMIT: 
     647                retval = get_user(joydev->glue.JS_TIMELIMIT, 
     648                                  (long __user *) arg); 
     649                break; 
     650 
     651        case JS_GET_TIMELIMIT: 
     652                retval = put_user(joydev->glue.JS_TIMELIMIT, 
     653                                  (long __user *) arg); 
     654                break; 
     655 
     656        case JS_SET_ALL: 
     657                retval = copy_from_user(&joydev->glue, argp, 
     658                                        sizeof(joydev->glue)) ? -EFAULT: 0; 
     659                break; 
     660 
     661        case JS_GET_ALL: 
     662                retval = copy_to_user(argp, &joydev->glue, 
     663                                      sizeof(joydev->glue)) ? -EFAULT : 0; 
     664                break; 
     665 
     666        default: 
     667                retval = joydev_ioctl_common(joydev, cmd, argp); 
     668                break; 
     669        } 
     670 out: 
     671        mutex_unlock(&joydev->mutex); 
     672        return retval; 
    474673} 
    475674 
    476675static const struct file_operations joydev_fops = { 
    477         .owner =        THIS_MODULE, 
    478         .read =         joydev_read, 
    479         .write =        joydev_write, 
    480         .poll =         joydev_poll, 
    481         .open =         joydev_open, 
    482         .release =      joydev_release, 
    483         .ioctl =        joydev_ioctl, 
     676        .owner          = THIS_MODULE, 
     677        .read           = joydev_read, 
     678        .poll           = joydev_poll, 
     679        .open           = joydev_open, 
     680        .release        = joydev_release, 
     681        .unlocked_ioctl = joydev_ioctl, 
    484682#ifdef CONFIG_COMPAT 
    485         .compat_ioctl = joydev_compat_ioctl, 
     683        .compat_ioctl   = joydev_compat_ioctl, 
    486684#endif 
    487         .fasync =       joydev_fasync, 
     685        .fasync         = joydev_fasync, 
    488686}; 
     687 
     688static int joydev_install_chrdev(struct joydev *joydev) 
     689{ 
     690        joydev_table[joydev->minor] = joydev; 
     691        return 0; 
     692} 
     693 
     694static void joydev_remove_chrdev(struct joydev *joydev) 
     695{ 
     696        mutex_lock(&joydev_table_mutex); 
     697        joydev_table[joydev->minor] = NULL; 
     698        mutex_unlock(&joydev_table_mutex); 
     699} 
     700 
     701/* 
     702 * Mark device non-existant. This disables writes, ioctls and 
     703 * prevents new users from opening the device. Already posted 
     704 * blocking reads will stay, however new ones will fail. 
     705 */ 
     706static void joydev_mark_dead(struct joydev *joydev) 
     707{ 
     708        mutex_lock(&joydev->mutex); 
     709        joydev->exist = 0; 
     710        mutex_unlock(&joydev->mutex); 
     711} 
     712 
     713static void joydev_cleanup(struct joydev *joydev) 
     714{ 
     715        struct input_handle *handle = &joydev->handle; 
     716 
     717        joydev_mark_dead(joydev); 
     718        joydev_hangup(joydev); 
     719        joydev_remove_chrdev(joydev); 
     720 
     721        /* joydev is marked dead so noone else accesses joydev->open */ 
     722        if (joydev->open) 
     723                input_close_device(handle); 
     724} 
    489725 
    490726static int joydev_connect(struct input_handler *handler, struct input_dev *dev, 
     
    495731        int error; 
    496732 
    497         for (minor = 0; minor < JOYDEV_MINORS && joydev_table[minor]; minor++); 
     733        for (minor = 0; minor < JOYDEV_MINORS; minor++) 
     734                if (!joydev_table[minor]) 
     735                        break; 
     736 
    498737        if (minor == JOYDEV_MINORS) { 
    499738                printk(KERN_ERR "joydev: no more free joydev devices\n"); 
     
    506745 
    507746        INIT_LIST_HEAD(&joydev->client_list); 
     747        spin_lock_init(&joydev->client_lock); 
     748        mutex_init(&joydev->mutex); 
    508749        init_waitqueue_head(&joydev->wait); 
    509750 
     751        snprintf(joydev->name, sizeof(joydev->name), "js%d", minor); 
     752        joydev->exist = 1; 
    510753        joydev->minor = minor; 
     754 
    511755        joydev->exist = 1; 
    512756        joydev->handle.dev = dev; 
     
    514758        joydev->handle.handler = handler; 
    515759        joydev->handle.private = joydev; 
    516         snprintf(joydev->name, sizeof(joydev->name), "js%d", minor); 
    517760 
    518761        for (i = 0; i < ABS_MAX + 1; i++) 
     
    546789                joydev->corr[i].type = JS_CORR_BROKEN; 
    547790                joydev->corr[i].prec = dev->absfuzz[j]; 
    548                 joydev->corr[i].coef[0] = (dev->absmax[j] + dev->absmin[j]) / 2 - dev->absflat[j]; 
    549                 joydev->corr[i].coef[1] = (dev->absmax[j] + dev->absmin[j]) / 2 + dev->absflat[j]; 
    550                 if (!(t = ((dev->absmax[j] - dev->absmin[j]) / 2 - 2 * dev->absflat[j]))) 
    551                         continue; 
    552                 joydev->corr[i].coef[2] = (1 << 29) / t; 
    553                 joydev->corr[i].coef[3] = (1 << 29) / t; 
    554  
    555                 joydev->abs[i] = joydev_correct(dev->abs[j], joydev->corr + i); 
    556         } 
    557  
    558         snprintf(joydev->dev.bus_id, sizeof(joydev->dev.bus_id), 
    559                  "js%d", minor); 
     791                joydev->corr[i].coef[0] = 
     792                        (dev->absmax[j] + dev->absmin[j]) / 2 - dev->absflat[j]; 
     793                joydev->corr[i].coef[1] = 
     794                        (dev->absmax[j] + dev->absmin[j]) / 2 + dev->absflat[j]; 
     795 
     796                t = (dev->absmax[j] - dev->absmin[j]) / 2 - 2 * dev->absflat[j]; 
     797                if (t) { 
     798                        joydev->corr[i].coef[2] = (1 << 29) / t; 
     799                        joydev->corr[i].coef[3] = (1 << 29) / t; 
     800 
     801                        joydev->abs[i] = joydev_correct(dev->abs[j], 
     802                                                        joydev->corr + i); 
     803                } 
     804        } 
     805 
     806        strlcpy(joydev->dev.bus_id, joydev->name, sizeof(joydev->dev.bus_id)); 
     807        joydev->dev.devt = MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor); 
    560808        joydev->dev.class = &input_class; 
    561809        joydev->dev.parent = &dev->dev; 
    562         joydev->dev.devt = MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor); 
    563810        joydev->dev.release = joydev_free; 
    564811        device_initialize(&joydev->dev); 
    565812 
    566         joydev_table[minor] = joydev; 
     813        error = input_register_handle(&joydev->handle); 
     814        if (error) 
     815                goto err_free_joydev; 
     816 
     817        error = joydev_install_chrdev(joydev); 
     818        if (error) 
     819                goto err_unregister_handle; 
    567820 
    568821        error = device_add(&joydev->dev); 
    569822        if (error) 
    570                 goto err_free_joydev; 
    571  
    572         error = input_register_handle(&joydev->handle); 
    573         if (error) 
    574                 goto err_delete_joydev; 
     823                goto err_cleanup_joydev; 
    575824 
    576825        return 0; 
    577826 
    578  err_delete_joydev: 
    579         device_del(&joydev->dev); 
     827 err_cleanup_joydev: 
     828        joydev_cleanup(joydev); 
     829 err_unregister_handle: 
     830        input_unregister_handle(&joydev->handle); 
    580831 err_free_joydev: 
    581832        put_device(&joydev->dev); 
     
    583834} 
    584835 
    585  
    586836static void joydev_disconnect(struct input_handle *handle) 
    587837{ 
    588838        struct joydev *joydev = handle->private; 
    589         struct joydev_client *client; 
    590  
     839 
     840        device_del(&joydev->dev); 
     841        joydev_cleanup(joydev); 
    591842        input_unregister_handle(handle); 
    592         device_del(&joydev->dev); 
    593  
    594         joydev->exist = 0; 
    595  
    596         if (joydev->open) { 
    597                 input_close_device(handle); 
    598                 list_for_each_entry(client, &joydev->client_list, node) 
    599                         kill_fasync(&client->fasync, SIGIO, POLL_HUP); 
    600                 wake_up_interruptible(&joydev->wait); 
    601         } 
    602  
    603843        put_device(&joydev->dev); 
    604844} 
     
    606846static const struct input_device_id joydev_blacklist[] = { 
    607847        { 
    608                 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 
     848                .flags = INPUT_DEVICE_ID_MATCH_EVBIT | 
     849                                INPUT_DEVICE_ID_MATCH_KEYBIT, 
    609850                .evbit = { BIT(EV_KEY) }, 
    610851                .keybit = { [LONG(BTN_TOUCH)] = BIT(BTN_TOUCH) }, 
     
    615856static const struct input_device_id joydev_ids[] = { 
    616857        { 
    617                 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT, 
     858                .flags = INPUT_DEVICE_ID_MATCH_EVBIT | 
     859                                INPUT_DEVICE_ID_MATCH_ABSBIT, 
    618860                .evbit = { BIT(EV_ABS) }, 
    619861                .absbit = { BIT(ABS_X) }, 
    620862        }, 
    621863        { 
    622                 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT, 
     864                .flags = INPUT_DEVICE_ID_MATCH_EVBIT | 
     865                                INPUT_DEVICE_ID_MATCH_ABSBIT, 
    623866                .evbit = { BIT(EV_ABS) }, 
    624867                .absbit = { BIT(ABS_WHEEL) }, 
    625868        }, 
    626869        { 
    627                 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT, 
     870                .flags = INPUT_DEVICE_ID_MATCH_EVBIT | 
     871                                INPUT_DEVICE_ID_MATCH_ABSBIT, 
    628872                .evbit = { BIT(EV_ABS) }, 
    629873                .absbit = { BIT(ABS_THROTTLE) }, 
     
    635879 
    636880static struct input_handler joydev_handler = { 
    637         .event =        joydev_event, 
    638         .connect =      joydev_connect, 
    639         .disconnect =   joydev_disconnect, 
    640         .fops =         &joydev_fops, 
    641         .minor =        JOYDEV_MINOR_BASE, 
    642         .name =         "joydev", 
    643         .id_table =     joydev_ids, 
    644         .blacklist =    joydev_blacklist, 
     881        .event          = joydev_event, 
     882        .connect        = joydev_connect, 
     883        .disconnect     = joydev_disconnect, 
     884        .fops           = &joydev_fops, 
     885        .minor          = JOYDEV_MINOR_BASE, 
     886        .name           = "joydev", 
     887        .id_table       = joydev_ids, 
     888        .blacklist      = joydev_blacklist, 
    645889}; 
    646890 
  • src/linux/ar531x/linux-2.6.23/drivers/input/mousedev.c

    r8169 r9058  
    6262        int minor; 
    6363        char name[16]; 
     64        struct input_handle handle; 
    6465        wait_queue_head_t wait; 
    6566        struct list_head client_list; 
    66         struct input_handle handle; 
     67        spinlock_t client_lock; /* protects client_list */ 
     68        struct mutex mutex; 
    6769        struct device dev; 
    6870 
     
    114116 
    115117static struct mousedev *mousedev_table[MOUSEDEV_MINORS]; 
     118static DEFINE_MUTEX(mousedev_table_mutex); 
    116119static struct mousedev *mousedev_mix; 
    117120static LIST_HEAD(mousedev_mix_list); 
    118121 
     122static void mixdev_open_devices(void); 
     123static void mixdev_close_devices(void); 
     124 
    119125#define fx(i)  (mousedev->old_x[(mousedev->pkt_count - (i)) & 03]) 
    120126#define fy(i)  (mousedev->old_y[(mousedev->pkt_count - (i)) & 03]) 
    121127 
    122 static void mousedev_touchpad_event(struct input_dev *dev, struct mousedev *mousedev, unsigned int code, int value) 
     128static void mousedev_touchpad_event(struct input_dev *dev, 
     129                                    struct mousedev *mousedev, 
     130                                    unsigned int code, int value) 
    123131{ 
    124132        int size, tmp; 
     
    126134 
    127135        switch (code) { 
    128                 case ABS_X: 
    129                         fx(0) = value; 
    130                         if (mousedev->touch && mousedev->pkt_count >= 2) { 
    131                                 size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 
    132                                 if (size == 0) 
    133                                         size = 256 * 2; 
    134                                 tmp = ((value - fx(2)) * (256 * FRACTION_DENOM)) / size; 
    135                                 tmp += mousedev->frac_dx; 
    136                                 mousedev->packet.dx = tmp / FRACTION_DENOM; 
    137                                 mousedev->frac_dx = tmp - mousedev->packet.dx * FRACTION_DENOM; 
    138                         } 
    139                         break; 
    140  
    141                 case ABS_Y: 
    142                         fy(0) = value; 
    143                         if (mousedev->touch && mousedev->pkt_count >= 2) { 
    144                                 /* use X size to keep the same scale */ 
    145                                 size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 
    146                                 if (size == 0) 
    147                                         size = 256 * 2; 
    148                                 tmp = -((value - fy(2)) * (256 * FRACTION_DENOM)) / size; 
    149                                 tmp += mousedev->frac_dy; 
    150                                 mousedev->packet.dy = tmp / FRACTION_DENOM; 
    151                                 mousedev->frac_dy = tmp - mousedev->packet.dy * FRACTION_DENOM; 
    152                         } 
    153                         break; 
    154         } 
    155 } 
    156  
    157 static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev, unsigned int code, int value) 
    158 { 
    159         int size; 
    160  
    161         switch (code) { 
    162                 case ABS_X: 
     136 
     137        case ABS_X: 
     138                fx(0) = value; 
     139                if (mousedev->touch && mousedev->pkt_count >= 2) { 
    163140                        size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 
    164141                        if (size == 0) 
    165                                 size = xres ? : 1; 
    166                         if (value > dev->absmax[ABS_X]) 
    167                                 value = dev->absmax[ABS_X]; 
    168                         if (value < dev->absmin[ABS_X]) 
    169                                 value = dev->absmin[ABS_X]; 
    170                         mousedev->packet.x = ((value - dev->absmin[ABS_X]) * xres) / size; 
    171                         mousedev->packet.abs_event = 1; 
    172                         break; 
    173  
    174                 case ABS_Y: 
    175                         size = dev->absmax[ABS_Y] - dev->absmin[ABS_Y]; 
     142                                size = 256 * 2; 
     143                        tmp = ((value - fx(2)) * 256 * FRACTION_DENOM) / size; 
     144                        tmp += mousedev->frac_dx; 
     145                        mousedev->packet.dx = tmp / FRACTION_DENOM; 
     146                        mousedev->frac_dx = 
     147                                tmp - mousedev->packet.dx * FRACTION_DENOM; 
     148                } 
     149                break; 
     150 
     151        case ABS_Y: 
     152                fy(0) = value; 
     153                if (mousedev->touch && mousedev->pkt_count >= 2) { 
     154                        /* use X size to keep the same scale */ 
     155                        size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 
    176156                        if (size == 0) 
    177                                 size = yres ? : 1; 
    178                         if (value > dev->absmax[ABS_Y]) 
    179                                 value = dev->absmax[ABS_Y]; 
    180                         if (value < dev->absmin[ABS_Y]) 
    181                                 value = dev->absmin[ABS_Y]; 
    182                         mousedev->packet.y = yres - ((value - dev->absmin[ABS_Y]) * yres) / size; 
    183                         mousedev->packet.abs_event = 1; 
    184                         break; 
    185         } 
    186 } 
    187  
    188 static void mousedev_rel_event(struct mousedev *mousedev, unsigned int code, int value) 
    189 { 
     157                                size = 256 * 2; 
     158                        tmp = -((value - fy(2)) * 256 * FRACTION_DENOM) / size; 
     159                        tmp += mousedev->frac_dy; 
     160                        mousedev->packet.dy = tmp / FRACTION_DENOM; 
     161                        mousedev->frac_dy = tmp - 
     162                                mousedev->packet.dy * FRACTION_DENOM; 
     163                } 
     164                break; 
     165        } 
     166} 
     167 
     168static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev, 
     169                                unsigned int code, int value) 
     170{ 
     171        int size; 
     172 
    190173        switch (code) { 
    191                 case REL_X:     mousedev->packet.dx += value; break; 
    192                 case REL_Y:     mousedev->packet.dy -= value; break; 
    193                 case REL_WHEEL: mousedev->packet.dz -= value; break; 
    194         } 
    195 } 
    196  
    197 static void mousedev_key_event(struct mousedev *mousedev, unsigned int code, int value) 
     174 
     175        case ABS_X: 
     176                size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 
     177                if (size == 0) 
     178                        size = xres ? : 1; 
     179                if (value > dev->absmax[ABS_X]) 
     180                        value = dev->absmax[ABS_X]; 
     181                if (value < dev->absmin[ABS_X]) 
     182                        value = dev->absmin[ABS_X]; 
     183                mousedev->packet.x = 
     184                        ((value - dev->absmin[ABS_X]) * xres) / size; 
     185                mousedev->packet.abs_event = 1; 
     186                break; 
     187 
     188        case ABS_Y: 
     189                size = dev->absmax[ABS_Y] - dev->absmin[ABS_Y]; 
     190                if (size == 0) 
     191                        size = yres ? : 1; 
     192                if (value > dev->absmax[ABS_Y]) 
     193                        value = dev->absmax[ABS_Y]; 
     194                if (value < dev->absmin[ABS_Y]) 
     195                        value = dev->absmin[ABS_Y]; 
     196                mousedev->packet.y = yres - 
     197                        ((value - dev->absmin[ABS_Y]) * yres) / size; 
     198                mousedev->packet.abs_event = 1; 
     199                break; 
     200        } 
     201} 
     202 
     203static void mousedev_rel_event(struct mousedev *mousedev, 
     204                                unsigned int code, int value) 
     205{ 
     206        switch (code) { 
     207        case REL_X: 
     208                mousedev->packet.dx += value; 
     209                break; 
     210 
     211        case REL_Y: 
     212                mousedev->packet.dy -= value; 
     213                break; 
     214 
     215        case REL_WHEEL: 
     216                mousedev->packet.dz -= value; 
     217                break; 
     218        } 
     219} 
     220 
     221static void mousedev_key_event(struct mousedev *mousedev, 
     222                                unsigned int code, int value) 
    198223{ 
    199224        int index; 
    200225 
    201226        switch (code) { 
    202                 case BTN_TOUCH: 
    203                 case BTN_0: 
    204                 case BTN_LEFT:          index = 0; break; 
    205                 case BTN_STYLUS: 
    206                 case BTN_1: 
    207                 case BTN_RIGHT:         index = 1; break; 
    208                 case BTN_2: 
    209                 case BTN_FORWARD: 
    210                 case BTN_STYLUS2: 
    211                 case BTN_MIDDLE:        index = 2; break; 
    212                 case BTN_3: 
    213                 case BTN_BACK: 
    214                 case BTN_SIDE:          index = 3; break; 
    215                 case BTN_4: 
    216                 case BTN_EXTRA:         index = 4; break; 
    217                 default:                return; 
     227 
     228        case BTN_TOUCH: 
     229        case BTN_0: 
     230        case BTN_LEFT:          index = 0; break; 
     231 
     232        case BTN_STYLUS: 
     233        case BTN_1: 
     234        case BTN_RIGHT:         index = 1; break; 
     235 
     236        case BTN_2: 
     237        case BTN_FORWARD: 
     238        case BTN_STYLUS2: 
     239        case BTN_MIDDLE:        index = 2; break; 
     240 
     241        case BTN_3: 
     242        case BTN_BACK: 
     243        case BTN_SIDE:          index = 3; break; 
     244 
     245        case BTN_4: 
     246        case BTN_EXTRA:         index = 4; break; 
     247 
     248        default:                return; 
    218249        } 
    219250 
     
    227258} 
    228259 
    229 static void mousedev_notify_readers(struct mousedev *mousedev, struct mousedev_hw_data *packet) 
     260static void mousedev_notify_readers(struct mousedev *mousedev, 
     261                                    struct mousedev_hw_data *packet) 
    230262{ 
    231263        struct mousedev_client *client; 
    232264        struct mousedev_motion *p; 
    233         unsigned long flags; 
     265        unsigned int new_head; 
    234266        int wake_readers = 0; 
    235267 
    236         list_for_each_entry(client, &mousedev->client_list, node) { 
    237                 spin_lock_irqsave(&client->packet_lock, flags); 
     268        list_for_each_entry_rcu(client, &mousedev->client_list, node) { 
     269 
     270                /* Just acquire the lock, interrupts already disabled */ 
     271                spin_lock(&client->packet_lock); 
    238272 
    239273                p = &client->packets[client->head]; 
    240274                if (client->ready && p->buttons != mousedev->packet.buttons) { 
    241                         unsigned int new_head = (client->head + 1) % PACKET_QUEUE_LEN; 
     275                        new_head = (client->head + 1) % PACKET_QUEUE_LEN; 
    242276                        if (new_head != client->tail) { 
    243277                                p = &client->packets[client->head = new_head]; 
     
    254288 
    255289                client->pos_x += packet->dx; 
    256                 client->pos_x = client->pos_x < 0 ? 0 : (client->pos_x >= xres ? xres : client->pos_x); 
     290                client->pos_x = client->pos_x < 0 ? 
     291                        0 : (client->pos_x >= xres ? xres : client->pos_x); 
    257292                client->pos_y += packet->dy; 
    258                 client->pos_y = client->pos_y < 0 ? 0 : (client->pos_y >= yres ? yres : client->pos_y); 
     293                client->pos_y = client->pos_y < 0 ? 
     294                        0 : (client->pos_y >= yres ? yres : client->pos_y); 
    259295 
    260296                p->dx += packet->dx; 
     
    263299                p->buttons = mousedev->packet.buttons; 
    264300 
    265                 if (p->dx || p->dy || p->dz || p->buttons != client->last_buttons) 
     301                if (p->dx || p->dy || p->dz || 
     302                    p->buttons != client->last_buttons) 
    266303                        client->ready = 1; 
    267304 
    268                 spin_unlock_irqrestore(&client->packet_lock, flags); 
     305                spin_unlock(&client->packet_lock); 
    269306 
    270307                if (client->ready) { 
     
    282319        if (!value) { 
    283320                if (mousedev->touch && 
    284                     time_before(jiffies, mousedev->touch + msecs_to_jiffies(tap_time))) { 
     321                    time_before(jiffies, 
     322                                mousedev->touch + msecs_to_jiffies(tap_time))) { 
    285323                        /* 
    286324                         * Toggle left button to emulate tap. 
     
    291329                        set_bit(0, &mousedev_mix->packet.buttons); 
    292330                        mousedev_notify_readers(mousedev, &mousedev_mix->packet); 
    293                         mousedev_notify_readers(mousedev_mix, &mousedev_mix->packet); 
     331                        mousedev_notify_readers(mousedev_mix, 
     332                                                &mousedev_mix->packet); 
    294333                        clear_bit(0, &mousedev->packet.buttons); 
    295334                        clear_bit(0, &mousedev_mix->packet.buttons); 
     
    303342} 
    304343 
    305 static void mousedev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) 
     344static void mousedev_event(struct input_handle *handle, 
     345                           unsigned int type, unsigned int code, int value) 
    306346{ 
    307347        struct mousedev *mousedev = handle->private; 
    308348 
    309349        switch (type) { 
    310                 case EV_ABS: 
    311                         /* Ignore joysticks */ 
    312                         if (test_bit(BTN_TRIGGER, handle->dev->keybit)) 
    313                                 return; 
    314  
    315                         if (test_bit(BTN_TOOL_FINGER, handle->dev->keybit)) 
    316                                 mousedev_touchpad_event(handle->dev, mousedev, code, value); 
     350 
     351        case EV_ABS: 
     352                /* Ignore joysticks */ 
     353                if (test_bit(BTN_TRIGGER, handle->dev->keybit)) 
     354                        return; 
     355 
     356                if (test_bit(BTN_TOOL_FINGER, handle->dev->keybit)) 
     357                        mousedev_touchpad_event(handle->dev, 
     358                                                mousedev, code, value); 
     359                else 
     360                        mousedev_abs_event(handle->dev, mousedev, code, value); 
     361 
     362                break; 
     363 
     364        case EV_REL: 
     365                mousedev_rel_event(mousedev, code, value); 
     366                break; 
     367 
     368        case EV_KEY: 
     369                if (value != 2) { 
     370                        if (code == BTN_TOUCH && 
     371                            test_bit(BTN_TOOL_FINGER, handle->dev->keybit)) 
     372                                mousedev_touchpad_touch(mousedev, value); 
    317373                        else 
    318                                 mousedev_abs_event(handle->dev, mousedev, code, value); 
    319  
    320                         break; 
    321  
    322                 case EV_REL: 
    323                         mousedev_rel_event(mousedev, code, value); 
    324                         break; 
    325  
    326                 case EV_KEY: 
    327                         if (value != 2) { 
    328                                 if (code == BTN_TOUCH && test_bit(BTN_TOOL_FINGER, handle->dev->keybit)) 
    329                                         mousedev_touchpad_touch(mousedev, value); 
    330                                 else 
    331                                         mousedev_key_event(mousedev, code, value); 
     374                                mousedev_key_event(mousedev, code, value); 
     375                } 
     376                break; 
     377 
     378        case EV_SYN: 
     379                if (code == SYN_REPORT) { 
     380                        if (mousedev->touch) { 
     381                                mousedev->pkt_count++; 
     382                                /* 
     383                                 * Input system eats duplicate events, 
     384                                 * but we need all of them to do correct 
     385                                 * averaging so apply present one forward 
     386                                 */ 
     387                                fx(0) = fx(1); 
     388                                fy(0) = fy(1); 
    332389                        } 
    333                         break; 
    334  
    335                 case EV_SYN: 
    336                         if (code == SYN_REPORT) { 
    337                                 if (mousedev->touch) { 
    338                                         mousedev->pkt_count++; 
    339                                         /* Input system eats duplicate events, but we need all of them 
    340                                          * to do correct averaging so apply present one forward 
    341                                          */ 
    342                                         fx(0) = fx(1); 
    343                                         fy(0) = fy(1); 
    344                                 } 
    345  
    346                                 mousedev_notify_readers(mousedev, &mousedev->packet); 
    347                                 mousedev_notify_readers(mousedev_mix, &mousedev->packet); 
    348  
    349                                 mousedev->packet.dx = mousedev->packet.dy = mousedev->packet.dz = 0; 
    350                                 mousedev->packet.abs_event = 0; 
    351                         } 
    352                         break; 
     390 
     391                        mousedev_notify_readers(mousedev, &mousedev->packet); 
     392                        mousedev_notify_readers(mousedev_mix, &mousedev->packet); 
     393 
     394                        mousedev->packet.dx = mousedev->packet.dy = 
     395                                mousedev->packet.dz = 0; 
     396                        mousedev->packet.abs_event = 0; 
     397                } 
     398                break; 
    353399        } 
    354400} 
     
    368414        struct mousedev *mousedev = container_of(dev, struct mousedev, dev); 
    369415 
    370         mousedev_table[mousedev->minor] = NULL; 
    371416        kfree(mousedev); 
    372417} 
    373418 
    374 static int mixdev_add_device(struct mousedev *mousedev) 
    375 { 
    376         int error; 
    377  
    378         if (mousedev_mix->open) { 
    379                 error = input_open_device(&mousedev->handle); 
    380                 if (error) 
    381                         return error; 
    382  
    383                 mousedev->open++; 
    384                 mousedev->mixdev_open = 1; 
    385         } 
    386  
    387         get_device(&mousedev->dev); 
    388         list_add_tail(&mousedev->mixdev_node, &mousedev_mix_list); 
    389  
    390         return 0; 
    391 } 
    392  
    393 static void mixdev_remove_device(struct mousedev *mousedev) 
    394 { 
    395         if (mousedev->mixdev_open) { 
    396                 mousedev->mixdev_open = 0; 
    397                 if (!--mousedev->open && mousedev->exist) 
    398                         input_close_device(&mousedev->handle); 
    399         } 
    400  
    401         list_del_init(&mousedev->mixdev_node); 
    402         put_device(&mousedev->dev); 
    403 } 
    404  
     419static int mousedev_open_device(struct mousedev *mousedev) 
     420{ 
     421        int retval; 
     422 
     423        retval = mutex_lock_interruptible(&mousedev->mutex); 
     424        if (retval) 
     425                return retval; 
     426 
     427        if (mousedev->minor == MOUSEDEV_MIX) 
     428                mixdev_open_devices(); 
     429        else if (!mousedev->exist) 
     430                retval = -ENODEV; 
     431        else if (!mousedev->open++) { 
     432                retval = input_open_device(&mousedev->handle); 
     433                if (retval) 
     434                        mousedev->open--; 
     435        } 
     436 
     437        mutex_unlock(&mousedev->mutex); 
     438        return retval; 
     439} 
     440 
     441static void mousedev_close_device(struct mousedev *mousedev) 
     442{ 
     443        mutex_lock(&mousedev->mutex); 
     444 
     445        if (mousedev->minor == MOUSEDEV_MIX) 
     446                mixdev_close_devices(); 
     447        else if (mousedev->exist && !--mousedev->open) 
     448                input_close_device(&mousedev->handle); 
     449 
     450        mutex_unlock(&mousedev->mutex); 
     451} 
     452 
     453/* 
     454 * Open all available devices so they can all be multiplexed in one. 
     455 * stream. Note that this function is called with mousedev_mix->mutex 
     456 * held. 
     457 */ 
    405458static void mixdev_open_devices(void) 
    406459{ 
     
    412465        list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) { 
    413466                if (!mousedev->mixdev_open) { 
    414                         if (!mousedev->open && mousedev->exist) 
    415                                 if (input_open_device(&mousedev->handle)) 
    416                                         continue; 
    417  
    418                         mousedev->open++; 
     467                        if (mousedev_open_device(mousedev)) 
     468                                continue; 
     469 
    419470                        mousedev->mixdev_open = 1; 
    420471                } 
     
    422473} 
    423474 
     475/* 
     476 * Close all devices that were opened as part of multiplexed 
     477 * device. Note that this function is called with mousedev_mix->mutex 
     478 * held. 
     479 */ 
    424480static void mixdev_close_devices(void) 
    425481{ 
     
    432488                if (mousedev->mixdev_open) { 
    433489                        mousedev->mixdev_open = 0; 
    434                         if (!--mousedev->open && mousedev->exist) 
    435                                 input_close_device(&mousedev->handle); 
     490                        mousedev_close_device(mousedev); 
    436491                } 
    437492        } 
     493} 
     494 
     495 
     496static void mousedev_attach_client(struct mousedev *mousedev, 
     497                                   struct mousedev_client *client) 
     498{ 
     499        spin_lock(&mousedev->client_lock); 
     500        list_add_tail_rcu(&client->node, &mousedev->client_list); 
     501        spin_unlock(&mousedev->client_lock); 
     502        /* 
     503         * We don't use synchronize_rcu() here because read-side 
     504         * critical section is protected by a spinlock (dev->event_lock) 
     505         * instead of rcu_read_lock(). 
     506         */ 
     507        synchronize_sched(); 
     508} 
     509 
     510static void mousedev_detach_client(struct mousedev *mousedev, 
     511                                   struct mousedev_client *client) 
     512{ 
     513        spin_lock(&mousedev->client_lock); 
     514        list_del_rcu(&client->node); 
     515        spin_unlock(&mousedev->client_lock); 
     516        synchronize_sched(); 
    438517} 
    439518 
     
    444523 
    445524        mousedev_fasync(-1, file, 0); 
    446  
    447         list_del(&client->node); 
     525        mousedev_detach_client(mousedev, client); 
    448526        kfree(client); 
    449527 
    450         if (mousedev->minor == MOUSEDEV_MIX) 
    451                 mixdev_close_devices(); 
    452         else if (!--mousedev->open && mousedev->exist) 
    453                 input_close_device(&mousedev->handle); 
    454  
     528        mousedev_close_device(mousedev); 
    455529        put_device(&mousedev->dev); 
    456530 
    457531        return 0; 
    458532} 
    459  
    460533 
    461534static int mousedev_open(struct inode *inode, struct file *file) 
     
    476549                return -ENODEV; 
    477550 
     551        error = mutex_lock_interruptible(&mousedev_table_mutex); 
     552        if (error) 
     553                return error; 
    478554        mousedev = mousedev_table[i]; 
     555        if (mousedev) 
     556                get_device(&mousedev->dev); 
     557        mutex_unlock(&mousedev_table_mutex); 
     558 
    479559        if (!mousedev) <