From owner-svn-src-user@FreeBSD.ORG Wed Oct 8 05:23:54 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 062D1106569E; Wed, 8 Oct 2008 05:23:54 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9B6238FC14; Wed, 8 Oct 2008 05:23:50 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m985NoOR022535; Wed, 8 Oct 2008 05:23:50 GMT (envelope-from peter@svn.freebsd.org) Received: (from peter@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m985NoFC022534; Wed, 8 Oct 2008 05:23:50 GMT (envelope-from peter@svn.freebsd.org) Message-Id: <200810080523.m985NoFC022534@svn.freebsd.org> From: Peter Wemm Date: Wed, 8 Oct 2008 05:23:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183687 - in user/peter/long_cpumask: . sys X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Oct 2008 05:23:54 -0000 Author: peter Date: Wed Oct 8 05:23:50 2008 New Revision: 183687 URL: http://svn.freebsd.org/changeset/base/183687 Log: Experiment with changing 'cpumask_t' from 32 to 64 bit on 64 bit platforms by changing type from 'int' to 'long'. Added: user/peter/long_cpumask/ user/peter/long_cpumask/sys/ - copied from r183686, head/sys/ From owner-svn-src-user@FreeBSD.ORG Wed Oct 8 05:30:31 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AE4AB1065689; Wed, 8 Oct 2008 05:30:31 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9B22E8FC16; Wed, 8 Oct 2008 05:30:31 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m985UVG9022709; Wed, 8 Oct 2008 05:30:31 GMT (envelope-from peter@svn.freebsd.org) Received: (from peter@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m985UUS2022692; Wed, 8 Oct 2008 05:30:30 GMT (envelope-from peter@svn.freebsd.org) Message-Id: <200810080530.m985UUS2022692@svn.freebsd.org> From: Peter Wemm Date: Wed, 8 Oct 2008 05:30:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183688 - in user/peter/long_cpumask/sys: amd64/amd64 amd64/include kern X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Oct 2008 05:30:31 -0000 Author: peter Date: Wed Oct 8 05:30:30 2008 New Revision: 183688 URL: http://svn.freebsd.org/changeset/base/183688 Log: Expand cpumask_t from 'int' to 'long' on amd64. This compiles and boots, and might even boot on machines with >32 cores. I'll work on the type change for other platforms. Summary of changes: * printf formats * clean up various garbage. use cpumask_t instead of 'u_int' etc. * atomic macro names (xx_int -> xx_long) * bitmask operations ("1 << cpu" -> "1ul << cpu") Modified: user/peter/long_cpumask/sys/amd64/amd64/cpu_switch.S user/peter/long_cpumask/sys/amd64/amd64/intr_machdep.c user/peter/long_cpumask/sys/amd64/amd64/local_apic.c user/peter/long_cpumask/sys/amd64/amd64/mp_machdep.c user/peter/long_cpumask/sys/amd64/amd64/mptable.c user/peter/long_cpumask/sys/amd64/amd64/pmap.c user/peter/long_cpumask/sys/amd64/amd64/vm_machdep.c user/peter/long_cpumask/sys/amd64/include/_types.h user/peter/long_cpumask/sys/amd64/include/pmap.h user/peter/long_cpumask/sys/amd64/include/smp.h user/peter/long_cpumask/sys/kern/kern_ktr.c user/peter/long_cpumask/sys/kern/kern_pmc.c user/peter/long_cpumask/sys/kern/sched_4bsd.c user/peter/long_cpumask/sys/kern/sched_ule.c user/peter/long_cpumask/sys/kern/subr_pcpu.c user/peter/long_cpumask/sys/kern/subr_smp.c Modified: user/peter/long_cpumask/sys/amd64/amd64/cpu_switch.S ============================================================================== --- user/peter/long_cpumask/sys/amd64/amd64/cpu_switch.S Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/amd64/amd64/cpu_switch.S Wed Oct 8 05:30:30 2008 (r183688) @@ -80,7 +80,7 @@ ENTRY(cpu_throw) /* release bit from old pm_active */ movq TD_PROC(%rdi), %rdx /* oldtd->td_proc */ movq P_VMSPACE(%rdx), %rdx /* proc->p_vmspace */ - LK btrl %eax, VM_PMAP+PM_ACTIVE(%rdx) /* clear old */ + LK btrq %rax, VM_PMAP+PM_ACTIVE(%rdx) /* clear old */ movq TD_PCB(%rsi),%r8 /* newtd->td_proc */ movq PCB_CR3(%r8),%rdx movq %rdx,%cr3 /* new address space */ @@ -165,13 +165,13 @@ swinact: /* Release bit from old pmap->pm_active */ movq TD_PROC(%rdi), %rcx /* oldproc */ movq P_VMSPACE(%rcx), %rcx - LK btrl %eax, VM_PMAP+PM_ACTIVE(%rcx) /* clear old */ + LK btrq %rax, VM_PMAP+PM_ACTIVE(%rcx) /* clear old */ SETLK %rdx, TD_LOCK(%rdi) /* Release the old thread */ swact: /* Set bit in new pmap->pm_active */ movq TD_PROC(%rsi),%rdx /* newproc */ movq P_VMSPACE(%rdx), %rdx - LK btsl %eax, VM_PMAP+PM_ACTIVE(%rdx) /* set new */ + LK btsq %rax, VM_PMAP+PM_ACTIVE(%rdx) /* set new */ sw1: #if defined(SCHED_ULE) && defined(SMP) Modified: user/peter/long_cpumask/sys/amd64/amd64/intr_machdep.c ============================================================================== --- user/peter/long_cpumask/sys/amd64/amd64/intr_machdep.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/amd64/amd64/intr_machdep.c Wed Oct 8 05:30:30 2008 (r183688) @@ -435,7 +435,7 @@ DB_SHOW_COMMAND(irqs, db_show_irqs) */ /* The BSP is always a valid target. */ -static cpumask_t intr_cpus = (1 << 0); +static cpumask_t intr_cpus = (1ul << 0); static int current_cpu; static void @@ -450,7 +450,7 @@ intr_assign_next_cpu(struct intsrc *isrc current_cpu++; if (current_cpu > mp_maxid) current_cpu = 0; - } while (!(intr_cpus & (1 << current_cpu))); + } while (!(intr_cpus & (1ul << current_cpu))); } /* Attempt to bind the specified IRQ to the specified CPU. */ @@ -479,7 +479,7 @@ intr_add_cpu(u_int cpu) printf("INTR: Adding local APIC %d as a target\n", cpu_apic_ids[cpu]); - intr_cpus |= (1 << cpu); + intr_cpus |= (1ul << cpu); } /* Modified: user/peter/long_cpumask/sys/amd64/amd64/local_apic.c ============================================================================== --- user/peter/long_cpumask/sys/amd64/amd64/local_apic.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/amd64/amd64/local_apic.c Wed Oct 8 05:30:30 2008 (r183688) @@ -672,7 +672,7 @@ lapic_handle_timer(struct trapframe *fra * and unlike other schedulers it actually schedules threads to * those CPUs. */ - if ((hlt_cpus_mask & (1 << PCPU_GET(cpuid))) != 0) + if ((hlt_cpus_mask & (1ul << PCPU_GET(cpuid))) != 0) return; #endif Modified: user/peter/long_cpumask/sys/amd64/amd64/mp_machdep.c ============================================================================== --- user/peter/long_cpumask/sys/amd64/amd64/mp_machdep.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/amd64/amd64/mp_machdep.c Wed Oct 8 05:30:30 2008 (r183688) @@ -112,7 +112,7 @@ extern inthand_t IDTVEC(fast_syscall), I #ifdef STOP_NMI volatile cpumask_t ipi_nmi_pending; -static void ipi_nmi_selected(u_int32_t cpus); +static void ipi_nmi_selected(cpumask_t cpus); #endif /* @@ -733,7 +733,7 @@ start_all_aps(void) panic("AP #%d (PHY# %d) failed!", cpu, apic_id); } - all_cpus |= (1 << cpu); /* record AP in CPU map */ + all_cpus |= (1ul << cpu); /* record AP in CPU map */ } /* build our map of 'other' CPUs */ @@ -853,12 +853,12 @@ smp_tlb_shootdown(u_int vector, vm_offse } static void -smp_targeted_tlb_shootdown(u_int mask, u_int vector, vm_offset_t addr1, vm_offset_t addr2) +smp_targeted_tlb_shootdown(cpumask_t mask, u_int vector, vm_offset_t addr1, vm_offset_t addr2) { int ncpu, othercpus; othercpus = mp_ncpus - 1; - if (mask == (u_int)-1) { + if (mask == (cpumask_t)-1) { ncpu = othercpus; if (ncpu < 1) return; @@ -883,7 +883,7 @@ smp_targeted_tlb_shootdown(u_int mask, u smp_tlb_addr1 = addr1; smp_tlb_addr2 = addr2; atomic_store_rel_int(&smp_tlb_wait, 0); - if (mask == (u_int)-1) + if (mask == (cpumask_t)-1) ipi_all_but_self(vector); else ipi_selected(mask, vector); @@ -927,7 +927,7 @@ smp_invlpg_range(vm_offset_t addr1, vm_o } void -smp_masked_invltlb(u_int mask) +smp_masked_invltlb(cpumask_t mask) { if (smp_started) { @@ -936,7 +936,7 @@ smp_masked_invltlb(u_int mask) } void -smp_masked_invlpg(u_int mask, vm_offset_t addr) +smp_masked_invlpg(cpumask_t mask, vm_offset_t addr) { if (smp_started) { @@ -945,7 +945,7 @@ smp_masked_invlpg(u_int mask, vm_offset_ } void -smp_masked_invlpg_range(u_int mask, vm_offset_t addr1, vm_offset_t addr2) +smp_masked_invlpg_range(cpumask_t mask, vm_offset_t addr1, vm_offset_t addr2) { if (smp_started) { @@ -961,7 +961,7 @@ ipi_bitmap_handler(struct trapframe fram ipi_bitmap = atomic_readandclear_int(&cpu_ipi_pending[cpu]); - if (ipi_bitmap & (1 << IPI_PREEMPT)) + if (ipi_bitmap & (1ul << IPI_PREEMPT)) sched_preempt(curthread); /* Nothing to do for AST */ @@ -971,7 +971,7 @@ ipi_bitmap_handler(struct trapframe fram * send an IPI to a set of cpus. */ void -ipi_selected(u_int32_t cpus, u_int ipi) +ipi_selected(cpumask_t cpus, u_int ipi) { int cpu; u_int bitmap = 0; @@ -990,9 +990,9 @@ ipi_selected(u_int32_t cpus, u_int ipi) } #endif CTR3(KTR_SMP, "%s: cpus: %x ipi: %x", __func__, cpus, ipi); - while ((cpu = ffs(cpus)) != 0) { + while ((cpu = ffsl(cpus)) != 0) { cpu--; - cpus &= ~(1 << cpu); + cpus &= ~(1ul << cpu); KASSERT(cpu_apic_ids[cpu] != -1, ("IPI to non-existent CPU %d", cpu)); @@ -1035,7 +1035,7 @@ ipi_all_but_self(u_int ipi) #define BEFORE_SPIN 1000000 void -ipi_nmi_selected(u_int32_t cpus) +ipi_nmi_selected(cpumask_t cpus) { int cpu; register_t icrlo; @@ -1045,11 +1045,11 @@ ipi_nmi_selected(u_int32_t cpus) CTR2(KTR_SMP, "%s: cpus: %x nmi", __func__, cpus); - atomic_set_int(&ipi_nmi_pending, cpus); + atomic_set_long(&ipi_nmi_pending, cpus); - while ((cpu = ffs(cpus)) != 0) { + while ((cpu = ffsl(cpus)) != 0) { cpu--; - cpus &= ~(1 << cpu); + cpus &= ~(1ul << cpu); KASSERT(cpu_apic_ids[cpu] != -1, ("IPI NMI to non-existent CPU %d", cpu)); @@ -1065,12 +1065,12 @@ ipi_nmi_selected(u_int32_t cpus) int ipi_nmi_handler(void) { - int cpumask = PCPU_GET(cpumask); + cpumask_t cpumask = PCPU_GET(cpumask); if (!(ipi_nmi_pending & cpumask)) return 1; - atomic_clear_int(&ipi_nmi_pending, cpumask); + atomic_clear_long(&ipi_nmi_pending, cpumask); cpustop_handler(); return 0; } @@ -1085,19 +1085,19 @@ void cpustop_handler(void) { int cpu = PCPU_GET(cpuid); - int cpumask = PCPU_GET(cpumask); + cpumask_t cpumask = PCPU_GET(cpumask); savectx(&stoppcbs[cpu]); /* Indicate that we are stopped */ - atomic_set_int(&stopped_cpus, cpumask); + atomic_set_long(&stopped_cpus, cpumask); /* Wait for restart */ while (!(started_cpus & cpumask)) ia32_pause(); - atomic_clear_int(&started_cpus, cpumask); - atomic_clear_int(&stopped_cpus, cpumask); + atomic_clear_long(&started_cpus, cpumask); + atomic_clear_long(&stopped_cpus, cpumask); if (cpu == 0 && cpustop_restartfunc != NULL) { cpustop_restartfunc(); @@ -1245,7 +1245,7 @@ SYSINIT(cpu_hlt, SI_SUB_SMP, SI_ORDER_AN int mp_grab_cpu_hlt(void) { - u_int mask = PCPU_GET(cpumask); + cpumask_t mask = PCPU_GET(cpumask); #ifdef MP_WATCHDOG u_int cpuid = PCPU_GET(cpuid); #endif Modified: user/peter/long_cpumask/sys/amd64/amd64/mptable.c ============================================================================== --- user/peter/long_cpumask/sys/amd64/amd64/mptable.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/amd64/amd64/mptable.c Wed Oct 8 05:30:30 2008 (r183688) @@ -888,13 +888,13 @@ mptable_hyperthread_fixup(u_long id_mask * already in the table, then kill the fixup. */ for (id = 0; id <= MAX_LAPIC_ID; id++) { - if ((id_mask & 1 << id) == 0) + if ((id_mask & 1ul << id) == 0) continue; /* First, make sure we are on a logical_cpus boundary. */ if (id % logical_cpus != 0) return; for (i = id + 1; i < id + logical_cpus; i++) - if ((id_mask & 1 << i) != 0) + if ((id_mask & 1ul << i) != 0) return; } @@ -911,7 +911,7 @@ mptable_hyperthread_fixup(u_long id_mask i, id); lapic_create(i, 0); } - id_mask &= ~(1 << id); + id_mask &= ~(1ul << id); } } #endif /* MPTABLE_FORCE_HTT */ Modified: user/peter/long_cpumask/sys/amd64/amd64/pmap.c ============================================================================== --- user/peter/long_cpumask/sys/amd64/amd64/pmap.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/amd64/amd64/pmap.c Wed Oct 8 05:30:30 2008 (r183688) @@ -544,7 +544,7 @@ pmap_bootstrap(vm_paddr_t *firstaddr) PMAP_LOCK_INIT(kernel_pmap); kernel_pmap->pm_pml4 = (pdp_entry_t *) (KERNBASE + KPML4phys); kernel_pmap->pm_root = NULL; - kernel_pmap->pm_active = -1; /* don't allow deactivation */ + kernel_pmap->pm_active = (cpumask_t)-1; /* don't allow deactivation */ TAILQ_INIT(&kernel_pmap->pm_pvchunk); /* @@ -858,8 +858,7 @@ pmap_cache_bits(int mode, boolean_t is_p void pmap_invalidate_page(pmap_t pmap, vm_offset_t va) { - u_int cpumask; - u_int other_cpus; + cpumask_t cpumask, other_cpus; sched_pin(); if (pmap == kernel_pmap || pmap->pm_active == all_cpus) { @@ -879,8 +878,7 @@ pmap_invalidate_page(pmap_t pmap, vm_off void pmap_invalidate_range(pmap_t pmap, vm_offset_t sva, vm_offset_t eva) { - u_int cpumask; - u_int other_cpus; + cpumask_t cpumask, other_cpus; vm_offset_t addr; sched_pin(); @@ -904,8 +902,7 @@ pmap_invalidate_range(pmap_t pmap, vm_of void pmap_invalidate_all(pmap_t pmap) { - u_int cpumask; - u_int other_cpus; + cpumask_t cpumask, other_cpus; sched_pin(); if (pmap == kernel_pmap || pmap->pm_active == all_cpus) { @@ -4739,8 +4736,8 @@ pmap_activate(struct thread *td) oldpmap = PCPU_GET(curpmap); #ifdef SMP if (oldpmap) /* XXX FIXME */ - atomic_clear_int(&oldpmap->pm_active, PCPU_GET(cpumask)); - atomic_set_int(&pmap->pm_active, PCPU_GET(cpumask)); + atomic_clear_long(&oldpmap->pm_active, PCPU_GET(cpumask)); + atomic_set_long(&pmap->pm_active, PCPU_GET(cpumask)); #else if (oldpmap) /* XXX FIXME */ oldpmap->pm_active &= ~PCPU_GET(cpumask); Modified: user/peter/long_cpumask/sys/amd64/amd64/vm_machdep.c ============================================================================== --- user/peter/long_cpumask/sys/amd64/amd64/vm_machdep.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/amd64/amd64/vm_machdep.c Wed Oct 8 05:30:30 2008 (r183688) @@ -419,7 +419,8 @@ void cpu_reset() { #ifdef SMP - u_int cnt, map; + u_int cnt; + cpumask_t map; if (smp_active) { map = PCPU_GET(other_cpus) & ~stopped_cpus; @@ -435,7 +436,7 @@ cpu_reset() printf("cpu_reset: Restarting BSP\n"); /* Restart CPU #0. */ - atomic_store_rel_int(&started_cpus, 1 << 0); + atomic_store_rel_long(&started_cpus, 1 << 0); cnt = 0; while (cpu_reset_proxy_active == 0 && cnt < 10000000) Modified: user/peter/long_cpumask/sys/amd64/include/_types.h ============================================================================== --- user/peter/long_cpumask/sys/amd64/include/_types.h Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/amd64/include/_types.h Wed Oct 8 05:30:30 2008 (r183688) @@ -61,7 +61,7 @@ typedef unsigned long __uint64_t; * Standard type definitions. */ typedef __int32_t __clock_t; /* clock()... */ -typedef unsigned int __cpumask_t; +typedef unsigned long __cpumask_t; typedef __int64_t __critical_t; typedef double __double_t; typedef float __float_t; Modified: user/peter/long_cpumask/sys/amd64/include/pmap.h ============================================================================== --- user/peter/long_cpumask/sys/amd64/include/pmap.h Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/amd64/include/pmap.h Wed Oct 8 05:30:30 2008 (r183688) @@ -247,8 +247,7 @@ struct pmap { struct mtx pm_mtx; pml4_entry_t *pm_pml4; /* KVA of level 4 page table */ TAILQ_HEAD(,pv_chunk) pm_pvchunk; /* list of mappings in pmap */ - u_int pm_active; /* active on cpus */ - /* spare u_int here due to padding */ + cpumask_t pm_active; /* active on cpus */ struct pmap_statistics pm_stats; /* pmap statistics */ vm_page_t pm_root; /* spare page table pages */ }; Modified: user/peter/long_cpumask/sys/amd64/include/smp.h ============================================================================== --- user/peter/long_cpumask/sys/amd64/include/smp.h Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/amd64/include/smp.h Wed Oct 8 05:30:30 2008 (r183688) @@ -54,19 +54,19 @@ inthand_t void cpu_add(u_int apic_id, char boot_cpu); void cpustop_handler(void); void init_secondary(void); -void ipi_selected(u_int cpus, u_int ipi); +void ipi_selected(cpumask_t cpus, u_int ipi); void ipi_all_but_self(u_int ipi); void ipi_bitmap_handler(struct trapframe frame); u_int mp_bootaddress(u_int); int mp_grab_cpu_hlt(void); void smp_cache_flush(void); void smp_invlpg(vm_offset_t addr); -void smp_masked_invlpg(u_int mask, vm_offset_t addr); +void smp_masked_invlpg(cpumask_t mask, vm_offset_t addr); void smp_invlpg_range(vm_offset_t startva, vm_offset_t endva); -void smp_masked_invlpg_range(u_int mask, vm_offset_t startva, +void smp_masked_invlpg_range(cpumask_t mask, vm_offset_t startva, vm_offset_t endva); void smp_invltlb(void); -void smp_masked_invltlb(u_int mask); +void smp_masked_invltlb(cpumask_t mask); #ifdef STOP_NMI int ipi_nmi_handler(void); Modified: user/peter/long_cpumask/sys/kern/kern_ktr.c ============================================================================== --- user/peter/long_cpumask/sys/kern/kern_ktr.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/kern/kern_ktr.c Wed Oct 8 05:30:30 2008 (r183688) @@ -207,7 +207,7 @@ ktr_tracepoint(u_int mask, const char *f if ((ktr_mask & mask) == 0) return; cpu = KTR_CPU; - if (((1 << cpu) & ktr_cpumask) == 0) + if (((1ul << cpu) & ktr_cpumask) == 0) return; #if defined(KTR_VERBOSE) || defined(KTR_ALQ) td = curthread; Modified: user/peter/long_cpumask/sys/kern/kern_pmc.c ============================================================================== --- user/peter/long_cpumask/sys/kern/kern_pmc.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/kern/kern_pmc.c Wed Oct 8 05:30:30 2008 (r183688) @@ -110,7 +110,7 @@ pmc_cpu_is_active(int cpu) { #ifdef SMP return (pmc_cpu_is_present(cpu) && - (hlt_cpus_mask & (1 << cpu)) == 0); + (hlt_cpus_mask & (1ul << cpu)) == 0); #else return (1); #endif @@ -137,7 +137,7 @@ int pmc_cpu_is_primary(int cpu) { #ifdef SMP - return ((logical_cpus_mask & (1 << cpu)) == 0); + return ((logical_cpus_mask & (1ul << cpu)) == 0); #else return (1); #endif Modified: user/peter/long_cpumask/sys/kern/sched_4bsd.c ============================================================================== --- user/peter/long_cpumask/sys/kern/sched_4bsd.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/kern/sched_4bsd.c Wed Oct 8 05:30:30 2008 (r183688) @@ -1067,7 +1067,7 @@ forward_wakeup(int cpunum) me = PCPU_GET(cpumask); /* Don't bother if we should be doing it ourself. */ - if ((me & idle_cpus_mask) && (cpunum == NOCPU || me == (1 << cpunum))) + if ((me & idle_cpus_mask) && (cpunum == NOCPU || me == (1ul << cpunum))) return (0); dontuse = me | stopped_cpus | hlt_cpus_mask; @@ -1101,7 +1101,7 @@ forward_wakeup(int cpunum) /* If we only allow a specific CPU, then mask off all the others. */ if (cpunum != NOCPU) { KASSERT((cpunum <= mp_maxcpus),("forward_wakeup: bad cpunum.")); - map &= (1 << cpunum); + map &= (1ul << cpunum); } else { /* Try choose an idle die. */ if (forward_wakeup_use_htt) { @@ -1628,7 +1628,7 @@ sched_affinity(struct thread *td) td->td_flags |= TDF_NEEDRESCHED; if (td != curthread) - ipi_selected(1 << cpu, IPI_AST); + ipi_selected(1ul << cpu, IPI_AST); break; default: break; Modified: user/peter/long_cpumask/sys/kern/sched_ule.c ============================================================================== --- user/peter/long_cpumask/sys/kern/sched_ule.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/kern/sched_ule.c Wed Oct 8 05:30:30 2008 (r183688) @@ -540,7 +540,7 @@ struct cpu_search { #define CPUMASK_FOREACH(cpu, mask) \ for ((cpu) = 0; (cpu) < sizeof((mask)) * 8; (cpu)++) \ - if ((mask) & 1 << (cpu)) + if ((mask) & 1ul << (cpu)) static __inline int cpu_search(struct cpu_group *cg, struct cpu_search *low, struct cpu_search *high, const int match); @@ -562,14 +562,14 @@ cpu_compare(int cpu, struct cpu_search * tdq = TDQ_CPU(cpu); if (match & CPU_SEARCH_LOWEST) - if (low->cs_mask & (1 << cpu) && + if (low->cs_mask & (1ul << cpu) && tdq->tdq_load < low->cs_load && tdq->tdq_lowpri > low->cs_limit) { low->cs_cpu = cpu; low->cs_load = tdq->tdq_load; } if (match & CPU_SEARCH_HIGHEST) - if (high->cs_mask & (1 << cpu) && + if (high->cs_mask & (1ul << cpu) && tdq->tdq_load >= high->cs_limit && tdq->tdq_load > high->cs_load && tdq->tdq_transferable) { @@ -739,7 +739,7 @@ sched_balance_group(struct cpu_group *cg int low; int i; - mask = -1; + mask = (cpumask_t)-1; for (;;) { sched_both(cg, mask, &low, &high); if (low == high || low == -1 || high == -1) @@ -751,9 +751,9 @@ sched_balance_group(struct cpu_group *cg * to kick out of the set and try again. */ if (TDQ_CPU(high)->tdq_transferable == 0) - mask &= ~(1 << high); + mask &= ~(1ul << high); else - mask &= ~(1 << low); + mask &= ~(1ul << low); } for (i = 0; i < cg->cg_children; i++) @@ -839,7 +839,7 @@ sched_balance_pair(struct tdq *high, str * IPI the target cpu to force it to reschedule with the new * workload. */ - ipi_selected(1 << TDQ_ID(low), IPI_PREEMPT); + ipi_selected(1ul << TDQ_ID(low), IPI_PREEMPT); } tdq_unlock_pair(high, low); return (moved); @@ -894,7 +894,7 @@ tdq_idled(struct tdq *tdq) if (smp_started == 0 || steal_idle == 0) return (1); - mask = -1; + mask = (cpumask_t)-1; mask &= ~PCPU_GET(cpumask); /* We don't want to be preempted while we're iterating. */ spinlock_enter(); @@ -909,7 +909,7 @@ tdq_idled(struct tdq *tdq) continue; } steal = TDQ_CPU(cpu); - mask &= ~(1 << cpu); + mask &= ~(1ul << cpu); tdq_lock_pair(tdq, steal); if (steal->tdq_load < thresh || steal->tdq_transferable == 0) { tdq_unlock_pair(tdq, steal); @@ -969,7 +969,7 @@ tdq_notify(struct tdq *tdq, struct threa return; } tdq->tdq_ipipending = 1; - ipi_selected(1 << cpu, IPI_PREEMPT); + ipi_selected(1ul << cpu, IPI_PREEMPT); } /* @@ -2404,7 +2404,7 @@ sched_affinity(struct thread *td) cpu = ts->ts_cpu; ts->ts_cpu = sched_pickcpu(td, 0); if (cpu != PCPU_GET(cpuid)) - ipi_selected(1 << cpu, IPI_PREEMPT); + ipi_selected(1ul << cpu, IPI_PREEMPT); #endif } Modified: user/peter/long_cpumask/sys/kern/subr_pcpu.c ============================================================================== --- user/peter/long_cpumask/sys/kern/subr_pcpu.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/kern/subr_pcpu.c Wed Oct 8 05:30:30 2008 (r183688) @@ -70,7 +70,7 @@ pcpu_init(struct pcpu *pcpu, int cpuid, KASSERT(cpuid >= 0 && cpuid < MAXCPU, ("pcpu_init: invalid cpuid %d", cpuid)); pcpu->pc_cpuid = cpuid; - pcpu->pc_cpumask = 1 << cpuid; + pcpu->pc_cpumask = 1ul << cpuid; cpuid_to_pcpu[cpuid] = pcpu; SLIST_INSERT_HEAD(&cpuhead, pcpu, pc_allcpu); cpu_pcpu_init(pcpu, cpuid, size); Modified: user/peter/long_cpumask/sys/kern/subr_smp.c ============================================================================== --- user/peter/long_cpumask/sys/kern/subr_smp.c Wed Oct 8 05:23:50 2008 (r183687) +++ user/peter/long_cpumask/sys/kern/subr_smp.c Wed Oct 8 05:30:30 2008 (r183688) @@ -186,7 +186,7 @@ forward_signal(struct thread *td) id = td->td_oncpu; if (id == NOCPU) return; - ipi_selected(1 << id, IPI_AST); + ipi_selected(1ul << id, IPI_AST); } void @@ -285,7 +285,12 @@ restart_cpus(cpumask_t map) CTR1(KTR_SMP, "restart_cpus(%x)", map); /* signal other cpus to restart */ +#if defined(__amd64__) + /* cpumask_t is 64 bit on amd64. */ + atomic_store_rel_long(&started_cpus, map); +#else atomic_store_rel_int(&started_cpus, map); +#endif /* wait for each to clear its bit */ while ((stopped_cpus & map) != 0) @@ -363,7 +368,7 @@ smp_rendezvous_cpus(cpumask_t map, } for (i = 0; i < mp_maxid; i++) - if (((1 << i) & map) != 0 && !CPU_ABSENT(i)) + if (((1ul << i) & map) != 0 && !CPU_ABSENT(i)) ncpus++; /* obtain rendezvous lock */ @@ -380,10 +385,10 @@ smp_rendezvous_cpus(cpumask_t map, atomic_store_rel_int(&smp_rv_waiters[0], 0); /* signal other processors, which will enter the IPI with interrupts off */ - ipi_selected(map & ~(1 << curcpu), IPI_RENDEZVOUS); + ipi_selected(map & ~(1ul << curcpu), IPI_RENDEZVOUS); /* Check if the current CPU is in the map */ - if ((map & (1 << curcpu)) != 0) + if ((map & (1ul << curcpu)) != 0) smp_rendezvous_action(); if (teardown_func == smp_no_rendevous_barrier) @@ -455,8 +460,8 @@ smp_topo(void) panic("Built bad topology at %p. CPU count %d != %d", top, top->cg_count, mp_ncpus); if (top->cg_mask != all_cpus) - panic("Built bad topology at %p. CPU mask 0x%X != 0x%X", - top, top->cg_mask, all_cpus); + panic("Built bad topology at %p. CPU mask 0x%lX != 0x%lX", + top, (unsigned long)top->cg_mask, (unsigned long)all_cpus); return (top); } @@ -468,7 +473,7 @@ smp_topo_none(void) top = &group[0]; top->cg_parent = NULL; top->cg_child = NULL; - top->cg_mask = (1 << mp_ncpus) - 1; + top->cg_mask = (1ul << mp_ncpus) - 1; top->cg_count = mp_ncpus; top->cg_children = 0; top->cg_level = CG_SHARE_NONE; @@ -485,7 +490,7 @@ smp_topo_addleaf(struct cpu_group *paren int i; for (mask = 0, i = 0; i < count; i++, start++) - mask |= (1 << start); + mask |= (1ul << start); child->cg_parent = parent; child->cg_child = NULL; child->cg_children = 0; @@ -496,8 +501,9 @@ smp_topo_addleaf(struct cpu_group *paren parent->cg_children++; for (; parent != NULL; parent = parent->cg_parent) { if ((parent->cg_mask & child->cg_mask) != 0) - panic("Duplicate children in %p. mask 0x%X child 0x%X", - parent, parent->cg_mask, child->cg_mask); + panic("Duplicate children in %p. mask 0x%lX child 0x%lX", + parent, (unsigned long)parent->cg_mask, + (unsigned long)child->cg_mask); parent->cg_mask |= child->cg_mask; parent->cg_count += child->cg_count; } @@ -562,7 +568,7 @@ smp_topo_find(struct cpu_group *top, int int children; int i; - mask = (1 << cpu); + mask = (1ul << cpu); cg = top; for (;;) { if ((cg->cg_mask & mask) == 0) From owner-svn-src-user@FreeBSD.ORG Thu Oct 9 01:34:28 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A3A42106568E; Thu, 9 Oct 2008 01:34:28 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8F08C8FC18; Thu, 9 Oct 2008 01:34:28 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m991YSO4048231; Thu, 9 Oct 2008 01:34:28 GMT (envelope-from peter@svn.freebsd.org) Received: (from peter@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m991YSaQ048219; Thu, 9 Oct 2008 01:34:28 GMT (envelope-from peter@svn.freebsd.org) Message-Id: <200810090134.m991YSaQ048219@svn.freebsd.org> From: Peter Wemm Date: Thu, 9 Oct 2008 01:34:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183713 - in user/peter/long_cpumask/sys: . dev/e1000 dev/iicbus dev/mmc dev/pcn dev/sio dev/sis dev/ste dev/tl dev/usb dev/wb dev/xl kern mips/adm5120 mips/idt mips/malta mips/sentry5 ... X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Oct 2008 01:34:28 -0000 Author: peter Date: Thu Oct 9 01:34:27 2008 New Revision: 183713 URL: http://svn.freebsd.org/changeset/base/183713 Log: Merge r183687 through r183712 into wip branch. Suffer mergeinfo whiplash. Modified: user/peter/long_cpumask/sys/ (props changed) user/peter/long_cpumask/sys/dev/e1000/ (props changed) user/peter/long_cpumask/sys/dev/e1000/e1000_82575.c (props changed) user/peter/long_cpumask/sys/dev/e1000/e1000_82575.h (props changed) user/peter/long_cpumask/sys/dev/e1000/if_igb.c (props changed) user/peter/long_cpumask/sys/dev/e1000/if_igb.h (props changed) user/peter/long_cpumask/sys/dev/iicbus/ds133x.c (props changed) user/peter/long_cpumask/sys/dev/mmc/bridge.h user/peter/long_cpumask/sys/dev/mmc/mmc.c user/peter/long_cpumask/sys/dev/mmc/mmcbrvar.h user/peter/long_cpumask/sys/dev/mmc/mmcreg.h user/peter/long_cpumask/sys/dev/mmc/mmcsd.c user/peter/long_cpumask/sys/dev/mmc/mmcvar.h user/peter/long_cpumask/sys/dev/pcn/if_pcn.c (props changed) user/peter/long_cpumask/sys/dev/pcn/if_pcnreg.h (props changed) user/peter/long_cpumask/sys/dev/sio/sio.c user/peter/long_cpumask/sys/dev/sis/if_sis.c (props changed) user/peter/long_cpumask/sys/dev/sis/if_sisreg.h (props changed) user/peter/long_cpumask/sys/dev/ste/if_ste.c (props changed) user/peter/long_cpumask/sys/dev/ste/if_stereg.h (props changed) user/peter/long_cpumask/sys/dev/tl/if_tl.c (props changed) user/peter/long_cpumask/sys/dev/tl/if_tlreg.h (props changed) user/peter/long_cpumask/sys/dev/usb/umass.c user/peter/long_cpumask/sys/dev/usb/usbdevs user/peter/long_cpumask/sys/dev/wb/if_wb.c (props changed) user/peter/long_cpumask/sys/dev/wb/if_wbreg.h (props changed) user/peter/long_cpumask/sys/dev/xl/if_xl.c (props changed) user/peter/long_cpumask/sys/dev/xl/if_xlreg.h (props changed) user/peter/long_cpumask/sys/kern/imgact_elf.c user/peter/long_cpumask/sys/kern/uipc_usrreq.c user/peter/long_cpumask/sys/mips/adm5120/ (props changed) user/peter/long_cpumask/sys/mips/idt/ (props changed) user/peter/long_cpumask/sys/mips/malta/ (props changed) user/peter/long_cpumask/sys/mips/sentry5/ (props changed) user/peter/long_cpumask/sys/netgraph/netflow/netflow.c user/peter/long_cpumask/sys/netgraph/netflow/ng_netflow.c user/peter/long_cpumask/sys/netgraph/netflow/ng_netflow.h Modified: user/peter/long_cpumask/sys/dev/mmc/bridge.h ============================================================================== --- user/peter/long_cpumask/sys/dev/mmc/bridge.h Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/dev/mmc/bridge.h Thu Oct 9 01:34:27 2008 (r183713) @@ -104,6 +104,10 @@ enum mmc_bus_width { bus_width_1 = 0, bus_width_4 = 2, bus_width_8 = 3 }; +enum mmc_bus_timing { + bus_timing_normal = 0, bus_timing_hs +}; + struct mmc_ios { uint32_t clock; /* Speed of the clock in Hz to move data */ enum mmc_vdd vdd; /* Voltage to apply to the power pins/ */ @@ -111,6 +115,7 @@ struct mmc_ios { enum mmc_chip_select chip_select; enum mmc_bus_width bus_width; enum mmc_power_mode power_mode; + enum mmc_bus_timing timing; }; enum mmc_card_mode { @@ -125,6 +130,7 @@ struct mmc_host { uint32_t caps; #define MMC_CAP_4_BIT_DATA (1 << 0) /* Can do 4-bit data transfers */ #define MMC_CAP_8_BIT_DATA (1 << 1) /* Can do 8-bit data transfers */ +#define MMC_CAP_HSPEED (1 << 2) /* Can do High Speed transfers */ enum mmc_card_mode mode; struct mmc_ios ios; /* Current state of the host */ }; Modified: user/peter/long_cpumask/sys/dev/mmc/mmc.c ============================================================================== --- user/peter/long_cpumask/sys/dev/mmc/mmc.c Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/dev/mmc/mmc.c Thu Oct 9 01:34:27 2008 (r183713) @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -82,11 +83,19 @@ struct mmc_softc { struct mmc_ivars { uint32_t raw_cid[4]; /* Raw bits of the CID */ uint32_t raw_csd[4]; /* Raw bits of the CSD */ + uint32_t raw_scr[2]; /* Raw bits of the SCR */ + uint8_t raw_ext_csd[512]; /* Raw bits of the EXT_CSD */ uint16_t rca; enum mmc_card_mode mode; struct mmc_cid cid; /* cid decoded */ struct mmc_csd csd; /* csd decoded */ + struct mmc_scr scr; /* scr decoded */ u_char read_only; /* True when the device is read-only */ + u_char bus_width; /* Bus width to use */ + u_char timing; /* Bus timing support */ + u_char high_cap; /* High Capacity card */ + uint32_t tran_speed; /* Max speed in normal mode */ + uint32_t hs_tran_speed; /* Max speed in high speed mode */ }; #define CMD_RETRIES 3 @@ -111,6 +120,11 @@ static int mmc_wait_for_cmd(struct mmc_s int retries); static int mmc_wait_for_command(struct mmc_softc *sc, uint32_t opcode, uint32_t arg, uint32_t flags, uint32_t *resp, int retries); +static int mmc_select_card(struct mmc_softc *sc, uint16_t rca); +static int mmc_set_bus_width(struct mmc_softc *sc, uint16_t rca, int width); +static int mmc_app_send_scr(struct mmc_softc *sc, uint16_t rca, uint32_t *rawscr); +static void mmc_app_decode_scr(uint32_t *raw_scr, struct mmc_scr *scr); +static int mmc_send_ext_csd(struct mmc_softc *sc, uint8_t *rawextcsd); static void mmc_ms_delay(int ms) @@ -173,6 +187,7 @@ static int mmc_acquire_bus(device_t busdev, device_t dev) { struct mmc_softc *sc; + struct mmc_ivars *ivar; int err; int rca; @@ -195,21 +210,26 @@ mmc_acquire_bus(device_t busdev, device_ */ rca = mmc_get_rca(dev); if (sc->last_rca != rca) { - mmc_wait_for_command(sc, MMC_SELECT_CARD, rca << 16, - MMC_RSP_R1 | MMC_CMD_AC, NULL, CMD_RETRIES); + mmc_select_card(sc, rca); sc->last_rca = rca; + /* Prepare bus width for the new card. */ + ivar = device_get_ivars(dev); + device_printf(busdev, + "setting bus width to %d bits\n", + (ivar->bus_width == bus_width_4)?4: + (ivar->bus_width == bus_width_8)?8:1); + mmc_set_bus_width(sc, rca, ivar->bus_width); + mmcbr_set_bus_width(busdev, ivar->bus_width); + mmcbr_update_ios(busdev); } - /* XXX should set bus width here? */ } else { /* * If there's a card selected, stand down. */ if (sc->last_rca != 0) { - mmc_wait_for_command(sc, MMC_SELECT_CARD, 0, - MMC_RSP_R1 | MMC_CMD_AC, NULL, CMD_RETRIES); + mmc_select_card(sc, 0); sc->last_rca = 0; } - /* XXX should set bus width here? */ } return (0); @@ -408,7 +428,8 @@ mmc_send_app_op_cond(struct mmc_softc *s err = mmc_wait_for_app_cmd(sc, 0, &cmd, CMD_RETRIES); if (err != MMC_ERR_NONE) break; - if ((cmd.resp[0] & MMC_OCR_CARD_BUSY) || ocr == 0) + if ((cmd.resp[0] & MMC_OCR_CARD_BUSY) || + (ocr & MMC_OCR_VOLTAGE) == 0) break; err = MMC_ERR_TIMEOUT; mmc_ms_delay(10); @@ -434,7 +455,8 @@ mmc_send_op_cond(struct mmc_softc *sc, u err = mmc_wait_for_cmd(sc, &cmd, CMD_RETRIES); if (err != MMC_ERR_NONE) break; - if ((cmd.resp[0] & MMC_OCR_CARD_BUSY) || ocr == 0) + if ((cmd.resp[0] & MMC_OCR_CARD_BUSY) || + (ocr & MMC_OCR_VOLTAGE) == 0) break; err = MMC_ERR_TIMEOUT; mmc_ms_delay(10); @@ -444,6 +466,22 @@ mmc_send_op_cond(struct mmc_softc *sc, u return (err); } +static int +mmc_send_if_cond(struct mmc_softc *sc, uint8_t vhs) +{ + struct mmc_command cmd; + int err; + + memset(&cmd, 0, sizeof(cmd)); + cmd.opcode = SD_SEND_IF_COND; + cmd.arg = (vhs << 8) + 0xAA; + cmd.flags = MMC_RSP_R7 | MMC_CMD_BCR; + cmd.data = NULL; + + err = mmc_wait_for_cmd(sc, &cmd, CMD_RETRIES); + return (err); +} + static void mmc_power_up(struct mmc_softc *sc) { @@ -460,6 +498,7 @@ mmc_power_up(struct mmc_softc *sc) mmc_ms_delay(1); mmcbr_set_clock(dev, mmcbr_get_f_min(sc->dev)); + mmcbr_set_timing(dev, bus_timing_normal); mmcbr_set_power_mode(dev, power_on); mmcbr_update_ios(dev); mmc_ms_delay(2); @@ -475,9 +514,207 @@ mmc_power_down(struct mmc_softc *sc) mmcbr_set_bus_width(dev, bus_width_1); mmcbr_set_power_mode(dev, power_off); mmcbr_set_clock(dev, 0); + mmcbr_set_timing(dev, bus_timing_normal); mmcbr_update_ios(dev); } +static int +mmc_select_card(struct mmc_softc *sc, uint16_t rca) +{ + return (mmc_wait_for_command(sc, MMC_SELECT_CARD, ((uint32_t)rca) << 16, + MMC_RSP_R1B | MMC_CMD_AC, NULL, CMD_RETRIES)); +} + +static int +mmc_switch(struct mmc_softc *sc, uint8_t set, uint8_t index, uint8_t value) +{ + struct mmc_command cmd; + int err; + + cmd.opcode = MMC_SWITCH_FUNC; + cmd.arg = (MMC_SWITCH_FUNC_WR << 24) | + (index << 16) | + (value << 8) | + set; + cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; + cmd.data = NULL; + err = mmc_wait_for_cmd(sc, &cmd, 0); + return (err); +} + +static int +mmc_sd_switch(struct mmc_softc *sc, uint8_t mode, uint8_t grp, uint8_t value, uint8_t *res) +{ + int err; + struct mmc_command cmd; + struct mmc_data data; + + memset(&cmd, 0, sizeof(struct mmc_command)); + memset(&data, 0, sizeof(struct mmc_data)); + + memset(res, 0, 64); + cmd.opcode = SD_SWITCH_FUNC; + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; + cmd.arg = mode << 31; + cmd.arg |= 0x00FFFFFF; + cmd.arg &= ~(0xF << (grp * 4)); + cmd.arg |= value << (grp * 4); + cmd.data = &data; + + data.data = res; + data.len = 64; + data.flags = MMC_DATA_READ; + + err = mmc_wait_for_cmd(sc, &cmd, CMD_RETRIES); + return (err); +} + +static int +mmc_set_bus_width(struct mmc_softc *sc, uint16_t rca, int width) +{ + int err; + + if (mmcbr_get_mode(sc->dev) == mode_sd) { + struct mmc_command cmd; + + memset(&cmd, 0, sizeof(struct mmc_command)); + cmd.opcode = ACMD_SET_BUS_WIDTH; + cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; + switch (width) { + case bus_width_1: + cmd.arg = SD_BUS_WIDTH_1; + break; + case bus_width_4: + cmd.arg = SD_BUS_WIDTH_4; + break; + default: + return (MMC_ERR_INVALID); + } + err = mmc_wait_for_app_cmd(sc, rca, &cmd, CMD_RETRIES); + } else { + uint8_t value; + + switch (width) { + case bus_width_1: + value = EXT_CSD_BUS_WIDTH_1; + break; + case bus_width_4: + value = EXT_CSD_BUS_WIDTH_4; + break; + case bus_width_8: + value = EXT_CSD_BUS_WIDTH_8; + break; + default: + return (MMC_ERR_INVALID); + } + err = mmc_switch(sc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, value); + } + return (err); +} + +static int +mmc_set_timing(struct mmc_softc *sc, int timing) +{ + int err; + uint8_t value; + + switch (timing) { + case bus_timing_normal: + value = 0; + break; + case bus_timing_hs: + value = 1; + break; + default: + return (MMC_ERR_INVALID); + } + if (mmcbr_get_mode(sc->dev) == mode_sd) { + u_char switch_res[64]; + + err = mmc_sd_switch(sc, 1, 0, value, switch_res); + } else { + err = mmc_switch(sc, EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_HS_TIMING, value); + } + return (err); +} + +static int +mmc_test_bus_width(struct mmc_softc *sc) +{ + struct mmc_command cmd; + struct mmc_data data; + int err; + uint8_t buf[8]; + uint8_t p8[8] = { 0x55, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t p8ok[8] = { 0xAA, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t p4[4] = { 0x5A, 0x00, 0x00, 0x00, }; + uint8_t p4ok[4] = { 0xA5, 0x00, 0x00, 0x00, }; + + if (mmcbr_get_caps(sc->dev) & MMC_CAP_8_BIT_DATA) { + mmcbr_set_bus_width(sc->dev, bus_width_8); + mmcbr_update_ios(sc->dev); + + cmd.opcode = MMC_BUSTEST_W; + cmd.arg = 0; + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; + cmd.data = &data; + + data.data = p8; + data.len = 8; + data.flags = MMC_DATA_WRITE; + mmc_wait_for_cmd(sc, &cmd, 0); + + cmd.opcode = MMC_BUSTEST_R; + cmd.arg = 0; + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; + cmd.data = &data; + + data.data = buf; + data.len = 8; + data.flags = MMC_DATA_READ; + err = mmc_wait_for_cmd(sc, &cmd, 0); + + mmcbr_set_bus_width(sc->dev, bus_width_1); + mmcbr_update_ios(sc->dev); + + if (err == MMC_ERR_NONE && memcmp(buf, p8ok, 8) == 0) + return (bus_width_8); + } + + if (mmcbr_get_caps(sc->dev) & MMC_CAP_4_BIT_DATA) { + mmcbr_set_bus_width(sc->dev, bus_width_4); + mmcbr_update_ios(sc->dev); + + cmd.opcode = MMC_BUSTEST_W; + cmd.arg = 0; + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; + cmd.data = &data; + + data.data = p4; + data.len = 4; + data.flags = MMC_DATA_WRITE; + mmc_wait_for_cmd(sc, &cmd, 0); + + cmd.opcode = MMC_BUSTEST_R; + cmd.arg = 0; + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; + cmd.data = &data; + + data.data = buf; + data.len = 4; + data.flags = MMC_DATA_READ; + err = mmc_wait_for_cmd(sc, &cmd, 0); + + mmcbr_set_bus_width(sc->dev, bus_width_1); + mmcbr_update_ios(sc->dev); + + if (err == MMC_ERR_NONE && memcmp(buf, p4ok, 4) == 0) + return (bus_width_4); + } + return (bus_width_1); +} + static uint32_t mmc_get_bits(uint32_t *bits, int start, int size) { @@ -506,8 +743,14 @@ mmc_decode_cid(int is_sd, uint32_t *raw_ cid->mdt_year = mmc_get_bits(raw_cid, 12, 8) + 2001; cid->mdt_month = mmc_get_bits(raw_cid, 8, 4); } else { - /* XXX write me */ - panic("write mmc cid decoder"); + cid->mid = mmc_get_bits(raw_cid, 120, 8); + cid->oid = mmc_get_bits(raw_cid, 104, 8); + for (i = 0; i < 6; i++) + cid->pnm[i] = mmc_get_bits(raw_cid, 96 - i * 8, 8); + cid->prv = mmc_get_bits(raw_cid, 48, 8); + cid->psn = mmc_get_bits(raw_cid, 16, 32); + cid->mdt_month = mmc_get_bits(raw_cid, 12, 4); + cid->mdt_year = mmc_get_bits(raw_cid, 8, 4) + 1997; } } @@ -563,12 +806,82 @@ mmc_decode_csd(int is_sd, uint32_t *raw_ csd->write_bl_len = 1 << mmc_get_bits(raw_csd, 22, 4); csd->write_bl_partial = mmc_get_bits(raw_csd, 21, 1); } else if (v == 1) { - panic("Write SDHC CSD parser"); + m = mmc_get_bits(raw_csd, 115, 4); + e = mmc_get_bits(raw_csd, 112, 3); + csd->tacc = exp[e] * mant[m] + 9 / 10; + csd->nsac = mmc_get_bits(raw_csd, 104, 8) * 100; + m = mmc_get_bits(raw_csd, 99, 4); + e = mmc_get_bits(raw_csd, 96, 3); + csd->tran_speed = exp[e] * 10000 * mant[m]; + csd->ccc = mmc_get_bits(raw_csd, 84, 12); + csd->read_bl_len = 1 << mmc_get_bits(raw_csd, 80, 4); + csd->read_bl_partial = mmc_get_bits(raw_csd, 79, 1); + csd->write_blk_misalign = mmc_get_bits(raw_csd, 78, 1); + csd->read_blk_misalign = mmc_get_bits(raw_csd, 77, 1); + csd->dsr_imp = mmc_get_bits(raw_csd, 76, 1); + csd->capacity = ((uint64_t)mmc_get_bits(raw_csd, 48, 22) + 1) * + 512 * 1024; + csd->erase_blk_en = mmc_get_bits(raw_csd, 46, 1); + csd->sector_size = mmc_get_bits(raw_csd, 39, 7); + csd->wp_grp_size = mmc_get_bits(raw_csd, 32, 7); + csd->wp_grp_enable = mmc_get_bits(raw_csd, 31, 1); + csd->r2w_factor = 1 << mmc_get_bits(raw_csd, 26, 3); + csd->write_bl_len = 1 << mmc_get_bits(raw_csd, 22, 4); + csd->write_bl_partial = mmc_get_bits(raw_csd, 21, 1); } else panic("unknown SD CSD version"); } else { - panic("Write a MMC CSD parser"); + csd->csd_structure = mmc_get_bits(raw_csd, 126, 2); + csd->spec_vers = mmc_get_bits(raw_csd, 122, 4); + m = mmc_get_bits(raw_csd, 115, 4); + e = mmc_get_bits(raw_csd, 112, 3); + csd->tacc = exp[e] * mant[m] + 9 / 10; + csd->nsac = mmc_get_bits(raw_csd, 104, 8) * 100; + m = mmc_get_bits(raw_csd, 99, 4); + e = mmc_get_bits(raw_csd, 96, 3); + csd->tran_speed = exp[e] * 10000 * mant[m]; + csd->ccc = mmc_get_bits(raw_csd, 84, 12); + csd->read_bl_len = 1 << mmc_get_bits(raw_csd, 80, 4); + csd->read_bl_partial = mmc_get_bits(raw_csd, 79, 1); + csd->write_blk_misalign = mmc_get_bits(raw_csd, 78, 1); + csd->read_blk_misalign = mmc_get_bits(raw_csd, 77, 1); + csd->dsr_imp = mmc_get_bits(raw_csd, 76, 1); + csd->vdd_r_curr_min = cur_min[mmc_get_bits(raw_csd, 59, 3)]; + csd->vdd_r_curr_max = cur_max[mmc_get_bits(raw_csd, 56, 3)]; + csd->vdd_w_curr_min = cur_min[mmc_get_bits(raw_csd, 53, 3)]; + csd->vdd_w_curr_max = cur_max[mmc_get_bits(raw_csd, 50, 3)]; + m = mmc_get_bits(raw_csd, 62, 12); + e = mmc_get_bits(raw_csd, 47, 3); + csd->capacity = ((1 + m) << (e + 2)) * csd->read_bl_len; +// csd->erase_blk_en = mmc_get_bits(raw_csd, 46, 1); +// csd->sector_size = mmc_get_bits(raw_csd, 39, 7); + csd->wp_grp_size = mmc_get_bits(raw_csd, 32, 5); + csd->wp_grp_enable = mmc_get_bits(raw_csd, 31, 1); + csd->r2w_factor = 1 << mmc_get_bits(raw_csd, 26, 3); + csd->write_bl_len = 1 << mmc_get_bits(raw_csd, 22, 4); + csd->write_bl_partial = mmc_get_bits(raw_csd, 21, 1); + } +} + +static void +mmc_app_decode_scr(uint32_t *raw_scr, struct mmc_scr *scr) +{ + unsigned int scr_struct; + uint32_t tmp[4]; + + tmp[3] = raw_scr[1]; + tmp[2] = raw_scr[0]; + + memset(scr, 0, sizeof(*scr)); + + scr_struct = mmc_get_bits(tmp, 60, 4); + if (scr_struct != 0) { + printf("Unrecognised SCR structure version %d\n", + scr_struct); + return; } + scr->sda_vsn = mmc_get_bits(tmp, 56, 4); + scr->bus_widths = mmc_get_bits(tmp, 48, 4); } static int @@ -602,6 +915,70 @@ mmc_send_csd(struct mmc_softc *sc, uint1 } static int +mmc_app_send_scr(struct mmc_softc *sc, uint16_t rca, uint32_t *rawscr) +{ + int err; + struct mmc_command cmd; + struct mmc_data data; + + memset(&cmd, 0, sizeof(struct mmc_command)); + memset(&data, 0, sizeof(struct mmc_data)); + + memset(rawscr, 0, 8); + cmd.opcode = ACMD_SEND_SCR; + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; + cmd.arg = 0; + cmd.data = &data; + + data.data = rawscr; + data.len = 8; + data.flags = MMC_DATA_READ; + + err = mmc_wait_for_app_cmd(sc, rca, &cmd, CMD_RETRIES); + rawscr[0] = be32toh(rawscr[0]); + rawscr[1] = be32toh(rawscr[1]); + return (err); +} + +static int +mmc_send_ext_csd(struct mmc_softc *sc, uint8_t *rawextcsd) +{ + int err; + struct mmc_command cmd; + struct mmc_data data; + + memset(&cmd, 0, sizeof(struct mmc_command)); + memset(&data, 0, sizeof(struct mmc_data)); + + memset(rawextcsd, 0, 512); + cmd.opcode = MMC_SEND_EXT_CSD; + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; + cmd.arg = 0; + cmd.data = &data; + + data.data = rawextcsd; + data.len = 512; + data.flags = MMC_DATA_READ; + + err = mmc_wait_for_cmd(sc, &cmd, CMD_RETRIES); + return (err); +} + +static int +mmc_set_relative_addr(struct mmc_softc *sc, uint16_t resp) +{ + struct mmc_command cmd; + int err; + + cmd.opcode = MMC_SET_RELATIVE_ADDR; + cmd.arg = resp << 16; + cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR; + cmd.data = NULL; + err = mmc_wait_for_cmd(sc, &cmd, 0); + return (err); +} + +static int mmc_send_relative_addr(struct mmc_softc *sc, uint32_t *resp) { struct mmc_command cmd; @@ -623,6 +1000,8 @@ mmc_discover_cards(struct mmc_softc *sc) int err; uint32_t resp; device_t child; + uint16_t rca = 2; + u_char switch_res[64]; while (1) { ivar = malloc(sizeof(struct mmc_ivars), M_DEVBUF, @@ -636,22 +1015,75 @@ mmc_discover_cards(struct mmc_softc *sc) device_printf(sc->dev, "Error reading CID %d\n", err); break; } - if (mmcbr_get_mode(sc->dev) == mode_sd) { - ivar->mode = mode_sd; + if (mmcbr_get_ro(sc->dev)) + ivar->read_only = 1; + ivar->bus_width = bus_width_1; + ivar->mode = mmcbr_get_mode(sc->dev); + if (ivar->mode == mode_sd) { mmc_decode_cid(1, ivar->raw_cid, &ivar->cid); mmc_send_relative_addr(sc, &resp); ivar->rca = resp >> 16; - if (mmcbr_get_ro(sc->dev)) - ivar->read_only = 1; + /* Get card CSD. */ mmc_send_csd(sc, ivar->rca, ivar->raw_csd); mmc_decode_csd(1, ivar->raw_csd, &ivar->csd); - printf("SD CARD: %lld bytes\n", (long long) - ivar->csd.capacity); + if (ivar->csd.csd_structure > 0) + ivar->high_cap = 1; + ivar->tran_speed = ivar->csd.tran_speed; + /* Get card SCR. Card must be selected to fetch it. */ + mmc_select_card(sc, ivar->rca); + mmc_app_send_scr(sc, ivar->rca, ivar->raw_scr); + mmc_app_decode_scr(ivar->raw_scr, &ivar->scr); + /* Get card switch capabilities. */ + if ((ivar->scr.sda_vsn >= 1) && + (ivar->csd.ccc & (1<<10))) { + mmc_sd_switch(sc, 0, 0, 0xF, switch_res); + if (switch_res[13] & 2) { + ivar->timing = bus_timing_hs; + ivar->hs_tran_speed = 50000000; + } + } + mmc_select_card(sc, 0); + /* Find max supported bus width. */ + if ((mmcbr_get_caps(sc->dev) & MMC_CAP_4_BIT_DATA) && + (ivar->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) + ivar->bus_width = bus_width_4; + /* Add device. */ child = device_add_child(sc->dev, NULL, -1); device_set_ivars(child, ivar); return; } - panic("Write MMC card code here"); + mmc_decode_cid(0, ivar->raw_cid, &ivar->cid); + ivar->rca = rca++; + mmc_set_relative_addr(sc, ivar->rca); + /* Get card CSD. */ + mmc_send_csd(sc, ivar->rca, ivar->raw_csd); + mmc_decode_csd(0, ivar->raw_csd, &ivar->csd); + ivar->tran_speed = ivar->csd.tran_speed; + /* Only MMC >= 4.x cards support EXT_CSD. */ + if (ivar->csd.spec_vers >= 4) { + /* Card must be selected to fetch EXT_CSD. */ + mmc_select_card(sc, ivar->rca); + mmc_send_ext_csd(sc, ivar->raw_ext_csd); + /* Get card speed in high speed mode. */ + ivar->timing = bus_timing_hs; + if (((uint8_t *)(ivar->raw_ext_csd))[EXT_CSD_CARD_TYPE] + & EXT_CSD_CARD_TYPE_52) + ivar->hs_tran_speed = 52000000; + else if (((uint8_t *)(ivar->raw_ext_csd))[EXT_CSD_CARD_TYPE] + & EXT_CSD_CARD_TYPE_26) + ivar->hs_tran_speed = 26000000; + else + ivar->hs_tran_speed = ivar->tran_speed; + /* Find max supported bus width. */ + ivar->bus_width = mmc_test_bus_width(sc); + mmc_select_card(sc, 0); + } else { + ivar->bus_width = bus_width_1; + ivar->timing = bus_timing_normal; + } + /* Add device. */ + child = device_add_child(sc->dev, NULL, -1); + device_set_ivars(child, ivar); } free(ivar, M_DEVBUF); } @@ -661,6 +1093,7 @@ mmc_go_discovery(struct mmc_softc *sc) { uint32_t ocr; device_t dev; + int err; dev = sc->dev; if (mmcbr_get_power_mode(dev) != power_on) { @@ -671,7 +1104,9 @@ mmc_go_discovery(struct mmc_softc *sc) mmc_power_up(sc); mmcbr_set_bus_mode(dev, pushpull); mmc_idle_cards(sc); - if (mmc_send_app_op_cond(sc, 0, &ocr) != MMC_ERR_NONE) { + err = mmc_send_if_cond(sc, 1); + if (mmc_send_app_op_cond(sc, err?0:MMC_OCR_CCS, &ocr) != + MMC_ERR_NONE) { /* * Failed, try MMC */ @@ -697,9 +1132,11 @@ mmc_go_discovery(struct mmc_softc *sc) /* * Reselect the cards after we've idled them above. */ - if (mmcbr_get_mode(dev) == mode_sd) - mmc_send_app_op_cond(sc, mmcbr_get_ocr(dev), NULL); - else + if (mmcbr_get_mode(dev) == mode_sd) { + err = mmc_send_if_cond(sc, 1); + mmc_send_app_op_cond(sc, + (err?0:MMC_OCR_CCS)|mmcbr_get_ocr(dev), NULL); + } else mmc_send_op_cond(sc, mmcbr_get_ocr(dev), NULL); mmc_discover_cards(sc); @@ -712,22 +1149,47 @@ mmc_go_discovery(struct mmc_softc *sc) static int mmc_calculate_clock(struct mmc_softc *sc) { - int max_dtr = 0; + int max_dtr, max_hs_dtr, max_timing; int nkid, i, f_min, f_max; device_t *kids; + struct mmc_ivars *ivar; f_min = mmcbr_get_f_min(sc->dev); f_max = mmcbr_get_f_max(sc->dev); - max_dtr = f_max; + max_dtr = max_hs_dtr = f_max; + if ((mmcbr_get_caps(sc->dev) & MMC_CAP_HSPEED)) + max_timing = bus_timing_hs; + else + max_timing = bus_timing_normal; if (device_get_children(sc->dev, &kids, &nkid) != 0) panic("can't get children"); - for (i = 0; i < nkid; i++) - if (mmc_get_tran_speed(kids[i]) < max_dtr) - max_dtr = mmc_get_tran_speed(kids[i]); + for (i = 0; i < nkid; i++) { + ivar = device_get_ivars(kids[i]); + if (ivar->timing < max_timing) + max_timing = ivar->timing; + if (ivar->tran_speed < max_dtr) + max_dtr = ivar->tran_speed; + if (ivar->hs_tran_speed < max_dtr) + max_hs_dtr = ivar->hs_tran_speed; + } + for (i = 0; i < nkid; i++) { + ivar = device_get_ivars(kids[i]); + if (ivar->timing == bus_timing_normal) + continue; + mmc_select_card(sc, ivar->rca); + mmc_set_timing(sc, max_timing); + } + mmc_select_card(sc, 0); free(kids, M_TEMP); - device_printf(sc->dev, "setting transfer rate to %d.%03dMHz\n", - max_dtr / 1000000, (max_dtr / 1000) % 1000); - return (max_dtr); + if (max_timing == bus_timing_hs) + max_dtr = max_hs_dtr; + device_printf(sc->dev, "setting transfer rate to %d.%03dMHz%s\n", + max_dtr / 1000000, (max_dtr / 1000) % 1000, + (max_timing == bus_timing_hs)?" with high speed timing":""); + mmcbr_set_timing(sc->dev, max_timing); + mmcbr_set_clock(sc->dev, max_dtr); + mmcbr_update_ios(sc->dev); + return max_dtr; } static void @@ -741,8 +1203,7 @@ mmc_scan(struct mmc_softc *sc) if (mmcbr_get_power_mode(dev) == power_on) mmc_rescan_cards(sc); mmc_go_discovery(sc); - mmcbr_set_clock(dev, mmc_calculate_clock(sc)); - mmcbr_update_ios(dev); + mmc_calculate_clock(sc); mmc_release_bus(dev, dev); /* XXX probe/attach/detach children? */ @@ -774,6 +1235,9 @@ mmc_read_ivar(device_t bus, device_t chi case MMC_IVAR_READ_ONLY: *(int *)result = ivar->read_only; break; + case MMC_IVAR_HIGH_CAP: + *(int *)result = ivar->high_cap; + break; } return (0); } @@ -824,4 +1288,4 @@ static devclass_t mmc_devclass; DRIVER_MODULE(mmc, at91_mci, mmc_driver, mmc_devclass, 0, 0); -DRIVER_MODULE(mmc, sdh, mmc_driver, mmc_devclass, 0, 0); +DRIVER_MODULE(mmc, sdhci, mmc_driver, mmc_devclass, 0, 0); Modified: user/peter/long_cpumask/sys/dev/mmc/mmcbrvar.h ============================================================================== --- user/peter/long_cpumask/sys/dev/mmc/mmcbrvar.h Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/dev/mmc/mmcbrvar.h Thu Oct 9 01:34:27 2008 (r183713) @@ -71,6 +71,7 @@ enum mmcbr_device_ivars { MMCBR_IVAR_POWER_MODE, MMCBR_IVAR_VDD, MMCBR_IVAR_CAPS, + MMCBR_IVAR_TIMING, // MMCBR_IVAR_, }; @@ -92,6 +93,7 @@ MMCBR_ACCESSOR(ocr, OCR, int) MMCBR_ACCESSOR(power_mode, POWER_MODE, int) MMCBR_ACCESSOR(vdd, VDD, int) MMCBR_ACCESSOR(caps, CAPS, int) +MMCBR_ACCESSOR(timing, TIMING, int) static int __inline mmcbr_update_ios(device_t dev) Modified: user/peter/long_cpumask/sys/dev/mmc/mmcreg.h ============================================================================== --- user/peter/long_cpumask/sys/dev/mmc/mmcreg.h Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/dev/mmc/mmcreg.h Thu Oct 9 01:34:27 2008 (r183713) @@ -86,7 +86,7 @@ struct mmc_command { #define MMC_RSP_R2 (MMC_RSP_PRESENT | MMC_RSP_136 | MMC_RSP_CRC) #define MMC_RSP_R3 (MMC_RSP_PRESENT) #define MMC_RSP_R6 (MMC_RSP_PRESENT | MMC_RSP_CRC) -/* R7 -- new in sd 2.0 */ +#define MMC_RSP_R7 (MMC_RSP_PRESENT | MMC_RSP_CRC) #define MMC_RSP(x) ((x) & MMC_RSP_MASK) uint32_t retries; uint32_t error; @@ -181,16 +181,23 @@ struct mmc_request { #define SD_SEND_RELATIVE_ADDR 3 #define MMC_SET_DSR 4 /* reserved: 5 */ +#define MMC_SWITCH_FUNC 6 +#define MMC_SWITCH_FUNC_CMDS 0 +#define MMC_SWITCH_FUNC_SET 1 +#define MMC_SWITCH_FUNC_CLR 2 +#define MMC_SWITCH_FUNC_WR 3 #define MMC_SELECT_CARD 7 #define MMC_DESELECT_CARD 7 -#define MMC_SEND_IF_COND 8 +#define MMC_SEND_EXT_CSD 8 +#define SD_SEND_IF_COND 8 #define MMC_SEND_CSD 9 #define MMC_SEND_CID 10 #define MMC_READ_DAT_UNTIL_STOP 11 #define MMC_STOP_TRANSMISSION 12 #define MMC_SEND_STATUS 13 - /* reserved: 14 */ +#define MMC_BUSTEST_R 14 #define MMC_GO_INACTIVE_STATE 15 +#define MMC_BUSTEST_W 19 /* Class 2: Block oriented read commands */ #define MMC_SET_BLOCKLEN 16 @@ -277,6 +284,37 @@ struct mmc_request { #define ACMD_SET_CLR_CARD_DETECT 42 #define ACMD_SEND_SCR 51 +/* + * EXT_CSD fields + */ + +#define EXT_CSD_BUS_WIDTH 183 /* R/W */ +#define EXT_CSD_HS_TIMING 185 /* R/W */ +#define EXT_CSD_CARD_TYPE 196 /* RO */ +#define EXT_CSD_REV 192 /* RO */ +#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */ + +/* + * EXT_CSD field definitions + */ + +#define EXT_CSD_CMD_SET_NORMAL 1 +#define EXT_CSD_CMD_SET_SECURE 2 +#define EXT_CSD_CMD_SET_CPSECURE 4 + +#define EXT_CSD_CARD_TYPE_26 1 +#define EXT_CSD_CARD_TYPE_52 2 + +#define EXT_CSD_BUS_WIDTH_1 0 +#define EXT_CSD_BUS_WIDTH_4 1 +#define EXT_CSD_BUS_WIDTH_8 2 + +/* + * SD bus widths + */ +#define SD_BUS_WIDTH_1 0 +#define SD_BUS_WIDTH_4 2 + /* OCR bits */ /* @@ -328,6 +366,7 @@ struct mmc_cid { struct mmc_csd { uint8_t csd_structure; + uint8_t spec_vers; uint16_t ccc; uint16_t tacc; uint32_t nsac; @@ -351,6 +390,14 @@ struct mmc_csd wp_grp_enable:1; }; +struct mmc_scr +{ + unsigned char sda_vsn; + unsigned char bus_widths; +#define SD_SCR_BUS_WIDTH_1 (1<<0) +#define SD_SCR_BUS_WIDTH_4 (1<<2) +}; + /* * Older versions of the MMC standard had a variable sector size. However, * I've been able to find no old MMC or SD cards that have a non 512 Modified: user/peter/long_cpumask/sys/dev/mmc/mmcsd.c ============================================================================== --- user/peter/long_cpumask/sys/dev/mmc/mmcsd.c Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/dev/mmc/mmcsd.c Thu Oct 9 01:34:27 2008 (r183713) @@ -106,6 +106,7 @@ static int mmcsd_probe(device_t dev) { + device_quiet(dev); device_set_desc(dev, "MMC/SD Memory Card"); return (0); } @@ -256,7 +257,9 @@ mmcsd_task(void *arg) else cmd.opcode = MMC_WRITE_BLOCK; } - cmd.arg = block << 9; + cmd.arg = block; + if (!mmc_get_high_cap(dev)) + cmd.arg <<= 9; cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; data.data = vaddr; data.mrq = &req; Modified: user/peter/long_cpumask/sys/dev/mmc/mmcvar.h ============================================================================== --- user/peter/long_cpumask/sys/dev/mmc/mmcvar.h Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/dev/mmc/mmcvar.h Thu Oct 9 01:34:27 2008 (r183713) @@ -62,6 +62,7 @@ enum mmc_device_ivars { MMC_IVAR_SECTOR_SIZE, MMC_IVAR_TRAN_SPEED, MMC_IVAR_READ_ONLY, + MMC_IVAR_HIGH_CAP, // MMC_IVAR_, }; @@ -77,5 +78,6 @@ MMC_ACCESSOR(rca, RCA, int) MMC_ACCESSOR(sector_size, SECTOR_SIZE, int) MMC_ACCESSOR(tran_speed, TRAN_SPEED, int) MMC_ACCESSOR(read_only, READ_ONLY, int) +MMC_ACCESSOR(high_cap, HIGH_CAP, int) #endif /* DEV_MMC_MMCVAR_H */ Modified: user/peter/long_cpumask/sys/dev/sio/sio.c ============================================================================== --- user/peter/long_cpumask/sys/dev/sio/sio.c Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/dev/sio/sio.c Thu Oct 9 01:34:27 2008 (r183713) @@ -696,6 +696,14 @@ sioprobe(dev, xrid, rclk, noprobe) bus_release_resource(dev, SYS_RES_IOPORT, rid, port); if (iobase == siocniobase) result = 0; + /* + * XXX: Since we don't return 0, we shouldn't be relying on + * the softc that we set to persist to the call to attach + * since other probe routines may be called, and the malloc + * here causes subr_bus to not allocate anything for the + * other probes. Instead, this softc is preserved and other + * probe routines can corrupt it. + */ if (result != 0) { device_set_softc(dev, NULL); free(com, M_DEVBUF); @@ -773,6 +781,13 @@ sioprobe(dev, xrid, rclk, noprobe) bus_release_resource(dev, SYS_RES_IOPORT, rid, port); if (iobase == siocniobase) result = 0; + /* + * XXX: Since we don't return 0, we shouldn't be relying on the softc + * that we set to persist to the call to attach since other probe + * routines may be called, and the malloc here causes subr_bus to not + * allocate anything for the other probes. Instead, this softc is + * preserved and other probe routines can corrupt it. + */ if (result != 0) { device_set_softc(dev, NULL); free(com, M_DEVBUF); Modified: user/peter/long_cpumask/sys/dev/usb/umass.c ============================================================================== --- user/peter/long_cpumask/sys/dev/usb/umass.c Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/dev/usb/umass.c Thu Oct 9 01:34:27 2008 (r183713) @@ -610,6 +610,10 @@ static struct umass_devdescr_t umass_dev UMASS_PROTO_SCSI, NO_QUIRKS }, + { USB_VENDOR_ONSPEC, USB_PRODUCT_ONSPEC_SDS_HOTFIND_D, RID_WILDCARD, + UMASS_PROTO_SCSI | UMASS_PROTO_BBB, + NO_GETMAXLUN | NO_SYNCHRONIZE_CACHE + }, { USB_VENDOR_ONSPEC, USB_PRODUCT_ONSPEC_MDCFE_B_CF_READER, RID_WILDCARD, UMASS_PROTO_SCSI, NO_QUIRKS Modified: user/peter/long_cpumask/sys/dev/usb/usbdevs ============================================================================== --- user/peter/long_cpumask/sys/dev/usb/usbdevs Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/dev/usb/usbdevs Thu Oct 9 01:34:27 2008 (r183713) @@ -1855,6 +1855,7 @@ product OMNIVISION OV511 0x0511 OV511 Ca product OMNIVISION OV511PLUS 0xa511 OV511+ Camera /* OnSpec Electronic, Inc. */ +product ONSPEC SDS_HOTFIND_D 0x0400 SDS-infrared.com Hotfind-D Infrared Camera product ONSPEC MDCFE_B_CF_READER 0xa000 MDCFE-B USB CF Reader product ONSPEC CFMS_RW 0xa001 SIIG/Datafab Memory Stick+CF Reader/Writer product ONSPEC READER 0xa003 Datafab-based Reader Modified: user/peter/long_cpumask/sys/kern/imgact_elf.c ============================================================================== --- user/peter/long_cpumask/sys/kern/imgact_elf.c Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/kern/imgact_elf.c Thu Oct 9 01:34:27 2008 (r183713) @@ -813,7 +813,8 @@ __CONCAT(exec_, __elfN(imgact))(struct i if (!have_interp && newinterp != NULL) { error = __elfN(load_file)(imgp->proc, newinterp, &addr, &imgp->entry_addr, sv->sv_pagesize); - have_interp = TRUE; + if (error == 0) + have_interp = TRUE; } if (!have_interp) { error = __elfN(load_file)(imgp->proc, interp, &addr, Modified: user/peter/long_cpumask/sys/kern/uipc_usrreq.c ============================================================================== --- user/peter/long_cpumask/sys/kern/uipc_usrreq.c Wed Oct 8 21:46:17 2008 (r183712) +++ user/peter/long_cpumask/sys/kern/uipc_usrreq.c Thu Oct 9 01:34:27 2008 (r183713) @@ -249,20 +249,20 @@ static struct mbuf *unp_addsockcred(stru * Definitions of protocols supported in the LOCAL domain. */ static struct domain localdomain; -static struct pr_usrreqs uipc_usrreqs; +static struct pr_usrreqs uipc_usrreqs_dgram, uipc_usrreqs_stream; static struct protosw localsw[] = { { .pr_type = SOCK_STREAM, .pr_domain = &localdomain, .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, .pr_ctloutput = &uipc_ctloutput, - .pr_usrreqs = &uipc_usrreqs + .pr_usrreqs = &uipc_usrreqs_stream }, { .pr_type = SOCK_DGRAM, .pr_domain = &localdomain, .pr_flags = PR_ATOMIC|PR_ADDR|PR_RIGHTS, - .pr_usrreqs = &uipc_usrreqs + .pr_usrreqs = &uipc_usrreqs_dgram }, }; @@ -996,7 +996,7 @@ uipc_sockaddr(struct socket *so, struct return (0); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Thu Oct 9 04:38:38 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 08E821065687; Thu, 9 Oct 2008 04:38:38 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D52138FC15; Thu, 9 Oct 2008 04:38:37 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m994cbGJ051903; Thu, 9 Oct 2008 04:38:37 GMT (envelope-from peter@svn.freebsd.org) Received: (from peter@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m994cb8F051902; Thu, 9 Oct 2008 04:38:37 GMT (envelope-from peter@svn.freebsd.org) Message-Id: <200810090438.m994cb8F051902@svn.freebsd.org> From: Peter Wemm Date: Thu, 9 Oct 2008 04:38:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183715 - user/peter/long_cpumask/sys X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Oct 2008 04:38:38 -0000 Author: peter Date: Thu Oct 9 04:38:37 2008 New Revision: 183715 URL: http://svn.freebsd.org/changeset/base/183715 Log: Merge 183713 through 183714 Modified: user/peter/long_cpumask/sys/ (props changed) From owner-svn-src-user@FreeBSD.ORG Thu Oct 9 05:11:27 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D4C35106568E; Thu, 9 Oct 2008 05:11:27 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AD0398FC13; Thu, 9 Oct 2008 05:11:27 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m995BREN052556; Thu, 9 Oct 2008 05:11:27 GMT (envelope-from peter@svn.freebsd.org) Received: (from peter@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m995BRO5052555; Thu, 9 Oct 2008 05:11:27 GMT (envelope-from peter@svn.freebsd.org) Message-Id: <200810090511.m995BRO5052555@svn.freebsd.org> From: Peter Wemm Date: Thu, 9 Oct 2008 05:11:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183716 - user/peter/long_cpumask/sys X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Oct 2008 05:11:27 -0000 Author: peter Date: Thu Oct 9 05:11:27 2008 New Revision: 183716 URL: http://svn.freebsd.org/changeset/base/183716 Log: Another test merge. Sorry for the spam. Modified: user/peter/long_cpumask/sys/ (props changed) From owner-svn-src-user@FreeBSD.ORG Thu Oct 9 10:01:09 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6DF241065686; Thu, 9 Oct 2008 10:01:09 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5BE8A8FC1B; Thu, 9 Oct 2008 10:01:09 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m99A19BO057648; Thu, 9 Oct 2008 10:01:09 GMT (envelope-from peter@svn.freebsd.org) Received: (from peter@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m99A19KW057647; Thu, 9 Oct 2008 10:01:09 GMT (envelope-from peter@svn.freebsd.org) Message-Id: <200810091001.m99A19KW057647@svn.freebsd.org> From: Peter Wemm Date: Thu, 9 Oct 2008 10:01:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183719 - user X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Oct 2008 10:01:09 -0000 Author: peter Date: Thu Oct 9 10:01:09 2008 New Revision: 183719 URL: http://svn.freebsd.org/changeset/base/183719 Log: Add a quick braindump about the state of /user and /projects Added: user/GUIDELINES.txt (contents, props changed) Added: user/GUIDELINES.txt ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/GUIDELINES.txt Thu Oct 9 10:01:09 2008 (r183719) @@ -0,0 +1,95 @@ +$FreeBSD$ + +Golden rules: +Rule #1: TAKE IT EASY! DON'T RUSH AND MAKE A MESS! ASK IF NEEDED! +Rule #2: See rule #1, repeat as needed + +Peril sensitive sunglasses advisory: +This is in flux. Expect refinement. + +Guidelines for what can go in /user and /projects +------------------------------------------------- + +First of all, eveyrbody needs to keep in mind that this repository is +replicated as a unit. Anything that goes into the repository uses project +and volunteer resources. Once something goes in, it essentially never comes +out. Therefore, these are not dumping grounds to put random junk in the +tree that we have to mirror forever. + +General guidelines: + +* Should be relevant to FreeBSD. +* Should be at least concievably of interest to somebody else. +* Should be in a format that is suitable to merge into the base tree. +* Should be something that is worth people's time to read commit mail for. +* Write decent commit messages! + + +The difference between /projects and /user is mostly one of intentions. + +If some WIP is intended to be committed to the main src tree, then it +should go in /projects/$name/*. We encourage people to subscribe to projects +commit messages. The reason is that WIP in projects can be expected to hit +the base tree at some point. + +If some WIP is more of an experiment or speculative, that might not ever be +merged, then it goes in /user/$username/$name/*. We don't encourage +people to subscribe to user commit messages. + +If it is something unrelated to the src tree, it should probably go elsewhere. +There will be a separate repostory made available for such things, whether it +be a special version of mysql or xorg or gcc or whatever. + + +Layout: +Since this is for WIP that can concievably be merged, there is an argument +that can be made that teaching the pre-commit scripts to sanity check WIP +as it goes, rather than having a mammoth fixup being needed prior to merging. + +For that to work, the layout has to be predictable. eg: a branch of +"head/sys/*" for a project called "ia65" should be /projects/ia65/sys/*. +An experimental X11-aware verison of bin/ls/* in a user directory for jdoe +would be /user/jdoe/x11-ls/bin/ls/*. + + +Creation and merging: + +Merging is in flux. The procedure as understood right now: + +Assue projects/ia65/sys. $BASE="svn+ssh://svn.freebsd.org/base" + +Initial creation: + $ svn cp --parents $BASE/head/sys $BASE/projects/ia65/sys + +Then check it out: + $ svn co $BASE/projects/ia65 + +To integrate changes from head into your branch: + $ cd ia65 ; svn update; svn status | read output! Should preferably be clean. + (you may prefer to do merges in a second, clean checkout. It will be easier!) + $ svn merge $BASE/head/sys + (this merges head/sys/* into ., which is projects/ia65/sys) + $ svn commit + +To merge your changes into head/sys. + $ mail -s 'Is it ok to merge projects/ia65 to head?' peter@freebsd.org + $ wait_for_reply + (set up a clean checkout of head/sys and projects/ia65/sys. MUST BE CLEAN!!) + $ cd work + $ svn co $BASE/head/sys + $ svn co $BASE/projects/ia65/sys + $ svn info head - NOTE CHANGE NUMBER!!! assume 12345 for this example. + (now, bring projects/ia65 up to date with head, AS YOU JUST CHECKED IT OUT) + $ svn merge $BASE/head/sys@12345 projects/ia65/sys + (resolve conflicts) + $ svn commit projects/ia65/sys + (now, projects/ia65 is in sync with @12345, as is your head checkout) + (reverse merge to base tree!) + $ svn merge $BASE/projects/ia65/sys head/sys + (resolve conflicts) + $ svn commit head/sys + $ profit! + +Tags: + Place tags in your /user area if possible, even if the origin is a project. + Tag by using svn cp $BASE/projects/xxx $BASE/user/jdoe/yyy. From owner-svn-src-user@FreeBSD.ORG Thu Oct 9 10:13:33 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 973431065697; Thu, 9 Oct 2008 10:13:33 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 858698FC1E; Thu, 9 Oct 2008 10:13:33 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m99ADXCh057931; Thu, 9 Oct 2008 10:13:33 GMT (envelope-from peter@svn.freebsd.org) Received: (from peter@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m99ADXCv057930; Thu, 9 Oct 2008 10:13:33 GMT (envelope-from peter@svn.freebsd.org) Message-Id: <200810091013.m99ADXCv057930@svn.freebsd.org> From: Peter Wemm Date: Thu, 9 Oct 2008 10:13:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183721 - user X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Oct 2008 10:13:33 -0000 Author: peter Date: Thu Oct 9 10:13:33 2008 New Revision: 183721 URL: http://svn.freebsd.org/changeset/base/183721 Log: Update typos. clarify some failed attempts at humour at 3am. Note that merge --reintegrate gets confused by the complexity of our tree. Modified: user/GUIDELINES.txt Modified: user/GUIDELINES.txt ============================================================================== --- user/GUIDELINES.txt Thu Oct 9 10:02:16 2008 (r183720) +++ user/GUIDELINES.txt Thu Oct 9 10:13:33 2008 (r183721) @@ -5,7 +5,7 @@ Rule #1: TAKE IT EASY! DON'T RUSH AND M Rule #2: See rule #1, repeat as needed Peril sensitive sunglasses advisory: -This is in flux. Expect refinement. +This is in flux. Expect refinement. Expect typos. Guidelines for what can go in /user and /projects ------------------------------------------------- @@ -56,7 +56,7 @@ Creation and merging: Merging is in flux. The procedure as understood right now: -Assue projects/ia65/sys. $BASE="svn+ssh://svn.freebsd.org/base" +Assume projects/ia65/sys. $BASE="svn+ssh://svn.freebsd.org/base" Initial creation: $ svn cp --parents $BASE/head/sys $BASE/projects/ia65/sys @@ -73,11 +73,14 @@ To integrate changes from head into your To merge your changes into head/sys. $ mail -s 'Is it ok to merge projects/ia65 to head?' peter@freebsd.org - $ wait_for_reply + $ wait_for_reply (the point is to have somebody on hand for the first + timeto help rescue you if things go horribly wrong.) (set up a clean checkout of head/sys and projects/ia65/sys. MUST BE CLEAN!!) $ cd work $ svn co $BASE/head/sys $ svn co $BASE/projects/ia65/sys + (If you've already got clean checkouts handy, replace with appropriate + svn update commands) $ svn info head - NOTE CHANGE NUMBER!!! assume 12345 for this example. (now, bring projects/ia65 up to date with head, AS YOU JUST CHECKED IT OUT) $ svn merge $BASE/head/sys@12345 projects/ia65/sys @@ -89,6 +92,8 @@ To merge your changes into head/sys. (resolve conflicts) $ svn commit head/sys $ profit! + (regular svn users might wonder about merge --reintegrate. Our tree breaks + it, sorry. We can't use it.) Tags: Place tags in your /user area if possible, even if the origin is a project. From owner-svn-src-user@FreeBSD.ORG Fri Oct 10 17:37:20 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8390D1065689; Fri, 10 Oct 2008 17:37:20 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5DF9D8FC15; Fri, 10 Oct 2008 17:37:20 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9AHbKmB096811; Fri, 10 Oct 2008 17:37:20 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9AHbKI1096810; Fri, 10 Oct 2008 17:37:20 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <200810101737.m9AHbKI1096810@svn.freebsd.org> From: Rui Paulo Date: Fri, 10 Oct 2008 17:37:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183745 - user/rpaulo X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Oct 2008 17:37:20 -0000 Author: rpaulo Date: Fri Oct 10 17:37:20 2008 New Revision: 183745 URL: http://svn.freebsd.org/changeset/base/183745 Log: Add my user dir. Added: user/rpaulo/ From owner-svn-src-user@FreeBSD.ORG Fri Oct 10 17:41:34 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9256F1065688; Fri, 10 Oct 2008 17:41:34 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 842598FC0A; Fri, 10 Oct 2008 17:41:34 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9AHfYj3096935; Fri, 10 Oct 2008 17:41:34 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9AHfYgJ096932; Fri, 10 Oct 2008 17:41:34 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <200810101741.m9AHfYgJ096932@svn.freebsd.org> From: Rui Paulo Date: Fri, 10 Oct 2008 17:41:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183746 - user/rpaulo/aird X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Oct 2008 17:41:34 -0000 Author: rpaulo Date: Fri Oct 10 17:41:34 2008 New Revision: 183746 URL: http://svn.freebsd.org/changeset/base/183746 Log: Apple IR daemon. Makes the Apple remote functional under FreeBSD. Imported from P4. Added: user/rpaulo/aird/ user/rpaulo/aird/Makefile (contents, props changed) user/rpaulo/aird/aird.1 (contents, props changed) user/rpaulo/aird/aird.c (contents, props changed) Added: user/rpaulo/aird/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/rpaulo/aird/Makefile Fri Oct 10 17:41:34 2008 (r183746) @@ -0,0 +1,10 @@ +# $P4: //depot/user/rpaulo/aird/Makefile#1 $ + +PROG= aird +MAN= aird.1 +WARNS?= 6 + +DPADD= ${LIBUTIL} +LDADD= -lutil + +.include Added: user/rpaulo/aird/aird.1 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/rpaulo/aird/aird.1 Fri Oct 10 17:41:34 2008 (r183746) @@ -0,0 +1,180 @@ +.\" +.\" Copyright (c) 2007 Rui Paulo +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $P4: //depot/user/rpaulo/aird/aird.1#1 $ +.\" +.Dd July 30, 2007 +.Dt AIRD 1 +.Sh NAME +.Nm aird +.Nd "USB Apple IR receiver daemon" +.Sh SYNOPSIS +.Nm +.Op Fl vd +.Op Fl p Ar pidfile +.Op Fl k Ar key +.Fl f Ar device +.Op Fl M Ar menu command +.Op Fl P Ar play command +.Op Fl F Ar forward command +.Op Fl B Ar backward command +.Op Fl U Ar volume up command +.Op Fl D Ar volume down command +.Sh DESCRIPTION +The +.Nm +daemon handles Apple IR receiver button events. +If your system has an USB Apple IR receiver, most likely you'll also +have an Apple Remote. +An Apple remote has six (6) buttons: Volume up, Volume down, +Play/Pause, Forward, Backward and Menu. +For each button you can assign a command to execute. +.Pp +Apple IR receiver modules are found on: +.Pp +.Bl -bullet -offset indent -compact +.It +MacBook (any generation) +.It +MacBook Pro (any generation) +.It +Intel iMac +.It +Intel MacMini +.El +.Pp +The following program options are available: +.Bl -tag -width indent +.It Fl v +Enable verbose mode. +.It Fl d +Toggles the daemon flag. +.It Fl p Ar pidfile +Use the specified file to store the process ID. +.It Fl f Ar device +Read from the specified device entry. This is mandatory. +.It Fl k Ar key +Only accept commands from the remote with the specified +.Pa key . +See the +.Sx EXAMPLES +section to understand how remote pairing works. +.El +.Pp +The following options specify commands to run upon button down +events: +.Bl -tag -width indent +.It Fl M Ar menu command +Command to run when the daemon recieves a notification that the +.Em Menu +button was pressed. +.It Fl P Ar play command +Command to run when the daemon recieves a notification that the +.Em Play/Pause +button was pressed. +.It Fl F Ar forward command +Command to run when the daemon recieves a notification that the +.Em Forward +button was pressed. +.It Fl B Ar backward command +Command to run when the daemon recieves a notification that the +.Em Backward +button was pressed. +.It Fl U Ar volume up command +Command to run when the daemon recieves a notification that the +.Em Volume Up +button was pressed. +.It Fl D Ar volume down command +Command to run when the daemon recieves a notification that the +.Em Volume Down +button was pressed. +.El +.Pp +Note that lower case options are program options and upper case +options specify the commands to run upon button down events. +.Sh FILES +.Bl -tag -width indent +.It Pa /var/run/aird.pid +The default location of the PID file. +.El +.Sh EXAMPLES +To pair a remote controller with your IR receiver, do the following: +.Bd -literal -offset indent +aird -f /dev/uhid1 -k 0 +.Ed +.Pp +Then press the +.Pa Menu +and +.Pa Forward +keys at the same time for five seconds. The following will show up: +.Bd -literal -offset indent +Your Apple remote pairing key is: 131 +Next time you run aird, pass this number as the -k argument. +.Ed +.Pp +This example shows how to control +.Xr mpd 1 +with +.Xr aird 1 . +You need +.Xr mpc 1 +and +.Xr ncmpc 1 +installed. +Run +.Xr aird 1 +from your +.Pa ~/.xinitrc +startup file like this: +.Bd -literal -offset indent +aird -p ~/.aird.pid -f /dev/uhid1 -P "mpc toggle" -F "mpc next" \\ + -B "mpc prev" -U "mixer vol +2" -D "mixer vol -2" \\ + -M "xterm -e ncmpc" +.Ed +.Pp +If you want to stop other users from gaining control of the IR receiver +and to prevent commands to be executed when someone presses a button +on the remote control, run +.Xr aird 1 +only with the +.Fl f +argument: +.Bd -literal -offset indent +aird -f /dev/uhid1 +.Ed +.Sh SEE ALSO +.Xr mpd 1 Pq Pa ports/audio/musicpd , +.Xr mpc 1 Pq Pa ports/audio/mpc , +.Xr ncmpc 1 Pq Pa ports/audio/ncmpc , +.Xr uhid 4 , +.Xr usb 4 +.Sh HISTORY +The +.Nm +utility first appeared in +.Fx 8.0 . +.Sh AUTHORS +.An Rui Paulo Aq rpaulo@FreeBSD.org Added: user/rpaulo/aird/aird.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/rpaulo/aird/aird.c Fri Oct 10 17:41:34 2008 (r183746) @@ -0,0 +1,317 @@ +/*- + * Copyright (c) 2007 Rui Paulo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $P4: //depot/user/rpaulo/aird/aird.c#1 $ + * + */ + +/* + * aird - a deamon to interact with an USB Apple IR receiver. + * Runs commands for each key pressed. + * + * This daemon reads an uhid(4) device 6 bytes each time. + * For example, when the user presses the volume up, the read buffer will + * contain: + * 0x25 0x87 0xee 0x[any] 0x0a/0x0b + * 0x[any] means that there can be any value in that byte (as it's remote + * controller dependent). The last byte is also hardware dependent. + * + * When I key is repeated the read will return: + * 0x26 0x00 0x00 0x00 0x00 + * + * For flat batteries we only check the value of the third byte (0xe0) and + * send a syslog warning. + * + * All the magic numbers came from the Linux appleir driver (now integrated + * into LIRC). + * + */ + +#if 0 +#include +__FBSDID("$FreeBSD$"); +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include + +static struct pidfh *pfh; + +static void sighandler(int sig); +static void usage(void); +static void runcmd(const char *cmd, int fd); + + +static void +sighandler(__unused int sig) +{ + + if (pfh) + pidfile_remove(pfh); + + exit(EXIT_SUCCESS); +} + +static void +usage(void) +{ + fprintf(stderr, "usage: %s [-vd] [-p pidfile] -f device " + "[-M menu command]\n\t[-P play command] [-F forward command] " + "[-B backward command]\n\t[-U volume up command] " + "[-D volume down command]\n", getprogname()); + + exit(1); +} + +static void +runcmd(const char *cmd, int fd) +{ + int r; + + if (fork() == 0) { + close(fd); + signal(SIGCHLD, SIG_DFL); + r = system(cmd); + _exit(r); + } +} + +int +main(int argc, char *argv[]) +{ + int fd; + int inpair; + int repeating; + char ch; + unsigned char buf[5]; + unsigned char prevbuf[5]; + int foreground; + int verbose; + char *cmd_menu, *cmd_play, *cmd_forward, *cmd_backward, + *cmd_volup, *cmd_voldown; + pid_t otherpid; + const char *pidfile; + const char *deventry; + unsigned char key; + + pfh = NULL; + + signal(SIGHUP, sighandler); + signal(SIGINT, sighandler); + signal(SIGCHLD, SIG_IGN); + + deventry = NULL; + foreground = 0; + verbose = 0; + repeating = 0; + cmd_menu = NULL; + cmd_play = NULL; + cmd_forward = NULL; + cmd_backward = NULL; + cmd_volup = NULL; + cmd_voldown = NULL; + pidfile = "/var/run/aird.pid"; + key = 0; + inpair = 0; + + while ((ch = getopt(argc, argv, "f:dvk:p:M:P:F:B:U:D:?")) != -1) + switch (ch) { + case 'f': + deventry = optarg; + break; + case 'd': + foreground = 1; + break; + case 'v': + verbose = 1; + break; + case 'k': + key = atoi(optarg); + if (key == 0) { + foreground = 1; + inpair = 1; + } + break; + case 'M': + cmd_menu = optarg; + break; + case 'P': + cmd_play = optarg; + break; + case 'F': + cmd_forward = optarg; + break; + case 'B': + cmd_backward = optarg; + break; + case 'U': + cmd_volup = optarg; + break; + case 'D': + cmd_voldown = optarg; + break; + case 'p': + pidfile = optarg; + break; + case '?': + default: + usage(); + /* NOTREACHED */ + } + argc -= optind; + argv += optind; + + if (!deventry) + usage(); + + fd = open(deventry, O_RDONLY); + if (fd < 0) + err(EXIT_FAILURE, "open %s", deventry); + + if (!foreground) { + pfh = pidfile_open(pidfile, 0600, &otherpid); + if (pfh == NULL) { + if (errno == EEXIST) { + errx(EXIT_FAILURE, + "Daemon already running, pid: %jd.", + (intmax_t)otherpid); + } + /* If we cannot create pidfile from other reasons, + only warn. */ + warn("Cannot open or create pidfile"); + } + + if (daemon(0, 0) < 0) { + pidfile_remove(pfh); + err(EXIT_FAILURE, "daemon"); + } + pidfile_write(pfh); + } + + memset(prevbuf, 0, sizeof(prevbuf)); + while (read(fd, &buf, sizeof(buf)) >= 0) { + if (verbose) + fprintf(stderr, "%x %x %x %x %x\n", buf[0], buf[1], + buf[2], buf[3], buf[4]); + + /* + * Handle pairing. + */ + if (inpair && buf[2] == 0xe0) { + fprintf(stderr, "Your Apple remote pairing key is: " + "%d\n" + "Next time you run aird, pass this number as the " + "-k argument.\n", buf[3]); + exit(EXIT_SUCCESS); + } + + if (key && buf[3] != key) + continue; + + /* + * Check for key repeats. + */ + if (buf[0] == 0x26) + repeating++; + else { + memcpy(prevbuf, buf, sizeof(prevbuf)); + repeating = 0; + } + + /* + * The controller can generate repeating key codes + * very fast and this makes a lot of users upset. + * + * This check makes the program only consider repeats + * if the key has been pressed for actually 1 second. + */ + if (repeating >= 5) { + if (verbose) + fprintf(stderr, "repeating key: %x %x %x %x " + "%x\n", prevbuf[0], prevbuf[1], + prevbuf[2], prevbuf[3], prevbuf[4]); + + memcpy(buf, prevbuf, sizeof(buf)); + repeating = 0; + } + + switch (buf[4]) { + /* Menu */ + case 0x02: + case 0x03: + runcmd(cmd_menu, fd); + break; + /* Play/Pause */ + case 0x04: + case 0x05: + runcmd(cmd_play, fd); + break; + /* Forward */ + case 0x06: + case 0x07: + runcmd(cmd_forward ,fd); + break; + /* Backward */ + case 0x08: + case 0x09: + runcmd(cmd_backward, fd); + break; + /* Volume Up */ + case 0x0a: + case 0x0b: + runcmd(cmd_volup, fd); + break; + /* Volume Down */ + case 0x0c: + case 0x0d: + runcmd(cmd_voldown, fd); + break; + + } + + } + pidfile_remove(pfh); + close(fd); + + return (0); +} From owner-svn-src-user@FreeBSD.ORG Fri Oct 10 17:43:22 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4D6281065687; Fri, 10 Oct 2008 17:43:22 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3F1568FC19; Fri, 10 Oct 2008 17:43:22 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9AHhM09097007; Fri, 10 Oct 2008 17:43:22 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9AHhMD2097003; Fri, 10 Oct 2008 17:43:22 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <200810101743.m9AHhMD2097003@svn.freebsd.org> From: Rui Paulo Date: Fri, 10 Oct 2008 17:43:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183747 - user/rpaulo/ubthidctl X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Oct 2008 17:43:22 -0000 Author: rpaulo Date: Fri Oct 10 17:43:21 2008 New Revision: 183747 URL: http://svn.freebsd.org/changeset/base/183747 Log: USB Bluetooth HID<->HCI control utility. Changes a USB dongle from HID mode to Bluetooth HCI mode. Imported from P4. Added: user/rpaulo/ubthidctl/ user/rpaulo/ubthidctl/Makefile (contents, props changed) user/rpaulo/ubthidctl/ubthidctl.1 (contents, props changed) user/rpaulo/ubthidctl/ubthidctl.c (contents, props changed) user/rpaulo/ubthidctl/ubthidtbl Added: user/rpaulo/ubthidctl/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/rpaulo/ubthidctl/Makefile Fri Oct 10 17:43:21 2008 (r183747) @@ -0,0 +1,6 @@ +# $FreeBSD$ + +PROG= ubthidctl +WARNS?= 6 + +.include Added: user/rpaulo/ubthidctl/ubthidctl.1 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/rpaulo/ubthidctl/ubthidctl.1 Fri Oct 10 17:43:21 2008 (r183747) @@ -0,0 +1,93 @@ +.\" +.\" Copyright (c) 2007 Rui Paulo +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd July 30, 2007 +.Dt UBTHIDCTL 1 +.Sh NAME +.Nm ubthidctl +.Nd "Bluetooth USB HID-HCI proxy switcher" +.Sh SYNOPSIS +.Nm +.Fl f Ar device +.Fl a Ar addr +.Op Fl m Ar mode +.Nm +.Fl t Ar tablefile +.Sh DESCRIPTION +The +.Nm +utility changes Bluetooth controllers from HID (Human Interface Device) +to HCI (Host Controller Interface) and vice-versa. +HCI is the interface used by Bluetooth devices and HID is the interface +used by some USB devices. The device will reattach every time you switch +modes. +.Pp +Some Bluetooth controllers present themselves to the BIOS as +an +.Xr uhid 4 +device. +This is done so that the user can use a Bluetooth keyboard and a Bluetooth +mouse with BIOS implementations that already support USB. +After the operating system boots, it's the system administrator's +responsibility to switch the device to HCI mode. +.Pp +This utility supports two modes of operation. +In the first one you run the utility with the exact location of the +device (device entry, address and an optional mode). +In the other mode, the utility reads a filename with several vendors +and product identifiers. If your system has a device listed in +.Pa tablefile +it will be switched to the appropriate mode automatically. +.Sh FILES +.Bl -tag -width indent +.It Pa /usr/share/misc/ubthidtbl +The location of the table file. +.El +.Sh EXAMPLES +First mode of operation: +.Bd -literal -offset indent +ubthidctl -f /dev/usb3 -a 2 +.Ed +.Pp +Second mode of operation: +.Bd -literal -offset indent +ubthidctl -t /usr/share/misc/ubthidtbl +.Ed +.Sh SEE ALSO +.Xr ng_ubt 4 , +.Xr uhid 4 , +.Xr usb 4 +.Sh HISTORY +The +.Nm +utility first appeared in +.Fx 8.0 . +.Pp +It was based on the hid2hci utility for Linux written by +.An Marcel Holtmann Aq marcel@holtmann.org +.Sh AUTHORS +.An Rui Paulo Aq rpaulo@fnop.net Added: user/rpaulo/ubthidctl/ubthidctl.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/rpaulo/ubthidctl/ubthidctl.c Fri Oct 10 17:43:21 2008 (r183747) @@ -0,0 +1,249 @@ +/*- + * Copyright (c) 2007 Rui Paulo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + * + */ + +/* + * Based on bluez-utils hid2hci tool written by + * Marcel Holtmann + */ + +#include +#ifdef __FreeBSD__ +__FBSDID("$FreeBSD$"); +#endif + +#include +#include +#include +#include +#include +#include + +#include + +#include + +typedef enum { + HCI = 0, + HID = 1 +} hidmode_t; + +typedef struct { + hidmode_t mode; + uint16_t vendor; + uint16_t product; +} tblentry_t; + +typedef struct { + int devno; + int devaddr; +} devinfo_t; + + +static void switchmode(const char *dev, const int devaddr, hidmode_t mode); + + +static devinfo_t +finddevice(tblentry_t tblentry) +{ + struct usb_device_info usbdev; + char filename[16]; + devinfo_t dev; + int i; + int j; + int fd; + + dev.devno = -1; + + for (i = 0; i < 20; i++) { + snprintf(filename, sizeof(filename) - 1, "/dev/usb%d", i); + fd = open(filename, O_RDONLY); + if (fd < 0) + return dev; + + for (j = USB_START_ADDR; j < USB_MAX_DEVICES; j++) { + memset(&usbdev, 0, sizeof(usbdev)); + usbdev.udi_addr = j; + ioctl(fd, USB_DEVICEINFO, &usbdev); + if (tblentry.vendor == usbdev.udi_vendorNo && + tblentry.product == usbdev.udi_productNo) { + dev.devno = i; + dev.devaddr = j; + close(fd); + + return dev; + } + } + + close(fd); + } + + return dev; +} + +static void +parsetable(const char *filename) +{ + FILE *fp; + tblentry_t tblentry; + unsigned int vendor; + unsigned int product; + char modestr[4]; + devinfo_t dev; + char usbname[16]; + char buf[1024]; + char *p; + + fp = fopen(filename, "r"); + if (!fp) + err(1, "fopen %s", filename); + + while (!feof(fp)) { + fgets(buf, sizeof(buf) - 1, fp); + for (p = buf; *p == ' '; p++); + if (*p == '#' || *p == '\n') + continue; + + sscanf(p, "%3s 0x%x 0x%x\n", modestr, &vendor, &product); + + tblentry.vendor = vendor; + tblentry.product = product; + + if (!strncmp(modestr, "HCI", 3)) + tblentry.mode = HCI; + else if (!strncmp(modestr, "HID", 3)) + tblentry.mode = HID; + else { + warnx("invalid mode: %s", modestr); + continue; + } + dev = finddevice(tblentry); + if (dev.devno != -1) { + snprintf(usbname, sizeof(usbname) - 1, "/dev/usb%d", + dev.devno); + switchmode(usbname, dev.devaddr, tblentry.mode); + } + + } + + fclose(fp); + +} + +static void +switchmode(const char *dev, const int devaddr, hidmode_t mode) +{ + int fd; + struct usb_ctl_request req; + + fd = open(dev, O_RDWR, 0); + if (fd < 0) + err(1, "open %s", dev); + + memset(&req, 0, sizeof(req)); + req.ucr_addr = devaddr; + USETW(req.ucr_request.wValue, mode); + USETW(req.ucr_request.wIndex, 0); + USETW(req.ucr_request.wLength, 0); + req.ucr_data = NULL; + req.ucr_flags = USBD_SHORT_XFER_OK; + req.ucr_request.bmRequestType = UT_VENDOR; + req.ucr_request.bRequest = 0; + + ioctl(fd, USB_REQUEST, &req); + + /* + * The return value of ioctl() will always be EIO, so it's up + * to the user to check whether the device was switched sucessfuly. + */ + + close(fd); +} + +static void +usage(void) +{ + fprintf(stderr, "usage:\t%s -f device -a addr [-m mode]\n" + "\t%s -t tablefile\n", getprogname(), getprogname()); + + exit(1); +} + +int +main(int argc, char *argv[]) +{ + char ch; + char *dev; + char *tablefile; + int devaddr; + int mode; + + dev = NULL; + devaddr = -1; + mode = HCI; + tablefile = NULL; + + while ((ch = getopt(argc, argv, "f:m:a:t:?")) != -1) + switch (ch) { + case 'f': + dev = optarg; + break; + case 'm': + mode = atoi(optarg); + if (mode < 0 || mode > 1) + usage(); + break; + case 'a': + devaddr = atoi(optarg); + if (devaddr < 0) + usage(); + break; + case 't': + tablefile = optarg; + break; + case '?': + default: + usage(); + /* NOTREACHED */ + } + + argc -= optind; + argv += optind; + + if (tablefile) { + parsetable(tablefile); + return 0; + } + + if (dev == NULL || devaddr == -1) + usage(); + + switchmode(dev, devaddr, mode); + + return 0; +} Added: user/rpaulo/ubthidctl/ubthidtbl ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/rpaulo/ubthidctl/ubthidtbl Fri Oct 10 17:43:21 2008 (r183747) @@ -0,0 +1,15 @@ +# +# $FreeBSD$ +# +# The following table lists the devices that ubthidctl(1) should switch +# from HID to HCI and vice versa. +# + +# Apple +HID 0x05ac 0x1000 + +# Cambridge Silicon Radio +HID 0x0a12 0x1000 + +# KYE Systems +HID 0x0458 0x1000 From owner-svn-src-user@FreeBSD.ORG Fri Oct 10 17:47:06 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1089A106568A; Fri, 10 Oct 2008 17:47:06 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 03FFC8FC15; Fri, 10 Oct 2008 17:47:06 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9AHl5kk097119; Fri, 10 Oct 2008 17:47:05 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9AHl5gf097116; Fri, 10 Oct 2008 17:47:05 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <200810101747.m9AHl5gf097116@svn.freebsd.org> From: Rui Paulo Date: Fri, 10 Oct 2008 17:47:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183748 - user/rpaulo/aird X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Oct 2008 17:47:06 -0000 Author: rpaulo Date: Fri Oct 10 17:47:05 2008 New Revision: 183748 URL: http://svn.freebsd.org/changeset/base/183748 Log: Replace P4 tags by FreeBSD SVN tag. Modified: user/rpaulo/aird/Makefile user/rpaulo/aird/aird.1 user/rpaulo/aird/aird.c Modified: user/rpaulo/aird/Makefile ============================================================================== --- user/rpaulo/aird/Makefile Fri Oct 10 17:43:21 2008 (r183747) +++ user/rpaulo/aird/Makefile Fri Oct 10 17:47:05 2008 (r183748) @@ -1,4 +1,4 @@ -# $P4: //depot/user/rpaulo/aird/Makefile#1 $ +# $FreeBSD$ PROG= aird MAN= aird.1 Modified: user/rpaulo/aird/aird.1 ============================================================================== --- user/rpaulo/aird/aird.1 Fri Oct 10 17:43:21 2008 (r183747) +++ user/rpaulo/aird/aird.1 Fri Oct 10 17:47:05 2008 (r183748) @@ -23,7 +23,7 @@ .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.\" $P4: //depot/user/rpaulo/aird/aird.1#1 $ +.\" $FreeBSD$ .\" .Dd July 30, 2007 .Dt AIRD 1 Modified: user/rpaulo/aird/aird.c ============================================================================== --- user/rpaulo/aird/aird.c Fri Oct 10 17:43:21 2008 (r183747) +++ user/rpaulo/aird/aird.c Fri Oct 10 17:47:05 2008 (r183748) @@ -23,7 +23,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/user/rpaulo/aird/aird.c#1 $ + * $FreeBSD$ * */ From owner-svn-src-user@FreeBSD.ORG Fri Oct 10 17:48:40 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2226B10656CC; Fri, 10 Oct 2008 17:48:40 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 15A338FC1F; Fri, 10 Oct 2008 17:48:40 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9AHmdBN097183; Fri, 10 Oct 2008 17:48:39 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9AHmdMZ097181; Fri, 10 Oct 2008 17:48:39 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <200810101748.m9AHmdMZ097181@svn.freebsd.org> From: Rui Paulo Date: Fri, 10 Oct 2008 17:48:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183749 - user/rpaulo/ubthidctl X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Oct 2008 17:48:40 -0000 Author: rpaulo Date: Fri Oct 10 17:48:39 2008 New Revision: 183749 URL: http://svn.freebsd.org/changeset/base/183749 Log: Prefer my FreeBSD.org alias. Modified: user/rpaulo/ubthidctl/ubthidctl.1 user/rpaulo/ubthidctl/ubthidctl.c Modified: user/rpaulo/ubthidctl/ubthidctl.1 ============================================================================== --- user/rpaulo/ubthidctl/ubthidctl.1 Fri Oct 10 17:47:05 2008 (r183748) +++ user/rpaulo/ubthidctl/ubthidctl.1 Fri Oct 10 17:48:39 2008 (r183749) @@ -1,5 +1,5 @@ .\" -.\" Copyright (c) 2007 Rui Paulo +.\" Copyright (c) 2007 Rui Paulo .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without Modified: user/rpaulo/ubthidctl/ubthidctl.c ============================================================================== --- user/rpaulo/ubthidctl/ubthidctl.c Fri Oct 10 17:47:05 2008 (r183748) +++ user/rpaulo/ubthidctl/ubthidctl.c Fri Oct 10 17:48:39 2008 (r183749) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2007 Rui Paulo + * Copyright (c) 2007 Rui Paulo * All rights reserved. * * Redistribution and use in source and binary forms, with or without From owner-svn-src-user@FreeBSD.ORG Fri Oct 10 17:53:27 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 03CA5106568E; Fri, 10 Oct 2008 17:53:27 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EA9ED8FC12; Fri, 10 Oct 2008 17:53:26 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9AHrQD5097336; Fri, 10 Oct 2008 17:53:26 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9AHrQJU097333; Fri, 10 Oct 2008 17:53:26 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <200810101753.m9AHrQJU097333@svn.freebsd.org> From: Rui Paulo Date: Fri, 10 Oct 2008 17:53:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183751 - user/rpaulo/eeemon X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Oct 2008 17:53:27 -0000 Author: rpaulo Date: Fri Oct 10 17:53:26 2008 New Revision: 183751 URL: http://svn.freebsd.org/changeset/base/183751 Log: eeemon is a kernel module for Asus Eee notebooks that allows you to control the fan speed, high/low voltage and it shows the cpu temperature. Includes fan control code by "harrow@yandex.ru". Imported from my peronal repo. Added: user/rpaulo/eeemon/ user/rpaulo/eeemon/Makefile (contents, props changed) user/rpaulo/eeemon/eeemon.c (contents, props changed) user/rpaulo/eeemon/eeemonreg.h (contents, props changed) Added: user/rpaulo/eeemon/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/rpaulo/eeemon/Makefile Fri Oct 10 17:53:26 2008 (r183751) @@ -0,0 +1,6 @@ +# $FreeBSD$ + +KMOD= eeemon +SRCS= eeemon.c isa_if.h bus_if.h device_if.h + +.include Added: user/rpaulo/eeemon/eeemon.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/rpaulo/eeemon/eeemon.c Fri Oct 10 17:53:26 2008 (r183751) @@ -0,0 +1,305 @@ +/*- + * Copyright (c) 2008 Rui Paulo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "eeemonreg.h" + +enum { + EEEMON_TEMP, + EEEMON_FAN, + EEEMON_VOLT, + EEEMON_FANMANUAL, + EEEMON_FANSPEED +}; + +/* + * Device interface. + */ +static void eeemon_identify(driver_t *driver, device_t parent); +static int eeemon_probe(device_t dev); +static int eeemon_attach(device_t dev); +static int eeemon_detach(device_t dev); +static void eeemon_intrhook(void *arg); +static int eeemon_match(void); +static int eeemon_readbyte(uint16_t addr); +static void eeemon_writebyte(uint16_t addr, uint8_t byte); +static int eeemon_sysctl(SYSCTL_HANDLER_ARGS); + +struct eeemon_softc { + device_t sc_dev; + struct sysctl_oid *sc_sctl_cputemp; + struct sysctl_oid *sc_sctl_cpufan; + struct intr_config_hook sc_ich; +}; + +/* + * Driver methods. + */ +static device_method_t eeemon_methods[] = { + DEVMETHOD(device_identify, eeemon_identify), + DEVMETHOD(device_probe, eeemon_probe), + DEVMETHOD(device_attach, eeemon_attach), + DEVMETHOD(device_detach, eeemon_detach), + + { 0, 0 } +}; + +static driver_t eeemon_driver = { + "eeemon", + eeemon_methods, + sizeof(struct eeemon_softc) +}; + +static devclass_t eeemon_devclass; + +DRIVER_MODULE(eeemon, isa, eeemon_driver, eeemon_devclass, 0, 0); + +static int +eeemon_match(void) +{ + int i; + char *model; + + model = getenv("smbios.system.serial"); + i = 0; + if (strncmp(model, "EeePC", 5) == 0) + i = 1; + freeenv(model); + + return (i); +} + +static void +eeemon_identify(driver_t *driver, device_t parent) +{ + device_t child; + + if (device_find_child(parent, "eeemon", -1) != NULL) + return; + + if (eeemon_match() == 0) + return; + + child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "eeemon", -1); + if (child == NULL) + device_printf(parent, "add eeemon child failed\n"); + +} + +static int +eeemon_probe(device_t dev) +{ + if (resource_disabled("eeemon", 0)) + return (ENXIO); + + if (eeemon_match() == 0) { + device_printf(dev, "model not recognized\n"); + return (ENXIO); + } + device_set_desc(dev, "Asus Eee PC Hardware Monitor"); + + return (BUS_PROBE_DEFAULT); +} + +static int +eeemon_attach(device_t dev) +{ + struct eeemon_softc *sc; + + sc = device_get_softc(dev); + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "voltage", CTLTYPE_INT | CTLFLAG_RW, + sc, EEEMON_VOLT, eeemon_sysctl, "I", + "Voltage (V)"); + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "fan_manual", CTLTYPE_INT | CTLFLAG_RW, + sc, EEEMON_FANMANUAL, eeemon_sysctl, "I", + "Fan Manual"); + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "fan_speed", CTLTYPE_INT | CTLFLAG_RW, + sc, EEEMON_FANSPEED, eeemon_sysctl, "I", + "Fan Speed (%)"); + + sc->sc_ich.ich_func = eeemon_intrhook; + sc->sc_ich.ich_arg = sc; + config_intrhook_establish(&sc->sc_ich); + + return (0); +} + +static int +eeemon_detach(device_t dev) +{ + struct eeemon_softc *sc; + + sc = device_get_softc(dev); + sysctl_remove_oid(sc->sc_sctl_cputemp, 1, 0); + sysctl_remove_oid(sc->sc_sctl_cpufan, 1, 0); + + return (0); +} + +static void +eeemon_intrhook(void *arg) +{ + device_t nexus, acpi, cpu; + struct sysctl_ctx_list *sysctlctx; + struct eeemon_softc *sc; + + sc = arg; + + /* + * dev.cpu.0.temperature and dev.cpu.0.fan + */ + nexus = device_find_child(root_bus, "nexus", 0); + acpi = device_find_child(nexus, "acpi", 0); + cpu = device_find_child(acpi, "cpu", 0); + if (cpu) { + sysctlctx = device_get_sysctl_ctx(cpu); + sc->sc_sctl_cputemp = SYSCTL_ADD_PROC(sysctlctx, + SYSCTL_CHILDREN(device_get_sysctl_tree(cpu)), + OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD, + sc, EEEMON_TEMP, eeemon_sysctl, "I", + "CPU temperature (degC)"); + sc->sc_sctl_cpufan = SYSCTL_ADD_PROC(sysctlctx, + SYSCTL_CHILDREN(device_get_sysctl_tree(cpu)), + OID_AUTO, "fan", CTLTYPE_INT | CTLFLAG_RD, + sc, EEEMON_FAN, eeemon_sysctl, "I", + "CPU Fan speed (RPM)"); + } + config_intrhook_disestablish(&sc->sc_ich); +} + +static int +eeemon_readbyte(uint16_t addr) +{ + int d; + + outb(EEEMON_ADDRH, (addr & 0xff00) >> 8); + outb(EEEMON_ADDRL, addr & 0x00ff); + d = inb(EEEMON_DATA); + + return (d); +} + +static void +eeemon_writebyte(uint16_t addr, uint8_t byte) +{ + outb(EEEMON_ADDRH, (addr & 0xff00) >> 8); + outb(EEEMON_ADDRL, addr & 0x00ff); + outb(EEEMON_DATA, byte); +} + +static int +eeemon_sysctl(SYSCTL_HANDLER_ARGS) +{ + int value; + unsigned short port; + unsigned char mask; + int pin; + int error; + + switch (arg2) { + case EEEMON_TEMP: + value = eeemon_readbyte(EEEMON_TEMPVAL); + break; + case EEEMON_FAN: + value = (eeemon_readbyte(EEEMON_FANHVAL) << 8) + | eeemon_readbyte(EEEMON_FANLVAL); + break; + case EEEMON_FANMANUAL: + value = (eeemon_readbyte(EEEMON_FANMANUALVAL) & 0x02) ? 1 : 0; + break; + case EEEMON_FANSPEED: + value = eeemon_readbyte(EEEMON_FANSPEEDVAL); + break; + case EEEMON_VOLT: + pin = 0x66; + port = 0xfc20 + ((pin >> 3) & 0x1f); + mask = 1 << (pin & 0x07); + value = (eeemon_readbyte(port) & mask) ? 1 : 0; + } + + + error = sysctl_handle_int(oidp, &value, 0, req); + if (error || !req->newptr) + return (error); + + switch (arg2) { + case EEEMON_FANSPEED: + if (value > 100 || value < 0) + return (EINVAL); + eeemon_writebyte(EEEMON_FANSPEEDVAL, value); + break; + case EEEMON_FANMANUAL: + if (value > 1 || value < 0) + return (EINVAL); + if (value) { + // SF25=1: Prevent the EC from controlling the fan. + eeemon_writebyte(EEEMON_FANMANUALVAL, eeemon_readbyte(EEEMON_FANMANUALVAL) | 0x02); + } else + // SF25=0: Allow the EC to control the fan. + eeemon_writebyte(EEEMON_FANMANUALVAL, eeemon_readbyte(EEEMON_FANMANUALVAL) & ~0x02); + break; + case EEEMON_VOLT: + if (value > 1 || value < 0) + return (EINVAL); + pin = 0x66; + port = 0xfc20 + ((pin >> 3) & 0x1f); + mask = 1 << (pin & 0x07); + if (value) { + eeemon_writebyte(port, eeemon_readbyte(port) | mask); + } else + eeemon_writebyte(port, eeemon_readbyte(port) & ~mask); + } + + return (0); +} Added: user/rpaulo/eeemon/eeemonreg.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/rpaulo/eeemon/eeemonreg.h Fri Oct 10 17:53:26 2008 (r183751) @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2008 Rui Paulo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + + +/* + * Port addresses. + */ +#define EEEMON_ADDRH 0x381 +#define EEEMON_ADDRL 0x382 +#define EEEMON_DATA 0x383 + +/* + * Values writable to the EC port. + */ + +#define EEEMON_TEMPVAL 0xf451 /* Temperature of CPU (C) */ +#define EEEMON_FANSPEEDVAL 0xf463 /* Fan PWM duty cycle (%) */ +#define EEEMON_FANHVAL 0xf466 /* High byte of fan speed (RPM) */ +#define EEEMON_FANLVAL 0xf467 /* Low byte of fan speed (RPM) */ +#define EEEMON_FANMANUALVAL 0xf4d3 /* Flag byte containing SF25 (FANctrl) */ From owner-svn-src-user@FreeBSD.ORG Sat Oct 11 01:40:21 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 553B2106568E; Sat, 11 Oct 2008 01:40:21 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1754F8FC12; Sat, 11 Oct 2008 01:40:21 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9B1eKWn005743; Sat, 11 Oct 2008 01:40:20 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9B1eKHd005742; Sat, 11 Oct 2008 01:40:20 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200810110140.m9B1eKHd005742@svn.freebsd.org> From: Kip Macy Date: Sat, 11 Oct 2008 01:40:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183756 - user/kmacy X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Oct 2008 01:40:21 -0000 Author: kmacy Date: Sat Oct 11 01:40:20 2008 New Revision: 183756 URL: http://svn.freebsd.org/changeset/base/183756 Log: Create user directory for personal projects Added: user/kmacy/ From owner-svn-src-user@FreeBSD.ORG Sat Oct 11 20:48:54 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1EC23106568A; Sat, 11 Oct 2008 20:48:54 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EA2038FC1E; Sat, 11 Oct 2008 20:48:53 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9BKmrkP026559; Sat, 11 Oct 2008 20:48:53 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9BKmrbK026558; Sat, 11 Oct 2008 20:48:53 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <200810112048.m9BKmrbK026558@svn.freebsd.org> From: Edwin Groothuis Date: Sat, 11 Oct 2008 20:48:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183766 - user/edwin X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Oct 2008 20:48:54 -0000 Author: edwin Date: Sat Oct 11 20:48:53 2008 New Revision: 183766 URL: http://svn.freebsd.org/changeset/base/183766 Log: Add my own user directory for my own projects - FreeBSD related. Added: user/edwin/ From owner-svn-src-user@FreeBSD.ORG Sat Oct 11 21:33:52 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 44D6D1065690; Sat, 11 Oct 2008 21:33:52 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 18C658FC08; Sat, 11 Oct 2008 21:33:52 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9BLXpd4027676; Sat, 11 Oct 2008 21:33:51 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9BLXpNH027675; Sat, 11 Oct 2008 21:33:51 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <200810112133.m9BLXpNH027675@svn.freebsd.org> From: Edwin Groothuis Date: Sat, 11 Oct 2008 21:33:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183767 - user/edwin/top-3.8b1 X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Oct 2008 21:33:52 -0000 Author: edwin Date: Sat Oct 11 21:33:51 2008 New Revision: 183767 URL: http://svn.freebsd.org/changeset/base/183767 Log: Create working directory for top-3.8b1 update. Added: user/edwin/top-3.8b1/ From owner-svn-src-user@FreeBSD.ORG Sat Oct 11 21:58:37 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 238C6106568C; Sat, 11 Oct 2008 21:58:37 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EADBE8FC17; Sat, 11 Oct 2008 21:58:36 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9BLwat0028137; Sat, 11 Oct 2008 21:58:36 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9BLwaoR028136; Sat, 11 Oct 2008 21:58:36 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <200810112158.m9BLwaoR028136@svn.freebsd.org> From: Edwin Groothuis Date: Sat, 11 Oct 2008 21:58:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183768 - in user/edwin/top-3.8b1/usr.bin: . top X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Oct 2008 21:58:37 -0000 Author: edwin Date: Sat Oct 11 21:58:36 2008 New Revision: 183768 URL: http://svn.freebsd.org/changeset/base/183768 Log: Initial creation of top-3.8b1/usr.bin/top Added: user/edwin/top-3.8b1/usr.bin/ user/edwin/top-3.8b1/usr.bin/top/ - copied from r183767, head/usr.bin/top/ From owner-svn-src-user@FreeBSD.ORG Sat Oct 11 21:59:03 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8865B1065694; Sat, 11 Oct 2008 21:59:03 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5BD9B8FC26; Sat, 11 Oct 2008 21:59:03 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9BLx3nu028184; Sat, 11 Oct 2008 21:59:03 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9BLx3gG028183; Sat, 11 Oct 2008 21:59:03 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <200810112159.m9BLx3gG028183@svn.freebsd.org> From: Edwin Groothuis Date: Sat, 11 Oct 2008 21:59:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r183769 - in user/edwin/top-3.8b1/contrib: . top X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Oct 2008 21:59:03 -0000 Author: edwin Date: Sat Oct 11 21:59:03 2008 New Revision: 183769 URL: http://svn.freebsd.org/changeset/base/183769 Log: Initial creation of top-3.8b1/contrib/top Added: user/edwin/top-3.8b1/contrib/ user/edwin/top-3.8b1/contrib/top/ (props changed) - copied from r183768, head/contrib/top/