code_text
stringlengths
604
999k
repo_name
stringlengths
4
100
file_path
stringlengths
4
873
language
stringclasses
23 values
license
stringclasses
15 values
size
int32
1.02k
999k
/* ir-sony-decoder.c - handle Sony IR Pulse/Space protocol * * Copyright (C) 2010 by David Härdeman <david@hardeman.nu> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <linux/bitrev.h> #include "rc-core-priv.h" #define SONY_UNIT 600000 /* ns */ #define SONY_HEADER_PULSE (4 * SONY_UNIT) #define SONY_HEADER_SPACE (1 * SONY_UNIT) #define SONY_BIT_0_PULSE (1 * SONY_UNIT) #define SONY_BIT_1_PULSE (2 * SONY_UNIT) #define SONY_BIT_SPACE (1 * SONY_UNIT) #define SONY_TRAILER_SPACE (10 * SONY_UNIT) /* minimum */ enum sony_state { STATE_INACTIVE, STATE_HEADER_SPACE, STATE_BIT_PULSE, STATE_BIT_SPACE, STATE_FINISHED, }; /** * ir_sony_decode() - Decode one Sony pulse or space * @dev: the struct rc_dev descriptor of the device * @ev: the struct ir_raw_event descriptor of the pulse/space * * This function returns -EINVAL if the pulse violates the state machine */ static int ir_sony_decode(struct rc_dev *dev, struct ir_raw_event ev) { struct sony_dec *data = &dev->raw->sony; u32 scancode; u8 device, subdevice, function; if (!(dev->raw->enabled_protocols & RC_TYPE_SONY)) return 0; if (!is_timing_event(ev)) { if (ev.reset) data->state = STATE_INACTIVE; return 0; } if (!geq_margin(ev.duration, SONY_UNIT, SONY_UNIT / 2)) goto out; IR_dprintk(2, "Sony decode started at state %d (%uus %s)\n", data->state, TO_US(ev.duration), TO_STR(ev.pulse)); switch (data->state) { case STATE_INACTIVE: if (!ev.pulse) break; if (!eq_margin(ev.duration, SONY_HEADER_PULSE, SONY_UNIT / 2)) break; data->count = 0; data->state = STATE_HEADER_SPACE; return 0; case STATE_HEADER_SPACE: if (ev.pulse) break; if (!eq_margin(ev.duration, SONY_HEADER_SPACE, SONY_UNIT / 2)) break; data->state = STATE_BIT_PULSE; return 0; case STATE_BIT_PULSE: if (!ev.pulse) break; data->bits <<= 1; if (eq_margin(ev.duration, SONY_BIT_1_PULSE, SONY_UNIT / 2)) data->bits |= 1; else if (!eq_margin(ev.duration, SONY_BIT_0_PULSE, SONY_UNIT / 2)) break; data->count++; data->state = STATE_BIT_SPACE; return 0; case STATE_BIT_SPACE: if (ev.pulse) break; if (!geq_margin(ev.duration, SONY_BIT_SPACE, SONY_UNIT / 2)) break; decrease_duration(&ev, SONY_BIT_SPACE); if (!geq_margin(ev.duration, SONY_UNIT, SONY_UNIT / 2)) { data->state = STATE_BIT_PULSE; return 0; } data->state = STATE_FINISHED; /* Fall through */ case STATE_FINISHED: if (ev.pulse) break; if (!geq_margin(ev.duration, SONY_TRAILER_SPACE, SONY_UNIT / 2)) break; switch (data->count) { case 12: device = bitrev8((data->bits << 3) & 0xF8); subdevice = 0; function = bitrev8((data->bits >> 4) & 0xFE); break; case 15: device = bitrev8((data->bits >> 0) & 0xFF); subdevice = 0; function = bitrev8((data->bits >> 7) & 0xFD); break; case 20: device = bitrev8((data->bits >> 5) & 0xF8); subdevice = bitrev8((data->bits >> 0) & 0xFF); function = bitrev8((data->bits >> 12) & 0xFE); break; default: IR_dprintk(1, "Sony invalid bitcount %u\n", data->count); goto out; } scancode = device << 16 | subdevice << 8 | function; IR_dprintk(1, "Sony(%u) scancode 0x%05x\n", data->count, scancode); rc_keydown(dev, scancode, 0); data->state = STATE_INACTIVE; return 0; } out: IR_dprintk(1, "Sony decode failed at state %d (%uus %s)\n", data->state, TO_US(ev.duration), TO_STR(ev.pulse)); data->state = STATE_INACTIVE; return -EINVAL; } static struct ir_raw_handler sony_handler = { .protocols = RC_TYPE_SONY, .decode = ir_sony_decode, }; static int __init ir_sony_decode_init(void) { ir_raw_handler_register(&sony_handler); printk(KERN_INFO "IR Sony protocol handler initialized\n"); return 0; } static void __exit ir_sony_decode_exit(void) { ir_raw_handler_unregister(&sony_handler); } module_init(ir_sony_decode_init); module_exit(ir_sony_decode_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("David Härdeman <david@hardeman.nu>"); MODULE_DESCRIPTION("Sony IR protocol decoder");
dlandoll/android_kernel_omap
drivers/media/rc/ir-sony-decoder.c
C
gpl-2.0
4,476
/* * User address space access functions. * The non-inlined parts of asm-metag/uaccess.h are here. * * Copyright (C) 2006, Imagination Technologies. * Copyright (C) 2000, Axis Communications AB. * * Written by Hans-Peter Nilsson. * Pieces used from memcpy, originally by Kenny Ranerup long time ago. * Modified for Meta by Will Newton. */ #include <linux/export.h> #include <linux/uaccess.h> #include <asm/cache.h> /* def of L1_CACHE_BYTES */ #define USE_RAPF #define RAPF_MIN_BUF_SIZE (3*L1_CACHE_BYTES) /* The "double write" in this code is because the Meta will not fault * immediately unless the memory pipe is forced to by e.g. a data stall or * another memory op. The second write should be discarded by the write * combiner so should have virtually no cost. */ #define __asm_copy_user_cont(to, from, ret, COPY, FIXUP, TENTRY) \ asm volatile ( \ COPY \ "1:\n" \ " .section .fixup,\"ax\"\n" \ " MOV D1Ar1,#0\n" \ FIXUP \ " MOVT D1Ar1,#HI(1b)\n" \ " JUMP D1Ar1,#LO(1b)\n" \ " .previous\n" \ " .section __ex_table,\"a\"\n" \ TENTRY \ " .previous\n" \ : "=r" (to), "=r" (from), "=r" (ret) \ : "0" (to), "1" (from), "2" (ret) \ : "D1Ar1", "memory") #define __asm_copy_to_user_1(to, from, ret) \ __asm_copy_user_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ " SETB [%0],D1Ar1\n" \ "2: SETB [%0++],D1Ar1\n", \ "3: ADD %2,%2,#1\n", \ " .long 2b,3b\n") #define __asm_copy_to_user_2x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_user_cont(to, from, ret, \ " GETW D1Ar1,[%1++]\n" \ " SETW [%0],D1Ar1\n" \ "2: SETW [%0++],D1Ar1\n" COPY, \ "3: ADD %2,%2,#2\n" FIXUP, \ " .long 2b,3b\n" TENTRY) #define __asm_copy_to_user_2(to, from, ret) \ __asm_copy_to_user_2x_cont(to, from, ret, "", "", "") #define __asm_copy_to_user_3(to, from, ret) \ __asm_copy_to_user_2x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ " SETB [%0],D1Ar1\n" \ "4: SETB [%0++],D1Ar1\n", \ "5: ADD %2,%2,#1\n", \ " .long 4b,5b\n") #define __asm_copy_to_user_4x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_user_cont(to, from, ret, \ " GETD D1Ar1,[%1++]\n" \ " SETD [%0],D1Ar1\n" \ "2: SETD [%0++],D1Ar1\n" COPY, \ "3: ADD %2,%2,#4\n" FIXUP, \ " .long 2b,3b\n" TENTRY) #define __asm_copy_to_user_4(to, from, ret) \ __asm_copy_to_user_4x_cont(to, from, ret, "", "", "") #define __asm_copy_to_user_5(to, from, ret) \ __asm_copy_to_user_4x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ " SETB [%0],D1Ar1\n" \ "4: SETB [%0++],D1Ar1\n", \ "5: ADD %2,%2,#1\n", \ " .long 4b,5b\n") #define __asm_copy_to_user_6x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_to_user_4x_cont(to, from, ret, \ " GETW D1Ar1,[%1++]\n" \ " SETW [%0],D1Ar1\n" \ "4: SETW [%0++],D1Ar1\n" COPY, \ "5: ADD %2,%2,#2\n" FIXUP, \ " .long 4b,5b\n" TENTRY) #define __asm_copy_to_user_6(to, from, ret) \ __asm_copy_to_user_6x_cont(to, from, ret, "", "", "") #define __asm_copy_to_user_7(to, from, ret) \ __asm_copy_to_user_6x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ " SETB [%0],D1Ar1\n" \ "6: SETB [%0++],D1Ar1\n", \ "7: ADD %2,%2,#1\n", \ " .long 6b,7b\n") #define __asm_copy_to_user_8x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_to_user_4x_cont(to, from, ret, \ " GETD D1Ar1,[%1++]\n" \ " SETD [%0],D1Ar1\n" \ "4: SETD [%0++],D1Ar1\n" COPY, \ "5: ADD %2,%2,#4\n" FIXUP, \ " .long 4b,5b\n" TENTRY) #define __asm_copy_to_user_8(to, from, ret) \ __asm_copy_to_user_8x_cont(to, from, ret, "", "", "") #define __asm_copy_to_user_9(to, from, ret) \ __asm_copy_to_user_8x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ " SETB [%0],D1Ar1\n" \ "6: SETB [%0++],D1Ar1\n", \ "7: ADD %2,%2,#1\n", \ " .long 6b,7b\n") #define __asm_copy_to_user_10x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_to_user_8x_cont(to, from, ret, \ " GETW D1Ar1,[%1++]\n" \ " SETW [%0],D1Ar1\n" \ "6: SETW [%0++],D1Ar1\n" COPY, \ "7: ADD %2,%2,#2\n" FIXUP, \ " .long 6b,7b\n" TENTRY) #define __asm_copy_to_user_10(to, from, ret) \ __asm_copy_to_user_10x_cont(to, from, ret, "", "", "") #define __asm_copy_to_user_11(to, from, ret) \ __asm_copy_to_user_10x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ " SETB [%0],D1Ar1\n" \ "8: SETB [%0++],D1Ar1\n", \ "9: ADD %2,%2,#1\n", \ " .long 8b,9b\n") #define __asm_copy_to_user_12x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_to_user_8x_cont(to, from, ret, \ " GETD D1Ar1,[%1++]\n" \ " SETD [%0],D1Ar1\n" \ "6: SETD [%0++],D1Ar1\n" COPY, \ "7: ADD %2,%2,#4\n" FIXUP, \ " .long 6b,7b\n" TENTRY) #define __asm_copy_to_user_12(to, from, ret) \ __asm_copy_to_user_12x_cont(to, from, ret, "", "", "") #define __asm_copy_to_user_13(to, from, ret) \ __asm_copy_to_user_12x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ " SETB [%0],D1Ar1\n" \ "8: SETB [%0++],D1Ar1\n", \ "9: ADD %2,%2,#1\n", \ " .long 8b,9b\n") #define __asm_copy_to_user_14x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_to_user_12x_cont(to, from, ret, \ " GETW D1Ar1,[%1++]\n" \ " SETW [%0],D1Ar1\n" \ "8: SETW [%0++],D1Ar1\n" COPY, \ "9: ADD %2,%2,#2\n" FIXUP, \ " .long 8b,9b\n" TENTRY) #define __asm_copy_to_user_14(to, from, ret) \ __asm_copy_to_user_14x_cont(to, from, ret, "", "", "") #define __asm_copy_to_user_15(to, from, ret) \ __asm_copy_to_user_14x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ " SETB [%0],D1Ar1\n" \ "10: SETB [%0++],D1Ar1\n", \ "11: ADD %2,%2,#1\n", \ " .long 10b,11b\n") #define __asm_copy_to_user_16x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_to_user_12x_cont(to, from, ret, \ " GETD D1Ar1,[%1++]\n" \ " SETD [%0],D1Ar1\n" \ "8: SETD [%0++],D1Ar1\n" COPY, \ "9: ADD %2,%2,#4\n" FIXUP, \ " .long 8b,9b\n" TENTRY) #define __asm_copy_to_user_16(to, from, ret) \ __asm_copy_to_user_16x_cont(to, from, ret, "", "", "") #define __asm_copy_to_user_8x64(to, from, ret) \ asm volatile ( \ " GETL D0Ar2,D1Ar1,[%1++]\n" \ " SETL [%0],D0Ar2,D1Ar1\n" \ "2: SETL [%0++],D0Ar2,D1Ar1\n" \ "1:\n" \ " .section .fixup,\"ax\"\n" \ "3: ADD %2,%2,#8\n" \ " MOVT D0Ar2,#HI(1b)\n" \ " JUMP D0Ar2,#LO(1b)\n" \ " .previous\n" \ " .section __ex_table,\"a\"\n" \ " .long 2b,3b\n" \ " .previous\n" \ : "=r" (to), "=r" (from), "=r" (ret) \ : "0" (to), "1" (from), "2" (ret) \ : "D1Ar1", "D0Ar2", "memory") /* * optimized copying loop using RAPF when 64 bit aligned * * n will be automatically decremented inside the loop * ret will be left intact. if error occurs we will rewind * so that the original non optimized code will fill up * this value correctly. * * on fault: * > n will hold total number of uncopied bytes * * > {'to','from'} will be rewind back so that * the non-optimized code will do the proper fix up * * DCACHE drops the cacheline which helps in reducing cache * pollution. * * We introduce an extra SETL at the end of the loop to * ensure we don't fall off the loop before we catch all * erros. * * NOTICE: * LSM_STEP in TXSTATUS must be cleared in fix up code. * since we're using M{S,G}ETL, a fault might happen at * any address in the middle of M{S,G}ETL causing * the value of LSM_STEP to be incorrect which can * cause subsequent use of M{S,G}ET{L,D} to go wrong. * ie: if LSM_STEP was 1 when a fault occurs, the * next call to M{S,G}ET{L,D} will skip the first * copy/getting as it think that the first 1 has already * been done. * */ #define __asm_copy_user_64bit_rapf_loop( \ to, from, ret, n, id, FIXUP) \ asm volatile ( \ ".balign 8\n" \ "MOV RAPF, %1\n" \ "MSETL [A0StP++], D0Ar6, D0FrT, D0.5, D0.6, D0.7\n" \ "MOV D0Ar6, #0\n" \ "LSR D1Ar5, %3, #6\n" \ "SUB TXRPT, D1Ar5, #2\n" \ "MOV RAPF, %1\n" \ "$Lloop"id":\n" \ "ADD RAPF, %1, #64\n" \ "21:\n" \ "MGETL D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "22:\n" \ "MSETL [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %3, %3, #32\n" \ "23:\n" \ "MGETL D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "24:\n" \ "MSETL [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %3, %3, #32\n" \ "DCACHE [%1+#-64], D0Ar6\n" \ "BR $Lloop"id"\n" \ \ "MOV RAPF, %1\n" \ "25:\n" \ "MGETL D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "26:\n" \ "MSETL [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %3, %3, #32\n" \ "27:\n" \ "MGETL D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "28:\n" \ "MSETL [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %0, %0, #8\n" \ "29:\n" \ "SETL [%0++], D0.7, D1.7\n" \ "SUB %3, %3, #32\n" \ "1:" \ "DCACHE [%1+#-64], D0Ar6\n" \ "GETL D0Ar6, D1Ar5, [A0StP+#-40]\n" \ "GETL D0FrT, D1RtP, [A0StP+#-32]\n" \ "GETL D0.5, D1.5, [A0StP+#-24]\n" \ "GETL D0.6, D1.6, [A0StP+#-16]\n" \ "GETL D0.7, D1.7, [A0StP+#-8]\n" \ "SUB A0StP, A0StP, #40\n" \ " .section .fixup,\"ax\"\n" \ "4:\n" \ " ADD %0, %0, #8\n" \ "3:\n" \ " MOV D0Ar2, TXSTATUS\n" \ " MOV D1Ar1, TXSTATUS\n" \ " AND D1Ar1, D1Ar1, #0xFFFFF8FF\n" \ " MOV TXSTATUS, D1Ar1\n" \ FIXUP \ " MOVT D0Ar2,#HI(1b)\n" \ " JUMP D0Ar2,#LO(1b)\n" \ " .previous\n" \ " .section __ex_table,\"a\"\n" \ " .long 21b,3b\n" \ " .long 22b,3b\n" \ " .long 23b,3b\n" \ " .long 24b,3b\n" \ " .long 25b,3b\n" \ " .long 26b,3b\n" \ " .long 27b,3b\n" \ " .long 28b,3b\n" \ " .long 29b,4b\n" \ " .previous\n" \ : "=r" (to), "=r" (from), "=r" (ret), "=d" (n) \ : "0" (to), "1" (from), "2" (ret), "3" (n) \ : "D1Ar1", "D0Ar2", "memory") /* rewind 'to' and 'from' pointers when a fault occurs * * Rationale: * A fault always occurs on writing to user buffer. A fault * is at a single address, so we need to rewind by only 4 * bytes. * Since we do a complete read from kernel buffer before * writing, we need to rewind it also. The amount to be * rewind equals the number of faulty writes in MSETD * which is: [4 - (LSM_STEP-1)]*8 * LSM_STEP is bits 10:8 in TXSTATUS which is already read * and stored in D0Ar2 * * NOTE: If a fault occurs at the last operation in M{G,S}ETL * LSM_STEP will be 0. ie: we do 4 writes in our case, if * a fault happens at the 4th write, LSM_STEP will be 0 * instead of 4. The code copes with that. * * n is updated by the number of successful writes, which is: * n = n - (LSM_STEP-1)*8 */ #define __asm_copy_to_user_64bit_rapf_loop(to, from, ret, n, id)\ __asm_copy_user_64bit_rapf_loop(to, from, ret, n, id, \ "LSR D0Ar2, D0Ar2, #8\n" \ "AND D0Ar2, D0Ar2, #0x7\n" \ "ADDZ D0Ar2, D0Ar2, #4\n" \ "SUB D0Ar2, D0Ar2, #1\n" \ "MOV D1Ar1, #4\n" \ "SUB D0Ar2, D1Ar1, D0Ar2\n" \ "LSL D0Ar2, D0Ar2, #3\n" \ "LSL D1Ar1, D1Ar1, #3\n" \ "SUB D1Ar1, D1Ar1, D0Ar2\n" \ "SUB %0, %0, #8\n" \ "SUB %1, %1,D0Ar2\n" \ "SUB %3, %3, D1Ar1\n") /* * optimized copying loop using RAPF when 32 bit aligned * * n will be automatically decremented inside the loop * ret will be left intact. if error occurs we will rewind * so that the original non optimized code will fill up * this value correctly. * * on fault: * > n will hold total number of uncopied bytes * * > {'to','from'} will be rewind back so that * the non-optimized code will do the proper fix up * * DCACHE drops the cacheline which helps in reducing cache * pollution. * * We introduce an extra SETD at the end of the loop to * ensure we don't fall off the loop before we catch all * erros. * * NOTICE: * LSM_STEP in TXSTATUS must be cleared in fix up code. * since we're using M{S,G}ETL, a fault might happen at * any address in the middle of M{S,G}ETL causing * the value of LSM_STEP to be incorrect which can * cause subsequent use of M{S,G}ET{L,D} to go wrong. * ie: if LSM_STEP was 1 when a fault occurs, the * next call to M{S,G}ET{L,D} will skip the first * copy/getting as it think that the first 1 has already * been done. * */ #define __asm_copy_user_32bit_rapf_loop( \ to, from, ret, n, id, FIXUP) \ asm volatile ( \ ".balign 8\n" \ "MOV RAPF, %1\n" \ "MSETL [A0StP++], D0Ar6, D0FrT, D0.5, D0.6, D0.7\n" \ "MOV D0Ar6, #0\n" \ "LSR D1Ar5, %3, #6\n" \ "SUB TXRPT, D1Ar5, #2\n" \ "MOV RAPF, %1\n" \ "$Lloop"id":\n" \ "ADD RAPF, %1, #64\n" \ "21:\n" \ "MGETD D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "22:\n" \ "MSETD [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %3, %3, #16\n" \ "23:\n" \ "MGETD D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "24:\n" \ "MSETD [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %3, %3, #16\n" \ "25:\n" \ "MGETD D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "26:\n" \ "MSETD [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %3, %3, #16\n" \ "27:\n" \ "MGETD D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "28:\n" \ "MSETD [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %3, %3, #16\n" \ "DCACHE [%1+#-64], D0Ar6\n" \ "BR $Lloop"id"\n" \ \ "MOV RAPF, %1\n" \ "29:\n" \ "MGETD D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "30:\n" \ "MSETD [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %3, %3, #16\n" \ "31:\n" \ "MGETD D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "32:\n" \ "MSETD [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %3, %3, #16\n" \ "33:\n" \ "MGETD D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "34:\n" \ "MSETD [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %3, %3, #16\n" \ "35:\n" \ "MGETD D0FrT, D0.5, D0.6, D0.7, [%1++]\n" \ "36:\n" \ "MSETD [%0++], D0FrT, D0.5, D0.6, D0.7\n" \ "SUB %0, %0, #4\n" \ "37:\n" \ "SETD [%0++], D0.7\n" \ "SUB %3, %3, #16\n" \ "1:" \ "DCACHE [%1+#-64], D0Ar6\n" \ "GETL D0Ar6, D1Ar5, [A0StP+#-40]\n" \ "GETL D0FrT, D1RtP, [A0StP+#-32]\n" \ "GETL D0.5, D1.5, [A0StP+#-24]\n" \ "GETL D0.6, D1.6, [A0StP+#-16]\n" \ "GETL D0.7, D1.7, [A0StP+#-8]\n" \ "SUB A0StP, A0StP, #40\n" \ " .section .fixup,\"ax\"\n" \ "4:\n" \ " ADD %0, %0, #4\n" \ "3:\n" \ " MOV D0Ar2, TXSTATUS\n" \ " MOV D1Ar1, TXSTATUS\n" \ " AND D1Ar1, D1Ar1, #0xFFFFF8FF\n" \ " MOV TXSTATUS, D1Ar1\n" \ FIXUP \ " MOVT D0Ar2,#HI(1b)\n" \ " JUMP D0Ar2,#LO(1b)\n" \ " .previous\n" \ " .section __ex_table,\"a\"\n" \ " .long 21b,3b\n" \ " .long 22b,3b\n" \ " .long 23b,3b\n" \ " .long 24b,3b\n" \ " .long 25b,3b\n" \ " .long 26b,3b\n" \ " .long 27b,3b\n" \ " .long 28b,3b\n" \ " .long 29b,3b\n" \ " .long 30b,3b\n" \ " .long 31b,3b\n" \ " .long 32b,3b\n" \ " .long 33b,3b\n" \ " .long 34b,3b\n" \ " .long 35b,3b\n" \ " .long 36b,3b\n" \ " .long 37b,4b\n" \ " .previous\n" \ : "=r" (to), "=r" (from), "=r" (ret), "=d" (n) \ : "0" (to), "1" (from), "2" (ret), "3" (n) \ : "D1Ar1", "D0Ar2", "memory") /* rewind 'to' and 'from' pointers when a fault occurs * * Rationale: * A fault always occurs on writing to user buffer. A fault * is at a single address, so we need to rewind by only 4 * bytes. * Since we do a complete read from kernel buffer before * writing, we need to rewind it also. The amount to be * rewind equals the number of faulty writes in MSETD * which is: [4 - (LSM_STEP-1)]*4 * LSM_STEP is bits 10:8 in TXSTATUS which is already read * and stored in D0Ar2 * * NOTE: If a fault occurs at the last operation in M{G,S}ETL * LSM_STEP will be 0. ie: we do 4 writes in our case, if * a fault happens at the 4th write, LSM_STEP will be 0 * instead of 4. The code copes with that. * * n is updated by the number of successful writes, which is: * n = n - (LSM_STEP-1)*4 */ #define __asm_copy_to_user_32bit_rapf_loop(to, from, ret, n, id)\ __asm_copy_user_32bit_rapf_loop(to, from, ret, n, id, \ "LSR D0Ar2, D0Ar2, #8\n" \ "AND D0Ar2, D0Ar2, #0x7\n" \ "ADDZ D0Ar2, D0Ar2, #4\n" \ "SUB D0Ar2, D0Ar2, #1\n" \ "MOV D1Ar1, #4\n" \ "SUB D0Ar2, D1Ar1, D0Ar2\n" \ "LSL D0Ar2, D0Ar2, #2\n" \ "LSL D1Ar1, D1Ar1, #2\n" \ "SUB D1Ar1, D1Ar1, D0Ar2\n" \ "SUB %0, %0, #4\n" \ "SUB %1, %1, D0Ar2\n" \ "SUB %3, %3, D1Ar1\n") unsigned long __copy_user(void __user *pdst, const void *psrc, unsigned long n) { register char __user *dst asm ("A0.2") = pdst; register const char *src asm ("A1.2") = psrc; unsigned long retn = 0; if (n == 0) return 0; if ((unsigned long) src & 1) { __asm_copy_to_user_1(dst, src, retn); n--; } if ((unsigned long) dst & 1) { /* Worst case - byte copy */ while (n > 0) { __asm_copy_to_user_1(dst, src, retn); n--; } } if (((unsigned long) src & 2) && n >= 2) { __asm_copy_to_user_2(dst, src, retn); n -= 2; } if ((unsigned long) dst & 2) { /* Second worst case - word copy */ while (n >= 2) { __asm_copy_to_user_2(dst, src, retn); n -= 2; } } #ifdef USE_RAPF /* 64 bit copy loop */ if (!(((unsigned long) src | (__force unsigned long) dst) & 7)) { if (n >= RAPF_MIN_BUF_SIZE) { /* copy user using 64 bit rapf copy */ __asm_copy_to_user_64bit_rapf_loop(dst, src, retn, n, "64cu"); } while (n >= 8) { __asm_copy_to_user_8x64(dst, src, retn); n -= 8; } } if (n >= RAPF_MIN_BUF_SIZE) { /* copy user using 32 bit rapf copy */ __asm_copy_to_user_32bit_rapf_loop(dst, src, retn, n, "32cu"); } #else /* 64 bit copy loop */ if (!(((unsigned long) src | (__force unsigned long) dst) & 7)) { while (n >= 8) { __asm_copy_to_user_8x64(dst, src, retn); n -= 8; } } #endif while (n >= 16) { __asm_copy_to_user_16(dst, src, retn); n -= 16; } while (n >= 4) { __asm_copy_to_user_4(dst, src, retn); n -= 4; } switch (n) { case 0: break; case 1: __asm_copy_to_user_1(dst, src, retn); break; case 2: __asm_copy_to_user_2(dst, src, retn); break; case 3: __asm_copy_to_user_3(dst, src, retn); break; } return retn; } EXPORT_SYMBOL(__copy_user); #define __asm_copy_from_user_1(to, from, ret) \ __asm_copy_user_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ "2: SETB [%0++],D1Ar1\n", \ "3: ADD %2,%2,#1\n" \ " SETB [%0++],D1Ar1\n", \ " .long 2b,3b\n") #define __asm_copy_from_user_2x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_user_cont(to, from, ret, \ " GETW D1Ar1,[%1++]\n" \ "2: SETW [%0++],D1Ar1\n" COPY, \ "3: ADD %2,%2,#2\n" \ " SETW [%0++],D1Ar1\n" FIXUP, \ " .long 2b,3b\n" TENTRY) #define __asm_copy_from_user_2(to, from, ret) \ __asm_copy_from_user_2x_cont(to, from, ret, "", "", "") #define __asm_copy_from_user_3(to, from, ret) \ __asm_copy_from_user_2x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ "4: SETB [%0++],D1Ar1\n", \ "5: ADD %2,%2,#1\n" \ " SETB [%0++],D1Ar1\n", \ " .long 4b,5b\n") #define __asm_copy_from_user_4x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_user_cont(to, from, ret, \ " GETD D1Ar1,[%1++]\n" \ "2: SETD [%0++],D1Ar1\n" COPY, \ "3: ADD %2,%2,#4\n" \ " SETD [%0++],D1Ar1\n" FIXUP, \ " .long 2b,3b\n" TENTRY) #define __asm_copy_from_user_4(to, from, ret) \ __asm_copy_from_user_4x_cont(to, from, ret, "", "", "") #define __asm_copy_from_user_5(to, from, ret) \ __asm_copy_from_user_4x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ "4: SETB [%0++],D1Ar1\n", \ "5: ADD %2,%2,#1\n" \ " SETB [%0++],D1Ar1\n", \ " .long 4b,5b\n") #define __asm_copy_from_user_6x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_from_user_4x_cont(to, from, ret, \ " GETW D1Ar1,[%1++]\n" \ "4: SETW [%0++],D1Ar1\n" COPY, \ "5: ADD %2,%2,#2\n" \ " SETW [%0++],D1Ar1\n" FIXUP, \ " .long 4b,5b\n" TENTRY) #define __asm_copy_from_user_6(to, from, ret) \ __asm_copy_from_user_6x_cont(to, from, ret, "", "", "") #define __asm_copy_from_user_7(to, from, ret) \ __asm_copy_from_user_6x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ "6: SETB [%0++],D1Ar1\n", \ "7: ADD %2,%2,#1\n" \ " SETB [%0++],D1Ar1\n", \ " .long 6b,7b\n") #define __asm_copy_from_user_8x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_from_user_4x_cont(to, from, ret, \ " GETD D1Ar1,[%1++]\n" \ "4: SETD [%0++],D1Ar1\n" COPY, \ "5: ADD %2,%2,#4\n" \ " SETD [%0++],D1Ar1\n" FIXUP, \ " .long 4b,5b\n" TENTRY) #define __asm_copy_from_user_8(to, from, ret) \ __asm_copy_from_user_8x_cont(to, from, ret, "", "", "") #define __asm_copy_from_user_9(to, from, ret) \ __asm_copy_from_user_8x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ "6: SETB [%0++],D1Ar1\n", \ "7: ADD %2,%2,#1\n" \ " SETB [%0++],D1Ar1\n", \ " .long 6b,7b\n") #define __asm_copy_from_user_10x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_from_user_8x_cont(to, from, ret, \ " GETW D1Ar1,[%1++]\n" \ "6: SETW [%0++],D1Ar1\n" COPY, \ "7: ADD %2,%2,#2\n" \ " SETW [%0++],D1Ar1\n" FIXUP, \ " .long 6b,7b\n" TENTRY) #define __asm_copy_from_user_10(to, from, ret) \ __asm_copy_from_user_10x_cont(to, from, ret, "", "", "") #define __asm_copy_from_user_11(to, from, ret) \ __asm_copy_from_user_10x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ "8: SETB [%0++],D1Ar1\n", \ "9: ADD %2,%2,#1\n" \ " SETB [%0++],D1Ar1\n", \ " .long 8b,9b\n") #define __asm_copy_from_user_12x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_from_user_8x_cont(to, from, ret, \ " GETD D1Ar1,[%1++]\n" \ "6: SETD [%0++],D1Ar1\n" COPY, \ "7: ADD %2,%2,#4\n" \ " SETD [%0++],D1Ar1\n" FIXUP, \ " .long 6b,7b\n" TENTRY) #define __asm_copy_from_user_12(to, from, ret) \ __asm_copy_from_user_12x_cont(to, from, ret, "", "", "") #define __asm_copy_from_user_13(to, from, ret) \ __asm_copy_from_user_12x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ "8: SETB [%0++],D1Ar1\n", \ "9: ADD %2,%2,#1\n" \ " SETB [%0++],D1Ar1\n", \ " .long 8b,9b\n") #define __asm_copy_from_user_14x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_from_user_12x_cont(to, from, ret, \ " GETW D1Ar1,[%1++]\n" \ "8: SETW [%0++],D1Ar1\n" COPY, \ "9: ADD %2,%2,#2\n" \ " SETW [%0++],D1Ar1\n" FIXUP, \ " .long 8b,9b\n" TENTRY) #define __asm_copy_from_user_14(to, from, ret) \ __asm_copy_from_user_14x_cont(to, from, ret, "", "", "") #define __asm_copy_from_user_15(to, from, ret) \ __asm_copy_from_user_14x_cont(to, from, ret, \ " GETB D1Ar1,[%1++]\n" \ "10: SETB [%0++],D1Ar1\n", \ "11: ADD %2,%2,#1\n" \ " SETB [%0++],D1Ar1\n", \ " .long 10b,11b\n") #define __asm_copy_from_user_16x_cont(to, from, ret, COPY, FIXUP, TENTRY) \ __asm_copy_from_user_12x_cont(to, from, ret, \ " GETD D1Ar1,[%1++]\n" \ "8: SETD [%0++],D1Ar1\n" COPY, \ "9: ADD %2,%2,#4\n" \ " SETD [%0++],D1Ar1\n" FIXUP, \ " .long 8b,9b\n" TENTRY) #define __asm_copy_from_user_16(to, from, ret) \ __asm_copy_from_user_16x_cont(to, from, ret, "", "", "") #define __asm_copy_from_user_8x64(to, from, ret) \ asm volatile ( \ " GETL D0Ar2,D1Ar1,[%1++]\n" \ "2: SETL [%0++],D0Ar2,D1Ar1\n" \ "1:\n" \ " .section .fixup,\"ax\"\n" \ " MOV D1Ar1,#0\n" \ " MOV D0Ar2,#0\n" \ "3: ADD %2,%2,#8\n" \ " SETL [%0++],D0Ar2,D1Ar1\n" \ " MOVT D0Ar2,#HI(1b)\n" \ " JUMP D0Ar2,#LO(1b)\n" \ " .previous\n" \ " .section __ex_table,\"a\"\n" \ " .long 2b,3b\n" \ " .previous\n" \ : "=a" (to), "=r" (from), "=r" (ret) \ : "0" (to), "1" (from), "2" (ret) \ : "D1Ar1", "D0Ar2", "memory") /* rewind 'from' pointer when a fault occurs * * Rationale: * A fault occurs while reading from user buffer, which is the * source. Since the fault is at a single address, we only * need to rewind by 8 bytes. * Since we don't write to kernel buffer until we read first, * the kernel buffer is at the right state and needn't be * corrected. */ #define __asm_copy_from_user_64bit_rapf_loop(to, from, ret, n, id) \ __asm_copy_user_64bit_rapf_loop(to, from, ret, n, id, \ "SUB %1, %1, #8\n") /* rewind 'from' pointer when a fault occurs * * Rationale: * A fault occurs while reading from user buffer, which is the * source. Since the fault is at a single address, we only * need to rewind by 4 bytes. * Since we don't write to kernel buffer until we read first, * the kernel buffer is at the right state and needn't be * corrected. */ #define __asm_copy_from_user_32bit_rapf_loop(to, from, ret, n, id) \ __asm_copy_user_32bit_rapf_loop(to, from, ret, n, id, \ "SUB %1, %1, #4\n") /* Copy from user to kernel, zeroing the bytes that were inaccessible in userland. The return-value is the number of bytes that were inaccessible. */ unsigned long __copy_user_zeroing(void *pdst, const void __user *psrc, unsigned long n) { register char *dst asm ("A0.2") = pdst; register const char __user *src asm ("A1.2") = psrc; unsigned long retn = 0; if (n == 0) return 0; if ((unsigned long) src & 1) { __asm_copy_from_user_1(dst, src, retn); n--; } if ((unsigned long) dst & 1) { /* Worst case - byte copy */ while (n > 0) { __asm_copy_from_user_1(dst, src, retn); n--; if (retn) goto copy_exception_bytes; } } if (((unsigned long) src & 2) && n >= 2) { __asm_copy_from_user_2(dst, src, retn); n -= 2; } if ((unsigned long) dst & 2) { /* Second worst case - word copy */ while (n >= 2) { __asm_copy_from_user_2(dst, src, retn); n -= 2; if (retn) goto copy_exception_bytes; } } /* We only need one check after the unalignment-adjustments, because if both adjustments were done, either both or neither reference had an exception. */ if (retn != 0) goto copy_exception_bytes; #ifdef USE_RAPF /* 64 bit copy loop */ if (!(((unsigned long) src | (unsigned long) dst) & 7)) { if (n >= RAPF_MIN_BUF_SIZE) { /* Copy using fast 64bit rapf */ __asm_copy_from_user_64bit_rapf_loop(dst, src, retn, n, "64cuz"); } while (n >= 8) { __asm_copy_from_user_8x64(dst, src, retn); n -= 8; if (retn) goto copy_exception_bytes; } } if (n >= RAPF_MIN_BUF_SIZE) { /* Copy using fast 32bit rapf */ __asm_copy_from_user_32bit_rapf_loop(dst, src, retn, n, "32cuz"); } #else /* 64 bit copy loop */ if (!(((unsigned long) src | (unsigned long) dst) & 7)) { while (n >= 8) { __asm_copy_from_user_8x64(dst, src, retn); n -= 8; if (retn) goto copy_exception_bytes; } } #endif while (n >= 4) { __asm_copy_from_user_4(dst, src, retn); n -= 4; if (retn) goto copy_exception_bytes; } /* If we get here, there were no memory read faults. */ switch (n) { /* These copies are at least "naturally aligned" (so we don't have to check each byte), due to the src alignment code. The *_3 case *will* get the correct count for retn. */ case 0: /* This case deliberately left in (if you have doubts check the generated assembly code). */ break; case 1: __asm_copy_from_user_1(dst, src, retn); break; case 2: __asm_copy_from_user_2(dst, src, retn); break; case 3: __asm_copy_from_user_3(dst, src, retn); break; } /* If we get here, retn correctly reflects the number of failing bytes. */ return retn; copy_exception_bytes: /* We already have "retn" bytes cleared, and need to clear the remaining "n" bytes. A non-optimized simple byte-for-byte in-line memset is preferred here, since this isn't speed-critical code and we'd rather have this a leaf-function than calling memset. */ { char *endp; for (endp = dst + n; dst < endp; dst++) *dst = 0; } return retn + n; } EXPORT_SYMBOL(__copy_user_zeroing); #define __asm_clear_8x64(to, ret) \ asm volatile ( \ " MOV D0Ar2,#0\n" \ " MOV D1Ar1,#0\n" \ " SETL [%0],D0Ar2,D1Ar1\n" \ "2: SETL [%0++],D0Ar2,D1Ar1\n" \ "1:\n" \ " .section .fixup,\"ax\"\n" \ "3: ADD %1,%1,#8\n" \ " MOVT D0Ar2,#HI(1b)\n" \ " JUMP D0Ar2,#LO(1b)\n" \ " .previous\n" \ " .section __ex_table,\"a\"\n" \ " .long 2b,3b\n" \ " .previous\n" \ : "=r" (to), "=r" (ret) \ : "0" (to), "1" (ret) \ : "D1Ar1", "D0Ar2", "memory") /* Zero userspace. */ #define __asm_clear(to, ret, CLEAR, FIXUP, TENTRY) \ asm volatile ( \ " MOV D1Ar1,#0\n" \ CLEAR \ "1:\n" \ " .section .fixup,\"ax\"\n" \ FIXUP \ " MOVT D1Ar1,#HI(1b)\n" \ " JUMP D1Ar1,#LO(1b)\n" \ " .previous\n" \ " .section __ex_table,\"a\"\n" \ TENTRY \ " .previous" \ : "=r" (to), "=r" (ret) \ : "0" (to), "1" (ret) \ : "D1Ar1", "memory") #define __asm_clear_1(to, ret) \ __asm_clear(to, ret, \ " SETB [%0],D1Ar1\n" \ "2: SETB [%0++],D1Ar1\n", \ "3: ADD %1,%1,#1\n", \ " .long 2b,3b\n") #define __asm_clear_2(to, ret) \ __asm_clear(to, ret, \ " SETW [%0],D1Ar1\n" \ "2: SETW [%0++],D1Ar1\n", \ "3: ADD %1,%1,#2\n", \ " .long 2b,3b\n") #define __asm_clear_3(to, ret) \ __asm_clear(to, ret, \ "2: SETW [%0++],D1Ar1\n" \ " SETB [%0],D1Ar1\n" \ "3: SETB [%0++],D1Ar1\n", \ "4: ADD %1,%1,#2\n" \ "5: ADD %1,%1,#1\n", \ " .long 2b,4b\n" \ " .long 3b,5b\n") #define __asm_clear_4x_cont(to, ret, CLEAR, FIXUP, TENTRY) \ __asm_clear(to, ret, \ " SETD [%0],D1Ar1\n" \ "2: SETD [%0++],D1Ar1\n" CLEAR, \ "3: ADD %1,%1,#4\n" FIXUP, \ " .long 2b,3b\n" TENTRY) #define __asm_clear_4(to, ret) \ __asm_clear_4x_cont(to, ret, "", "", "") #define __asm_clear_8x_cont(to, ret, CLEAR, FIXUP, TENTRY) \ __asm_clear_4x_cont(to, ret, \ " SETD [%0],D1Ar1\n" \ "4: SETD [%0++],D1Ar1\n" CLEAR, \ "5: ADD %1,%1,#4\n" FIXUP, \ " .long 4b,5b\n" TENTRY) #define __asm_clear_8(to, ret) \ __asm_clear_8x_cont(to, ret, "", "", "") #define __asm_clear_12x_cont(to, ret, CLEAR, FIXUP, TENTRY) \ __asm_clear_8x_cont(to, ret, \ " SETD [%0],D1Ar1\n" \ "6: SETD [%0++],D1Ar1\n" CLEAR, \ "7: ADD %1,%1,#4\n" FIXUP, \ " .long 6b,7b\n" TENTRY) #define __asm_clear_12(to, ret) \ __asm_clear_12x_cont(to, ret, "", "", "") #define __asm_clear_16x_cont(to, ret, CLEAR, FIXUP, TENTRY) \ __asm_clear_12x_cont(to, ret, \ " SETD [%0],D1Ar1\n" \ "8: SETD [%0++],D1Ar1\n" CLEAR, \ "9: ADD %1,%1,#4\n" FIXUP, \ " .long 8b,9b\n" TENTRY) #define __asm_clear_16(to, ret) \ __asm_clear_16x_cont(to, ret, "", "", "") unsigned long __do_clear_user(void __user *pto, unsigned long pn) { register char __user *dst asm ("D0Re0") = pto; register unsigned long n asm ("D1Re0") = pn; register unsigned long retn asm ("D0Ar6") = 0; if ((unsigned long) dst & 1) { __asm_clear_1(dst, retn); n--; } if ((unsigned long) dst & 2) { __asm_clear_2(dst, retn); n -= 2; } /* 64 bit copy loop */ if (!((__force unsigned long) dst & 7)) { while (n >= 8) { __asm_clear_8x64(dst, retn); n -= 8; } } while (n >= 16) { __asm_clear_16(dst, retn); n -= 16; } while (n >= 4) { __asm_clear_4(dst, retn); n -= 4; } switch (n) { case 0: break; case 1: __asm_clear_1(dst, retn); break; case 2: __asm_clear_2(dst, retn); break; case 3: __asm_clear_3(dst, retn); break; } return retn; } EXPORT_SYMBOL(__do_clear_user); unsigned char __get_user_asm_b(const void __user *addr, long *err) { register unsigned char x asm ("D0Re0") = 0; asm volatile ( " GETB %0,[%2]\n" "1:\n" " GETB %0,[%2]\n" "2:\n" " .section .fixup,\"ax\"\n" "3: MOV D0FrT,%3\n" " SETD [%1],D0FrT\n" " MOVT D0FrT,#HI(2b)\n" " JUMP D0FrT,#LO(2b)\n" " .previous\n" " .section __ex_table,\"a\"\n" " .long 1b,3b\n" " .previous\n" : "=r" (x) : "r" (err), "r" (addr), "P" (-EFAULT) : "D0FrT"); return x; } EXPORT_SYMBOL(__get_user_asm_b); unsigned short __get_user_asm_w(const void __user *addr, long *err) { register unsigned short x asm ("D0Re0") = 0; asm volatile ( " GETW %0,[%2]\n" "1:\n" " GETW %0,[%2]\n" "2:\n" " .section .fixup,\"ax\"\n" "3: MOV D0FrT,%3\n" " SETD [%1],D0FrT\n" " MOVT D0FrT,#HI(2b)\n" " JUMP D0FrT,#LO(2b)\n" " .previous\n" " .section __ex_table,\"a\"\n" " .long 1b,3b\n" " .previous\n" : "=r" (x) : "r" (err), "r" (addr), "P" (-EFAULT) : "D0FrT"); return x; } EXPORT_SYMBOL(__get_user_asm_w); unsigned int __get_user_asm_d(const void __user *addr, long *err) { register unsigned int x asm ("D0Re0") = 0; asm volatile ( " GETD %0,[%2]\n" "1:\n" " GETD %0,[%2]\n" "2:\n" " .section .fixup,\"ax\"\n" "3: MOV D0FrT,%3\n" " SETD [%1],D0FrT\n" " MOVT D0FrT,#HI(2b)\n" " JUMP D0FrT,#LO(2b)\n" " .previous\n" " .section __ex_table,\"a\"\n" " .long 1b,3b\n" " .previous\n" : "=r" (x) : "r" (err), "r" (addr), "P" (-EFAULT) : "D0FrT"); return x; } EXPORT_SYMBOL(__get_user_asm_d); long __put_user_asm_b(unsigned int x, void __user *addr) { register unsigned int err asm ("D0Re0") = 0; asm volatile ( " MOV %0,#0\n" " SETB [%2],%1\n" "1:\n" " SETB [%2],%1\n" "2:\n" ".section .fixup,\"ax\"\n" "3: MOV %0,%3\n" " MOVT D0FrT,#HI(2b)\n" " JUMP D0FrT,#LO(2b)\n" ".previous\n" ".section __ex_table,\"a\"\n" " .long 1b,3b\n" ".previous" : "=r"(err) : "d" (x), "a" (addr), "P"(-EFAULT) : "D0FrT"); return err; } EXPORT_SYMBOL(__put_user_asm_b); long __put_user_asm_w(unsigned int x, void __user *addr) { register unsigned int err asm ("D0Re0") = 0; asm volatile ( " MOV %0,#0\n" " SETW [%2],%1\n" "1:\n" " SETW [%2],%1\n" "2:\n" ".section .fixup,\"ax\"\n" "3: MOV %0,%3\n" " MOVT D0FrT,#HI(2b)\n" " JUMP D0FrT,#LO(2b)\n" ".previous\n" ".section __ex_table,\"a\"\n" " .long 1b,3b\n" ".previous" : "=r"(err) : "d" (x), "a" (addr), "P"(-EFAULT) : "D0FrT"); return err; } EXPORT_SYMBOL(__put_user_asm_w); long __put_user_asm_d(unsigned int x, void __user *addr) { register unsigned int err asm ("D0Re0") = 0; asm volatile ( " MOV %0,#0\n" " SETD [%2],%1\n" "1:\n" " SETD [%2],%1\n" "2:\n" ".section .fixup,\"ax\"\n" "3: MOV %0,%3\n" " MOVT D0FrT,#HI(2b)\n" " JUMP D0FrT,#LO(2b)\n" ".previous\n" ".section __ex_table,\"a\"\n" " .long 1b,3b\n" ".previous" : "=r"(err) : "d" (x), "a" (addr), "P"(-EFAULT) : "D0FrT"); return err; } EXPORT_SYMBOL(__put_user_asm_d); long __put_user_asm_l(unsigned long long x, void __user *addr) { register unsigned int err asm ("D0Re0") = 0; asm volatile ( " MOV %0,#0\n" " SETL [%2],%1,%t1\n" "1:\n" " SETL [%2],%1,%t1\n" "2:\n" ".section .fixup,\"ax\"\n" "3: MOV %0,%3\n" " MOVT D0FrT,#HI(2b)\n" " JUMP D0FrT,#LO(2b)\n" ".previous\n" ".section __ex_table,\"a\"\n" " .long 1b,3b\n" ".previous" : "=r"(err) : "d" (x), "a" (addr), "P"(-EFAULT) : "D0FrT"); return err; } EXPORT_SYMBOL(__put_user_asm_l); long strnlen_user(const char __user *src, long count) { long res; if (!access_ok(VERIFY_READ, src, 0)) return 0; asm volatile (" MOV D0Ar4, %1\n" " MOV D0Ar6, %2\n" "0:\n" " SUBS D0FrT, D0Ar6, #0\n" " SUB D0Ar6, D0Ar6, #1\n" " BLE 2f\n" " GETB D0FrT, [D0Ar4+#1++]\n" "1:\n" " TST D0FrT, #255\n" " BNE 0b\n" "2:\n" " SUB %0, %2, D0Ar6\n" "3:\n" " .section .fixup,\"ax\"\n" "4:\n" " MOV %0, #0\n" " MOVT D0FrT,#HI(3b)\n" " JUMP D0FrT,#LO(3b)\n" " .previous\n" " .section __ex_table,\"a\"\n" " .long 1b,4b\n" " .previous\n" : "=r" (res) : "r" (src), "r" (count) : "D0FrT", "D0Ar4", "D0Ar6", "cc"); return res; } EXPORT_SYMBOL(strnlen_user); long __strncpy_from_user(char *dst, const char __user *src, long count) { long res; if (count == 0) return 0; /* * Currently, in 2.4.0-test9, most ports use a simple byte-copy loop. * So do we. * * This code is deduced from: * * char tmp2; * long tmp1, tmp3; * tmp1 = count; * while ((*dst++ = (tmp2 = *src++)) != 0 * && --tmp1) * ; * * res = count - tmp1; * * with tweaks. */ asm volatile (" MOV %0,%3\n" "1:\n" " GETB D0FrT,[%2++]\n" "2:\n" " CMP D0FrT,#0\n" " SETB [%1++],D0FrT\n" " BEQ 3f\n" " SUBS %0,%0,#1\n" " BNZ 1b\n" "3:\n" " SUB %0,%3,%0\n" "4:\n" " .section .fixup,\"ax\"\n" "5:\n" " MOV %0,%7\n" " MOVT D0FrT,#HI(4b)\n" " JUMP D0FrT,#LO(4b)\n" " .previous\n" " .section __ex_table,\"a\"\n" " .long 2b,5b\n" " .previous" : "=r" (res), "=r" (dst), "=r" (src), "=r" (count) : "3" (count), "1" (dst), "2" (src), "P" (-EFAULT) : "D0FrT", "memory", "cc"); return res; } EXPORT_SYMBOL(__strncpy_from_user);
nel82/android_zenfone4_kernel
arch/metag/lib/usercopy.c
C
gpl-2.0
37,247
/* central.c: Central FHC driver for Sunfire/Starfire/Wildfire. * * Copyright (C) 1997, 1999, 2008 David S. Miller (davem@davemloft.net) */ #include <linux/kernel.h> #include <linux/types.h> #include <linux/slab.h> #include <linux/export.h> #include <linux/string.h> #include <linux/init.h> #include <linux/of_device.h> #include <linux/platform_device.h> #include <asm/fhc.h> #include <asm/upa.h> struct clock_board { void __iomem *clock_freq_regs; void __iomem *clock_regs; void __iomem *clock_ver_reg; int num_slots; struct resource leds_resource; struct platform_device leds_pdev; }; struct fhc { void __iomem *pregs; bool central; bool jtag_master; int board_num; struct resource leds_resource; struct platform_device leds_pdev; }; static int __devinit clock_board_calc_nslots(struct clock_board *p) { u8 reg = upa_readb(p->clock_regs + CLOCK_STAT1) & 0xc0; switch (reg) { case 0x40: return 16; case 0xc0: return 8; case 0x80: reg = 0; if (p->clock_ver_reg) reg = upa_readb(p->clock_ver_reg); if (reg) { if (reg & 0x80) return 4; else return 5; } /* Fallthrough */ default: return 4; } } static int __devinit clock_board_probe(struct platform_device *op) { struct clock_board *p = kzalloc(sizeof(*p), GFP_KERNEL); int err = -ENOMEM; if (!p) { printk(KERN_ERR "clock_board: Cannot allocate struct clock_board\n"); goto out; } p->clock_freq_regs = of_ioremap(&op->resource[0], 0, resource_size(&op->resource[0]), "clock_board_freq"); if (!p->clock_freq_regs) { printk(KERN_ERR "clock_board: Cannot map clock_freq_regs\n"); goto out_free; } p->clock_regs = of_ioremap(&op->resource[1], 0, resource_size(&op->resource[1]), "clock_board_regs"); if (!p->clock_regs) { printk(KERN_ERR "clock_board: Cannot map clock_regs\n"); goto out_unmap_clock_freq_regs; } if (op->resource[2].flags) { p->clock_ver_reg = of_ioremap(&op->resource[2], 0, resource_size(&op->resource[2]), "clock_ver_reg"); if (!p->clock_ver_reg) { printk(KERN_ERR "clock_board: Cannot map clock_ver_reg\n"); goto out_unmap_clock_regs; } } p->num_slots = clock_board_calc_nslots(p); p->leds_resource.start = (unsigned long) (p->clock_regs + CLOCK_CTRL); p->leds_resource.end = p->leds_resource.start; p->leds_resource.name = "leds"; p->leds_pdev.name = "sunfire-clockboard-leds"; p->leds_pdev.id = -1; p->leds_pdev.resource = &p->leds_resource; p->leds_pdev.num_resources = 1; p->leds_pdev.dev.parent = &op->dev; err = platform_device_register(&p->leds_pdev); if (err) { printk(KERN_ERR "clock_board: Could not register LEDS " "platform device\n"); goto out_unmap_clock_ver_reg; } printk(KERN_INFO "clock_board: Detected %d slot Enterprise system.\n", p->num_slots); err = 0; out: return err; out_unmap_clock_ver_reg: if (p->clock_ver_reg) of_iounmap(&op->resource[2], p->clock_ver_reg, resource_size(&op->resource[2])); out_unmap_clock_regs: of_iounmap(&op->resource[1], p->clock_regs, resource_size(&op->resource[1])); out_unmap_clock_freq_regs: of_iounmap(&op->resource[0], p->clock_freq_regs, resource_size(&op->resource[0])); out_free: kfree(p); goto out; } static const struct of_device_id clock_board_match[] = { { .name = "clock-board", }, {}, }; static struct platform_driver clock_board_driver = { .probe = clock_board_probe, .driver = { .name = "clock_board", .owner = THIS_MODULE, .of_match_table = clock_board_match, }, }; static int __devinit fhc_probe(struct platform_device *op) { struct fhc *p = kzalloc(sizeof(*p), GFP_KERNEL); int err = -ENOMEM; u32 reg; if (!p) { printk(KERN_ERR "fhc: Cannot allocate struct fhc\n"); goto out; } if (!strcmp(op->dev.of_node->parent->name, "central")) p->central = true; p->pregs = of_ioremap(&op->resource[0], 0, resource_size(&op->resource[0]), "fhc_pregs"); if (!p->pregs) { printk(KERN_ERR "fhc: Cannot map pregs\n"); goto out_free; } if (p->central) { reg = upa_readl(p->pregs + FHC_PREGS_BSR); p->board_num = ((reg >> 16) & 1) | ((reg >> 12) & 0x0e); } else { p->board_num = of_getintprop_default(op->dev.of_node, "board#", -1); if (p->board_num == -1) { printk(KERN_ERR "fhc: No board# property\n"); goto out_unmap_pregs; } if (upa_readl(p->pregs + FHC_PREGS_JCTRL) & FHC_JTAG_CTRL_MENAB) p->jtag_master = true; } if (!p->central) { p->leds_resource.start = (unsigned long) (p->pregs + FHC_PREGS_CTRL); p->leds_resource.end = p->leds_resource.start; p->leds_resource.name = "leds"; p->leds_pdev.name = "sunfire-fhc-leds"; p->leds_pdev.id = p->board_num; p->leds_pdev.resource = &p->leds_resource; p->leds_pdev.num_resources = 1; p->leds_pdev.dev.parent = &op->dev; err = platform_device_register(&p->leds_pdev); if (err) { printk(KERN_ERR "fhc: Could not register LEDS " "platform device\n"); goto out_unmap_pregs; } } reg = upa_readl(p->pregs + FHC_PREGS_CTRL); if (!p->central) reg |= FHC_CONTROL_IXIST; reg &= ~(FHC_CONTROL_AOFF | FHC_CONTROL_BOFF | FHC_CONTROL_SLINE); upa_writel(reg, p->pregs + FHC_PREGS_CTRL); upa_readl(p->pregs + FHC_PREGS_CTRL); reg = upa_readl(p->pregs + FHC_PREGS_ID); printk(KERN_INFO "fhc: Board #%d, Version[%x] PartID[%x] Manuf[%x] %s\n", p->board_num, (reg & FHC_ID_VERS) >> 28, (reg & FHC_ID_PARTID) >> 12, (reg & FHC_ID_MANUF) >> 1, (p->jtag_master ? "(JTAG Master)" : (p->central ? "(Central)" : ""))); err = 0; out: return err; out_unmap_pregs: of_iounmap(&op->resource[0], p->pregs, resource_size(&op->resource[0])); out_free: kfree(p); goto out; } static const struct of_device_id fhc_match[] = { { .name = "fhc", }, {}, }; static struct platform_driver fhc_driver = { .probe = fhc_probe, .driver = { .name = "fhc", .owner = THIS_MODULE, .of_match_table = fhc_match, }, }; static int __init sunfire_init(void) { (void) platform_driver_register(&fhc_driver); (void) platform_driver_register(&clock_board_driver); return 0; } fs_initcall(sunfire_init);
FrozenCow/msm
arch/sparc/kernel/central.c
C
gpl-2.0
6,172
/* * Using hardware provided CRC32 instruction to accelerate the CRC32 disposal. * CRC32C polynomial:0x1EDC6F41(BE)/0x82F63B78(LE) * CRC32 is a new instruction in Intel SSE4.2, the reference can be found at: * http://www.intel.com/products/processor/manuals/ * Intel(R) 64 and IA-32 Architectures Software Developer's Manual * Volume 2A: Instruction Set Reference, A-M * * Copyright (C) 2008 Intel Corporation * Authors: Austin Zhang <austin_zhang@linux.intel.com> * Kent Liu <kent.liu@intel.com> * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * */ #include <linux/init.h> #include <linux/module.h> #include <linux/string.h> #include <linux/kernel.h> #include <crypto/internal/hash.h> #include <asm/cpufeature.h> #include <asm/cpu_device_id.h> #define CHKSUM_BLOCK_SIZE 1 #define CHKSUM_DIGEST_SIZE 4 #define SCALE_F sizeof(unsigned long) #ifdef CONFIG_X86_64 #define REX_PRE "0x48, " #else #define REX_PRE #endif static u32 crc32c_intel_le_hw_byte(u32 crc, unsigned char const *data, size_t length) { while (length--) { __asm__ __volatile__( ".byte 0xf2, 0xf, 0x38, 0xf0, 0xf1" :"=S"(crc) :"0"(crc), "c"(*data) ); data++; } return crc; } static u32 __pure crc32c_intel_le_hw(u32 crc, unsigned char const *p, size_t len) { unsigned int iquotient = len / SCALE_F; unsigned int iremainder = len % SCALE_F; unsigned long *ptmp = (unsigned long *)p; while (iquotient--) { __asm__ __volatile__( ".byte 0xf2, " REX_PRE "0xf, 0x38, 0xf1, 0xf1;" :"=S"(crc) :"0"(crc), "c"(*ptmp) ); ptmp++; } if (iremainder) crc = crc32c_intel_le_hw_byte(crc, (unsigned char *)ptmp, iremainder); return crc; } /* * Setting the seed allows arbitrary accumulators and flexible XOR policy * If your algorithm starts with ~0, then XOR with ~0 before you set * the seed. */ static int crc32c_intel_setkey(struct crypto_shash *hash, const u8 *key, unsigned int keylen) { u32 *mctx = crypto_shash_ctx(hash); if (keylen != sizeof(u32)) { crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN); return -EINVAL; } *mctx = le32_to_cpup((__le32 *)key); return 0; } static int crc32c_intel_init(struct shash_desc *desc) { u32 *mctx = crypto_shash_ctx(desc->tfm); u32 *crcp = shash_desc_ctx(desc); *crcp = *mctx; return 0; } static int crc32c_intel_update(struct shash_desc *desc, const u8 *data, unsigned int len) { u32 *crcp = shash_desc_ctx(desc); *crcp = crc32c_intel_le_hw(*crcp, data, len); return 0; } static int __crc32c_intel_finup(u32 *crcp, const u8 *data, unsigned int len, u8 *out) { *(__le32 *)out = ~cpu_to_le32(crc32c_intel_le_hw(*crcp, data, len)); return 0; } static int crc32c_intel_finup(struct shash_desc *desc, const u8 *data, unsigned int len, u8 *out) { return __crc32c_intel_finup(shash_desc_ctx(desc), data, len, out); } static int crc32c_intel_final(struct shash_desc *desc, u8 *out) { u32 *crcp = shash_desc_ctx(desc); *(__le32 *)out = ~cpu_to_le32p(crcp); return 0; } static int crc32c_intel_digest(struct shash_desc *desc, const u8 *data, unsigned int len, u8 *out) { return __crc32c_intel_finup(crypto_shash_ctx(desc->tfm), data, len, out); } static int crc32c_intel_cra_init(struct crypto_tfm *tfm) { u32 *key = crypto_tfm_ctx(tfm); *key = ~0; return 0; } static struct shash_alg alg = { .setkey = crc32c_intel_setkey, .init = crc32c_intel_init, .update = crc32c_intel_update, .final = crc32c_intel_final, .finup = crc32c_intel_finup, .digest = crc32c_intel_digest, .descsize = sizeof(u32), .digestsize = CHKSUM_DIGEST_SIZE, .base = { .cra_name = "crc32c", .cra_driver_name = "crc32c-intel", .cra_priority = 200, .cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_ctxsize = sizeof(u32), .cra_module = THIS_MODULE, .cra_init = crc32c_intel_cra_init, } }; static const struct x86_cpu_id crc32c_cpu_id[] = { X86_FEATURE_MATCH(X86_FEATURE_XMM4_2), {} }; MODULE_DEVICE_TABLE(x86cpu, crc32c_cpu_id); static int __init crc32c_intel_mod_init(void) { if (!x86_match_cpu(crc32c_cpu_id)) return -ENODEV; return crypto_register_shash(&alg); } static void __exit crc32c_intel_mod_fini(void) { crypto_unregister_shash(&alg); } module_init(crc32c_intel_mod_init); module_exit(crc32c_intel_mod_fini); MODULE_AUTHOR("Austin Zhang <austin.zhang@intel.com>, Kent Liu <kent.liu@intel.com>"); MODULE_DESCRIPTION("CRC32c (Castagnoli) optimization using Intel Hardware."); MODULE_LICENSE("GPL"); MODULE_ALIAS("crc32c"); MODULE_ALIAS("crc32c-intel");
shankarathi07/linux_lg_lollipop
arch/x86/crypto/crc32c-intel.c
C
gpl-2.0
5,156
/* * linux/drivers/video/omap2/dss/dpi.c * * Copyright (C) 2009 Nokia Corporation * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> * * Some code and ideas taken from drivers/video/omap/ driver * by Imre Deak. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. */ #define DSS_SUBSYS_NAME "DPI" #include <linux/kernel.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/err.h> #include <linux/errno.h> #include <linux/platform_device.h> #include <linux/regulator/consumer.h> #include <video/omapdss.h> #include <plat/cpu.h> #include "dss.h" static struct { struct regulator *vdds_dsi_reg; struct platform_device *dsidev; } dpi; static struct platform_device *dpi_get_dsidev(enum omap_dss_clk_source clk) { int dsi_module; dsi_module = clk == OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ? 0 : 1; return dsi_get_dsidev_from_id(dsi_module); } static bool dpi_use_dsi_pll(struct omap_dss_device *dssdev) { if (dssdev->clocks.dispc.dispc_fclk_src == OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC || dssdev->clocks.dispc.dispc_fclk_src == OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC || dssdev->clocks.dispc.channel.lcd_clk_src == OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC || dssdev->clocks.dispc.channel.lcd_clk_src == OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC) return true; else return false; } static int dpi_set_dsi_clk(struct omap_dss_device *dssdev, bool is_tft, unsigned long pck_req, unsigned long *fck, int *lck_div, int *pck_div) { struct dsi_clock_info dsi_cinfo; struct dispc_clock_info dispc_cinfo; int r; r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft, pck_req, &dsi_cinfo, &dispc_cinfo); if (r) return r; r = dsi_pll_set_clock_div(dpi.dsidev, &dsi_cinfo); if (r) return r; dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src); r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo); if (r) { dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); return r; } *fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk; *lck_div = dispc_cinfo.lck_div; *pck_div = dispc_cinfo.pck_div; return 0; } static int dpi_set_dispc_clk(struct omap_dss_device *dssdev, bool is_tft, unsigned long pck_req, unsigned long *fck, int *lck_div, int *pck_div) { struct dss_clock_info dss_cinfo; struct dispc_clock_info dispc_cinfo; int r; r = dss_calc_clock_div(is_tft, pck_req, &dss_cinfo, &dispc_cinfo); if (r) return r; r = dss_set_clock_div(&dss_cinfo); if (r) return r; r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo); if (r) return r; *fck = dss_cinfo.fck; *lck_div = dispc_cinfo.lck_div; *pck_div = dispc_cinfo.pck_div; return 0; } static int dpi_set_mode(struct omap_dss_device *dssdev) { struct omap_video_timings *t = &dssdev->panel.timings; int lck_div = 0, pck_div = 0; unsigned long fck = 0; unsigned long pck; bool is_tft; int r = 0; dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config, dssdev->panel.acbi, dssdev->panel.acb); is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0; if (dpi_use_dsi_pll(dssdev)) r = dpi_set_dsi_clk(dssdev, is_tft, t->pixel_clock * 1000, &fck, &lck_div, &pck_div); else r = dpi_set_dispc_clk(dssdev, is_tft, t->pixel_clock * 1000, &fck, &lck_div, &pck_div); if (r) return r; pck = fck / lck_div / pck_div / 1000; if (pck != t->pixel_clock) { DSSWARN("Could not find exact pixel clock. " "Requested %d kHz, got %lu kHz\n", t->pixel_clock, pck); t->pixel_clock = pck; } dispc_mgr_set_lcd_timings(dssdev->manager->id, t); return 0; } static void dpi_basic_init(struct omap_dss_device *dssdev) { bool is_tft; is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0; dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_BYPASS); dispc_mgr_enable_stallmode(dssdev->manager->id, false); dispc_mgr_set_lcd_display_type(dssdev->manager->id, is_tft ? OMAP_DSS_LCD_DISPLAY_TFT : OMAP_DSS_LCD_DISPLAY_STN); dispc_mgr_set_tft_data_lines(dssdev->manager->id, dssdev->phy.dpi.data_lines); } int omapdss_dpi_display_enable(struct omap_dss_device *dssdev) { int r; if (cpu_is_omap34xx() && !dpi.vdds_dsi_reg) { DSSERR("no VDSS_DSI regulator\n"); return -ENODEV; } if (dssdev->manager == NULL) { DSSERR("failed to enable display: no manager\n"); return -ENODEV; } r = omap_dss_start_device(dssdev); if (r) { DSSERR("failed to start device\n"); goto err_start_dev; } if (cpu_is_omap34xx()) { r = regulator_enable(dpi.vdds_dsi_reg); if (r) goto err_reg_enable; } r = dss_runtime_get(); if (r) goto err_get_dss; r = dispc_runtime_get(); if (r) goto err_get_dispc; dpi_basic_init(dssdev); if (dpi_use_dsi_pll(dssdev)) { r = dsi_runtime_get(dpi.dsidev); if (r) goto err_get_dsi; r = dsi_pll_init(dpi.dsidev, 0, 1); if (r) goto err_dsi_pll_init; } r = dpi_set_mode(dssdev); if (r) goto err_set_mode; mdelay(2); r = dss_mgr_enable(dssdev->manager); if (r) goto err_mgr_enable; return 0; err_mgr_enable: err_set_mode: if (dpi_use_dsi_pll(dssdev)) dsi_pll_uninit(dpi.dsidev, true); err_dsi_pll_init: if (dpi_use_dsi_pll(dssdev)) dsi_runtime_put(dpi.dsidev); err_get_dsi: dispc_runtime_put(); err_get_dispc: dss_runtime_put(); err_get_dss: if (cpu_is_omap34xx()) regulator_disable(dpi.vdds_dsi_reg); err_reg_enable: omap_dss_stop_device(dssdev); err_start_dev: return r; } EXPORT_SYMBOL(omapdss_dpi_display_enable); void omapdss_dpi_display_disable(struct omap_dss_device *dssdev) { dss_mgr_disable(dssdev->manager); if (dpi_use_dsi_pll(dssdev)) { dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); dsi_pll_uninit(dpi.dsidev, true); dsi_runtime_put(dpi.dsidev); } dispc_runtime_put(); dss_runtime_put(); if (cpu_is_omap34xx()) regulator_disable(dpi.vdds_dsi_reg); omap_dss_stop_device(dssdev); } EXPORT_SYMBOL(omapdss_dpi_display_disable); void dpi_set_timings(struct omap_dss_device *dssdev, struct omap_video_timings *timings) { int r; DSSDBG("dpi_set_timings\n"); dssdev->panel.timings = *timings; if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { r = dss_runtime_get(); if (r) return; r = dispc_runtime_get(); if (r) { dss_runtime_put(); return; } dpi_set_mode(dssdev); dispc_mgr_go(dssdev->manager->id); dispc_runtime_put(); dss_runtime_put(); } } EXPORT_SYMBOL(dpi_set_timings); int dpi_check_timings(struct omap_dss_device *dssdev, struct omap_video_timings *timings) { bool is_tft; int r; int lck_div, pck_div; unsigned long fck; unsigned long pck; struct dispc_clock_info dispc_cinfo; if (!dispc_lcd_timings_ok(timings)) return -EINVAL; if (timings->pixel_clock == 0) return -EINVAL; is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0; if (dpi_use_dsi_pll(dssdev)) { struct dsi_clock_info dsi_cinfo; r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft, timings->pixel_clock * 1000, &dsi_cinfo, &dispc_cinfo); if (r) return r; fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk; } else { struct dss_clock_info dss_cinfo; r = dss_calc_clock_div(is_tft, timings->pixel_clock * 1000, &dss_cinfo, &dispc_cinfo); if (r) return r; fck = dss_cinfo.fck; } lck_div = dispc_cinfo.lck_div; pck_div = dispc_cinfo.pck_div; pck = fck / lck_div / pck_div / 1000; timings->pixel_clock = pck; return 0; } EXPORT_SYMBOL(dpi_check_timings); int dpi_init_display(struct omap_dss_device *dssdev) { DSSDBG("init_display\n"); if (cpu_is_omap34xx() && dpi.vdds_dsi_reg == NULL) { struct regulator *vdds_dsi; vdds_dsi = dss_get_vdds_dsi(); if (IS_ERR(vdds_dsi)) { DSSERR("can't get VDDS_DSI regulator\n"); return PTR_ERR(vdds_dsi); } dpi.vdds_dsi_reg = vdds_dsi; } if (dpi_use_dsi_pll(dssdev)) { enum omap_dss_clk_source dispc_fclk_src = dssdev->clocks.dispc.dispc_fclk_src; dpi.dsidev = dpi_get_dsidev(dispc_fclk_src); } return 0; } int dpi_init(void) { return 0; } void dpi_exit(void) { }
jfdsmabalot/kernel_legacy_exynos5410
drivers/video/omap2/dss/dpi.c
C
gpl-2.0
8,459
/* Thai initialisation for the jQuery UI date picker plugin. */ /* Written by pipo (pipo@sixhead.com). */ jQuery(function($){ $.datepicker.regional['th'] = { closeText: 'ปิด', prevText: '&#xAB;&#xA0;ย้อน', nextText: 'ถัดไป&#xA0;&#xBB;', currentText: 'วันนี้', monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน', 'กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'], monthNamesShort: ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.', 'ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.'], dayNames: ['อาทิตย์','จันทร์','อังคาร','พุธ','พฤหัสบดี','ศุกร์','เสาร์'], dayNamesShort: ['อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'], dayNamesMin: ['อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'], weekHeader: 'Wk', dateFormat: 'dd/mm/yy', firstDay: 0, isRTL: false, showMonthAfterYear: false, yearSuffix: ''}; $.datepicker.setDefaults($.datepicker.regional['th']); });
chrisatwebis/bannerq
sites/all/modules/contrib/jquery_update/replace/ui/ui/i18n/jquery.ui.datepicker-th.js
JavaScript
gpl-2.0
1,274
/* * i2c-pca-isa.c driver for PCA9564 on ISA boards * Copyright (C) 2004 Arcom Control Systems * Copyright (C) 2008 Pengutronix * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/kernel.h> #include <linux/ioport.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/delay.h> #include <linux/jiffies.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/wait.h> #include <linux/isa.h> #include <linux/i2c.h> #include <linux/i2c-algo-pca.h> #include <linux/io.h> #include <asm/irq.h> #define DRIVER "i2c-pca-isa" #define IO_SIZE 4 static unsigned long base; static int irq = -1; /* Data sheet recommends 59kHz for 100kHz operation due to variation * in the actual clock rate */ static int clock = 59000; static struct i2c_adapter pca_isa_ops; static wait_queue_head_t pca_wait; static void pca_isa_writebyte(void *pd, int reg, int val) { #ifdef DEBUG_IO static char *names[] = { "T/O", "DAT", "ADR", "CON" }; printk(KERN_DEBUG "*** write %s at %#lx <= %#04x\n", names[reg], base+reg, val); #endif outb(val, base+reg); } static int pca_isa_readbyte(void *pd, int reg) { int res = inb(base+reg); #ifdef DEBUG_IO { static char *names[] = { "STA", "DAT", "ADR", "CON" }; printk(KERN_DEBUG "*** read %s => %#04x\n", names[reg], res); } #endif return res; } static int pca_isa_waitforcompletion(void *pd) { unsigned long timeout; long ret; if (irq > -1) { ret = wait_event_timeout(pca_wait, pca_isa_readbyte(pd, I2C_PCA_CON) & I2C_PCA_CON_SI, pca_isa_ops.timeout); } else { /* Do polling */ timeout = jiffies + pca_isa_ops.timeout; do { ret = time_before(jiffies, timeout); if (pca_isa_readbyte(pd, I2C_PCA_CON) & I2C_PCA_CON_SI) break; udelay(100); } while (ret); } return ret > 0; } static void pca_isa_resetchip(void *pd) { /* apparently only an external reset will do it. not a lot can be done */ printk(KERN_WARNING DRIVER ": Haven't figured out how to do a reset yet\n"); } static irqreturn_t pca_handler(int this_irq, void *dev_id) { wake_up(&pca_wait); return IRQ_HANDLED; } static struct i2c_algo_pca_data pca_isa_data = { /* .data intentionally left NULL, not needed with ISA */ .write_byte = pca_isa_writebyte, .read_byte = pca_isa_readbyte, .wait_for_completion = pca_isa_waitforcompletion, .reset_chip = pca_isa_resetchip, }; static struct i2c_adapter pca_isa_ops = { .owner = THIS_MODULE, .algo_data = &pca_isa_data, .name = "PCA9564/PCA9665 ISA Adapter", .timeout = HZ, }; static int __devinit pca_isa_match(struct device *dev, unsigned int id) { int match = base != 0; if (match) { if (irq <= -1) dev_warn(dev, "Using polling mode (specify irq)\n"); } else dev_err(dev, "Please specify I/O base\n"); return match; } static int __devinit pca_isa_probe(struct device *dev, unsigned int id) { init_waitqueue_head(&pca_wait); dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq); #ifdef CONFIG_PPC if (check_legacy_ioport(base)) { dev_err(dev, "I/O address %#08lx is not available\n", base); goto out; } #endif if (!request_region(base, IO_SIZE, "i2c-pca-isa")) { dev_err(dev, "I/O address %#08lx is in use\n", base); goto out; } if (irq > -1) { if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) { dev_err(dev, "Request irq%d failed\n", irq); goto out_region; } } pca_isa_data.i2c_clock = clock; if (i2c_pca_add_bus(&pca_isa_ops) < 0) { dev_err(dev, "Failed to add i2c bus\n"); goto out_irq; } return 0; out_irq: if (irq > -1) free_irq(irq, &pca_isa_ops); out_region: release_region(base, IO_SIZE); out: return -ENODEV; } static int __devexit pca_isa_remove(struct device *dev, unsigned int id) { i2c_del_adapter(&pca_isa_ops); if (irq > -1) { disable_irq(irq); free_irq(irq, &pca_isa_ops); } release_region(base, IO_SIZE); return 0; } static struct isa_driver pca_isa_driver = { .match = pca_isa_match, .probe = pca_isa_probe, .remove = __devexit_p(pca_isa_remove), .driver = { .owner = THIS_MODULE, .name = DRIVER, } }; static int __init pca_isa_init(void) { return isa_register_driver(&pca_isa_driver, 1); } static void __exit pca_isa_exit(void) { isa_unregister_driver(&pca_isa_driver); } MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); MODULE_DESCRIPTION("ISA base PCA9564/PCA9665 driver"); MODULE_LICENSE("GPL"); module_param(base, ulong, 0); MODULE_PARM_DESC(base, "I/O base address"); module_param(irq, int, 0); MODULE_PARM_DESC(irq, "IRQ"); module_param(clock, int, 0); MODULE_PARM_DESC(clock, "Clock rate in hertz.\n\t\t" "For PCA9564: 330000,288000,217000,146000," "88000,59000,44000,36000\n" "\t\tFor PCA9665:\tStandard: 60300 - 100099\n" "\t\t\t\tFast: 100100 - 400099\n" "\t\t\t\tFast+: 400100 - 10000099\n" "\t\t\t\tTurbo: Up to 1265800"); module_init(pca_isa_init); module_exit(pca_isa_exit);
TeamRegular/android_kernel_samsung_exynos5420
drivers/i2c/busses/i2c-pca-isa.c
C
gpl-2.0
5,584
/* ppc-opc.c -- PowerPC opcode list Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Written by Ian Lance Taylor, Cygnus Support This file is part of GDB, GAS, and the GNU binutils. GDB, GAS, and the GNU binutils are free software; you can redistribute them and/or modify them under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GDB, GAS, and the GNU binutils are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this file; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ #include <linux/stddef.h> #include <linux/kernel.h> #include <linux/bug.h> #include "nonstdio.h" #include "ppc.h" #define ATTRIBUTE_UNUSED #define _(x) x /* This file holds the PowerPC opcode table. The opcode table includes almost all of the extended instruction mnemonics. This permits the disassembler to use them, and simplifies the assembler logic, at the cost of increasing the table size. The table is strictly constant data, so the compiler should be able to put it in the .text section. This file also holds the operand table. All knowledge about inserting operands into instructions and vice-versa is kept in this file. */ /* Local insertion and extraction functions. */ static unsigned long insert_bat (unsigned long, long, int, const char **); static long extract_bat (unsigned long, int, int *); static unsigned long insert_bba (unsigned long, long, int, const char **); static long extract_bba (unsigned long, int, int *); static unsigned long insert_bd (unsigned long, long, int, const char **); static long extract_bd (unsigned long, int, int *); static unsigned long insert_bdm (unsigned long, long, int, const char **); static long extract_bdm (unsigned long, int, int *); static unsigned long insert_bdp (unsigned long, long, int, const char **); static long extract_bdp (unsigned long, int, int *); static unsigned long insert_bo (unsigned long, long, int, const char **); static long extract_bo (unsigned long, int, int *); static unsigned long insert_boe (unsigned long, long, int, const char **); static long extract_boe (unsigned long, int, int *); static unsigned long insert_dq (unsigned long, long, int, const char **); static long extract_dq (unsigned long, int, int *); static unsigned long insert_ds (unsigned long, long, int, const char **); static long extract_ds (unsigned long, int, int *); static unsigned long insert_de (unsigned long, long, int, const char **); static long extract_de (unsigned long, int, int *); static unsigned long insert_des (unsigned long, long, int, const char **); static long extract_des (unsigned long, int, int *); static unsigned long insert_fxm (unsigned long, long, int, const char **); static long extract_fxm (unsigned long, int, int *); static unsigned long insert_li (unsigned long, long, int, const char **); static long extract_li (unsigned long, int, int *); static unsigned long insert_mbe (unsigned long, long, int, const char **); static long extract_mbe (unsigned long, int, int *); static unsigned long insert_mb6 (unsigned long, long, int, const char **); static long extract_mb6 (unsigned long, int, int *); static unsigned long insert_nb (unsigned long, long, int, const char **); static long extract_nb (unsigned long, int, int *); static unsigned long insert_nsi (unsigned long, long, int, const char **); static long extract_nsi (unsigned long, int, int *); static unsigned long insert_ral (unsigned long, long, int, const char **); static unsigned long insert_ram (unsigned long, long, int, const char **); static unsigned long insert_raq (unsigned long, long, int, const char **); static unsigned long insert_ras (unsigned long, long, int, const char **); static unsigned long insert_rbs (unsigned long, long, int, const char **); static long extract_rbs (unsigned long, int, int *); static unsigned long insert_rsq (unsigned long, long, int, const char **); static unsigned long insert_rtq (unsigned long, long, int, const char **); static unsigned long insert_sh6 (unsigned long, long, int, const char **); static long extract_sh6 (unsigned long, int, int *); static unsigned long insert_spr (unsigned long, long, int, const char **); static long extract_spr (unsigned long, int, int *); static unsigned long insert_sprg (unsigned long, long, int, const char **); static long extract_sprg (unsigned long, int, int *); static unsigned long insert_tbr (unsigned long, long, int, const char **); static long extract_tbr (unsigned long, int, int *); static unsigned long insert_ev2 (unsigned long, long, int, const char **); static long extract_ev2 (unsigned long, int, int *); static unsigned long insert_ev4 (unsigned long, long, int, const char **); static long extract_ev4 (unsigned long, int, int *); static unsigned long insert_ev8 (unsigned long, long, int, const char **); static long extract_ev8 (unsigned long, int, int *); /* The operands table. The fields are bits, shift, insert, extract, flags. We used to put parens around the various additions, like the one for BA just below. However, that caused trouble with feeble compilers with a limit on depth of a parenthesized expression, like (reportedly) the compiler in Microsoft Developer Studio 5. So we omit the parens, since the macros are never used in a context where the addition will be ambiguous. */ const struct powerpc_operand powerpc_operands[] = { /* The zero index is used to indicate the end of the list of operands. */ #define UNUSED 0 { 0, 0, NULL, NULL, 0 }, /* The BA field in an XL form instruction. */ #define BA UNUSED + 1 #define BA_MASK (0x1f << 16) { 5, 16, NULL, NULL, PPC_OPERAND_CR }, /* The BA field in an XL form instruction when it must be the same as the BT field in the same instruction. */ #define BAT BA + 1 { 5, 16, insert_bat, extract_bat, PPC_OPERAND_FAKE }, /* The BB field in an XL form instruction. */ #define BB BAT + 1 #define BB_MASK (0x1f << 11) { 5, 11, NULL, NULL, PPC_OPERAND_CR }, /* The BB field in an XL form instruction when it must be the same as the BA field in the same instruction. */ #define BBA BB + 1 { 5, 11, insert_bba, extract_bba, PPC_OPERAND_FAKE }, /* The BD field in a B form instruction. The lower two bits are forced to zero. */ #define BD BBA + 1 { 16, 0, insert_bd, extract_bd, PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED }, /* The BD field in a B form instruction when absolute addressing is used. */ #define BDA BD + 1 { 16, 0, insert_bd, extract_bd, PPC_OPERAND_ABSOLUTE | PPC_OPERAND_SIGNED }, /* The BD field in a B form instruction when the - modifier is used. This sets the y bit of the BO field appropriately. */ #define BDM BDA + 1 { 16, 0, insert_bdm, extract_bdm, PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED }, /* The BD field in a B form instruction when the - modifier is used and absolute address is used. */ #define BDMA BDM + 1 { 16, 0, insert_bdm, extract_bdm, PPC_OPERAND_ABSOLUTE | PPC_OPERAND_SIGNED }, /* The BD field in a B form instruction when the + modifier is used. This sets the y bit of the BO field appropriately. */ #define BDP BDMA + 1 { 16, 0, insert_bdp, extract_bdp, PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED }, /* The BD field in a B form instruction when the + modifier is used and absolute addressing is used. */ #define BDPA BDP + 1 { 16, 0, insert_bdp, extract_bdp, PPC_OPERAND_ABSOLUTE | PPC_OPERAND_SIGNED }, /* The BF field in an X or XL form instruction. */ #define BF BDPA + 1 { 3, 23, NULL, NULL, PPC_OPERAND_CR }, /* An optional BF field. This is used for comparison instructions, in which an omitted BF field is taken as zero. */ #define OBF BF + 1 { 3, 23, NULL, NULL, PPC_OPERAND_CR | PPC_OPERAND_OPTIONAL }, /* The BFA field in an X or XL form instruction. */ #define BFA OBF + 1 { 3, 18, NULL, NULL, PPC_OPERAND_CR }, /* The BI field in a B form or XL form instruction. */ #define BI BFA + 1 #define BI_MASK (0x1f << 16) { 5, 16, NULL, NULL, PPC_OPERAND_CR }, /* The BO field in a B form instruction. Certain values are illegal. */ #define BO BI + 1 #define BO_MASK (0x1f << 21) { 5, 21, insert_bo, extract_bo, 0 }, /* The BO field in a B form instruction when the + or - modifier is used. This is like the BO field, but it must be even. */ #define BOE BO + 1 { 5, 21, insert_boe, extract_boe, 0 }, #define BH BOE + 1 { 2, 11, NULL, NULL, PPC_OPERAND_OPTIONAL }, /* The BT field in an X or XL form instruction. */ #define BT BH + 1 { 5, 21, NULL, NULL, PPC_OPERAND_CR }, /* The condition register number portion of the BI field in a B form or XL form instruction. This is used for the extended conditional branch mnemonics, which set the lower two bits of the BI field. This field is optional. */ #define CR BT + 1 { 3, 18, NULL, NULL, PPC_OPERAND_CR | PPC_OPERAND_OPTIONAL }, /* The CRB field in an X form instruction. */ #define CRB CR + 1 { 5, 6, NULL, NULL, 0 }, /* The CRFD field in an X form instruction. */ #define CRFD CRB + 1 { 3, 23, NULL, NULL, PPC_OPERAND_CR }, /* The CRFS field in an X form instruction. */ #define CRFS CRFD + 1 { 3, 0, NULL, NULL, PPC_OPERAND_CR }, /* The CT field in an X form instruction. */ #define CT CRFS + 1 { 5, 21, NULL, NULL, PPC_OPERAND_OPTIONAL }, /* The D field in a D form instruction. This is a displacement off a register, and implies that the next operand is a register in parentheses. */ #define D CT + 1 { 16, 0, NULL, NULL, PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED }, /* The DE field in a DE form instruction. This is like D, but is 12 bits only. */ #define DE D + 1 { 14, 0, insert_de, extract_de, PPC_OPERAND_PARENS }, /* The DES field in a DES form instruction. This is like DS, but is 14 bits only (12 stored.) */ #define DES DE + 1 { 14, 0, insert_des, extract_des, PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED }, /* The DQ field in a DQ form instruction. This is like D, but the lower four bits are forced to zero. */ #define DQ DES + 1 { 16, 0, insert_dq, extract_dq, PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED | PPC_OPERAND_DQ }, /* The DS field in a DS form instruction. This is like D, but the lower two bits are forced to zero. */ #define DS DQ + 1 { 16, 0, insert_ds, extract_ds, PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED | PPC_OPERAND_DS }, /* The E field in a wrteei instruction. */ #define E DS + 1 { 1, 15, NULL, NULL, 0 }, /* The FL1 field in a POWER SC form instruction. */ #define FL1 E + 1 { 4, 12, NULL, NULL, 0 }, /* The FL2 field in a POWER SC form instruction. */ #define FL2 FL1 + 1 { 3, 2, NULL, NULL, 0 }, /* The FLM field in an XFL form instruction. */ #define FLM FL2 + 1 { 8, 17, NULL, NULL, 0 }, /* The FRA field in an X or A form instruction. */ #define FRA FLM + 1 #define FRA_MASK (0x1f << 16) { 5, 16, NULL, NULL, PPC_OPERAND_FPR }, /* The FRB field in an X or A form instruction. */ #define FRB FRA + 1 #define FRB_MASK (0x1f << 11) { 5, 11, NULL, NULL, PPC_OPERAND_FPR }, /* The FRC field in an A form instruction. */ #define FRC FRB + 1 #define FRC_MASK (0x1f << 6) { 5, 6, NULL, NULL, PPC_OPERAND_FPR }, /* The FRS field in an X form instruction or the FRT field in a D, X or A form instruction. */ #define FRS FRC + 1 #define FRT FRS { 5, 21, NULL, NULL, PPC_OPERAND_FPR }, /* The FXM field in an XFX instruction. */ #define FXM FRS + 1 #define FXM_MASK (0xff << 12) { 8, 12, insert_fxm, extract_fxm, 0 }, /* Power4 version for mfcr. */ #define FXM4 FXM + 1 { 8, 12, insert_fxm, extract_fxm, PPC_OPERAND_OPTIONAL }, /* The L field in a D or X form instruction. */ #define L FXM4 + 1 { 1, 21, NULL, NULL, PPC_OPERAND_OPTIONAL }, /* The LEV field in a POWER SVC form instruction. */ #define SVC_LEV L + 1 { 7, 5, NULL, NULL, 0 }, /* The LEV field in an SC form instruction. */ #define LEV SVC_LEV + 1 { 7, 5, NULL, NULL, PPC_OPERAND_OPTIONAL }, /* The LI field in an I form instruction. The lower two bits are forced to zero. */ #define LI LEV + 1 { 26, 0, insert_li, extract_li, PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED }, /* The LI field in an I form instruction when used as an absolute address. */ #define LIA LI + 1 { 26, 0, insert_li, extract_li, PPC_OPERAND_ABSOLUTE | PPC_OPERAND_SIGNED }, /* The LS field in an X (sync) form instruction. */ #define LS LIA + 1 { 2, 21, NULL, NULL, PPC_OPERAND_OPTIONAL }, /* The MB field in an M form instruction. */ #define MB LS + 1 #define MB_MASK (0x1f << 6) { 5, 6, NULL, NULL, 0 }, /* The ME field in an M form instruction. */ #define ME MB + 1 #define ME_MASK (0x1f << 1) { 5, 1, NULL, NULL, 0 }, /* The MB and ME fields in an M form instruction expressed a single operand which is a bitmask indicating which bits to select. This is a two operand form using PPC_OPERAND_NEXT. See the description in opcode/ppc.h for what this means. */ #define MBE ME + 1 { 5, 6, NULL, NULL, PPC_OPERAND_OPTIONAL | PPC_OPERAND_NEXT }, { 32, 0, insert_mbe, extract_mbe, 0 }, /* The MB or ME field in an MD or MDS form instruction. The high bit is wrapped to the low end. */ #define MB6 MBE + 2 #define ME6 MB6 #define MB6_MASK (0x3f << 5) { 6, 5, insert_mb6, extract_mb6, 0 }, /* The MO field in an mbar instruction. */ #define MO MB6 + 1 { 5, 21, NULL, NULL, PPC_OPERAND_OPTIONAL }, /* The NB field in an X form instruction. The value 32 is stored as 0. */ #define NB MO + 1 { 6, 11, insert_nb, extract_nb, 0 }, /* The NSI field in a D form instruction. This is the same as the SI field, only negated. */ #define NSI NB + 1 { 16, 0, insert_nsi, extract_nsi, PPC_OPERAND_NEGATIVE | PPC_OPERAND_SIGNED }, /* The RA field in an D, DS, DQ, X, XO, M, or MDS form instruction. */ #define RA NSI + 1 #define RA_MASK (0x1f << 16) { 5, 16, NULL, NULL, PPC_OPERAND_GPR }, /* As above, but 0 in the RA field means zero, not r0. */ #define RA0 RA + 1 { 5, 16, NULL, NULL, PPC_OPERAND_GPR_0 }, /* The RA field in the DQ form lq instruction, which has special value restrictions. */ #define RAQ RA0 + 1 { 5, 16, insert_raq, NULL, PPC_OPERAND_GPR_0 }, /* The RA field in a D or X form instruction which is an updating load, which means that the RA field may not be zero and may not equal the RT field. */ #define RAL RAQ + 1 { 5, 16, insert_ral, NULL, PPC_OPERAND_GPR_0 }, /* The RA field in an lmw instruction, which has special value restrictions. */ #define RAM RAL + 1 { 5, 16, insert_ram, NULL, PPC_OPERAND_GPR_0 }, /* The RA field in a D or X form instruction which is an updating store or an updating floating point load, which means that the RA field may not be zero. */ #define RAS RAM + 1 { 5, 16, insert_ras, NULL, PPC_OPERAND_GPR_0 }, /* The RA field of the tlbwe instruction, which is optional. */ #define RAOPT RAS + 1 { 5, 16, NULL, NULL, PPC_OPERAND_GPR | PPC_OPERAND_OPTIONAL }, /* The RB field in an X, XO, M, or MDS form instruction. */ #define RB RAOPT + 1 #define RB_MASK (0x1f << 11) { 5, 11, NULL, NULL, PPC_OPERAND_GPR }, /* The RB field in an X form instruction when it must be the same as the RS field in the instruction. This is used for extended mnemonics like mr. */ #define RBS RB + 1 { 5, 1, insert_rbs, extract_rbs, PPC_OPERAND_FAKE }, /* The RS field in a D, DS, X, XFX, XS, M, MD or MDS form instruction or the RT field in a D, DS, X, XFX or XO form instruction. */ #define RS RBS + 1 #define RT RS #define RT_MASK (0x1f << 21) { 5, 21, NULL, NULL, PPC_OPERAND_GPR }, /* The RS field of the DS form stq instruction, which has special value restrictions. */ #define RSQ RS + 1 { 5, 21, insert_rsq, NULL, PPC_OPERAND_GPR_0 }, /* The RT field of the DQ form lq instruction, which has special value restrictions. */ #define RTQ RSQ + 1 { 5, 21, insert_rtq, NULL, PPC_OPERAND_GPR_0 }, /* The RS field of the tlbwe instruction, which is optional. */ #define RSO RTQ + 1 #define RTO RSO { 5, 21, NULL, NULL, PPC_OPERAND_GPR | PPC_OPERAND_OPTIONAL }, /* The SH field in an X or M form instruction. */ #define SH RSO + 1 #define SH_MASK (0x1f << 11) { 5, 11, NULL, NULL, 0 }, /* The SH field in an MD form instruction. This is split. */ #define SH6 SH + 1 #define SH6_MASK ((0x1f << 11) | (1 << 1)) { 6, 1, insert_sh6, extract_sh6, 0 }, /* The SH field of the tlbwe instruction, which is optional. */ #define SHO SH6 + 1 { 5, 11,NULL, NULL, PPC_OPERAND_OPTIONAL }, /* The SI field in a D form instruction. */ #define SI SHO + 1 { 16, 0, NULL, NULL, PPC_OPERAND_SIGNED }, /* The SI field in a D form instruction when we accept a wide range of positive values. */ #define SISIGNOPT SI + 1 { 16, 0, NULL, NULL, PPC_OPERAND_SIGNED | PPC_OPERAND_SIGNOPT }, /* The SPR field in an XFX form instruction. This is flipped--the lower 5 bits are stored in the upper 5 and vice- versa. */ #define SPR SISIGNOPT + 1 #define PMR SPR #define SPR_MASK (0x3ff << 11) { 10, 11, insert_spr, extract_spr, 0 }, /* The BAT index number in an XFX form m[ft]ibat[lu] instruction. */ #define SPRBAT SPR + 1 #define SPRBAT_MASK (0x3 << 17) { 2, 17, NULL, NULL, 0 }, /* The SPRG register number in an XFX form m[ft]sprg instruction. */ #define SPRG SPRBAT + 1 { 5, 16, insert_sprg, extract_sprg, 0 }, /* The SR field in an X form instruction. */ #define SR SPRG + 1 { 4, 16, NULL, NULL, 0 }, /* The STRM field in an X AltiVec form instruction. */ #define STRM SR + 1 #define STRM_MASK (0x3 << 21) { 2, 21, NULL, NULL, 0 }, /* The SV field in a POWER SC form instruction. */ #define SV STRM + 1 { 14, 2, NULL, NULL, 0 }, /* The TBR field in an XFX form instruction. This is like the SPR field, but it is optional. */ #define TBR SV + 1 { 10, 11, insert_tbr, extract_tbr, PPC_OPERAND_OPTIONAL }, /* The TO field in a D or X form instruction. */ #define TO TBR + 1 #define TO_MASK (0x1f << 21) { 5, 21, NULL, NULL, 0 }, /* The U field in an X form instruction. */ #define U TO + 1 { 4, 12, NULL, NULL, 0 }, /* The UI field in a D form instruction. */ #define UI U + 1 { 16, 0, NULL, NULL, 0 }, /* The VA field in a VA, VX or VXR form instruction. */ #define VA UI + 1 #define VA_MASK (0x1f << 16) { 5, 16, NULL, NULL, PPC_OPERAND_VR }, /* The VB field in a VA, VX or VXR form instruction. */ #define VB VA + 1 #define VB_MASK (0x1f << 11) { 5, 11, NULL, NULL, PPC_OPERAND_VR }, /* The VC field in a VA form instruction. */ #define VC VB + 1 #define VC_MASK (0x1f << 6) { 5, 6, NULL, NULL, PPC_OPERAND_VR }, /* The VD or VS field in a VA, VX, VXR or X form instruction. */ #define VD VC + 1 #define VS VD #define VD_MASK (0x1f << 21) { 5, 21, NULL, NULL, PPC_OPERAND_VR }, /* The SIMM field in a VX form instruction. */ #define SIMM VD + 1 { 5, 16, NULL, NULL, PPC_OPERAND_SIGNED}, /* The UIMM field in a VX form instruction. */ #define UIMM SIMM + 1 { 5, 16, NULL, NULL, 0 }, /* The SHB field in a VA form instruction. */ #define SHB UIMM + 1 { 4, 6, NULL, NULL, 0 }, /* The other UIMM field in a EVX form instruction. */ #define EVUIMM SHB + 1 { 5, 11, NULL, NULL, 0 }, /* The other UIMM field in a half word EVX form instruction. */ #define EVUIMM_2 EVUIMM + 1 { 32, 11, insert_ev2, extract_ev2, PPC_OPERAND_PARENS }, /* The other UIMM field in a word EVX form instruction. */ #define EVUIMM_4 EVUIMM_2 + 1 { 32, 11, insert_ev4, extract_ev4, PPC_OPERAND_PARENS }, /* The other UIMM field in a double EVX form instruction. */ #define EVUIMM_8 EVUIMM_4 + 1 { 32, 11, insert_ev8, extract_ev8, PPC_OPERAND_PARENS }, /* The WS field. */ #define WS EVUIMM_8 + 1 #define WS_MASK (0x7 << 11) { 3, 11, NULL, NULL, 0 }, /* The L field in an mtmsrd or A form instruction. */ #define MTMSRD_L WS + 1 #define A_L MTMSRD_L { 1, 16, NULL, NULL, PPC_OPERAND_OPTIONAL }, /* The DCM field in a Z form instruction. */ #define DCM MTMSRD_L + 1 { 6, 16, NULL, NULL, 0 }, /* Likewise, the DGM field in a Z form instruction. */ #define DGM DCM + 1 { 6, 16, NULL, NULL, 0 }, #define TE DGM + 1 { 5, 11, NULL, NULL, 0 }, #define RMC TE + 1 { 2, 21, NULL, NULL, 0 }, #define R RMC + 1 { 1, 15, NULL, NULL, 0 }, #define SP R + 1 { 2, 11, NULL, NULL, 0 }, #define S SP + 1 { 1, 11, NULL, NULL, 0 }, /* SH field starting at bit position 16. */ #define SH16 S + 1 { 6, 10, NULL, NULL, 0 }, /* The L field in an X form with the RT field fixed instruction. */ #define XRT_L SH16 + 1 { 2, 21, NULL, NULL, PPC_OPERAND_OPTIONAL }, /* The EH field in larx instruction. */ #define EH XRT_L + 1 { 1, 0, NULL, NULL, PPC_OPERAND_OPTIONAL }, }; /* The functions used to insert and extract complicated operands. */ /* The BA field in an XL form instruction when it must be the same as the BT field in the same instruction. This operand is marked FAKE. The insertion function just copies the BT field into the BA field, and the extraction function just checks that the fields are the same. */ static unsigned long insert_bat (unsigned long insn, long value ATTRIBUTE_UNUSED, int dialect ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED) { return insn | (((insn >> 21) & 0x1f) << 16); } static long extract_bat (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid) { if (((insn >> 21) & 0x1f) != ((insn >> 16) & 0x1f)) *invalid = 1; return 0; } /* The BB field in an XL form instruction when it must be the same as the BA field in the same instruction. This operand is marked FAKE. The insertion function just copies the BA field into the BB field, and the extraction function just checks that the fields are the same. */ static unsigned long insert_bba (unsigned long insn, long value ATTRIBUTE_UNUSED, int dialect ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED) { return insn | (((insn >> 16) & 0x1f) << 11); } static long extract_bba (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid) { if (((insn >> 16) & 0x1f) != ((insn >> 11) & 0x1f)) *invalid = 1; return 0; } /* The BD field in a B form instruction. The lower two bits are forced to zero. */ static unsigned long insert_bd (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED) { return insn | (value & 0xfffc); } static long extract_bd (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return ((insn & 0xfffc) ^ 0x8000) - 0x8000; } /* The BD field in a B form instruction when the - modifier is used. This modifier means that the branch is not expected to be taken. For chips built to versions of the architecture prior to version 2 (ie. not Power4 compatible), we set the y bit of the BO field to 1 if the offset is negative. When extracting, we require that the y bit be 1 and that the offset be positive, since if the y bit is 0 we just want to print the normal form of the instruction. Power4 compatible targets use two bits, "a", and "t", instead of the "y" bit. "at" == 00 => no hint, "at" == 01 => unpredictable, "at" == 10 => not taken, "at" == 11 => taken. The "t" bit is 00001 in BO field, the "a" bit is 00010 for branch on CR(BI) and 01000 for branch on CTR. We only handle the taken/not-taken hint here. */ static unsigned long insert_bdm (unsigned long insn, long value, int dialect, const char **errmsg ATTRIBUTE_UNUSED) { if ((dialect & PPC_OPCODE_POWER4) == 0) { if ((value & 0x8000) != 0) insn |= 1 << 21; } else { if ((insn & (0x14 << 21)) == (0x04 << 21)) insn |= 0x02 << 21; else if ((insn & (0x14 << 21)) == (0x10 << 21)) insn |= 0x08 << 21; } return insn | (value & 0xfffc); } static long extract_bdm (unsigned long insn, int dialect, int *invalid) { if ((dialect & PPC_OPCODE_POWER4) == 0) { if (((insn & (1 << 21)) == 0) != ((insn & (1 << 15)) == 0)) *invalid = 1; } else { if ((insn & (0x17 << 21)) != (0x06 << 21) && (insn & (0x1d << 21)) != (0x18 << 21)) *invalid = 1; } return ((insn & 0xfffc) ^ 0x8000) - 0x8000; } /* The BD field in a B form instruction when the + modifier is used. This is like BDM, above, except that the branch is expected to be taken. */ static unsigned long insert_bdp (unsigned long insn, long value, int dialect, const char **errmsg ATTRIBUTE_UNUSED) { if ((dialect & PPC_OPCODE_POWER4) == 0) { if ((value & 0x8000) == 0) insn |= 1 << 21; } else { if ((insn & (0x14 << 21)) == (0x04 << 21)) insn |= 0x03 << 21; else if ((insn & (0x14 << 21)) == (0x10 << 21)) insn |= 0x09 << 21; } return insn | (value & 0xfffc); } static long extract_bdp (unsigned long insn, int dialect, int *invalid) { if ((dialect & PPC_OPCODE_POWER4) == 0) { if (((insn & (1 << 21)) == 0) == ((insn & (1 << 15)) == 0)) *invalid = 1; } else { if ((insn & (0x17 << 21)) != (0x07 << 21) && (insn & (0x1d << 21)) != (0x19 << 21)) *invalid = 1; } return ((insn & 0xfffc) ^ 0x8000) - 0x8000; } /* Check for legal values of a BO field. */ static int valid_bo (long value, int dialect) { if ((dialect & PPC_OPCODE_POWER4) == 0) { /* Certain encodings have bits that are required to be zero. These are (z must be zero, y may be anything): 001zy 011zy 1z00y 1z01y 1z1zz */ switch (value & 0x14) { default: case 0: return 1; case 0x4: return (value & 0x2) == 0; case 0x10: return (value & 0x8) == 0; case 0x14: return value == 0x14; } } else { /* Certain encodings have bits that are required to be zero. These are (z must be zero, a & t may be anything): 0000z 0001z 0100z 0101z 001at 011at 1a00t 1a01t 1z1zz */ if ((value & 0x14) == 0) return (value & 0x1) == 0; else if ((value & 0x14) == 0x14) return value == 0x14; else return 1; } } /* The BO field in a B form instruction. Warn about attempts to set the field to an illegal value. */ static unsigned long insert_bo (unsigned long insn, long value, int dialect, const char **errmsg) { if (!valid_bo (value, dialect)) *errmsg = _("invalid conditional option"); return insn | ((value & 0x1f) << 21); } static long extract_bo (unsigned long insn, int dialect, int *invalid) { long value; value = (insn >> 21) & 0x1f; if (!valid_bo (value, dialect)) *invalid = 1; return value; } /* The BO field in a B form instruction when the + or - modifier is used. This is like the BO field, but it must be even. When extracting it, we force it to be even. */ static unsigned long insert_boe (unsigned long insn, long value, int dialect, const char **errmsg) { if (!valid_bo (value, dialect)) *errmsg = _("invalid conditional option"); else if ((value & 1) != 0) *errmsg = _("attempt to set y bit when using + or - modifier"); return insn | ((value & 0x1f) << 21); } static long extract_boe (unsigned long insn, int dialect, int *invalid) { long value; value = (insn >> 21) & 0x1f; if (!valid_bo (value, dialect)) *invalid = 1; return value & 0x1e; } /* The DQ field in a DQ form instruction. This is like D, but the lower four bits are forced to zero. */ static unsigned long insert_dq (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if ((value & 0xf) != 0) *errmsg = _("offset not a multiple of 16"); return insn | (value & 0xfff0); } static long extract_dq (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return ((insn & 0xfff0) ^ 0x8000) - 0x8000; } static unsigned long insert_ev2 (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if ((value & 1) != 0) *errmsg = _("offset not a multiple of 2"); if ((value > 62) != 0) *errmsg = _("offset greater than 62"); return insn | ((value & 0x3e) << 10); } static long extract_ev2 (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return (insn >> 10) & 0x3e; } static unsigned long insert_ev4 (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if ((value & 3) != 0) *errmsg = _("offset not a multiple of 4"); if ((value > 124) != 0) *errmsg = _("offset greater than 124"); return insn | ((value & 0x7c) << 9); } static long extract_ev4 (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return (insn >> 9) & 0x7c; } static unsigned long insert_ev8 (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if ((value & 7) != 0) *errmsg = _("offset not a multiple of 8"); if ((value > 248) != 0) *errmsg = _("offset greater than 248"); return insn | ((value & 0xf8) << 8); } static long extract_ev8 (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return (insn >> 8) & 0xf8; } /* The DS field in a DS form instruction. This is like D, but the lower two bits are forced to zero. */ static unsigned long insert_ds (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if ((value & 3) != 0) *errmsg = _("offset not a multiple of 4"); return insn | (value & 0xfffc); } static long extract_ds (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return ((insn & 0xfffc) ^ 0x8000) - 0x8000; } /* The DE field in a DE form instruction. */ static unsigned long insert_de (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if (value > 2047 || value < -2048) *errmsg = _("offset not between -2048 and 2047"); return insn | ((value << 4) & 0xfff0); } static long extract_de (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return (insn & 0xfff0) >> 4; } /* The DES field in a DES form instruction. */ static unsigned long insert_des (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if (value > 8191 || value < -8192) *errmsg = _("offset not between -8192 and 8191"); else if ((value & 3) != 0) *errmsg = _("offset not a multiple of 4"); return insn | ((value << 2) & 0xfff0); } static long extract_des (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return (((insn >> 2) & 0x3ffc) ^ 0x2000) - 0x2000; } /* FXM mask in mfcr and mtcrf instructions. */ static unsigned long insert_fxm (unsigned long insn, long value, int dialect, const char **errmsg) { /* If we're handling the mfocrf and mtocrf insns ensure that exactly one bit of the mask field is set. */ if ((insn & (1 << 20)) != 0) { if (value == 0 || (value & -value) != value) { *errmsg = _("invalid mask field"); value = 0; } } /* If the optional field on mfcr is missing that means we want to use the old form of the instruction that moves the whole cr. In that case we'll have VALUE zero. There doesn't seem to be a way to distinguish this from the case where someone writes mfcr %r3,0. */ else if (value == 0) ; /* If only one bit of the FXM field is set, we can use the new form of the instruction, which is faster. Unlike the Power4 branch hint encoding, this is not backward compatible. Do not generate the new form unless -mpower4 has been given, or -many and the two operand form of mfcr was used. */ else if ((value & -value) == value && ((dialect & PPC_OPCODE_POWER4) != 0 || ((dialect & PPC_OPCODE_ANY) != 0 && (insn & (0x3ff << 1)) == 19 << 1))) insn |= 1 << 20; /* Any other value on mfcr is an error. */ else if ((insn & (0x3ff << 1)) == 19 << 1) { *errmsg = _("ignoring invalid mfcr mask"); value = 0; } return insn | ((value & 0xff) << 12); } static long extract_fxm (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid) { long mask = (insn >> 12) & 0xff; /* Is this a Power4 insn? */ if ((insn & (1 << 20)) != 0) { /* Exactly one bit of MASK should be set. */ if (mask == 0 || (mask & -mask) != mask) *invalid = 1; } /* Check that non-power4 form of mfcr has a zero MASK. */ else if ((insn & (0x3ff << 1)) == 19 << 1) { if (mask != 0) *invalid = 1; } return mask; } /* The LI field in an I form instruction. The lower two bits are forced to zero. */ static unsigned long insert_li (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if ((value & 3) != 0) *errmsg = _("ignoring least significant bits in branch offset"); return insn | (value & 0x3fffffc); } static long extract_li (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return ((insn & 0x3fffffc) ^ 0x2000000) - 0x2000000; } /* The MB and ME fields in an M form instruction expressed as a single operand which is itself a bitmask. The extraction function always marks it as invalid, since we never want to recognize an instruction which uses a field of this type. */ static unsigned long insert_mbe (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { unsigned long uval, mask; int mb, me, mx, count, last; uval = value; if (uval == 0) { *errmsg = _("illegal bitmask"); return insn; } mb = 0; me = 32; if ((uval & 1) != 0) last = 1; else last = 0; count = 0; /* mb: location of last 0->1 transition */ /* me: location of last 1->0 transition */ /* count: # transitions */ for (mx = 0, mask = 1L << 31; mx < 32; ++mx, mask >>= 1) { if ((uval & mask) && !last) { ++count; mb = mx; last = 1; } else if (!(uval & mask) && last) { ++count; me = mx; last = 0; } } if (me == 0) me = 32; if (count != 2 && (count != 0 || ! last)) *errmsg = _("illegal bitmask"); return insn | (mb << 6) | ((me - 1) << 1); } static long extract_mbe (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid) { long ret; int mb, me; int i; *invalid = 1; mb = (insn >> 6) & 0x1f; me = (insn >> 1) & 0x1f; if (mb < me + 1) { ret = 0; for (i = mb; i <= me; i++) ret |= 1L << (31 - i); } else if (mb == me + 1) ret = ~0; else /* (mb > me + 1) */ { ret = ~0; for (i = me + 1; i < mb; i++) ret &= ~(1L << (31 - i)); } return ret; } /* The MB or ME field in an MD or MDS form instruction. The high bit is wrapped to the low end. */ static unsigned long insert_mb6 (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED) { return insn | ((value & 0x1f) << 6) | (value & 0x20); } static long extract_mb6 (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return ((insn >> 6) & 0x1f) | (insn & 0x20); } /* The NB field in an X form instruction. The value 32 is stored as 0. */ static unsigned long insert_nb (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if (value < 0 || value > 32) *errmsg = _("value out of range"); if (value == 32) value = 0; return insn | ((value & 0x1f) << 11); } static long extract_nb (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { long ret; ret = (insn >> 11) & 0x1f; if (ret == 0) ret = 32; return ret; } /* The NSI field in a D form instruction. This is the same as the SI field, only negated. The extraction function always marks it as invalid, since we never want to recognize an instruction which uses a field of this type. */ static unsigned long insert_nsi (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED) { return insn | (-value & 0xffff); } static long extract_nsi (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid) { *invalid = 1; return -(((insn & 0xffff) ^ 0x8000) - 0x8000); } /* The RA field in a D or X form instruction which is an updating load, which means that the RA field may not be zero and may not equal the RT field. */ static unsigned long insert_ral (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if (value == 0 || (unsigned long) value == ((insn >> 21) & 0x1f)) *errmsg = "invalid register operand when updating"; return insn | ((value & 0x1f) << 16); } /* The RA field in an lmw instruction, which has special value restrictions. */ static unsigned long insert_ram (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if ((unsigned long) value >= ((insn >> 21) & 0x1f)) *errmsg = _("index register in load range"); return insn | ((value & 0x1f) << 16); } /* The RA field in the DQ form lq instruction, which has special value restrictions. */ static unsigned long insert_raq (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { long rtvalue = (insn & RT_MASK) >> 21; if (value == rtvalue) *errmsg = _("source and target register operands must be different"); return insn | ((value & 0x1f) << 16); } /* The RA field in a D or X form instruction which is an updating store or an updating floating point load, which means that the RA field may not be zero. */ static unsigned long insert_ras (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if (value == 0) *errmsg = _("invalid register operand when updating"); return insn | ((value & 0x1f) << 16); } /* The RB field in an X form instruction when it must be the same as the RS field in the instruction. This is used for extended mnemonics like mr. This operand is marked FAKE. The insertion function just copies the BT field into the BA field, and the extraction function just checks that the fields are the same. */ static unsigned long insert_rbs (unsigned long insn, long value ATTRIBUTE_UNUSED, int dialect ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED) { return insn | (((insn >> 21) & 0x1f) << 11); } static long extract_rbs (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid) { if (((insn >> 21) & 0x1f) != ((insn >> 11) & 0x1f)) *invalid = 1; return 0; } /* The RT field of the DQ form lq instruction, which has special value restrictions. */ static unsigned long insert_rtq (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if ((value & 1) != 0) *errmsg = _("target register operand must be even"); return insn | ((value & 0x1f) << 21); } /* The RS field of the DS form stq instruction, which has special value restrictions. */ static unsigned long insert_rsq (unsigned long insn, long value ATTRIBUTE_UNUSED, int dialect ATTRIBUTE_UNUSED, const char **errmsg) { if ((value & 1) != 0) *errmsg = _("source register operand must be even"); return insn | ((value & 0x1f) << 21); } /* The SH field in an MD form instruction. This is split. */ static unsigned long insert_sh6 (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED) { return insn | ((value & 0x1f) << 11) | ((value & 0x20) >> 4); } static long extract_sh6 (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return ((insn >> 11) & 0x1f) | ((insn << 4) & 0x20); } /* The SPR field in an XFX form instruction. This is flipped--the lower 5 bits are stored in the upper 5 and vice- versa. */ static unsigned long insert_spr (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED) { return insn | ((value & 0x1f) << 16) | ((value & 0x3e0) << 6); } static long extract_spr (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { return ((insn >> 16) & 0x1f) | ((insn >> 6) & 0x3e0); } /* Some dialects have 8 SPRG registers instead of the standard 4. */ static unsigned long insert_sprg (unsigned long insn, long value, int dialect, const char **errmsg) { /* This check uses PPC_OPCODE_403 because PPC405 is later defined as a synonym. If ever a 405 specific dialect is added this check should use that instead. */ if (value > 7 || (value > 3 && (dialect & (PPC_OPCODE_BOOKE | PPC_OPCODE_403)) == 0)) *errmsg = _("invalid sprg number"); /* If this is mfsprg4..7 then use spr 260..263 which can be read in user mode. Anything else must use spr 272..279. */ if (value <= 3 || (insn & 0x100) != 0) value |= 0x10; return insn | ((value & 0x17) << 16); } static long extract_sprg (unsigned long insn, int dialect, int *invalid) { unsigned long val = (insn >> 16) & 0x1f; /* mfsprg can use 260..263 and 272..279. mtsprg only uses spr 272..279 If not BOOKE or 405, then both use only 272..275. */ if (val <= 3 || (val < 0x10 && (insn & 0x100) != 0) || (val - 0x10 > 3 && (dialect & (PPC_OPCODE_BOOKE | PPC_OPCODE_403)) == 0)) *invalid = 1; return val & 7; } /* The TBR field in an XFX instruction. This is just like SPR, but it is optional. When TBR is omitted, it must be inserted as 268 (the magic number of the TB register). These functions treat 0 (indicating an omitted optional operand) as 268. This means that ``mftb 4,0'' is not handled correctly. This does not matter very much, since the architecture manual does not define mftb as accepting any values other than 268 or 269. */ #define TB (268) static unsigned long insert_tbr (unsigned long insn, long value, int dialect ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED) { if (value == 0) value = TB; return insn | ((value & 0x1f) << 16) | ((value & 0x3e0) << 6); } static long extract_tbr (unsigned long insn, int dialect ATTRIBUTE_UNUSED, int *invalid ATTRIBUTE_UNUSED) { long ret; ret = ((insn >> 16) & 0x1f) | ((insn >> 6) & 0x3e0); if (ret == TB) ret = 0; return ret; } /* Macros used to form opcodes. */ /* The main opcode. */ #define OP(x) ((((unsigned long)(x)) & 0x3f) << 26) #define OP_MASK OP (0x3f) /* The main opcode combined with a trap code in the TO field of a D form instruction. Used for extended mnemonics for the trap instructions. */ #define OPTO(x,to) (OP (x) | ((((unsigned long)(to)) & 0x1f) << 21)) #define OPTO_MASK (OP_MASK | TO_MASK) /* The main opcode combined with a comparison size bit in the L field of a D form or X form instruction. Used for extended mnemonics for the comparison instructions. */ #define OPL(x,l) (OP (x) | ((((unsigned long)(l)) & 1) << 21)) #define OPL_MASK OPL (0x3f,1) /* An A form instruction. */ #define A(op, xop, rc) (OP (op) | ((((unsigned long)(xop)) & 0x1f) << 1) | (((unsigned long)(rc)) & 1)) #define A_MASK A (0x3f, 0x1f, 1) /* An A_MASK with the FRB field fixed. */ #define AFRB_MASK (A_MASK | FRB_MASK) /* An A_MASK with the FRC field fixed. */ #define AFRC_MASK (A_MASK | FRC_MASK) /* An A_MASK with the FRA and FRC fields fixed. */ #define AFRAFRC_MASK (A_MASK | FRA_MASK | FRC_MASK) /* An AFRAFRC_MASK, but with L bit clear. */ #define AFRALFRC_MASK (AFRAFRC_MASK & ~((unsigned long) 1 << 16)) /* A B form instruction. */ #define B(op, aa, lk) (OP (op) | ((((unsigned long)(aa)) & 1) << 1) | ((lk) & 1)) #define B_MASK B (0x3f, 1, 1) /* A B form instruction setting the BO field. */ #define BBO(op, bo, aa, lk) (B ((op), (aa), (lk)) | ((((unsigned long)(bo)) & 0x1f) << 21)) #define BBO_MASK BBO (0x3f, 0x1f, 1, 1) /* A BBO_MASK with the y bit of the BO field removed. This permits matching a conditional branch regardless of the setting of the y bit. Similarly for the 'at' bits used for power4 branch hints. */ #define Y_MASK (((unsigned long) 1) << 21) #define AT1_MASK (((unsigned long) 3) << 21) #define AT2_MASK (((unsigned long) 9) << 21) #define BBOY_MASK (BBO_MASK &~ Y_MASK) #define BBOAT_MASK (BBO_MASK &~ AT1_MASK) /* A B form instruction setting the BO field and the condition bits of the BI field. */ #define BBOCB(op, bo, cb, aa, lk) \ (BBO ((op), (bo), (aa), (lk)) | ((((unsigned long)(cb)) & 0x3) << 16)) #define BBOCB_MASK BBOCB (0x3f, 0x1f, 0x3, 1, 1) /* A BBOCB_MASK with the y bit of the BO field removed. */ #define BBOYCB_MASK (BBOCB_MASK &~ Y_MASK) #define BBOATCB_MASK (BBOCB_MASK &~ AT1_MASK) #define BBOAT2CB_MASK (BBOCB_MASK &~ AT2_MASK) /* A BBOYCB_MASK in which the BI field is fixed. */ #define BBOYBI_MASK (BBOYCB_MASK | BI_MASK) #define BBOATBI_MASK (BBOAT2CB_MASK | BI_MASK) /* An Context form instruction. */ #define CTX(op, xop) (OP (op) | (((unsigned long)(xop)) & 0x7)) #define CTX_MASK CTX(0x3f, 0x7) /* An User Context form instruction. */ #define UCTX(op, xop) (OP (op) | (((unsigned long)(xop)) & 0x1f)) #define UCTX_MASK UCTX(0x3f, 0x1f) /* The main opcode mask with the RA field clear. */ #define DRA_MASK (OP_MASK | RA_MASK) /* A DS form instruction. */ #define DSO(op, xop) (OP (op) | ((xop) & 0x3)) #define DS_MASK DSO (0x3f, 3) /* A DE form instruction. */ #define DEO(op, xop) (OP (op) | ((xop) & 0xf)) #define DE_MASK DEO (0x3e, 0xf) /* An EVSEL form instruction. */ #define EVSEL(op, xop) (OP (op) | (((unsigned long)(xop)) & 0xff) << 3) #define EVSEL_MASK EVSEL(0x3f, 0xff) /* An M form instruction. */ #define M(op, rc) (OP (op) | ((rc) & 1)) #define M_MASK M (0x3f, 1) /* An M form instruction with the ME field specified. */ #define MME(op, me, rc) (M ((op), (rc)) | ((((unsigned long)(me)) & 0x1f) << 1)) /* An M_MASK with the MB and ME fields fixed. */ #define MMBME_MASK (M_MASK | MB_MASK | ME_MASK) /* An M_MASK with the SH and ME fields fixed. */ #define MSHME_MASK (M_MASK | SH_MASK | ME_MASK) /* An MD form instruction. */ #define MD(op, xop, rc) (OP (op) | ((((unsigned long)(xop)) & 0x7) << 2) | ((rc) & 1)) #define MD_MASK MD (0x3f, 0x7, 1) /* An MD_MASK with the MB field fixed. */ #define MDMB_MASK (MD_MASK | MB6_MASK) /* An MD_MASK with the SH field fixed. */ #define MDSH_MASK (MD_MASK | SH6_MASK) /* An MDS form instruction. */ #define MDS(op, xop, rc) (OP (op) | ((((unsigned long)(xop)) & 0xf) << 1) | ((rc) & 1)) #define MDS_MASK MDS (0x3f, 0xf, 1) /* An MDS_MASK with the MB field fixed. */ #define MDSMB_MASK (MDS_MASK | MB6_MASK) /* An SC form instruction. */ #define SC(op, sa, lk) (OP (op) | ((((unsigned long)(sa)) & 1) << 1) | ((lk) & 1)) #define SC_MASK (OP_MASK | (((unsigned long)0x3ff) << 16) | (((unsigned long)1) << 1) | 1) /* An VX form instruction. */ #define VX(op, xop) (OP (op) | (((unsigned long)(xop)) & 0x7ff)) /* The mask for an VX form instruction. */ #define VX_MASK VX(0x3f, 0x7ff) /* An VA form instruction. */ #define VXA(op, xop) (OP (op) | (((unsigned long)(xop)) & 0x03f)) /* The mask for an VA form instruction. */ #define VXA_MASK VXA(0x3f, 0x3f) /* An VXR form instruction. */ #define VXR(op, xop, rc) (OP (op) | (((rc) & 1) << 10) | (((unsigned long)(xop)) & 0x3ff)) /* The mask for a VXR form instruction. */ #define VXR_MASK VXR(0x3f, 0x3ff, 1) /* An X form instruction. */ #define X(op, xop) (OP (op) | ((((unsigned long)(xop)) & 0x3ff) << 1)) /* A Z form instruction. */ #define Z(op, xop) (OP (op) | ((((unsigned long)(xop)) & 0x1ff) << 1)) /* An X form instruction with the RC bit specified. */ #define XRC(op, xop, rc) (X ((op), (xop)) | ((rc) & 1)) /* A Z form instruction with the RC bit specified. */ #define ZRC(op, xop, rc) (Z ((op), (xop)) | ((rc) & 1)) /* The mask for an X form instruction. */ #define X_MASK XRC (0x3f, 0x3ff, 1) /* The mask for a Z form instruction. */ #define Z_MASK ZRC (0x3f, 0x1ff, 1) /* An X_MASK with the RA field fixed. */ #define XRA_MASK (X_MASK | RA_MASK) /* An X_MASK with the RB field fixed. */ #define XRB_MASK (X_MASK | RB_MASK) /* An X_MASK with the RT field fixed. */ #define XRT_MASK (X_MASK | RT_MASK) /* An XRT_MASK mask with the L bits clear. */ #define XLRT_MASK (XRT_MASK & ~((unsigned long) 0x3 << 21)) /* An X_MASK with the RA and RB fields fixed. */ #define XRARB_MASK (X_MASK | RA_MASK | RB_MASK) /* An XRARB_MASK, but with the L bit clear. */ #define XRLARB_MASK (XRARB_MASK & ~((unsigned long) 1 << 16)) /* An X_MASK with the RT and RA fields fixed. */ #define XRTRA_MASK (X_MASK | RT_MASK | RA_MASK) /* An XRTRA_MASK, but with L bit clear. */ #define XRTLRA_MASK (XRTRA_MASK & ~((unsigned long) 1 << 21)) /* An X form instruction with the L bit specified. */ #define XOPL(op, xop, l) (X ((op), (xop)) | ((((unsigned long)(l)) & 1) << 21)) /* The mask for an X form comparison instruction. */ #define XCMP_MASK (X_MASK | (((unsigned long)1) << 22)) /* The mask for an X form comparison instruction with the L field fixed. */ #define XCMPL_MASK (XCMP_MASK | (((unsigned long)1) << 21)) /* An X form trap instruction with the TO field specified. */ #define XTO(op, xop, to) (X ((op), (xop)) | ((((unsigned long)(to)) & 0x1f) << 21)) #define XTO_MASK (X_MASK | TO_MASK) /* An X form tlb instruction with the SH field specified. */ #define XTLB(op, xop, sh) (X ((op), (xop)) | ((((unsigned long)(sh)) & 0x1f) << 11)) #define XTLB_MASK (X_MASK | SH_MASK) /* An X form sync instruction. */ #define XSYNC(op, xop, l) (X ((op), (xop)) | ((((unsigned long)(l)) & 3) << 21)) /* An X form sync instruction with everything filled in except the LS field. */ #define XSYNC_MASK (0xff9fffff) /* An X_MASK, but with the EH bit clear. */ #define XEH_MASK (X_MASK & ~((unsigned long )1)) /* An X form AltiVec dss instruction. */ #define XDSS(op, xop, a) (X ((op), (xop)) | ((((unsigned long)(a)) & 1) << 25)) #define XDSS_MASK XDSS(0x3f, 0x3ff, 1) /* An XFL form instruction. */ #define XFL(op, xop, rc) (OP (op) | ((((unsigned long)(xop)) & 0x3ff) << 1) | (((unsigned long)(rc)) & 1)) #define XFL_MASK (XFL (0x3f, 0x3ff, 1) | (((unsigned long)1) << 25) | (((unsigned long)1) << 16)) /* An X form isel instruction. */ #define XISEL(op, xop) (OP (op) | ((((unsigned long)(xop)) & 0x1f) << 1)) #define XISEL_MASK XISEL(0x3f, 0x1f) /* An XL form instruction with the LK field set to 0. */ #define XL(op, xop) (OP (op) | ((((unsigned long)(xop)) & 0x3ff) << 1)) /* An XL form instruction which uses the LK field. */ #define XLLK(op, xop, lk) (XL ((op), (xop)) | ((lk) & 1)) /* The mask for an XL form instruction. */ #define XL_MASK XLLK (0x3f, 0x3ff, 1) /* An XL form instruction which explicitly sets the BO field. */ #define XLO(op, bo, xop, lk) \ (XLLK ((op), (xop), (lk)) | ((((unsigned long)(bo)) & 0x1f) << 21)) #define XLO_MASK (XL_MASK | BO_MASK) /* An XL form instruction which explicitly sets the y bit of the BO field. */ #define XLYLK(op, xop, y, lk) (XLLK ((op), (xop), (lk)) | ((((unsigned long)(y)) & 1) << 21)) #define XLYLK_MASK (XL_MASK | Y_MASK) /* An XL form instruction which sets the BO field and the condition bits of the BI field. */ #define XLOCB(op, bo, cb, xop, lk) \ (XLO ((op), (bo), (xop), (lk)) | ((((unsigned long)(cb)) & 3) << 16)) #define XLOCB_MASK XLOCB (0x3f, 0x1f, 0x3, 0x3ff, 1) /* An XL_MASK or XLYLK_MASK or XLOCB_MASK with the BB field fixed. */ #define XLBB_MASK (XL_MASK | BB_MASK) #define XLYBB_MASK (XLYLK_MASK | BB_MASK) #define XLBOCBBB_MASK (XLOCB_MASK | BB_MASK) /* A mask for branch instructions using the BH field. */ #define XLBH_MASK (XL_MASK | (0x1c << 11)) /* An XL_MASK with the BO and BB fields fixed. */ #define XLBOBB_MASK (XL_MASK | BO_MASK | BB_MASK) /* An XL_MASK with the BO, BI and BB fields fixed. */ #define XLBOBIBB_MASK (XL_MASK | BO_MASK | BI_MASK | BB_MASK) /* An XO form instruction. */ #define XO(op, xop, oe, rc) \ (OP (op) | ((((unsigned long)(xop)) & 0x1ff) << 1) | ((((unsigned long)(oe)) & 1) << 10) | (((unsigned long)(rc)) & 1)) #define XO_MASK XO (0x3f, 0x1ff, 1, 1) /* An XO_MASK with the RB field fixed. */ #define XORB_MASK (XO_MASK | RB_MASK) /* An XS form instruction. */ #define XS(op, xop, rc) (OP (op) | ((((unsigned long)(xop)) & 0x1ff) << 2) | (((unsigned long)(rc)) & 1)) #define XS_MASK XS (0x3f, 0x1ff, 1) /* A mask for the FXM version of an XFX form instruction. */ #define XFXFXM_MASK (X_MASK | (1 << 11) | (1 << 20)) /* An XFX form instruction with the FXM field filled in. */ #define XFXM(op, xop, fxm, p4) \ (X ((op), (xop)) | ((((unsigned long)(fxm)) & 0xff) << 12) \ | ((unsigned long)(p4) << 20)) /* An XFX form instruction with the SPR field filled in. */ #define XSPR(op, xop, spr) \ (X ((op), (xop)) | ((((unsigned long)(spr)) & 0x1f) << 16) | ((((unsigned long)(spr)) & 0x3e0) << 6)) #define XSPR_MASK (X_MASK | SPR_MASK) /* An XFX form instruction with the SPR field filled in except for the SPRBAT field. */ #define XSPRBAT_MASK (XSPR_MASK &~ SPRBAT_MASK) /* An XFX form instruction with the SPR field filled in except for the SPRG field. */ #define XSPRG_MASK (XSPR_MASK & ~(0x17 << 16)) /* An X form instruction with everything filled in except the E field. */ #define XE_MASK (0xffff7fff) /* An X form user context instruction. */ #define XUC(op, xop) (OP (op) | (((unsigned long)(xop)) & 0x1f)) #define XUC_MASK XUC(0x3f, 0x1f) /* The BO encodings used in extended conditional branch mnemonics. */ #define BODNZF (0x0) #define BODNZFP (0x1) #define BODZF (0x2) #define BODZFP (0x3) #define BODNZT (0x8) #define BODNZTP (0x9) #define BODZT (0xa) #define BODZTP (0xb) #define BOF (0x4) #define BOFP (0x5) #define BOFM4 (0x6) #define BOFP4 (0x7) #define BOT (0xc) #define BOTP (0xd) #define BOTM4 (0xe) #define BOTP4 (0xf) #define BODNZ (0x10) #define BODNZP (0x11) #define BODZ (0x12) #define BODZP (0x13) #define BODNZM4 (0x18) #define BODNZP4 (0x19) #define BODZM4 (0x1a) #define BODZP4 (0x1b) #define BOU (0x14) /* The BI condition bit encodings used in extended conditional branch mnemonics. */ #define CBLT (0) #define CBGT (1) #define CBEQ (2) #define CBSO (3) /* The TO encodings used in extended trap mnemonics. */ #define TOLGT (0x1) #define TOLLT (0x2) #define TOEQ (0x4) #define TOLGE (0x5) #define TOLNL (0x5) #define TOLLE (0x6) #define TOLNG (0x6) #define TOGT (0x8) #define TOGE (0xc) #define TONL (0xc) #define TOLT (0x10) #define TOLE (0x14) #define TONG (0x14) #define TONE (0x18) #define TOU (0x1f) /* Smaller names for the flags so each entry in the opcodes table will fit on a single line. */ #undef PPC #define PPC PPC_OPCODE_PPC #define PPCCOM PPC_OPCODE_PPC | PPC_OPCODE_COMMON #define NOPOWER4 PPC_OPCODE_NOPOWER4 | PPCCOM #define POWER4 PPC_OPCODE_POWER4 #define POWER5 PPC_OPCODE_POWER5 #define POWER6 PPC_OPCODE_POWER6 #define CELL PPC_OPCODE_CELL #define PPC32 PPC_OPCODE_32 | PPC_OPCODE_PPC #define PPC64 PPC_OPCODE_64 | PPC_OPCODE_PPC #define PPC403 PPC_OPCODE_403 #define PPC405 PPC403 #define PPC440 PPC_OPCODE_440 #define PPC750 PPC #define PPC860 PPC #define PPCVEC PPC_OPCODE_ALTIVEC #define POWER PPC_OPCODE_POWER #define POWER2 PPC_OPCODE_POWER | PPC_OPCODE_POWER2 #define PPCPWR2 PPC_OPCODE_PPC | PPC_OPCODE_POWER | PPC_OPCODE_POWER2 #define POWER32 PPC_OPCODE_POWER | PPC_OPCODE_32 #define COM PPC_OPCODE_POWER | PPC_OPCODE_PPC | PPC_OPCODE_COMMON #define COM32 PPC_OPCODE_POWER | PPC_OPCODE_PPC | PPC_OPCODE_COMMON | PPC_OPCODE_32 #define M601 PPC_OPCODE_POWER | PPC_OPCODE_601 #define PWRCOM PPC_OPCODE_POWER | PPC_OPCODE_601 | PPC_OPCODE_COMMON #define MFDEC1 PPC_OPCODE_POWER #define MFDEC2 PPC_OPCODE_PPC | PPC_OPCODE_601 | PPC_OPCODE_BOOKE #define BOOKE PPC_OPCODE_BOOKE #define BOOKE64 PPC_OPCODE_BOOKE64 #define CLASSIC PPC_OPCODE_CLASSIC #define PPCE300 PPC_OPCODE_E300 #define PPCSPE PPC_OPCODE_SPE #define PPCISEL PPC_OPCODE_ISEL #define PPCEFS PPC_OPCODE_EFS #define PPCBRLK PPC_OPCODE_BRLOCK #define PPCPMR PPC_OPCODE_PMR #define PPCCHLK PPC_OPCODE_CACHELCK #define PPCCHLK64 PPC_OPCODE_CACHELCK | PPC_OPCODE_BOOKE64 #define PPCRFMCI PPC_OPCODE_RFMCI /* The opcode table. The format of the opcode table is: NAME OPCODE MASK FLAGS { OPERANDS } NAME is the name of the instruction. OPCODE is the instruction opcode. MASK is the opcode mask; this is used to tell the disassembler which bits in the actual opcode must match OPCODE. FLAGS are flags indicated what processors support the instruction. OPERANDS is the list of operands. The disassembler reads the table in order and prints the first instruction which matches, so this table is sorted to put more specific instructions before more general instructions. It is also sorted by major opcode. */ const struct powerpc_opcode powerpc_opcodes[] = { { "attn", X(0,256), X_MASK, POWER4, { 0 } }, { "tdlgti", OPTO(2,TOLGT), OPTO_MASK, PPC64, { RA, SI } }, { "tdllti", OPTO(2,TOLLT), OPTO_MASK, PPC64, { RA, SI } }, { "tdeqi", OPTO(2,TOEQ), OPTO_MASK, PPC64, { RA, SI } }, { "tdlgei", OPTO(2,TOLGE), OPTO_MASK, PPC64, { RA, SI } }, { "tdlnli", OPTO(2,TOLNL), OPTO_MASK, PPC64, { RA, SI } }, { "tdllei", OPTO(2,TOLLE), OPTO_MASK, PPC64, { RA, SI } }, { "tdlngi", OPTO(2,TOLNG), OPTO_MASK, PPC64, { RA, SI } }, { "tdgti", OPTO(2,TOGT), OPTO_MASK, PPC64, { RA, SI } }, { "tdgei", OPTO(2,TOGE), OPTO_MASK, PPC64, { RA, SI } }, { "tdnli", OPTO(2,TONL), OPTO_MASK, PPC64, { RA, SI } }, { "tdlti", OPTO(2,TOLT), OPTO_MASK, PPC64, { RA, SI } }, { "tdlei", OPTO(2,TOLE), OPTO_MASK, PPC64, { RA, SI } }, { "tdngi", OPTO(2,TONG), OPTO_MASK, PPC64, { RA, SI } }, { "tdnei", OPTO(2,TONE), OPTO_MASK, PPC64, { RA, SI } }, { "tdi", OP(2), OP_MASK, PPC64, { TO, RA, SI } }, { "twlgti", OPTO(3,TOLGT), OPTO_MASK, PPCCOM, { RA, SI } }, { "tlgti", OPTO(3,TOLGT), OPTO_MASK, PWRCOM, { RA, SI } }, { "twllti", OPTO(3,TOLLT), OPTO_MASK, PPCCOM, { RA, SI } }, { "tllti", OPTO(3,TOLLT), OPTO_MASK, PWRCOM, { RA, SI } }, { "tweqi", OPTO(3,TOEQ), OPTO_MASK, PPCCOM, { RA, SI } }, { "teqi", OPTO(3,TOEQ), OPTO_MASK, PWRCOM, { RA, SI } }, { "twlgei", OPTO(3,TOLGE), OPTO_MASK, PPCCOM, { RA, SI } }, { "tlgei", OPTO(3,TOLGE), OPTO_MASK, PWRCOM, { RA, SI } }, { "twlnli", OPTO(3,TOLNL), OPTO_MASK, PPCCOM, { RA, SI } }, { "tlnli", OPTO(3,TOLNL), OPTO_MASK, PWRCOM, { RA, SI } }, { "twllei", OPTO(3,TOLLE), OPTO_MASK, PPCCOM, { RA, SI } }, { "tllei", OPTO(3,TOLLE), OPTO_MASK, PWRCOM, { RA, SI } }, { "twlngi", OPTO(3,TOLNG), OPTO_MASK, PPCCOM, { RA, SI } }, { "tlngi", OPTO(3,TOLNG), OPTO_MASK, PWRCOM, { RA, SI } }, { "twgti", OPTO(3,TOGT), OPTO_MASK, PPCCOM, { RA, SI } }, { "tgti", OPTO(3,TOGT), OPTO_MASK, PWRCOM, { RA, SI } }, { "twgei", OPTO(3,TOGE), OPTO_MASK, PPCCOM, { RA, SI } }, { "tgei", OPTO(3,TOGE), OPTO_MASK, PWRCOM, { RA, SI } }, { "twnli", OPTO(3,TONL), OPTO_MASK, PPCCOM, { RA, SI } }, { "tnli", OPTO(3,TONL), OPTO_MASK, PWRCOM, { RA, SI } }, { "twlti", OPTO(3,TOLT), OPTO_MASK, PPCCOM, { RA, SI } }, { "tlti", OPTO(3,TOLT), OPTO_MASK, PWRCOM, { RA, SI } }, { "twlei", OPTO(3,TOLE), OPTO_MASK, PPCCOM, { RA, SI } }, { "tlei", OPTO(3,TOLE), OPTO_MASK, PWRCOM, { RA, SI } }, { "twngi", OPTO(3,TONG), OPTO_MASK, PPCCOM, { RA, SI } }, { "tngi", OPTO(3,TONG), OPTO_MASK, PWRCOM, { RA, SI } }, { "twnei", OPTO(3,TONE), OPTO_MASK, PPCCOM, { RA, SI } }, { "tnei", OPTO(3,TONE), OPTO_MASK, PWRCOM, { RA, SI } }, { "twi", OP(3), OP_MASK, PPCCOM, { TO, RA, SI } }, { "ti", OP(3), OP_MASK, PWRCOM, { TO, RA, SI } }, { "macchw", XO(4,172,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchw.", XO(4,172,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwo", XO(4,172,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwo.", XO(4,172,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchws", XO(4,236,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchws.", XO(4,236,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwso", XO(4,236,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwso.", XO(4,236,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwsu", XO(4,204,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwsu.", XO(4,204,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwsuo", XO(4,204,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwsuo.", XO(4,204,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwu", XO(4,140,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwu.", XO(4,140,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwuo", XO(4,140,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "macchwuo.", XO(4,140,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhw", XO(4,44,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhw.", XO(4,44,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwo", XO(4,44,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwo.", XO(4,44,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhws", XO(4,108,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhws.", XO(4,108,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwso", XO(4,108,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwso.", XO(4,108,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwsu", XO(4,76,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwsu.", XO(4,76,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwsuo", XO(4,76,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwsuo.", XO(4,76,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwu", XO(4,12,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwu.", XO(4,12,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwuo", XO(4,12,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "machhwuo.", XO(4,12,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhw", XO(4,428,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhw.", XO(4,428,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwo", XO(4,428,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwo.", XO(4,428,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhws", XO(4,492,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhws.", XO(4,492,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwso", XO(4,492,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwso.", XO(4,492,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwsu", XO(4,460,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwsu.", XO(4,460,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwsuo", XO(4,460,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwsuo.", XO(4,460,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwu", XO(4,396,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwu.", XO(4,396,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwuo", XO(4,396,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "maclhwuo.", XO(4,396,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mulchw", XRC(4,168,0), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mulchw.", XRC(4,168,1), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mulchwu", XRC(4,136,0), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mulchwu.", XRC(4,136,1), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mulhhw", XRC(4,40,0), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mulhhw.", XRC(4,40,1), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mulhhwu", XRC(4,8,0), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mulhhwu.", XRC(4,8,1), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mullhw", XRC(4,424,0), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mullhw.", XRC(4,424,1), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mullhwu", XRC(4,392,0), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mullhwu.", XRC(4,392,1), X_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmacchw", XO(4,174,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmacchw.", XO(4,174,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmacchwo", XO(4,174,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmacchwo.", XO(4,174,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmacchws", XO(4,238,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmacchws.", XO(4,238,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmacchwso", XO(4,238,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmacchwso.", XO(4,238,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmachhw", XO(4,46,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmachhw.", XO(4,46,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmachhwo", XO(4,46,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmachhwo.", XO(4,46,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmachhws", XO(4,110,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmachhws.", XO(4,110,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmachhwso", XO(4,110,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmachhwso.", XO(4,110,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmaclhw", XO(4,430,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmaclhw.", XO(4,430,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmaclhwo", XO(4,430,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmaclhwo.", XO(4,430,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmaclhws", XO(4,494,0,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmaclhws.", XO(4,494,0,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmaclhwso", XO(4,494,1,0), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "nmaclhwso.", XO(4,494,1,1), XO_MASK, PPC405|PPC440, { RT, RA, RB } }, { "mfvscr", VX(4, 1540), VX_MASK, PPCVEC, { VD } }, { "mtvscr", VX(4, 1604), VX_MASK, PPCVEC, { VB } }, /* Double-precision opcodes. */ /* Some of these conflict with AltiVec, so move them before, since PPCVEC includes the PPC_OPCODE_PPC set. */ { "efscfd", VX(4, 719), VX_MASK, PPCEFS, { RS, RB } }, { "efdabs", VX(4, 740), VX_MASK, PPCEFS, { RS, RA } }, { "efdnabs", VX(4, 741), VX_MASK, PPCEFS, { RS, RA } }, { "efdneg", VX(4, 742), VX_MASK, PPCEFS, { RS, RA } }, { "efdadd", VX(4, 736), VX_MASK, PPCEFS, { RS, RA, RB } }, { "efdsub", VX(4, 737), VX_MASK, PPCEFS, { RS, RA, RB } }, { "efdmul", VX(4, 744), VX_MASK, PPCEFS, { RS, RA, RB } }, { "efddiv", VX(4, 745), VX_MASK, PPCEFS, { RS, RA, RB } }, { "efdcmpgt", VX(4, 748), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efdcmplt", VX(4, 749), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efdcmpeq", VX(4, 750), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efdtstgt", VX(4, 764), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efdtstlt", VX(4, 765), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efdtsteq", VX(4, 766), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efdcfsi", VX(4, 753), VX_MASK, PPCEFS, { RS, RB } }, { "efdcfsid", VX(4, 739), VX_MASK, PPCEFS, { RS, RB } }, { "efdcfui", VX(4, 752), VX_MASK, PPCEFS, { RS, RB } }, { "efdcfuid", VX(4, 738), VX_MASK, PPCEFS, { RS, RB } }, { "efdcfsf", VX(4, 755), VX_MASK, PPCEFS, { RS, RB } }, { "efdcfuf", VX(4, 754), VX_MASK, PPCEFS, { RS, RB } }, { "efdctsi", VX(4, 757), VX_MASK, PPCEFS, { RS, RB } }, { "efdctsidz",VX(4, 747), VX_MASK, PPCEFS, { RS, RB } }, { "efdctsiz", VX(4, 762), VX_MASK, PPCEFS, { RS, RB } }, { "efdctui", VX(4, 756), VX_MASK, PPCEFS, { RS, RB } }, { "efdctuidz",VX(4, 746), VX_MASK, PPCEFS, { RS, RB } }, { "efdctuiz", VX(4, 760), VX_MASK, PPCEFS, { RS, RB } }, { "efdctsf", VX(4, 759), VX_MASK, PPCEFS, { RS, RB } }, { "efdctuf", VX(4, 758), VX_MASK, PPCEFS, { RS, RB } }, { "efdcfs", VX(4, 751), VX_MASK, PPCEFS, { RS, RB } }, /* End of double-precision opcodes. */ { "vaddcuw", VX(4, 384), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vaddfp", VX(4, 10), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vaddsbs", VX(4, 768), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vaddshs", VX(4, 832), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vaddsws", VX(4, 896), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vaddubm", VX(4, 0), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vaddubs", VX(4, 512), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vadduhm", VX(4, 64), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vadduhs", VX(4, 576), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vadduwm", VX(4, 128), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vadduws", VX(4, 640), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vand", VX(4, 1028), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vandc", VX(4, 1092), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vavgsb", VX(4, 1282), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vavgsh", VX(4, 1346), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vavgsw", VX(4, 1410), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vavgub", VX(4, 1026), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vavguh", VX(4, 1090), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vavguw", VX(4, 1154), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vcfsx", VX(4, 842), VX_MASK, PPCVEC, { VD, VB, UIMM } }, { "vcfux", VX(4, 778), VX_MASK, PPCVEC, { VD, VB, UIMM } }, { "vcmpbfp", VXR(4, 966, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpbfp.", VXR(4, 966, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpeqfp", VXR(4, 198, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpeqfp.", VXR(4, 198, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpequb", VXR(4, 6, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpequb.", VXR(4, 6, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpequh", VXR(4, 70, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpequh.", VXR(4, 70, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpequw", VXR(4, 134, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpequw.", VXR(4, 134, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgefp", VXR(4, 454, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgefp.", VXR(4, 454, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtfp", VXR(4, 710, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtfp.", VXR(4, 710, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtsb", VXR(4, 774, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtsb.", VXR(4, 774, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtsh", VXR(4, 838, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtsh.", VXR(4, 838, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtsw", VXR(4, 902, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtsw.", VXR(4, 902, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtub", VXR(4, 518, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtub.", VXR(4, 518, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtuh", VXR(4, 582, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtuh.", VXR(4, 582, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtuw", VXR(4, 646, 0), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vcmpgtuw.", VXR(4, 646, 1), VXR_MASK, PPCVEC, { VD, VA, VB } }, { "vctsxs", VX(4, 970), VX_MASK, PPCVEC, { VD, VB, UIMM } }, { "vctuxs", VX(4, 906), VX_MASK, PPCVEC, { VD, VB, UIMM } }, { "vexptefp", VX(4, 394), VX_MASK, PPCVEC, { VD, VB } }, { "vlogefp", VX(4, 458), VX_MASK, PPCVEC, { VD, VB } }, { "vmaddfp", VXA(4, 46), VXA_MASK, PPCVEC, { VD, VA, VC, VB } }, { "vmaxfp", VX(4, 1034), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmaxsb", VX(4, 258), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmaxsh", VX(4, 322), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmaxsw", VX(4, 386), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmaxub", VX(4, 2), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmaxuh", VX(4, 66), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmaxuw", VX(4, 130), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmhaddshs", VXA(4, 32), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vmhraddshs", VXA(4, 33), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vminfp", VX(4, 1098), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vminsb", VX(4, 770), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vminsh", VX(4, 834), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vminsw", VX(4, 898), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vminub", VX(4, 514), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vminuh", VX(4, 578), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vminuw", VX(4, 642), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmladduhm", VXA(4, 34), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vmrghb", VX(4, 12), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmrghh", VX(4, 76), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmrghw", VX(4, 140), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmrglb", VX(4, 268), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmrglh", VX(4, 332), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmrglw", VX(4, 396), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmsummbm", VXA(4, 37), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vmsumshm", VXA(4, 40), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vmsumshs", VXA(4, 41), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vmsumubm", VXA(4, 36), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vmsumuhm", VXA(4, 38), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vmsumuhs", VXA(4, 39), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vmulesb", VX(4, 776), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmulesh", VX(4, 840), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmuleub", VX(4, 520), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmuleuh", VX(4, 584), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmulosb", VX(4, 264), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmulosh", VX(4, 328), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmuloub", VX(4, 8), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vmulouh", VX(4, 72), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vnmsubfp", VXA(4, 47), VXA_MASK, PPCVEC, { VD, VA, VC, VB } }, { "vnor", VX(4, 1284), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vor", VX(4, 1156), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vperm", VXA(4, 43), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vpkpx", VX(4, 782), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vpkshss", VX(4, 398), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vpkshus", VX(4, 270), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vpkswss", VX(4, 462), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vpkswus", VX(4, 334), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vpkuhum", VX(4, 14), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vpkuhus", VX(4, 142), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vpkuwum", VX(4, 78), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vpkuwus", VX(4, 206), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vrefp", VX(4, 266), VX_MASK, PPCVEC, { VD, VB } }, { "vrfim", VX(4, 714), VX_MASK, PPCVEC, { VD, VB } }, { "vrfin", VX(4, 522), VX_MASK, PPCVEC, { VD, VB } }, { "vrfip", VX(4, 650), VX_MASK, PPCVEC, { VD, VB } }, { "vrfiz", VX(4, 586), VX_MASK, PPCVEC, { VD, VB } }, { "vrlb", VX(4, 4), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vrlh", VX(4, 68), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vrlw", VX(4, 132), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vrsqrtefp", VX(4, 330), VX_MASK, PPCVEC, { VD, VB } }, { "vsel", VXA(4, 42), VXA_MASK, PPCVEC, { VD, VA, VB, VC } }, { "vsl", VX(4, 452), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vslb", VX(4, 260), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsldoi", VXA(4, 44), VXA_MASK, PPCVEC, { VD, VA, VB, SHB } }, { "vslh", VX(4, 324), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vslo", VX(4, 1036), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vslw", VX(4, 388), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vspltb", VX(4, 524), VX_MASK, PPCVEC, { VD, VB, UIMM } }, { "vsplth", VX(4, 588), VX_MASK, PPCVEC, { VD, VB, UIMM } }, { "vspltisb", VX(4, 780), VX_MASK, PPCVEC, { VD, SIMM } }, { "vspltish", VX(4, 844), VX_MASK, PPCVEC, { VD, SIMM } }, { "vspltisw", VX(4, 908), VX_MASK, PPCVEC, { VD, SIMM } }, { "vspltw", VX(4, 652), VX_MASK, PPCVEC, { VD, VB, UIMM } }, { "vsr", VX(4, 708), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsrab", VX(4, 772), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsrah", VX(4, 836), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsraw", VX(4, 900), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsrb", VX(4, 516), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsrh", VX(4, 580), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsro", VX(4, 1100), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsrw", VX(4, 644), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsubcuw", VX(4, 1408), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsubfp", VX(4, 74), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsubsbs", VX(4, 1792), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsubshs", VX(4, 1856), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsubsws", VX(4, 1920), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsububm", VX(4, 1024), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsububs", VX(4, 1536), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsubuhm", VX(4, 1088), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsubuhs", VX(4, 1600), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsubuwm", VX(4, 1152), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsubuws", VX(4, 1664), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsumsws", VX(4, 1928), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsum2sws", VX(4, 1672), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsum4sbs", VX(4, 1800), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsum4shs", VX(4, 1608), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vsum4ubs", VX(4, 1544), VX_MASK, PPCVEC, { VD, VA, VB } }, { "vupkhpx", VX(4, 846), VX_MASK, PPCVEC, { VD, VB } }, { "vupkhsb", VX(4, 526), VX_MASK, PPCVEC, { VD, VB } }, { "vupkhsh", VX(4, 590), VX_MASK, PPCVEC, { VD, VB } }, { "vupklpx", VX(4, 974), VX_MASK, PPCVEC, { VD, VB } }, { "vupklsb", VX(4, 654), VX_MASK, PPCVEC, { VD, VB } }, { "vupklsh", VX(4, 718), VX_MASK, PPCVEC, { VD, VB } }, { "vxor", VX(4, 1220), VX_MASK, PPCVEC, { VD, VA, VB } }, { "evaddw", VX(4, 512), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evaddiw", VX(4, 514), VX_MASK, PPCSPE, { RS, RB, UIMM } }, { "evsubfw", VX(4, 516), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evsubw", VX(4, 516), VX_MASK, PPCSPE, { RS, RB, RA } }, { "evsubifw", VX(4, 518), VX_MASK, PPCSPE, { RS, UIMM, RB } }, { "evsubiw", VX(4, 518), VX_MASK, PPCSPE, { RS, RB, UIMM } }, { "evabs", VX(4, 520), VX_MASK, PPCSPE, { RS, RA } }, { "evneg", VX(4, 521), VX_MASK, PPCSPE, { RS, RA } }, { "evextsb", VX(4, 522), VX_MASK, PPCSPE, { RS, RA } }, { "evextsh", VX(4, 523), VX_MASK, PPCSPE, { RS, RA } }, { "evrndw", VX(4, 524), VX_MASK, PPCSPE, { RS, RA } }, { "evcntlzw", VX(4, 525), VX_MASK, PPCSPE, { RS, RA } }, { "evcntlsw", VX(4, 526), VX_MASK, PPCSPE, { RS, RA } }, { "brinc", VX(4, 527), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evand", VX(4, 529), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evandc", VX(4, 530), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmr", VX(4, 535), VX_MASK, PPCSPE, { RS, RA, BBA } }, { "evor", VX(4, 535), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evorc", VX(4, 539), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evxor", VX(4, 534), VX_MASK, PPCSPE, { RS, RA, RB } }, { "eveqv", VX(4, 537), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evnand", VX(4, 542), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evnot", VX(4, 536), VX_MASK, PPCSPE, { RS, RA, BBA } }, { "evnor", VX(4, 536), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evrlw", VX(4, 552), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evrlwi", VX(4, 554), VX_MASK, PPCSPE, { RS, RA, EVUIMM } }, { "evslw", VX(4, 548), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evslwi", VX(4, 550), VX_MASK, PPCSPE, { RS, RA, EVUIMM } }, { "evsrws", VX(4, 545), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evsrwu", VX(4, 544), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evsrwis", VX(4, 547), VX_MASK, PPCSPE, { RS, RA, EVUIMM } }, { "evsrwiu", VX(4, 546), VX_MASK, PPCSPE, { RS, RA, EVUIMM } }, { "evsplati", VX(4, 553), VX_MASK, PPCSPE, { RS, SIMM } }, { "evsplatfi", VX(4, 555), VX_MASK, PPCSPE, { RS, SIMM } }, { "evmergehi", VX(4, 556), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmergelo", VX(4, 557), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmergehilo",VX(4,558), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmergelohi",VX(4,559), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evcmpgts", VX(4, 561), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evcmpgtu", VX(4, 560), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evcmplts", VX(4, 563), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evcmpltu", VX(4, 562), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evcmpeq", VX(4, 564), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evsel", EVSEL(4,79),EVSEL_MASK, PPCSPE, { RS, RA, RB, CRFS } }, { "evldd", VX(4, 769), VX_MASK, PPCSPE, { RS, EVUIMM_8, RA } }, { "evlddx", VX(4, 768), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evldw", VX(4, 771), VX_MASK, PPCSPE, { RS, EVUIMM_8, RA } }, { "evldwx", VX(4, 770), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evldh", VX(4, 773), VX_MASK, PPCSPE, { RS, EVUIMM_8, RA } }, { "evldhx", VX(4, 772), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evlwhe", VX(4, 785), VX_MASK, PPCSPE, { RS, EVUIMM_4, RA } }, { "evlwhex", VX(4, 784), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evlwhou", VX(4, 789), VX_MASK, PPCSPE, { RS, EVUIMM_4, RA } }, { "evlwhoux", VX(4, 788), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evlwhos", VX(4, 791), VX_MASK, PPCSPE, { RS, EVUIMM_4, RA } }, { "evlwhosx", VX(4, 790), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evlwwsplat",VX(4, 793), VX_MASK, PPCSPE, { RS, EVUIMM_4, RA } }, { "evlwwsplatx",VX(4, 792), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evlwhsplat",VX(4, 797), VX_MASK, PPCSPE, { RS, EVUIMM_4, RA } }, { "evlwhsplatx",VX(4, 796), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evlhhesplat",VX(4, 777), VX_MASK, PPCSPE, { RS, EVUIMM_2, RA } }, { "evlhhesplatx",VX(4, 776), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evlhhousplat",VX(4, 781), VX_MASK, PPCSPE, { RS, EVUIMM_2, RA } }, { "evlhhousplatx",VX(4, 780), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evlhhossplat",VX(4, 783), VX_MASK, PPCSPE, { RS, EVUIMM_2, RA } }, { "evlhhossplatx",VX(4, 782), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evstdd", VX(4, 801), VX_MASK, PPCSPE, { RS, EVUIMM_8, RA } }, { "evstddx", VX(4, 800), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evstdw", VX(4, 803), VX_MASK, PPCSPE, { RS, EVUIMM_8, RA } }, { "evstdwx", VX(4, 802), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evstdh", VX(4, 805), VX_MASK, PPCSPE, { RS, EVUIMM_8, RA } }, { "evstdhx", VX(4, 804), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evstwwe", VX(4, 825), VX_MASK, PPCSPE, { RS, EVUIMM_4, RA } }, { "evstwwex", VX(4, 824), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evstwwo", VX(4, 829), VX_MASK, PPCSPE, { RS, EVUIMM_4, RA } }, { "evstwwox", VX(4, 828), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evstwhe", VX(4, 817), VX_MASK, PPCSPE, { RS, EVUIMM_4, RA } }, { "evstwhex", VX(4, 816), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evstwho", VX(4, 821), VX_MASK, PPCSPE, { RS, EVUIMM_4, RA } }, { "evstwhox", VX(4, 820), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evfsabs", VX(4, 644), VX_MASK, PPCSPE, { RS, RA } }, { "evfsnabs", VX(4, 645), VX_MASK, PPCSPE, { RS, RA } }, { "evfsneg", VX(4, 646), VX_MASK, PPCSPE, { RS, RA } }, { "evfsadd", VX(4, 640), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evfssub", VX(4, 641), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evfsmul", VX(4, 648), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evfsdiv", VX(4, 649), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evfscmpgt", VX(4, 652), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evfscmplt", VX(4, 653), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evfscmpeq", VX(4, 654), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evfststgt", VX(4, 668), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evfststlt", VX(4, 669), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evfststeq", VX(4, 670), VX_MASK, PPCSPE, { CRFD, RA, RB } }, { "evfscfui", VX(4, 656), VX_MASK, PPCSPE, { RS, RB } }, { "evfsctuiz", VX(4, 664), VX_MASK, PPCSPE, { RS, RB } }, { "evfscfsi", VX(4, 657), VX_MASK, PPCSPE, { RS, RB } }, { "evfscfuf", VX(4, 658), VX_MASK, PPCSPE, { RS, RB } }, { "evfscfsf", VX(4, 659), VX_MASK, PPCSPE, { RS, RB } }, { "evfsctui", VX(4, 660), VX_MASK, PPCSPE, { RS, RB } }, { "evfsctsi", VX(4, 661), VX_MASK, PPCSPE, { RS, RB } }, { "evfsctsiz", VX(4, 666), VX_MASK, PPCSPE, { RS, RB } }, { "evfsctuf", VX(4, 662), VX_MASK, PPCSPE, { RS, RB } }, { "evfsctsf", VX(4, 663), VX_MASK, PPCSPE, { RS, RB } }, { "efsabs", VX(4, 708), VX_MASK, PPCEFS, { RS, RA } }, { "efsnabs", VX(4, 709), VX_MASK, PPCEFS, { RS, RA } }, { "efsneg", VX(4, 710), VX_MASK, PPCEFS, { RS, RA } }, { "efsadd", VX(4, 704), VX_MASK, PPCEFS, { RS, RA, RB } }, { "efssub", VX(4, 705), VX_MASK, PPCEFS, { RS, RA, RB } }, { "efsmul", VX(4, 712), VX_MASK, PPCEFS, { RS, RA, RB } }, { "efsdiv", VX(4, 713), VX_MASK, PPCEFS, { RS, RA, RB } }, { "efscmpgt", VX(4, 716), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efscmplt", VX(4, 717), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efscmpeq", VX(4, 718), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efststgt", VX(4, 732), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efststlt", VX(4, 733), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efststeq", VX(4, 734), VX_MASK, PPCEFS, { CRFD, RA, RB } }, { "efscfui", VX(4, 720), VX_MASK, PPCEFS, { RS, RB } }, { "efsctuiz", VX(4, 728), VX_MASK, PPCEFS, { RS, RB } }, { "efscfsi", VX(4, 721), VX_MASK, PPCEFS, { RS, RB } }, { "efscfuf", VX(4, 722), VX_MASK, PPCEFS, { RS, RB } }, { "efscfsf", VX(4, 723), VX_MASK, PPCEFS, { RS, RB } }, { "efsctui", VX(4, 724), VX_MASK, PPCEFS, { RS, RB } }, { "efsctsi", VX(4, 725), VX_MASK, PPCEFS, { RS, RB } }, { "efsctsiz", VX(4, 730), VX_MASK, PPCEFS, { RS, RB } }, { "efsctuf", VX(4, 726), VX_MASK, PPCEFS, { RS, RB } }, { "efsctsf", VX(4, 727), VX_MASK, PPCEFS, { RS, RB } }, { "evmhossf", VX(4, 1031), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhossfa", VX(4, 1063), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhosmf", VX(4, 1039), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhosmfa", VX(4, 1071), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhosmi", VX(4, 1037), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhosmia", VX(4, 1069), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhoumi", VX(4, 1036), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhoumia", VX(4, 1068), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhessf", VX(4, 1027), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhessfa", VX(4, 1059), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhesmf", VX(4, 1035), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhesmfa", VX(4, 1067), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhesmi", VX(4, 1033), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhesmia", VX(4, 1065), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmheumi", VX(4, 1032), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmheumia", VX(4, 1064), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhossfaaw",VX(4, 1287), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhossiaaw",VX(4, 1285), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhosmfaaw",VX(4, 1295), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhosmiaaw",VX(4, 1293), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhousiaaw",VX(4, 1284), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhoumiaaw",VX(4, 1292), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhessfaaw",VX(4, 1283), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhessiaaw",VX(4, 1281), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhesmfaaw",VX(4, 1291), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhesmiaaw",VX(4, 1289), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmheusiaaw",VX(4, 1280), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmheumiaaw",VX(4, 1288), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhossfanw",VX(4, 1415), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhossianw",VX(4, 1413), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhosmfanw",VX(4, 1423), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhosmianw",VX(4, 1421), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhousianw",VX(4, 1412), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhoumianw",VX(4, 1420), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhessfanw",VX(4, 1411), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhessianw",VX(4, 1409), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhesmfanw",VX(4, 1419), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhesmianw",VX(4, 1417), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmheusianw",VX(4, 1408), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmheumianw",VX(4, 1416), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhogsmfaa",VX(4, 1327), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhogsmiaa",VX(4, 1325), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhogumiaa",VX(4, 1324), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhegsmfaa",VX(4, 1323), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhegsmiaa",VX(4, 1321), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhegumiaa",VX(4, 1320), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhogsmfan",VX(4, 1455), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhogsmian",VX(4, 1453), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhogumian",VX(4, 1452), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhegsmfan",VX(4, 1451), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhegsmian",VX(4, 1449), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmhegumian",VX(4, 1448), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwhssf", VX(4, 1095), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwhssfa", VX(4, 1127), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwhsmf", VX(4, 1103), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwhsmfa", VX(4, 1135), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwhsmi", VX(4, 1101), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwhsmia", VX(4, 1133), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwhumi", VX(4, 1100), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwhumia", VX(4, 1132), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwlumi", VX(4, 1096), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwlumia", VX(4, 1128), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwlssiaaw",VX(4, 1345), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwlsmiaaw",VX(4, 1353), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwlusiaaw",VX(4, 1344), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwlumiaaw",VX(4, 1352), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwlssianw",VX(4, 1473), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwlsmianw",VX(4, 1481), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwlusianw",VX(4, 1472), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwlumianw",VX(4, 1480), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwssf", VX(4, 1107), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwssfa", VX(4, 1139), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwsmf", VX(4, 1115), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwsmfa", VX(4, 1147), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwsmi", VX(4, 1113), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwsmia", VX(4, 1145), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwumi", VX(4, 1112), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwumia", VX(4, 1144), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwssfaa", VX(4, 1363), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwsmfaa", VX(4, 1371), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwsmiaa", VX(4, 1369), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwumiaa", VX(4, 1368), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwssfan", VX(4, 1491), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwsmfan", VX(4, 1499), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwsmian", VX(4, 1497), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evmwumian", VX(4, 1496), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evaddssiaaw",VX(4, 1217), VX_MASK, PPCSPE, { RS, RA } }, { "evaddsmiaaw",VX(4, 1225), VX_MASK, PPCSPE, { RS, RA } }, { "evaddusiaaw",VX(4, 1216), VX_MASK, PPCSPE, { RS, RA } }, { "evaddumiaaw",VX(4, 1224), VX_MASK, PPCSPE, { RS, RA } }, { "evsubfssiaaw",VX(4, 1219), VX_MASK, PPCSPE, { RS, RA } }, { "evsubfsmiaaw",VX(4, 1227), VX_MASK, PPCSPE, { RS, RA } }, { "evsubfusiaaw",VX(4, 1218), VX_MASK, PPCSPE, { RS, RA } }, { "evsubfumiaaw",VX(4, 1226), VX_MASK, PPCSPE, { RS, RA } }, { "evmra", VX(4, 1220), VX_MASK, PPCSPE, { RS, RA } }, { "evdivws", VX(4, 1222), VX_MASK, PPCSPE, { RS, RA, RB } }, { "evdivwu", VX(4, 1223), VX_MASK, PPCSPE, { RS, RA, RB } }, { "mulli", OP(7), OP_MASK, PPCCOM, { RT, RA, SI } }, { "muli", OP(7), OP_MASK, PWRCOM, { RT, RA, SI } }, { "subfic", OP(8), OP_MASK, PPCCOM, { RT, RA, SI } }, { "sfi", OP(8), OP_MASK, PWRCOM, { RT, RA, SI } }, { "dozi", OP(9), OP_MASK, M601, { RT, RA, SI } }, { "bce", B(9,0,0), B_MASK, BOOKE64, { BO, BI, BD } }, { "bcel", B(9,0,1), B_MASK, BOOKE64, { BO, BI, BD } }, { "bcea", B(9,1,0), B_MASK, BOOKE64, { BO, BI, BDA } }, { "bcela", B(9,1,1), B_MASK, BOOKE64, { BO, BI, BDA } }, { "cmplwi", OPL(10,0), OPL_MASK, PPCCOM, { OBF, RA, UI } }, { "cmpldi", OPL(10,1), OPL_MASK, PPC64, { OBF, RA, UI } }, { "cmpli", OP(10), OP_MASK, PPC, { BF, L, RA, UI } }, { "cmpli", OP(10), OP_MASK, PWRCOM, { BF, RA, UI } }, { "cmpwi", OPL(11,0), OPL_MASK, PPCCOM, { OBF, RA, SI } }, { "cmpdi", OPL(11,1), OPL_MASK, PPC64, { OBF, RA, SI } }, { "cmpi", OP(11), OP_MASK, PPC, { BF, L, RA, SI } }, { "cmpi", OP(11), OP_MASK, PWRCOM, { BF, RA, SI } }, { "addic", OP(12), OP_MASK, PPCCOM, { RT, RA, SI } }, { "ai", OP(12), OP_MASK, PWRCOM, { RT, RA, SI } }, { "subic", OP(12), OP_MASK, PPCCOM, { RT, RA, NSI } }, { "addic.", OP(13), OP_MASK, PPCCOM, { RT, RA, SI } }, { "ai.", OP(13), OP_MASK, PWRCOM, { RT, RA, SI } }, { "subic.", OP(13), OP_MASK, PPCCOM, { RT, RA, NSI } }, { "li", OP(14), DRA_MASK, PPCCOM, { RT, SI } }, { "lil", OP(14), DRA_MASK, PWRCOM, { RT, SI } }, { "addi", OP(14), OP_MASK, PPCCOM, { RT, RA0, SI } }, { "cal", OP(14), OP_MASK, PWRCOM, { RT, D, RA0 } }, { "subi", OP(14), OP_MASK, PPCCOM, { RT, RA0, NSI } }, { "la", OP(14), OP_MASK, PPCCOM, { RT, D, RA0 } }, { "lis", OP(15), DRA_MASK, PPCCOM, { RT, SISIGNOPT } }, { "liu", OP(15), DRA_MASK, PWRCOM, { RT, SISIGNOPT } }, { "addis", OP(15), OP_MASK, PPCCOM, { RT,RA0,SISIGNOPT } }, { "cau", OP(15), OP_MASK, PWRCOM, { RT,RA0,SISIGNOPT } }, { "subis", OP(15), OP_MASK, PPCCOM, { RT, RA0, NSI } }, { "bdnz-", BBO(16,BODNZ,0,0), BBOATBI_MASK, PPCCOM, { BDM } }, { "bdnz+", BBO(16,BODNZ,0,0), BBOATBI_MASK, PPCCOM, { BDP } }, { "bdnz", BBO(16,BODNZ,0,0), BBOATBI_MASK, PPCCOM, { BD } }, { "bdn", BBO(16,BODNZ,0,0), BBOATBI_MASK, PWRCOM, { BD } }, { "bdnzl-", BBO(16,BODNZ,0,1), BBOATBI_MASK, PPCCOM, { BDM } }, { "bdnzl+", BBO(16,BODNZ,0,1), BBOATBI_MASK, PPCCOM, { BDP } }, { "bdnzl", BBO(16,BODNZ,0,1), BBOATBI_MASK, PPCCOM, { BD } }, { "bdnl", BBO(16,BODNZ,0,1), BBOATBI_MASK, PWRCOM, { BD } }, { "bdnza-", BBO(16,BODNZ,1,0), BBOATBI_MASK, PPCCOM, { BDMA } }, { "bdnza+", BBO(16,BODNZ,1,0), BBOATBI_MASK, PPCCOM, { BDPA } }, { "bdnza", BBO(16,BODNZ,1,0), BBOATBI_MASK, PPCCOM, { BDA } }, { "bdna", BBO(16,BODNZ,1,0), BBOATBI_MASK, PWRCOM, { BDA } }, { "bdnzla-", BBO(16,BODNZ,1,1), BBOATBI_MASK, PPCCOM, { BDMA } }, { "bdnzla+", BBO(16,BODNZ,1,1), BBOATBI_MASK, PPCCOM, { BDPA } }, { "bdnzla", BBO(16,BODNZ,1,1), BBOATBI_MASK, PPCCOM, { BDA } }, { "bdnla", BBO(16,BODNZ,1,1), BBOATBI_MASK, PWRCOM, { BDA } }, { "bdz-", BBO(16,BODZ,0,0), BBOATBI_MASK, PPCCOM, { BDM } }, { "bdz+", BBO(16,BODZ,0,0), BBOATBI_MASK, PPCCOM, { BDP } }, { "bdz", BBO(16,BODZ,0,0), BBOATBI_MASK, COM, { BD } }, { "bdzl-", BBO(16,BODZ,0,1), BBOATBI_MASK, PPCCOM, { BDM } }, { "bdzl+", BBO(16,BODZ,0,1), BBOATBI_MASK, PPCCOM, { BDP } }, { "bdzl", BBO(16,BODZ,0,1), BBOATBI_MASK, COM, { BD } }, { "bdza-", BBO(16,BODZ,1,0), BBOATBI_MASK, PPCCOM, { BDMA } }, { "bdza+", BBO(16,BODZ,1,0), BBOATBI_MASK, PPCCOM, { BDPA } }, { "bdza", BBO(16,BODZ,1,0), BBOATBI_MASK, COM, { BDA } }, { "bdzla-", BBO(16,BODZ,1,1), BBOATBI_MASK, PPCCOM, { BDMA } }, { "bdzla+", BBO(16,BODZ,1,1), BBOATBI_MASK, PPCCOM, { BDPA } }, { "bdzla", BBO(16,BODZ,1,1), BBOATBI_MASK, COM, { BDA } }, { "blt-", BBOCB(16,BOT,CBLT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "blt+", BBOCB(16,BOT,CBLT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "blt", BBOCB(16,BOT,CBLT,0,0), BBOATCB_MASK, COM, { CR, BD } }, { "bltl-", BBOCB(16,BOT,CBLT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bltl+", BBOCB(16,BOT,CBLT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bltl", BBOCB(16,BOT,CBLT,0,1), BBOATCB_MASK, COM, { CR, BD } }, { "blta-", BBOCB(16,BOT,CBLT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "blta+", BBOCB(16,BOT,CBLT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "blta", BBOCB(16,BOT,CBLT,1,0), BBOATCB_MASK, COM, { CR, BDA } }, { "bltla-", BBOCB(16,BOT,CBLT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bltla+", BBOCB(16,BOT,CBLT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bltla", BBOCB(16,BOT,CBLT,1,1), BBOATCB_MASK, COM, { CR, BDA } }, { "bgt-", BBOCB(16,BOT,CBGT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bgt+", BBOCB(16,BOT,CBGT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bgt", BBOCB(16,BOT,CBGT,0,0), BBOATCB_MASK, COM, { CR, BD } }, { "bgtl-", BBOCB(16,BOT,CBGT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bgtl+", BBOCB(16,BOT,CBGT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bgtl", BBOCB(16,BOT,CBGT,0,1), BBOATCB_MASK, COM, { CR, BD } }, { "bgta-", BBOCB(16,BOT,CBGT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bgta+", BBOCB(16,BOT,CBGT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bgta", BBOCB(16,BOT,CBGT,1,0), BBOATCB_MASK, COM, { CR, BDA } }, { "bgtla-", BBOCB(16,BOT,CBGT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bgtla+", BBOCB(16,BOT,CBGT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bgtla", BBOCB(16,BOT,CBGT,1,1), BBOATCB_MASK, COM, { CR, BDA } }, { "beq-", BBOCB(16,BOT,CBEQ,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "beq+", BBOCB(16,BOT,CBEQ,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "beq", BBOCB(16,BOT,CBEQ,0,0), BBOATCB_MASK, COM, { CR, BD } }, { "beql-", BBOCB(16,BOT,CBEQ,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "beql+", BBOCB(16,BOT,CBEQ,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "beql", BBOCB(16,BOT,CBEQ,0,1), BBOATCB_MASK, COM, { CR, BD } }, { "beqa-", BBOCB(16,BOT,CBEQ,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "beqa+", BBOCB(16,BOT,CBEQ,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "beqa", BBOCB(16,BOT,CBEQ,1,0), BBOATCB_MASK, COM, { CR, BDA } }, { "beqla-", BBOCB(16,BOT,CBEQ,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "beqla+", BBOCB(16,BOT,CBEQ,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "beqla", BBOCB(16,BOT,CBEQ,1,1), BBOATCB_MASK, COM, { CR, BDA } }, { "bso-", BBOCB(16,BOT,CBSO,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bso+", BBOCB(16,BOT,CBSO,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bso", BBOCB(16,BOT,CBSO,0,0), BBOATCB_MASK, COM, { CR, BD } }, { "bsol-", BBOCB(16,BOT,CBSO,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bsol+", BBOCB(16,BOT,CBSO,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bsol", BBOCB(16,BOT,CBSO,0,1), BBOATCB_MASK, COM, { CR, BD } }, { "bsoa-", BBOCB(16,BOT,CBSO,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bsoa+", BBOCB(16,BOT,CBSO,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bsoa", BBOCB(16,BOT,CBSO,1,0), BBOATCB_MASK, COM, { CR, BDA } }, { "bsola-", BBOCB(16,BOT,CBSO,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bsola+", BBOCB(16,BOT,CBSO,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bsola", BBOCB(16,BOT,CBSO,1,1), BBOATCB_MASK, COM, { CR, BDA } }, { "bun-", BBOCB(16,BOT,CBSO,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bun+", BBOCB(16,BOT,CBSO,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bun", BBOCB(16,BOT,CBSO,0,0), BBOATCB_MASK, PPCCOM, { CR, BD } }, { "bunl-", BBOCB(16,BOT,CBSO,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bunl+", BBOCB(16,BOT,CBSO,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bunl", BBOCB(16,BOT,CBSO,0,1), BBOATCB_MASK, PPCCOM, { CR, BD } }, { "buna-", BBOCB(16,BOT,CBSO,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "buna+", BBOCB(16,BOT,CBSO,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "buna", BBOCB(16,BOT,CBSO,1,0), BBOATCB_MASK, PPCCOM, { CR, BDA } }, { "bunla-", BBOCB(16,BOT,CBSO,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bunla+", BBOCB(16,BOT,CBSO,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bunla", BBOCB(16,BOT,CBSO,1,1), BBOATCB_MASK, PPCCOM, { CR, BDA } }, { "bge-", BBOCB(16,BOF,CBLT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bge+", BBOCB(16,BOF,CBLT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bge", BBOCB(16,BOF,CBLT,0,0), BBOATCB_MASK, COM, { CR, BD } }, { "bgel-", BBOCB(16,BOF,CBLT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bgel+", BBOCB(16,BOF,CBLT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bgel", BBOCB(16,BOF,CBLT,0,1), BBOATCB_MASK, COM, { CR, BD } }, { "bgea-", BBOCB(16,BOF,CBLT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bgea+", BBOCB(16,BOF,CBLT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bgea", BBOCB(16,BOF,CBLT,1,0), BBOATCB_MASK, COM, { CR, BDA } }, { "bgela-", BBOCB(16,BOF,CBLT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bgela+", BBOCB(16,BOF,CBLT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bgela", BBOCB(16,BOF,CBLT,1,1), BBOATCB_MASK, COM, { CR, BDA } }, { "bnl-", BBOCB(16,BOF,CBLT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bnl+", BBOCB(16,BOF,CBLT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bnl", BBOCB(16,BOF,CBLT,0,0), BBOATCB_MASK, COM, { CR, BD } }, { "bnll-", BBOCB(16,BOF,CBLT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bnll+", BBOCB(16,BOF,CBLT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bnll", BBOCB(16,BOF,CBLT,0,1), BBOATCB_MASK, COM, { CR, BD } }, { "bnla-", BBOCB(16,BOF,CBLT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bnla+", BBOCB(16,BOF,CBLT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bnla", BBOCB(16,BOF,CBLT,1,0), BBOATCB_MASK, COM, { CR, BDA } }, { "bnlla-", BBOCB(16,BOF,CBLT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bnlla+", BBOCB(16,BOF,CBLT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bnlla", BBOCB(16,BOF,CBLT,1,1), BBOATCB_MASK, COM, { CR, BDA } }, { "ble-", BBOCB(16,BOF,CBGT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "ble+", BBOCB(16,BOF,CBGT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "ble", BBOCB(16,BOF,CBGT,0,0), BBOATCB_MASK, COM, { CR, BD } }, { "blel-", BBOCB(16,BOF,CBGT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "blel+", BBOCB(16,BOF,CBGT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "blel", BBOCB(16,BOF,CBGT,0,1), BBOATCB_MASK, COM, { CR, BD } }, { "blea-", BBOCB(16,BOF,CBGT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "blea+", BBOCB(16,BOF,CBGT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "blea", BBOCB(16,BOF,CBGT,1,0), BBOATCB_MASK, COM, { CR, BDA } }, { "blela-", BBOCB(16,BOF,CBGT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "blela+", BBOCB(16,BOF,CBGT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "blela", BBOCB(16,BOF,CBGT,1,1), BBOATCB_MASK, COM, { CR, BDA } }, { "bng-", BBOCB(16,BOF,CBGT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bng+", BBOCB(16,BOF,CBGT,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bng", BBOCB(16,BOF,CBGT,0,0), BBOATCB_MASK, COM, { CR, BD } }, { "bngl-", BBOCB(16,BOF,CBGT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bngl+", BBOCB(16,BOF,CBGT,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bngl", BBOCB(16,BOF,CBGT,0,1), BBOATCB_MASK, COM, { CR, BD } }, { "bnga-", BBOCB(16,BOF,CBGT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bnga+", BBOCB(16,BOF,CBGT,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bnga", BBOCB(16,BOF,CBGT,1,0), BBOATCB_MASK, COM, { CR, BDA } }, { "bngla-", BBOCB(16,BOF,CBGT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bngla+", BBOCB(16,BOF,CBGT,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bngla", BBOCB(16,BOF,CBGT,1,1), BBOATCB_MASK, COM, { CR, BDA } }, { "bne-", BBOCB(16,BOF,CBEQ,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bne+", BBOCB(16,BOF,CBEQ,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bne", BBOCB(16,BOF,CBEQ,0,0), BBOATCB_MASK, COM, { CR, BD } }, { "bnel-", BBOCB(16,BOF,CBEQ,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bnel+", BBOCB(16,BOF,CBEQ,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bnel", BBOCB(16,BOF,CBEQ,0,1), BBOATCB_MASK, COM, { CR, BD } }, { "bnea-", BBOCB(16,BOF,CBEQ,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bnea+", BBOCB(16,BOF,CBEQ,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bnea", BBOCB(16,BOF,CBEQ,1,0), BBOATCB_MASK, COM, { CR, BDA } }, { "bnela-", BBOCB(16,BOF,CBEQ,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bnela+", BBOCB(16,BOF,CBEQ,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bnela", BBOCB(16,BOF,CBEQ,1,1), BBOATCB_MASK, COM, { CR, BDA } }, { "bns-", BBOCB(16,BOF,CBSO,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bns+", BBOCB(16,BOF,CBSO,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bns", BBOCB(16,BOF,CBSO,0,0), BBOATCB_MASK, COM, { CR, BD } }, { "bnsl-", BBOCB(16,BOF,CBSO,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bnsl+", BBOCB(16,BOF,CBSO,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bnsl", BBOCB(16,BOF,CBSO,0,1), BBOATCB_MASK, COM, { CR, BD } }, { "bnsa-", BBOCB(16,BOF,CBSO,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bnsa+", BBOCB(16,BOF,CBSO,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bnsa", BBOCB(16,BOF,CBSO,1,0), BBOATCB_MASK, COM, { CR, BDA } }, { "bnsla-", BBOCB(16,BOF,CBSO,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bnsla+", BBOCB(16,BOF,CBSO,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bnsla", BBOCB(16,BOF,CBSO,1,1), BBOATCB_MASK, COM, { CR, BDA } }, { "bnu-", BBOCB(16,BOF,CBSO,0,0), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bnu+", BBOCB(16,BOF,CBSO,0,0), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bnu", BBOCB(16,BOF,CBSO,0,0), BBOATCB_MASK, PPCCOM, { CR, BD } }, { "bnul-", BBOCB(16,BOF,CBSO,0,1), BBOATCB_MASK, PPCCOM, { CR, BDM } }, { "bnul+", BBOCB(16,BOF,CBSO,0,1), BBOATCB_MASK, PPCCOM, { CR, BDP } }, { "bnul", BBOCB(16,BOF,CBSO,0,1), BBOATCB_MASK, PPCCOM, { CR, BD } }, { "bnua-", BBOCB(16,BOF,CBSO,1,0), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bnua+", BBOCB(16,BOF,CBSO,1,0), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bnua", BBOCB(16,BOF,CBSO,1,0), BBOATCB_MASK, PPCCOM, { CR, BDA } }, { "bnula-", BBOCB(16,BOF,CBSO,1,1), BBOATCB_MASK, PPCCOM, { CR, BDMA } }, { "bnula+", BBOCB(16,BOF,CBSO,1,1), BBOATCB_MASK, PPCCOM, { CR, BDPA } }, { "bnula", BBOCB(16,BOF,CBSO,1,1), BBOATCB_MASK, PPCCOM, { CR, BDA } }, { "bdnzt-", BBO(16,BODNZT,0,0), BBOY_MASK, NOPOWER4, { BI, BDM } }, { "bdnzt+", BBO(16,BODNZT,0,0), BBOY_MASK, NOPOWER4, { BI, BDP } }, { "bdnzt", BBO(16,BODNZT,0,0), BBOY_MASK, PPCCOM, { BI, BD } }, { "bdnztl-", BBO(16,BODNZT,0,1), BBOY_MASK, NOPOWER4, { BI, BDM } }, { "bdnztl+", BBO(16,BODNZT,0,1), BBOY_MASK, NOPOWER4, { BI, BDP } }, { "bdnztl", BBO(16,BODNZT,0,1), BBOY_MASK, PPCCOM, { BI, BD } }, { "bdnzta-", BBO(16,BODNZT,1,0), BBOY_MASK, NOPOWER4, { BI, BDMA } }, { "bdnzta+", BBO(16,BODNZT,1,0), BBOY_MASK, NOPOWER4, { BI, BDPA } }, { "bdnzta", BBO(16,BODNZT,1,0), BBOY_MASK, PPCCOM, { BI, BDA } }, { "bdnztla-",BBO(16,BODNZT,1,1), BBOY_MASK, NOPOWER4, { BI, BDMA } }, { "bdnztla+",BBO(16,BODNZT,1,1), BBOY_MASK, NOPOWER4, { BI, BDPA } }, { "bdnztla", BBO(16,BODNZT,1,1), BBOY_MASK, PPCCOM, { BI, BDA } }, { "bdnzf-", BBO(16,BODNZF,0,0), BBOY_MASK, NOPOWER4, { BI, BDM } }, { "bdnzf+", BBO(16,BODNZF,0,0), BBOY_MASK, NOPOWER4, { BI, BDP } }, { "bdnzf", BBO(16,BODNZF,0,0), BBOY_MASK, PPCCOM, { BI, BD } }, { "bdnzfl-", BBO(16,BODNZF,0,1), BBOY_MASK, NOPOWER4, { BI, BDM } }, { "bdnzfl+", BBO(16,BODNZF,0,1), BBOY_MASK, NOPOWER4, { BI, BDP } }, { "bdnzfl", BBO(16,BODNZF,0,1), BBOY_MASK, PPCCOM, { BI, BD } }, { "bdnzfa-", BBO(16,BODNZF,1,0), BBOY_MASK, NOPOWER4, { BI, BDMA } }, { "bdnzfa+", BBO(16,BODNZF,1,0), BBOY_MASK, NOPOWER4, { BI, BDPA } }, { "bdnzfa", BBO(16,BODNZF,1,0), BBOY_MASK, PPCCOM, { BI, BDA } }, { "bdnzfla-",BBO(16,BODNZF,1,1), BBOY_MASK, NOPOWER4, { BI, BDMA } }, { "bdnzfla+",BBO(16,BODNZF,1,1), BBOY_MASK, NOPOWER4, { BI, BDPA } }, { "bdnzfla", BBO(16,BODNZF,1,1), BBOY_MASK, PPCCOM, { BI, BDA } }, { "bt-", BBO(16,BOT,0,0), BBOAT_MASK, PPCCOM, { BI, BDM } }, { "bt+", BBO(16,BOT,0,0), BBOAT_MASK, PPCCOM, { BI, BDP } }, { "bt", BBO(16,BOT,0,0), BBOAT_MASK, PPCCOM, { BI, BD } }, { "bbt", BBO(16,BOT,0,0), BBOAT_MASK, PWRCOM, { BI, BD } }, { "btl-", BBO(16,BOT,0,1), BBOAT_MASK, PPCCOM, { BI, BDM } }, { "btl+", BBO(16,BOT,0,1), BBOAT_MASK, PPCCOM, { BI, BDP } }, { "btl", BBO(16,BOT,0,1), BBOAT_MASK, PPCCOM, { BI, BD } }, { "bbtl", BBO(16,BOT,0,1), BBOAT_MASK, PWRCOM, { BI, BD } }, { "bta-", BBO(16,BOT,1,0), BBOAT_MASK, PPCCOM, { BI, BDMA } }, { "bta+", BBO(16,BOT,1,0), BBOAT_MASK, PPCCOM, { BI, BDPA } }, { "bta", BBO(16,BOT,1,0), BBOAT_MASK, PPCCOM, { BI, BDA } }, { "bbta", BBO(16,BOT,1,0), BBOAT_MASK, PWRCOM, { BI, BDA } }, { "btla-", BBO(16,BOT,1,1), BBOAT_MASK, PPCCOM, { BI, BDMA } }, { "btla+", BBO(16,BOT,1,1), BBOAT_MASK, PPCCOM, { BI, BDPA } }, { "btla", BBO(16,BOT,1,1), BBOAT_MASK, PPCCOM, { BI, BDA } }, { "bbtla", BBO(16,BOT,1,1), BBOAT_MASK, PWRCOM, { BI, BDA } }, { "bf-", BBO(16,BOF,0,0), BBOAT_MASK, PPCCOM, { BI, BDM } }, { "bf+", BBO(16,BOF,0,0), BBOAT_MASK, PPCCOM, { BI, BDP } }, { "bf", BBO(16,BOF,0,0), BBOAT_MASK, PPCCOM, { BI, BD } }, { "bbf", BBO(16,BOF,0,0), BBOAT_MASK, PWRCOM, { BI, BD } }, { "bfl-", BBO(16,BOF,0,1), BBOAT_MASK, PPCCOM, { BI, BDM } }, { "bfl+", BBO(16,BOF,0,1), BBOAT_MASK, PPCCOM, { BI, BDP } }, { "bfl", BBO(16,BOF,0,1), BBOAT_MASK, PPCCOM, { BI, BD } }, { "bbfl", BBO(16,BOF,0,1), BBOAT_MASK, PWRCOM, { BI, BD } }, { "bfa-", BBO(16,BOF,1,0), BBOAT_MASK, PPCCOM, { BI, BDMA } }, { "bfa+", BBO(16,BOF,1,0), BBOAT_MASK, PPCCOM, { BI, BDPA } }, { "bfa", BBO(16,BOF,1,0), BBOAT_MASK, PPCCOM, { BI, BDA } }, { "bbfa", BBO(16,BOF,1,0), BBOAT_MASK, PWRCOM, { BI, BDA } }, { "bfla-", BBO(16,BOF,1,1), BBOAT_MASK, PPCCOM, { BI, BDMA } }, { "bfla+", BBO(16,BOF,1,1), BBOAT_MASK, PPCCOM, { BI, BDPA } }, { "bfla", BBO(16,BOF,1,1), BBOAT_MASK, PPCCOM, { BI, BDA } }, { "bbfla", BBO(16,BOF,1,1), BBOAT_MASK, PWRCOM, { BI, BDA } }, { "bdzt-", BBO(16,BODZT,0,0), BBOY_MASK, NOPOWER4, { BI, BDM } }, { "bdzt+", BBO(16,BODZT,0,0), BBOY_MASK, NOPOWER4, { BI, BDP } }, { "bdzt", BBO(16,BODZT,0,0), BBOY_MASK, PPCCOM, { BI, BD } }, { "bdztl-", BBO(16,BODZT,0,1), BBOY_MASK, NOPOWER4, { BI, BDM } }, { "bdztl+", BBO(16,BODZT,0,1), BBOY_MASK, NOPOWER4, { BI, BDP } }, { "bdztl", BBO(16,BODZT,0,1), BBOY_MASK, PPCCOM, { BI, BD } }, { "bdzta-", BBO(16,BODZT,1,0), BBOY_MASK, NOPOWER4, { BI, BDMA } }, { "bdzta+", BBO(16,BODZT,1,0), BBOY_MASK, NOPOWER4, { BI, BDPA } }, { "bdzta", BBO(16,BODZT,1,0), BBOY_MASK, PPCCOM, { BI, BDA } }, { "bdztla-", BBO(16,BODZT,1,1), BBOY_MASK, NOPOWER4, { BI, BDMA } }, { "bdztla+", BBO(16,BODZT,1,1), BBOY_MASK, NOPOWER4, { BI, BDPA } }, { "bdztla", BBO(16,BODZT,1,1), BBOY_MASK, PPCCOM, { BI, BDA } }, { "bdzf-", BBO(16,BODZF,0,0), BBOY_MASK, NOPOWER4, { BI, BDM } }, { "bdzf+", BBO(16,BODZF,0,0), BBOY_MASK, NOPOWER4, { BI, BDP } }, { "bdzf", BBO(16,BODZF,0,0), BBOY_MASK, PPCCOM, { BI, BD } }, { "bdzfl-", BBO(16,BODZF,0,1), BBOY_MASK, NOPOWER4, { BI, BDM } }, { "bdzfl+", BBO(16,BODZF,0,1), BBOY_MASK, NOPOWER4, { BI, BDP } }, { "bdzfl", BBO(16,BODZF,0,1), BBOY_MASK, PPCCOM, { BI, BD } }, { "bdzfa-", BBO(16,BODZF,1,0), BBOY_MASK, NOPOWER4, { BI, BDMA } }, { "bdzfa+", BBO(16,BODZF,1,0), BBOY_MASK, NOPOWER4, { BI, BDPA } }, { "bdzfa", BBO(16,BODZF,1,0), BBOY_MASK, PPCCOM, { BI, BDA } }, { "bdzfla-", BBO(16,BODZF,1,1), BBOY_MASK, NOPOWER4, { BI, BDMA } }, { "bdzfla+", BBO(16,BODZF,1,1), BBOY_MASK, NOPOWER4, { BI, BDPA } }, { "bdzfla", BBO(16,BODZF,1,1), BBOY_MASK, PPCCOM, { BI, BDA } }, { "bc-", B(16,0,0), B_MASK, PPCCOM, { BOE, BI, BDM } }, { "bc+", B(16,0,0), B_MASK, PPCCOM, { BOE, BI, BDP } }, { "bc", B(16,0,0), B_MASK, COM, { BO, BI, BD } }, { "bcl-", B(16,0,1), B_MASK, PPCCOM, { BOE, BI, BDM } }, { "bcl+", B(16,0,1), B_MASK, PPCCOM, { BOE, BI, BDP } }, { "bcl", B(16,0,1), B_MASK, COM, { BO, BI, BD } }, { "bca-", B(16,1,0), B_MASK, PPCCOM, { BOE, BI, BDMA } }, { "bca+", B(16,1,0), B_MASK, PPCCOM, { BOE, BI, BDPA } }, { "bca", B(16,1,0), B_MASK, COM, { BO, BI, BDA } }, { "bcla-", B(16,1,1), B_MASK, PPCCOM, { BOE, BI, BDMA } }, { "bcla+", B(16,1,1), B_MASK, PPCCOM, { BOE, BI, BDPA } }, { "bcla", B(16,1,1), B_MASK, COM, { BO, BI, BDA } }, { "sc", SC(17,1,0), SC_MASK, PPC, { LEV } }, { "svc", SC(17,0,0), SC_MASK, POWER, { SVC_LEV, FL1, FL2 } }, { "svcl", SC(17,0,1), SC_MASK, POWER, { SVC_LEV, FL1, FL2 } }, { "svca", SC(17,1,0), SC_MASK, PWRCOM, { SV } }, { "svcla", SC(17,1,1), SC_MASK, POWER, { SV } }, { "b", B(18,0,0), B_MASK, COM, { LI } }, { "bl", B(18,0,1), B_MASK, COM, { LI } }, { "ba", B(18,1,0), B_MASK, COM, { LIA } }, { "bla", B(18,1,1), B_MASK, COM, { LIA } }, { "mcrf", XL(19,0), XLBB_MASK|(3 << 21)|(3 << 16), COM, { BF, BFA } }, { "blr", XLO(19,BOU,16,0), XLBOBIBB_MASK, PPCCOM, { 0 } }, { "br", XLO(19,BOU,16,0), XLBOBIBB_MASK, PWRCOM, { 0 } }, { "blrl", XLO(19,BOU,16,1), XLBOBIBB_MASK, PPCCOM, { 0 } }, { "brl", XLO(19,BOU,16,1), XLBOBIBB_MASK, PWRCOM, { 0 } }, { "bdnzlr", XLO(19,BODNZ,16,0), XLBOBIBB_MASK, PPCCOM, { 0 } }, { "bdnzlr-", XLO(19,BODNZ,16,0), XLBOBIBB_MASK, NOPOWER4, { 0 } }, { "bdnzlr-", XLO(19,BODNZM4,16,0), XLBOBIBB_MASK, POWER4, { 0 } }, { "bdnzlr+", XLO(19,BODNZP,16,0), XLBOBIBB_MASK, NOPOWER4, { 0 } }, { "bdnzlr+", XLO(19,BODNZP4,16,0), XLBOBIBB_MASK, POWER4, { 0 } }, { "bdnzlrl", XLO(19,BODNZ,16,1), XLBOBIBB_MASK, PPCCOM, { 0 } }, { "bdnzlrl-",XLO(19,BODNZ,16,1), XLBOBIBB_MASK, NOPOWER4, { 0 } }, { "bdnzlrl-",XLO(19,BODNZM4,16,1), XLBOBIBB_MASK, POWER4, { 0 } }, { "bdnzlrl+",XLO(19,BODNZP,16,1), XLBOBIBB_MASK, NOPOWER4, { 0 } }, { "bdnzlrl+",XLO(19,BODNZP4,16,1), XLBOBIBB_MASK, POWER4, { 0 } }, { "bdzlr", XLO(19,BODZ,16,0), XLBOBIBB_MASK, PPCCOM, { 0 } }, { "bdzlr-", XLO(19,BODZ,16,0), XLBOBIBB_MASK, NOPOWER4, { 0 } }, { "bdzlr-", XLO(19,BODZM4,16,0), XLBOBIBB_MASK, POWER4, { 0 } }, { "bdzlr+", XLO(19,BODZP,16,0), XLBOBIBB_MASK, NOPOWER4, { 0 } }, { "bdzlr+", XLO(19,BODZP4,16,0), XLBOBIBB_MASK, POWER4, { 0 } }, { "bdzlrl", XLO(19,BODZ,16,1), XLBOBIBB_MASK, PPCCOM, { 0 } }, { "bdzlrl-", XLO(19,BODZ,16,1), XLBOBIBB_MASK, NOPOWER4, { 0 } }, { "bdzlrl-", XLO(19,BODZM4,16,1), XLBOBIBB_MASK, POWER4, { 0 } }, { "bdzlrl+", XLO(19,BODZP,16,1), XLBOBIBB_MASK, NOPOWER4, { 0 } }, { "bdzlrl+", XLO(19,BODZP4,16,1), XLBOBIBB_MASK, POWER4, { 0 } }, { "bltlr", XLOCB(19,BOT,CBLT,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bltlr-", XLOCB(19,BOT,CBLT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bltlr-", XLOCB(19,BOTM4,CBLT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bltlr+", XLOCB(19,BOTP,CBLT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bltlr+", XLOCB(19,BOTP4,CBLT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bltr", XLOCB(19,BOT,CBLT,16,0), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bltlrl", XLOCB(19,BOT,CBLT,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bltlrl-", XLOCB(19,BOT,CBLT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bltlrl-", XLOCB(19,BOTM4,CBLT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bltlrl+", XLOCB(19,BOTP,CBLT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bltlrl+", XLOCB(19,BOTP4,CBLT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bltrl", XLOCB(19,BOT,CBLT,16,1), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bgtlr", XLOCB(19,BOT,CBGT,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bgtlr-", XLOCB(19,BOT,CBGT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgtlr-", XLOCB(19,BOTM4,CBGT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bgtlr+", XLOCB(19,BOTP,CBGT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgtlr+", XLOCB(19,BOTP4,CBGT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bgtr", XLOCB(19,BOT,CBGT,16,0), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bgtlrl", XLOCB(19,BOT,CBGT,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bgtlrl-", XLOCB(19,BOT,CBGT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgtlrl-", XLOCB(19,BOTM4,CBGT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bgtlrl+", XLOCB(19,BOTP,CBGT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgtlrl+", XLOCB(19,BOTP4,CBGT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bgtrl", XLOCB(19,BOT,CBGT,16,1), XLBOCBBB_MASK, PWRCOM, { CR } }, { "beqlr", XLOCB(19,BOT,CBEQ,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "beqlr-", XLOCB(19,BOT,CBEQ,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "beqlr-", XLOCB(19,BOTM4,CBEQ,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "beqlr+", XLOCB(19,BOTP,CBEQ,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "beqlr+", XLOCB(19,BOTP4,CBEQ,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "beqr", XLOCB(19,BOT,CBEQ,16,0), XLBOCBBB_MASK, PWRCOM, { CR } }, { "beqlrl", XLOCB(19,BOT,CBEQ,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "beqlrl-", XLOCB(19,BOT,CBEQ,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "beqlrl-", XLOCB(19,BOTM4,CBEQ,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "beqlrl+", XLOCB(19,BOTP,CBEQ,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "beqlrl+", XLOCB(19,BOTP4,CBEQ,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "beqrl", XLOCB(19,BOT,CBEQ,16,1), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bsolr", XLOCB(19,BOT,CBSO,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bsolr-", XLOCB(19,BOT,CBSO,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bsolr-", XLOCB(19,BOTM4,CBSO,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bsolr+", XLOCB(19,BOTP,CBSO,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bsolr+", XLOCB(19,BOTP4,CBSO,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bsor", XLOCB(19,BOT,CBSO,16,0), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bsolrl", XLOCB(19,BOT,CBSO,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bsolrl-", XLOCB(19,BOT,CBSO,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bsolrl-", XLOCB(19,BOTM4,CBSO,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bsolrl+", XLOCB(19,BOTP,CBSO,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bsolrl+", XLOCB(19,BOTP4,CBSO,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bsorl", XLOCB(19,BOT,CBSO,16,1), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bunlr", XLOCB(19,BOT,CBSO,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bunlr-", XLOCB(19,BOT,CBSO,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bunlr-", XLOCB(19,BOTM4,CBSO,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bunlr+", XLOCB(19,BOTP,CBSO,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bunlr+", XLOCB(19,BOTP4,CBSO,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bunlrl", XLOCB(19,BOT,CBSO,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bunlrl-", XLOCB(19,BOT,CBSO,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bunlrl-", XLOCB(19,BOTM4,CBSO,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bunlrl+", XLOCB(19,BOTP,CBSO,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bunlrl+", XLOCB(19,BOTP4,CBSO,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bgelr", XLOCB(19,BOF,CBLT,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bgelr-", XLOCB(19,BOF,CBLT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgelr-", XLOCB(19,BOFM4,CBLT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bgelr+", XLOCB(19,BOFP,CBLT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgelr+", XLOCB(19,BOFP4,CBLT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bger", XLOCB(19,BOF,CBLT,16,0), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bgelrl", XLOCB(19,BOF,CBLT,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bgelrl-", XLOCB(19,BOF,CBLT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgelrl-", XLOCB(19,BOFM4,CBLT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bgelrl+", XLOCB(19,BOFP,CBLT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgelrl+", XLOCB(19,BOFP4,CBLT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bgerl", XLOCB(19,BOF,CBLT,16,1), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bnllr", XLOCB(19,BOF,CBLT,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnllr-", XLOCB(19,BOF,CBLT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnllr-", XLOCB(19,BOFM4,CBLT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnllr+", XLOCB(19,BOFP,CBLT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnllr+", XLOCB(19,BOFP4,CBLT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnlr", XLOCB(19,BOF,CBLT,16,0), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bnllrl", XLOCB(19,BOF,CBLT,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnllrl-", XLOCB(19,BOF,CBLT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnllrl-", XLOCB(19,BOFM4,CBLT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnllrl+", XLOCB(19,BOFP,CBLT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnllrl+", XLOCB(19,BOFP4,CBLT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnlrl", XLOCB(19,BOF,CBLT,16,1), XLBOCBBB_MASK, PWRCOM, { CR } }, { "blelr", XLOCB(19,BOF,CBGT,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "blelr-", XLOCB(19,BOF,CBGT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "blelr-", XLOCB(19,BOFM4,CBGT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "blelr+", XLOCB(19,BOFP,CBGT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "blelr+", XLOCB(19,BOFP4,CBGT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bler", XLOCB(19,BOF,CBGT,16,0), XLBOCBBB_MASK, PWRCOM, { CR } }, { "blelrl", XLOCB(19,BOF,CBGT,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "blelrl-", XLOCB(19,BOF,CBGT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "blelrl-", XLOCB(19,BOFM4,CBGT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "blelrl+", XLOCB(19,BOFP,CBGT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "blelrl+", XLOCB(19,BOFP4,CBGT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "blerl", XLOCB(19,BOF,CBGT,16,1), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bnglr", XLOCB(19,BOF,CBGT,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnglr-", XLOCB(19,BOF,CBGT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnglr-", XLOCB(19,BOFM4,CBGT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnglr+", XLOCB(19,BOFP,CBGT,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnglr+", XLOCB(19,BOFP4,CBGT,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bngr", XLOCB(19,BOF,CBGT,16,0), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bnglrl", XLOCB(19,BOF,CBGT,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnglrl-", XLOCB(19,BOF,CBGT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnglrl-", XLOCB(19,BOFM4,CBGT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnglrl+", XLOCB(19,BOFP,CBGT,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnglrl+", XLOCB(19,BOFP4,CBGT,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bngrl", XLOCB(19,BOF,CBGT,16,1), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bnelr", XLOCB(19,BOF,CBEQ,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnelr-", XLOCB(19,BOF,CBEQ,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnelr-", XLOCB(19,BOFM4,CBEQ,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnelr+", XLOCB(19,BOFP,CBEQ,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnelr+", XLOCB(19,BOFP4,CBEQ,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bner", XLOCB(19,BOF,CBEQ,16,0), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bnelrl", XLOCB(19,BOF,CBEQ,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnelrl-", XLOCB(19,BOF,CBEQ,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnelrl-", XLOCB(19,BOFM4,CBEQ,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnelrl+", XLOCB(19,BOFP,CBEQ,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnelrl+", XLOCB(19,BOFP4,CBEQ,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnerl", XLOCB(19,BOF,CBEQ,16,1), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bnslr", XLOCB(19,BOF,CBSO,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnslr-", XLOCB(19,BOF,CBSO,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnslr-", XLOCB(19,BOFM4,CBSO,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnslr+", XLOCB(19,BOFP,CBSO,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnslr+", XLOCB(19,BOFP4,CBSO,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnsr", XLOCB(19,BOF,CBSO,16,0), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bnslrl", XLOCB(19,BOF,CBSO,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnslrl-", XLOCB(19,BOF,CBSO,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnslrl-", XLOCB(19,BOFM4,CBSO,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnslrl+", XLOCB(19,BOFP,CBSO,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnslrl+", XLOCB(19,BOFP4,CBSO,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnsrl", XLOCB(19,BOF,CBSO,16,1), XLBOCBBB_MASK, PWRCOM, { CR } }, { "bnulr", XLOCB(19,BOF,CBSO,16,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnulr-", XLOCB(19,BOF,CBSO,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnulr-", XLOCB(19,BOFM4,CBSO,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnulr+", XLOCB(19,BOFP,CBSO,16,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnulr+", XLOCB(19,BOFP4,CBSO,16,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnulrl", XLOCB(19,BOF,CBSO,16,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnulrl-", XLOCB(19,BOF,CBSO,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnulrl-", XLOCB(19,BOFM4,CBSO,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnulrl+", XLOCB(19,BOFP,CBSO,16,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnulrl+", XLOCB(19,BOFP4,CBSO,16,1), XLBOCBBB_MASK, POWER4, { CR } }, { "btlr", XLO(19,BOT,16,0), XLBOBB_MASK, PPCCOM, { BI } }, { "btlr-", XLO(19,BOT,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "btlr-", XLO(19,BOTM4,16,0), XLBOBB_MASK, POWER4, { BI } }, { "btlr+", XLO(19,BOTP,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "btlr+", XLO(19,BOTP4,16,0), XLBOBB_MASK, POWER4, { BI } }, { "bbtr", XLO(19,BOT,16,0), XLBOBB_MASK, PWRCOM, { BI } }, { "btlrl", XLO(19,BOT,16,1), XLBOBB_MASK, PPCCOM, { BI } }, { "btlrl-", XLO(19,BOT,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "btlrl-", XLO(19,BOTM4,16,1), XLBOBB_MASK, POWER4, { BI } }, { "btlrl+", XLO(19,BOTP,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "btlrl+", XLO(19,BOTP4,16,1), XLBOBB_MASK, POWER4, { BI } }, { "bbtrl", XLO(19,BOT,16,1), XLBOBB_MASK, PWRCOM, { BI } }, { "bflr", XLO(19,BOF,16,0), XLBOBB_MASK, PPCCOM, { BI } }, { "bflr-", XLO(19,BOF,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bflr-", XLO(19,BOFM4,16,0), XLBOBB_MASK, POWER4, { BI } }, { "bflr+", XLO(19,BOFP,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bflr+", XLO(19,BOFP4,16,0), XLBOBB_MASK, POWER4, { BI } }, { "bbfr", XLO(19,BOF,16,0), XLBOBB_MASK, PWRCOM, { BI } }, { "bflrl", XLO(19,BOF,16,1), XLBOBB_MASK, PPCCOM, { BI } }, { "bflrl-", XLO(19,BOF,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bflrl-", XLO(19,BOFM4,16,1), XLBOBB_MASK, POWER4, { BI } }, { "bflrl+", XLO(19,BOFP,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bflrl+", XLO(19,BOFP4,16,1), XLBOBB_MASK, POWER4, { BI } }, { "bbfrl", XLO(19,BOF,16,1), XLBOBB_MASK, PWRCOM, { BI } }, { "bdnztlr", XLO(19,BODNZT,16,0), XLBOBB_MASK, PPCCOM, { BI } }, { "bdnztlr-",XLO(19,BODNZT,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdnztlr+",XLO(19,BODNZTP,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdnztlrl",XLO(19,BODNZT,16,1), XLBOBB_MASK, PPCCOM, { BI } }, { "bdnztlrl-",XLO(19,BODNZT,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdnztlrl+",XLO(19,BODNZTP,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdnzflr", XLO(19,BODNZF,16,0), XLBOBB_MASK, PPCCOM, { BI } }, { "bdnzflr-",XLO(19,BODNZF,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdnzflr+",XLO(19,BODNZFP,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdnzflrl",XLO(19,BODNZF,16,1), XLBOBB_MASK, PPCCOM, { BI } }, { "bdnzflrl-",XLO(19,BODNZF,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdnzflrl+",XLO(19,BODNZFP,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdztlr", XLO(19,BODZT,16,0), XLBOBB_MASK, PPCCOM, { BI } }, { "bdztlr-", XLO(19,BODZT,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdztlr+", XLO(19,BODZTP,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdztlrl", XLO(19,BODZT,16,1), XLBOBB_MASK, PPCCOM, { BI } }, { "bdztlrl-",XLO(19,BODZT,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdztlrl+",XLO(19,BODZTP,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdzflr", XLO(19,BODZF,16,0), XLBOBB_MASK, PPCCOM, { BI } }, { "bdzflr-", XLO(19,BODZF,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdzflr+", XLO(19,BODZFP,16,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdzflrl", XLO(19,BODZF,16,1), XLBOBB_MASK, PPCCOM, { BI } }, { "bdzflrl-",XLO(19,BODZF,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bdzflrl+",XLO(19,BODZFP,16,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bclr+", XLYLK(19,16,1,0), XLYBB_MASK, PPCCOM, { BOE, BI } }, { "bclrl+", XLYLK(19,16,1,1), XLYBB_MASK, PPCCOM, { BOE, BI } }, { "bclr-", XLYLK(19,16,0,0), XLYBB_MASK, PPCCOM, { BOE, BI } }, { "bclrl-", XLYLK(19,16,0,1), XLYBB_MASK, PPCCOM, { BOE, BI } }, { "bclr", XLLK(19,16,0), XLBH_MASK, PPCCOM, { BO, BI, BH } }, { "bclrl", XLLK(19,16,1), XLBH_MASK, PPCCOM, { BO, BI, BH } }, { "bcr", XLLK(19,16,0), XLBB_MASK, PWRCOM, { BO, BI } }, { "bcrl", XLLK(19,16,1), XLBB_MASK, PWRCOM, { BO, BI } }, { "bclre", XLLK(19,17,0), XLBB_MASK, BOOKE64, { BO, BI } }, { "bclrel", XLLK(19,17,1), XLBB_MASK, BOOKE64, { BO, BI } }, { "rfid", XL(19,18), 0xffffffff, PPC64, { 0 } }, { "crnot", XL(19,33), XL_MASK, PPCCOM, { BT, BA, BBA } }, { "crnor", XL(19,33), XL_MASK, COM, { BT, BA, BB } }, { "rfmci", X(19,38), 0xffffffff, PPCRFMCI, { 0 } }, { "rfi", XL(19,50), 0xffffffff, COM, { 0 } }, { "rfci", XL(19,51), 0xffffffff, PPC403 | BOOKE, { 0 } }, { "rfsvc", XL(19,82), 0xffffffff, POWER, { 0 } }, { "crandc", XL(19,129), XL_MASK, COM, { BT, BA, BB } }, { "isync", XL(19,150), 0xffffffff, PPCCOM, { 0 } }, { "ics", XL(19,150), 0xffffffff, PWRCOM, { 0 } }, { "crclr", XL(19,193), XL_MASK, PPCCOM, { BT, BAT, BBA } }, { "crxor", XL(19,193), XL_MASK, COM, { BT, BA, BB } }, { "crnand", XL(19,225), XL_MASK, COM, { BT, BA, BB } }, { "crand", XL(19,257), XL_MASK, COM, { BT, BA, BB } }, { "hrfid", XL(19,274), 0xffffffff, POWER5 | CELL, { 0 } }, { "crset", XL(19,289), XL_MASK, PPCCOM, { BT, BAT, BBA } }, { "creqv", XL(19,289), XL_MASK, COM, { BT, BA, BB } }, { "doze", XL(19,402), 0xffffffff, POWER6, { 0 } }, { "crorc", XL(19,417), XL_MASK, COM, { BT, BA, BB } }, { "nap", XL(19,434), 0xffffffff, POWER6, { 0 } }, { "crmove", XL(19,449), XL_MASK, PPCCOM, { BT, BA, BBA } }, { "cror", XL(19,449), XL_MASK, COM, { BT, BA, BB } }, { "sleep", XL(19,466), 0xffffffff, POWER6, { 0 } }, { "rvwinkle", XL(19,498), 0xffffffff, POWER6, { 0 } }, { "bctr", XLO(19,BOU,528,0), XLBOBIBB_MASK, COM, { 0 } }, { "bctrl", XLO(19,BOU,528,1), XLBOBIBB_MASK, COM, { 0 } }, { "bltctr", XLOCB(19,BOT,CBLT,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bltctr-", XLOCB(19,BOT,CBLT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bltctr-", XLOCB(19,BOTM4,CBLT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bltctr+", XLOCB(19,BOTP,CBLT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bltctr+", XLOCB(19,BOTP4,CBLT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bltctrl", XLOCB(19,BOT,CBLT,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bltctrl-",XLOCB(19,BOT,CBLT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bltctrl-",XLOCB(19,BOTM4,CBLT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bltctrl+",XLOCB(19,BOTP,CBLT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bltctrl+",XLOCB(19,BOTP4,CBLT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bgtctr", XLOCB(19,BOT,CBGT,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bgtctr-", XLOCB(19,BOT,CBGT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgtctr-", XLOCB(19,BOTM4,CBGT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bgtctr+", XLOCB(19,BOTP,CBGT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgtctr+", XLOCB(19,BOTP4,CBGT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bgtctrl", XLOCB(19,BOT,CBGT,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bgtctrl-",XLOCB(19,BOT,CBGT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgtctrl-",XLOCB(19,BOTM4,CBGT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bgtctrl+",XLOCB(19,BOTP,CBGT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgtctrl+",XLOCB(19,BOTP4,CBGT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "beqctr", XLOCB(19,BOT,CBEQ,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "beqctr-", XLOCB(19,BOT,CBEQ,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "beqctr-", XLOCB(19,BOTM4,CBEQ,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "beqctr+", XLOCB(19,BOTP,CBEQ,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "beqctr+", XLOCB(19,BOTP4,CBEQ,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "beqctrl", XLOCB(19,BOT,CBEQ,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "beqctrl-",XLOCB(19,BOT,CBEQ,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "beqctrl-",XLOCB(19,BOTM4,CBEQ,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "beqctrl+",XLOCB(19,BOTP,CBEQ,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "beqctrl+",XLOCB(19,BOTP4,CBEQ,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bsoctr", XLOCB(19,BOT,CBSO,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bsoctr-", XLOCB(19,BOT,CBSO,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bsoctr-", XLOCB(19,BOTM4,CBSO,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bsoctr+", XLOCB(19,BOTP,CBSO,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bsoctr+", XLOCB(19,BOTP4,CBSO,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bsoctrl", XLOCB(19,BOT,CBSO,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bsoctrl-",XLOCB(19,BOT,CBSO,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bsoctrl-",XLOCB(19,BOTM4,CBSO,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bsoctrl+",XLOCB(19,BOTP,CBSO,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bsoctrl+",XLOCB(19,BOTP4,CBSO,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bunctr", XLOCB(19,BOT,CBSO,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bunctr-", XLOCB(19,BOT,CBSO,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bunctr-", XLOCB(19,BOTM4,CBSO,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bunctr+", XLOCB(19,BOTP,CBSO,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bunctr+", XLOCB(19,BOTP4,CBSO,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bunctrl", XLOCB(19,BOT,CBSO,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bunctrl-",XLOCB(19,BOT,CBSO,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bunctrl-",XLOCB(19,BOTM4,CBSO,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bunctrl+",XLOCB(19,BOTP,CBSO,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bunctrl+",XLOCB(19,BOTP4,CBSO,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bgectr", XLOCB(19,BOF,CBLT,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bgectr-", XLOCB(19,BOF,CBLT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgectr-", XLOCB(19,BOFM4,CBLT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bgectr+", XLOCB(19,BOFP,CBLT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgectr+", XLOCB(19,BOFP4,CBLT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bgectrl", XLOCB(19,BOF,CBLT,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bgectrl-",XLOCB(19,BOF,CBLT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgectrl-",XLOCB(19,BOFM4,CBLT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bgectrl+",XLOCB(19,BOFP,CBLT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bgectrl+",XLOCB(19,BOFP4,CBLT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnlctr", XLOCB(19,BOF,CBLT,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnlctr-", XLOCB(19,BOF,CBLT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnlctr-", XLOCB(19,BOFM4,CBLT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnlctr+", XLOCB(19,BOFP,CBLT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnlctr+", XLOCB(19,BOFP4,CBLT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnlctrl", XLOCB(19,BOF,CBLT,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnlctrl-",XLOCB(19,BOF,CBLT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnlctrl-",XLOCB(19,BOFM4,CBLT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnlctrl+",XLOCB(19,BOFP,CBLT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnlctrl+",XLOCB(19,BOFP4,CBLT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "blectr", XLOCB(19,BOF,CBGT,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "blectr-", XLOCB(19,BOF,CBGT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "blectr-", XLOCB(19,BOFM4,CBGT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "blectr+", XLOCB(19,BOFP,CBGT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "blectr+", XLOCB(19,BOFP4,CBGT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "blectrl", XLOCB(19,BOF,CBGT,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "blectrl-",XLOCB(19,BOF,CBGT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "blectrl-",XLOCB(19,BOFM4,CBGT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "blectrl+",XLOCB(19,BOFP,CBGT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "blectrl+",XLOCB(19,BOFP4,CBGT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bngctr", XLOCB(19,BOF,CBGT,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bngctr-", XLOCB(19,BOF,CBGT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bngctr-", XLOCB(19,BOFM4,CBGT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bngctr+", XLOCB(19,BOFP,CBGT,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bngctr+", XLOCB(19,BOFP4,CBGT,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bngctrl", XLOCB(19,BOF,CBGT,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bngctrl-",XLOCB(19,BOF,CBGT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bngctrl-",XLOCB(19,BOFM4,CBGT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bngctrl+",XLOCB(19,BOFP,CBGT,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bngctrl+",XLOCB(19,BOFP4,CBGT,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnectr", XLOCB(19,BOF,CBEQ,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnectr-", XLOCB(19,BOF,CBEQ,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnectr-", XLOCB(19,BOFM4,CBEQ,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnectr+", XLOCB(19,BOFP,CBEQ,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnectr+", XLOCB(19,BOFP4,CBEQ,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnectrl", XLOCB(19,BOF,CBEQ,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnectrl-",XLOCB(19,BOF,CBEQ,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnectrl-",XLOCB(19,BOFM4,CBEQ,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnectrl+",XLOCB(19,BOFP,CBEQ,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnectrl+",XLOCB(19,BOFP4,CBEQ,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnsctr", XLOCB(19,BOF,CBSO,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnsctr-", XLOCB(19,BOF,CBSO,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnsctr-", XLOCB(19,BOFM4,CBSO,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnsctr+", XLOCB(19,BOFP,CBSO,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnsctr+", XLOCB(19,BOFP4,CBSO,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnsctrl", XLOCB(19,BOF,CBSO,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnsctrl-",XLOCB(19,BOF,CBSO,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnsctrl-",XLOCB(19,BOFM4,CBSO,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnsctrl+",XLOCB(19,BOFP,CBSO,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnsctrl+",XLOCB(19,BOFP4,CBSO,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnuctr", XLOCB(19,BOF,CBSO,528,0), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnuctr-", XLOCB(19,BOF,CBSO,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnuctr-", XLOCB(19,BOFM4,CBSO,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnuctr+", XLOCB(19,BOFP,CBSO,528,0), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnuctr+", XLOCB(19,BOFP4,CBSO,528,0), XLBOCBBB_MASK, POWER4, { CR } }, { "bnuctrl", XLOCB(19,BOF,CBSO,528,1), XLBOCBBB_MASK, PPCCOM, { CR } }, { "bnuctrl-",XLOCB(19,BOF,CBSO,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnuctrl-",XLOCB(19,BOFM4,CBSO,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "bnuctrl+",XLOCB(19,BOFP,CBSO,528,1), XLBOCBBB_MASK, NOPOWER4, { CR } }, { "bnuctrl+",XLOCB(19,BOFP4,CBSO,528,1), XLBOCBBB_MASK, POWER4, { CR } }, { "btctr", XLO(19,BOT,528,0), XLBOBB_MASK, PPCCOM, { BI } }, { "btctr-", XLO(19,BOT,528,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "btctr-", XLO(19,BOTM4,528,0), XLBOBB_MASK, POWER4, { BI } }, { "btctr+", XLO(19,BOTP,528,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "btctr+", XLO(19,BOTP4,528,0), XLBOBB_MASK, POWER4, { BI } }, { "btctrl", XLO(19,BOT,528,1), XLBOBB_MASK, PPCCOM, { BI } }, { "btctrl-", XLO(19,BOT,528,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "btctrl-", XLO(19,BOTM4,528,1), XLBOBB_MASK, POWER4, { BI } }, { "btctrl+", XLO(19,BOTP,528,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "btctrl+", XLO(19,BOTP4,528,1), XLBOBB_MASK, POWER4, { BI } }, { "bfctr", XLO(19,BOF,528,0), XLBOBB_MASK, PPCCOM, { BI } }, { "bfctr-", XLO(19,BOF,528,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bfctr-", XLO(19,BOFM4,528,0), XLBOBB_MASK, POWER4, { BI } }, { "bfctr+", XLO(19,BOFP,528,0), XLBOBB_MASK, NOPOWER4, { BI } }, { "bfctr+", XLO(19,BOFP4,528,0), XLBOBB_MASK, POWER4, { BI } }, { "bfctrl", XLO(19,BOF,528,1), XLBOBB_MASK, PPCCOM, { BI } }, { "bfctrl-", XLO(19,BOF,528,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bfctrl-", XLO(19,BOFM4,528,1), XLBOBB_MASK, POWER4, { BI } }, { "bfctrl+", XLO(19,BOFP,528,1), XLBOBB_MASK, NOPOWER4, { BI } }, { "bfctrl+", XLO(19,BOFP4,528,1), XLBOBB_MASK, POWER4, { BI } }, { "bcctr-", XLYLK(19,528,0,0), XLYBB_MASK, PPCCOM, { BOE, BI } }, { "bcctr+", XLYLK(19,528,1,0), XLYBB_MASK, PPCCOM, { BOE, BI } }, { "bcctrl-", XLYLK(19,528,0,1), XLYBB_MASK, PPCCOM, { BOE, BI } }, { "bcctrl+", XLYLK(19,528,1,1), XLYBB_MASK, PPCCOM, { BOE, BI } }, { "bcctr", XLLK(19,528,0), XLBH_MASK, PPCCOM, { BO, BI, BH } }, { "bcctrl", XLLK(19,528,1), XLBH_MASK, PPCCOM, { BO, BI, BH } }, { "bcc", XLLK(19,528,0), XLBB_MASK, PWRCOM, { BO, BI } }, { "bccl", XLLK(19,528,1), XLBB_MASK, PWRCOM, { BO, BI } }, { "bcctre", XLLK(19,529,0), XLYBB_MASK, BOOKE64, { BO, BI } }, { "bcctrel", XLLK(19,529,1), XLYBB_MASK, BOOKE64, { BO, BI } }, { "rlwimi", M(20,0), M_MASK, PPCCOM, { RA,RS,SH,MBE,ME } }, { "rlimi", M(20,0), M_MASK, PWRCOM, { RA,RS,SH,MBE,ME } }, { "rlwimi.", M(20,1), M_MASK, PPCCOM, { RA,RS,SH,MBE,ME } }, { "rlimi.", M(20,1), M_MASK, PWRCOM, { RA,RS,SH,MBE,ME } }, { "rotlwi", MME(21,31,0), MMBME_MASK, PPCCOM, { RA, RS, SH } }, { "clrlwi", MME(21,31,0), MSHME_MASK, PPCCOM, { RA, RS, MB } }, { "rlwinm", M(21,0), M_MASK, PPCCOM, { RA,RS,SH,MBE,ME } }, { "rlinm", M(21,0), M_MASK, PWRCOM, { RA,RS,SH,MBE,ME } }, { "rotlwi.", MME(21,31,1), MMBME_MASK, PPCCOM, { RA,RS,SH } }, { "clrlwi.", MME(21,31,1), MSHME_MASK, PPCCOM, { RA, RS, MB } }, { "rlwinm.", M(21,1), M_MASK, PPCCOM, { RA,RS,SH,MBE,ME } }, { "rlinm.", M(21,1), M_MASK, PWRCOM, { RA,RS,SH,MBE,ME } }, { "rlmi", M(22,0), M_MASK, M601, { RA,RS,RB,MBE,ME } }, { "rlmi.", M(22,1), M_MASK, M601, { RA,RS,RB,MBE,ME } }, { "be", B(22,0,0), B_MASK, BOOKE64, { LI } }, { "bel", B(22,0,1), B_MASK, BOOKE64, { LI } }, { "bea", B(22,1,0), B_MASK, BOOKE64, { LIA } }, { "bela", B(22,1,1), B_MASK, BOOKE64, { LIA } }, { "rotlw", MME(23,31,0), MMBME_MASK, PPCCOM, { RA, RS, RB } }, { "rlwnm", M(23,0), M_MASK, PPCCOM, { RA,RS,RB,MBE,ME } }, { "rlnm", M(23,0), M_MASK, PWRCOM, { RA,RS,RB,MBE,ME } }, { "rotlw.", MME(23,31,1), MMBME_MASK, PPCCOM, { RA, RS, RB } }, { "rlwnm.", M(23,1), M_MASK, PPCCOM, { RA,RS,RB,MBE,ME } }, { "rlnm.", M(23,1), M_MASK, PWRCOM, { RA,RS,RB,MBE,ME } }, { "nop", OP(24), 0xffffffff, PPCCOM, { 0 } }, { "ori", OP(24), OP_MASK, PPCCOM, { RA, RS, UI } }, { "oril", OP(24), OP_MASK, PWRCOM, { RA, RS, UI } }, { "oris", OP(25), OP_MASK, PPCCOM, { RA, RS, UI } }, { "oriu", OP(25), OP_MASK, PWRCOM, { RA, RS, UI } }, { "xori", OP(26), OP_MASK, PPCCOM, { RA, RS, UI } }, { "xoril", OP(26), OP_MASK, PWRCOM, { RA, RS, UI } }, { "xoris", OP(27), OP_MASK, PPCCOM, { RA, RS, UI } }, { "xoriu", OP(27), OP_MASK, PWRCOM, { RA, RS, UI } }, { "andi.", OP(28), OP_MASK, PPCCOM, { RA, RS, UI } }, { "andil.", OP(28), OP_MASK, PWRCOM, { RA, RS, UI } }, { "andis.", OP(29), OP_MASK, PPCCOM, { RA, RS, UI } }, { "andiu.", OP(29), OP_MASK, PWRCOM, { RA, RS, UI } }, { "rotldi", MD(30,0,0), MDMB_MASK, PPC64, { RA, RS, SH6 } }, { "clrldi", MD(30,0,0), MDSH_MASK, PPC64, { RA, RS, MB6 } }, { "rldicl", MD(30,0,0), MD_MASK, PPC64, { RA, RS, SH6, MB6 } }, { "rotldi.", MD(30,0,1), MDMB_MASK, PPC64, { RA, RS, SH6 } }, { "clrldi.", MD(30,0,1), MDSH_MASK, PPC64, { RA, RS, MB6 } }, { "rldicl.", MD(30,0,1), MD_MASK, PPC64, { RA, RS, SH6, MB6 } }, { "rldicr", MD(30,1,0), MD_MASK, PPC64, { RA, RS, SH6, ME6 } }, { "rldicr.", MD(30,1,1), MD_MASK, PPC64, { RA, RS, SH6, ME6 } }, { "rldic", MD(30,2,0), MD_MASK, PPC64, { RA, RS, SH6, MB6 } }, { "rldic.", MD(30,2,1), MD_MASK, PPC64, { RA, RS, SH6, MB6 } }, { "rldimi", MD(30,3,0), MD_MASK, PPC64, { RA, RS, SH6, MB6 } }, { "rldimi.", MD(30,3,1), MD_MASK, PPC64, { RA, RS, SH6, MB6 } }, { "rotld", MDS(30,8,0), MDSMB_MASK, PPC64, { RA, RS, RB } }, { "rldcl", MDS(30,8,0), MDS_MASK, PPC64, { RA, RS, RB, MB6 } }, { "rotld.", MDS(30,8,1), MDSMB_MASK, PPC64, { RA, RS, RB } }, { "rldcl.", MDS(30,8,1), MDS_MASK, PPC64, { RA, RS, RB, MB6 } }, { "rldcr", MDS(30,9,0), MDS_MASK, PPC64, { RA, RS, RB, ME6 } }, { "rldcr.", MDS(30,9,1), MDS_MASK, PPC64, { RA, RS, RB, ME6 } }, { "cmpw", XOPL(31,0,0), XCMPL_MASK, PPCCOM, { OBF, RA, RB } }, { "cmpd", XOPL(31,0,1), XCMPL_MASK, PPC64, { OBF, RA, RB } }, { "cmp", X(31,0), XCMP_MASK, PPC, { BF, L, RA, RB } }, { "cmp", X(31,0), XCMPL_MASK, PWRCOM, { BF, RA, RB } }, { "twlgt", XTO(31,4,TOLGT), XTO_MASK, PPCCOM, { RA, RB } }, { "tlgt", XTO(31,4,TOLGT), XTO_MASK, PWRCOM, { RA, RB } }, { "twllt", XTO(31,4,TOLLT), XTO_MASK, PPCCOM, { RA, RB } }, { "tllt", XTO(31,4,TOLLT), XTO_MASK, PWRCOM, { RA, RB } }, { "tweq", XTO(31,4,TOEQ), XTO_MASK, PPCCOM, { RA, RB } }, { "teq", XTO(31,4,TOEQ), XTO_MASK, PWRCOM, { RA, RB } }, { "twlge", XTO(31,4,TOLGE), XTO_MASK, PPCCOM, { RA, RB } }, { "tlge", XTO(31,4,TOLGE), XTO_MASK, PWRCOM, { RA, RB } }, { "twlnl", XTO(31,4,TOLNL), XTO_MASK, PPCCOM, { RA, RB } }, { "tlnl", XTO(31,4,TOLNL), XTO_MASK, PWRCOM, { RA, RB } }, { "twlle", XTO(31,4,TOLLE), XTO_MASK, PPCCOM, { RA, RB } }, { "tlle", XTO(31,4,TOLLE), XTO_MASK, PWRCOM, { RA, RB } }, { "twlng", XTO(31,4,TOLNG), XTO_MASK, PPCCOM, { RA, RB } }, { "tlng", XTO(31,4,TOLNG), XTO_MASK, PWRCOM, { RA, RB } }, { "twgt", XTO(31,4,TOGT), XTO_MASK, PPCCOM, { RA, RB } }, { "tgt", XTO(31,4,TOGT), XTO_MASK, PWRCOM, { RA, RB } }, { "twge", XTO(31,4,TOGE), XTO_MASK, PPCCOM, { RA, RB } }, { "tge", XTO(31,4,TOGE), XTO_MASK, PWRCOM, { RA, RB } }, { "twnl", XTO(31,4,TONL), XTO_MASK, PPCCOM, { RA, RB } }, { "tnl", XTO(31,4,TONL), XTO_MASK, PWRCOM, { RA, RB } }, { "twlt", XTO(31,4,TOLT), XTO_MASK, PPCCOM, { RA, RB } }, { "tlt", XTO(31,4,TOLT), XTO_MASK, PWRCOM, { RA, RB } }, { "twle", XTO(31,4,TOLE), XTO_MASK, PPCCOM, { RA, RB } }, { "tle", XTO(31,4,TOLE), XTO_MASK, PWRCOM, { RA, RB } }, { "twng", XTO(31,4,TONG), XTO_MASK, PPCCOM, { RA, RB } }, { "tng", XTO(31,4,TONG), XTO_MASK, PWRCOM, { RA, RB } }, { "twne", XTO(31,4,TONE), XTO_MASK, PPCCOM, { RA, RB } }, { "tne", XTO(31,4,TONE), XTO_MASK, PWRCOM, { RA, RB } }, { "trap", XTO(31,4,TOU), 0xffffffff, PPCCOM, { 0 } }, { "tw", X(31,4), X_MASK, PPCCOM, { TO, RA, RB } }, { "t", X(31,4), X_MASK, PWRCOM, { TO, RA, RB } }, { "subfc", XO(31,8,0,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "sf", XO(31,8,0,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "subc", XO(31,8,0,0), XO_MASK, PPC, { RT, RB, RA } }, { "subfc.", XO(31,8,0,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "sf.", XO(31,8,0,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "subc.", XO(31,8,0,1), XO_MASK, PPCCOM, { RT, RB, RA } }, { "subfco", XO(31,8,1,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "sfo", XO(31,8,1,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "subco", XO(31,8,1,0), XO_MASK, PPC, { RT, RB, RA } }, { "subfco.", XO(31,8,1,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "sfo.", XO(31,8,1,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "subco.", XO(31,8,1,1), XO_MASK, PPC, { RT, RB, RA } }, { "mulhdu", XO(31,9,0,0), XO_MASK, PPC64, { RT, RA, RB } }, { "mulhdu.", XO(31,9,0,1), XO_MASK, PPC64, { RT, RA, RB } }, { "addc", XO(31,10,0,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "a", XO(31,10,0,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "addc.", XO(31,10,0,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "a.", XO(31,10,0,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "addco", XO(31,10,1,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "ao", XO(31,10,1,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "addco.", XO(31,10,1,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "ao.", XO(31,10,1,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "mulhwu", XO(31,11,0,0), XO_MASK, PPC, { RT, RA, RB } }, { "mulhwu.", XO(31,11,0,1), XO_MASK, PPC, { RT, RA, RB } }, { "isellt", X(31,15), X_MASK, PPCISEL, { RT, RA, RB } }, { "iselgt", X(31,47), X_MASK, PPCISEL, { RT, RA, RB } }, { "iseleq", X(31,79), X_MASK, PPCISEL, { RT, RA, RB } }, { "isel", XISEL(31,15), XISEL_MASK, PPCISEL, { RT, RA, RB, CRB } }, { "mfocrf", XFXM(31,19,0,1), XFXFXM_MASK, COM, { RT, FXM } }, { "mfcr", X(31,19), XRARB_MASK, NOPOWER4 | COM, { RT } }, { "mfcr", X(31,19), XFXFXM_MASK, POWER4, { RT, FXM4 } }, { "lwarx", X(31,20), XEH_MASK, PPC, { RT, RA0, RB, EH } }, { "ldx", X(31,21), X_MASK, PPC64, { RT, RA0, RB } }, { "icbt", X(31,22), X_MASK, BOOKE|PPCE300, { CT, RA, RB } }, { "icbt", X(31,262), XRT_MASK, PPC403, { RA, RB } }, { "lwzx", X(31,23), X_MASK, PPCCOM, { RT, RA0, RB } }, { "lx", X(31,23), X_MASK, PWRCOM, { RT, RA, RB } }, { "slw", XRC(31,24,0), X_MASK, PPCCOM, { RA, RS, RB } }, { "sl", XRC(31,24,0), X_MASK, PWRCOM, { RA, RS, RB } }, { "slw.", XRC(31,24,1), X_MASK, PPCCOM, { RA, RS, RB } }, { "sl.", XRC(31,24,1), X_MASK, PWRCOM, { RA, RS, RB } }, { "cntlzw", XRC(31,26,0), XRB_MASK, PPCCOM, { RA, RS } }, { "cntlz", XRC(31,26,0), XRB_MASK, PWRCOM, { RA, RS } }, { "cntlzw.", XRC(31,26,1), XRB_MASK, PPCCOM, { RA, RS } }, { "cntlz.", XRC(31,26,1), XRB_MASK, PWRCOM, { RA, RS } }, { "sld", XRC(31,27,0), X_MASK, PPC64, { RA, RS, RB } }, { "sld.", XRC(31,27,1), X_MASK, PPC64, { RA, RS, RB } }, { "and", XRC(31,28,0), X_MASK, COM, { RA, RS, RB } }, { "and.", XRC(31,28,1), X_MASK, COM, { RA, RS, RB } }, { "maskg", XRC(31,29,0), X_MASK, M601, { RA, RS, RB } }, { "maskg.", XRC(31,29,1), X_MASK, M601, { RA, RS, RB } }, { "icbte", X(31,30), X_MASK, BOOKE64, { CT, RA, RB } }, { "lwzxe", X(31,31), X_MASK, BOOKE64, { RT, RA0, RB } }, { "cmplw", XOPL(31,32,0), XCMPL_MASK, PPCCOM, { OBF, RA, RB } }, { "cmpld", XOPL(31,32,1), XCMPL_MASK, PPC64, { OBF, RA, RB } }, { "cmpl", X(31,32), XCMP_MASK, PPC, { BF, L, RA, RB } }, { "cmpl", X(31,32), XCMPL_MASK, PWRCOM, { BF, RA, RB } }, { "subf", XO(31,40,0,0), XO_MASK, PPC, { RT, RA, RB } }, { "sub", XO(31,40,0,0), XO_MASK, PPC, { RT, RB, RA } }, { "subf.", XO(31,40,0,1), XO_MASK, PPC, { RT, RA, RB } }, { "sub.", XO(31,40,0,1), XO_MASK, PPC, { RT, RB, RA } }, { "subfo", XO(31,40,1,0), XO_MASK, PPC, { RT, RA, RB } }, { "subo", XO(31,40,1,0), XO_MASK, PPC, { RT, RB, RA } }, { "subfo.", XO(31,40,1,1), XO_MASK, PPC, { RT, RA, RB } }, { "subo.", XO(31,40,1,1), XO_MASK, PPC, { RT, RB, RA } }, { "ldux", X(31,53), X_MASK, PPC64, { RT, RAL, RB } }, { "dcbst", X(31,54), XRT_MASK, PPC, { RA, RB } }, { "lwzux", X(31,55), X_MASK, PPCCOM, { RT, RAL, RB } }, { "lux", X(31,55), X_MASK, PWRCOM, { RT, RA, RB } }, { "dcbste", X(31,62), XRT_MASK, BOOKE64, { RA, RB } }, { "lwzuxe", X(31,63), X_MASK, BOOKE64, { RT, RAL, RB } }, { "cntlzd", XRC(31,58,0), XRB_MASK, PPC64, { RA, RS } }, { "cntlzd.", XRC(31,58,1), XRB_MASK, PPC64, { RA, RS } }, { "andc", XRC(31,60,0), X_MASK, COM, { RA, RS, RB } }, { "andc.", XRC(31,60,1), X_MASK, COM, { RA, RS, RB } }, { "tdlgt", XTO(31,68,TOLGT), XTO_MASK, PPC64, { RA, RB } }, { "tdllt", XTO(31,68,TOLLT), XTO_MASK, PPC64, { RA, RB } }, { "tdeq", XTO(31,68,TOEQ), XTO_MASK, PPC64, { RA, RB } }, { "tdlge", XTO(31,68,TOLGE), XTO_MASK, PPC64, { RA, RB } }, { "tdlnl", XTO(31,68,TOLNL), XTO_MASK, PPC64, { RA, RB } }, { "tdlle", XTO(31,68,TOLLE), XTO_MASK, PPC64, { RA, RB } }, { "tdlng", XTO(31,68,TOLNG), XTO_MASK, PPC64, { RA, RB } }, { "tdgt", XTO(31,68,TOGT), XTO_MASK, PPC64, { RA, RB } }, { "tdge", XTO(31,68,TOGE), XTO_MASK, PPC64, { RA, RB } }, { "tdnl", XTO(31,68,TONL), XTO_MASK, PPC64, { RA, RB } }, { "tdlt", XTO(31,68,TOLT), XTO_MASK, PPC64, { RA, RB } }, { "tdle", XTO(31,68,TOLE), XTO_MASK, PPC64, { RA, RB } }, { "tdng", XTO(31,68,TONG), XTO_MASK, PPC64, { RA, RB } }, { "tdne", XTO(31,68,TONE), XTO_MASK, PPC64, { RA, RB } }, { "td", X(31,68), X_MASK, PPC64, { TO, RA, RB } }, { "mulhd", XO(31,73,0,0), XO_MASK, PPC64, { RT, RA, RB } }, { "mulhd.", XO(31,73,0,1), XO_MASK, PPC64, { RT, RA, RB } }, { "mulhw", XO(31,75,0,0), XO_MASK, PPC, { RT, RA, RB } }, { "mulhw.", XO(31,75,0,1), XO_MASK, PPC, { RT, RA, RB } }, { "dlmzb", XRC(31,78,0), X_MASK, PPC403|PPC440, { RA, RS, RB } }, { "dlmzb.", XRC(31,78,1), X_MASK, PPC403|PPC440, { RA, RS, RB } }, { "mtsrd", X(31,82), XRB_MASK|(1<<20), PPC64, { SR, RS } }, { "mfmsr", X(31,83), XRARB_MASK, COM, { RT } }, { "ldarx", X(31,84), XEH_MASK, PPC64, { RT, RA0, RB, EH } }, { "dcbfl", XOPL(31,86,1), XRT_MASK, POWER5, { RA, RB } }, { "dcbf", X(31,86), XLRT_MASK, PPC, { RA, RB, XRT_L } }, { "lbzx", X(31,87), X_MASK, COM, { RT, RA0, RB } }, { "dcbfe", X(31,94), XRT_MASK, BOOKE64, { RA, RB } }, { "lbzxe", X(31,95), X_MASK, BOOKE64, { RT, RA0, RB } }, { "neg", XO(31,104,0,0), XORB_MASK, COM, { RT, RA } }, { "neg.", XO(31,104,0,1), XORB_MASK, COM, { RT, RA } }, { "nego", XO(31,104,1,0), XORB_MASK, COM, { RT, RA } }, { "nego.", XO(31,104,1,1), XORB_MASK, COM, { RT, RA } }, { "mul", XO(31,107,0,0), XO_MASK, M601, { RT, RA, RB } }, { "mul.", XO(31,107,0,1), XO_MASK, M601, { RT, RA, RB } }, { "mulo", XO(31,107,1,0), XO_MASK, M601, { RT, RA, RB } }, { "mulo.", XO(31,107,1,1), XO_MASK, M601, { RT, RA, RB } }, { "mtsrdin", X(31,114), XRA_MASK, PPC64, { RS, RB } }, { "clf", X(31,118), XTO_MASK, POWER, { RA, RB } }, { "lbzux", X(31,119), X_MASK, COM, { RT, RAL, RB } }, { "popcntb", X(31,122), XRB_MASK, POWER5, { RA, RS } }, { "not", XRC(31,124,0), X_MASK, COM, { RA, RS, RBS } }, { "nor", XRC(31,124,0), X_MASK, COM, { RA, RS, RB } }, { "not.", XRC(31,124,1), X_MASK, COM, { RA, RS, RBS } }, { "nor.", XRC(31,124,1), X_MASK, COM, { RA, RS, RB } }, { "lwarxe", X(31,126), X_MASK, BOOKE64, { RT, RA0, RB } }, { "lbzuxe", X(31,127), X_MASK, BOOKE64, { RT, RAL, RB } }, { "wrtee", X(31,131), XRARB_MASK, PPC403 | BOOKE, { RS } }, { "dcbtstls",X(31,134), X_MASK, PPCCHLK, { CT, RA, RB }}, { "subfe", XO(31,136,0,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "sfe", XO(31,136,0,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "subfe.", XO(31,136,0,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "sfe.", XO(31,136,0,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "subfeo", XO(31,136,1,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "sfeo", XO(31,136,1,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "subfeo.", XO(31,136,1,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "sfeo.", XO(31,136,1,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "adde", XO(31,138,0,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "ae", XO(31,138,0,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "adde.", XO(31,138,0,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "ae.", XO(31,138,0,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "addeo", XO(31,138,1,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "aeo", XO(31,138,1,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "addeo.", XO(31,138,1,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "aeo.", XO(31,138,1,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "dcbtstlse",X(31,142),X_MASK, PPCCHLK64, { CT, RA, RB }}, { "mtocrf", XFXM(31,144,0,1), XFXFXM_MASK, COM, { FXM, RS } }, { "mtcr", XFXM(31,144,0xff,0), XRARB_MASK, COM, { RS }}, { "mtcrf", X(31,144), XFXFXM_MASK, COM, { FXM, RS } }, { "mtmsr", X(31,146), XRARB_MASK, COM, { RS } }, { "stdx", X(31,149), X_MASK, PPC64, { RS, RA0, RB } }, { "stwcx.", XRC(31,150,1), X_MASK, PPC, { RS, RA0, RB } }, { "stwx", X(31,151), X_MASK, PPCCOM, { RS, RA0, RB } }, { "stx", X(31,151), X_MASK, PWRCOM, { RS, RA, RB } }, { "stwcxe.", XRC(31,158,1), X_MASK, BOOKE64, { RS, RA0, RB } }, { "stwxe", X(31,159), X_MASK, BOOKE64, { RS, RA0, RB } }, { "slq", XRC(31,152,0), X_MASK, M601, { RA, RS, RB } }, { "slq.", XRC(31,152,1), X_MASK, M601, { RA, RS, RB } }, { "sle", XRC(31,153,0), X_MASK, M601, { RA, RS, RB } }, { "sle.", XRC(31,153,1), X_MASK, M601, { RA, RS, RB } }, { "prtyw", X(31,154), XRB_MASK, POWER6, { RA, RS } }, { "wrteei", X(31,163), XE_MASK, PPC403 | BOOKE, { E } }, { "dcbtls", X(31,166), X_MASK, PPCCHLK, { CT, RA, RB }}, { "dcbtlse", X(31,174), X_MASK, PPCCHLK64, { CT, RA, RB }}, { "mtmsrd", X(31,178), XRLARB_MASK, PPC64, { RS, MTMSRD_L } }, { "stdux", X(31,181), X_MASK, PPC64, { RS, RAS, RB } }, { "stwux", X(31,183), X_MASK, PPCCOM, { RS, RAS, RB } }, { "stux", X(31,183), X_MASK, PWRCOM, { RS, RA0, RB } }, { "sliq", XRC(31,184,0), X_MASK, M601, { RA, RS, SH } }, { "sliq.", XRC(31,184,1), X_MASK, M601, { RA, RS, SH } }, { "prtyd", X(31,186), XRB_MASK, POWER6, { RA, RS } }, { "stwuxe", X(31,191), X_MASK, BOOKE64, { RS, RAS, RB } }, { "subfze", XO(31,200,0,0), XORB_MASK, PPCCOM, { RT, RA } }, { "sfze", XO(31,200,0,0), XORB_MASK, PWRCOM, { RT, RA } }, { "subfze.", XO(31,200,0,1), XORB_MASK, PPCCOM, { RT, RA } }, { "sfze.", XO(31,200,0,1), XORB_MASK, PWRCOM, { RT, RA } }, { "subfzeo", XO(31,200,1,0), XORB_MASK, PPCCOM, { RT, RA } }, { "sfzeo", XO(31,200,1,0), XORB_MASK, PWRCOM, { RT, RA } }, { "subfzeo.",XO(31,200,1,1), XORB_MASK, PPCCOM, { RT, RA } }, { "sfzeo.", XO(31,200,1,1), XORB_MASK, PWRCOM, { RT, RA } }, { "addze", XO(31,202,0,0), XORB_MASK, PPCCOM, { RT, RA } }, { "aze", XO(31,202,0,0), XORB_MASK, PWRCOM, { RT, RA } }, { "addze.", XO(31,202,0,1), XORB_MASK, PPCCOM, { RT, RA } }, { "aze.", XO(31,202,0,1), XORB_MASK, PWRCOM, { RT, RA } }, { "addzeo", XO(31,202,1,0), XORB_MASK, PPCCOM, { RT, RA } }, { "azeo", XO(31,202,1,0), XORB_MASK, PWRCOM, { RT, RA } }, { "addzeo.", XO(31,202,1,1), XORB_MASK, PPCCOM, { RT, RA } }, { "azeo.", XO(31,202,1,1), XORB_MASK, PWRCOM, { RT, RA } }, { "mtsr", X(31,210), XRB_MASK|(1<<20), COM32, { SR, RS } }, { "stdcx.", XRC(31,214,1), X_MASK, PPC64, { RS, RA0, RB } }, { "stbx", X(31,215), X_MASK, COM, { RS, RA0, RB } }, { "sllq", XRC(31,216,0), X_MASK, M601, { RA, RS, RB } }, { "sllq.", XRC(31,216,1), X_MASK, M601, { RA, RS, RB } }, { "sleq", XRC(31,217,0), X_MASK, M601, { RA, RS, RB } }, { "sleq.", XRC(31,217,1), X_MASK, M601, { RA, RS, RB } }, { "stbxe", X(31,223), X_MASK, BOOKE64, { RS, RA0, RB } }, { "icblc", X(31,230), X_MASK, PPCCHLK, { CT, RA, RB }}, { "subfme", XO(31,232,0,0), XORB_MASK, PPCCOM, { RT, RA } }, { "sfme", XO(31,232,0,0), XORB_MASK, PWRCOM, { RT, RA } }, { "subfme.", XO(31,232,0,1), XORB_MASK, PPCCOM, { RT, RA } }, { "sfme.", XO(31,232,0,1), XORB_MASK, PWRCOM, { RT, RA } }, { "subfmeo", XO(31,232,1,0), XORB_MASK, PPCCOM, { RT, RA } }, { "sfmeo", XO(31,232,1,0), XORB_MASK, PWRCOM, { RT, RA } }, { "subfmeo.",XO(31,232,1,1), XORB_MASK, PPCCOM, { RT, RA } }, { "sfmeo.", XO(31,232,1,1), XORB_MASK, PWRCOM, { RT, RA } }, { "mulld", XO(31,233,0,0), XO_MASK, PPC64, { RT, RA, RB } }, { "mulld.", XO(31,233,0,1), XO_MASK, PPC64, { RT, RA, RB } }, { "mulldo", XO(31,233,1,0), XO_MASK, PPC64, { RT, RA, RB } }, { "mulldo.", XO(31,233,1,1), XO_MASK, PPC64, { RT, RA, RB } }, { "addme", XO(31,234,0,0), XORB_MASK, PPCCOM, { RT, RA } }, { "ame", XO(31,234,0,0), XORB_MASK, PWRCOM, { RT, RA } }, { "addme.", XO(31,234,0,1), XORB_MASK, PPCCOM, { RT, RA } }, { "ame.", XO(31,234,0,1), XORB_MASK, PWRCOM, { RT, RA } }, { "addmeo", XO(31,234,1,0), XORB_MASK, PPCCOM, { RT, RA } }, { "ameo", XO(31,234,1,0), XORB_MASK, PWRCOM, { RT, RA } }, { "addmeo.", XO(31,234,1,1), XORB_MASK, PPCCOM, { RT, RA } }, { "ameo.", XO(31,234,1,1), XORB_MASK, PWRCOM, { RT, RA } }, { "mullw", XO(31,235,0,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "muls", XO(31,235,0,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "mullw.", XO(31,235,0,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "muls.", XO(31,235,0,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "mullwo", XO(31,235,1,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "mulso", XO(31,235,1,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "mullwo.", XO(31,235,1,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "mulso.", XO(31,235,1,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "icblce", X(31,238), X_MASK, PPCCHLK64, { CT, RA, RB }}, { "mtsrin", X(31,242), XRA_MASK, PPC32, { RS, RB } }, { "mtsri", X(31,242), XRA_MASK, POWER32, { RS, RB } }, { "dcbtst", X(31,246), X_MASK, PPC, { CT, RA, RB } }, { "stbux", X(31,247), X_MASK, COM, { RS, RAS, RB } }, { "slliq", XRC(31,248,0), X_MASK, M601, { RA, RS, SH } }, { "slliq.", XRC(31,248,1), X_MASK, M601, { RA, RS, SH } }, { "dcbtste", X(31,253), X_MASK, BOOKE64, { CT, RA, RB } }, { "stbuxe", X(31,255), X_MASK, BOOKE64, { RS, RAS, RB } }, { "mfdcrx", X(31,259), X_MASK, BOOKE, { RS, RA } }, { "doz", XO(31,264,0,0), XO_MASK, M601, { RT, RA, RB } }, { "doz.", XO(31,264,0,1), XO_MASK, M601, { RT, RA, RB } }, { "dozo", XO(31,264,1,0), XO_MASK, M601, { RT, RA, RB } }, { "dozo.", XO(31,264,1,1), XO_MASK, M601, { RT, RA, RB } }, { "add", XO(31,266,0,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "cax", XO(31,266,0,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "add.", XO(31,266,0,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "cax.", XO(31,266,0,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "addo", XO(31,266,1,0), XO_MASK, PPCCOM, { RT, RA, RB } }, { "caxo", XO(31,266,1,0), XO_MASK, PWRCOM, { RT, RA, RB } }, { "addo.", XO(31,266,1,1), XO_MASK, PPCCOM, { RT, RA, RB } }, { "caxo.", XO(31,266,1,1), XO_MASK, PWRCOM, { RT, RA, RB } }, { "tlbiel", X(31,274), XRTLRA_MASK, POWER4, { RB, L } }, { "mfapidi", X(31,275), X_MASK, BOOKE, { RT, RA } }, { "lscbx", XRC(31,277,0), X_MASK, M601, { RT, RA, RB } }, { "lscbx.", XRC(31,277,1), X_MASK, M601, { RT, RA, RB } }, { "dcbt", X(31,278), X_MASK, PPC, { CT, RA, RB } }, { "lhzx", X(31,279), X_MASK, COM, { RT, RA0, RB } }, { "eqv", XRC(31,284,0), X_MASK, COM, { RA, RS, RB } }, { "eqv.", XRC(31,284,1), X_MASK, COM, { RA, RS, RB } }, { "dcbte", X(31,286), X_MASK, BOOKE64, { CT, RA, RB } }, { "lhzxe", X(31,287), X_MASK, BOOKE64, { RT, RA0, RB } }, { "tlbie", X(31,306), XRTLRA_MASK, PPC, { RB, L } }, { "tlbi", X(31,306), XRT_MASK, POWER, { RA0, RB } }, { "eciwx", X(31,310), X_MASK, PPC, { RT, RA, RB } }, { "lhzux", X(31,311), X_MASK, COM, { RT, RAL, RB } }, { "xor", XRC(31,316,0), X_MASK, COM, { RA, RS, RB } }, { "xor.", XRC(31,316,1), X_MASK, COM, { RA, RS, RB } }, { "lhzuxe", X(31,319), X_MASK, BOOKE64, { RT, RAL, RB } }, { "mfexisr", XSPR(31,323,64), XSPR_MASK, PPC403, { RT } }, { "mfexier", XSPR(31,323,66), XSPR_MASK, PPC403, { RT } }, { "mfbr0", XSPR(31,323,128), XSPR_MASK, PPC403, { RT } }, { "mfbr1", XSPR(31,323,129), XSPR_MASK, PPC403, { RT } }, { "mfbr2", XSPR(31,323,130), XSPR_MASK, PPC403, { RT } }, { "mfbr3", XSPR(31,323,131), XSPR_MASK, PPC403, { RT } }, { "mfbr4", XSPR(31,323,132), XSPR_MASK, PPC403, { RT } }, { "mfbr5", XSPR(31,323,133), XSPR_MASK, PPC403, { RT } }, { "mfbr6", XSPR(31,323,134), XSPR_MASK, PPC403, { RT } }, { "mfbr7", XSPR(31,323,135), XSPR_MASK, PPC403, { RT } }, { "mfbear", XSPR(31,323,144), XSPR_MASK, PPC403, { RT } }, { "mfbesr", XSPR(31,323,145), XSPR_MASK, PPC403, { RT } }, { "mfiocr", XSPR(31,323,160), XSPR_MASK, PPC403, { RT } }, { "mfdmacr0", XSPR(31,323,192), XSPR_MASK, PPC403, { RT } }, { "mfdmact0", XSPR(31,323,193), XSPR_MASK, PPC403, { RT } }, { "mfdmada0", XSPR(31,323,194), XSPR_MASK, PPC403, { RT } }, { "mfdmasa0", XSPR(31,323,195), XSPR_MASK, PPC403, { RT } }, { "mfdmacc0", XSPR(31,323,196), XSPR_MASK, PPC403, { RT } }, { "mfdmacr1", XSPR(31,323,200), XSPR_MASK, PPC403, { RT } }, { "mfdmact1", XSPR(31,323,201), XSPR_MASK, PPC403, { RT } }, { "mfdmada1", XSPR(31,323,202), XSPR_MASK, PPC403, { RT } }, { "mfdmasa1", XSPR(31,323,203), XSPR_MASK, PPC403, { RT } }, { "mfdmacc1", XSPR(31,323,204), XSPR_MASK, PPC403, { RT } }, { "mfdmacr2", XSPR(31,323,208), XSPR_MASK, PPC403, { RT } }, { "mfdmact2", XSPR(31,323,209), XSPR_MASK, PPC403, { RT } }, { "mfdmada2", XSPR(31,323,210), XSPR_MASK, PPC403, { RT } }, { "mfdmasa2", XSPR(31,323,211), XSPR_MASK, PPC403, { RT } }, { "mfdmacc2", XSPR(31,323,212), XSPR_MASK, PPC403, { RT } }, { "mfdmacr3", XSPR(31,323,216), XSPR_MASK, PPC403, { RT } }, { "mfdmact3", XSPR(31,323,217), XSPR_MASK, PPC403, { RT } }, { "mfdmada3", XSPR(31,323,218), XSPR_MASK, PPC403, { RT } }, { "mfdmasa3", XSPR(31,323,219), XSPR_MASK, PPC403, { RT } }, { "mfdmacc3", XSPR(31,323,220), XSPR_MASK, PPC403, { RT } }, { "mfdmasr", XSPR(31,323,224), XSPR_MASK, PPC403, { RT } }, { "mfdcr", X(31,323), X_MASK, PPC403 | BOOKE, { RT, SPR } }, { "div", XO(31,331,0,0), XO_MASK, M601, { RT, RA, RB } }, { "div.", XO(31,331,0,1), XO_MASK, M601, { RT, RA, RB } }, { "divo", XO(31,331,1,0), XO_MASK, M601, { RT, RA, RB } }, { "divo.", XO(31,331,1,1), XO_MASK, M601, { RT, RA, RB } }, { "mfpmr", X(31,334), X_MASK, PPCPMR, { RT, PMR }}, { "mfmq", XSPR(31,339,0), XSPR_MASK, M601, { RT } }, { "mfxer", XSPR(31,339,1), XSPR_MASK, COM, { RT } }, { "mfrtcu", XSPR(31,339,4), XSPR_MASK, COM, { RT } }, { "mfrtcl", XSPR(31,339,5), XSPR_MASK, COM, { RT } }, { "mfdec", XSPR(31,339,6), XSPR_MASK, MFDEC1, { RT } }, { "mfdec", XSPR(31,339,22), XSPR_MASK, MFDEC2, { RT } }, { "mflr", XSPR(31,339,8), XSPR_MASK, COM, { RT } }, { "mfctr", XSPR(31,339,9), XSPR_MASK, COM, { RT } }, { "mftid", XSPR(31,339,17), XSPR_MASK, POWER, { RT } }, { "mfdsisr", XSPR(31,339,18), XSPR_MASK, COM, { RT } }, { "mfdar", XSPR(31,339,19), XSPR_MASK, COM, { RT } }, { "mfsdr0", XSPR(31,339,24), XSPR_MASK, POWER, { RT } }, { "mfsdr1", XSPR(31,339,25), XSPR_MASK, COM, { RT } }, { "mfsrr0", XSPR(31,339,26), XSPR_MASK, COM, { RT } }, { "mfsrr1", XSPR(31,339,27), XSPR_MASK, COM, { RT } }, { "mfcfar", XSPR(31,339,28), XSPR_MASK, POWER6, { RT } }, { "mfpid", XSPR(31,339,48), XSPR_MASK, BOOKE, { RT } }, { "mfpid", XSPR(31,339,945), XSPR_MASK, PPC403, { RT } }, { "mfcsrr0", XSPR(31,339,58), XSPR_MASK, BOOKE, { RT } }, { "mfcsrr1", XSPR(31,339,59), XSPR_MASK, BOOKE, { RT } }, { "mfdear", XSPR(31,339,61), XSPR_MASK, BOOKE, { RT } }, { "mfdear", XSPR(31,339,981), XSPR_MASK, PPC403, { RT } }, { "mfesr", XSPR(31,339,62), XSPR_MASK, BOOKE, { RT } }, { "mfesr", XSPR(31,339,980), XSPR_MASK, PPC403, { RT } }, { "mfivpr", XSPR(31,339,63), XSPR_MASK, BOOKE, { RT } }, { "mfcmpa", XSPR(31,339,144), XSPR_MASK, PPC860, { RT } }, { "mfcmpb", XSPR(31,339,145), XSPR_MASK, PPC860, { RT } }, { "mfcmpc", XSPR(31,339,146), XSPR_MASK, PPC860, { RT } }, { "mfcmpd", XSPR(31,339,147), XSPR_MASK, PPC860, { RT } }, { "mficr", XSPR(31,339,148), XSPR_MASK, PPC860, { RT } }, { "mfder", XSPR(31,339,149), XSPR_MASK, PPC860, { RT } }, { "mfcounta", XSPR(31,339,150), XSPR_MASK, PPC860, { RT } }, { "mfcountb", XSPR(31,339,151), XSPR_MASK, PPC860, { RT } }, { "mfcmpe", XSPR(31,339,152), XSPR_MASK, PPC860, { RT } }, { "mfcmpf", XSPR(31,339,153), XSPR_MASK, PPC860, { RT } }, { "mfcmpg", XSPR(31,339,154), XSPR_MASK, PPC860, { RT } }, { "mfcmph", XSPR(31,339,155), XSPR_MASK, PPC860, { RT } }, { "mflctrl1", XSPR(31,339,156), XSPR_MASK, PPC860, { RT } }, { "mflctrl2", XSPR(31,339,157), XSPR_MASK, PPC860, { RT } }, { "mfictrl", XSPR(31,339,158), XSPR_MASK, PPC860, { RT } }, { "mfbar", XSPR(31,339,159), XSPR_MASK, PPC860, { RT } }, { "mfvrsave", XSPR(31,339,256), XSPR_MASK, PPCVEC, { RT } }, { "mfusprg0", XSPR(31,339,256), XSPR_MASK, BOOKE, { RT } }, { "mftb", X(31,371), X_MASK, CLASSIC, { RT, TBR } }, { "mftb", XSPR(31,339,268), XSPR_MASK, BOOKE, { RT } }, { "mftbl", XSPR(31,371,268), XSPR_MASK, CLASSIC, { RT } }, { "mftbl", XSPR(31,339,268), XSPR_MASK, BOOKE, { RT } }, { "mftbu", XSPR(31,371,269), XSPR_MASK, CLASSIC, { RT } }, { "mftbu", XSPR(31,339,269), XSPR_MASK, BOOKE, { RT } }, { "mfsprg", XSPR(31,339,256), XSPRG_MASK, PPC, { RT, SPRG } }, { "mfsprg0", XSPR(31,339,272), XSPR_MASK, PPC, { RT } }, { "mfsprg1", XSPR(31,339,273), XSPR_MASK, PPC, { RT } }, { "mfsprg2", XSPR(31,339,274), XSPR_MASK, PPC, { RT } }, { "mfsprg3", XSPR(31,339,275), XSPR_MASK, PPC, { RT } }, { "mfsprg4", XSPR(31,339,260), XSPR_MASK, PPC405 | BOOKE, { RT } }, { "mfsprg5", XSPR(31,339,261), XSPR_MASK, PPC405 | BOOKE, { RT } }, { "mfsprg6", XSPR(31,339,262), XSPR_MASK, PPC405 | BOOKE, { RT } }, { "mfsprg7", XSPR(31,339,263), XSPR_MASK, PPC405 | BOOKE, { RT } }, { "mfasr", XSPR(31,339,280), XSPR_MASK, PPC64, { RT } }, { "mfear", XSPR(31,339,282), XSPR_MASK, PPC, { RT } }, { "mfpir", XSPR(31,339,286), XSPR_MASK, BOOKE, { RT } }, { "mfpvr", XSPR(31,339,287), XSPR_MASK, PPC, { RT } }, { "mfdbsr", XSPR(31,339,304), XSPR_MASK, BOOKE, { RT } }, { "mfdbsr", XSPR(31,339,1008), XSPR_MASK, PPC403, { RT } }, { "mfdbcr0", XSPR(31,339,308), XSPR_MASK, BOOKE, { RT } }, { "mfdbcr0", XSPR(31,339,1010), XSPR_MASK, PPC405, { RT } }, { "mfdbcr1", XSPR(31,339,309), XSPR_MASK, BOOKE, { RT } }, { "mfdbcr1", XSPR(31,339,957), XSPR_MASK, PPC405, { RT } }, { "mfdbcr2", XSPR(31,339,310), XSPR_MASK, BOOKE, { RT } }, { "mfiac1", XSPR(31,339,312), XSPR_MASK, BOOKE, { RT } }, { "mfiac1", XSPR(31,339,1012), XSPR_MASK, PPC403, { RT } }, { "mfiac2", XSPR(31,339,313), XSPR_MASK, BOOKE, { RT } }, { "mfiac2", XSPR(31,339,1013), XSPR_MASK, PPC403, { RT } }, { "mfiac3", XSPR(31,339,314), XSPR_MASK, BOOKE, { RT } }, { "mfiac3", XSPR(31,339,948), XSPR_MASK, PPC405, { RT } }, { "mfiac4", XSPR(31,339,315), XSPR_MASK, BOOKE, { RT } }, { "mfiac4", XSPR(31,339,949), XSPR_MASK, PPC405, { RT } }, { "mfdac1", XSPR(31,339,316), XSPR_MASK, BOOKE, { RT } }, { "mfdac1", XSPR(31,339,1014), XSPR_MASK, PPC403, { RT } }, { "mfdac2", XSPR(31,339,317), XSPR_MASK, BOOKE, { RT } }, { "mfdac2", XSPR(31,339,1015), XSPR_MASK, PPC403, { RT } }, { "mfdvc1", XSPR(31,339,318), XSPR_MASK, BOOKE, { RT } }, { "mfdvc1", XSPR(31,339,950), XSPR_MASK, PPC405, { RT } }, { "mfdvc2", XSPR(31,339,319), XSPR_MASK, BOOKE, { RT } }, { "mfdvc2", XSPR(31,339,951), XSPR_MASK, PPC405, { RT } }, { "mftsr", XSPR(31,339,336), XSPR_MASK, BOOKE, { RT } }, { "mftsr", XSPR(31,339,984), XSPR_MASK, PPC403, { RT } }, { "mftcr", XSPR(31,339,340), XSPR_MASK, BOOKE, { RT } }, { "mftcr", XSPR(31,339,986), XSPR_MASK, PPC403, { RT } }, { "mfivor0", XSPR(31,339,400), XSPR_MASK, BOOKE, { RT } }, { "mfivor1", XSPR(31,339,401), XSPR_MASK, BOOKE, { RT } }, { "mfivor2", XSPR(31,339,402), XSPR_MASK, BOOKE, { RT } }, { "mfivor3", XSPR(31,339,403), XSPR_MASK, BOOKE, { RT } }, { "mfivor4", XSPR(31,339,404), XSPR_MASK, BOOKE, { RT } }, { "mfivor5", XSPR(31,339,405), XSPR_MASK, BOOKE, { RT } }, { "mfivor6", XSPR(31,339,406), XSPR_MASK, BOOKE, { RT } }, { "mfivor7", XSPR(31,339,407), XSPR_MASK, BOOKE, { RT } }, { "mfivor8", XSPR(31,339,408), XSPR_MASK, BOOKE, { RT } }, { "mfivor9", XSPR(31,339,409), XSPR_MASK, BOOKE, { RT } }, { "mfivor10", XSPR(31,339,410), XSPR_MASK, BOOKE, { RT } }, { "mfivor11", XSPR(31,339,411), XSPR_MASK, BOOKE, { RT } }, { "mfivor12", XSPR(31,339,412), XSPR_MASK, BOOKE, { RT } }, { "mfivor13", XSPR(31,339,413), XSPR_MASK, BOOKE, { RT } }, { "mfivor14", XSPR(31,339,414), XSPR_MASK, BOOKE, { RT } }, { "mfivor15", XSPR(31,339,415), XSPR_MASK, BOOKE, { RT } }, { "mfspefscr", XSPR(31,339,512), XSPR_MASK, PPCSPE, { RT } }, { "mfbbear", XSPR(31,339,513), XSPR_MASK, PPCBRLK, { RT } }, { "mfbbtar", XSPR(31,339,514), XSPR_MASK, PPCBRLK, { RT } }, { "mfivor32", XSPR(31,339,528), XSPR_MASK, PPCSPE, { RT } }, { "mfivor33", XSPR(31,339,529), XSPR_MASK, PPCSPE, { RT } }, { "mfivor34", XSPR(31,339,530), XSPR_MASK, PPCSPE, { RT } }, { "mfivor35", XSPR(31,339,531), XSPR_MASK, PPCPMR, { RT } }, { "mfibatu", XSPR(31,339,528), XSPRBAT_MASK, PPC, { RT, SPRBAT } }, { "mfibatl", XSPR(31,339,529), XSPRBAT_MASK, PPC, { RT, SPRBAT } }, { "mfdbatu", XSPR(31,339,536), XSPRBAT_MASK, PPC, { RT, SPRBAT } }, { "mfdbatl", XSPR(31,339,537), XSPRBAT_MASK, PPC, { RT, SPRBAT } }, { "mfic_cst", XSPR(31,339,560), XSPR_MASK, PPC860, { RT } }, { "mfic_adr", XSPR(31,339,561), XSPR_MASK, PPC860, { RT } }, { "mfic_dat", XSPR(31,339,562), XSPR_MASK, PPC860, { RT } }, { "mfdc_cst", XSPR(31,339,568), XSPR_MASK, PPC860, { RT } }, { "mfdc_adr", XSPR(31,339,569), XSPR_MASK, PPC860, { RT } }, { "mfmcsrr0", XSPR(31,339,570), XSPR_MASK, PPCRFMCI, { RT } }, { "mfdc_dat", XSPR(31,339,570), XSPR_MASK, PPC860, { RT } }, { "mfmcsrr1", XSPR(31,339,571), XSPR_MASK, PPCRFMCI, { RT } }, { "mfmcsr", XSPR(31,339,572), XSPR_MASK, PPCRFMCI, { RT } }, { "mfmcar", XSPR(31,339,573), XSPR_MASK, PPCRFMCI, { RT } }, { "mfdpdr", XSPR(31,339,630), XSPR_MASK, PPC860, { RT } }, { "mfdpir", XSPR(31,339,631), XSPR_MASK, PPC860, { RT } }, { "mfimmr", XSPR(31,339,638), XSPR_MASK, PPC860, { RT } }, { "mfmi_ctr", XSPR(31,339,784), XSPR_MASK, PPC860, { RT } }, { "mfmi_ap", XSPR(31,339,786), XSPR_MASK, PPC860, { RT } }, { "mfmi_epn", XSPR(31,339,787), XSPR_MASK, PPC860, { RT } }, { "mfmi_twc", XSPR(31,339,789), XSPR_MASK, PPC860, { RT } }, { "mfmi_rpn", XSPR(31,339,790), XSPR_MASK, PPC860, { RT } }, { "mfmd_ctr", XSPR(31,339,792), XSPR_MASK, PPC860, { RT } }, { "mfm_casid", XSPR(31,339,793), XSPR_MASK, PPC860, { RT } }, { "mfmd_ap", XSPR(31,339,794), XSPR_MASK, PPC860, { RT } }, { "mfmd_epn", XSPR(31,339,795), XSPR_MASK, PPC860, { RT } }, { "mfmd_twb", XSPR(31,339,796), XSPR_MASK, PPC860, { RT } }, { "mfmd_twc", XSPR(31,339,797), XSPR_MASK, PPC860, { RT } }, { "mfmd_rpn", XSPR(31,339,798), XSPR_MASK, PPC860, { RT } }, { "mfm_tw", XSPR(31,339,799), XSPR_MASK, PPC860, { RT } }, { "mfmi_dbcam", XSPR(31,339,816), XSPR_MASK, PPC860, { RT } }, { "mfmi_dbram0",XSPR(31,339,817), XSPR_MASK, PPC860, { RT } }, { "mfmi_dbram1",XSPR(31,339,818), XSPR_MASK, PPC860, { RT } }, { "mfmd_dbcam", XSPR(31,339,824), XSPR_MASK, PPC860, { RT } }, { "mfmd_dbram0",XSPR(31,339,825), XSPR_MASK, PPC860, { RT } }, { "mfmd_dbram1",XSPR(31,339,826), XSPR_MASK, PPC860, { RT } }, { "mfummcr0", XSPR(31,339,936), XSPR_MASK, PPC750, { RT } }, { "mfupmc1", XSPR(31,339,937), XSPR_MASK, PPC750, { RT } }, { "mfupmc2", XSPR(31,339,938), XSPR_MASK, PPC750, { RT } }, { "mfusia", XSPR(31,339,939), XSPR_MASK, PPC750, { RT } }, { "mfummcr1", XSPR(31,339,940), XSPR_MASK, PPC750, { RT } }, { "mfupmc3", XSPR(31,339,941), XSPR_MASK, PPC750, { RT } }, { "mfupmc4", XSPR(31,339,942), XSPR_MASK, PPC750, { RT } }, { "mfzpr", XSPR(31,339,944), XSPR_MASK, PPC403, { RT } }, { "mfccr0", XSPR(31,339,947), XSPR_MASK, PPC405, { RT } }, { "mfmmcr0", XSPR(31,339,952), XSPR_MASK, PPC750, { RT } }, { "mfpmc1", XSPR(31,339,953), XSPR_MASK, PPC750, { RT } }, { "mfsgr", XSPR(31,339,953), XSPR_MASK, PPC403, { RT } }, { "mfpmc2", XSPR(31,339,954), XSPR_MASK, PPC750, { RT } }, { "mfdcwr", XSPR(31,339,954), XSPR_MASK, PPC403, { RT } }, { "mfsia", XSPR(31,339,955), XSPR_MASK, PPC750, { RT } }, { "mfsler", XSPR(31,339,955), XSPR_MASK, PPC405, { RT } }, { "mfmmcr1", XSPR(31,339,956), XSPR_MASK, PPC750, { RT } }, { "mfsu0r", XSPR(31,339,956), XSPR_MASK, PPC405, { RT } }, { "mfpmc3", XSPR(31,339,957), XSPR_MASK, PPC750, { RT } }, { "mfpmc4", XSPR(31,339,958), XSPR_MASK, PPC750, { RT } }, { "mficdbdr", XSPR(31,339,979), XSPR_MASK, PPC403, { RT } }, { "mfevpr", XSPR(31,339,982), XSPR_MASK, PPC403, { RT } }, { "mfcdbcr", XSPR(31,339,983), XSPR_MASK, PPC403, { RT } }, { "mfpit", XSPR(31,339,987), XSPR_MASK, PPC403, { RT } }, { "mftbhi", XSPR(31,339,988), XSPR_MASK, PPC403, { RT } }, { "mftblo", XSPR(31,339,989), XSPR_MASK, PPC403, { RT } }, { "mfsrr2", XSPR(31,339,990), XSPR_MASK, PPC403, { RT } }, { "mfsrr3", XSPR(31,339,991), XSPR_MASK, PPC403, { RT } }, { "mfl2cr", XSPR(31,339,1017), XSPR_MASK, PPC750, { RT } }, { "mfdccr", XSPR(31,339,1018), XSPR_MASK, PPC403, { RT } }, { "mficcr", XSPR(31,339,1019), XSPR_MASK, PPC403, { RT } }, { "mfictc", XSPR(31,339,1019), XSPR_MASK, PPC750, { RT } }, { "mfpbl1", XSPR(31,339,1020), XSPR_MASK, PPC403, { RT } }, { "mfthrm1", XSPR(31,339,1020), XSPR_MASK, PPC750, { RT } }, { "mfpbu1", XSPR(31,339,1021), XSPR_MASK, PPC403, { RT } }, { "mfthrm2", XSPR(31,339,1021), XSPR_MASK, PPC750, { RT } }, { "mfpbl2", XSPR(31,339,1022), XSPR_MASK, PPC403, { RT } }, { "mfthrm3", XSPR(31,339,1022), XSPR_MASK, PPC750, { RT } }, { "mfpbu2", XSPR(31,339,1023), XSPR_MASK, PPC403, { RT } }, { "mfspr", X(31,339), X_MASK, COM, { RT, SPR } }, { "lwax", X(31,341), X_MASK, PPC64, { RT, RA0, RB } }, { "dst", XDSS(31,342,0), XDSS_MASK, PPCVEC, { RA, RB, STRM } }, { "dstt", XDSS(31,342,1), XDSS_MASK, PPCVEC, { RA, RB, STRM } }, { "lhax", X(31,343), X_MASK, COM, { RT, RA0, RB } }, { "lhaxe", X(31,351), X_MASK, BOOKE64, { RT, RA0, RB } }, { "dstst", XDSS(31,374,0), XDSS_MASK, PPCVEC, { RA, RB, STRM } }, { "dststt", XDSS(31,374,1), XDSS_MASK, PPCVEC, { RA, RB, STRM } }, { "dccci", X(31,454), XRT_MASK, PPC403|PPC440, { RA, RB } }, { "abs", XO(31,360,0,0), XORB_MASK, M601, { RT, RA } }, { "abs.", XO(31,360,0,1), XORB_MASK, M601, { RT, RA } }, { "abso", XO(31,360,1,0), XORB_MASK, M601, { RT, RA } }, { "abso.", XO(31,360,1,1), XORB_MASK, M601, { RT, RA } }, { "divs", XO(31,363,0,0), XO_MASK, M601, { RT, RA, RB } }, { "divs.", XO(31,363,0,1), XO_MASK, M601, { RT, RA, RB } }, { "divso", XO(31,363,1,0), XO_MASK, M601, { RT, RA, RB } }, { "divso.", XO(31,363,1,1), XO_MASK, M601, { RT, RA, RB } }, { "tlbia", X(31,370), 0xffffffff, PPC, { 0 } }, { "lwaux", X(31,373), X_MASK, PPC64, { RT, RAL, RB } }, { "lhaux", X(31,375), X_MASK, COM, { RT, RAL, RB } }, { "lhauxe", X(31,383), X_MASK, BOOKE64, { RT, RAL, RB } }, { "mtdcrx", X(31,387), X_MASK, BOOKE, { RA, RS } }, { "dcblc", X(31,390), X_MASK, PPCCHLK, { CT, RA, RB }}, { "subfe64", XO(31,392,0,0), XO_MASK, BOOKE64, { RT, RA, RB } }, { "subfe64o",XO(31,392,1,0), XO_MASK, BOOKE64, { RT, RA, RB } }, { "adde64", XO(31,394,0,0), XO_MASK, BOOKE64, { RT, RA, RB } }, { "adde64o", XO(31,394,1,0), XO_MASK, BOOKE64, { RT, RA, RB } }, { "dcblce", X(31,398), X_MASK, PPCCHLK64, { CT, RA, RB }}, { "slbmte", X(31,402), XRA_MASK, PPC64, { RS, RB } }, { "sthx", X(31,407), X_MASK, COM, { RS, RA0, RB } }, { "cmpb", X(31,508), X_MASK, POWER6, { RA, RS, RB } }, { "lfqx", X(31,791), X_MASK, POWER2, { FRT, RA, RB } }, { "lfdpx", X(31,791), X_MASK, POWER6, { FRT, RA, RB } }, { "lfqux", X(31,823), X_MASK, POWER2, { FRT, RA, RB } }, { "stfqx", X(31,919), X_MASK, POWER2, { FRS, RA, RB } }, { "stfdpx", X(31,919), X_MASK, POWER6, { FRS, RA, RB } }, { "stfqux", X(31,951), X_MASK, POWER2, { FRS, RA, RB } }, { "orc", XRC(31,412,0), X_MASK, COM, { RA, RS, RB } }, { "orc.", XRC(31,412,1), X_MASK, COM, { RA, RS, RB } }, { "sradi", XS(31,413,0), XS_MASK, PPC64, { RA, RS, SH6 } }, { "sradi.", XS(31,413,1), XS_MASK, PPC64, { RA, RS, SH6 } }, { "sthxe", X(31,415), X_MASK, BOOKE64, { RS, RA0, RB } }, { "slbie", X(31,434), XRTRA_MASK, PPC64, { RB } }, { "ecowx", X(31,438), X_MASK, PPC, { RT, RA, RB } }, { "sthux", X(31,439), X_MASK, COM, { RS, RAS, RB } }, { "sthuxe", X(31,447), X_MASK, BOOKE64, { RS, RAS, RB } }, { "mr", XRC(31,444,0), X_MASK, COM, { RA, RS, RBS } }, { "or", XRC(31,444,0), X_MASK, COM, { RA, RS, RB } }, { "mr.", XRC(31,444,1), X_MASK, COM, { RA, RS, RBS } }, { "or.", XRC(31,444,1), X_MASK, COM, { RA, RS, RB } }, { "mtexisr", XSPR(31,451,64), XSPR_MASK, PPC403, { RS } }, { "mtexier", XSPR(31,451,66), XSPR_MASK, PPC403, { RS } }, { "mtbr0", XSPR(31,451,128), XSPR_MASK, PPC403, { RS } }, { "mtbr1", XSPR(31,451,129), XSPR_MASK, PPC403, { RS } }, { "mtbr2", XSPR(31,451,130), XSPR_MASK, PPC403, { RS } }, { "mtbr3", XSPR(31,451,131), XSPR_MASK, PPC403, { RS } }, { "mtbr4", XSPR(31,451,132), XSPR_MASK, PPC403, { RS } }, { "mtbr5", XSPR(31,451,133), XSPR_MASK, PPC403, { RS } }, { "mtbr6", XSPR(31,451,134), XSPR_MASK, PPC403, { RS } }, { "mtbr7", XSPR(31,451,135), XSPR_MASK, PPC403, { RS } }, { "mtbear", XSPR(31,451,144), XSPR_MASK, PPC403, { RS } }, { "mtbesr", XSPR(31,451,145), XSPR_MASK, PPC403, { RS } }, { "mtiocr", XSPR(31,451,160), XSPR_MASK, PPC403, { RS } }, { "mtdmacr0", XSPR(31,451,192), XSPR_MASK, PPC403, { RS } }, { "mtdmact0", XSPR(31,451,193), XSPR_MASK, PPC403, { RS } }, { "mtdmada0", XSPR(31,451,194), XSPR_MASK, PPC403, { RS } }, { "mtdmasa0", XSPR(31,451,195), XSPR_MASK, PPC403, { RS } }, { "mtdmacc0", XSPR(31,451,196), XSPR_MASK, PPC403, { RS } }, { "mtdmacr1", XSPR(31,451,200), XSPR_MASK, PPC403, { RS } }, { "mtdmact1", XSPR(31,451,201), XSPR_MASK, PPC403, { RS } }, { "mtdmada1", XSPR(31,451,202), XSPR_MASK, PPC403, { RS } }, { "mtdmasa1", XSPR(31,451,203), XSPR_MASK, PPC403, { RS } }, { "mtdmacc1", XSPR(31,451,204), XSPR_MASK, PPC403, { RS } }, { "mtdmacr2", XSPR(31,451,208), XSPR_MASK, PPC403, { RS } }, { "mtdmact2", XSPR(31,451,209), XSPR_MASK, PPC403, { RS } }, { "mtdmada2", XSPR(31,451,210), XSPR_MASK, PPC403, { RS } }, { "mtdmasa2", XSPR(31,451,211), XSPR_MASK, PPC403, { RS } }, { "mtdmacc2", XSPR(31,451,212), XSPR_MASK, PPC403, { RS } }, { "mtdmacr3", XSPR(31,451,216), XSPR_MASK, PPC403, { RS } }, { "mtdmact3", XSPR(31,451,217), XSPR_MASK, PPC403, { RS } }, { "mtdmada3", XSPR(31,451,218), XSPR_MASK, PPC403, { RS } }, { "mtdmasa3", XSPR(31,451,219), XSPR_MASK, PPC403, { RS } }, { "mtdmacc3", XSPR(31,451,220), XSPR_MASK, PPC403, { RS } }, { "mtdmasr", XSPR(31,451,224), XSPR_MASK, PPC403, { RS } }, { "mtdcr", X(31,451), X_MASK, PPC403 | BOOKE, { SPR, RS } }, { "subfze64",XO(31,456,0,0), XORB_MASK, BOOKE64, { RT, RA } }, { "subfze64o",XO(31,456,1,0), XORB_MASK, BOOKE64, { RT, RA } }, { "divdu", XO(31,457,0,0), XO_MASK, PPC64, { RT, RA, RB } }, { "divdu.", XO(31,457,0,1), XO_MASK, PPC64, { RT, RA, RB } }, { "divduo", XO(31,457,1,0), XO_MASK, PPC64, { RT, RA, RB } }, { "divduo.", XO(31,457,1,1), XO_MASK, PPC64, { RT, RA, RB } }, { "addze64", XO(31,458,0,0), XORB_MASK, BOOKE64, { RT, RA } }, { "addze64o",XO(31,458,1,0), XORB_MASK, BOOKE64, { RT, RA } }, { "divwu", XO(31,459,0,0), XO_MASK, PPC, { RT, RA, RB } }, { "divwu.", XO(31,459,0,1), XO_MASK, PPC, { RT, RA, RB } }, { "divwuo", XO(31,459,1,0), XO_MASK, PPC, { RT, RA, RB } }, { "divwuo.", XO(31,459,1,1), XO_MASK, PPC, { RT, RA, RB } }, { "mtmq", XSPR(31,467,0), XSPR_MASK, M601, { RS } }, { "mtxer", XSPR(31,467,1), XSPR_MASK, COM, { RS } }, { "mtlr", XSPR(31,467,8), XSPR_MASK, COM, { RS } }, { "mtctr", XSPR(31,467,9), XSPR_MASK, COM, { RS } }, { "mttid", XSPR(31,467,17), XSPR_MASK, POWER, { RS } }, { "mtdsisr", XSPR(31,467,18), XSPR_MASK, COM, { RS } }, { "mtdar", XSPR(31,467,19), XSPR_MASK, COM, { RS } }, { "mtrtcu", XSPR(31,467,20), XSPR_MASK, COM, { RS } }, { "mtrtcl", XSPR(31,467,21), XSPR_MASK, COM, { RS } }, { "mtdec", XSPR(31,467,22), XSPR_MASK, COM, { RS } }, { "mtsdr0", XSPR(31,467,24), XSPR_MASK, POWER, { RS } }, { "mtsdr1", XSPR(31,467,25), XSPR_MASK, COM, { RS } }, { "mtsrr0", XSPR(31,467,26), XSPR_MASK, COM, { RS } }, { "mtsrr1", XSPR(31,467,27), XSPR_MASK, COM, { RS } }, { "mtcfar", XSPR(31,467,28), XSPR_MASK, POWER6, { RS } }, { "mtpid", XSPR(31,467,48), XSPR_MASK, BOOKE, { RS } }, { "mtpid", XSPR(31,467,945), XSPR_MASK, PPC403, { RS } }, { "mtdecar", XSPR(31,467,54), XSPR_MASK, BOOKE, { RS } }, { "mtcsrr0", XSPR(31,467,58), XSPR_MASK, BOOKE, { RS } }, { "mtcsrr1", XSPR(31,467,59), XSPR_MASK, BOOKE, { RS } }, { "mtdear", XSPR(31,467,61), XSPR_MASK, BOOKE, { RS } }, { "mtdear", XSPR(31,467,981), XSPR_MASK, PPC403, { RS } }, { "mtesr", XSPR(31,467,62), XSPR_MASK, BOOKE, { RS } }, { "mtesr", XSPR(31,467,980), XSPR_MASK, PPC403, { RS } }, { "mtivpr", XSPR(31,467,63), XSPR_MASK, BOOKE, { RS } }, { "mtcmpa", XSPR(31,467,144), XSPR_MASK, PPC860, { RS } }, { "mtcmpb", XSPR(31,467,145), XSPR_MASK, PPC860, { RS } }, { "mtcmpc", XSPR(31,467,146), XSPR_MASK, PPC860, { RS } }, { "mtcmpd", XSPR(31,467,147), XSPR_MASK, PPC860, { RS } }, { "mticr", XSPR(31,467,148), XSPR_MASK, PPC860, { RS } }, { "mtder", XSPR(31,467,149), XSPR_MASK, PPC860, { RS } }, { "mtcounta", XSPR(31,467,150), XSPR_MASK, PPC860, { RS } }, { "mtcountb", XSPR(31,467,151), XSPR_MASK, PPC860, { RS } }, { "mtcmpe", XSPR(31,467,152), XSPR_MASK, PPC860, { RS } }, { "mtcmpf", XSPR(31,467,153), XSPR_MASK, PPC860, { RS } }, { "mtcmpg", XSPR(31,467,154), XSPR_MASK, PPC860, { RS } }, { "mtcmph", XSPR(31,467,155), XSPR_MASK, PPC860, { RS } }, { "mtlctrl1", XSPR(31,467,156), XSPR_MASK, PPC860, { RS } }, { "mtlctrl2", XSPR(31,467,157), XSPR_MASK, PPC860, { RS } }, { "mtictrl", XSPR(31,467,158), XSPR_MASK, PPC860, { RS } }, { "mtbar", XSPR(31,467,159), XSPR_MASK, PPC860, { RS } }, { "mtvrsave", XSPR(31,467,256), XSPR_MASK, PPCVEC, { RS } }, { "mtusprg0", XSPR(31,467,256), XSPR_MASK, BOOKE, { RS } }, { "mtsprg", XSPR(31,467,256), XSPRG_MASK,PPC, { SPRG, RS } }, { "mtsprg0", XSPR(31,467,272), XSPR_MASK, PPC, { RS } }, { "mtsprg1", XSPR(31,467,273), XSPR_MASK, PPC, { RS } }, { "mtsprg2", XSPR(31,467,274), XSPR_MASK, PPC, { RS } }, { "mtsprg3", XSPR(31,467,275), XSPR_MASK, PPC, { RS } }, { "mtsprg4", XSPR(31,467,276), XSPR_MASK, PPC405 | BOOKE, { RS } }, { "mtsprg5", XSPR(31,467,277), XSPR_MASK, PPC405 | BOOKE, { RS } }, { "mtsprg6", XSPR(31,467,278), XSPR_MASK, PPC405 | BOOKE, { RS } }, { "mtsprg7", XSPR(31,467,279), XSPR_MASK, PPC405 | BOOKE, { RS } }, { "mtasr", XSPR(31,467,280), XSPR_MASK, PPC64, { RS } }, { "mtear", XSPR(31,467,282), XSPR_MASK, PPC, { RS } }, { "mttbl", XSPR(31,467,284), XSPR_MASK, PPC, { RS } }, { "mttbu", XSPR(31,467,285), XSPR_MASK, PPC, { RS } }, { "mtdbsr", XSPR(31,467,304), XSPR_MASK, BOOKE, { RS } }, { "mtdbsr", XSPR(31,467,1008), XSPR_MASK, PPC403, { RS } }, { "mtdbcr0", XSPR(31,467,308), XSPR_MASK, BOOKE, { RS } }, { "mtdbcr0", XSPR(31,467,1010), XSPR_MASK, PPC405, { RS } }, { "mtdbcr1", XSPR(31,467,309), XSPR_MASK, BOOKE, { RS } }, { "mtdbcr1", XSPR(31,467,957), XSPR_MASK, PPC405, { RS } }, { "mtdbcr2", XSPR(31,467,310), XSPR_MASK, BOOKE, { RS } }, { "mtiac1", XSPR(31,467,312), XSPR_MASK, BOOKE, { RS } }, { "mtiac1", XSPR(31,467,1012), XSPR_MASK, PPC403, { RS } }, { "mtiac2", XSPR(31,467,313), XSPR_MASK, BOOKE, { RS } }, { "mtiac2", XSPR(31,467,1013), XSPR_MASK, PPC403, { RS } }, { "mtiac3", XSPR(31,467,314), XSPR_MASK, BOOKE, { RS } }, { "mtiac3", XSPR(31,467,948), XSPR_MASK, PPC405, { RS } }, { "mtiac4", XSPR(31,467,315), XSPR_MASK, BOOKE, { RS } }, { "mtiac4", XSPR(31,467,949), XSPR_MASK, PPC405, { RS } }, { "mtdac1", XSPR(31,467,316), XSPR_MASK, BOOKE, { RS } }, { "mtdac1", XSPR(31,467,1014), XSPR_MASK, PPC403, { RS } }, { "mtdac2", XSPR(31,467,317), XSPR_MASK, BOOKE, { RS } }, { "mtdac2", XSPR(31,467,1015), XSPR_MASK, PPC403, { RS } }, { "mtdvc1", XSPR(31,467,318), XSPR_MASK, BOOKE, { RS } }, { "mtdvc1", XSPR(31,467,950), XSPR_MASK, PPC405, { RS } }, { "mtdvc2", XSPR(31,467,319), XSPR_MASK, BOOKE, { RS } }, { "mtdvc2", XSPR(31,467,951), XSPR_MASK, PPC405, { RS } }, { "mttsr", XSPR(31,467,336), XSPR_MASK, BOOKE, { RS } }, { "mttsr", XSPR(31,467,984), XSPR_MASK, PPC403, { RS } }, { "mttcr", XSPR(31,467,340), XSPR_MASK, BOOKE, { RS } }, { "mttcr", XSPR(31,467,986), XSPR_MASK, PPC403, { RS } }, { "mtivor0", XSPR(31,467,400), XSPR_MASK, BOOKE, { RS } }, { "mtivor1", XSPR(31,467,401), XSPR_MASK, BOOKE, { RS } }, { "mtivor2", XSPR(31,467,402), XSPR_MASK, BOOKE, { RS } }, { "mtivor3", XSPR(31,467,403), XSPR_MASK, BOOKE, { RS } }, { "mtivor4", XSPR(31,467,404), XSPR_MASK, BOOKE, { RS } }, { "mtivor5", XSPR(31,467,405), XSPR_MASK, BOOKE, { RS } }, { "mtivor6", XSPR(31,467,406), XSPR_MASK, BOOKE, { RS } }, { "mtivor7", XSPR(31,467,407), XSPR_MASK, BOOKE, { RS } }, { "mtivor8", XSPR(31,467,408), XSPR_MASK, BOOKE, { RS } }, { "mtivor9", XSPR(31,467,409), XSPR_MASK, BOOKE, { RS } }, { "mtivor10", XSPR(31,467,410), XSPR_MASK, BOOKE, { RS } }, { "mtivor11", XSPR(31,467,411), XSPR_MASK, BOOKE, { RS } }, { "mtivor12", XSPR(31,467,412), XSPR_MASK, BOOKE, { RS } }, { "mtivor13", XSPR(31,467,413), XSPR_MASK, BOOKE, { RS } }, { "mtivor14", XSPR(31,467,414), XSPR_MASK, BOOKE, { RS } }, { "mtivor15", XSPR(31,467,415), XSPR_MASK, BOOKE, { RS } }, { "mtspefscr", XSPR(31,467,512), XSPR_MASK, PPCSPE, { RS } }, { "mtbbear", XSPR(31,467,513), XSPR_MASK, PPCBRLK, { RS } }, { "mtbbtar", XSPR(31,467,514), XSPR_MASK, PPCBRLK, { RS } }, { "mtivor32", XSPR(31,467,528), XSPR_MASK, PPCSPE, { RS } }, { "mtivor33", XSPR(31,467,529), XSPR_MASK, PPCSPE, { RS } }, { "mtivor34", XSPR(31,467,530), XSPR_MASK, PPCSPE, { RS } }, { "mtivor35", XSPR(31,467,531), XSPR_MASK, PPCPMR, { RS } }, { "mtibatu", XSPR(31,467,528), XSPRBAT_MASK, PPC, { SPRBAT, RS } }, { "mtibatl", XSPR(31,467,529), XSPRBAT_MASK, PPC, { SPRBAT, RS } }, { "mtdbatu", XSPR(31,467,536), XSPRBAT_MASK, PPC, { SPRBAT, RS } }, { "mtdbatl", XSPR(31,467,537), XSPRBAT_MASK, PPC, { SPRBAT, RS } }, { "mtmcsrr0", XSPR(31,467,570), XSPR_MASK, PPCRFMCI, { RS } }, { "mtmcsrr1", XSPR(31,467,571), XSPR_MASK, PPCRFMCI, { RS } }, { "mtmcsr", XSPR(31,467,572), XSPR_MASK, PPCRFMCI, { RS } }, { "mtummcr0", XSPR(31,467,936), XSPR_MASK, PPC750, { RS } }, { "mtupmc1", XSPR(31,467,937), XSPR_MASK, PPC750, { RS } }, { "mtupmc2", XSPR(31,467,938), XSPR_MASK, PPC750, { RS } }, { "mtusia", XSPR(31,467,939), XSPR_MASK, PPC750, { RS } }, { "mtummcr1", XSPR(31,467,940), XSPR_MASK, PPC750, { RS } }, { "mtupmc3", XSPR(31,467,941), XSPR_MASK, PPC750, { RS } }, { "mtupmc4", XSPR(31,467,942), XSPR_MASK, PPC750, { RS } }, { "mtzpr", XSPR(31,467,944), XSPR_MASK, PPC403, { RS } }, { "mtccr0", XSPR(31,467,947), XSPR_MASK, PPC405, { RS } }, { "mtmmcr0", XSPR(31,467,952), XSPR_MASK, PPC750, { RS } }, { "mtsgr", XSPR(31,467,953), XSPR_MASK, PPC403, { RS } }, { "mtpmc1", XSPR(31,467,953), XSPR_MASK, PPC750, { RS } }, { "mtdcwr", XSPR(31,467,954), XSPR_MASK, PPC403, { RS } }, { "mtpmc2", XSPR(31,467,954), XSPR_MASK, PPC750, { RS } }, { "mtsler", XSPR(31,467,955), XSPR_MASK, PPC405, { RS } }, { "mtsia", XSPR(31,467,955), XSPR_MASK, PPC750, { RS } }, { "mtsu0r", XSPR(31,467,956), XSPR_MASK, PPC405, { RS } }, { "mtmmcr1", XSPR(31,467,956), XSPR_MASK, PPC750, { RS } }, { "mtpmc3", XSPR(31,467,957), XSPR_MASK, PPC750, { RS } }, { "mtpmc4", XSPR(31,467,958), XSPR_MASK, PPC750, { RS } }, { "mticdbdr", XSPR(31,467,979), XSPR_MASK, PPC403, { RS } }, { "mtevpr", XSPR(31,467,982), XSPR_MASK, PPC403, { RS } }, { "mtcdbcr", XSPR(31,467,983), XSPR_MASK, PPC403, { RS } }, { "mtpit", XSPR(31,467,987), XSPR_MASK, PPC403, { RS } }, { "mttbhi", XSPR(31,467,988), XSPR_MASK, PPC403, { RS } }, { "mttblo", XSPR(31,467,989), XSPR_MASK, PPC403, { RS } }, { "mtsrr2", XSPR(31,467,990), XSPR_MASK, PPC403, { RS } }, { "mtsrr3", XSPR(31,467,991), XSPR_MASK, PPC403, { RS } }, { "mtl2cr", XSPR(31,467,1017), XSPR_MASK, PPC750, { RS } }, { "mtdccr", XSPR(31,467,1018), XSPR_MASK, PPC403, { RS } }, { "mticcr", XSPR(31,467,1019), XSPR_MASK, PPC403, { RS } }, { "mtictc", XSPR(31,467,1019), XSPR_MASK, PPC750, { RS } }, { "mtpbl1", XSPR(31,467,1020), XSPR_MASK, PPC403, { RS } }, { "mtthrm1", XSPR(31,467,1020), XSPR_MASK, PPC750, { RS } }, { "mtpbu1", XSPR(31,467,1021), XSPR_MASK, PPC403, { RS } }, { "mtthrm2", XSPR(31,467,1021), XSPR_MASK, PPC750, { RS } }, { "mtpbl2", XSPR(31,467,1022), XSPR_MASK, PPC403, { RS } }, { "mtthrm3", XSPR(31,467,1022), XSPR_MASK, PPC750, { RS } }, { "mtpbu2", XSPR(31,467,1023), XSPR_MASK, PPC403, { RS } }, { "mtspr", X(31,467), X_MASK, COM, { SPR, RS } }, { "dcbi", X(31,470), XRT_MASK, PPC, { RA, RB } }, { "nand", XRC(31,476,0), X_MASK, COM, { RA, RS, RB } }, { "nand.", XRC(31,476,1), X_MASK, COM, { RA, RS, RB } }, { "dcbie", X(31,478), XRT_MASK, BOOKE64, { RA, RB } }, { "dcread", X(31,486), X_MASK, PPC403|PPC440, { RT, RA, RB }}, { "mtpmr", X(31,462), X_MASK, PPCPMR, { PMR, RS }}, { "icbtls", X(31,486), X_MASK, PPCCHLK, { CT, RA, RB }}, { "nabs", XO(31,488,0,0), XORB_MASK, M601, { RT, RA } }, { "subfme64",XO(31,488,0,0), XORB_MASK, BOOKE64, { RT, RA } }, { "nabs.", XO(31,488,0,1), XORB_MASK, M601, { RT, RA } }, { "nabso", XO(31,488,1,0), XORB_MASK, M601, { RT, RA } }, { "subfme64o",XO(31,488,1,0), XORB_MASK, BOOKE64, { RT, RA } }, { "nabso.", XO(31,488,1,1), XORB_MASK, M601, { RT, RA } }, { "divd", XO(31,489,0,0), XO_MASK, PPC64, { RT, RA, RB } }, { "divd.", XO(31,489,0,1), XO_MASK, PPC64, { RT, RA, RB } }, { "divdo", XO(31,489,1,0), XO_MASK, PPC64, { RT, RA, RB } }, { "divdo.", XO(31,489,1,1), XO_MASK, PPC64, { RT, RA, RB } }, { "addme64", XO(31,490,0,0), XORB_MASK, BOOKE64, { RT, RA } }, { "addme64o",XO(31,490,1,0), XORB_MASK, BOOKE64, { RT, RA } }, { "divw", XO(31,491,0,0), XO_MASK, PPC, { RT, RA, RB } }, { "divw.", XO(31,491,0,1), XO_MASK, PPC, { RT, RA, RB } }, { "divwo", XO(31,491,1,0), XO_MASK, PPC, { RT, RA, RB } }, { "divwo.", XO(31,491,1,1), XO_MASK, PPC, { RT, RA, RB } }, { "icbtlse", X(31,494), X_MASK, PPCCHLK64, { CT, RA, RB }}, { "slbia", X(31,498), 0xffffffff, PPC64, { 0 } }, { "cli", X(31,502), XRB_MASK, POWER, { RT, RA } }, { "stdcxe.", XRC(31,511,1), X_MASK, BOOKE64, { RS, RA, RB } }, { "mcrxr", X(31,512), XRARB_MASK|(3<<21), COM, { BF } }, { "bblels", X(31,518), X_MASK, PPCBRLK, { 0 }}, { "mcrxr64", X(31,544), XRARB_MASK|(3<<21), BOOKE64, { BF } }, { "clcs", X(31,531), XRB_MASK, M601, { RT, RA } }, { "ldbrx", X(31,532), X_MASK, CELL, { RT, RA0, RB } }, { "lswx", X(31,533), X_MASK, PPCCOM, { RT, RA0, RB } }, { "lsx", X(31,533), X_MASK, PWRCOM, { RT, RA, RB } }, { "lwbrx", X(31,534), X_MASK, PPCCOM, { RT, RA0, RB } }, { "lbrx", X(31,534), X_MASK, PWRCOM, { RT, RA, RB } }, { "lfsx", X(31,535), X_MASK, COM, { FRT, RA0, RB } }, { "srw", XRC(31,536,0), X_MASK, PPCCOM, { RA, RS, RB } }, { "sr", XRC(31,536,0), X_MASK, PWRCOM, { RA, RS, RB } }, { "srw.", XRC(31,536,1), X_MASK, PPCCOM, { RA, RS, RB } }, { "sr.", XRC(31,536,1), X_MASK, PWRCOM, { RA, RS, RB } }, { "rrib", XRC(31,537,0), X_MASK, M601, { RA, RS, RB } }, { "rrib.", XRC(31,537,1), X_MASK, M601, { RA, RS, RB } }, { "srd", XRC(31,539,0), X_MASK, PPC64, { RA, RS, RB } }, { "srd.", XRC(31,539,1), X_MASK, PPC64, { RA, RS, RB } }, { "maskir", XRC(31,541,0), X_MASK, M601, { RA, RS, RB } }, { "maskir.", XRC(31,541,1), X_MASK, M601, { RA, RS, RB } }, { "lwbrxe", X(31,542), X_MASK, BOOKE64, { RT, RA0, RB } }, { "lfsxe", X(31,543), X_MASK, BOOKE64, { FRT, RA0, RB } }, { "bbelr", X(31,550), X_MASK, PPCBRLK, { 0 }}, { "tlbsync", X(31,566), 0xffffffff, PPC, { 0 } }, { "lfsux", X(31,567), X_MASK, COM, { FRT, RAS, RB } }, { "lfsuxe", X(31,575), X_MASK, BOOKE64, { FRT, RAS, RB } }, { "mfsr", X(31,595), XRB_MASK|(1<<20), COM32, { RT, SR } }, { "lswi", X(31,597), X_MASK, PPCCOM, { RT, RA0, NB } }, { "lsi", X(31,597), X_MASK, PWRCOM, { RT, RA0, NB } }, { "lwsync", XSYNC(31,598,1), 0xffffffff, PPC, { 0 } }, { "ptesync", XSYNC(31,598,2), 0xffffffff, PPC64, { 0 } }, { "msync", X(31,598), 0xffffffff, BOOKE, { 0 } }, { "sync", X(31,598), XSYNC_MASK, PPCCOM, { LS } }, { "dcs", X(31,598), 0xffffffff, PWRCOM, { 0 } }, { "lfdx", X(31,599), X_MASK, COM, { FRT, RA0, RB } }, { "lfdxe", X(31,607), X_MASK, BOOKE64, { FRT, RA0, RB } }, { "mffgpr", XRC(31,607,0), XRA_MASK, POWER6, { FRT, RB } }, { "mfsri", X(31,627), X_MASK, PWRCOM, { RT, RA, RB } }, { "dclst", X(31,630), XRB_MASK, PWRCOM, { RS, RA } }, { "lfdux", X(31,631), X_MASK, COM, { FRT, RAS, RB } }, { "lfduxe", X(31,639), X_MASK, BOOKE64, { FRT, RAS, RB } }, { "mfsrin", X(31,659), XRA_MASK, PPC32, { RT, RB } }, { "stdbrx", X(31,660), X_MASK, CELL, { RS, RA0, RB } }, { "stswx", X(31,661), X_MASK, PPCCOM, { RS, RA0, RB } }, { "stsx", X(31,661), X_MASK, PWRCOM, { RS, RA0, RB } }, { "stwbrx", X(31,662), X_MASK, PPCCOM, { RS, RA0, RB } }, { "stbrx", X(31,662), X_MASK, PWRCOM, { RS, RA0, RB } }, { "stfsx", X(31,663), X_MASK, COM, { FRS, RA0, RB } }, { "srq", XRC(31,664,0), X_MASK, M601, { RA, RS, RB } }, { "srq.", XRC(31,664,1), X_MASK, M601, { RA, RS, RB } }, { "sre", XRC(31,665,0), X_MASK, M601, { RA, RS, RB } }, { "sre.", XRC(31,665,1), X_MASK, M601, { RA, RS, RB } }, { "stwbrxe", X(31,670), X_MASK, BOOKE64, { RS, RA0, RB } }, { "stfsxe", X(31,671), X_MASK, BOOKE64, { FRS, RA0, RB } }, { "stfsux", X(31,695), X_MASK, COM, { FRS, RAS, RB } }, { "sriq", XRC(31,696,0), X_MASK, M601, { RA, RS, SH } }, { "sriq.", XRC(31,696,1), X_MASK, M601, { RA, RS, SH } }, { "stfsuxe", X(31,703), X_MASK, BOOKE64, { FRS, RAS, RB } }, { "stswi", X(31,725), X_MASK, PPCCOM, { RS, RA0, NB } }, { "stsi", X(31,725), X_MASK, PWRCOM, { RS, RA0, NB } }, { "stfdx", X(31,727), X_MASK, COM, { FRS, RA0, RB } }, { "srlq", XRC(31,728,0), X_MASK, M601, { RA, RS, RB } }, { "srlq.", XRC(31,728,1), X_MASK, M601, { RA, RS, RB } }, { "sreq", XRC(31,729,0), X_MASK, M601, { RA, RS, RB } }, { "sreq.", XRC(31,729,1), X_MASK, M601, { RA, RS, RB } }, { "stfdxe", X(31,735), X_MASK, BOOKE64, { FRS, RA0, RB } }, { "mftgpr", XRC(31,735,0), XRA_MASK, POWER6, { RT, FRB } }, { "dcba", X(31,758), XRT_MASK, PPC405 | BOOKE, { RA, RB } }, { "stfdux", X(31,759), X_MASK, COM, { FRS, RAS, RB } }, { "srliq", XRC(31,760,0), X_MASK, M601, { RA, RS, SH } }, { "srliq.", XRC(31,760,1), X_MASK, M601, { RA, RS, SH } }, { "dcbae", X(31,766), XRT_MASK, BOOKE64, { RA, RB } }, { "stfduxe", X(31,767), X_MASK, BOOKE64, { FRS, RAS, RB } }, { "tlbivax", X(31,786), XRT_MASK, BOOKE, { RA, RB } }, { "tlbivaxe",X(31,787), XRT_MASK, BOOKE64, { RA, RB } }, { "lwzcix", X(31,789), X_MASK, POWER6, { RT, RA0, RB } }, { "lhbrx", X(31,790), X_MASK, COM, { RT, RA0, RB } }, { "sraw", XRC(31,792,0), X_MASK, PPCCOM, { RA, RS, RB } }, { "sra", XRC(31,792,0), X_MASK, PWRCOM, { RA, RS, RB } }, { "sraw.", XRC(31,792,1), X_MASK, PPCCOM, { RA, RS, RB } }, { "sra.", XRC(31,792,1), X_MASK, PWRCOM, { RA, RS, RB } }, { "srad", XRC(31,794,0), X_MASK, PPC64, { RA, RS, RB } }, { "srad.", XRC(31,794,1), X_MASK, PPC64, { RA, RS, RB } }, { "lhbrxe", X(31,798), X_MASK, BOOKE64, { RT, RA0, RB } }, { "ldxe", X(31,799), X_MASK, BOOKE64, { RT, RA0, RB } }, { "lduxe", X(31,831), X_MASK, BOOKE64, { RT, RA0, RB } }, { "rac", X(31,818), X_MASK, PWRCOM, { RT, RA, RB } }, { "lhzcix", X(31,821), X_MASK, POWER6, { RT, RA0, RB } }, { "dss", XDSS(31,822,0), XDSS_MASK, PPCVEC, { STRM } }, { "dssall", XDSS(31,822,1), XDSS_MASK, PPCVEC, { 0 } }, { "srawi", XRC(31,824,0), X_MASK, PPCCOM, { RA, RS, SH } }, { "srai", XRC(31,824,0), X_MASK, PWRCOM, { RA, RS, SH } }, { "srawi.", XRC(31,824,1), X_MASK, PPCCOM, { RA, RS, SH } }, { "srai.", XRC(31,824,1), X_MASK, PWRCOM, { RA, RS, SH } }, { "slbmfev", X(31,851), XRA_MASK, PPC64, { RT, RB } }, { "lbzcix", X(31,853), X_MASK, POWER6, { RT, RA0, RB } }, { "mbar", X(31,854), X_MASK, BOOKE, { MO } }, { "eieio", X(31,854), 0xffffffff, PPC, { 0 } }, { "lfiwax", X(31,855), X_MASK, POWER6, { FRT, RA0, RB } }, { "ldcix", X(31,885), X_MASK, POWER6, { RT, RA0, RB } }, { "tlbsx", XRC(31,914,0), X_MASK, PPC403|BOOKE, { RTO, RA, RB } }, { "tlbsx.", XRC(31,914,1), X_MASK, PPC403|BOOKE, { RTO, RA, RB } }, { "tlbsxe", XRC(31,915,0), X_MASK, BOOKE64, { RA, RB } }, { "tlbsxe.", XRC(31,915,1), X_MASK, BOOKE64, { RA, RB } }, { "slbmfee", X(31,915), XRA_MASK, PPC64, { RT, RB } }, { "stwcix", X(31,917), X_MASK, POWER6, { RS, RA0, RB } }, { "sthbrx", X(31,918), X_MASK, COM, { RS, RA0, RB } }, { "sraq", XRC(31,920,0), X_MASK, M601, { RA, RS, RB } }, { "sraq.", XRC(31,920,1), X_MASK, M601, { RA, RS, RB } }, { "srea", XRC(31,921,0), X_MASK, M601, { RA, RS, RB } }, { "srea.", XRC(31,921,1), X_MASK, M601, { RA, RS, RB } }, { "extsh", XRC(31,922,0), XRB_MASK, PPCCOM, { RA, RS } }, { "exts", XRC(31,922,0), XRB_MASK, PWRCOM, { RA, RS } }, { "extsh.", XRC(31,922,1), XRB_MASK, PPCCOM, { RA, RS } }, { "exts.", XRC(31,922,1), XRB_MASK, PWRCOM, { RA, RS } }, { "sthbrxe", X(31,926), X_MASK, BOOKE64, { RS, RA0, RB } }, { "stdxe", X(31,927), X_MASK, BOOKE64, { RS, RA0, RB } }, { "tlbrehi", XTLB(31,946,0), XTLB_MASK, PPC403, { RT, RA } }, { "tlbrelo", XTLB(31,946,1), XTLB_MASK, PPC403, { RT, RA } }, { "tlbre", X(31,946), X_MASK, PPC403|BOOKE, { RSO, RAOPT, SHO } }, { "sthcix", X(31,949), X_MASK, POWER6, { RS, RA0, RB } }, { "sraiq", XRC(31,952,0), X_MASK, M601, { RA, RS, SH } }, { "sraiq.", XRC(31,952,1), X_MASK, M601, { RA, RS, SH } }, { "extsb", XRC(31,954,0), XRB_MASK, PPC, { RA, RS} }, { "extsb.", XRC(31,954,1), XRB_MASK, PPC, { RA, RS} }, { "stduxe", X(31,959), X_MASK, BOOKE64, { RS, RAS, RB } }, { "iccci", X(31,966), XRT_MASK, PPC403|PPC440, { RA, RB } }, { "tlbwehi", XTLB(31,978,0), XTLB_MASK, PPC403, { RT, RA } }, { "tlbwelo", XTLB(31,978,1), XTLB_MASK, PPC403, { RT, RA } }, { "tlbwe", X(31,978), X_MASK, PPC403|BOOKE, { RSO, RAOPT, SHO } }, { "tlbld", X(31,978), XRTRA_MASK, PPC, { RB } }, { "stbcix", X(31,981), X_MASK, POWER6, { RS, RA0, RB } }, { "icbi", X(31,982), XRT_MASK, PPC, { RA, RB } }, { "stfiwx", X(31,983), X_MASK, PPC, { FRS, RA0, RB } }, { "extsw", XRC(31,986,0), XRB_MASK, PPC64 | BOOKE64,{ RA, RS } }, { "extsw.", XRC(31,986,1), XRB_MASK, PPC64, { RA, RS } }, { "icread", X(31,998), XRT_MASK, PPC403|PPC440, { RA, RB } }, { "icbie", X(31,990), XRT_MASK, BOOKE64, { RA, RB } }, { "stfiwxe", X(31,991), X_MASK, BOOKE64, { FRS, RA0, RB } }, { "tlbli", X(31,1010), XRTRA_MASK, PPC, { RB } }, { "stdcix", X(31,1013), X_MASK, POWER6, { RS, RA0, RB } }, { "dcbzl", XOPL(31,1014,1), XRT_MASK,POWER4, { RA, RB } }, { "dcbz", X(31,1014), XRT_MASK, PPC, { RA, RB } }, { "dclz", X(31,1014), XRT_MASK, PPC, { RA, RB } }, { "dcbze", X(31,1022), XRT_MASK, BOOKE64, { RA, RB } }, { "lvebx", X(31, 7), X_MASK, PPCVEC, { VD, RA, RB } }, { "lvehx", X(31, 39), X_MASK, PPCVEC, { VD, RA, RB } }, { "lvewx", X(31, 71), X_MASK, PPCVEC, { VD, RA, RB } }, { "lvsl", X(31, 6), X_MASK, PPCVEC, { VD, RA, RB } }, { "lvsr", X(31, 38), X_MASK, PPCVEC, { VD, RA, RB } }, { "lvx", X(31, 103), X_MASK, PPCVEC, { VD, RA, RB } }, { "lvxl", X(31, 359), X_MASK, PPCVEC, { VD, RA, RB } }, { "stvebx", X(31, 135), X_MASK, PPCVEC, { VS, RA, RB } }, { "stvehx", X(31, 167), X_MASK, PPCVEC, { VS, RA, RB } }, { "stvewx", X(31, 199), X_MASK, PPCVEC, { VS, RA, RB } }, { "stvx", X(31, 231), X_MASK, PPCVEC, { VS, RA, RB } }, { "stvxl", X(31, 487), X_MASK, PPCVEC, { VS, RA, RB } }, /* New load/store left/right index vector instructions that are in the Cell only. */ { "lvlx", X(31, 519), X_MASK, CELL, { VD, RA0, RB } }, { "lvlxl", X(31, 775), X_MASK, CELL, { VD, RA0, RB } }, { "lvrx", X(31, 551), X_MASK, CELL, { VD, RA0, RB } }, { "lvrxl", X(31, 807), X_MASK, CELL, { VD, RA0, RB } }, { "stvlx", X(31, 647), X_MASK, CELL, { VS, RA0, RB } }, { "stvlxl", X(31, 903), X_MASK, CELL, { VS, RA0, RB } }, { "stvrx", X(31, 679), X_MASK, CELL, { VS, RA0, RB } }, { "stvrxl", X(31, 935), X_MASK, CELL, { VS, RA0, RB } }, { "lwz", OP(32), OP_MASK, PPCCOM, { RT, D, RA0 } }, { "l", OP(32), OP_MASK, PWRCOM, { RT, D, RA0 } }, { "lwzu", OP(33), OP_MASK, PPCCOM, { RT, D, RAL } }, { "lu", OP(33), OP_MASK, PWRCOM, { RT, D, RA0 } }, { "lbz", OP(34), OP_MASK, COM, { RT, D, RA0 } }, { "lbzu", OP(35), OP_MASK, COM, { RT, D, RAL } }, { "stw", OP(36), OP_MASK, PPCCOM, { RS, D, RA0 } }, { "st", OP(36), OP_MASK, PWRCOM, { RS, D, RA0 } }, { "stwu", OP(37), OP_MASK, PPCCOM, { RS, D, RAS } }, { "stu", OP(37), OP_MASK, PWRCOM, { RS, D, RA0 } }, { "stb", OP(38), OP_MASK, COM, { RS, D, RA0 } }, { "stbu", OP(39), OP_MASK, COM, { RS, D, RAS } }, { "lhz", OP(40), OP_MASK, COM, { RT, D, RA0 } }, { "lhzu", OP(41), OP_MASK, COM, { RT, D, RAL } }, { "lha", OP(42), OP_MASK, COM, { RT, D, RA0 } }, { "lhau", OP(43), OP_MASK, COM, { RT, D, RAL } }, { "sth", OP(44), OP_MASK, COM, { RS, D, RA0 } }, { "sthu", OP(45), OP_MASK, COM, { RS, D, RAS } }, { "lmw", OP(46), OP_MASK, PPCCOM, { RT, D, RAM } }, { "lm", OP(46), OP_MASK, PWRCOM, { RT, D, RA0 } }, { "stmw", OP(47), OP_MASK, PPCCOM, { RS, D, RA0 } }, { "stm", OP(47), OP_MASK, PWRCOM, { RS, D, RA0 } }, { "lfs", OP(48), OP_MASK, COM, { FRT, D, RA0 } }, { "lfsu", OP(49), OP_MASK, COM, { FRT, D, RAS } }, { "lfd", OP(50), OP_MASK, COM, { FRT, D, RA0 } }, { "lfdu", OP(51), OP_MASK, COM, { FRT, D, RAS } }, { "stfs", OP(52), OP_MASK, COM, { FRS, D, RA0 } }, { "stfsu", OP(53), OP_MASK, COM, { FRS, D, RAS } }, { "stfd", OP(54), OP_MASK, COM, { FRS, D, RA0 } }, { "stfdu", OP(55), OP_MASK, COM, { FRS, D, RAS } }, { "lq", OP(56), OP_MASK, POWER4, { RTQ, DQ, RAQ } }, { "lfq", OP(56), OP_MASK, POWER2, { FRT, D, RA0 } }, { "lfqu", OP(57), OP_MASK, POWER2, { FRT, D, RA0 } }, { "lfdp", OP(57), OP_MASK, POWER6, { FRT, D, RA0 } }, { "lbze", DEO(58,0), DE_MASK, BOOKE64, { RT, DE, RA0 } }, { "lbzue", DEO(58,1), DE_MASK, BOOKE64, { RT, DE, RAL } }, { "lhze", DEO(58,2), DE_MASK, BOOKE64, { RT, DE, RA0 } }, { "lhzue", DEO(58,3), DE_MASK, BOOKE64, { RT, DE, RAL } }, { "lhae", DEO(58,4), DE_MASK, BOOKE64, { RT, DE, RA0 } }, { "lhaue", DEO(58,5), DE_MASK, BOOKE64, { RT, DE, RAL } }, { "lwze", DEO(58,6), DE_MASK, BOOKE64, { RT, DE, RA0 } }, { "lwzue", DEO(58,7), DE_MASK, BOOKE64, { RT, DE, RAL } }, { "stbe", DEO(58,8), DE_MASK, BOOKE64, { RS, DE, RA0 } }, { "stbue", DEO(58,9), DE_MASK, BOOKE64, { RS, DE, RAS } }, { "sthe", DEO(58,10), DE_MASK, BOOKE64, { RS, DE, RA0 } }, { "sthue", DEO(58,11), DE_MASK, BOOKE64, { RS, DE, RAS } }, { "stwe", DEO(58,14), DE_MASK, BOOKE64, { RS, DE, RA0 } }, { "stwue", DEO(58,15), DE_MASK, BOOKE64, { RS, DE, RAS } }, { "ld", DSO(58,0), DS_MASK, PPC64, { RT, DS, RA0 } }, { "ldu", DSO(58,1), DS_MASK, PPC64, { RT, DS, RAL } }, { "lwa", DSO(58,2), DS_MASK, PPC64, { RT, DS, RA0 } }, { "dadd", XRC(59,2,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "dadd.", XRC(59,2,1), X_MASK, POWER6, { FRT, FRA, FRB } }, { "dqua", ZRC(59,3,0), Z_MASK, POWER6, { FRT, FRA, FRB, RMC } }, { "dqua.", ZRC(59,3,1), Z_MASK, POWER6, { FRT, FRA, FRB, RMC } }, { "fdivs", A(59,18,0), AFRC_MASK, PPC, { FRT, FRA, FRB } }, { "fdivs.", A(59,18,1), AFRC_MASK, PPC, { FRT, FRA, FRB } }, { "fsubs", A(59,20,0), AFRC_MASK, PPC, { FRT, FRA, FRB } }, { "fsubs.", A(59,20,1), AFRC_MASK, PPC, { FRT, FRA, FRB } }, { "fadds", A(59,21,0), AFRC_MASK, PPC, { FRT, FRA, FRB } }, { "fadds.", A(59,21,1), AFRC_MASK, PPC, { FRT, FRA, FRB } }, { "fsqrts", A(59,22,0), AFRAFRC_MASK, PPC, { FRT, FRB } }, { "fsqrts.", A(59,22,1), AFRAFRC_MASK, PPC, { FRT, FRB } }, { "fres", A(59,24,0), AFRALFRC_MASK, PPC, { FRT, FRB, A_L } }, { "fres.", A(59,24,1), AFRALFRC_MASK, PPC, { FRT, FRB, A_L } }, { "fmuls", A(59,25,0), AFRB_MASK, PPC, { FRT, FRA, FRC } }, { "fmuls.", A(59,25,1), AFRB_MASK, PPC, { FRT, FRA, FRC } }, { "frsqrtes", A(59,26,0), AFRALFRC_MASK,POWER5, { FRT, FRB, A_L } }, { "frsqrtes.",A(59,26,1), AFRALFRC_MASK,POWER5, { FRT, FRB, A_L } }, { "fmsubs", A(59,28,0), A_MASK, PPC, { FRT,FRA,FRC,FRB } }, { "fmsubs.", A(59,28,1), A_MASK, PPC, { FRT,FRA,FRC,FRB } }, { "fmadds", A(59,29,0), A_MASK, PPC, { FRT,FRA,FRC,FRB } }, { "fmadds.", A(59,29,1), A_MASK, PPC, { FRT,FRA,FRC,FRB } }, { "fnmsubs", A(59,30,0), A_MASK, PPC, { FRT,FRA,FRC,FRB } }, { "fnmsubs.",A(59,30,1), A_MASK, PPC, { FRT,FRA,FRC,FRB } }, { "fnmadds", A(59,31,0), A_MASK, PPC, { FRT,FRA,FRC,FRB } }, { "fnmadds.",A(59,31,1), A_MASK, PPC, { FRT,FRA,FRC,FRB } }, { "dmul", XRC(59,34,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "dmul.", XRC(59,34,1), X_MASK, POWER6, { FRT, FRA, FRB } }, { "drrnd", ZRC(59,35,0), Z_MASK, POWER6, { FRT, FRA, FRB, RMC } }, { "drrnd.", ZRC(59,35,1), Z_MASK, POWER6, { FRT, FRA, FRB, RMC } }, { "dscli", ZRC(59,66,0), Z_MASK, POWER6, { FRT, FRA, SH16 } }, { "dscli.", ZRC(59,66,1), Z_MASK, POWER6, { FRT, FRA, SH16 } }, { "dquai", ZRC(59,67,0), Z_MASK, POWER6, { TE, FRT, FRB, RMC } }, { "dquai.", ZRC(59,67,1), Z_MASK, POWER6, { TE, FRT, FRB, RMC } }, { "dscri", ZRC(59,98,0), Z_MASK, POWER6, { FRT, FRA, SH16 } }, { "dscri.", ZRC(59,98,1), Z_MASK, POWER6, { FRT, FRA, SH16 } }, { "drintx", ZRC(59,99,0), Z_MASK, POWER6, { R, FRT, FRB, RMC } }, { "drintx.", ZRC(59,99,1), Z_MASK, POWER6, { R, FRT, FRB, RMC } }, { "dcmpo", X(59,130), X_MASK, POWER6, { BF, FRA, FRB } }, { "dtstex", X(59,162), X_MASK, POWER6, { BF, FRA, FRB } }, { "dtstdc", Z(59,194), Z_MASK, POWER6, { BF, FRA, DCM } }, { "dtstdg", Z(59,226), Z_MASK, POWER6, { BF, FRA, DGM } }, { "drintn", ZRC(59,227,0), Z_MASK, POWER6, { R, FRT, FRB, RMC } }, { "drintn.", ZRC(59,227,1), Z_MASK, POWER6, { R, FRT, FRB, RMC } }, { "dctdp", XRC(59,258,0), X_MASK, POWER6, { FRT, FRB } }, { "dctdp.", XRC(59,258,1), X_MASK, POWER6, { FRT, FRB } }, { "dctfix", XRC(59,290,0), X_MASK, POWER6, { FRT, FRB } }, { "dctfix.", XRC(59,290,1), X_MASK, POWER6, { FRT, FRB } }, { "ddedpd", XRC(59,322,0), X_MASK, POWER6, { SP, FRT, FRB } }, { "ddedpd.", XRC(59,322,1), X_MASK, POWER6, { SP, FRT, FRB } }, { "dxex", XRC(59,354,0), X_MASK, POWER6, { FRT, FRB } }, { "dxex.", XRC(59,354,1), X_MASK, POWER6, { FRT, FRB } }, { "dsub", XRC(59,514,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "dsub.", XRC(59,514,1), X_MASK, POWER6, { FRT, FRA, FRB } }, { "ddiv", XRC(59,546,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "ddiv.", XRC(59,546,1), X_MASK, POWER6, { FRT, FRA, FRB } }, { "dcmpu", X(59,642), X_MASK, POWER6, { BF, FRA, FRB } }, { "dtstsf", X(59,674), X_MASK, POWER6, { BF, FRA, FRB } }, { "drsp", XRC(59,770,0), X_MASK, POWER6, { FRT, FRB } }, { "drsp.", XRC(59,770,1), X_MASK, POWER6, { FRT, FRB } }, { "dcffix", XRC(59,802,0), X_MASK, POWER6, { FRT, FRB } }, { "dcffix.", XRC(59,802,1), X_MASK, POWER6, { FRT, FRB } }, { "denbcd", XRC(59,834,0), X_MASK, POWER6, { S, FRT, FRB } }, { "denbcd.", XRC(59,834,1), X_MASK, POWER6, { S, FRT, FRB } }, { "diex", XRC(59,866,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "diex.", XRC(59,866,1), X_MASK, POWER6, { FRT, FRA, FRB } }, { "stfq", OP(60), OP_MASK, POWER2, { FRS, D, RA } }, { "stfqu", OP(61), OP_MASK, POWER2, { FRS, D, RA } }, { "stfdp", OP(61), OP_MASK, POWER6, { FRT, D, RA0 } }, { "lde", DEO(62,0), DE_MASK, BOOKE64, { RT, DES, RA0 } }, { "ldue", DEO(62,1), DE_MASK, BOOKE64, { RT, DES, RA0 } }, { "lfse", DEO(62,4), DE_MASK, BOOKE64, { FRT, DES, RA0 } }, { "lfsue", DEO(62,5), DE_MASK, BOOKE64, { FRT, DES, RAS } }, { "lfde", DEO(62,6), DE_MASK, BOOKE64, { FRT, DES, RA0 } }, { "lfdue", DEO(62,7), DE_MASK, BOOKE64, { FRT, DES, RAS } }, { "stde", DEO(62,8), DE_MASK, BOOKE64, { RS, DES, RA0 } }, { "stdue", DEO(62,9), DE_MASK, BOOKE64, { RS, DES, RAS } }, { "stfse", DEO(62,12), DE_MASK, BOOKE64, { FRS, DES, RA0 } }, { "stfsue", DEO(62,13), DE_MASK, BOOKE64, { FRS, DES, RAS } }, { "stfde", DEO(62,14), DE_MASK, BOOKE64, { FRS, DES, RA0 } }, { "stfdue", DEO(62,15), DE_MASK, BOOKE64, { FRS, DES, RAS } }, { "std", DSO(62,0), DS_MASK, PPC64, { RS, DS, RA0 } }, { "stdu", DSO(62,1), DS_MASK, PPC64, { RS, DS, RAS } }, { "stq", DSO(62,2), DS_MASK, POWER4, { RSQ, DS, RA0 } }, { "fcmpu", X(63,0), X_MASK|(3<<21), COM, { BF, FRA, FRB } }, { "daddq", XRC(63,2,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "daddq.", XRC(63,2,1), X_MASK, POWER6, { FRT, FRA, FRB } }, { "dquaq", ZRC(63,3,0), Z_MASK, POWER6, { FRT, FRA, FRB, RMC } }, { "dquaq.", ZRC(63,3,1), Z_MASK, POWER6, { FRT, FRA, FRB, RMC } }, { "fcpsgn", XRC(63,8,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "fcpsgn.", XRC(63,8,1), X_MASK, POWER6, { FRT, FRA, FRB } }, { "frsp", XRC(63,12,0), XRA_MASK, COM, { FRT, FRB } }, { "frsp.", XRC(63,12,1), XRA_MASK, COM, { FRT, FRB } }, { "fctiw", XRC(63,14,0), XRA_MASK, PPCCOM, { FRT, FRB } }, { "fcir", XRC(63,14,0), XRA_MASK, POWER2, { FRT, FRB } }, { "fctiw.", XRC(63,14,1), XRA_MASK, PPCCOM, { FRT, FRB } }, { "fcir.", XRC(63,14,1), XRA_MASK, POWER2, { FRT, FRB } }, { "fctiwz", XRC(63,15,0), XRA_MASK, PPCCOM, { FRT, FRB } }, { "fcirz", XRC(63,15,0), XRA_MASK, POWER2, { FRT, FRB } }, { "fctiwz.", XRC(63,15,1), XRA_MASK, PPCCOM, { FRT, FRB } }, { "fcirz.", XRC(63,15,1), XRA_MASK, POWER2, { FRT, FRB } }, { "fdiv", A(63,18,0), AFRC_MASK, PPCCOM, { FRT, FRA, FRB } }, { "fd", A(63,18,0), AFRC_MASK, PWRCOM, { FRT, FRA, FRB } }, { "fdiv.", A(63,18,1), AFRC_MASK, PPCCOM, { FRT, FRA, FRB } }, { "fd.", A(63,18,1), AFRC_MASK, PWRCOM, { FRT, FRA, FRB } }, { "fsub", A(63,20,0), AFRC_MASK, PPCCOM, { FRT, FRA, FRB } }, { "fs", A(63,20,0), AFRC_MASK, PWRCOM, { FRT, FRA, FRB } }, { "fsub.", A(63,20,1), AFRC_MASK, PPCCOM, { FRT, FRA, FRB } }, { "fs.", A(63,20,1), AFRC_MASK, PWRCOM, { FRT, FRA, FRB } }, { "fadd", A(63,21,0), AFRC_MASK, PPCCOM, { FRT, FRA, FRB } }, { "fa", A(63,21,0), AFRC_MASK, PWRCOM, { FRT, FRA, FRB } }, { "fadd.", A(63,21,1), AFRC_MASK, PPCCOM, { FRT, FRA, FRB } }, { "fa.", A(63,21,1), AFRC_MASK, PWRCOM, { FRT, FRA, FRB } }, { "fsqrt", A(63,22,0), AFRAFRC_MASK, PPCPWR2, { FRT, FRB } }, { "fsqrt.", A(63,22,1), AFRAFRC_MASK, PPCPWR2, { FRT, FRB } }, { "fsel", A(63,23,0), A_MASK, PPC, { FRT,FRA,FRC,FRB } }, { "fsel.", A(63,23,1), A_MASK, PPC, { FRT,FRA,FRC,FRB } }, { "fre", A(63,24,0), AFRALFRC_MASK, POWER5, { FRT, FRB, A_L } }, { "fre.", A(63,24,1), AFRALFRC_MASK, POWER5, { FRT, FRB, A_L } }, { "fmul", A(63,25,0), AFRB_MASK, PPCCOM, { FRT, FRA, FRC } }, { "fm", A(63,25,0), AFRB_MASK, PWRCOM, { FRT, FRA, FRC } }, { "fmul.", A(63,25,1), AFRB_MASK, PPCCOM, { FRT, FRA, FRC } }, { "fm.", A(63,25,1), AFRB_MASK, PWRCOM, { FRT, FRA, FRC } }, { "frsqrte", A(63,26,0), AFRALFRC_MASK, PPC, { FRT, FRB, A_L } }, { "frsqrte.",A(63,26,1), AFRALFRC_MASK, PPC, { FRT, FRB, A_L } }, { "fmsub", A(63,28,0), A_MASK, PPCCOM, { FRT,FRA,FRC,FRB } }, { "fms", A(63,28,0), A_MASK, PWRCOM, { FRT,FRA,FRC,FRB } }, { "fmsub.", A(63,28,1), A_MASK, PPCCOM, { FRT,FRA,FRC,FRB } }, { "fms.", A(63,28,1), A_MASK, PWRCOM, { FRT,FRA,FRC,FRB } }, { "fmadd", A(63,29,0), A_MASK, PPCCOM, { FRT,FRA,FRC,FRB } }, { "fma", A(63,29,0), A_MASK, PWRCOM, { FRT,FRA,FRC,FRB } }, { "fmadd.", A(63,29,1), A_MASK, PPCCOM, { FRT,FRA,FRC,FRB } }, { "fma.", A(63,29,1), A_MASK, PWRCOM, { FRT,FRA,FRC,FRB } }, { "fnmsub", A(63,30,0), A_MASK, PPCCOM, { FRT,FRA,FRC,FRB } }, { "fnms", A(63,30,0), A_MASK, PWRCOM, { FRT,FRA,FRC,FRB } }, { "fnmsub.", A(63,30,1), A_MASK, PPCCOM, { FRT,FRA,FRC,FRB } }, { "fnms.", A(63,30,1), A_MASK, PWRCOM, { FRT,FRA,FRC,FRB } }, { "fnmadd", A(63,31,0), A_MASK, PPCCOM, { FRT,FRA,FRC,FRB } }, { "fnma", A(63,31,0), A_MASK, PWRCOM, { FRT,FRA,FRC,FRB } }, { "fnmadd.", A(63,31,1), A_MASK, PPCCOM, { FRT,FRA,FRC,FRB } }, { "fnma.", A(63,31,1), A_MASK, PWRCOM, { FRT,FRA,FRC,FRB } }, { "fcmpo", X(63,32), X_MASK|(3<<21), COM, { BF, FRA, FRB } }, { "dmulq", XRC(63,34,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "dmulq.", XRC(63,34,1), X_MASK, POWER6, { FRT, FRA, FRB } }, { "drrndq", ZRC(63,35,0), Z_MASK, POWER6, { FRT, FRA, FRB, RMC } }, { "drrndq.", ZRC(63,35,1), Z_MASK, POWER6, { FRT, FRA, FRB, RMC } }, { "mtfsb1", XRC(63,38,0), XRARB_MASK, COM, { BT } }, { "mtfsb1.", XRC(63,38,1), XRARB_MASK, COM, { BT } }, { "fneg", XRC(63,40,0), XRA_MASK, COM, { FRT, FRB } }, { "fneg.", XRC(63,40,1), XRA_MASK, COM, { FRT, FRB } }, { "mcrfs", X(63,64), XRB_MASK|(3<<21)|(3<<16), COM, { BF, BFA } }, { "dscliq", ZRC(63,66,0), Z_MASK, POWER6, { FRT, FRA, SH16 } }, { "dscliq.", ZRC(63,66,1), Z_MASK, POWER6, { FRT, FRA, SH16 } }, { "dquaiq", ZRC(63,67,0), Z_MASK, POWER6, { TE, FRT, FRB, RMC } }, { "dquaiq.", ZRC(63,67,1), Z_MASK, POWER6, { FRT, FRA, FRB, RMC } }, { "mtfsb0", XRC(63,70,0), XRARB_MASK, COM, { BT } }, { "mtfsb0.", XRC(63,70,1), XRARB_MASK, COM, { BT } }, { "fmr", XRC(63,72,0), XRA_MASK, COM, { FRT, FRB } }, { "fmr.", XRC(63,72,1), XRA_MASK, COM, { FRT, FRB } }, { "dscriq", ZRC(63,98,0), Z_MASK, POWER6, { FRT, FRA, SH16 } }, { "dscriq.", ZRC(63,98,1), Z_MASK, POWER6, { FRT, FRA, SH16 } }, { "drintxq", ZRC(63,99,0), Z_MASK, POWER6, { R, FRT, FRB, RMC } }, { "drintxq.",ZRC(63,99,1), Z_MASK, POWER6, { R, FRT, FRB, RMC } }, { "dcmpoq", X(63,130), X_MASK, POWER6, { BF, FRA, FRB } }, { "mtfsfi", XRC(63,134,0), XRA_MASK|(3<<21)|(1<<11), COM, { BF, U } }, { "mtfsfi.", XRC(63,134,1), XRA_MASK|(3<<21)|(1<<11), COM, { BF, U } }, { "fnabs", XRC(63,136,0), XRA_MASK, COM, { FRT, FRB } }, { "fnabs.", XRC(63,136,1), XRA_MASK, COM, { FRT, FRB } }, { "dtstexq", X(63,162), X_MASK, POWER6, { BF, FRA, FRB } }, { "dtstdcq", Z(63,194), Z_MASK, POWER6, { BF, FRA, DCM } }, { "dtstdgq", Z(63,226), Z_MASK, POWER6, { BF, FRA, DGM } }, { "drintnq", ZRC(63,227,0), Z_MASK, POWER6, { R, FRT, FRB, RMC } }, { "drintnq.",ZRC(63,227,1), Z_MASK, POWER6, { R, FRT, FRB, RMC } }, { "dctqpq", XRC(63,258,0), X_MASK, POWER6, { FRT, FRB } }, { "dctqpq.", XRC(63,258,1), X_MASK, POWER6, { FRT, FRB } }, { "fabs", XRC(63,264,0), XRA_MASK, COM, { FRT, FRB } }, { "fabs.", XRC(63,264,1), XRA_MASK, COM, { FRT, FRB } }, { "dctfixq", XRC(63,290,0), X_MASK, POWER6, { FRT, FRB } }, { "dctfixq.",XRC(63,290,1), X_MASK, POWER6, { FRT, FRB } }, { "ddedpdq", XRC(63,322,0), X_MASK, POWER6, { SP, FRT, FRB } }, { "ddedpdq.",XRC(63,322,1), X_MASK, POWER6, { SP, FRT, FRB } }, { "dxexq", XRC(63,354,0), X_MASK, POWER6, { FRT, FRB } }, { "dxexq.", XRC(63,354,1), X_MASK, POWER6, { FRT, FRB } }, { "frin", XRC(63,392,0), XRA_MASK, POWER5, { FRT, FRB } }, { "frin.", XRC(63,392,1), XRA_MASK, POWER5, { FRT, FRB } }, { "friz", XRC(63,424,0), XRA_MASK, POWER5, { FRT, FRB } }, { "friz.", XRC(63,424,1), XRA_MASK, POWER5, { FRT, FRB } }, { "frip", XRC(63,456,0), XRA_MASK, POWER5, { FRT, FRB } }, { "frip.", XRC(63,456,1), XRA_MASK, POWER5, { FRT, FRB } }, { "frim", XRC(63,488,0), XRA_MASK, POWER5, { FRT, FRB } }, { "frim.", XRC(63,488,1), XRA_MASK, POWER5, { FRT, FRB } }, { "dsubq", XRC(63,514,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "dsubq.", XRC(63,514,1), X_MASK, POWER6, { FRT, FRA, FRB } }, { "ddivq", XRC(63,546,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "ddivq.", XRC(63,546,1), X_MASK, POWER6, { FRT, FRA, FRB } }, { "mffs", XRC(63,583,0), XRARB_MASK, COM, { FRT } }, { "mffs.", XRC(63,583,1), XRARB_MASK, COM, { FRT } }, { "dcmpuq", X(63,642), X_MASK, POWER6, { BF, FRA, FRB } }, { "dtstsfq", X(63,674), X_MASK, POWER6, { BF, FRA, FRB } }, { "mtfsf", XFL(63,711,0), XFL_MASK, COM, { FLM, FRB } }, { "mtfsf.", XFL(63,711,1), XFL_MASK, COM, { FLM, FRB } }, { "drdpq", XRC(63,770,0), X_MASK, POWER6, { FRT, FRB } }, { "drdpq.", XRC(63,770,1), X_MASK, POWER6, { FRT, FRB } }, { "dcffixq", XRC(63,802,0), X_MASK, POWER6, { FRT, FRB } }, { "dcffixq.",XRC(63,802,1), X_MASK, POWER6, { FRT, FRB } }, { "fctid", XRC(63,814,0), XRA_MASK, PPC64, { FRT, FRB } }, { "fctid.", XRC(63,814,1), XRA_MASK, PPC64, { FRT, FRB } }, { "fctidz", XRC(63,815,0), XRA_MASK, PPC64, { FRT, FRB } }, { "fctidz.", XRC(63,815,1), XRA_MASK, PPC64, { FRT, FRB } }, { "denbcdq", XRC(63,834,0), X_MASK, POWER6, { S, FRT, FRB } }, { "denbcdq.",XRC(63,834,1), X_MASK, POWER6, { S, FRT, FRB } }, { "fcfid", XRC(63,846,0), XRA_MASK, PPC64, { FRT, FRB } }, { "fcfid.", XRC(63,846,1), XRA_MASK, PPC64, { FRT, FRB } }, { "diexq", XRC(63,866,0), X_MASK, POWER6, { FRT, FRA, FRB } }, { "diexq.", XRC(63,866,1), X_MASK, POWER6, { FRT, FRA, FRB } }, }; const int powerpc_num_opcodes = ARRAY_SIZE(powerpc_opcodes); /* The macro table. This is only used by the assembler. */ /* The expressions of the form (-x ! 31) & (x | 31) have the value 0 when x=0; 32-x when x is between 1 and 31; are negative if x is negative; and are 32 or more otherwise. This is what you want when, for instance, you are emulating a right shift by a rotate-left-and-mask, because the underlying instructions support shifts of size 0 but not shifts of size 32. By comparison, when extracting x bits from some word you want to use just 32-x, because the underlying instructions don't support extracting 0 bits but do support extracting the whole word (32 bits in this case). */ const struct powerpc_macro powerpc_macros[] = { { "extldi", 4, PPC64, "rldicr %0,%1,%3,(%2)-1" }, { "extldi.", 4, PPC64, "rldicr. %0,%1,%3,(%2)-1" }, { "extrdi", 4, PPC64, "rldicl %0,%1,(%2)+(%3),64-(%2)" }, { "extrdi.", 4, PPC64, "rldicl. %0,%1,(%2)+(%3),64-(%2)" }, { "insrdi", 4, PPC64, "rldimi %0,%1,64-((%2)+(%3)),%3" }, { "insrdi.", 4, PPC64, "rldimi. %0,%1,64-((%2)+(%3)),%3" }, { "rotrdi", 3, PPC64, "rldicl %0,%1,(-(%2)!63)&((%2)|63),0" }, { "rotrdi.", 3, PPC64, "rldicl. %0,%1,(-(%2)!63)&((%2)|63),0" }, { "sldi", 3, PPC64, "rldicr %0,%1,%2,63-(%2)" }, { "sldi.", 3, PPC64, "rldicr. %0,%1,%2,63-(%2)" }, { "srdi", 3, PPC64, "rldicl %0,%1,(-(%2)!63)&((%2)|63),%2" }, { "srdi.", 3, PPC64, "rldicl. %0,%1,(-(%2)!63)&((%2)|63),%2" }, { "clrrdi", 3, PPC64, "rldicr %0,%1,0,63-(%2)" }, { "clrrdi.", 3, PPC64, "rldicr. %0,%1,0,63-(%2)" }, { "clrlsldi",4, PPC64, "rldic %0,%1,%3,(%2)-(%3)" }, { "clrlsldi.",4, PPC64, "rldic. %0,%1,%3,(%2)-(%3)" }, { "extlwi", 4, PPCCOM, "rlwinm %0,%1,%3,0,(%2)-1" }, { "extlwi.", 4, PPCCOM, "rlwinm. %0,%1,%3,0,(%2)-1" }, { "extrwi", 4, PPCCOM, "rlwinm %0,%1,((%2)+(%3))&((%2)+(%3)<>32),32-(%2),31" }, { "extrwi.", 4, PPCCOM, "rlwinm. %0,%1,((%2)+(%3))&((%2)+(%3)<>32),32-(%2),31" }, { "inslwi", 4, PPCCOM, "rlwimi %0,%1,(-(%3)!31)&((%3)|31),%3,(%2)+(%3)-1" }, { "inslwi.", 4, PPCCOM, "rlwimi. %0,%1,(-(%3)!31)&((%3)|31),%3,(%2)+(%3)-1"}, { "insrwi", 4, PPCCOM, "rlwimi %0,%1,32-((%2)+(%3)),%3,(%2)+(%3)-1" }, { "insrwi.", 4, PPCCOM, "rlwimi. %0,%1,32-((%2)+(%3)),%3,(%2)+(%3)-1"}, { "rotrwi", 3, PPCCOM, "rlwinm %0,%1,(-(%2)!31)&((%2)|31),0,31" }, { "rotrwi.", 3, PPCCOM, "rlwinm. %0,%1,(-(%2)!31)&((%2)|31),0,31" }, { "slwi", 3, PPCCOM, "rlwinm %0,%1,%2,0,31-(%2)" }, { "sli", 3, PWRCOM, "rlinm %0,%1,%2,0,31-(%2)" }, { "slwi.", 3, PPCCOM, "rlwinm. %0,%1,%2,0,31-(%2)" }, { "sli.", 3, PWRCOM, "rlinm. %0,%1,%2,0,31-(%2)" }, { "srwi", 3, PPCCOM, "rlwinm %0,%1,(-(%2)!31)&((%2)|31),%2,31" }, { "sri", 3, PWRCOM, "rlinm %0,%1,(-(%2)!31)&((%2)|31),%2,31" }, { "srwi.", 3, PPCCOM, "rlwinm. %0,%1,(-(%2)!31)&((%2)|31),%2,31" }, { "sri.", 3, PWRCOM, "rlinm. %0,%1,(-(%2)!31)&((%2)|31),%2,31" }, { "clrrwi", 3, PPCCOM, "rlwinm %0,%1,0,0,31-(%2)" }, { "clrrwi.", 3, PPCCOM, "rlwinm. %0,%1,0,0,31-(%2)" }, { "clrlslwi",4, PPCCOM, "rlwinm %0,%1,%3,(%2)-(%3),31-(%3)" }, { "clrlslwi.",4, PPCCOM, "rlwinm. %0,%1,%3,(%2)-(%3),31-(%3)" }, }; const int powerpc_num_macros = ARRAY_SIZE(powerpc_macros);
n3ocort3x/msm_htc_helper
arch/powerpc/xmon/ppc-opc.c
C
gpl-2.0
226,188
/* * Detection routine for the NCR53c710 based Amiga SCSI Controllers for Linux. * Amiga MacroSystemUS WarpEngine SCSI controller. * Amiga Technologies/DKB A4091 SCSI controller. * * Written 1997 by Alan Hourihane <alanh@fairlite.demon.co.uk> * plus modifications of the 53c7xx.c driver to support the Amiga. * * Rewritten to use 53c700.c by Kars de Jong <jongk@linux-m68k.org> */ #include <linux/module.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/zorro.h> #include <linux/slab.h> #include <asm/amigahw.h> #include <asm/amigaints.h> #include <scsi/scsi_host.h> #include <scsi/scsi_transport_spi.h> #include "53c700.h" MODULE_AUTHOR("Alan Hourihane <alanh@fairlite.demon.co.uk> / Kars de Jong <jongk@linux-m68k.org>"); MODULE_DESCRIPTION("Amiga Zorro NCR53C710 driver"); MODULE_LICENSE("GPL"); static struct scsi_host_template zorro7xx_scsi_driver_template = { .proc_name = "zorro7xx", .this_id = 7, .module = THIS_MODULE, }; static struct zorro_driver_data { const char *name; unsigned long offset; int absolute; /* offset is absolute address */ } zorro7xx_driver_data[] __devinitdata = { { .name = "PowerUP 603e+", .offset = 0xf40000, .absolute = 1 }, { .name = "WarpEngine 40xx", .offset = 0x40000 }, { .name = "A4091", .offset = 0x800000 }, { .name = "GForce 040/060", .offset = 0x40000 }, { 0 } }; static struct zorro_device_id zorro7xx_zorro_tbl[] __devinitdata = { { .id = ZORRO_PROD_PHASE5_BLIZZARD_603E_PLUS, .driver_data = (unsigned long)&zorro7xx_driver_data[0], }, { .id = ZORRO_PROD_MACROSYSTEMS_WARP_ENGINE_40xx, .driver_data = (unsigned long)&zorro7xx_driver_data[1], }, { .id = ZORRO_PROD_CBM_A4091_1, .driver_data = (unsigned long)&zorro7xx_driver_data[2], }, { .id = ZORRO_PROD_CBM_A4091_2, .driver_data = (unsigned long)&zorro7xx_driver_data[2], }, { .id = ZORRO_PROD_GVP_GFORCE_040_060, .driver_data = (unsigned long)&zorro7xx_driver_data[3], }, { 0 } }; MODULE_DEVICE_TABLE(zorro, zorro7xx_zorro_tbl); static int __devinit zorro7xx_init_one(struct zorro_dev *z, const struct zorro_device_id *ent) { struct Scsi_Host *host; struct NCR_700_Host_Parameters *hostdata; struct zorro_driver_data *zdd; unsigned long board, ioaddr; board = zorro_resource_start(z); zdd = (struct zorro_driver_data *)ent->driver_data; if (zdd->absolute) { ioaddr = zdd->offset; } else { ioaddr = board + zdd->offset; } if (!zorro_request_device(z, zdd->name)) { printk(KERN_ERR "zorro7xx: cannot reserve region 0x%lx, abort\n", board); return -EBUSY; } hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL); if (!hostdata) { printk(KERN_ERR "zorro7xx: Failed to allocate host data\n"); goto out_release; } /* Fill in the required pieces of hostdata */ if (ioaddr > 0x01000000) hostdata->base = ioremap(ioaddr, zorro_resource_len(z)); else hostdata->base = (void __iomem *)ZTWO_VADDR(ioaddr); hostdata->clock = 50; hostdata->chip710 = 1; /* Settings for at least WarpEngine 40xx */ hostdata->ctest7_extra = CTEST7_TT1; zorro7xx_scsi_driver_template.name = zdd->name; /* and register the chip */ host = NCR_700_detect(&zorro7xx_scsi_driver_template, hostdata, &z->dev); if (!host) { printk(KERN_ERR "zorro7xx: No host detected; " "board configuration problem?\n"); goto out_free; } host->this_id = 7; host->base = ioaddr; host->irq = IRQ_AMIGA_PORTS; if (request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "zorro7xx-scsi", host)) { printk(KERN_ERR "zorro7xx: request_irq failed\n"); goto out_put_host; } zorro_set_drvdata(z, host); scsi_scan_host(host); return 0; out_put_host: scsi_host_put(host); out_free: if (ioaddr > 0x01000000) iounmap(hostdata->base); kfree(hostdata); out_release: zorro_release_device(z); return -ENODEV; } static __devexit void zorro7xx_remove_one(struct zorro_dev *z) { struct Scsi_Host *host = zorro_get_drvdata(z); struct NCR_700_Host_Parameters *hostdata = shost_priv(host); scsi_remove_host(host); NCR_700_release(host); kfree(hostdata); free_irq(host->irq, host); zorro_release_device(z); } static struct zorro_driver zorro7xx_driver = { .name = "zorro7xx-scsi", .id_table = zorro7xx_zorro_tbl, .probe = zorro7xx_init_one, .remove = __devexit_p(zorro7xx_remove_one), }; static int __init zorro7xx_scsi_init(void) { return zorro_register_driver(&zorro7xx_driver); } static void __exit zorro7xx_scsi_exit(void) { zorro_unregister_driver(&zorro7xx_driver); } module_init(zorro7xx_scsi_init); module_exit(zorro7xx_scsi_exit);
kerneldevs/caf-kernel
drivers/scsi/zorro7xx.c
C
gpl-2.0
4,600
/* * Context.c. Python interfaces for perf script. * * Copyright (C) 2010 Tom Zanussi <tzanussi@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <Python.h> #include "../../../perf.h" #include "../../../util/trace-event.h" PyMODINIT_FUNC initperf_trace_context(void); static PyObject *perf_trace_context_common_pc(PyObject *self, PyObject *args) { static struct scripting_context *scripting_context; PyObject *context; int retval; if (!PyArg_ParseTuple(args, "O", &context)) return NULL; scripting_context = PyCObject_AsVoidPtr(context); retval = common_pc(scripting_context); return Py_BuildValue("i", retval); } static PyObject *perf_trace_context_common_flags(PyObject *self, PyObject *args) { static struct scripting_context *scripting_context; PyObject *context; int retval; if (!PyArg_ParseTuple(args, "O", &context)) return NULL; scripting_context = PyCObject_AsVoidPtr(context); retval = common_flags(scripting_context); return Py_BuildValue("i", retval); } static PyObject *perf_trace_context_common_lock_depth(PyObject *self, PyObject *args) { static struct scripting_context *scripting_context; PyObject *context; int retval; if (!PyArg_ParseTuple(args, "O", &context)) return NULL; scripting_context = PyCObject_AsVoidPtr(context); retval = common_lock_depth(scripting_context); return Py_BuildValue("i", retval); } static PyMethodDef ContextMethods[] = { { "common_pc", perf_trace_context_common_pc, METH_VARARGS, "Get the common preempt count event field value."}, { "common_flags", perf_trace_context_common_flags, METH_VARARGS, "Get the common flags event field value."}, { "common_lock_depth", perf_trace_context_common_lock_depth, METH_VARARGS, "Get the common lock depth event field value."}, { NULL, NULL, 0, NULL} }; PyMODINIT_FUNC initperf_trace_context(void) { (void) Py_InitModule("perf_trace_context", ContextMethods); }
F4uzan/f4kernel-u0
tools/perf/scripts/python/Perf-Trace-Util/Context.c
C
gpl-2.0
2,630
/* Skinr styles /-------------------------------------------------------------- */ /* Rounded Titles */ .prosper-rounded-title h2.block-title { background: #a9a9a9; color: #fff; font-weight: normal; margin: 0; padding: 0 10px; border-top-left-radius: 5px; border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; } /* Gray Rounded - Plain */ .prosper-gray-rounded-plain h2.block-title { background: #fff; border-bottom: 2px solid #b0b0b0; border-left: 1px solid #f3f3f3; border-right: 1px solid #f3f3f3; color: #5b5b5b; padding: 10px; } .prosper-gray-rounded-plain a:link, .prosper-gray-rounded-plain a:visited { color: #af0000; } .prosper-gray-rounded-plain a:hover, .prosper-gray-rounded-plain a:focus, .prosper-gray-rounded-plain a:active { color: #369; } .prosper-gray-rounded-plain ul.pager li.pager-current { background-color: #fff; } .prosper-gray-rounded-plain .content { padding: 10px; } /* Gray Rounded - Style */ .prosper-gray-rounded-style h2.title .block-title { padding: 10px; border-top-left-radius: 5px; border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; } .prosper-gray-rounded-style .content { background: #fff; border-bottom: 2px solid #b0b0b0; border-left: 1px solid #f3f3f3; border-right: 1px solid #f3f3f3; color: #5b5b5b; padding: 10px; } .prosper-gray-rounded-style ul { margin: 0; padding: 0; } .prosper-gray-rounded-style ul li { background: #fff; border-bottom: 1px solid #f3f3f3; display: block; list-style: none; list-style-image: none; margin: 0; padding: 5px 5px 5px 25px; } .prosper-gray-rounded-style ul li.active-trail a.active { text-decoration: underline; } .prosper-gray-rounded-style ul li ul { background: #f3f3f3; border-bottom: 1px solid #e6e6e6; border-top: 2px solid #e6e6e6; margin: 5px -5px -6px -25px ; padding: 0 10px; } .prosper-gray-rounded-style ul li ul li { border-bottom: none; } .prosper-gray-rounded-style ul li ul li a:link, .prosper-gray-rounded-style ul li ul li a:visited { color: #a9a9a9; } .prosper-gray-rounded-style ul li ul li ul { border-bottom: none; border-top: none; } /* Gray border - dark background */ .prosper-grayborder-darkbackground .inner { background: #343434; border-bottom: 1px solid #404040; border-top: 1px solid #343434; color: #a9a9a9; padding: 20px; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; } .prosper-grayborder-darkbackground h2.block-title { color: #f3f3f3; } .prosper-grayborder-darkbackground a:link, .prosper-grayborder-darkbackground a:visited { color: #fff; } .prosper-grayborder-darkbackground ul { margin: 0 -10px; padding: 0; } .prosper-grayborder-darkbackground ul li { background: #fff; border-bottom: 1px solid #4e4e4e; display: block; list-style: none; list-style-image: none; margin: 0; padding: 5px 5px 5px 25px; } .prosper-grayborder-darkbackground ul li a:link, .prosper-grayborder-darkbackground ul li a:visited { color: #a9a9a9; } .prosper-grayborder-darkbackground ul li a:hover, .prosper-grayborder-darkbackground ul li.active-trail a.active { color: #fff; text-decoration: none; } .prosper-grayborder-darkbackground ul li.active-trail a.active { text-decoration: underline; } .prosper-grayborder-darkbackground ul li ul { background: #2f2f2f; border-bottom: 1px solid #4e4e4e; border-top: 2px solid #4e4e4e; margin: 5px -5px -6px -25px ; padding: 0 10px; } .prosper-grayborder-darkbackground ul li ul li { border-bottom: none; } .prosper-grayborder-darkbackground ul li ul li ul { border-bottom: none; border-top: none; } .prosper-grayborder-darkbackground ul li ul li a { color: #a9a9a9; } /* Medium gray background - bottom border */ .prosper-mediumgraybackground-bottomborder .inner { background: #d8d8d8; border-bottom: 2px solid #b0b0b0; padding: 20px; } .prosper-mediumgraybackground-bottomborder h2.block-title { color: #5b5b5b; } .prosper-mediumgraybackground-bottomborder a:link, .prosper-mediumgraybackground-bottomborder a:visited { color: #af0000; } /* Light gray background - border */ .prosper-lightgraybackground-border .inner { background: #f3f3f3; border: 1px solid #f3f3f3; color: #5b5b5b; padding: 20px; border-radius: 4px; -moz-border-radius: 4px; -webkit-border-radius: 4px; } .prosper-lightgraybackground-border h2.block-title { color: #000; } .prosper-lightgraybackground-border a:link, .prosper-lightgraybackground-border a:visited { color: #af0000; } /* Gradient & border */ .prosper-gradient-border .inner { background: -moz-linear-gradient(top, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.1) 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.2)), color-stop(100%,rgba(0,0,0,0.1))); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, rgba(0,0,0,0.2) 0%,rgba(0,0,0,0.1) 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, rgba(0,0,0,0.2) 0%,rgba(0,0,0,0.1) 100%); /* Opera11.10+ */ background: -ms-linear-gradient(top, rgba(0,0,0,0.2) 0%,rgba(0,0,0,0.1) 100%); /* IE10+ */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#33000000', endColorstr='#1a000000',GradientType=0 ); /* IE6-9 */ background: linear-gradient(top, rgba(0,0,0,0.2) 0%,rgba(0,0,0,0.1) 100%); /* W3C */ padding: 2em; } .prosper-gradient-border h2.block-title { color: #404040; } .prosper-gradient-border a:link, .prosper-gradient-border a:visited { color: #000; } /* Menu list */ prosper-menu-list .inner { border-bottom: 2px solid #b0b0b0; } .prosper-menu-list h2.block-title { background: #a9a9a9; color: #fff; font-weight: normal; margin: 0; padding: 0 10px; border-top-left-radius: 5px; border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; } .prosper-menu-list ul { background: #ff3f3f3; border: 1px solid #f3f3f3; margin: 0; padding: 0; } .prosper-menu-list ul li { background: -moz-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(0,0,0,null) 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(0,0,0,null))); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,null) 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,null) 100%); /* Opera11.10+ */ background: -ms-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,null) 100%); /* IE10+ */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#00000000',GradientType=0 ); /* IE6-9 */ background: linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,null) 100%); /* W3C */ line-height: 250%; /* 30px/12px */ list-style: none; list-style-image: none; } .prosper-menu-list ul li.leaf{ line-height: 250%; } .inner .prosper-menu-list ul li a:link, .inner .prosper-menu-list ul li a:visited, .inner .prosper-menu-list ul li .nolink { background: url(images/menu-block-leaf.png) no-repeat 5px 10px; border-bottom: 1px solid #fff; color: #222; display: block; padding: 0 10px 0 20px; } .inner .prosper-menu-list ul li.collapsed a:link, .inner .prosper-menu-list ul li.collapsed a:visited, .inner .prosper-menu-list ul li.collapsed .nolink { background: url(images/menu-block-collapsed.png) no-repeat 5px 8px; } .inner .prosper-menu-list ul li.expanded a:link, .inner .prosper-menu-list ul li.expanded a:visited, .inner .prosper-menu-list ul li.expanded .nolink { background: url(images/menu-block-expanded.png) no-repeat 5px 9px; } .prosper-menu-list ul li ul { border-top: 2px solid #e6e6e6; margin: 0; padding: 5px 0 5px 5px; } .prosper-menu-list ul li ul li { background: transparent none; line-height: 100%; padding: 5px 0; } .inner .prosper-menu-list ul li ul li a:link, .inner .prosper-menu-list ul li ul li a:visited, .inner .prosper-menu-list ul li.collapsed ul li a:link, .inner .prosper-menu-list ul li.collapsed ul li a:visited, .inner .prosper-menu-list ul li.expanded ul li a:link, .inner .prosper-menu-list ul li.expanded ul li a:visited, .inner .prosper-menu-list ul li ul li .nolink, .inner .prosper-menu-list ul li.collapsed ul li .nolink, .inner .prosper-menu-list ul li.expanded ul li .nolink { background: url(images/menu-block-leaf-2.png) no-repeat 5px 0; border-bottom: none; color: #a9a9a9; padding: 0 10px 0 20px; } .prosper-menu-list ul li ul li ul { margin: 5px 0 -10px 10px; } .inner .prosper-menu-list ul li ul li ul li a:link, .inner .prosper-menu-list ul li ul li ul li a:visited, .inner .prosper-menu-list ul li ul li.collapsed ul li a:link, .inner .prosper-menu-list ul li ul li.collapsed ul li a:visited, .inner .prosper-menu-list ul li ul li.expanded ul li a:link, .inner .prosper-menu-list ul li ul li.expanded ul li a:visited, .inner .prosper-menu-list ul li ul li ul li .nolink, .inner .prosper-menu-list ul li ul li.collapsed ul li .nolink, .inner .prosper-menu-list ul li ul li.expanded ul li .nolink { background: url(images/menu-block-leaf.png) no-repeat 5px 0; color: #a9a9a9; margin-top: -5px; padding: 0 10px 0 20px; } /* Shopping cart - light */ .prosper-shoppingcart-light h2.block-title { background: #a9a9a9; color: #fff; font-weight: normal; margin: 0; padding: 0 10px; } .prosper-shoppingcart-light .content { background: #fff; border-bottom: 2px solid #b0b0b0; border-left: 1px solid #f3f3f3; border-right: 1px solid #f3f3f3; color: #5b5b5b; padding: 5px; } .prosper-shoppingcart-light .cart-block-icon-empty, .prosper-shoppingcart-light .cart-block-icon-full { display: block; float: left; height: 11px; margin-right: 5px; padding: 10px 5px; width: 10px; } .prosper-shoppingcart-light td.cart-block-item-title a:link, .prosper-shoppingcart-light td.cart-block-item-title a:visited { color: #af0000; } .prosper-shoppingcart-light table { margin: 5px 0; } .prosper-shoppingcart-light table td { border: none; padding: 0 5px 0 0; } .prosper-shoppingcart-light #cart-block-contents ul.product-description { margin: 0 0 0 20px; } .prosper-shoppingcart-light .cart-block-summary-links ul { float: right; margin: 10px 0 5px 0; } .prosper-shoppingcart-light .cart-block-summary-links ul li { border: none; display: block; float: left; margin: 0 0 0 5px; padding: 0; } .prosper-shoppingcart-light .cart-block-summary-links ul li.cart-block-view-cart a:link, .prosper-shoppingcart-light .cart-block-summary-links ul li.cart-block-view-cart a:visited { color: #5b5b5b; } .prosper-shoppingcart-light .cart-block-summary-links ul li.cart-block-view-cart a:link, .prosper-shoppingcart-light .cart-block-summary-links ul li.cart-block-view-cart a:visited, .prosper-shoppingcart-light .cart-block-summary-links ul li.cart-block-checkout a:link, .prosper-shoppingcart-light .cart-block-summary-links ul li.cart-block-checkout a:visited { border: none; margin: 0; padding: 4px 4px; text-decoration: none; } .prosper-shoppingcart-light .cart-block-summary-links ul li.cart-block-checkout a:link, .prosper-shoppingcart-light .cart-block-summary-links ul li.cart-block-checkout a:visited { background: #a9a9a9 url(images/button-bg.png) repeat-x 50% 0; color: #fff; font-weight: bold; } /* Shopping cart - dark */ .prosper-shoppingcart-dark .inner { background: #343434; border-bottom: 1px solid #404040; border-top: 1px solid #343434; color: #a9a9a9; padding: 8px 5px 5px 5px; border-radius: 4px; -moz-border-radius: 4px; -webkit-border-radius: 4px; } .prosper-shoppingcart-dark a:link, .prosper-shoppingcart-dark a:visited, .prosper-shoppingcart-dark a:hover, .prosper-shoppingcart-dark a:active, .prosper-shoppingcart-dark a:focus { color: #fff; } .prosper-shoppingcart-dark h2.block-title { color: #f3f3f3; } .prosper-shoppingcart-dark .content { color: #d8d8d8; } .prosper-shoppingcart-dark .cart-block-icon-empty, .prosper-shoppingcart-dark .cart-block-icon-full { display: block; float: left; height: 11px; margin-right: 5px; padding: 5px; width: 10px; } .prosper-shoppingcart-dark table { margin: 0; } .prosper-shoppingcart-dark table td { border: none; padding: 0; } .prosper-shoppingcart-dark #cart-block-contents ul.product-description { margin: 0 0 0 20px; } .prosper-shoppingcart-dark .cart-block-summary-links ul { float: right; margin: 10px 0 5px 0; } .prosper-shoppingcart-dark .cart-block-summary-links ul li { border: none; display: block; float: left; margin: 0 0 0 5px; padding: 0; } .prosper-shoppingcart-dark .cart-block-summary-links ul li.cart-block-view-cart a:link, .prosper-shoppingcart-dark .cart-block-summary-links ul li.cart-block-view-cart a:visited { color: #d8d8d8; } .prosper-shoppingcart-dark .cart-block-summary-links ul li.cart-block-view-cart a:link, .prosper-shoppingcart-dark .cart-block-summary-links ul li.cart-block-view-cart a:visited, .prosper-shoppingcart-dark .cart-block-summary-links ul li.cart-block-checkout a:link, .prosper-shoppingcart-dark .cart-block-summary-links ul li.cart-block-checkout a:visited { border: none; margin: 0; padding: 4px 4px; text-decoration: none; } .prosper-shoppingcart-dark .cart-block-summary-links ul li.cart-block-checkout a:link, .prosper-shoppingcart-dark .cart-block-summary-links ul li.cart-block-checkout a:visited { background: #4e4e4e; /* Old browsers */ background: -moz-linear-gradient(top, #4e4e4e 0%, #424242 47%, #4e4e4e 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4e4e4e), color-stop(47%,#424242), color-stop(100%,#4e4e4e)); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, #4e4e4e 0%,#424242 47%,#4e4e4e 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, #4e4e4e 0%,#424242 47%,#4e4e4e 100%); /* Opera11.10+ */ background: -ms-linear-gradient(top, #4e4e4e 0%,#424242 47%,#4e4e4e 100%); /* IE10+ */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4E4E4E', endColorstr='#4E4E4E',GradientType=0 ); /* IE6-9 */ background: linear-gradient(top, #4e4e4e 0%,#424242 47%,#4e4e4e 100%); /* W3C */ color: #d8d8d8; font-weight: bold; } /* Prosper quicktabs */ .prosper-quicktabs .quicktabs_wrapper { margin: 10px 0; } .prosper-quicktabs .quicktabs_wrapper ul.quicktabs_tabs { margin: 0; padding: 0 0 20px 0; } .prosper-quicktabs .quicktabs_wrapper ul.quicktabs_tabs li { display: block; float: left; margin: 0 2px 0 0; padding: 0; } .prosper-quicktabs .quicktabs_wrapper ul.quicktabs_tabs li a:link, .prosper-quicktabs .quicktabs_wrapper ul.quicktabs_tabs li a:visited { background: #b0b0b0; border-bottom: 2px solid #ff3f3f3; border-top: 1px solid #f3f3f3; color: #fff; padding: 8px 20px; } .prosper-quicktabs .quicktabs_wrapper ul.quicktabs_tabs li.active a:link, .prosper-quicktabs .quicktabs_wrapper ul.quicktabs_tabs li.active a:visited { background: #fff; color: #000; border-bottom: none; } .prosper-quicktabs .quicktabs_main { background: #fff; border-bottom: 2px solid #b0b0b0; border-top: 1px solid #f3f3f3; margin: 4px 0; padding: 20px; } /* Prosper - Gray border around images */ .prosper-gray-border-image .inner img { border: 2px solid #b0b0b0; } /* Prosper comments - edgy */ .prosper-comments-edgy div.comment { border: none; margin: 0 0 20px 0; padding: 0; } .prosper-comments-edgy #comments .comment-wrapper div.odd, .prosper-comments-edgy #comments .comment-wrapper div.even { background: none; } .prosper-comments-edgy #comments .comment-wrapper div.comment-by-author .submitted { background: #404040; color: #a9a9a9; padding: 0 10px; } .prosper-comments-edgy #comments .comment-wrapper div.comment-by-author .submitted a:link, .prosper-comments-edgy #comments .comment-wrapper div.comment-by-author .submitted a:visited { color: #fff; } .prosper-comments-edgy .comment-wrapper .submitted { color: #9a9a9a; } .prosper-comments-edgy .comment-wrapper .content-inner h3.title, .prosper-comments-edgy .comment-wrapper .content-inner h3.title a { color: #343434; } .prosper-comments-edgy .comment-wrapper .picture img { border: 1px solid #d8d8d8; } .comment-wrapper .odd .content { border-top: 1px solid #ccc; } .prosper-comments-edgy .comment-wrapper .withpicture .withpicture-column-left { float: left; width: 25%; } .prosper-comments-edgy .comment-wrapper .withpicture .withpicture-column-right { float: right; width: 75%; } .prosper-comments-edgy .comment-wrapper .content-inner { padding: 20px; } .prosper-comments-edgy .comment-wrapper .odd .content-inner { background: #fff; border-bottom: 1px solid #b0b0b0; margin-left: 10px; } .prosper-comments-edgy .comment-wrapper .odd .comment-top-left { display: block; float: left; height: 11px; width: 10px; } .prosper-comments-edgy .comment-wrapper .even .content { border-top: 1px solid #dadada; } .prosper-comments-edgy .comment-wrapper .even .content-inner { background: #d8d8d8; border-bottom: 1px solid #b0b0b0; margin-left: 10px; } .prosper-comments-edgy .comment-wrapper .even .comment-top-left { display: block; float: left; height: 11px; width: 10px; } .prosper-comments-edgy .comment-wrapper .signature { background: #EFEFEF; border-top: 2px solid #cdcdcd; margin: 0 0 10px 0; padding: 5px 10px; } .prosper-comments-edgy .comment-wrapper .signature p { margin: 0; } .prosper-comments-edgy .comment-wrapper .links { margin: 0 -20px; padding: 5px; } .prosper-comments-edgy .comment-wrapper .links ul.links { border: none; float: right; margin: 0; padding: 0; text-align: right; width: 100%; } .prosper-comments-edgy .comment-wrapper .odd .links { border-top: 1px solid #ebebeb; } .prosper-comments-edgy .comment-wrapper .even .links { border-top: 1px solid #cdcdcd; } .prosper-comments-edgy .box .content { background: #fff; border-bottom: 2px solid #b0b0b0; padding: 20px; } .prosper-comments-edgy .box .form-item input, .prosper-comments-edgy .box .form-item select, .prosper-comments-edgy .box .form-item textarea { background: #f3f3f3; } /* Prosper comments - clean */ .prosper-comments-clean div.comment { margin: 0 0 15px 0; } .prosper-comments-clean .comment-wrapper { background: #fff; color: #a9a9a9; } .prosper-comments-clean .comment-wrapper .withpicture .withpicture-column-left { float: left; width: 25%; } .prosper-comments-clean .comment-wrapper .withpicture .withpicture-column-right { border-bottom: 1px solid #ccc; float: right; padding: 0 0 10px 0; width: 75%; } .prosper-comments-clean .comment-wrapper .odd .content { border-top: none; } .prosper-comments-clean .comment-wrapper .links ul.links { border: none; float: right; margin: 0; padding: 0; text-align: right; width: 100%; } /* Prosper Skinr styles */ .prosper-rounded-title h2.block-title, .prosper-shoppingcart-light h2.block-title, .prosper-menu-list h2.block-title { font-size: 116.67%; /* 14px/12px */ line-height: 250%; /* 30px/12px */ } .prosper-gray-rounded-plain h2.block-title, .prosper-gray-rounded-style h2.block-title { line-height: 120%; } .prosper-mediumgraybackground-bottomborder h2.block-title, .prosper-lightgraybackground-border h2.block-title, .prosper-shoppingcart-dark h2.block-title { font-size: 150%; /* 18px/12px */ } .prosper-gradient-border h2.block-title { font-size: 250%; /* 30px/12px */ } .prosper-shoppingcart-light table, .prosper-shoppingcart-dark table { font-size: 91.67%; /* 11px/12px */ } .prosper-shoppingcart-light .cart-block-summary-links ul li, .prosper-shoppingcart-dark .cart-block-summary-links ul li { font-size: 100%; /* 12px/12px */ } .prosper-comments-edgy .comment-wrapper .content-inner h3.title { font-size: 150%; /* 18px/12px */ } .prosper-comments-clean .comment-wrapper h3.title a { color: #a9a9a9; font-size: 100%; /* 12px/12px */ } /* User Menu (for header top region) -------------------------------------------------------------- */ div.user-menu{ margin-bottom: 0; } .user-menu ul.menu{ margin: 0; float: none; } .user-menu ul.menu li { float: left; list-style-image: none; list-style: none; } .user-menu ul.menu li a:link, .user-menu ul.menu li a:visited { border-left: 1px solid #343434; color: #d8d8d8; display: block; float: left; padding: 7px 10px; } .user-menu ul.menu li.last a { border-right: 1px solid #343434; } .user-menu ul.menu li a:hover, .user-menu ul.menu li a:focus { background: #a9a9a9; text-decoration: none; } .user-menu ul.menu li a.active { background: #404040; }
rtdean93/drupalengage
store.drupalengage.com/sites/all/themes/acquia_prosper/skins/acquia_prosper_default/acquia-prosper-default.css
CSS
gpl-2.0
21,101
## This file is part of Scapy ## See http://www.secdev.org/projects/scapy for more informations ## Copyright (C) Philippe Biondi <phil@secdev.org> ## This program is published under a GPLv2 license """ Direct Access dictionary. """ from error import Scapy_Exception ############################### ## Direct Access dictionnary ## ############################### def fixname(x): if x and x[0] in "0123456789": x = "n_"+x return x.translate("________________________________________________0123456789_______ABCDEFGHIJKLMNOPQRSTUVWXYZ______abcdefghijklmnopqrstuvwxyz_____________________________________________________________________________________________________________________________________") class DADict_Exception(Scapy_Exception): pass class DADict: def __init__(self, _name="DADict", **kargs): self._name=_name self.__dict__.update(kargs) def fixname(self,val): return fixname(val) def __contains__(self, val): return val in self.__dict__ def __getitem__(self, attr): return getattr(self, attr) def __setitem__(self, attr, val): return setattr(self, self.fixname(attr), val) def __iter__(self): return iter(map(lambda (x,y):y,filter(lambda (x,y):x and x[0]!="_", self.__dict__.items()))) def _show(self): for k in self.__dict__.keys(): if k and k[0] != "_": print "%10s = %r" % (k,getattr(self,k)) def __repr__(self): return "<%s/ %s>" % (self._name," ".join(filter(lambda x:x and x[0]!="_",self.__dict__.keys()))) def _branch(self, br, uniq=0): if uniq and br._name in self: raise DADict_Exception("DADict: [%s] already branched in [%s]" % (br._name, self._name)) self[br._name] = br def _my_find(self, *args, **kargs): if args and self._name not in args: return False for k in kargs: if k not in self or self[k] != kargs[k]: return False return True def _find(self, *args, **kargs): return self._recurs_find((), *args, **kargs) def _recurs_find(self, path, *args, **kargs): if self in path: return None if self._my_find(*args, **kargs): return self for o in self: if isinstance(o, DADict): p = o._recurs_find(path+(self,), *args, **kargs) if p is not None: return p return None def _find_all(self, *args, **kargs): return self._recurs_find_all((), *args, **kargs) def _recurs_find_all(self, path, *args, **kargs): r = [] if self in path: return r if self._my_find(*args, **kargs): r.append(self) for o in self: if isinstance(o, DADict): p = o._recurs_find_all(path+(self,), *args, **kargs) r += p return r def keys(self): return filter(lambda x:x and x[0]!="_", self.__dict__.keys())
enddo/smod
System/Lib/scapy/dadict.py
Python
gpl-2.0
3,052
/* * Copyright (c) 2008 Affine Systems, Inc (Michael Sullivan, Bobby Impollonia) * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Box drawing filter. Also a nice template for a filter that needs to * write in the input frame. */ #include "libavutil/colorspace.h" #include "libavutil/common.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "libavutil/parseutils.h" #include "avfilter.h" #include "formats.h" #include "internal.h" #include "video.h" enum { Y, U, V, A }; typedef struct { const AVClass *class; int x, y, w, h, thickness; char *color_str; unsigned char yuv_color[4]; int invert_color; ///< invert luma color int vsub, hsub; ///< chroma subsampling } DrawBoxContext; #define OFFSET(x) offsetof(DrawBoxContext, x) #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM static const AVOption drawbox_options[] = { { "x", "set the box top-left corner x position", OFFSET(x), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS }, { "y", "set the box top-left corner y position", OFFSET(y), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS }, { "width", "set the box width", OFFSET(w), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS }, { "w", "set the box width", OFFSET(w), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS }, { "height", "set the box height", OFFSET(h), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS }, { "h", "set the box height", OFFSET(h), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS }, { "color", "set the box edge color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str="black"}, CHAR_MIN, CHAR_MAX, FLAGS }, { "c", "set the box edge color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str="black"}, CHAR_MIN, CHAR_MAX, FLAGS }, { "thickness", "set the box maximum thickness", OFFSET(thickness), AV_OPT_TYPE_INT, {.i64=4}, 0, INT_MAX, FLAGS }, { "t", "set the box maximum thickness", OFFSET(thickness), AV_OPT_TYPE_INT, {.i64=4}, 0, INT_MAX, FLAGS }, {NULL}, }; AVFILTER_DEFINE_CLASS(drawbox); static av_cold int init(AVFilterContext *ctx, const char *args) { DrawBoxContext *drawbox = ctx->priv; uint8_t rgba_color[4]; static const char *shorthand[] = { "x", "y", "w", "h", "color", "thickness", NULL }; int ret; drawbox->class = &drawbox_class; av_opt_set_defaults(drawbox); if ((ret = av_opt_set_from_string(drawbox, args, shorthand, "=", ":")) < 0) return ret; if (!strcmp(drawbox->color_str, "invert")) drawbox->invert_color = 1; else if (av_parse_color(rgba_color, drawbox->color_str, -1, ctx) < 0) return AVERROR(EINVAL); if (!drawbox->invert_color) { drawbox->yuv_color[Y] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]); drawbox->yuv_color[U] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0); drawbox->yuv_color[V] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0); drawbox->yuv_color[A] = rgba_color[3]; } return 0; } static av_cold void uninit(AVFilterContext *ctx) { DrawBoxContext *drawbox = ctx->priv; av_opt_free(drawbox); } static int query_formats(AVFilterContext *ctx) { static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_NONE }; ff_set_common_formats(ctx, ff_make_format_list(pix_fmts)); return 0; } static int config_input(AVFilterLink *inlink) { DrawBoxContext *drawbox = inlink->dst->priv; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); drawbox->hsub = desc->log2_chroma_w; drawbox->vsub = desc->log2_chroma_h; if (drawbox->w == 0) drawbox->w = inlink->w; if (drawbox->h == 0) drawbox->h = inlink->h; av_log(inlink->dst, AV_LOG_VERBOSE, "x:%d y:%d w:%d h:%d color:0x%02X%02X%02X%02X\n", drawbox->x, drawbox->y, drawbox->w, drawbox->h, drawbox->yuv_color[Y], drawbox->yuv_color[U], drawbox->yuv_color[V], drawbox->yuv_color[A]); return 0; } static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame) { DrawBoxContext *drawbox = inlink->dst->priv; int plane, x, y, xb = drawbox->x, yb = drawbox->y; unsigned char *row[4]; for (y = FFMAX(yb, 0); y < frame->video->h && y < (yb + drawbox->h); y++) { row[0] = frame->data[0] + y * frame->linesize[0]; for (plane = 1; plane < 3; plane++) row[plane] = frame->data[plane] + frame->linesize[plane] * (y >> drawbox->vsub); if (drawbox->invert_color) { for (x = FFMAX(xb, 0); x < xb + drawbox->w && x < frame->video->w; x++) if ((y - yb < drawbox->thickness-1) || (yb + drawbox->h - y < drawbox->thickness) || (x - xb < drawbox->thickness-1) || (xb + drawbox->w - x < drawbox->thickness)) row[0][x] = 0xff - row[0][x]; } else { for (x = FFMAX(xb, 0); x < xb + drawbox->w && x < frame->video->w; x++) { double alpha = (double)drawbox->yuv_color[A] / 255; if ((y - yb < drawbox->thickness-1) || (yb + drawbox->h - y < drawbox->thickness) || (x - xb < drawbox->thickness-1) || (xb + drawbox->w - x < drawbox->thickness)) { row[0][x ] = (1 - alpha) * row[0][x ] + alpha * drawbox->yuv_color[Y]; row[1][x >> drawbox->hsub] = (1 - alpha) * row[1][x >> drawbox->hsub] + alpha * drawbox->yuv_color[U]; row[2][x >> drawbox->hsub] = (1 - alpha) * row[2][x >> drawbox->hsub] + alpha * drawbox->yuv_color[V]; } } } } return ff_filter_frame(inlink->dst->outputs[0], frame); } static const AVFilterPad avfilter_vf_drawbox_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, .config_props = config_input, .get_video_buffer = ff_null_get_video_buffer, .filter_frame = filter_frame, .min_perms = AV_PERM_WRITE | AV_PERM_READ, }, { NULL } }; static const AVFilterPad avfilter_vf_drawbox_outputs[] = { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, }, { NULL } }; AVFilter avfilter_vf_drawbox = { .name = "drawbox", .description = NULL_IF_CONFIG_SMALL("Draw a colored box on the input video."), .priv_size = sizeof(DrawBoxContext), .init = init, .uninit = uninit, .query_formats = query_formats, .inputs = avfilter_vf_drawbox_inputs, .outputs = avfilter_vf_drawbox_outputs, .priv_class = &drawbox_class, };
da-anda/xbmc
lib/ffmpeg/libavfilter/vf_drawbox.c
C
gpl-2.0
7,671
/* 3c527.c: 3Com Etherlink/MC32 driver for Linux 2.4 and 2.6. * * (c) Copyright 1998 Red Hat Software Inc * Written by Alan Cox. * Further debugging by Carl Drougge. * Initial SMP support by Felipe W Damasio <felipewd@terra.com.br> * Heavily modified by Richard Procter <rnp@paradise.net.nz> * * Based on skeleton.c written 1993-94 by Donald Becker and ne2.c * (for the MCA stuff) written by Wim Dumon. * * Thanks to 3Com for making this possible by providing me with the * documentation. * * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * */ #define DRV_NAME "3c527" #define DRV_VERSION "0.7-SMP" #define DRV_RELDATE "2003/09/21" static const char *version = DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Richard Procter <rnp@paradise.net.nz>\n"; /** * DOC: Traps for the unwary * * The diagram (Figure 1-1) and the POS summary disagree with the * "Interrupt Level" section in the manual. * * The manual contradicts itself when describing the minimum number * buffers in the 'configure lists' command. * My card accepts a buffer config of 4/4. * * Setting the SAV BP bit does not save bad packets, but * only enables RX on-card stats collection. * * The documentation in places seems to miss things. In actual fact * I've always eventually found everything is documented, it just * requires careful study. * * DOC: Theory Of Operation * * The 3com 3c527 is a 32bit MCA bus mastering adapter with a large * amount of on board intelligence that housekeeps a somewhat dumber * Intel NIC. For performance we want to keep the transmit queue deep * as the card can transmit packets while fetching others from main * memory by bus master DMA. Transmission and reception are driven by * circular buffer queues. * * The mailboxes can be used for controlling how the card traverses * its buffer rings, but are used only for inital setup in this * implementation. The exec mailbox allows a variety of commands to * be executed. Each command must complete before the next is * executed. Primarily we use the exec mailbox for controlling the * multicast lists. We have to do a certain amount of interesting * hoop jumping as the multicast list changes can occur in interrupt * state when the card has an exec command pending. We defer such * events until the command completion interrupt. * * A copy break scheme (taken from 3c59x.c) is employed whereby * received frames exceeding a configurable length are passed * directly to the higher networking layers without incuring a copy, * in what amounts to a time/space trade-off. * * The card also keeps a large amount of statistical information * on-board. In a perfect world, these could be used safely at no * cost. However, lacking information to the contrary, processing * them without races would involve so much extra complexity as to * make it unworthwhile to do so. In the end, a hybrid SW/HW * implementation was made necessary --- see mc32_update_stats(). * * DOC: Notes * * It should be possible to use two or more cards, but at this stage * only by loading two copies of the same module. * * The on-board 82586 NIC has trouble receiving multiple * back-to-back frames and so is likely to drop packets from fast * senders. **/ #include <linux/module.h> #include <linux/errno.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/if_ether.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/fcntl.h> #include <linux/interrupt.h> #include <linux/mca-legacy.h> #include <linux/ioport.h> #include <linux/in.h> #include <linux/skbuff.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/wait.h> #include <linux/ethtool.h> #include <linux/completion.h> #include <linux/bitops.h> #include <asm/semaphore.h> #include <asm/uaccess.h> #include <asm/system.h> #include <asm/io.h> #include <asm/dma.h> #include "3c527.h" MODULE_LICENSE("GPL"); /* * The name of the card. Is used for messages and in the requests for * io regions, irqs and dma channels */ static const char* cardname = DRV_NAME; /* use 0 for production, 1 for verification, >2 for debug */ #ifndef NET_DEBUG #define NET_DEBUG 2 #endif #undef DEBUG_IRQ static unsigned int mc32_debug = NET_DEBUG; /* The number of low I/O ports used by the ethercard. */ #define MC32_IO_EXTENT 8 /* As implemented, values must be a power-of-2 -- 4/8/16/32 */ #define TX_RING_LEN 32 /* Typically the card supports 37 */ #define RX_RING_LEN 8 /* " " " */ /* Copy break point, see above for details. * Setting to > 1512 effectively disables this feature. */ #define RX_COPYBREAK 200 /* Value from 3c59x.c */ /* Issue the 82586 workaround command - this is for "busy lans", but * basically means for all lans now days - has a performance (latency) * cost, but best set. */ static const int WORKAROUND_82586=1; /* Pointers to buffers and their on-card records */ struct mc32_ring_desc { volatile struct skb_header *p; struct sk_buff *skb; }; /* Information that needs to be kept for each board. */ struct mc32_local { int slot; u32 base; struct net_device_stats net_stats; volatile struct mc32_mailbox *rx_box; volatile struct mc32_mailbox *tx_box; volatile struct mc32_mailbox *exec_box; volatile struct mc32_stats *stats; /* Start of on-card statistics */ u16 tx_chain; /* Transmit list start offset */ u16 rx_chain; /* Receive list start offset */ u16 tx_len; /* Transmit list count */ u16 rx_len; /* Receive list count */ u16 xceiver_desired_state; /* HALTED or RUNNING */ u16 cmd_nonblocking; /* Thread is uninterested in command result */ u16 mc_reload_wait; /* A multicast load request is pending */ u32 mc_list_valid; /* True when the mclist is set */ struct mc32_ring_desc tx_ring[TX_RING_LEN]; /* Host Transmit ring */ struct mc32_ring_desc rx_ring[RX_RING_LEN]; /* Host Receive ring */ atomic_t tx_count; /* buffers left */ atomic_t tx_ring_head; /* index to tx en-queue end */ u16 tx_ring_tail; /* index to tx de-queue end */ u16 rx_ring_tail; /* index to rx de-queue end */ struct semaphore cmd_mutex; /* Serialises issuing of execute commands */ struct completion execution_cmd; /* Card has completed an execute command */ struct completion xceiver_cmd; /* Card has completed a tx or rx command */ }; /* The station (ethernet) address prefix, used for a sanity check. */ #define SA_ADDR0 0x02 #define SA_ADDR1 0x60 #define SA_ADDR2 0xAC struct mca_adapters_t { unsigned int id; char *name; }; static const struct mca_adapters_t mc32_adapters[] = { { 0x0041, "3COM EtherLink MC/32" }, { 0x8EF5, "IBM High Performance Lan Adapter" }, { 0x0000, NULL } }; /* Macros for ring index manipulations */ static inline u16 next_rx(u16 rx) { return (rx+1)&(RX_RING_LEN-1); }; static inline u16 prev_rx(u16 rx) { return (rx-1)&(RX_RING_LEN-1); }; static inline u16 next_tx(u16 tx) { return (tx+1)&(TX_RING_LEN-1); }; /* Index to functions, as function prototypes. */ static int mc32_probe1(struct net_device *dev, int ioaddr); static int mc32_command(struct net_device *dev, u16 cmd, void *data, int len); static int mc32_open(struct net_device *dev); static void mc32_timeout(struct net_device *dev); static int mc32_send_packet(struct sk_buff *skb, struct net_device *dev); static irqreturn_t mc32_interrupt(int irq, void *dev_id); static int mc32_close(struct net_device *dev); static struct net_device_stats *mc32_get_stats(struct net_device *dev); static void mc32_set_multicast_list(struct net_device *dev); static void mc32_reset_multicast_list(struct net_device *dev); static const struct ethtool_ops netdev_ethtool_ops; static void cleanup_card(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); unsigned slot = lp->slot; mca_mark_as_unused(slot); mca_set_adapter_name(slot, NULL); free_irq(dev->irq, dev); release_region(dev->base_addr, MC32_IO_EXTENT); } /** * mc32_probe - Search for supported boards * @unit: interface number to use * * Because MCA bus is a real bus and we can scan for cards we could do a * single scan for all boards here. Right now we use the passed in device * structure and scan for only one board. This needs fixing for modules * in particular. */ struct net_device *__init mc32_probe(int unit) { struct net_device *dev = alloc_etherdev(sizeof(struct mc32_local)); static int current_mca_slot = -1; int i; int err; if (!dev) return ERR_PTR(-ENOMEM); if (unit >= 0) sprintf(dev->name, "eth%d", unit); SET_MODULE_OWNER(dev); /* Do not check any supplied i/o locations. POS registers usually don't fail :) */ /* MCA cards have POS registers. Autodetecting MCA cards is extremely simple. Just search for the card. */ for(i = 0; (mc32_adapters[i].name != NULL); i++) { current_mca_slot = mca_find_unused_adapter(mc32_adapters[i].id, 0); if(current_mca_slot != MCA_NOTFOUND) { if(!mc32_probe1(dev, current_mca_slot)) { mca_set_adapter_name(current_mca_slot, mc32_adapters[i].name); mca_mark_as_used(current_mca_slot); err = register_netdev(dev); if (err) { cleanup_card(dev); free_netdev(dev); dev = ERR_PTR(err); } return dev; } } } free_netdev(dev); return ERR_PTR(-ENODEV); } /** * mc32_probe1 - Check a given slot for a board and test the card * @dev: Device structure to fill in * @slot: The MCA bus slot being used by this card * * Decode the slot data and configure the card structures. Having done this we * can reset the card and configure it. The card does a full self test cycle * in firmware so we have to wait for it to return and post us either a * failure case or some addresses we use to find the board internals. */ static int __init mc32_probe1(struct net_device *dev, int slot) { static unsigned version_printed; int i, err; u8 POS; u32 base; struct mc32_local *lp = netdev_priv(dev); static u16 mca_io_bases[]={ 0x7280,0x7290, 0x7680,0x7690, 0x7A80,0x7A90, 0x7E80,0x7E90 }; static u32 mca_mem_bases[]={ 0x00C0000, 0x00C4000, 0x00C8000, 0x00CC000, 0x00D0000, 0x00D4000, 0x00D8000, 0x00DC000 }; static char *failures[]={ "Processor instruction", "Processor data bus", "Processor data bus", "Processor data bus", "Adapter bus", "ROM checksum", "Base RAM", "Extended RAM", "82586 internal loopback", "82586 initialisation failure", "Adapter list configuration error" }; /* Time to play MCA games */ if (mc32_debug && version_printed++ == 0) printk(KERN_DEBUG "%s", version); printk(KERN_INFO "%s: %s found in slot %d:", dev->name, cardname, slot); POS = mca_read_stored_pos(slot, 2); if(!(POS&1)) { printk(" disabled.\n"); return -ENODEV; } /* Fill in the 'dev' fields. */ dev->base_addr = mca_io_bases[(POS>>1)&7]; dev->mem_start = mca_mem_bases[(POS>>4)&7]; POS = mca_read_stored_pos(slot, 4); if(!(POS&1)) { printk("memory window disabled.\n"); return -ENODEV; } POS = mca_read_stored_pos(slot, 5); i=(POS>>4)&3; if(i==3) { printk("invalid memory window.\n"); return -ENODEV; } i*=16384; i+=16384; dev->mem_end=dev->mem_start + i; dev->irq = ((POS>>2)&3)+9; if(!request_region(dev->base_addr, MC32_IO_EXTENT, cardname)) { printk("io 0x%3lX, which is busy.\n", dev->base_addr); return -EBUSY; } printk("io 0x%3lX irq %d mem 0x%lX (%dK)\n", dev->base_addr, dev->irq, dev->mem_start, i/1024); /* We ought to set the cache line size here.. */ /* * Go PROM browsing */ printk("%s: Address ", dev->name); /* Retrieve and print the ethernet address. */ for (i = 0; i < 6; i++) { mca_write_pos(slot, 6, i+12); mca_write_pos(slot, 7, 0); printk(" %2.2x", dev->dev_addr[i] = mca_read_pos(slot,3)); } mca_write_pos(slot, 6, 0); mca_write_pos(slot, 7, 0); POS = mca_read_stored_pos(slot, 4); if(POS&2) printk(" : BNC port selected.\n"); else printk(" : AUI port selected.\n"); POS=inb(dev->base_addr+HOST_CTRL); POS|=HOST_CTRL_ATTN|HOST_CTRL_RESET; POS&=~HOST_CTRL_INTE; outb(POS, dev->base_addr+HOST_CTRL); /* Reset adapter */ udelay(100); /* Reset off */ POS&=~(HOST_CTRL_ATTN|HOST_CTRL_RESET); outb(POS, dev->base_addr+HOST_CTRL); udelay(300); /* * Grab the IRQ */ err = request_irq(dev->irq, &mc32_interrupt, IRQF_SHARED | IRQF_SAMPLE_RANDOM, DRV_NAME, dev); if (err) { release_region(dev->base_addr, MC32_IO_EXTENT); printk(KERN_ERR "%s: unable to get IRQ %d.\n", DRV_NAME, dev->irq); goto err_exit_ports; } memset(lp, 0, sizeof(struct mc32_local)); lp->slot = slot; i=0; base = inb(dev->base_addr); while(base == 0xFF) { i++; if(i == 1000) { printk(KERN_ERR "%s: failed to boot adapter.\n", dev->name); err = -ENODEV; goto err_exit_irq; } udelay(1000); if(inb(dev->base_addr+2)&(1<<5)) base = inb(dev->base_addr); } if(base>0) { if(base < 0x0C) printk(KERN_ERR "%s: %s%s.\n", dev->name, failures[base-1], base<0x0A?" test failure":""); else printk(KERN_ERR "%s: unknown failure %d.\n", dev->name, base); err = -ENODEV; goto err_exit_irq; } base=0; for(i=0;i<4;i++) { int n=0; while(!(inb(dev->base_addr+2)&(1<<5))) { n++; udelay(50); if(n>100) { printk(KERN_ERR "%s: mailbox read fail (%d).\n", dev->name, i); err = -ENODEV; goto err_exit_irq; } } base|=(inb(dev->base_addr)<<(8*i)); } lp->exec_box=isa_bus_to_virt(dev->mem_start+base); base=lp->exec_box->data[1]<<16|lp->exec_box->data[0]; lp->base = dev->mem_start+base; lp->rx_box=isa_bus_to_virt(lp->base + lp->exec_box->data[2]); lp->tx_box=isa_bus_to_virt(lp->base + lp->exec_box->data[3]); lp->stats = isa_bus_to_virt(lp->base + lp->exec_box->data[5]); /* * Descriptor chains (card relative) */ lp->tx_chain = lp->exec_box->data[8]; /* Transmit list start offset */ lp->rx_chain = lp->exec_box->data[10]; /* Receive list start offset */ lp->tx_len = lp->exec_box->data[9]; /* Transmit list count */ lp->rx_len = lp->exec_box->data[11]; /* Receive list count */ init_MUTEX_LOCKED(&lp->cmd_mutex); init_completion(&lp->execution_cmd); init_completion(&lp->xceiver_cmd); printk("%s: Firmware Rev %d. %d RX buffers, %d TX buffers. Base of 0x%08X.\n", dev->name, lp->exec_box->data[12], lp->rx_len, lp->tx_len, lp->base); dev->open = mc32_open; dev->stop = mc32_close; dev->hard_start_xmit = mc32_send_packet; dev->get_stats = mc32_get_stats; dev->set_multicast_list = mc32_set_multicast_list; dev->tx_timeout = mc32_timeout; dev->watchdog_timeo = HZ*5; /* Board does all the work */ dev->ethtool_ops = &netdev_ethtool_ops; return 0; err_exit_irq: free_irq(dev->irq, dev); err_exit_ports: release_region(dev->base_addr, MC32_IO_EXTENT); return err; } /** * mc32_ready_poll - wait until we can feed it a command * @dev: The device to wait for * * Wait until the card becomes ready to accept a command via the * command register. This tells us nothing about the completion * status of any pending commands and takes very little time at all. */ static inline void mc32_ready_poll(struct net_device *dev) { int ioaddr = dev->base_addr; while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR)); } /** * mc32_command_nowait - send a command non blocking * @dev: The 3c527 to issue the command to * @cmd: The command word to write to the mailbox * @data: A data block if the command expects one * @len: Length of the data block * * Send a command from interrupt state. If there is a command * currently being executed then we return an error of -1. It * simply isn't viable to wait around as commands may be * slow. This can theoretically be starved on SMP, but it's hard * to see a realistic situation. We do not wait for the command * to complete --- we rely on the interrupt handler to tidy up * after us. */ static int mc32_command_nowait(struct net_device *dev, u16 cmd, void *data, int len) { struct mc32_local *lp = netdev_priv(dev); int ioaddr = dev->base_addr; int ret = -1; if (down_trylock(&lp->cmd_mutex) == 0) { lp->cmd_nonblocking=1; lp->exec_box->mbox=0; lp->exec_box->mbox=cmd; memcpy((void *)lp->exec_box->data, data, len); barrier(); /* the memcpy forgot the volatile so be sure */ /* Send the command */ mc32_ready_poll(dev); outb(1<<6, ioaddr+HOST_CMD); ret = 0; /* Interrupt handler will signal mutex on completion */ } return ret; } /** * mc32_command - send a command and sleep until completion * @dev: The 3c527 card to issue the command to * @cmd: The command word to write to the mailbox * @data: A data block if the command expects one * @len: Length of the data block * * Sends exec commands in a user context. This permits us to wait around * for the replies and also to wait for the command buffer to complete * from a previous command before we execute our command. After our * command completes we will attempt any pending multicast reload * we blocked off by hogging the exec buffer. * * You feed the card a command, you wait, it interrupts you get a * reply. All well and good. The complication arises because you use * commands for filter list changes which come in at bh level from things * like IPV6 group stuff. */ static int mc32_command(struct net_device *dev, u16 cmd, void *data, int len) { struct mc32_local *lp = netdev_priv(dev); int ioaddr = dev->base_addr; int ret = 0; down(&lp->cmd_mutex); /* * My Turn */ lp->cmd_nonblocking=0; lp->exec_box->mbox=0; lp->exec_box->mbox=cmd; memcpy((void *)lp->exec_box->data, data, len); barrier(); /* the memcpy forgot the volatile so be sure */ mc32_ready_poll(dev); outb(1<<6, ioaddr+HOST_CMD); wait_for_completion(&lp->execution_cmd); if(lp->exec_box->mbox&(1<<13)) ret = -1; up(&lp->cmd_mutex); /* * A multicast set got blocked - try it now */ if(lp->mc_reload_wait) { mc32_reset_multicast_list(dev); } return ret; } /** * mc32_start_transceiver - tell board to restart tx/rx * @dev: The 3c527 card to issue the command to * * This may be called from the interrupt state, where it is used * to restart the rx ring if the card runs out of rx buffers. * * We must first check if it's ok to (re)start the transceiver. See * mc32_close for details. */ static void mc32_start_transceiver(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); int ioaddr = dev->base_addr; /* Ignore RX overflow on device closure */ if (lp->xceiver_desired_state==HALTED) return; /* Give the card the offset to the post-EOL-bit RX descriptor */ mc32_ready_poll(dev); lp->rx_box->mbox=0; lp->rx_box->data[0]=lp->rx_ring[prev_rx(lp->rx_ring_tail)].p->next; outb(HOST_CMD_START_RX, ioaddr+HOST_CMD); mc32_ready_poll(dev); lp->tx_box->mbox=0; outb(HOST_CMD_RESTRT_TX, ioaddr+HOST_CMD); /* card ignores this on RX restart */ /* We are not interrupted on start completion */ } /** * mc32_halt_transceiver - tell board to stop tx/rx * @dev: The 3c527 card to issue the command to * * We issue the commands to halt the card's transceiver. In fact, * after some experimenting we now simply tell the card to * suspend. When issuing aborts occasionally odd things happened. * * We then sleep until the card has notified us that both rx and * tx have been suspended. */ static void mc32_halt_transceiver(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); int ioaddr = dev->base_addr; mc32_ready_poll(dev); lp->rx_box->mbox=0; outb(HOST_CMD_SUSPND_RX, ioaddr+HOST_CMD); wait_for_completion(&lp->xceiver_cmd); mc32_ready_poll(dev); lp->tx_box->mbox=0; outb(HOST_CMD_SUSPND_TX, ioaddr+HOST_CMD); wait_for_completion(&lp->xceiver_cmd); } /** * mc32_load_rx_ring - load the ring of receive buffers * @dev: 3c527 to build the ring for * * This initalises the on-card and driver datastructures to * the point where mc32_start_transceiver() can be called. * * The card sets up the receive ring for us. We are required to use the * ring it provides, although the size of the ring is configurable. * * We allocate an sk_buff for each ring entry in turn and * initalise its house-keeping info. At the same time, we read * each 'next' pointer in our rx_ring array. This reduces slow * shared-memory reads and makes it easy to access predecessor * descriptors. * * We then set the end-of-list bit for the last entry so that the * card will know when it has run out of buffers. */ static int mc32_load_rx_ring(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); int i; u16 rx_base; volatile struct skb_header *p; rx_base=lp->rx_chain; for(i=0; i<RX_RING_LEN; i++) { lp->rx_ring[i].skb=alloc_skb(1532, GFP_KERNEL); if (lp->rx_ring[i].skb==NULL) { for (;i>=0;i--) kfree_skb(lp->rx_ring[i].skb); return -ENOBUFS; } skb_reserve(lp->rx_ring[i].skb, 18); p=isa_bus_to_virt(lp->base+rx_base); p->control=0; p->data=isa_virt_to_bus(lp->rx_ring[i].skb->data); p->status=0; p->length=1532; lp->rx_ring[i].p=p; rx_base=p->next; } lp->rx_ring[i-1].p->control |= CONTROL_EOL; lp->rx_ring_tail=0; return 0; } /** * mc32_flush_rx_ring - free the ring of receive buffers * @lp: Local data of 3c527 to flush the rx ring of * * Free the buffer for each ring slot. This may be called * before mc32_load_rx_ring(), eg. on error in mc32_open(). * Requires rx skb pointers to point to a valid skb, or NULL. */ static void mc32_flush_rx_ring(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); int i; for(i=0; i < RX_RING_LEN; i++) { if (lp->rx_ring[i].skb) { dev_kfree_skb(lp->rx_ring[i].skb); lp->rx_ring[i].skb = NULL; } lp->rx_ring[i].p=NULL; } } /** * mc32_load_tx_ring - load transmit ring * @dev: The 3c527 card to issue the command to * * This sets up the host transmit data-structures. * * First, we obtain from the card it's current postion in the tx * ring, so that we will know where to begin transmitting * packets. * * Then, we read the 'next' pointers from the on-card tx ring into * our tx_ring array to reduce slow shared-mem reads. Finally, we * intitalise the tx house keeping variables. * */ static void mc32_load_tx_ring(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); volatile struct skb_header *p; int i; u16 tx_base; tx_base=lp->tx_box->data[0]; for(i=0 ; i<TX_RING_LEN ; i++) { p=isa_bus_to_virt(lp->base+tx_base); lp->tx_ring[i].p=p; lp->tx_ring[i].skb=NULL; tx_base=p->next; } /* -1 so that tx_ring_head cannot "lap" tx_ring_tail */ /* see mc32_tx_ring */ atomic_set(&lp->tx_count, TX_RING_LEN-1); atomic_set(&lp->tx_ring_head, 0); lp->tx_ring_tail=0; } /** * mc32_flush_tx_ring - free transmit ring * @lp: Local data of 3c527 to flush the tx ring of * * If the ring is non-empty, zip over the it, freeing any * allocated skb_buffs. The tx ring house-keeping variables are * then reset. Requires rx skb pointers to point to a valid skb, * or NULL. */ static void mc32_flush_tx_ring(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); int i; for (i=0; i < TX_RING_LEN; i++) { if (lp->tx_ring[i].skb) { dev_kfree_skb(lp->tx_ring[i].skb); lp->tx_ring[i].skb = NULL; } } atomic_set(&lp->tx_count, 0); atomic_set(&lp->tx_ring_head, 0); lp->tx_ring_tail=0; } /** * mc32_open - handle 'up' of card * @dev: device to open * * The user is trying to bring the card into ready state. This requires * a brief dialogue with the card. Firstly we enable interrupts and then * 'indications'. Without these enabled the card doesn't bother telling * us what it has done. This had me puzzled for a week. * * We configure the number of card descriptors, then load the network * address and multicast filters. Turn on the workaround mode. This * works around a bug in the 82586 - it asks the firmware to do * so. It has a performance (latency) hit but is needed on busy * [read most] lans. We load the ring with buffers then we kick it * all off. */ static int mc32_open(struct net_device *dev) { int ioaddr = dev->base_addr; struct mc32_local *lp = netdev_priv(dev); u8 one=1; u8 regs; u16 descnumbuffs[2] = {TX_RING_LEN, RX_RING_LEN}; /* * Interrupts enabled */ regs=inb(ioaddr+HOST_CTRL); regs|=HOST_CTRL_INTE; outb(regs, ioaddr+HOST_CTRL); /* * Allow ourselves to issue commands */ up(&lp->cmd_mutex); /* * Send the indications on command */ mc32_command(dev, 4, &one, 2); /* * Poke it to make sure it's really dead. */ mc32_halt_transceiver(dev); mc32_flush_tx_ring(dev); /* * Ask card to set up on-card descriptors to our spec */ if(mc32_command(dev, 8, descnumbuffs, 4)) { printk("%s: %s rejected our buffer configuration!\n", dev->name, cardname); mc32_close(dev); return -ENOBUFS; } /* Report new configuration */ mc32_command(dev, 6, NULL, 0); lp->tx_chain = lp->exec_box->data[8]; /* Transmit list start offset */ lp->rx_chain = lp->exec_box->data[10]; /* Receive list start offset */ lp->tx_len = lp->exec_box->data[9]; /* Transmit list count */ lp->rx_len = lp->exec_box->data[11]; /* Receive list count */ /* Set Network Address */ mc32_command(dev, 1, dev->dev_addr, 6); /* Set the filters */ mc32_set_multicast_list(dev); if (WORKAROUND_82586) { u16 zero_word=0; mc32_command(dev, 0x0D, &zero_word, 2); /* 82586 bug workaround on */ } mc32_load_tx_ring(dev); if(mc32_load_rx_ring(dev)) { mc32_close(dev); return -ENOBUFS; } lp->xceiver_desired_state = RUNNING; /* And finally, set the ball rolling... */ mc32_start_transceiver(dev); netif_start_queue(dev); return 0; } /** * mc32_timeout - handle a timeout from the network layer * @dev: 3c527 that timed out * * Handle a timeout on transmit from the 3c527. This normally means * bad things as the hardware handles cable timeouts and mess for * us. * */ static void mc32_timeout(struct net_device *dev) { printk(KERN_WARNING "%s: transmit timed out?\n", dev->name); /* Try to restart the adaptor. */ netif_wake_queue(dev); } /** * mc32_send_packet - queue a frame for transmit * @skb: buffer to transmit * @dev: 3c527 to send it out of * * Transmit a buffer. This normally means throwing the buffer onto * the transmit queue as the queue is quite large. If the queue is * full then we set tx_busy and return. Once the interrupt handler * gets messages telling it to reclaim transmit queue entries, we will * clear tx_busy and the kernel will start calling this again. * * We do not disable interrupts or acquire any locks; this can * run concurrently with mc32_tx_ring(), and the function itself * is serialised at a higher layer. However, similarly for the * card itself, we must ensure that we update tx_ring_head only * after we've established a valid packet on the tx ring (and * before we let the card "see" it, to prevent it racing with the * irq handler). * */ static int mc32_send_packet(struct sk_buff *skb, struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); u32 head = atomic_read(&lp->tx_ring_head); volatile struct skb_header *p, *np; netif_stop_queue(dev); if(atomic_read(&lp->tx_count)==0) { return 1; } if (skb_padto(skb, ETH_ZLEN)) { netif_wake_queue(dev); return 0; } atomic_dec(&lp->tx_count); /* P is the last sending/sent buffer as a pointer */ p=lp->tx_ring[head].p; head = next_tx(head); /* NP is the buffer we will be loading */ np=lp->tx_ring[head].p; /* We will need this to flush the buffer out */ lp->tx_ring[head].skb=skb; np->length = unlikely(skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len; np->data = isa_virt_to_bus(skb->data); np->status = 0; np->control = CONTROL_EOP | CONTROL_EOL; wmb(); /* * The new frame has been setup; we can now * let the interrupt handler and card "see" it */ atomic_set(&lp->tx_ring_head, head); p->control &= ~CONTROL_EOL; netif_wake_queue(dev); return 0; } /** * mc32_update_stats - pull off the on board statistics * @dev: 3c527 to service * * * Query and reset the on-card stats. There's the small possibility * of a race here, which would result in an underestimation of * actual errors. As such, we'd prefer to keep all our stats * collection in software. As a rule, we do. However it can't be * used for rx errors and collisions as, by default, the card discards * bad rx packets. * * Setting the SAV BP in the rx filter command supposedly * stops this behaviour. However, testing shows that it only seems to * enable the collation of on-card rx statistics --- the driver * never sees an RX descriptor with an error status set. * */ static void mc32_update_stats(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); volatile struct mc32_stats *st = lp->stats; u32 rx_errors=0; rx_errors+=lp->net_stats.rx_crc_errors +=st->rx_crc_errors; st->rx_crc_errors=0; rx_errors+=lp->net_stats.rx_fifo_errors +=st->rx_overrun_errors; st->rx_overrun_errors=0; rx_errors+=lp->net_stats.rx_frame_errors +=st->rx_alignment_errors; st->rx_alignment_errors=0; rx_errors+=lp->net_stats.rx_length_errors+=st->rx_tooshort_errors; st->rx_tooshort_errors=0; rx_errors+=lp->net_stats.rx_missed_errors+=st->rx_outofresource_errors; st->rx_outofresource_errors=0; lp->net_stats.rx_errors=rx_errors; /* Number of packets which saw one collision */ lp->net_stats.collisions+=st->dataC[10]; st->dataC[10]=0; /* Number of packets which saw 2--15 collisions */ lp->net_stats.collisions+=st->dataC[11]; st->dataC[11]=0; } /** * mc32_rx_ring - process the receive ring * @dev: 3c527 that needs its receive ring processing * * * We have received one or more indications from the card that a * receive has completed. The buffer ring thus contains dirty * entries. We walk the ring by iterating over the circular rx_ring * array, starting at the next dirty buffer (which happens to be the * one we finished up at last time around). * * For each completed packet, we will either copy it and pass it up * the stack or, if the packet is near MTU sized, we allocate * another buffer and flip the old one up the stack. * * We must succeed in keeping a buffer on the ring. If necessary we * will toss a received packet rather than lose a ring entry. Once * the first uncompleted descriptor is found, we move the * End-Of-List bit to include the buffers just processed. * */ static void mc32_rx_ring(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); volatile struct skb_header *p; u16 rx_ring_tail; u16 rx_old_tail; int x=0; rx_old_tail = rx_ring_tail = lp->rx_ring_tail; do { p=lp->rx_ring[rx_ring_tail].p; if(!(p->status & (1<<7))) { /* Not COMPLETED */ break; } if(p->status & (1<<6)) /* COMPLETED_OK */ { u16 length=p->length; struct sk_buff *skb; struct sk_buff *newskb; /* Try to save time by avoiding a copy on big frames */ if ((length > RX_COPYBREAK) && ((newskb=dev_alloc_skb(1532)) != NULL)) { skb=lp->rx_ring[rx_ring_tail].skb; skb_put(skb, length); skb_reserve(newskb,18); lp->rx_ring[rx_ring_tail].skb=newskb; p->data=isa_virt_to_bus(newskb->data); } else { skb=dev_alloc_skb(length+2); if(skb==NULL) { lp->net_stats.rx_dropped++; goto dropped; } skb_reserve(skb,2); memcpy(skb_put(skb, length), lp->rx_ring[rx_ring_tail].skb->data, length); } skb->protocol=eth_type_trans(skb,dev); skb->dev=dev; dev->last_rx = jiffies; lp->net_stats.rx_packets++; lp->net_stats.rx_bytes += length; netif_rx(skb); } dropped: p->length = 1532; p->status = 0; rx_ring_tail=next_rx(rx_ring_tail); } while(x++<48); /* If there was actually a frame to be processed, place the EOL bit */ /* at the descriptor prior to the one to be filled next */ if (rx_ring_tail != rx_old_tail) { lp->rx_ring[prev_rx(rx_ring_tail)].p->control |= CONTROL_EOL; lp->rx_ring[prev_rx(rx_old_tail)].p->control &= ~CONTROL_EOL; lp->rx_ring_tail=rx_ring_tail; } } /** * mc32_tx_ring - process completed transmits * @dev: 3c527 that needs its transmit ring processing * * * This operates in a similar fashion to mc32_rx_ring. We iterate * over the transmit ring. For each descriptor which has been * processed by the card, we free its associated buffer and note * any errors. This continues until the transmit ring is emptied * or we reach a descriptor that hasn't yet been processed by the * card. * */ static void mc32_tx_ring(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); volatile struct skb_header *np; /* * We rely on head==tail to mean 'queue empty'. * This is why lp->tx_count=TX_RING_LEN-1: in order to prevent * tx_ring_head wrapping to tail and confusing a 'queue empty' * condition with 'queue full' */ while (lp->tx_ring_tail != atomic_read(&lp->tx_ring_head)) { u16 t; t=next_tx(lp->tx_ring_tail); np=lp->tx_ring[t].p; if(!(np->status & (1<<7))) { /* Not COMPLETED */ break; } lp->net_stats.tx_packets++; if(!(np->status & (1<<6))) /* Not COMPLETED_OK */ { lp->net_stats.tx_errors++; switch(np->status&0x0F) { case 1: lp->net_stats.tx_aborted_errors++; break; /* Max collisions */ case 2: lp->net_stats.tx_fifo_errors++; break; case 3: lp->net_stats.tx_carrier_errors++; break; case 4: lp->net_stats.tx_window_errors++; break; /* CTS Lost */ case 5: lp->net_stats.tx_aborted_errors++; break; /* Transmit timeout */ } } /* Packets are sent in order - this is basically a FIFO queue of buffers matching the card ring */ lp->net_stats.tx_bytes+=lp->tx_ring[t].skb->len; dev_kfree_skb_irq(lp->tx_ring[t].skb); lp->tx_ring[t].skb=NULL; atomic_inc(&lp->tx_count); netif_wake_queue(dev); lp->tx_ring_tail=t; } } /** * mc32_interrupt - handle an interrupt from a 3c527 * @irq: Interrupt number * @dev_id: 3c527 that requires servicing * @regs: Registers (unused) * * * An interrupt is raised whenever the 3c527 writes to the command * register. This register contains the message it wishes to send us * packed into a single byte field. We keep reading status entries * until we have processed all the control items, but simply count * transmit and receive reports. When all reports are in we empty the * transceiver rings as appropriate. This saves the overhead of * multiple command requests. * * Because MCA is level-triggered, we shouldn't miss indications. * Therefore, we needn't ask the card to suspend interrupts within * this handler. The card receives an implicit acknowledgment of the * current interrupt when we read the command register. * */ static irqreturn_t mc32_interrupt(int irq, void *dev_id) { struct net_device *dev = dev_id; struct mc32_local *lp; int ioaddr, status, boguscount = 0; int rx_event = 0; int tx_event = 0; ioaddr = dev->base_addr; lp = netdev_priv(dev); /* See whats cooking */ while((inb(ioaddr+HOST_STATUS)&HOST_STATUS_CWR) && boguscount++<2000) { status=inb(ioaddr+HOST_CMD); #ifdef DEBUG_IRQ printk("Status TX%d RX%d EX%d OV%d BC%d\n", (status&7), (status>>3)&7, (status>>6)&1, (status>>7)&1, boguscount); #endif switch(status&7) { case 0: break; case 6: /* TX fail */ case 2: /* TX ok */ tx_event = 1; break; case 3: /* Halt */ case 4: /* Abort */ complete(&lp->xceiver_cmd); break; default: printk("%s: strange tx ack %d\n", dev->name, status&7); } status>>=3; switch(status&7) { case 0: break; case 2: /* RX */ rx_event=1; break; case 3: /* Halt */ case 4: /* Abort */ complete(&lp->xceiver_cmd); break; case 6: /* Out of RX buffers stat */ /* Must restart rx */ lp->net_stats.rx_dropped++; mc32_rx_ring(dev); mc32_start_transceiver(dev); break; default: printk("%s: strange rx ack %d\n", dev->name, status&7); } status>>=3; if(status&1) { /* * No thread is waiting: we need to tidy * up ourself. */ if (lp->cmd_nonblocking) { up(&lp->cmd_mutex); if (lp->mc_reload_wait) mc32_reset_multicast_list(dev); } else complete(&lp->execution_cmd); } if(status&2) { /* * We get interrupted once per * counter that is about to overflow. */ mc32_update_stats(dev); } } /* * Process the transmit and receive rings */ if(tx_event) mc32_tx_ring(dev); if(rx_event) mc32_rx_ring(dev); return IRQ_HANDLED; } /** * mc32_close - user configuring the 3c527 down * @dev: 3c527 card to shut down * * The 3c527 is a bus mastering device. We must be careful how we * shut it down. It may also be running shared interrupt so we have * to be sure to silence it properly * * We indicate that the card is closing to the rest of the * driver. Otherwise, it is possible that the card may run out * of receive buffers and restart the transceiver while we're * trying to close it. * * We abort any receive and transmits going on and then wait until * any pending exec commands have completed in other code threads. * In theory we can't get here while that is true, in practice I am * paranoid * * We turn off the interrupt enable for the board to be sure it can't * intefere with other devices. */ static int mc32_close(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); int ioaddr = dev->base_addr; u8 regs; u16 one=1; lp->xceiver_desired_state = HALTED; netif_stop_queue(dev); /* * Send the indications on command (handy debug check) */ mc32_command(dev, 4, &one, 2); /* Shut down the transceiver */ mc32_halt_transceiver(dev); /* Ensure we issue no more commands beyond this point */ down(&lp->cmd_mutex); /* Ok the card is now stopping */ regs=inb(ioaddr+HOST_CTRL); regs&=~HOST_CTRL_INTE; outb(regs, ioaddr+HOST_CTRL); mc32_flush_rx_ring(dev); mc32_flush_tx_ring(dev); mc32_update_stats(dev); return 0; } /** * mc32_get_stats - hand back stats to network layer * @dev: The 3c527 card to handle * * We've collected all the stats we can in software already. Now * it's time to update those kept on-card and return the lot. * */ static struct net_device_stats *mc32_get_stats(struct net_device *dev) { struct mc32_local *lp = netdev_priv(dev); mc32_update_stats(dev); return &lp->net_stats; } /** * do_mc32_set_multicast_list - attempt to update multicasts * @dev: 3c527 device to load the list on * @retry: indicates this is not the first call. * * * Actually set or clear the multicast filter for this adaptor. The * locking issues are handled by this routine. We have to track * state as it may take multiple calls to get the command sequence * completed. We just keep trying to schedule the loads until we * manage to process them all. * * num_addrs == -1 Promiscuous mode, receive all packets * * num_addrs == 0 Normal mode, clear multicast list * * num_addrs > 0 Multicast mode, receive normal and MC packets, * and do best-effort filtering. * * See mc32_update_stats() regards setting the SAV BP bit. * */ static void do_mc32_set_multicast_list(struct net_device *dev, int retry) { struct mc32_local *lp = netdev_priv(dev); u16 filt = (1<<2); /* Save Bad Packets, for stats purposes */ if (dev->flags&IFF_PROMISC) /* Enable promiscuous mode */ filt |= 1; else if((dev->flags&IFF_ALLMULTI) || dev->mc_count > 10) { dev->flags|=IFF_PROMISC; filt |= 1; } else if(dev->mc_count) { unsigned char block[62]; unsigned char *bp; struct dev_mc_list *dmc=dev->mc_list; int i; if(retry==0) lp->mc_list_valid = 0; if(!lp->mc_list_valid) { block[1]=0; block[0]=dev->mc_count; bp=block+2; for(i=0;i<dev->mc_count;i++) { memcpy(bp, dmc->dmi_addr, 6); bp+=6; dmc=dmc->next; } if(mc32_command_nowait(dev, 2, block, 2+6*dev->mc_count)==-1) { lp->mc_reload_wait = 1; return; } lp->mc_list_valid=1; } } if(mc32_command_nowait(dev, 0, &filt, 2)==-1) { lp->mc_reload_wait = 1; } else { lp->mc_reload_wait = 0; } } /** * mc32_set_multicast_list - queue multicast list update * @dev: The 3c527 to use * * Commence loading the multicast list. This is called when the kernel * changes the lists. It will override any pending list we are trying to * load. */ static void mc32_set_multicast_list(struct net_device *dev) { do_mc32_set_multicast_list(dev,0); } /** * mc32_reset_multicast_list - reset multicast list * @dev: The 3c527 to use * * Attempt the next step in loading the multicast lists. If this attempt * fails to complete then it will be scheduled and this function called * again later from elsewhere. */ static void mc32_reset_multicast_list(struct net_device *dev) { do_mc32_set_multicast_list(dev,1); } static void netdev_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) { strcpy(info->driver, DRV_NAME); strcpy(info->version, DRV_VERSION); sprintf(info->bus_info, "MCA 0x%lx", dev->base_addr); } static u32 netdev_get_msglevel(struct net_device *dev) { return mc32_debug; } static void netdev_set_msglevel(struct net_device *dev, u32 level) { mc32_debug = level; } static const struct ethtool_ops netdev_ethtool_ops = { .get_drvinfo = netdev_get_drvinfo, .get_msglevel = netdev_get_msglevel, .set_msglevel = netdev_set_msglevel, }; #ifdef MODULE static struct net_device *this_device; /** * init_module - entry point * * Probe and locate a 3c527 card. This really should probe and locate * all the 3c527 cards in the machine not just one of them. Yes you can * insmod multiple modules for now but it's a hack. */ int __init init_module(void) { this_device = mc32_probe(-1); if (IS_ERR(this_device)) return PTR_ERR(this_device); return 0; } /** * cleanup_module - free resources for an unload * * Unloading time. We release the MCA bus resources and the interrupt * at which point everything is ready to unload. The card must be stopped * at this point or we would not have been called. When we unload we * leave the card stopped but not totally shut down. When the card is * initialized it must be rebooted or the rings reloaded before any * transmit operations are allowed to start scribbling into memory. */ void __exit cleanup_module(void) { unregister_netdev(this_device); cleanup_card(this_device); free_netdev(this_device); } #endif /* MODULE */
pigworlds/asuswrttest
release/src-ra/linux/linux-2.6.21.x/drivers/net/3c527.c
C
gpl-2.0
43,201
/* * flushb.c --- Hides system-dependent information for both syncing a * device to disk and to flush any buffers from disk cache. * * Copyright (C) 2000 Theodore Ts'o. * * %Begin-Header% * This file may be redistributed under the terms of the GNU Library * General Public License, version 2. * %End-Header% */ #include "config.h" #include <stdio.h> #if HAVE_ERRNO_H #include <errno.h> #endif #if HAVE_UNISTD_H #include <unistd.h> #endif #if HAVE_SYS_IOCTL_H #include <sys/ioctl.h> #endif #if HAVE_SYS_MOUNT_H #include <sys/param.h> #include <sys/mount.h> /* This may define BLKFLSBUF */ #endif #include "ext2_fs.h" #include "ext2fs.h" /* * For Linux, define BLKFLSBUF and FDFLUSH if necessary, since * not all portable header file does so for us. This really should be * fixed in the glibc header files. (Recent glibcs appear to define * BLKFLSBUF in sys/mount.h, but FDFLUSH still doesn't seem to be * defined anywhere portable.) Until then.... */ #ifdef __linux__ #ifndef BLKFLSBUF #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ #endif #ifndef FDFLUSH #define FDFLUSH _IO(2,0x4b) /* flush floppy disk */ #endif #endif /* * This function will sync a device/file, and optionally attempt to * flush the buffer cache. The latter is basically only useful for * system benchmarks and for torturing systems in burn-in tests. :) */ errcode_t ext2fs_sync_device(int fd, int flushb) { /* * We always sync the device in case we're running on old * kernels for which we can lose data if we don't. (There * still is a race condition for those kernels, but this * reduces it greatly.) */ if (fsync (fd) == -1) return errno; if (flushb) { #ifdef BLKFLSBUF if (ioctl (fd, BLKFLSBUF, 0) == 0) return 0; #elif defined(__linux__) #warning BLKFLSBUF not defined #endif #ifdef FDFLUSH ioctl (fd, FDFLUSH, 0); /* In case this is a floppy */ #elif defined(__linux__) #warning FDFLUSH not defined #endif } return 0; }
SanDisk-Open-Source/SSD_Dashboard
uefi/userspace/e2fsprogs-1.42.5/lib/ext2fs/flushb.c
C
gpl-2.0
1,967
/** * udc.c - Core UDC Framework * * Copyright (C) 2010 Texas Instruments * Author: Felipe Balbi <balbi@ti.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 of * the License as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/device.h> #include <linux/list.h> #include <linux/err.h> #include <linux/dma-mapping.h> #include <linux/workqueue.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> /** * struct usb_udc - describes one usb device controller * @driver - the gadget driver pointer. For use by the class code * @dev - the child device to the actual controller * @gadget - the gadget. For use by the class code * @list - for use by the udc class driver * * This represents the internal data structure which is used by the UDC-class * to hold information about udc driver and gadget together. */ struct usb_udc { struct usb_gadget_driver *driver; struct usb_gadget *gadget; struct device dev; struct list_head list; }; static struct class *udc_class; static LIST_HEAD(udc_list); static DEFINE_MUTEX(udc_lock); /* ------------------------------------------------------------------------- */ #ifdef CONFIG_HAS_DMA int usb_gadget_map_request(struct usb_gadget *gadget, struct usb_request *req, int is_in) { if (req->length == 0) return 0; if (req->num_sgs) { int mapped; mapped = dma_map_sg(&gadget->dev, req->sg, req->num_sgs, is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); if (mapped == 0) { dev_err(&gadget->dev, "failed to map SGs\n"); return -EFAULT; } req->num_mapped_sgs = mapped; } else { req->dma = dma_map_single(&gadget->dev, req->buf, req->length, is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); if (dma_mapping_error(&gadget->dev, req->dma)) { dev_err(&gadget->dev, "failed to map buffer\n"); return -EFAULT; } } return 0; } EXPORT_SYMBOL_GPL(usb_gadget_map_request); void usb_gadget_unmap_request(struct usb_gadget *gadget, struct usb_request *req, int is_in) { if (req->length == 0) return; if (req->num_mapped_sgs) { dma_unmap_sg(&gadget->dev, req->sg, req->num_mapped_sgs, is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); req->num_mapped_sgs = 0; } else { dma_unmap_single(&gadget->dev, req->dma, req->length, is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); } } EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); #endif /* CONFIG_HAS_DMA */ /* ------------------------------------------------------------------------- */ static void usb_gadget_state_work(struct work_struct *work) { struct usb_gadget *gadget = work_to_gadget(work); sysfs_notify(&gadget->dev.kobj, NULL, "state"); } void usb_gadget_set_state(struct usb_gadget *gadget, enum usb_device_state state) { gadget->state = state; schedule_work(&gadget->work); } EXPORT_SYMBOL_GPL(usb_gadget_set_state); /* ------------------------------------------------------------------------- */ /** * usb_gadget_udc_start - tells usb device controller to start up * @gadget: The gadget we want to get started * @driver: The driver we want to bind to @gadget * * This call is issued by the UDC Class driver when it's about * to register a gadget driver to the device controller, before * calling gadget driver's bind() method. * * It allows the controller to be powered off until strictly * necessary to have it powered on. * * Returns zero on success, else negative errno. */ static inline int usb_gadget_udc_start(struct usb_gadget *gadget, struct usb_gadget_driver *driver) { return gadget->ops->udc_start(gadget, driver); } /** * usb_gadget_udc_stop - tells usb device controller we don't need it anymore * @gadget: The device we want to stop activity * @driver: The driver to unbind from @gadget * * This call is issued by the UDC Class driver after calling * gadget driver's unbind() method. * * The details are implementation specific, but it can go as * far as powering off UDC completely and disable its data * line pullups. */ static inline void usb_gadget_udc_stop(struct usb_gadget *gadget, struct usb_gadget_driver *driver) { gadget->ops->udc_stop(gadget, driver); } /** * usb_udc_release - release the usb_udc struct * @dev: the dev member within usb_udc * * This is called by driver's core in order to free memory once the last * reference is released. */ static void usb_udc_release(struct device *dev) { struct usb_udc *udc; udc = container_of(dev, struct usb_udc, dev); dev_dbg(dev, "releasing '%s'\n", dev_name(dev)); kfree(udc); } static const struct attribute_group *usb_udc_attr_groups[]; static void usb_udc_nop_release(struct device *dev) { dev_vdbg(dev, "%s\n", __func__); } /** * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list * @parent: the parent device to this udc. Usually the controller driver's * device. * @gadget: the gadget to be added to the list. * @release: a gadget release function. * * Returns zero on success, negative errno otherwise. */ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, void (*release)(struct device *dev)) { struct usb_udc *udc; int ret = -ENOMEM; udc = kzalloc(sizeof(*udc), GFP_KERNEL); if (!udc) goto err1; dev_set_name(&gadget->dev, "gadget"); INIT_WORK(&gadget->work, usb_gadget_state_work); gadget->dev.parent = parent; #ifdef CONFIG_HAS_DMA dma_set_coherent_mask(&gadget->dev, parent->coherent_dma_mask); gadget->dev.dma_parms = parent->dma_parms; gadget->dev.dma_mask = parent->dma_mask; #endif if (release) gadget->dev.release = release; else gadget->dev.release = usb_udc_nop_release; ret = device_register(&gadget->dev); if (ret) goto err2; device_initialize(&udc->dev); udc->dev.release = usb_udc_release; udc->dev.class = udc_class; udc->dev.groups = usb_udc_attr_groups; udc->dev.parent = parent; ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); if (ret) goto err3; udc->gadget = gadget; mutex_lock(&udc_lock); list_add_tail(&udc->list, &udc_list); ret = device_add(&udc->dev); if (ret) goto err4; usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); mutex_unlock(&udc_lock); return 0; err4: list_del(&udc->list); mutex_unlock(&udc_lock); err3: put_device(&udc->dev); err2: put_device(&gadget->dev); kfree(udc); err1: return ret; } EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); /** * usb_add_gadget_udc - adds a new gadget to the udc class driver list * @parent: the parent device to this udc. Usually the controller * driver's device. * @gadget: the gadget to be added to the list * * Returns zero on success, negative errno otherwise. */ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) { return usb_add_gadget_udc_release(parent, gadget, NULL); } EXPORT_SYMBOL_GPL(usb_add_gadget_udc); static void usb_gadget_remove_driver(struct usb_udc *udc) { dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n", udc->gadget->name); kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); usb_gadget_disconnect(udc->gadget); udc->driver->disconnect(udc->gadget); udc->driver->unbind(udc->gadget); usb_gadget_udc_stop(udc->gadget, NULL); udc->driver = NULL; udc->dev.driver = NULL; udc->gadget->dev.driver = NULL; } /** * usb_del_gadget_udc - deletes @udc from udc_list * @gadget: the gadget to be removed. * * This, will call usb_gadget_unregister_driver() if * the @udc is still busy. */ void usb_del_gadget_udc(struct usb_gadget *gadget) { struct usb_udc *udc = NULL; mutex_lock(&udc_lock); list_for_each_entry(udc, &udc_list, list) if (udc->gadget == gadget) goto found; dev_err(gadget->dev.parent, "gadget not registered.\n"); mutex_unlock(&udc_lock); return; found: dev_vdbg(gadget->dev.parent, "unregistering gadget\n"); list_del(&udc->list); mutex_unlock(&udc_lock); if (udc->driver) usb_gadget_remove_driver(udc); kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); flush_work(&gadget->work); device_unregister(&udc->dev); device_unregister(&gadget->dev); } EXPORT_SYMBOL_GPL(usb_del_gadget_udc); /* ------------------------------------------------------------------------- */ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver) { int ret; dev_dbg(&udc->dev, "registering UDC driver [%s]\n", driver->function); udc->driver = driver; udc->dev.driver = &driver->driver; udc->gadget->dev.driver = &driver->driver; ret = driver->bind(udc->gadget, driver); if (ret) goto err1; ret = usb_gadget_udc_start(udc->gadget, driver); if (ret) { driver->unbind(udc->gadget); goto err1; } /* * HACK: The Android gadget driver disconnects the gadget * on bind and expects the gadget to stay disconnected until * it calls usb_gadget_connect when userspace is ready. Remove * the call to usb_gadget_connect bellow to avoid enabling the * pullup before userspace is ready. * * usb_gadget_connect(udc->gadget); */ kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); return 0; err1: if (ret != -EISNAM) dev_err(&udc->dev, "failed to start %s: %d\n", udc->driver->function, ret); udc->driver = NULL; udc->dev.driver = NULL; udc->gadget->dev.driver = NULL; return ret; } int udc_attach_driver(const char *name, struct usb_gadget_driver *driver) { struct usb_udc *udc = NULL; int ret = -ENODEV; mutex_lock(&udc_lock); list_for_each_entry(udc, &udc_list, list) { ret = strcmp(name, dev_name(&udc->dev)); if (!ret) break; } if (ret) { ret = -ENODEV; goto out; } if (udc->driver) { ret = -EBUSY; goto out; } ret = udc_bind_to_driver(udc, driver); out: mutex_unlock(&udc_lock); return ret; } EXPORT_SYMBOL_GPL(udc_attach_driver); int usb_gadget_probe_driver(struct usb_gadget_driver *driver) { struct usb_udc *udc = NULL; int ret; if (!driver || !driver->bind || !driver->setup) return -EINVAL; mutex_lock(&udc_lock); list_for_each_entry(udc, &udc_list, list) { /* For now we take the first one */ if (!udc->driver) goto found; } pr_debug("couldn't find an available UDC\n"); mutex_unlock(&udc_lock); return -ENODEV; found: ret = udc_bind_to_driver(udc, driver); mutex_unlock(&udc_lock); return ret; } EXPORT_SYMBOL_GPL(usb_gadget_probe_driver); int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) { struct usb_udc *udc = NULL; int ret = -ENODEV; if (!driver || !driver->unbind) return -EINVAL; mutex_lock(&udc_lock); list_for_each_entry(udc, &udc_list, list) if (udc->driver == driver) { usb_gadget_remove_driver(udc); ret = 0; break; } mutex_unlock(&udc_lock); return ret; } EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver); /* ------------------------------------------------------------------------- */ static ssize_t usb_udc_srp_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) { struct usb_udc *udc = container_of(dev, struct usb_udc, dev); if (sysfs_streq(buf, "1")) usb_gadget_wakeup(udc->gadget); return n; } static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store); static ssize_t usb_udc_softconn_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) { struct usb_udc *udc = container_of(dev, struct usb_udc, dev); if (!udc->driver) { dev_err(dev, "soft-connect without a gadget driver\n"); return -EOPNOTSUPP; } if (sysfs_streq(buf, "connect")) { usb_gadget_udc_start(udc->gadget, udc->driver); usb_gadget_connect(udc->gadget); } else if (sysfs_streq(buf, "disconnect")) { usb_gadget_disconnect(udc->gadget); usb_gadget_udc_stop(udc->gadget, udc->driver); } else { dev_err(dev, "unsupported command '%s'\n", buf); return -EINVAL; } return n; } static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf) { struct usb_udc *udc = container_of(dev, struct usb_udc, dev); struct usb_gadget *gadget = udc->gadget; return sprintf(buf, "%s\n", usb_state_string(gadget->state)); } static DEVICE_ATTR_RO(state); #define USB_UDC_SPEED_ATTR(name, param) \ ssize_t name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ { \ struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ return snprintf(buf, PAGE_SIZE, "%s\n", \ usb_speed_string(udc->gadget->param)); \ } \ static DEVICE_ATTR_RO(name) static USB_UDC_SPEED_ATTR(current_speed, speed); static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); #define USB_UDC_ATTR(name) \ ssize_t name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ { \ struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ struct usb_gadget *gadget = udc->gadget; \ \ return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \ } \ static DEVICE_ATTR_RO(name) static USB_UDC_ATTR(is_otg); static USB_UDC_ATTR(is_a_peripheral); static USB_UDC_ATTR(b_hnp_enable); static USB_UDC_ATTR(a_hnp_support); static USB_UDC_ATTR(a_alt_hnp_support); static struct attribute *usb_udc_attrs[] = { &dev_attr_srp.attr, &dev_attr_soft_connect.attr, &dev_attr_state.attr, &dev_attr_current_speed.attr, &dev_attr_maximum_speed.attr, &dev_attr_is_otg.attr, &dev_attr_is_a_peripheral.attr, &dev_attr_b_hnp_enable.attr, &dev_attr_a_hnp_support.attr, &dev_attr_a_alt_hnp_support.attr, NULL, }; static const struct attribute_group usb_udc_attr_group = { .attrs = usb_udc_attrs, }; static const struct attribute_group *usb_udc_attr_groups[] = { &usb_udc_attr_group, NULL, }; static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env) { struct usb_udc *udc = container_of(dev, struct usb_udc, dev); int ret; ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name); if (ret) { dev_err(dev, "failed to add uevent USB_UDC_NAME\n"); return ret; } if (udc->driver) { ret = add_uevent_var(env, "USB_UDC_DRIVER=%s", udc->driver->function); if (ret) { dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n"); return ret; } } return 0; } static int __init usb_udc_init(void) { udc_class = class_create(THIS_MODULE, "udc"); if (IS_ERR(udc_class)) { pr_err("failed to create udc class --> %ld\n", PTR_ERR(udc_class)); return PTR_ERR(udc_class); } udc_class->dev_uevent = usb_udc_uevent; return 0; } subsys_initcall(usb_udc_init); static void __exit usb_udc_exit(void) { class_destroy(udc_class); } module_exit(usb_udc_exit); MODULE_DESCRIPTION("UDC Framework"); MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); MODULE_LICENSE("GPL v2");
tank0412/android_kernel_xiaomi_latte
drivers/usb/gadget/udc-core.c
C
gpl-2.0
15,088
function setmytime(){function a(){var a=jQuery(window).width();jQuery(".ult_tabs").each(function(){var b=(jQuery(this).data("tabsstyle"),jQuery(this).data("respmode")),d=jQuery(this).data("respwidth"),e=jQuery(this).data("responsivemode");a>=d?(jQuery(this).parent().find(".ult_acord").css({display:"none"}),jQuery(this).parent().find(".ult_tabs").css({display:"block"}),"Both"!=e&&(jQuery(this).find(".aio-icon").hasClass("ult_tab_resp_icon")&&jQuery(this).find(".aio-icon").removeClass("ult_tab_resp_icon").addClass("icon-top"),jQuery(this).find(".ult_tab_main").hasClass("ult_tab_resp_ult_top")&&jQuery(this).find(".ult_tab_main").removeClass("ult_tab_resp_ult_top").addClass("ult_top"))):("Accordion"==b&&(jQuery(this).parent().find(".ult_acord").css({display:"block"}),jQuery(this).parent().find(".ult_tabs").css({display:"none"})),"Both"!=e&&(jQuery(this).find(".aio-icon").hasClass("icon-top")&&jQuery(this).find(".aio-icon").removeClass("icon-top").addClass("ult_tab_resp_icon"),jQuery(this).find(".ult_tab_main").hasClass("ult_top")&&jQuery(this).find(".ult_tab_main").removeClass("ult_top").addClass("ult_tab_resp_ult_top"))),a>300&&660>a&&(jQuery(this).find(".ult_a ").removeClass("false"),c.push(ht1),"Both"!=e&&(jQuery(this).find(".aio-icon").hasClass("icon-top")&&jQuery(this).find(".aio-icon").removeClass("icon-top").addClass("ult_tab_resp_icon"),jQuery(this).find(".ult_tab_main").hasClass("ult_top")&&jQuery(this).find(".ult_tab_main").removeClass("ult_top").addClass("ult_tab_resp_ult_top")))})}var b=[],c=[],d=!0,e=window.location.hash.substr(1);if(""!=e){var f=jQuery("a[href$='"+e+"']");if(f.parents(".ult_tabs").length>0){var g=f.parents(".ult_tabs"),h=g.data("activebg"),i=g.data("titlebg"),j=g.data("titlecolor"),k=g.data("activetitle"),l=g.data("tabsstyle"),m=g.data("activeicon"),n=g.find("li.ult_tab_li").data("iconcolor");if(""==m)var m=g.find("li.ult_tab_li").data("iconhover");g.find("li.ult_tab_li").removeClass("current"),f.parent().addClass("current"),"style1"==l||"style2"==l?(g.find("a.ult_a").css({"background-color":i}),f.css({"background-color":h})):(g.find("li.ult_tab_li").css({"background-color":i}),f.parent().css({"background-color":h})),g.find("a.ult_a").css({color:j}),f.css({color:k}),g.find(".ult_tab_icon").css({color:n}),f.find(".ult_tab_icon").css({color:m});var o=f.parent().index()+1;g.find(".ult_tabitemname").css({display:"none"}),g.find(".ult_tabitemname:nth-child("+o+")").css({display:"block"});g.offset().top,g.offset().left;g.hasClass("ult_aniamte")||jQuery("html, body").animate({scrollTop:g.offset().top},1e3),g.addClass("ult_aniamte"),g.find("ul.ult_tabmenu li a.ult_a").click(function(a){a.preventDefault(),jQuery("html,body").clearQueue(),jQuery("html,body").stop()})}}jQuery(".ult_tabs").each(function(){var a=jQuery(this).data("fullheight"),e=0;"on"==a&&jQuery(this).find(".ult_tabitemname").each(function(){e<jQuery(this).outerHeight()&&(e=jQuery(this).outerHeight(),jQuery(this).parents(".ult_tabcontent").css({"min-height":e+"px"}))});var f=jQuery(this).data("tabsstyle"),g=jQuery(window).width(),h=jQuery(this).data("respmode"),i=jQuery(this).data("respwidth"),j=jQuery(this).data("responsivemode"),k=jQuery(this).closest(".ult_tabs").data("animation");if("Fade"==k||"Scale"==k||"Slide-Zoom"==k){var l=jQuery(this).find("div.ult_tabcontent").outerHeight();jQuery(this).find(".ult_tabcontent").css({height:l})}if("Slide-Horizontal"==k){var g=jQuery(this).find("div.ult_tabcontent").outerWidth();jQuery(this).find(".ult_tabcontent").find("div.ult_tabitemname:eq(0)").addClass("ult_active_tabnme")}"Scale"==k&&(jQuery(this).find(".ult_tabitemname").not("div.ult_tabitemname:eq(0)").addClass("scaleTabname"),jQuery(this).find(".ult_tabcontent").find("div.ult_tabitemname:eq(0)").addClass("scaleTabname2")),"Slide-Zoom"==k&&(jQuery(this).closest(".ult_tabs").find("div.ult_tabitemname").removeClass("owl-backSlide-in"),jQuery(this).closest(".ult_tabs").find("div.ult_tabitemname").removeClass("owl-backSlide-in")),g>=i?(jQuery(this).parent().find(".ult_acord").css({display:"none"}),jQuery(this).parent().find(".ult_tabs").css({display:"block"})):"Accordion"==h&&(jQuery(this).parent().find(".ult_acord").css({display:"block"}),jQuery(this).parent().find(".ult_tabs").css({display:"none"})),jQuery(this).find(".ult_tabmenu").hasClass("Style_4");var m=0;d="false",jQuery(this).find(".ult_tab_li").each(function(){m<jQuery(this).outerHeight()&&(m=jQuery(this).outerHeight())}),jQuery(this).find(".ult_a").addClass(d),ht1=parseInt(m),"style2"==f?(ht1=parseInt(ht1/2),g>300&&660>g&&(ht1=m/2)):"style1"==f&&jQuery(this).find(".ult_tabmenu").hasClass("Style_5"),g>300&&660>g&&(jQuery(this).find(".ult_a ").removeClass("false"),c.push(ht1),"Both"!=j&&(jQuery(this).find(".aio-icon").hasClass("icon-top")&&jQuery(this).find(".aio-icon").removeClass("icon-top").addClass("ult_tab_resp_icon"),jQuery(this).find(".ult_tab_main").hasClass("ult_top")&&jQuery(this).find(".ult_tab_main").removeClass("ult_top").addClass("ult_tab_resp_ult_top"))),jQuery(this).find(".ult_a ").hasClass("false")&&b.push(ht1)}),jQuery(window).resize(function(b){a()})}jQuery(document).ready(function(a){a(".ult_tabs").each(function(){function b(){clearTimeout(q),o++,o>j-1&&(o=0),q=setTimeout(function(){c.find("ul.ult_tabmenu li.ult_tab_li").each(function(b){o==b&&a(this).find("a.ult_a").trigger("click")})},1e3*i)}var c=a(this),d=a(this).data("tabsstyle"),e=a(this).data("titlecolor"),f=a(this).data("titlebg"),g=a(this).data("titlehovercolor"),h=a(this).data("titlehoverbg"),i=parseInt(a(this).data("rotatetabs")),j=a(this).find("ul.ult_tabmenu li.ult_tab_li").length,k=a(this).data("activetitle"),l=a(this).data("activeicon"),m=a(this).data("activebg"),n=parseInt(a(this).find(".ult_tabcontent").outerWidth()),o=0,p=[];p.push(0),a(this).find("ul.ult_tabmenu").addClass("active").find("> li.ult_tab_li:eq(0)").addClass("current"),a(this).find("ul.ult_tabmenu li.ult_tab_li").each(function(b){var c=a(this).data("iconhover"),i=a(this).data("iconcolor");""==l&&(l=c),0==b&&("style2"==d||"style1"==d?(a(this).find("a.ult_a").css({background:m,color:k}),a(this).find(".ult_tab_icon").css({color:l})):(a(this).find("a.ult_a").css({color:k}),a(this).css({background:m,color:k}),a(this).find(".ult_tab_icon").css({color:k}))),a(this).on("mouseover",function(){a(this).hasClass("current")||(a(this).hasClass("current")||"style2"==d||"style1"==d?(a(this).find("a.ult_a").css({background:h,color:g}),a(this).find(".ult_tab_icon").css({color:c})):(a(this).find("a.ult_a").css({color:g}),a(this).css({background:h,color:g}),a(this).find("a.ult_a").find(".ult_tab_icon").css({color:c})))}).on("mouseleave",function(){a(this).hasClass("current")||("style2"==d||"style1"==d?(a(this).find("a.ult_a").css({background:f,color:e}),a(this).find(".ult_tab_icon").css({color:i})):(a(this).find("a.ult_a").css({color:e}),a(this).css({background:f,color:e}),a(this).find("a.ult_a").find(".ult_tab_icon").css({color:i})))})}),a(this).find("ul.ult_tabmenu li a.ult_a").click(function(c){var g=a(this).closest(".ult_tabs"),h=a(this).closest("li.ult_tab_li").index(),j=a(this).parent().data("iconcolor");a(this).parent().data("iconhover");p.push(h);var q=(p[p.length-1],p[p.length-2]),r=a(this).closest(".ult_tabs").data("animation");g.find("ul.ult_tabmenu > li.ult_tab_li").removeClass("current"),"style2"==d||"style1"==d?(g.find("ul.ult_tabmenu > li.ult_tab_li").find("a").css({background:f,color:e}),g.find("ul.ult_tabmenu > li.ult_tab_li").find(".ult_tab_icon").css({color:j})):(g.find("ul.ult_tabmenu > li.ult_tab_li").find("a.ult_a").css({color:e}),g.find("ul.ult_tabmenu > li.ult_tab_li").css({background:f,color:e}));var s=a(this).closest("li.ult_tab_li").addClass("current");"Slide"==r?("style2"==d||"style1"==d?(s.find("a.ult_a").css({background:m,color:k}),s.find(".ult_tab_icon").css({color:l})):(s.find("a.ult_a").css({color:k}),s.css({background:m,color:k})),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").stop().slideUp(500,function(){i>0&&b()}),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").stop().slideDown(500,function(){}),o=h,c.preventDefault()):"Fade"==r?("style2"==d||"style1"==d?(s.find("a.ult_a").css({background:m,color:k}),s.find(".ult_tab_icon").css({color:l})):(s.find("a.ult_a").css({color:k}),s.css({background:m,color:k})),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").fadeOut(100,function(){i>0&&b()}),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").fadeIn(1200),o=h,c.preventDefault()):"Scale"==r?("style2"==d||"style1"==d?(s.find("a.ult_a").css({background:m,color:k}),s.find(".ult_tab_icon").css({color:l})):(s.find("a.ult_a").css({color:k}),s.css({background:m,color:k})),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").fadeOut(100,function(){i>0&&b(),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").addClass("scaleTabname"),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").removeClass("scaleTabname2")}),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").fadeIn(300,function(){g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").removeClass("scaleTabname"),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").addClass("scaleTabname2")}),o=h,c.preventDefault()):"Slide-Zoom"==r?("style2"==d||"style1"==d?(s.find("a.ult_a").css({background:m,color:k}),s.find(".ult_tab_icon").css({color:l})):(s.find("a.ult_a").css({color:k}),s.css({background:m,color:k})),g.find(".ult_tabcontent").find("div.ult_tabitemname").removeClass("ult_owl-backSlide-in"),g.find(".ult_tabcontent").find("div.ult_tabitemname").removeClass("ult_owl-backSlide-out"),g.find(".ult_tabcontent").find("div.ult_tabitemname").removeClass("ult_owl-backSlideright-in"),g.find(".ult_tabcontent").find("div.ult_tabitemname").removeClass("ult_owl-backSlideright-out"),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").fadeOut(200,function(){g.find(".ult_tabcontent").find("div.ult_tab_min_contain").addClass("ult_owl-origin"),q>h?(g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").addClass("ult_owl-backSlide-in"),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").removeClass(" ult_owl-backSlide-out"),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+q+")").addClass("ult_owl-backSlide-out")):(g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").addClass("ult_owl-backSlideright-in"),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").removeClass(" ult_owl-backSlideright-out"),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+q+")").addClass("ult_owl-backSlideright-out")),i>0&&b()}),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").fadeIn(1500,function(){g.find(".ult_tabcontent").find("div.ult_tab_min_contain").removeClass("ult_owl-origin"),q>h?(g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+q+")").removeClass(" ult_owl-backSlide-in"),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").removeClass(" ult_owl-backSlide-out")):(g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+q+")").removeClass(" ult_owl-backSlideright-in"),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").removeClass(" ult_owl-backSlideright-out"))}),o=h,c.preventDefault()):"Slide-Horizontal"==r?("style2"==d||"style1"==d?(s.find("a.ult_a").css({background:m,color:k}),s.find(".ult_tab_icon").css({color:l})):(s.find("a.ult_a").css({color:k}),s.css({background:m,color:k})),j=g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").hasClass("ult_active_tabnme"),0==j?(g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").hide(10,function(){jQuery(this).addClass("ult_active_tabnme"),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").removeClass("ult_active_tabnme"),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").hide(10),h>q?jQuery(this).animate({left:"-"+n+"px"},10):jQuery(this).animate({left:""+n+"px"},10),i>0&&b()}),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").show(100,function(){jQuery(this).animate({left:"0px"},800)}),o=h,c.preventDefault()):(g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").animate({opacity:1},1,function(){i>0&&b()}),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").animate({opacity:1},1,function(){}),o=h,c.preventDefault())):("style2"==d||"style1"==d?(s.find("a.ult_a").css({background:m,color:k}),s.find(".ult_tab_icon").css({color:l})):(s.find("a.ult_a").css({color:k}),s.css({background:m,color:k})),g.find(".ult_tabcontent").find("div.ult_tabitemname").not("div.ult_tabitemname:eq("+h+")").hide(1,function(){i>0&&b()}),g.find(".ult_tabcontent").find("div.ult_tabitemname:eq("+h+")").show(10),o=h,c.preventDefault())});var q=0;i>0&&b()})}),jQuery(document).ready(function(a){a(this).find("ul.ult_tabmenu li a.ult_a").click(function(b){a(document).trigger("ultAdvancedTabClicked",a(this)),jQuery("html,body").stop(),a(this).closest("li.ult_tab_li").siblings().each(function(b,c){var d=a(this).data("iconcolor");a(this).find(".ult_tab_icon").css({color:d})})})}),jQuery(document).ready(function(){setmytime(),jQuery(this).find("ul.ult_tabmenu li a.ult_a").click(function(a){var b=jQuery(this).closest(".ult_tabs").data("animation");if(j=jQuery(this).closest("li.ult_tab_li").index(),"Fade"==b){var c=jQuery(this).closest(".ult_tabs").find("div.ult_tabitemname:eq("+j+")").outerHeight();jQuery(this).closest(".ult_tabs").find(".ult_tabitemname").css({position:"absolute",left:"0",right:"0"}),jQuery(this).closest(".ult_tabs").find(".ult_tabcontent").animate({height:c},"slow")}if("Slide-Horizontal"==b){var c=jQuery(this).closest(".ult_tabs").find("div.ult_tabitemname:eq("+j+")").outerHeight();jQuery(this).closest(".ult_tabs").find(".ult_tabcontent").css({overflow:"hidden"}),jQuery(this).closest(".ult_tabs").find(".ult_tabcontent").animate({height:c},"slow")}})}),jQuery(document).ready(function(){jQuery(this).find("ul.ult_tabmenu li a.ult_a").click(function(a){jQuery(".slick-slider").parents(".ult_tabitemname").length&&setTimeout(function(){jQuery(".slick-slider").slick("setPosition"),jQuery(window).trigger("resize")},200)}),jQuery(".vc_toggle").parents(".ult_tabs")&&jQuery(".vc_toggle").click(function(){jQuery(this).parents(".ult_tabitemname").height();jQuery(this).find(".vc_toggle_content").toggleClass("vc_toggle_for_tab"),jQuery(this).find(".vc_toggle_content").hasClass("vc_toggle_for_tab")?setTimeout(function(){var a=jQuery(".ult_tabitemname").height();jQuery(".ult_tabcontent").animate({height:a},100)},100):setTimeout(function(){var a=jQuery(".vc_toggle").parents(".ult_tabitemname").height();jQuery(".ult_tabcontent").animate({height:a},100)},200)})});
cdudley15/Griffey
wp-content/plugins/Ultimate_VC_Addons/assets/min-js/tabs.min.js
JavaScript
gpl-2.0
14,951
<?php /** * @version $Id: arrayhelper.php 13341 2009-10-27 03:03:54Z ian $ * @package Joomla.Framework * @subpackage Utilities * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. * @license GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant to the * GNU General Public License, and as distributed it includes or is derivative * of works licensed under the GNU General Public License or other free or open * source software licenses. See COPYRIGHT.php for copyright notices and * details. */ defined('JPATH_BASE') or die(); /** * JArrayHelper is an array utility class for doing all sorts of odds and ends with arrays. * * @static * @package Joomla.Framework * @subpackage Utilities * @since 1.5 */ class JArrayHelper { /** * Function to convert array to integer values * * @static * @param array $array The source array to convert * @param mixed $default A default value (int|array) to assign if $array is not an array * @since 1.5 */ function toInteger(&$array, $default = null) { if (is_array($array)) { foreach ($array as $i => $v) { $array[$i] = (int) $v; } } else { if ($default === null) { $array = array(); } elseif (is_array($default)) { JArrayHelper::toInteger($default, null); $array = $default; } else { $array = array( (int) $default ); } } } /** * Utility function to map an array to a stdClass object. * * @static * @param array $array The array to map. * @param string $calss Name of the class to create * @return object The object mapped from the given array * @since 1.5 */ function toObject(&$array, $class = 'stdClass') { $obj = null; if (is_array($array)) { $obj = new $class(); foreach ($array as $k => $v) { if (is_array($v)) { $obj->$k = JArrayHelper::toObject($v, $class); } else { $obj->$k = $v; } } } return $obj; } function toString( $array = null, $inner_glue = '=', $outer_glue = ' ', $keepOuterKey = false ) { $output = array(); if (is_array($array)) { foreach ($array as $key => $item) { if (is_array ($item)) { if ($keepOuterKey) { $output[] = $key; } // This is value is an array, go and do it again! $output[] = JArrayHelper::toString( $item, $inner_glue, $outer_glue, $keepOuterKey); } else { $output[] = $key.$inner_glue.'"'.$item.'"'; } } } return implode( $outer_glue, $output); } /** * Utility function to map an object to an array * * @static * @param object The source object * @param boolean True to recurve through multi-level objects * @param string An optional regular expression to match on field names * @return array The array mapped from the given object * @since 1.5 */ function fromObject( $p_obj, $recurse = true, $regex = null ) { $result = null; if (is_object( $p_obj )) { $result = array(); foreach (get_object_vars($p_obj) as $k => $v) { if ($regex) { if (!preg_match( $regex, $k )) { continue; } } if (is_object( $v )) { if ($recurse) { $result[$k] = JArrayHelper::fromObject( $v, $recurse, $regex ); } } else { $result[$k] = $v; } } } return $result; } /** * Extracts a column from an array of arrays or objects * * @static * @param array $array The source array * @param string $index The index of the column or name of object property * @return array Column of values from the source array * @since 1.5 */ function getColumn(&$array, $index) { $result = array (); if (is_array($array)) { $n = count($array); for ($i = 0; $i < $n; $i++) { $item = & $array[$i]; if (is_array($item) && isset ($item[$index])) { $result[] = $item[$index]; } elseif (is_object($item) && isset ($item-> $index)) { $result[] = $item-> $index; } // else ignore the entry } } return $result; } /** * Utility function to return a value from a named array or a specified default * * @static * @param array $array A named array * @param string $name The key to search for * @param mixed $default The default value to give if no key found * @param string $type Return type for the variable (INT, FLOAT, STRING, WORD, BOOLEAN, ARRAY) * @return mixed The value from the source array * @since 1.5 */ function getValue(&$array, $name, $default=null, $type='') { // Initialize variables $result = null; if (isset ($array[$name])) { $result = $array[$name]; } // Handle the default case if (is_null($result)) { $result = $default; } // Handle the type constraint switch (strtoupper($type)) { case 'INT' : case 'INTEGER' : // Only use the first integer value @ preg_match('/-?[0-9]+/', $result, $matches); $result = @ (int) $matches[0]; break; case 'FLOAT' : case 'DOUBLE' : // Only use the first floating point value @ preg_match('/-?[0-9]+(\.[0-9]+)?/', $result, $matches); $result = @ (float) $matches[0]; break; case 'BOOL' : case 'BOOLEAN' : $result = (bool) $result; break; case 'ARRAY' : if (!is_array($result)) { $result = array ($result); } break; case 'STRING' : $result = (string) $result; break; case 'WORD' : $result = (string) preg_replace( '#\W#', '', $result ); break; case 'NONE' : default : // No casting necessary break; } return $result; } /** * Utility function to sort an array of objects on a given field * * @static * @param array $arr An array of objects * @param string $k The key to sort on * @param int $direction Direction to sort in [1 = Ascending] [-1 = Descending] * @return array The sorted array of objects * @since 1.5 */ function sortObjects( &$a, $k, $direction=1 ) { $GLOBALS['JAH_so'] = array( 'key' => $k, 'direction' => $direction ); usort( $a, array('JArrayHelper', '_sortObjects') ); unset( $GLOBALS['JAH_so'] ); return $a; } /** * Private callback function for sorting an array of objects on a key * * @static * @param array $a An array of objects * @param array $b An array of objects * @return int Comparison status * @since 1.5 * @see JArrayHelper::sortObjects() */ function _sortObjects( &$a, &$b ) { $params = $GLOBALS['JAH_so']; if ( $a->$params['key'] > $b->$params['key'] ) { return $params['direction']; } if ( $a->$params['key'] < $b->$params['key'] ) { return -1 * $params['direction']; } return 0; } }
navinpai/GEC-Tandav
libraries/joomla/utilities/arrayhelper.php
PHP
gpl-2.0
6,658
.jumbotron { position: relative; padding: 40px 0; } .jumbotron h1 { font-size: 56px; letter-spacing: -1px; line-height: 1; margin: 0 0 10px 0; } .jumbotron p { font-size: 21px; line-height: 1.275; margin: 0 0 20px 0; } .jumbotron .btn { margin-top: 10px; } .jumbotron .btn-large { margin-top: 20px; font-size: 18px; } .masthead { padding: 80px 0 60px; text-align: center; } .masthead h1 { font-size: 98px; } .masthead p { font-size: 42px; } .masthead .btn-large { font-size: 28px; padding: 14px 28px; } .jumbotron.has-image { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .masthead.has-image { text-align: left; } .thumbnails { margin-bottom: 20px; margin-left: -40px; list-style: none; *zoom: 1; } .thumbnails:before, .thumbnails:after { display: table; content: ""; line-height: 0; } .thumbnails:after { clear: both; } .row-fluid .thumbnails { margin-left: 0; } .thumbnails > li { float: left; position: relative; margin-bottom: 20px; margin-left: 40px; } .thumbnail { border: 1px solid #ddd; display: block; padding: 4px; line-height: 20px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.055); -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.055); box-shadow: 0 1px 3px rgba(0,0,0,0.055); -webkit-transition: all .2s ease-in-out; -moz-transition: all .2s ease-in-out; -o-transition: all .2s ease-in-out; transition: all .2s ease-in-out; } a.thumbnail:hover { border-color: #690; -webkit-box-shadow: 0 1px 4px rgba(0,105,214,0.25); -moz-box-shadow: 0 1px 4px rgba(0,105,214,0.25); box-shadow: 0 1px 4px rgba(0,105,214,0.25); } .thumbnail > img { display: block; max-width: 100%; margin-left: auto; margin-right: auto; } .thumbnail .caption { padding: 9px; color: #666; } .thumbnails.paper > li:before, .thumbnails.paper > li:after { content: ''; position: absolute; z-index: -2; bottom: 15px; left: 10px; width: 50%; height: 20%; box-shadow: 0 15px 10px rgba(0,0,0,0.7); -webkit-transform: rotate(-3deg); -moz-transform: rotate(-3deg); -ms-transform: rotate(-3deg); -o-transform: rotate(-3deg); transform: rotate(-3deg); } .thumbnails.paper > li:after { right: 10px; left: auto; -webkit-transform: rotate(3deg); -moz-transform: rotate(3deg); -ms-transform: rotate(3deg); -o-transform: rotate(3deg); transform: rotate(3deg); } .thumbnails.paper .thumbnail { border: none; padding: 0; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; } .thumbnails.paper a.thumbnail.paper:hover { -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; } .t3-logo, .t3-logo-small { display: block; text-decoration: none; text-indent: -9999em; text-align: left; background-repeat: no-repeat; background-position: center; } .t3-logo { width: 182px; height: 50px; } .t3-logo-small { width: 60px; height: 30px; } .t3-logo, .t3-logo-color { background-image: url("http://joomlart.s3.amazonaws.com/images/jat3v3-documents/logo-complete/t3logo-big-color.png"); } .t3-logo-small, .t3-logo-small.t3-logo-color { background-image: url("http://joomlart.s3.amazonaws.com/images/jat3v3-documents/logo-complete/t3logo-small-color.png"); } .t3-logo-dark { background-image: url("http://joomlart.s3.amazonaws.com/images/jat3v3-documents/logo-complete/t3logo-big-dark.png"); } .t3-logo-small.t3-logo-dark { background-image: url("http://joomlart.s3.amazonaws.com/images/jat3v3-documents/logo-complete/t3logo-small-dark.png"); } .t3-logo-light { background-image: url("http://joomlart.s3.amazonaws.com/images/jat3v3-documents/logo-complete/t3logo-big-light.png"); } .t3-logo-small.t3-logo-light { background-image: url("http://joomlart.s3.amazonaws.com/images/jat3v3-documents/logo-complete/t3logo-small-light.png"); } .wrap { width: auto; clear: both; } .offset-12 { margin-left: -932px; } .offset-11 { margin-left: -851px; } .offset-10 { margin-left: -770px; } .offset-9 { margin-left: -689px; } .offset-8 { margin-left: -608px; } .offset-7 { margin-left: -527px; } .offset-6 { margin-left: -446px; } .offset-5 { margin-left: -365px; } .offset-4 { margin-left: -284px; } .offset-3 { margin-left: -203px; } .offset-2 { margin-left: -122px; } .offset-1 { margin-left: -41px; } .row-fluid .spanfirst { margin-left: 0 !important; } .logo-control .logo-img-sm { display: none; } .logo-control .logo-img { display: block; } .body-data-holder:before { display: none; content: "grid-float-breakpoint:767px screen-xs:600px screen-sm:736px screen-md:932px screen-lg:1196px"; } .wrap { width: auto; clear: both; } .tab-content { overflow: visible; } .accordion-body.collapse { position: relative; height: 0; overflow: hidden; -webkit-transition: height .35s ease; -moz-transition: height .35s ease; -o-transition: height .35s ease; transition: height .35s ease; } .accordion-body.collapse.in { height: auto; } body { background-color: #fff; color: #444; font-family: sans-serif; font-size: 14px; line-height: 20px; margin: 0; } a { color: #690; text-decoration: none; } a:hover { color: #334d00; text-decoration: underline; } img { max-width: 100% !important; } .img-rounded { -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .img-polaroid { padding: 4px; background-color: #fff; border: 1px solid #ccc; border: 1px solid rgba(0,0,0,0.2); -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.1); -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.1); box-shadow: 0 1px 3px rgba(0,0,0,0.1); } .img-circle { -webkit-border-radius: 500px; -moz-border-radius: 500px; border-radius: 500px; } table { background-color: transparent; border-collapse: collapse; border-spacing: 0; } th, td { line-height: 20px; padding: 8px 10px; text-align: left; vertical-align: top; } td { border-top: 1px solid #ddd; } th { background: #444; color: #eee; font-weight: bold; } th a { color: #eee; } th a:hover, th a:focus, th a:active { color: #fff; } .cat-list-row0:hover, .cat-list-row1:hover { background: #f5f5f5; } .cat-list-row1, tr.cat-list-row1 td { background: #f9f9f9; } table.contentpane, table.tablelist, table.category, table.admintable, table.blog { width: 100%; } table.contentpaneopen { border: 0; } .row-even, .row-odd { padding: 5px; width: 99%; border-bottom: 1px solid #ddd; } .row-odd { background-color: transparent; } .row-even { background-color: #f9f9f9; } .blog-row-rule, .blog-item-rule { border: 0; } .row-fluid .row-reveal { visibility: hidden; } .row-fluid:hover .row-reveal { visibility: visible; } .nav-list > li.offset > a { padding-left: 30px; font-size: 12px; } .blog-row-rule, .blog-item-rule { border: 0; } .list-striped, .row-striped { list-style: none; line-height: 18px; text-align: left; vertical-align: middle; border-top: 1px solid #ddd; margin-left: 0; } .list-striped li, .list-striped dd, .row-striped .row, .row-striped .row-fluid { border-bottom: 1px solid #ddd; padding: 10px 15px; } .list-striped li:nth-child(odd), .list-striped dd:nth-child(odd), .row-striped .row:nth-child(odd), .row-striped .row-fluid:nth-child(odd) { background-color: #f9f9f9; } .list-striped li:hover, .list-striped dd:hover, .row-striped .row:hover, .row-striped .row-fluid:hover { background-color: #f5f5f5; } .row-striped .row-fluid { width: 97%; } .row-striped .row-fluid [class*="span"] { min-height: 10px; } .row-striped .row-fluid [class*="span"] { margin-left: 8px; } .row-striped .row-fluid [class*="span"]:first-child { margin-left: 0; } .list-condensed li { padding: 5px 10px; } .row-condensed .row, .row-condensed .row-fluid { padding: 5px 10px; } .list-bordered, .row-bordered { list-style: none; line-height: 18px; text-align: left; vertical-align: middle; margin-left: 0; border: 1px solid #ddd; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .star { color: #fc0; } .red { color: #c00; } .center, .table td.center, .table th.center { text-align: center; } hr { margin: 20px 0; border: 0; border-top: 1px solid #eee; border-bottom: 1px solid #fff; } hr.hr-condensed { margin: 10px 0; } .element-invisible { position: absolute; padding: 0; margin: 0; border: 0; height: 1px; width: 1px; overflow: hidden; } .width-auto { width: auto; } p { margin: 0 0 10px; } p small, p .small { font-size: 12px; color: #999; } .lead { margin-bottom: 20px; font-size: 20px; font-weight: 200; line-height: 30px; } small { font-size: 85%; } strong { font-weight: bold; } em { font-style: italic; } cite { font-style: normal; } .muted { color: #999; } a.muted:hover, a.muted:focus { color: #808080; } .text-warning { color: #f80; } a.text-warning:hover, a.text-warning:focus { color: #cc6d00; } .text-error { color: #c00; } a.text-error:hover, a.text-error:focus { color: #990000; } .text-info { color: #07b; } a.text-info:hover, a.text-info:focus { color: #005788; } .text-success { color: #690; } a.text-success:hover, a.text-success:focus { color: #446600; } .text-left { text-align: left; } .text-right { text-align: right; } .text-center { text-align: center; } .highlight { background-color: #FFC; font-weight: bold; padding: 1px 4px; } h1, h2, h3, h4, h5, h6 { margin: 10px 0; font-family: sans-serif; font-weight: bold; line-height: 1; color: #444; text-rendering: optimizelegibility; } h1 small, h2 small, h3 small, h4 small, h5 small, h6 small { font-weight: normal; line-height: 1; color: #999; } h1 { font-size: 35px; line-height: 40px; } h1 small { font-size: 28px; } h2 { font-size: 28px; line-height: 40px; } h2 small { font-size: 21px; } h3 { font-size: 21px; line-height: 40px; } h3 small { font-size: 16px; } h4 { font-size: 16px; line-height: 20px; } h4 small { font-size: 14px; } h5 { font-size: 15px; line-height: 20px; } h5 small { font-size: 12px; } h6 { font-size: 14px; line-height: 20px; } .page-header { border-bottom: 1px solid #ddd; padding-bottom: 20px; margin: 0 0 40px; } .page-title, .page-header h1 { line-height: 1; margin: 0; } .page-subheader { border-bottom: 1px solid #ddd; margin: 0 0 20px; *zoom: 1; } .page-subheader:before, .page-subheader:after { display: table; content: ""; line-height: 0; } .page-subheader:after { clear: both; } .page-subtitle, .page-subheader h2 { line-height: 1; margin: 0; } .page-header + .page-subheader { margin-top: -20px; } .article-title, .article-header h1 { margin: 0 0 10px 0; line-height: 1; } .item-title { font-weight: bold; } ul, ol { padding: 0; margin: 0 0 10px 25px; } ul ul, ul ol, ol ol, ol ul { margin-bottom: 0; } ul { list-style: disc; } ol { list-style: decimal; } li { line-height: 20px; } ul.unstyled, ol.unstyled { margin-left: 0; list-style: none; } ul.inline, ol.inline { margin-left: 0; list-style: none; } ul.inline > li, ol.inline > li { display: inline-block; *display: inline; *zoom: 1; padding-left: 5px; padding-right: 5px; } dl { margin-bottom: 20px; } dt, dd { line-height: 20px; } dt { font-weight: bold; } dd { margin-left: 10px; } .dl-horizontal { *zoom: 1; } .dl-horizontal:before, .dl-horizontal:after { display: table; content: ""; line-height: 0; } .dl-horizontal:after { clear: both; } .dl-horizontal dt { float: left; width: 160px; clear: left; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .dl-horizontal dd { margin-left: 180px; } .label, .badge { display: inline-block; padding: 2px 4px; font-size: 11.844px; font-weight: bold; line-height: 14px; color: #fff; vertical-align: baseline; white-space: nowrap; text-shadow: 0 -1px 0 rgba(0,0,0,0.25); background-color: #999; } .label { -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .badge { padding-left: 9px; padding-right: 9px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .label:empty, .badge:empty { display: none; } a.label:hover, a.label:focus, a.badge:hover, a.badge:focus { color: #fff; text-decoration: none; cursor: pointer; } .label-important, .badge-important { background-color: #c00; } .label-important[href], .badge-important[href] { background-color: #990000; } .label-warning, .badge-warning { background-color: #f80; } .label-warning[href], .badge-warning[href] { background-color: #cc6d00; } .label-success, .badge-success { background-color: #690; } .label-success[href], .badge-success[href] { background-color: #446600; } .label-info, .badge-info { background-color: #07b; } .label-info[href], .badge-info[href] { background-color: #005788; } .label-inverse, .badge-inverse { background-color: #444; } .label-inverse[href], .badge-inverse[href] { background-color: #2b2b2b; } .btn .label, .btn .badge { position: relative; top: -1px; } .btn-mini .label, .btn-mini .badge { top: 0; } .page-header .label, .page-header .badge { vertical-align: middle; } abbr[title], abbr[data-original-title] { cursor: help; border-bottom: 1px dotted #999; } abbr.initialism { font-size: 90%; text-transform: uppercase; } blockquote { padding: 0 0 0 15px; margin: 0 0 20px; border-left: 5px solid #eee; } blockquote p { margin-bottom: 0; font-size: 17.5px; font-weight: 300; line-height: 1.25; } blockquote small { display: block; line-height: 20px; color: #999; } blockquote small:before { content: '\2014 \00A0'; } blockquote.pull-right { float: right; padding-right: 15px; padding-left: 0; border-right: 5px solid #eee; border-left: 0; } blockquote.pull-right p, blockquote.pull-right small { text-align: right; } blockquote.pull-right small:before { content: ''; } blockquote.pull-right small:after { content: '\00A0 \2014'; } q:before, q:after, blockquote:before, blockquote:after { content: ""; } address { display: block; margin-bottom: 0; font-style: normal; line-height: 20px; } form { margin: 0 0 20px; } input, textarea { width: 210px; } textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input { -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075); -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075); box-shadow: inset 0 1px 1px rgba(0,0,0,0.075); -webkit-transition: border linear .2s, box-shadow linear .2s, width 0.7s ease 0s; -moz-transition: border linear .2s, box-shadow linear .2s, width 0.7s ease 0s; -o-transition: border linear .2s, box-shadow linear .2s, width 0.7s ease 0s; transition: border linear .2s, box-shadow linear .2s, width 0.7s ease 0s; } textarea:focus, input[type="text"]:focus, input[type="password"]:focus, input[type="datetime"]:focus, input[type="datetime-local"]:focus, input[type="date"]:focus, input[type="month"]:focus, input[type="time"]:focus, input[type="week"]:focus, input[type="number"]:focus, input[type="email"]:focus, input[type="url"]:focus, input[type="search"]:focus, input[type="tel"]:focus, input[type="color"]:focus, .uneditable-input:focus { border-color: #999999; -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(0,0,0,.25); -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(0,0,0,.25); box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(0,0,0,.25); } input[type="file"], input[type="image"], input[type="submit"], input[type="reset"], input[type="button"], input[type="radio"], input[type="checkbox"] { width: auto; } select, input[type="file"] { height: 30px; line-height: 30px; } select { width: 220px; border: 1px solid #ddd; } select[multiple], select[size] { height: auto; } .radio, .checkbox { padding-left: 18px; } .radio input[type="radio"], .checkbox input[type="checkbox"] { margin-left: -18px; } .controls > .radio:first-child, .controls > .checkbox:first-child { padding-top: 5px; } .radio.inline, .checkbox.inline { padding-top: 5px; margin-bottom: 0; } .radio.inline + .radio.inline, .checkbox.inline + .checkbox.inline { margin-left: 10px; } .radio.btn-group input[type=radio] { display: none; } .radio.btn-group > label:first-of-type { margin-left: 0; -webkit-border-bottom-left-radius: 4px; border-bottom-left-radius: 4px; -webkit-border-top-left-radius: 4px; border-top-left-radius: 4px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-topleft: 4px; } fieldset.radio.btn-group { padding-left: 0; } .input-mini { width: 60px; } .input-small { width: 90px; } .input-medium { width: 150px; } .input-large { width: 210px; } .input-xlarge { width: 270px; } .input-xxlarge { width: 530px; } .form-actions { padding: 19px 20px 20px; margin-top: 20px; margin-bottom: 20px; background-color: #f5f5f5; border-top: 1px solid #ddd; } .help-block, .help-inline { color: #6a6a6a; } .help-block { margin-bottom: 10px; } .input-append, .input-prepend { margin-bottom: 5px; } .form-search input, .form-search textarea, .form-search select, .form-search .help-inline, .form-search .uneditable-input, .form-search .input-prepend, .form-search .input-append, .form-inline input, .form-inline textarea, .form-inline select, .form-inline .help-inline, .form-inline .uneditable-input, .form-inline .input-prepend, .form-inline .input-append, .form-horizontal input, .form-horizontal textarea, .form-horizontal select, .form-horizontal .help-inline, .form-horizontal .uneditable-input, .form-horizontal .input-prepend, .form-horizontal .input-append { margin-bottom: 0; } .form-search .input-append, .form-inline .input-append, .form-search .input-prepend, .form-inline .input-prepend { margin-bottom: 0; } .form-search .radio, .form-search .checkbox, .form-inline .radio, .form-inline .checkbox { padding-left: 0; margin-bottom: 0; } .form-search .radio input[type="radio"], .form-search .checkbox input[type="checkbox"], .form-inline .radio input[type="radio"], .form-inline .checkbox input[type="checkbox"] { margin-right: 3px; margin-left: 0; } .control-group { margin-bottom: 10px; } legend + .control-group { margin-top: 20px; } .form-horizontal .control-group { margin-bottom: 20px; } .form-horizontal .control-label { width: 140px; padding-top: 5px; text-align: right; } .form-horizontal .controls { margin-left: 160px; } .form-horizontal .help-block { margin-top: 10px; margin-bottom: 0; } .form-horizontal .form-actions { padding-left: 160px; } .form-vertical .control-label { float: none; width: auto; padding-right: 0; padding-top: 0; text-align: left; } .form-vertical .controls { margin-left: 0; } .btn, .button, button { padding: 4px 14px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; -webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 1px 2px rgba(0,0,0,.1); -moz-box-shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 1px 2px rgba(0,0,0,.1); box-shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 1px 2px rgba(0,0,0,.1); color: #444; text-shadow: 0 1px 1px rgba(255,255,255,0.75); background-color: #f8f8f8; background-image: -moz-linear-gradient(top,#ffffff,#eee); background-image: -webkit-gradient(linear,0 0,0 100%,from(#ffffff),to(#eee)); background-image: -webkit-linear-gradient(top,#ffffff,#eee); background-image: -o-linear-gradient(top,#ffffff,#eee); background-image: linear-gradient(to bottom,#ffffff,#eee); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffeeeeee', GradientType=0); border-color: #eee #eee #c8c8c8; border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25); *background-color: #eee; filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); } .btn:hover, .btn:focus, .btn:active, .btn.active, .btn.disabled, .btn[disabled], .button:hover, .button:focus, .button:active, .button.active, .button.disabled, .button[disabled], button:hover, button:focus, button:active, button.active, button.disabled, button[disabled] { color: #444; background-color: #eee; *background-color: #e1e1e1; } .btn:active, .btn.active, .button:active, .button.active, button:active, button.active { background-color: #d5d5d5 \9; } .btn:hover, .btn a.btn:hover, .button:hover, .button a.btn:hover, button:hover, button a.btn:hover { text-decoration: none; background-color: #eee; } .btn:focus, .btn a.btn:focus, .button:focus, .button a.btn:focus, button:focus, button a.btn:focus { outline: 0; } .btn.active, .btn:active, .btn a.btn:active, .button.active, .button:active, .button a.btn:active, button.active, button:active, button a.btn:active { text-decoration: none; outline: 0; -webkit-box-shadow: inset 0 2px 4px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.05); -moz-box-shadow: inset 0 2px 4px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.05); box-shadow: inset 0 2px 4px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.05); } .btn-large { padding: 9px 14px; font-size: 16px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; -webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 1px 2px rgba(0,0,0,.5); -moz-box-shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 1px 2px rgba(0,0,0,.5); box-shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 1px 2px rgba(0,0,0,.5); } .btn-small { padding: 3px 9px; font-size: 13px; } .btn-mini { padding: 2px 6px; font-size: 12px; } .btn-micro { padding: 1px 4px; font-size: 10px; line-height: 8px; } .btn { border-color: #c5c5c5; border-color: rgba(0,0,0,0.15) rgba(0,0,0,0.15) rgba(0,0,0,0.25); } .btn-primary { color: #fff; text-shadow: 0 -1px 0 rgba(0,0,0,0.25); background-color: #7ab800; background-image: -moz-linear-gradient(top,#88cc00,#690); background-image: -webkit-gradient(linear,0 0,0 100%,from(#88cc00),to(#690)); background-image: -webkit-linear-gradient(top,#88cc00,#690); background-image: -o-linear-gradient(top,#88cc00,#690); background-image: linear-gradient(to bottom,#88cc00,#690); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff87cc00', endColorstr='#ff669900', GradientType=0); border-color: #690 #690 #334d00; border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25); *background-color: #690; filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); } .btn-primary:hover, .btn-primary:focus, .btn-primary:active, .btn-primary.active, .btn-primary.disabled, .btn-primary[disabled] { color: #fff; background-color: #690; *background-color: #558000; } .btn-primary:active, .btn-primary.active { background-color: #446600 \9; } .btn-warning { color: #fff; text-shadow: 0 -1px 0 rgba(0,0,0,0.25); background-color: #ff961f; background-image: -moz-linear-gradient(top,#ffa033,#f80); background-image: -webkit-gradient(linear,0 0,0 100%,from(#ffa033),to(#f80)); background-image: -webkit-linear-gradient(top,#ffa033,#f80); background-image: -o-linear-gradient(top,#ffa033,#f80); background-image: linear-gradient(to bottom,#ffa033,#f80); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffff9f32', endColorstr='#ffff8800', GradientType=0); border-color: #f80 #f80 #b35f00; border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25); *background-color: #f80; filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); } .btn-warning:hover, .btn-warning:focus, .btn-warning:active, .btn-warning.active, .btn-warning.disabled, .btn-warning[disabled] { color: #fff; background-color: #f80; *background-color: #e67a00; } .btn-warning:active, .btn-warning.active { background-color: #cc6d00 \9; } .btn-danger, .btn-error { color: #fff; text-shadow: 0 -1px 0 rgba(0,0,0,0.25); background-color: #eb0000; background-image: -moz-linear-gradient(top,#ff0000,#c00); background-image: -webkit-gradient(linear,0 0,0 100%,from(#ff0000),to(#c00)); background-image: -webkit-linear-gradient(top,#ff0000,#c00); background-image: -o-linear-gradient(top,#ff0000,#c00); background-image: linear-gradient(to bottom,#ff0000,#c00); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffff0000', endColorstr='#ffcc0000', GradientType=0); border-color: #c00 #c00 #800000; border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25); *background-color: #c00; filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); } .btn-danger:hover, .btn-danger:focus, .btn-danger:active, .btn-danger.active, .btn-danger.disabled, .btn-danger[disabled], .btn-error:hover, .btn-error:focus, .btn-error:active, .btn-error.active, .btn-error.disabled, .btn-error[disabled] { color: #fff; background-color: #c00; *background-color: #b30000; } .btn-danger:active, .btn-danger.active, .btn-error:active, .btn-error.active { background-color: #990000 \9; } .btn-success { color: #fff; text-shadow: 0 -1px 0 rgba(0,0,0,0.25); background-color: #7ab800; background-image: -moz-linear-gradient(top,#88cc00,#690); background-image: -webkit-gradient(linear,0 0,0 100%,from(#88cc00),to(#690)); background-image: -webkit-linear-gradient(top,#88cc00,#690); background-image: -o-linear-gradient(top,#88cc00,#690); background-image: linear-gradient(to bottom,#88cc00,#690); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff87cc00', endColorstr='#ff669900', GradientType=0); border-color: #690 #690 #334d00; border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25); *background-color: #690; filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); } .btn-success:hover, .btn-success:focus, .btn-success:active, .btn-success.active, .btn-success.disabled, .btn-success[disabled] { color: #fff; background-color: #690; *background-color: #558000; } .btn-success:active, .btn-success.active { background-color: #446600 \9; } .btn-info { color: #fff; text-shadow: 0 -1px 0 rgba(0,0,0,0.25); background-color: #00b0eb; background-image: -moz-linear-gradient(top,#00bfff,#09c); background-image: -webkit-gradient(linear,0 0,0 100%,from(#00bfff),to(#09c)); background-image: -webkit-linear-gradient(top,#00bfff,#09c); background-image: -o-linear-gradient(top,#00bfff,#09c); background-image: linear-gradient(to bottom,#00bfff,#09c); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff00bfff', endColorstr='#ff0099cc', GradientType=0); border-color: #09c #09c #006080; border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25); *background-color: #09c; filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); } .btn-info:hover, .btn-info:focus, .btn-info:active, .btn-info.active, .btn-info.disabled, .btn-info[disabled] { color: #fff; background-color: #09c; *background-color: #0086b3; } .btn-info:active, .btn-info.active { background-color: #007399 \9; } .btn-inverse { color: #fff; text-shadow: 0 -1px 0 rgba(0,0,0,0.25); background-color: #535353; background-image: -moz-linear-gradient(top,#5e5e5e,#444); background-image: -webkit-gradient(linear,0 0,0 100%,from(#5e5e5e),to(#444)); background-image: -webkit-linear-gradient(top,#5e5e5e,#444); background-image: -o-linear-gradient(top,#5e5e5e,#444); background-image: linear-gradient(to bottom,#5e5e5e,#444); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5d5d5d', endColorstr='#ff444444', GradientType=0); border-color: #444 #444 #1e1e1e; border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25); *background-color: #444; filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); } .btn-inverse:hover, .btn-inverse:focus, .btn-inverse:active, .btn-inverse.active, .btn-inverse.disabled, .btn-inverse[disabled] { color: #fff; background-color: #444; *background-color: #373737; } .btn-inverse:active, .btn-inverse.active { background-color: #2b2b2b \9; } .invalid { border-color: #c00; } label.invalid { color: #c00; } input.invalid { border: 1px solid #c00; } .nav { margin-bottom: 20px; } .nav > li > a:hover { background-color: #666; color: #eee; } .nav .dropdown-toggle .caret { border-top-color: #690; border-bottom-color: #690; margin-top: 8px; margin-left: 5px; } .nav .dropdown-toggle:hover .caret { border-top-color: #334d00; border-bottom-color: #334d00; } .nav .active .dropdown-toggle .caret { border-top-color: #fff; border-bottom-color: #fff; } .nav-tabs .active .dropdown-toggle .caret { border-top-color: #666; border-bottom-color: #666; } .dropup, .dropdown { position: relative; } .dropdown-toggle { *margin-bottom: -3px; } .dropdown-toggle:active, .open .dropdown-toggle { outline: 0; } .caret { display: inline-block; width: 0; height: 0; vertical-align: top; border-top: 4px solid #000; border-right: 4px solid transparent; border-left: 4px solid transparent; content: ""; } .dropdown .caret { margin-top: 8px; margin-left: 2px; } .dropdown-menu { position: absolute; top: 100%; left: 0; z-index: 1000; display: none; float: left; min-width: 160px; list-style: none; background-color: #fff; border: 1px solid #ccc; border: 1px solid rgba(0,0,0,0.2); *border-right-width: 2px; *border-bottom-width: 2px; padding: 0; margin: 0; -webkit-border-radius: 0 0 4px 4px; -moz-border-radius: 0 0 4px 4px; border-radius: 0 0 4px 4px; -webkit-box-shadow: 0 5px 10px rgba(0,0,0,0.2); -moz-box-shadow: 0 5px 10px rgba(0,0,0,0.2); box-shadow: 0 5px 10px rgba(0,0,0,0.2); -webkit-background-clip: padding-box; -moz-background-clip: padding; background-clip: padding-box; } .dropdown-menu.pull-right { right: 0; left: auto; } .dropdown-menu .divider { *width: 100%; height: 1px; margin: 9px 1px; *margin: -5px 0 5px; overflow: hidden; background-color: #e5e5e5; border-bottom: 1px solid #fff; } .dropdown-menu li > a { clear: both; color: #444; display: block; line-height: 20px; font-weight: normal; padding: 3px 20px; text-shadow: none; white-space: nowrap; } .dropdown-menu li > a:hover, .dropdown-menu li > a:focus, .dropdown-submenu:hover > a { color: #eee; text-decoration: none; background-color: #666; background-color: #757575; background-image: -moz-linear-gradient(top,#808080,#666); background-image: -webkit-gradient(linear,0 0,0 100%,from(#808080),to(#666)); background-image: -webkit-linear-gradient(top,#808080,#666); background-image: -o-linear-gradient(top,#808080,#666); background-image: linear-gradient(to bottom,#808080,#666); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff7f7f7f', endColorstr='#ff666666', GradientType=0); } .dropdown-menu .active > a, .dropdown-menu .active > a:hover { color: #eee; text-decoration: none; outline: 0; background-color: #690; background-color: #7ab800; background-image: -moz-linear-gradient(top,#88cc00,#690); background-image: -webkit-gradient(linear,0 0,0 100%,from(#88cc00),to(#690)); background-image: -webkit-linear-gradient(top,#88cc00,#690); background-image: -o-linear-gradient(top,#88cc00,#690); background-image: linear-gradient(to bottom,#88cc00,#690); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff87cc00', endColorstr='#ff669900', GradientType=0); } .dropdown-menu .disabled > a, .dropdown-menu .disabled > a:hover { color: #999; } .dropdown-menu .disabled > a:hover { text-decoration: none; background-color: transparent; background-image: none; cursor: default; } .open { *z-index: 1000; } .open > .dropdown-menu { display: block; } .nav li.dropdown.open > .dropdown-toggle, .nav li.dropdown.active > .dropdown-toggle, .nav li.dropdown.open.active > .dropdown-toggle, .nav > li.dropdown.open.active > a:hover { background-color: #690; color: #eee; } .nav li.dropdown > .dropdown-toggle .caret { border-top-color: #666; border-bottom-color: #666; } .nav li.dropdown > .dropdown-toggle:hover .caret { border-top-color: #eee; border-bottom-color: #eee; } .nav li.dropdown.open > .dropdown-toggle .caret, .nav li.dropdown.active > .dropdown-toggle .caret, .nav li.dropdown.open.active > .dropdown-toggle .caret { border-top-color: #eee; border-bottom-color: #eee; } .pull-right > .dropdown-menu { right: 0; left: auto; } .dropup .caret, .navbar-fixed-bottom .dropdown .caret { border-top: 0; border-bottom: 4px solid #000; content: ""; } .dropup .dropdown-menu, .navbar-fixed-bottom .dropdown .dropdown-menu { top: auto; bottom: 100%; margin-bottom: 1px; } .dropdown-submenu { position: relative; } .dropdown-submenu > .dropdown-menu { top: 0; left: 100%; margin-top: -6px; margin-left: -1px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .dropdown-submenu:hover > .dropdown-menu { display: block; } .touch .dropdown-submenu:hover > .dropdown-menu { display: none; } .touch .dropdown-submenu.open > .dropdown-menu { display: block; } .dropup .dropdown-submenu > .dropdown-menu { top: auto; bottom: 0; margin-top: 0; margin-bottom: -2px; -webkit-border-radius: 0; -moz-border-radius: 0; border-radius: 0; } .dropdown-submenu > a:after { display: block; content: " "; float: right; width: 0; height: 0; border-color: transparent; border-style: solid; border-width: 5px 0 5px 5px; border-left-color: #cccccc; margin-top: 5px; margin-right: -10px; } .dropdown-submenu:hover > a:after { border-left-color: #eee; } .dropdown-submenu.pull-left { float: none; } .dropdown-submenu.pull-left > .dropdown-menu { left: -100%; margin-left: 10px; -webkit-border-radius: 6px 0 6px 6px; -moz-border-radius: 6px 0 6px 6px; border-radius: 6px 0 6px 6px; } .dropdown .dropdown-menu .nav-header { padding-left: 20px; padding-right: 20px; } .typeahead { margin-top: 2px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .t3-navhelper { background: #2f2f2f; color: #666; } .breadcrumb { padding: 10px 0; margin: 0; background-color: transparent; -webkit-border-radius: 0; -moz-border-radius: 0; border-radius: 0; *zoom: 1; } .breadcrumb:before, .breadcrumb:after { display: table; content: ""; line-height: 0; } .breadcrumb:after { clear: both; } .breadcrumb li { text-shadow: none; display: block; float: left; } .breadcrumb a { color: #666; } .breadcrumb .divider { padding: 0 5px; color: #666; } .breadcrumb .divider img { vertical-align: middle; } .breadcrumb .active { color: #999; } .pagination { margin: 20px 0; } .pagination ul { display: inline-block; *display: inline; *zoom: 1; margin-left: 0; margin-bottom: 0; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.05); -moz-box-shadow: 0 1px 2px rgba(0,0,0,0.05); box-shadow: 0 1px 2px rgba(0,0,0,0.05); } .pagination ul > li { display: inline; } .pagination ul > li > a, .pagination ul > li > span { float: left; padding: 4px 12px; line-height: 20px; text-decoration: none; background-color: #fff; border: 1px solid #ddd; border-left-width: 0; } .pagination ul > li > a:hover, .pagination ul > li > a:focus, .pagination ul > .active > a, .pagination ul > .active > span { background-color: #f5f5f5; } .pagination ul > .active > a, .pagination ul > .active > span { color: #999; cursor: default; } .pagination ul > .disabled > span, .pagination ul > .disabled > a, .pagination ul > .disabled > a:hover, .pagination ul > .disabled > a:focus { color: #999; background-color: transparent; cursor: default; } .pagination ul > li:first-child > a, .pagination ul > li:first-child > span { border-left-width: 1px; -webkit-border-top-left-radius: 4px; -moz-border-radius-topleft: 4px; border-top-left-radius: 4px; -webkit-border-bottom-left-radius: 4px; -moz-border-radius-bottomleft: 4px; border-bottom-left-radius: 4px; } .pagination ul > li:last-child > a, .pagination ul > li:last-child > span { -webkit-border-top-right-radius: 4px; -moz-border-radius-topright: 4px; border-top-right-radius: 4px; -webkit-border-bottom-right-radius: 4px; -moz-border-radius-bottomright: 4px; border-bottom-right-radius: 4px; } .pagination-centered { text-align: center; } .pagination-right { text-align: right; } .pagination-large ul > li > a, .pagination-large ul > li > span { padding: 11px 19px; font-size: 17.5px; } .pagination-large ul > li:first-child > a, .pagination-large ul > li:first-child > span { -webkit-border-top-left-radius: 6px; -moz-border-radius-topleft: 6px; border-top-left-radius: 6px; -webkit-border-bottom-left-radius: 6px; -moz-border-radius-bottomleft: 6px; border-bottom-left-radius: 6px; } .pagination-large ul > li:last-child > a, .pagination-large ul > li:last-child > span { -webkit-border-top-right-radius: 6px; -moz-border-radius-topright: 6px; border-top-right-radius: 6px; -webkit-border-bottom-right-radius: 6px; -moz-border-radius-bottomright: 6px; border-bottom-right-radius: 6px; } .pagination-mini ul > li:first-child > a, .pagination-mini ul > li:first-child > span, .pagination-small ul > li:first-child > a, .pagination-small ul > li:first-child > span { -webkit-border-top-left-radius: 3px; -moz-border-radius-topleft: 3px; border-top-left-radius: 3px; -webkit-border-bottom-left-radius: 3px; -moz-border-radius-bottomleft: 3px; border-bottom-left-radius: 3px; } .pagination-mini ul > li:last-child > a, .pagination-mini ul > li:last-child > span, .pagination-small ul > li:last-child > a, .pagination-small ul > li:last-child > span { -webkit-border-top-right-radius: 3px; -moz-border-radius-topright: 3px; border-top-right-radius: 3px; -webkit-border-bottom-right-radius: 3px; -moz-border-radius-bottomright: 3px; border-bottom-right-radius: 3px; } .pagination-small ul > li > a, .pagination-small ul > li > span { padding: 2px 10px; font-size: 11.9px; } .pagination-mini ul > li > a, .pagination-mini ul > li > span { padding: 1px 6px; font-size: 10.5px; } .pager { margin: 20px 0; list-style: none; text-align: center; *zoom: 1; } .pager:before, .pager:after { display: table; content: ""; line-height: 0; } .pager:after { clear: both; } .pager li { display: inline; } .pager li > a, .pager li > span { display: inline-block; padding: 5px 14px; background-color: #fff; border: 1px solid #ddd; -webkit-border-radius: 15px; -moz-border-radius: 15px; border-radius: 15px; } .pager li > a:hover, .pager li > a:focus { text-decoration: none; background-color: #f5f5f5; } .pager .next > a, .pager .next > span { float: right; } .pager .previous > a, .pager .previous > span { float: left; } .pager .disabled > a, .pager .disabled > a:hover, .pager .disabled > a:focus, .pager .disabled > span { color: #999; background-color: #fff; cursor: default; } .t3-mainnav { background-color: #f5f5f5; background-image: -moz-linear-gradient(top,#ffffff,#e6e6e6); background-image: -webkit-gradient(linear,0 0,0 100%,from(#ffffff),to(#e6e6e6)); background-image: -webkit-linear-gradient(top,#ffffff,#e6e6e6); background-image: -o-linear-gradient(top,#ffffff,#e6e6e6); background-image: linear-gradient(to bottom,#ffffff,#e6e6e6); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe5e5e5', GradientType=0); border-top: 1px solid #e6e6e6; border-bottom: 1px solid #cccccc; } .t3-mainnav .navbar { color: #666; margin-bottom: 0; margin-top: 0; } .t3-mainnav .navbar-inner { min-height: 40px; padding: 0; background: transparent; border: 0; border-left: 1px solid #d9d9d9; -webkit-border-radius: 0; -moz-border-radius: 0; border-radius: 0; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); } .t3-mainnav .navbar .nav { margin: 0; } .t3-mainnav .navbar .nav > li > a { border-top: 0; border-right: 1px solid #d9d9d9; padding: 10px 20px; text-shadow: none; } .t3-mainnav .navbar .nav > li > .separator, .t3-mainnav .navbar .nav > li > span { padding: 10px 20px; display: inline-block; } .t3-mainnav .navbar .nav > li > a:focus, .t3-mainnav .navbar .nav > li > a:hover { background-color: #666; background-color: #757575; background-image: -moz-linear-gradient(top,#808080,#666); background-image: -webkit-gradient(linear,0 0,0 100%,from(#808080),to(#666)); background-image: -webkit-linear-gradient(top,#808080,#666); background-image: -o-linear-gradient(top,#808080,#666); background-image: linear-gradient(to bottom,#808080,#666); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff7f7f7f', endColorstr='#ff666666', GradientType=0); text-shadow: none; outline: none; } .t3-mainnav .navbar .nav > .active > a, .t3-mainnav .navbar .nav > .active > a:hover, .t3-mainnav .navbar .nav > .active > a:focus { color: #eee; text-shadow: none; background-color: #7ab800; background-image: -moz-linear-gradient(top,#88cc00,#690); background-image: -webkit-gradient(linear,0 0,0 100%,from(#88cc00),to(#690)); background-image: -webkit-linear-gradient(top,#88cc00,#690); background-image: -o-linear-gradient(top,#88cc00,#690); background-image: linear-gradient(to bottom,#88cc00,#690); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff87cc00', endColorstr='#ff669900', GradientType=0); -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; outline: none; } .t3-mainnav .navbar .btn-navbar { float: left; padding: 5px 10px; margin: 4px 20px 4px; color: #fff; text-shadow: 0 -1px 0 rgba(0,0,0,0.25); background-color: #e8e8e8; background-image: -moz-linear-gradient(top,#f2f2f2,#d9d9d9); background-image: -webkit-gradient(linear,0 0,0 100%,from(#f2f2f2),to(#d9d9d9)); background-image: -webkit-linear-gradient(top,#f2f2f2,#d9d9d9); background-image: -o-linear-gradient(top,#f2f2f2,#d9d9d9); background-image: linear-gradient(to bottom,#f2f2f2,#d9d9d9); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2f2f2', endColorstr='#ffd8d8d8', GradientType=0); border-color: #d9d9d9 #d9d9d9 #b3b3b3; border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25); *background-color: #d9d9d9; filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); -webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 1px 0 rgba(255,255,255,.075); -moz-box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 1px 0 rgba(255,255,255,.075); box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 1px 0 rgba(255,255,255,.075); } .t3-mainnav .navbar .btn-navbar:hover, .t3-mainnav .navbar .btn-navbar:focus, .t3-mainnav .navbar .btn-navbar:active, .t3-mainnav .navbar .btn-navbar.active, .t3-mainnav .navbar .btn-navbar.disabled, .t3-mainnav .navbar .btn-navbar[disabled] { color: #fff; background-color: #d9d9d9; *background-color: #cccccc; } .t3-mainnav .navbar .btn-navbar:active, .t3-mainnav .navbar .btn-navbar.active { background-color: #bfbfbf \9; } .t3-mainnav .navbar .btn-navbar [class^="icon-"], .t3-mainnav .navbar .btn-navbar [class^=" icon-"] { color: #666; text-shadow: none; } .t3-mainnav .dropdown .caret { margin-left: 5px; } .t3-mainnav .dropdown-menu { -webkit-box-shadow: 0 5px 10px rgba(0,0,0,0.2); -moz-box-shadow: 0 5px 10px rgba(0,0,0,0.2); box-shadow: 0 5px 10px rgba(0,0,0,0.2); } .t3-mainnav .dropdown-menu li > a { border-top: 1px solid #eee; padding: 5px 20px; text-shadow: none; } .t3-mainnav .dropdown-menu li:first-child > a { border-top: 0; } .t3-mainnav .navbar .nav > li > .dropdown-menu:before { display: none; } .t3-mainnav .navbar .nav > li > .dropdown-menu:after { display: none; } .t3-mainnav .dropdown-submenu > .dropdown-menu { margin-top: 0; } .t3-mainnav .dropdown-menu .disabled > a, .t3-mainnav .dropdown-menu .disabled > a:hover { color: #999; } .t3-mainnav .dropdown-menu .disabled > a:hover { background-color: transparent; } .t3-mainnav .nav li.dropdown.open > .dropdown-toggle { background-color: #666; color: #eee; } .t3-mainnav .nav li.dropdown.active > .dropdown-toggle, .t3-mainnav .nav li.dropdown.open.active > .dropdown-toggle { background-color: #690; color: #eee; } .t3-module { background: transparent; color: inherit; margin-bottom: 40px; } .t3-module .module-inner { padding: 0; } .module-title { background: inherit; color: #444; line-height: 30px; margin: 0 0 10px 0; padding: 0; } .module-ct { background: inherit; color: inherit; padding: 0; *zoom: 1; } .module-ct:before, .module-ct:after { display: table; content: ""; line-height: 0; } .module-ct:after { clear: both; } .t3-module ul, .t3-module ol { margin-left: 20px; } .t3-module ul.unstyled, .t3-module ol.unstyled, .t3-module ul.nav, .t3-module ol.nav { margin-left: 0; } .module_menu .nav { margin-bottom: 20px; } .module_menu .nav > li { border-top: 1px solid #eee; } .module_menu .nav > li > a { padding: 5px; } .module_menu .nav > li:first-child { border-top: 0; } .module_menu .nav > li:first-child > a { padding-top: 0; border-top: 0; } #login-form input[type="text"], #login-form input[type="password"] { width: 90%; } .banneritem a { font-weight: bold; } .bannerfooter { border-top: 1px solid #ddd; font-size: 12px; padding-top: 10px; text-align: right; } .categories-module, ul.categories-module, .category-module, ul.category-module { margin: 0; } .categories-module li, ul.categories-module li, .category-module li, ul.category-module li { list-style: none; padding: 10px 0; border-top: 1px solid #ddd; } .categories-module li:first-child, ul.categories-module li:first-child, .category-module li:first-child, ul.category-module li:first-child { border-top: 0; padding-top: 0; } .categories-module h4, ul.categories-module h4, .category-module h4, ul.category-module h4 { font-size: 14px; font-weight: normal; margin: 0; } .feed h4 { font-weight: bold; } .feed .newsfeed, .feed ul.newsfeed { border-top: 1px solid #eee; } .feed .newsfeed .feed-link, .feed .newsfeed h5.feed-link, .feed ul.newsfeed .feed-link, .feed ul.newsfeed h5.feed-link { font-size: 14px; font-weight: normal; margin: 0; } .latestusers, ul.latestusers { margin-left: 0; } .latestusers li, ul.latestusers li { background: #eee; display: inline-block; padding: 5px 10px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .stats-module dt, .stats-module dd { display: inline-block; margin: 0; } .stats-module dt { font-weight: bold; width: 35%; } .stats-module dd { width: 60%; } div.tagspopular ul { display: block; margin: 0; padding: 0; list-style: none; overflow: hidden; } div.tagspopular ul li { color: #666; display: inline-block; margin: 0 5px 5px 0; } div.tagspopular ul li a { background: #eee; border-radius: 3px; color: #666; display: block; padding: 2px 5px; } div.tagspopular ul li a:hover, div.tagspopular ul li a:focus, div.tagspopular ul li a:active { background: #334d00; color: #fff; text-decoration: none; } div.tagssimilar ul { margin: 0; padding: 0; list-style: none; } div.tagssimilar ul li { border-bottom: 1px solid #eee; padding: 8px 0; } div.tagssimilar ul li a { color: #666; } div.tagssimilar ul li a:hover, div.tagssimilar ul li a:focus, div.tagssimilar ul li a:active { color: #334d00; } .items-leading .leading { margin-bottom: 40px; } .items-row .item { margin-bottom: 40px; } .divider-vertical { margin: 0 0 40px; border: 0; border-top: 1px solid #eee; border-bottom: 1px solid #fff; } .article-aside { color: #999; font-size: 13px; margin-bottom: 20px; } .article-info { margin: 0; width: 90%; } .article-info .article-info-term { display: none; } .article-info dd { float: left; margin-left: 0; margin-right: 10px; white-space: nowrap; } .article-info dd span { font-weight: bold; } .article-footer { color: #999; font-size: 13px; margin-bottom: 20px; } article img[align=left], .img_caption.left, .pull-left.item-image { margin: 0 40px 20px 0; } article img[align=right], .img_caption.right, .pull-right.item-image { margin: 0 0 20px 40px; } .img-intro-none, .img-intro-left, .img-intro-right, .img-fulltext-none, .img-fulltext-left, .img-fulltext-right, .img_caption { position: relative; } .img-intro-none, .img-intro-left, .img-intro-right, .img-fulltext-none, .img-fulltext-left, .img-fulltext-right, .img_caption { margin-bottom: 20px; max-width: 100%; } .img-fulltext-left { float: left; margin-right: 40px; } .img-fulltext-right { float: right; margin-left: 40px; } .img-intro-none img, .img-intro-left img, .img-intro-right img, .img-fulltext-none img, .img-fulltext-left img, .img-fulltext-right img { margin: 0; } .img_caption img { margin-bottom: 1px !important; } .img_caption p.img_caption { background: #eee; color: #666; font-size: 12px; width: 100%; margin: 0; padding: 5px; text-align: center; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; clear: both; } article aside .btn-group > .dropdown-toggle, article aside .btn-group > .dropdown-toggle:hover, article aside .btn-group > .dropdown-toggle:active, article aside .btn-group > .dropdown-toggle:focus { background: transparent; border: 0; padding: 0; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; } .login_form fieldset, .login fieldset { padding: 15px 0 0; } .login_form fieldset p, .login fieldset p { margin: 0 0 5px; } .login_form label, .login label { display: block; font-weight: bold; } .login-fields { margin: 0 0 10px; } .login_form .input, .login_form .inputbox, .login-fields .required { margin-left: 10px; width: 150px; } .login_form .remember .input, .login_form .remember .inputbox { width: 20px; } .form-register fieldset { padding: 0 0 10px; } .form-register p { margin: 0 0 5px; } .form-register p.form-des { margin: 15px 0; } .form-register label { display: block; float: left; font-weight: bold; text-align: right; width: 130px; } .form-register .input, .form-register .inputbox { margin-left: 10px; width: 200px; } .form-register .btn, .form-register .button { margin-left: 140px; } .registration fieldset dt { margin-right: 5px; } .admintable textarea { max-width: 90% !important; resize: none; } #mailto-window { background: #fff; margin: 10px 0 20px; padding: 0; position: relative; } #mailto-window h2 { margin-top: 0; margin-bottom: 20px; } #mailto-window .mailto-close { background: #FFF; background: -moz-linear-gradient(bottom,#ccc,#f0f0f0); background: -webkit-linear-gradient(bottom,#ccc,#f0f0f0); border: 1px solid #CCC; border-radius: 3px; color: #666; font-size: 92%; padding: 2px 5px; position: absolute; top: -10px; right: 0px; text-shadow: 1px 1px 0 #f0f0f0; } #mailto-window .mailto-close a { color: #666; } #mailto-window .mailto-close:hover { border-color: #999; box-shadow: 0 0 3px rgba(0,0,0,0.2); } #mailtoForm .formelm { padding: 5px 0; vertical-align: middle; overflow: hidden; } #mailtoForm .formelm label { display: inline-block; float: left; font-weight: bold; vertical-align: middle; width: 100px; } #mailtoForm p { margin-top: 20px; } #mailtoForm .input, #mailtoForm .inputbox { width: 65%; } #mailtoForm .btn, #mailtoForm .button, #mailtoForm button { margin-right: 5px; } .user-details { padding: 10px 0; } .user-details p { margin: 0 0 5px; } .user-details label { display: block; float: left; font-weight: bold; text-align: right; width: 130px; } .user-details .input, .user-details .inputbox { margin-left: 10px; width: 200px; } .user-details .btn, .user-details button { margin-left: 140px; } .user-details .paramlist .paramlist_key { padding: 0 0 5px; width: 130px; } .user-details .paramlist .paramlist_value { padding: 0 0 5px; } .user-details .user_name span { font-weight: bold; padding-left: 10px; } .reset .form-validate p, .remind .form-validate p { background: #eee; border: 1px solid #ddd; margin-bottom: 20px; padding: 10px 20px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .reset .form-validate fieldset dl, .remind .form-validate fieldset dl { margin: 0; } .reset .form-validate fieldset dt, .remind .form-validate fieldset dt { margin: 4px 0 0 0; } #searchForm { padding: 10px 20px; border: 1px solid #ddd; background: #eee; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; *zoom: 1; } #searchForm:before, #searchForm:after { display: table; content: ""; line-height: 0; } #searchForm:after { clear: both; } #searchForm fieldset { margin: 20px 0; } #searchForm legend { margin-bottom: 10px; } #searchForm .phrases-box input[type="radio"] { vertical-align: top; margin-top: 3px; } #search-form ul#finder-filter-select-list { margin-left: 0; } #search-form ul#finder-filter-select-list li { list-style: none; padding: 10px 0; } #search-form ul#finder-filter-select-list li label { width: 150px; } .phrases-box input, .phrases-box label, .form-limit input, .form-limit label, .only label { display: inline-block; margin-right: 10px; } .phrases-box input { margin: 0; } .search-results { margin-top: 20px; } .search-results .result-title { font-size: 16px; margin-top: 20px; } .search-results .result-category { font-size: 12px; color: #999; } .search-results .result-text { margin-top: 5px; margin-bottom: 5px; } .search-results .result-created { font-size: 12px; color: #999; } .contact .accordion-heading .accordion-toggle { font-weight: bold; } #archive-items > li { line-height: normal; margin: 0; overflow: visible; padding: 0; } #archive-items div.intro { clear: both; overflow: hidden; } .category-item { margin-top: 20px; *zoom: 1; } .category-item:before, .category-item:after { display: table; content: ""; line-height: 0; } .category-item:after { clear: both; } .category-item .page-header { line-height: normal; padding-top: 10px; padding-bottom: 10px; margin-bottom: 20px; } .category-item .category-item { margin-left: 4.2918454935622%; } .newsfeed-category > h2, .newsfeed > h2 { border-bottom: 1px solid #ddd; padding-bottom: 20px; margin-bottom: 20px; margin-top: 0; } .newsfeed-category .category-desc, .newsfeed .category-desc { margin-bottom: 20px; } .newsfeed-category .category li, .newsfeed .category li { *zoom: 1; } .newsfeed-category .category li:before, .newsfeed-category .category li:after, .newsfeed .category li:before, .newsfeed .category li:after { display: table; content: ""; line-height: 0; } .newsfeed-category .category li:after, .newsfeed .category li:after { clear: both; } .newsfeed > h2 { border-bottom: 1px solid #ddd; padding-bottom: 20px; margin-bottom: 20px; margin-top: 0; } .newsfeed .feed-description { margin-bottom: 20px; font-size: 16px; } .newsfeed .feed-item-description .feed-description { font-size: 14px; } .newsfeed ol li > a { font-weight: bold; font-size: 16px; } .edit textarea { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .edit.item-page fieldset .form-actions { clear: both; margin-top: 40px; } .com_media #imageForm #upbutton { margin-top: 5px; } .button2-left, .button2-left div { float: left; } .button2-right, .button2-right div { float: right; } .button2-left { margin: 5px 5px 0 0; } .button2-right { margin: 5px 0 0 5px; } .button2-left a, .button2-right a, .button2-left span, .button2-right span { background: #eee; border: 1px solid #e1e1e1; color: #999; cursor: pointer; display: block; float: left; padding: 2px 10px; border-radius: 4px; } .button2-left span, .button2-right span { color: #999; cursor: default; } .button2-left .page a, .button2-right .page a, .button2-left .page span, .button2-right .page span { padding: 0 6px; } .button2-left a:hover, .button2-right a:hover { background: #e1e1e1; color: #444; text-decoration: none; } .control-group a.modal { position: inherit; width: auto !important; margin-left: 0 !important; top: auto !important; } .controls img.calendar { cursor: pointer; margin-left: 5px; } #imageForm #upbutton { margin-top: -18px; } .view-imagesList body { padding-top: 0; } .view-imagesList .t3-mainbody { padding: 0; } .view-imagesList .manager.thumbnails { overflow: hidden; } .view-imagesList .manager.thumbnails li { float: left; margin: 0 10px 20px; } table.adminlist th a { color: #690; } .article-content .pagination ul { border-left: 1px solid #ddd; } .article-content .pagination li { float: left; padding: 10px 20px; line-height: normal; border: 1px solid #ddd; border-left: 0; } .article-content .pagination li a { border: 0; text-decoration: none; background-color: transparent; line-height: normal; padding: 0; } .pagenavcounter { margin: 0 0 20px; font-weight: bold; } #article-index { float: right; margin: 0 0 20px 20px; padding: 10px; width: 30%; border: 1px solid #ddd; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } #article-index ul { margin: 0 0 0 20px; } .pagenav { margin: 0; padding: 0; list-style: none; } .pagenav li { margin: 0; padding: 0; float: left; } .pagenav li.pagenav-prev { margin-right: 10px; } .pagenav li a { padding: 10px 20px; line-height: normal; border: 1px solid #ddd; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .pagenav li a:hover, .pagenav li a:active, .pagenav li a:focus { background-color: #666; color: #eee; } .counter { float: right; line-height: 1; margin: 10px 0; text-align: right; } .items-more h3 { margin: 0 0 5px; } .back_button a { display: block; margin: 10px 0; } .filters { margin: 10px 0 5px; } .display-limit { margin: 10px 0 5px; } .filters .filter-search, .filters .display-limit { float: left; width: 50%; } .filters .display-limit { float: right; text-align: right; } #system-message dt { font-weight: bold; } #system-message dd { font-weight: bold; } #system-message dd.message ul, #system-message dd.error ul, #system-message dd.notice ul { margin: 0; padding: 0; } #system-message dd.message ul li, #system-message dd.error ul li, #system-message dd.notice ul li { background: none; margin: 0; padding: 5px; } .tip-wrap { background: #fff6df; border: 1px solid #fb3; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: 0 0 3px rgba(0,0,0,0.4); -moz-box-shadow: 0 0 3px rgba(0,0,0,0.4); box-shadow: 0 0 3px rgba(0,0,0,0.4); max-width: 300px; z-index: 999; } .tip-title { border-bottom: 1px solid #fb3; font-weight: bold; padding: 5px 10px; } .tip-text { font-size: 14px; margin: 0; padding: 5px 10px; } .hasTip img { border: none; margin: 0 5px 0 0; } .width-10 { width: 10px; } .width-20 { width: 20px; } .width-30 { width: 30px; } .width-40 { width: 40px; } .width-50 { width: 50px; } .width-60 { width: 60px; } .width-70 { width: 70px; } .width-80 { width: 80px; } .width-90 { width: 90px; } .width-100 { width: 100px; } .height-10 { height: 10px; } .height-20 { height: 20px; } .height-30 { height: 30px; } .height-40 { height: 40px; } .height-50 { height: 50px; } .height-60 { height: 60px; } .height-70 { height: 70px; } .height-80 { height: 80px; } .height-90 { height: 90px; } .height-100 { height: 100px; } .iframe-bordered { border: 1px solid #ddd; } .input-prepend .chzn-container-single .chzn-single { border-color: #ccc; height: 26px; -webkit-border-radius: 0 3px 3px 0; -moz-border-radius: 0 3px 3px 0; border-radius: 0 3px 3px 0; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; } .input-prepend .chzn-container-active .chzn-single-with-drop { -webkit-border-radius: 0 3px 0 0; -moz-border-radius: 0 3px 0 0; border-radius: 0 3px 0 0; } .input-prepend .chzn-container-single .chzn-drop { border-color: #ccc; } .btn-group .chzn-results { white-space: normal; } .languageswitcherload { float: right; width: 100%; } .languageswitcherload .mod-languages { text-align: right; } .t3-header { padding-top: 20px; padding-bottom: 20px; } .logo { float: left; } .logo a { display: inline-block; line-height: 1; margin: 0; } .logo-image { overflow: hidden; } .logo-image a { background-repeat: no-repeat; width: 204px; height: 65px; } .logo-image span, .logo-image small { display: none; } .logo-text a { color: #444; text-decoration: none; font-size: 17.5px; } .logo-text:hover a, .logo-text a:hover, .logo-text a:active, .logo-text a:focus { text-decoration: none; } .logo-text .site-slogan { display: block; font-size: 14px; margin-top: 5px; } .head-search { float: right; margin-top: 20px; } .head-search form { margin: 0; float: right; } .head-search label { display: none; } .head-search .input { background: url("../../../images/ico/search-invert.png") no-repeat 8px center; width: 120px; padding-left: 26px; } .head-search .input:focus { color: #444; width: 180px; } .t3-sl { padding-bottom: 60px; padding-top: 60px; } .t3-mainbody { padding-bottom: 40px; padding-top: 40px; } .t3-footer { background: #222; color: #666; *zoom: 1; } .t3-footer:before, .t3-footer:after { display: table; content: ""; line-height: 0; } .t3-footer:after { clear: both; } .t3-footer small { display: block; font-size: 100%; } .t3-footer a { color: #999; } .t3-footer a:hover, .t3-footer a:active, .t3-footer a:focus { color: #e6e6e6; } .t3-footnav { padding: 60px 0 40px; *zoom: 1; } .t3-footnav:before, .t3-footnav:after { display: table; content: ""; line-height: 0; } .t3-footnav:after { clear: both; } .t3-footnav ul { list-style: none; margin-left: 0; } .t3-footnav li { line-height: 24px; } .t3-footnav .module-title { font-size: 18px; color: #999; } .t3-copyright { border-top: 1px solid #2f2f2f; font-size: 12px; padding: 40px 0 80px; *zoom: 1; } .t3-copyright:before, .t3-copyright:after { display: table; content: ""; line-height: 0; } .t3-copyright:after { clear: both; } .copyright { float: left; } .poweredby { float: right; text-align: right; } .poweredby .t3-logo, .poweredby .t3-logo-small { float: right; opacity: .5; } .t3-footer { background: #690; color: #fff; } .t3-footer a { color: #ddff99; } .t3-footer a:hover, .t3-footer a:active, .t3-footer a:focus { color: #fff; } .t3-footnav .module-title { color: #fff; } .t3-copyright { border-top: 1px solid #77b300; }
sabrinahung/test_cms
templates/t3_blank/css/themes/green/template.css
CSS
gpl-2.0
63,816
/* * x86 SMP booting functions * * This inherits a great deal from Linux's SMP boot code: * (c) 1995 Alan Cox, Building #3 <alan@redhat.com> * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <xen/config.h> #include <xen/init.h> #include <xen/kernel.h> #include <xen/mm.h> #include <xen/domain.h> #include <xen/sched.h> #include <xen/sched-if.h> #include <xen/irq.h> #include <xen/delay.h> #include <xen/softirq.h> #include <xen/tasklet.h> #include <xen/serial.h> #include <xen/numa.h> #include <xen/cpu.h> #include <asm/current.h> #include <asm/mc146818rtc.h> #include <asm/desc.h> #include <asm/div64.h> #include <asm/flushtlb.h> #include <asm/msr.h> #include <asm/mtrr.h> #include <asm/time.h> #include <asm/tboot.h> #include <mach_apic.h> #include <mach_wakecpu.h> #include <smpboot_hooks.h> #define setup_trampoline() (bootsym_phys(trampoline_realmode_entry)) unsigned long __read_mostly trampoline_phys; /* representing HT siblings of each logical CPU */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_mask); /* representing HT and core siblings of each logical CPU */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_mask); cpumask_t cpu_online_map __read_mostly; EXPORT_SYMBOL(cpu_online_map); struct cpuinfo_x86 cpu_data[NR_CPUS]; u32 x86_cpu_to_apicid[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID }; static int cpu_error; static enum cpu_state { CPU_STATE_DYING, /* slave -> master: I am dying */ CPU_STATE_DEAD, /* slave -> master: I am completely dead */ CPU_STATE_INIT, /* master -> slave: Early bringup phase 1 */ CPU_STATE_CALLOUT, /* master -> slave: Early bringup phase 2 */ CPU_STATE_CALLIN, /* slave -> master: Completed phase 2 */ CPU_STATE_ONLINE /* master -> slave: Go fully online now. */ } cpu_state; #define set_cpu_state(state) do { mb(); cpu_state = (state); } while (0) void *stack_base[NR_CPUS]; static void smp_store_cpu_info(int id) { struct cpuinfo_x86 *c = cpu_data + id; *c = boot_cpu_data; if ( id != 0 ) identify_cpu(c); /* * Certain Athlons might work (for various values of 'work') in SMP * but they are not certified as MP capable. */ if ( (c->x86_vendor == X86_VENDOR_AMD) && (c->x86 == 6) ) { /* Athlon 660/661 is valid. */ if ( (c->x86_model==6) && ((c->x86_mask==0) || (c->x86_mask==1)) ) goto valid_k7; /* Duron 670 is valid */ if ( (c->x86_model==7) && (c->x86_mask==0) ) goto valid_k7; /* * Athlon 662, Duron 671, and Athlon >model 7 have capability bit. * It's worth noting that the A5 stepping (662) of some Athlon XP's * have the MP bit set. * See http://www.heise.de/newsticker/data/jow-18.10.01-000 for more. */ if ( ((c->x86_model==6) && (c->x86_mask>=2)) || ((c->x86_model==7) && (c->x86_mask>=1)) || (c->x86_model> 7) ) if (cpu_has_mp) goto valid_k7; /* If we get here, it's not a certified SMP capable AMD system. */ add_taint(TAINT_UNSAFE_SMP); } valid_k7: ; } /* * TSC's upper 32 bits can't be written in earlier CPUs (before * Prescott), there is no way to resync one AP against BP. */ bool_t disable_tsc_sync; static atomic_t tsc_count; static uint64_t tsc_value; static cpumask_t tsc_sync_cpu_mask; static void synchronize_tsc_master(unsigned int slave) { unsigned int i; if ( disable_tsc_sync ) return; if ( boot_cpu_has(X86_FEATURE_TSC_RELIABLE) && !cpumask_test_cpu(slave, &tsc_sync_cpu_mask) ) return; for ( i = 1; i <= 5; i++ ) { rdtscll(tsc_value); wmb(); atomic_inc(&tsc_count); while ( atomic_read(&tsc_count) != (i<<1) ) cpu_relax(); } atomic_set(&tsc_count, 0); cpumask_clear_cpu(slave, &tsc_sync_cpu_mask); } static void synchronize_tsc_slave(unsigned int slave) { unsigned int i; if ( disable_tsc_sync ) return; if ( boot_cpu_has(X86_FEATURE_TSC_RELIABLE) && !cpumask_test_cpu(slave, &tsc_sync_cpu_mask) ) return; for ( i = 1; i <= 5; i++ ) { while ( atomic_read(&tsc_count) != ((i<<1)-1) ) cpu_relax(); rmb(); /* * If a CPU has been physically hotplugged, we may as well write * to its TSC in spite of X86_FEATURE_TSC_RELIABLE. The platform does * not sync up a new CPU's TSC for us. */ __write_tsc(tsc_value); atomic_inc(&tsc_count); } } static void smp_callin(void) { unsigned int cpu = smp_processor_id(); int i, rc; /* Wait 2s total for startup. */ Dprintk("Waiting for CALLOUT.\n"); for ( i = 0; cpu_state != CPU_STATE_CALLOUT; i++ ) { BUG_ON(i >= 200); cpu_relax(); mdelay(10); } /* * The boot CPU has finished the init stage and is spinning on cpu_state * update until we finish. We are free to set up this CPU: first the APIC. */ Dprintk("CALLIN, before setup_local_APIC().\n"); x2apic_ap_setup(); setup_local_APIC(); /* Save our processor parameters. */ smp_store_cpu_info(cpu); if ( (rc = hvm_cpu_up()) != 0 ) { printk("CPU%d: Failed to initialise HVM. Not coming online.\n", cpu); cpu_error = rc; clear_local_APIC(); spin_debug_enable(); cpu_exit_clear(cpu); (*dead_idle)(); } /* Allow the master to continue. */ set_cpu_state(CPU_STATE_CALLIN); synchronize_tsc_slave(cpu); /* And wait for our final Ack. */ while ( cpu_state != CPU_STATE_ONLINE ) cpu_relax(); } static int booting_cpu; /* CPUs for which sibling maps can be computed. */ static cpumask_t cpu_sibling_setup_map; static void link_thread_siblings(int cpu1, int cpu2) { cpumask_set_cpu(cpu1, per_cpu(cpu_sibling_mask, cpu2)); cpumask_set_cpu(cpu2, per_cpu(cpu_sibling_mask, cpu1)); cpumask_set_cpu(cpu1, per_cpu(cpu_core_mask, cpu2)); cpumask_set_cpu(cpu2, per_cpu(cpu_core_mask, cpu1)); } static void set_cpu_sibling_map(int cpu) { int i; struct cpuinfo_x86 *c = cpu_data; cpumask_set_cpu(cpu, &cpu_sibling_setup_map); if ( c[cpu].x86_num_siblings > 1 ) { for_each_cpu ( i, &cpu_sibling_setup_map ) { if ( cpu_has(c, X86_FEATURE_TOPOEXT) ) { if ( (c[cpu].phys_proc_id == c[i].phys_proc_id) && (c[cpu].compute_unit_id == c[i].compute_unit_id) ) link_thread_siblings(cpu, i); } else if ( (c[cpu].phys_proc_id == c[i].phys_proc_id) && (c[cpu].cpu_core_id == c[i].cpu_core_id) ) { link_thread_siblings(cpu, i); } } } else { cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu)); } if ( c[cpu].x86_max_cores == 1 ) { cpumask_copy(per_cpu(cpu_core_mask, cpu), per_cpu(cpu_sibling_mask, cpu)); c[cpu].booted_cores = 1; return; } for_each_cpu ( i, &cpu_sibling_setup_map ) { if ( c[cpu].phys_proc_id == c[i].phys_proc_id ) { cpumask_set_cpu(i, per_cpu(cpu_core_mask, cpu)); cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, i)); /* * Does this new cpu bringup a new core? */ if ( cpumask_weight(per_cpu(cpu_sibling_mask, cpu)) == 1 ) { /* * for each core in package, increment * the booted_cores for this new cpu */ if ( cpumask_first(per_cpu(cpu_sibling_mask, i)) == i ) c[cpu].booted_cores++; /* * increment the core count for all * the other cpus in this package */ if ( i != cpu ) c[i].booted_cores++; } else if ( (i != cpu) && !c[cpu].booted_cores ) { c[cpu].booted_cores = c[i].booted_cores; } } } } static void construct_percpu_idt(unsigned int cpu) { unsigned char idt_load[10]; *(unsigned short *)(&idt_load[0]) = (IDT_ENTRIES*sizeof(idt_entry_t))-1; *(unsigned long *)(&idt_load[2]) = (unsigned long)idt_tables[cpu]; __asm__ __volatile__ ( "lidt %0" : "=m" (idt_load) ); } void start_secondary(void *unused) { /* * Dont put anything before smp_callin(), SMP booting is so fragile that we * want to limit the things done here to the most necessary things. */ unsigned int cpu = booting_cpu; set_processor_id(cpu); set_current(idle_vcpu[cpu]); this_cpu(curr_vcpu) = idle_vcpu[cpu]; if ( cpu_has_efer ) rdmsrl(MSR_EFER, this_cpu(efer)); asm volatile ( "mov %%cr4,%0" : "=r" (this_cpu(cr4)) ); /* * Just as during early bootstrap, it is convenient here to disable * spinlock checking while we have IRQs disabled. This allows us to * acquire IRQ-unsafe locks when it would otherwise be disallowed. * * It is safe because the race we are usually trying to avoid involves * a group of CPUs rendezvousing in an IPI handler, where one cannot * join because it is spinning with IRQs disabled waiting to acquire a * lock held by another in the rendezvous group (the lock must be an * IRQ-unsafe lock since the CPU took the IPI after acquiring it, and * hence had IRQs enabled). This is a deadlock scenario. * * However, no CPU can be involved in rendezvous until it is online, * hence no such group can be waiting for this CPU until it is * visible in cpu_online_map. Hence such a deadlock is not possible. */ spin_debug_disable(); percpu_traps_init(); cpu_init(); smp_callin(); /* * At this point, boot CPU has fully initialised the IDT. It is * now safe to make ourselves a private copy. */ construct_percpu_idt(cpu); setup_secondary_APIC_clock(); /* * low-memory mappings have been cleared, flush them from * the local TLBs too. */ flush_tlb_local(); /* This must be done before setting cpu_online_map */ spin_debug_enable(); set_cpu_sibling_map(cpu); notify_cpu_starting(cpu); wmb(); /* * We need to hold vector_lock so there the set of online cpus * does not change while we are assigning vectors to cpus. Holding * this lock ensures we don't half assign or remove an irq from a cpu. */ lock_vector_lock(); __setup_vector_irq(cpu); cpumask_set_cpu(cpu, &cpu_online_map); unlock_vector_lock(); init_percpu_time(); /* We can take interrupts now: we're officially "up". */ local_irq_enable(); mtrr_ap_init(); microcode_resume_cpu(cpu); wmb(); startup_cpu_idle_loop(); } extern struct { void * esp; unsigned short ss; } stack_start; static int wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip) { unsigned long send_status = 0, accept_status = 0; int maxlvt, timeout, num_starts, i; /* * Be paranoid about clearing APIC errors. */ if ( APIC_INTEGRATED(apic_version[phys_apicid]) ) { apic_read_around(APIC_SPIV); apic_write(APIC_ESR, 0); apic_read(APIC_ESR); } Dprintk("Asserting INIT.\n"); /* * Turn INIT on target chip via IPI */ apic_icr_write(APIC_INT_LEVELTRIG | APIC_INT_ASSERT | APIC_DM_INIT, phys_apicid); if ( !x2apic_enabled ) { Dprintk("Waiting for send to finish...\n"); timeout = 0; do { Dprintk("+"); udelay(100); send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY; } while ( send_status && (timeout++ < 1000) ); mdelay(10); Dprintk("Deasserting INIT.\n"); apic_icr_write(APIC_INT_LEVELTRIG | APIC_DM_INIT, phys_apicid); Dprintk("Waiting for send to finish...\n"); timeout = 0; do { Dprintk("+"); udelay(100); send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY; } while ( send_status && (timeout++ < 1000) ); } else if ( tboot_in_measured_env() ) { /* * With tboot AP is actually spinning in a mini-guest before * receiving INIT. Upon receiving INIT ipi, AP need time to VMExit, * update VMCS to tracking SIPIs and VMResume. * * While AP is in root mode handling the INIT the CPU will drop * any SIPIs */ udelay(10); } /* * Should we send STARTUP IPIs ? * * Determine this based on the APIC version. * If we don't have an integrated APIC, don't send the STARTUP IPIs. */ num_starts = APIC_INTEGRATED(apic_version[phys_apicid]) ? 2 : 0; /* Run STARTUP IPI loop. */ Dprintk("#startup loops: %d.\n", num_starts); maxlvt = get_maxlvt(); for ( i = 0; i < num_starts; i++ ) { Dprintk("Sending STARTUP #%d.\n", i+1); apic_read_around(APIC_SPIV); apic_write(APIC_ESR, 0); apic_read(APIC_ESR); Dprintk("After apic_write.\n"); /* * STARTUP IPI * Boot on the stack */ apic_icr_write(APIC_DM_STARTUP | (start_eip >> 12), phys_apicid); if ( !x2apic_enabled ) { /* Give the other CPU some time to accept the IPI. */ udelay(300); Dprintk("Startup point 1.\n"); Dprintk("Waiting for send to finish...\n"); timeout = 0; do { Dprintk("+"); udelay(100); send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY; } while ( send_status && (timeout++ < 1000) ); /* Give the other CPU some time to accept the IPI. */ udelay(200); } /* Due to the Pentium erratum 3AP. */ if ( maxlvt > 3 ) { apic_read_around(APIC_SPIV); apic_write(APIC_ESR, 0); } accept_status = (apic_read(APIC_ESR) & 0xEF); if ( send_status || accept_status ) break; } Dprintk("After Startup.\n"); if ( send_status ) printk("APIC never delivered???\n"); if ( accept_status ) printk("APIC delivery error (%lx).\n", accept_status); return (send_status | accept_status); } int alloc_cpu_id(void) { cpumask_t tmp_map; int cpu; cpumask_complement(&tmp_map, &cpu_present_map); cpu = cpumask_first(&tmp_map); return (cpu < nr_cpu_ids) ? cpu : -ENODEV; } static int do_boot_cpu(int apicid, int cpu) { int timeout, boot_error = 0, rc = 0; unsigned long start_eip; /* * Save current MTRR state in case it was changed since early boot * (e.g. by the ACPI SMI) to initialize new CPUs with MTRRs in sync: */ mtrr_save_state(); booting_cpu = cpu; /* start_eip had better be page-aligned! */ start_eip = setup_trampoline(); /* So we see what's up */ if ( opt_cpu_info ) printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip); stack_start.esp = stack_base[cpu]; /* This grunge runs the startup process for the targeted processor. */ set_cpu_state(CPU_STATE_INIT); Dprintk("Setting warm reset code and vector.\n"); smpboot_setup_warm_reset_vector(start_eip); /* Starting actual IPI sequence... */ if ( !tboot_in_measured_env() || tboot_wake_ap(apicid, start_eip) ) boot_error = wakeup_secondary_cpu(apicid, start_eip); if ( !boot_error ) { /* Allow AP to start initializing. */ set_cpu_state(CPU_STATE_CALLOUT); Dprintk("After Callout %d.\n", cpu); /* Wait 5s total for a response. */ for ( timeout = 0; timeout < 50000; timeout++ ) { if ( cpu_state != CPU_STATE_CALLOUT ) break; udelay(100); } if ( cpu_state == CPU_STATE_CALLIN ) { /* number CPUs logically, starting from 1 (BSP is 0) */ Dprintk("OK.\n"); print_cpu_info(cpu); synchronize_tsc_master(cpu); Dprintk("CPU has booted.\n"); } else if ( cpu_state == CPU_STATE_DEAD ) { rmb(); rc = cpu_error; } else { boot_error = 1; mb(); if ( bootsym(trampoline_cpu_started) == 0xA5 ) /* trampoline started but...? */ printk("Stuck ??\n"); else /* trampoline code not run */ printk("Not responding.\n"); } } if ( boot_error ) { cpu_exit_clear(cpu); rc = -EIO; } /* mark "stuck" area as not stuck */ bootsym(trampoline_cpu_started) = 0; mb(); smpboot_restore_warm_reset_vector(); return rc; } void cpu_exit_clear(unsigned int cpu) { cpu_uninit(cpu); set_cpu_state(CPU_STATE_DEAD); } static void cpu_smpboot_free(unsigned int cpu) { unsigned int order; free_cpumask_var(per_cpu(cpu_sibling_mask, cpu)); free_cpumask_var(per_cpu(cpu_core_mask, cpu)); order = get_order_from_pages(NR_RESERVED_GDT_PAGES); free_xenheap_pages(per_cpu(gdt_table, cpu), order); free_xenheap_pages(per_cpu(compat_gdt_table, cpu), order); order = get_order_from_bytes(IDT_ENTRIES * sizeof(idt_entry_t)); free_xenheap_pages(idt_tables[cpu], order); idt_tables[cpu] = NULL; if ( stack_base[cpu] != NULL ) { memguard_unguard_stack(stack_base[cpu]); free_xenheap_pages(stack_base[cpu], STACK_ORDER); stack_base[cpu] = NULL; } } static int cpu_smpboot_alloc(unsigned int cpu) { unsigned int order; struct desc_struct *gdt; stack_base[cpu] = alloc_xenheap_pages(STACK_ORDER, 0); if ( stack_base[cpu] == NULL ) goto oom; memguard_guard_stack(stack_base[cpu]); order = get_order_from_pages(NR_RESERVED_GDT_PAGES); per_cpu(gdt_table, cpu) = gdt = alloc_xenheap_pages(order, MEMF_node(cpu_to_node(cpu))); if ( gdt == NULL ) goto oom; memcpy(gdt, boot_cpu_gdt_table, NR_RESERVED_GDT_PAGES * PAGE_SIZE); BUILD_BUG_ON(NR_CPUS > 0x10000); gdt[PER_CPU_GDT_ENTRY - FIRST_RESERVED_GDT_ENTRY].a = cpu; per_cpu(compat_gdt_table, cpu) = gdt = alloc_xenheap_pages(order, MEMF_node(cpu_to_node(cpu))); if ( gdt == NULL ) goto oom; memcpy(gdt, boot_cpu_compat_gdt_table, NR_RESERVED_GDT_PAGES * PAGE_SIZE); gdt[PER_CPU_GDT_ENTRY - FIRST_RESERVED_GDT_ENTRY].a = cpu; order = get_order_from_bytes(IDT_ENTRIES * sizeof(idt_entry_t)); idt_tables[cpu] = alloc_xenheap_pages(order, MEMF_node(cpu_to_node(cpu))); if ( idt_tables[cpu] == NULL ) goto oom; memcpy(idt_tables[cpu], idt_table, IDT_ENTRIES * sizeof(idt_entry_t)); if ( zalloc_cpumask_var(&per_cpu(cpu_sibling_mask, cpu)) && zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) ) return 0; oom: cpu_smpboot_free(cpu); return -ENOMEM; } static int cpu_smpboot_callback( struct notifier_block *nfb, unsigned long action, void *hcpu) { unsigned int cpu = (unsigned long)hcpu; int rc = 0; switch ( action ) { case CPU_UP_PREPARE: rc = cpu_smpboot_alloc(cpu); break; case CPU_UP_CANCELED: case CPU_DEAD: cpu_smpboot_free(cpu); break; default: break; } return !rc ? NOTIFY_DONE : notifier_from_errno(rc); } static struct notifier_block cpu_smpboot_nfb = { .notifier_call = cpu_smpboot_callback }; void __init smp_prepare_cpus(unsigned int max_cpus) { register_cpu_notifier(&cpu_smpboot_nfb); mtrr_aps_sync_begin(); /* Setup boot CPU information */ smp_store_cpu_info(0); /* Final full version of the data */ print_cpu_info(0); boot_cpu_physical_apicid = get_apic_id(); x86_cpu_to_apicid[0] = boot_cpu_physical_apicid; stack_base[0] = stack_start.esp; if ( !zalloc_cpumask_var(&per_cpu(cpu_sibling_mask, 0)) || !zalloc_cpumask_var(&per_cpu(cpu_core_mask, 0)) ) panic("No memory for boot CPU sibling/core maps\n"); set_cpu_sibling_map(0); /* * If we couldn't find an SMP configuration at boot time, * get out of here now! */ if ( !smp_found_config && !acpi_lapic ) { printk(KERN_NOTICE "SMP motherboard not detected.\n"); init_uniprocessor: physids_clear(phys_cpu_present_map); physid_set(0, phys_cpu_present_map); if (APIC_init_uniprocessor()) printk(KERN_NOTICE "Local APIC not detected." " Using dummy APIC emulation.\n"); return; } /* * Should not be necessary because the MP table should list the boot * CPU too, but we do it for the sake of robustness anyway. * Makes no sense to do this check in clustered apic mode, so skip it */ if ( !check_apicid_present(boot_cpu_physical_apicid) ) { printk("weird, boot CPU (#%d) not listed by the BIOS.\n", boot_cpu_physical_apicid); physid_set(hard_smp_processor_id(), phys_cpu_present_map); } /* If we couldn't find a local APIC, then get out of here now! */ if ( APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) && !cpu_has_apic ) { printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n", boot_cpu_physical_apicid); goto init_uniprocessor; } verify_local_APIC(); connect_bsp_APIC(); setup_local_APIC(); smpboot_setup_io_apic(); setup_boot_APIC_clock(); } void __init smp_prepare_boot_cpu(void) { cpumask_set_cpu(smp_processor_id(), &cpu_online_map); cpumask_set_cpu(smp_processor_id(), &cpu_present_map); } static void remove_siblinginfo(int cpu) { int sibling; struct cpuinfo_x86 *c = cpu_data; for_each_cpu ( sibling, per_cpu(cpu_core_mask, cpu) ) { cpumask_clear_cpu(cpu, per_cpu(cpu_core_mask, sibling)); /* Last thread sibling in this cpu core going down. */ if ( cpumask_weight(per_cpu(cpu_sibling_mask, cpu)) == 1 ) c[sibling].booted_cores--; } for_each_cpu(sibling, per_cpu(cpu_sibling_mask, cpu)) cpumask_clear_cpu(cpu, per_cpu(cpu_sibling_mask, sibling)); cpumask_clear(per_cpu(cpu_sibling_mask, cpu)); cpumask_clear(per_cpu(cpu_core_mask, cpu)); c[cpu].phys_proc_id = BAD_APICID; c[cpu].cpu_core_id = BAD_APICID; c[cpu].compute_unit_id = BAD_APICID; cpumask_clear_cpu(cpu, &cpu_sibling_setup_map); } void __cpu_disable(void) { int cpu = smp_processor_id(); set_cpu_state(CPU_STATE_DYING); local_irq_disable(); clear_local_APIC(); /* Allow any queued timer interrupts to get serviced */ local_irq_enable(); mdelay(1); local_irq_disable(); time_suspend(); remove_siblinginfo(cpu); /* It's now safe to remove this processor from the online map */ cpumask_clear_cpu(cpu, cpupool0->cpu_valid); cpumask_clear_cpu(cpu, &cpu_online_map); fixup_irqs(); if ( cpu_disable_scheduler(cpu) ) BUG(); } void __cpu_die(unsigned int cpu) { /* We don't do anything here: idle task is faking death itself. */ unsigned int i = 0; enum cpu_state seen_state; while ( (seen_state = cpu_state) != CPU_STATE_DEAD ) { BUG_ON(seen_state != CPU_STATE_DYING); mdelay(100); cpu_relax(); process_pending_softirqs(); if ( (++i % 10) == 0 ) printk(KERN_ERR "CPU %u still not dead...\n", cpu); } } int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm) { int node, cpu = -1; dprintk(XENLOG_DEBUG, "cpu_add apic_id %x acpi_id %x pxm %x\n", apic_id, acpi_id, pxm); if ( (acpi_id >= MAX_MADT_ENTRIES) || (apic_id >= MAX_APICS) || (pxm >= 256) ) return -EINVAL; if ( !cpu_hotplug_begin() ) return -EBUSY; /* Detect if the cpu has been added before */ if ( x86_acpiid_to_apicid[acpi_id] != BAD_APICID ) { cpu = (x86_acpiid_to_apicid[acpi_id] != apic_id) ? -EINVAL : -EEXIST; goto out; } if ( physid_isset(apic_id, phys_cpu_present_map) ) { cpu = -EEXIST; goto out; } if ( (cpu = mp_register_lapic(apic_id, 1, 1)) < 0 ) goto out; x86_acpiid_to_apicid[acpi_id] = apic_id; if ( !srat_disabled() ) { if ( (node = setup_node(pxm)) < 0 ) { dprintk(XENLOG_WARNING, "Setup node failed for pxm %x\n", pxm); x86_acpiid_to_apicid[acpi_id] = BAD_APICID; mp_unregister_lapic(apic_id, cpu); cpu = node; goto out; } apicid_to_node[apic_id] = node; } /* Physically added CPUs do not have synchronised TSC. */ if ( boot_cpu_has(X86_FEATURE_TSC_RELIABLE) ) { static bool_t once_only; if ( !test_and_set_bool(once_only) ) printk(XENLOG_WARNING " ** New physical CPU %u may have skewed TSC and hence " "break assumed cross-CPU TSC coherency.\n" " ** Consider using boot parameter \"tsc=skewed\" " "which forces TSC emulation where appropriate.\n", cpu); cpumask_set_cpu(cpu, &tsc_sync_cpu_mask); } srat_detect_node(cpu); numa_add_cpu(cpu); dprintk(XENLOG_INFO, "Add CPU %x with index %x\n", apic_id, cpu); out: cpu_hotplug_done(); return cpu; } int __cpu_up(unsigned int cpu) { int apicid, ret; if ( (apicid = x86_cpu_to_apicid[cpu]) == BAD_APICID ) return -ENODEV; if ( (ret = do_boot_cpu(apicid, cpu)) != 0 ) return ret; set_cpu_state(CPU_STATE_ONLINE); while ( !cpu_online(cpu) ) { cpu_relax(); process_pending_softirqs(); } return 0; } void __init smp_cpus_done(void) { /* * Don't taint if we are running SMP kernel on a single non-MP * approved Athlon */ if ( tainted & TAINT_UNSAFE_SMP ) { if ( num_online_cpus() > 1 ) printk(KERN_INFO "WARNING: This combination of AMD " "processors is not suitable for SMP.\n"); else tainted &= ~TAINT_UNSAFE_SMP; } if ( nmi_watchdog == NMI_LOCAL_APIC ) check_nmi_watchdog(); setup_ioapic_dest(); mtrr_save_state(); mtrr_aps_sync_end(); } void __init smp_intr_init(void) { int irq, vector, seridx, cpu = smp_processor_id(); /* * IRQ0 must be given a fixed assignment and initialized, * because it's used before the IO-APIC is set up. */ irq_to_desc(0)->arch.vector = IRQ0_VECTOR; /* * Also ensure serial interrupts are high priority. We do not * want them to be blocked by unacknowledged guest-bound interrupts. */ for ( seridx = 0; seridx <= SERHND_IDX; seridx++ ) { if ( (irq = serial_irq(seridx)) < 0 ) continue; vector = alloc_hipriority_vector(); per_cpu(vector_irq, cpu)[vector] = irq; irq_to_desc(irq)->arch.vector = vector; cpumask_copy(irq_to_desc(irq)->arch.cpu_mask, &cpu_online_map); } /* Direct IPI vectors. */ set_direct_apic_vector(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt); set_direct_apic_vector(EVENT_CHECK_VECTOR, event_check_interrupt); set_direct_apic_vector(INVALIDATE_TLB_VECTOR, invalidate_interrupt); set_direct_apic_vector(CALL_FUNCTION_VECTOR, call_function_interrupt); }
YongMan/Xen-4.3.1
xen/arch/x86/smpboot.c
C
gpl-2.0
28,588
/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved. * * This program and the accompanying materials are made available under * the terms of the Common Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/cpl-v10.html * * $Id: IItem.java,v 1.1.1.1.2.1 2005/06/12 22:43:11 vlad_r Exp $ */ package com.vladium.emma.report; import java.util.Iterator; // ---------------------------------------------------------------------------- /** * @author Vlad Roubtsov, (C) 2003 */ public interface IItem { // public: ................................................................ // TODO: consider making this an abstact class [merge into Item] // note: this design does not enforce all items at the same level being of the same 'type' (class, pkg, method, etc) IItem getParent (); int getChildCount (); Iterator /* IItem */ getChildren (); /** * * @param order [null is equivalent to no sort] * @return */ Iterator /* IItem */ getChildren (ItemComparator /* IItem */ order); String getName (); IItemMetadata getMetadata (); IItemAttribute getAttribute (int attributeID, int unitsID); int getAggregate (int type); void accept (IItemVisitor visitor, Object ctx); // TODO: move these elsewhere and fix gaps // WARNING: careful about reordering! // (coverage data) measured in counts: int COVERAGE_CLASS_COUNT = 5; // count of class loads int COVERAGE_METHOD_COUNT = 4; // count of method entries // (coverage data) measured in counts or instrs: int COVERAGE_BLOCK_COUNT = 0; // in count units int COVERAGE_LINE_COUNT = 1; // in count units int COVERAGE_BLOCK_INSTR = 2; // in instr units int COVERAGE_LINE_INSTR = 3; // total line instr coverage, scaled up by PRECISION // (metadata) measured in counts: int TOTAL_CLASS_COUNT = 11; int TOTAL_METHOD_COUNT = 10; // (metadata) measured in counts or instrs: int TOTAL_BLOCK_COUNT = 6; // in count units int TOTAL_LINE_COUNT = 7; // in count units int TOTAL_BLOCK_INSTR = 8; // in instr units //int TOTAL_LINE_INSTR = 9; // in instr units int TOTAL_SRCFILE_COUNT = 12; //int TOTAL_SRCLINE_COUNT = 13; int NUM_OF_AGGREGATES = TOTAL_SRCFILE_COUNT + 1; int PRECISION = 100; // BUG_SF988160: increase overflow safety margin for very large projects } // end of interface // ----------------------------------------------------------------------------
rex-xxx/mt6572_x201
external/emma/core/java12/com/vladium/emma/report/IItem.java
Java
gpl-2.0
2,751
<?php $this->attendees_table->prepare_items(); $event_id = isset( $_GET['event_id'] ) ? intval( $_GET['event_id'] ) : 0; $event = get_post( $event_id ); $tickets = Tribe__Events__Tickets__Tickets::get_event_tickets( $event_id ); ?> <div class="wrap"> <div id="icon-edit" class="icon32 icon32-tickets-attendees"><br></div> <h2><?php esc_html_e( 'Attendees', 'tribe-events-calendar' ); ?></h2> <h2><?php echo $event->post_title; ?></h2> <div id="tribe-filters" class="metabox-holder"> <div id="filters-wrap" class="postbox"> <h3 title="Click to toggle"><?php esc_html_e( 'Event Summary', 'tribe-events-calendar' ); ?></h3> <table class="eventtable ticket_list"> <tr> <td width="33%" valign="top"> <h4><?php esc_html_e( 'Event Details', 'tribe-events-calendar' ); ?></h4> <strong><?php esc_html_e( 'Start Date / Time:', 'tribe-events-calendar' ) ?></strong> <?php echo tribe_get_start_date( $event_id, false, tribe_get_datetime_format( true ) ) ?> <br /> <strong><?php esc_html_e( 'End Date / Time:', 'tribe-events-calendar' ) ?></strong> <?php echo tribe_get_end_date( $event_id, false, tribe_get_datetime_format( true ) ) ?> <?php // venue $venue_id = tribe_get_venue_id( $event_id ); if ( ! empty( $venue_id ) ) { $venue = get_post( $venue_id ); } if ( ! empty( $venue ) ) : ?> <br /> <strong> <?php echo tribe_get_venue_label_singular() ?> </strong> <?php echo $venue->post_title; ?> <?php // phone $phone = get_post_meta( $venue_id, '_VenuePhone', true ); if ( ! empty( $phone ) ) : ?> <br /> <strong><?php esc_html_e( 'Phone:', 'tribe-events-calendar' ); ?></strong> <?php echo esc_html( $phone ); endif; ?> <?php // website $website = get_post_meta( $venue_id, '_VenueURL', true ); if ( ! empty( $website ) ) : ?> <br /> <strong><?php esc_html_e( 'Website:', 'tribe-events-calendar' ) ?></strong> <a target="_blank" href="<?php echo esc_url( $website ) ?>"><?php echo esc_html( $website ) ?></a> <?php endif; ?> <?php endif; // if ( $venue ) ?> </td> <td width="33%" valign="top"> <h4><?php esc_html_e( 'Ticket Sales', 'tribe-events-calendar' ); ?></h4> <?php $total_sold = 0; $total_pending = 0; foreach ( $tickets as $ticket ) : ?> <strong><?php echo esc_html( $ticket->name ) ?>: </strong> <?php $stock = $ticket->stock; $sold = ! empty ( $ticket->qty_sold ) ? $ticket->qty_sold : 0; $pending = ''; if ( $ticket->qty_pending > 0 ) { $pending = sprintf( _n( '(%d awaiting review)', '(%d awaiting review)', 'tribe-events-calendar', $ticket->qty_pending ), (int) $ticket->qty_pending ); } if ( empty( $stock ) && $stock !== 0 ) { echo sprintf( __( 'Sold %d %s', 'tribe-events-calendar' ), esc_html( $sold ), $pending ); } else { echo sprintf( __( 'Sold %d of %d %s', 'tribe-events-calendar' ), esc_html( $sold ), esc_html( $sold + $stock ), $pending ); } echo '<br />'; $total_sold += $sold; $total_pending += $ticket->qty_pending; $total_completed = $total_sold - $total_pending; endforeach; ?> </td> <td width="33%" valign="middle"> <div class="totals"> <?php $checkedin = Tribe__Events__Tickets__Tickets::get_event_checkedin_attendees_count( $event_id ); ?> <span id="total_tickets_sold_wrapper"> <?php esc_html_e( 'Tickets sold:', 'tribe-events-calendar' ) ?> <span id="total_tickets_sold"><?php echo $total_sold ?></span> </span> <?php if ( $total_pending > 0 ) : ?> <span id="sales_breakdown_wrapper"> <br /> <?php esc_html_e( 'Finalized:', 'tribe-events-calendar' ); ?> <span id="total_issued"><?php echo $total_completed ?></span> <?php esc_html_e( 'Awaiting review:', 'tribe-events-calendar' ); ?> <span id="total_pending"><?php echo $total_pending ?></span> </span> <?php endif ?> <span id="total_checkedin_wrapper"> <br /> <?php esc_html_e( 'Checked in:', 'tribe-events-calendar' ); ?> <span id="total_checkedin"><?php echo $checkedin ?></span> </span> </div> </td> </tr> </table> </div> </div> <form id="topics-filter" method="post"> <input type="hidden" name="page" value="<?php echo esc_attr( $_GET['page'] ); ?>" /> <input type="hidden" name="event_id" id="event_id" value="<?php echo esc_attr( $event_id ); ?>" /> <input type="hidden" name="post_type" value="<?php echo esc_attr( Tribe__Events__Main::POSTTYPE ); ?>" /> <?php $this->attendees_table->display() ?> </form> <div id="attendees_email_wrapper" title="<?php esc_html_e( 'Send the attendee list by email', 'tribe-events-calendar' ); ?>"> <div id="email_errors"></div> <div id="email_send"> <label for="email_to_user"> <span><?php esc_html_e( 'Select a User:', 'tribe-events-calendar' ); ?></span> <?php wp_dropdown_users( array( 'name' => 'email_to_user', 'id' => 'email_to_user', 'show_option_none' => __( 'Select...', 'tribe-events-calendar' ), 'selected' => '', ) ); ?> </label> <span class="attendees_or"><?php esc_html_e( 'or', 'tribe-events-calendar' ); ?></span> <label for="email_to_address"> <span><?php esc_html_e( 'Email Address:', 'tribe-events-calendar' ); ?></span> <input type="text" name="email_to_address" id="email_to_address" value=""> </label> </div> <div id="email_response"></div> </div> </div>
sondang86/mySite
wp-content/plugins/the-events-calendar/src/admin-views/tickets/attendees.php
PHP
gpl-2.0
5,780
describe("Ext.Editor", function() { var editor, field, target; function makeEditor(cfg) { editor = new Ext.Editor(cfg); field = editor.field; } function makeTarget(cfg) { target = Ext.getBody().createChild(Ext.apply({ tag: 'span', html: 'Sample Text' }, cfg)); } afterEach(function() { Ext.destroy(editor, target); target = field = editor = null; }); function startEditWithTarget(value) { makeTarget(); if (arguments.length) { editor.startEdit(target, value); } else { editor.startEdit(target); } } function fireKeyOnField(key) { jasmine.fireKeyEvent(field.inputEl, 'keydown', key); } describe("field creation", function() { it("should create a text field by default", function() { makeEditor(); expect(field.$className).toBe('Ext.form.field.Text'); }); it("should accept a string xtype", function() { makeEditor({ field: 'datefield' }); expect(field.$className).toBe('Ext.form.field.Date'); }); it("should accept a config without xtype and default to a text field", function() { makeEditor({ field: { maxLength: 10 } }); expect(field.$className).toBe('Ext.form.field.Text'); expect(field.maxLength).toBe(10); }); it("should accept an object config including xtype", function() { makeEditor({ field: { xtype: 'numberfield', maxValue: 20 } }); expect(field.$className).toBe('Ext.form.field.Number'); expect(field.maxValue).toBe(20); }); }); describe("getValue/setValue", function() { it("should get the value from the underlying field", function() { makeEditor(); startEditWithTarget(); editor.field.setValue('asdf'); expect(editor.getValue()).toBe('asdf'); }); it("should set the value on the underlying field", function() { makeEditor(); startEditWithTarget(); editor.setValue('foo'); expect(editor.getValue()).toBe('foo'); }); }); describe("startEdit", function() { describe("basic functionality", function() { it("should show the editor", function() { makeEditor(); startEditWithTarget(); expect(editor.isVisible()).toBe(true); }); it("should set the editing property to true", function() { makeEditor(); startEditWithTarget(); expect(editor.editing).toBe(true); }); // Only Webkit focusing is reliable in the test runner (Ext.isWebKit ? it : xit)("should focus the field", function() { makeEditor(); startEditWithTarget(); waitsFor(function() { return field.hasFocus; }, "Field never focused"); runs(function() { expect(field.hasFocus).toBe(true); }); }); it("should complete an existing edit when starting", function() { makeEditor({ updateEl: true }); startEditWithTarget(); editor.setValue('Foo'); editor.startEdit(target); expect(target.getHtml()).toBe('Foo'); }); }); describe("positioning", function() { it("should align to c-c as the default", function() { makeEditor(); startEditWithTarget(); expect(editor.getXY()).toEqual([0, 0]); }); it("should use another alignment", function() { // Top left of the field aligns to the bottom right of the target makeEditor({ alignment: 'tl-br' }); startEditWithTarget(); var size = target.getSize(); expect(editor.getXY()).toEqual([size.width, size.height]); }); it("should use offsets", function() { makeEditor({ alignment: 'tl-tl', offsets: [20, 30] }); startEditWithTarget(); expect(editor.getXY()).toEqual([20, 30]); }); it("should use a combination of alignment & offsets", function() { // Top left of the field aligns to the bottom right of the target makeEditor({ alignment: 'tl-br', offsets: [20, 30] }); startEditWithTarget(); var size = target.getSize(); expect(editor.getXY()).toEqual([size.width + 20, size.height + 30]); }); }); describe("boundEl", function() { it("should accept an Ext.dom.Element", function() { makeEditor(); makeTarget(); editor.startEdit(target); expect(field.getValue()).toBe('Sample Text'); }); it("should accept an HtmlElement", function() { makeEditor(); makeTarget(); editor.startEdit(target.dom); expect(field.getValue()).toBe('Sample Text'); }); it("should accept an id", function() { makeEditor(); makeTarget(); editor.startEdit(target.id); expect(field.getValue()).toBe('Sample Text'); }); }); describe("value", function() { it("should take the value from the element by default", function() { makeEditor(); startEditWithTarget(); expect(field.getValue()).toBe('Sample Text'); }); it("should use the passed value", function() { makeEditor(); startEditWithTarget('Foo'); expect(field.getValue()).toBe('Foo'); }); it("should retain the type of the passed value", function() { var d = new Date(); makeEditor({ field: 'datefield' }); spyOn(field, 'setValue'); startEditWithTarget(d); expect(field.setValue).toHaveBeenCalledWith(d); }); }); describe("the field", function() { it("should not fire the change event", function() { makeEditor(); var spy = jasmine.createSpy(); field.on('change', spy); startEditWithTarget(); expect(spy).not.toHaveBeenCalled(); }); it("should not be dirty", function() { makeEditor(); startEditWithTarget(); expect(field.isDirty()).toBe(false); }); }); describe("hideEl", function() { it("should hide the el with hideEl: true", function() { makeEditor({ hideEl: true }); startEditWithTarget(); expect(target.isVisible()).toBe(false); }); it("should not hide the el with hideEl: false", function() { makeEditor({ hideEl: false }); startEditWithTarget(); expect(target.isVisible()).toBe(true); }); }); describe("events", function() { var spy; beforeEach(function() { spy = jasmine.createSpy(); }); afterEach(function() { spy = null; }); it("should fire beforestartedit and pass the editor, boundEl & value", function() { makeEditor(); editor.on('beforestartedit', spy); startEditWithTarget(); expect(spy).toHaveBeenCalled(); var args = spy.mostRecentCall.args; expect(args[0]).toBe(editor); expect(args[1]).toBe(target); expect(args[2]).toBe('Sample Text'); }); it("should fire startedit and pass the editor, boundEl & value", function() { makeEditor(); editor.on('startedit', spy); startEditWithTarget(); expect(spy).toHaveBeenCalled(); var args = spy.mostRecentCall.args; expect(args[0]).toBe(editor); expect(args[1]).toBe(target); expect(args[2]).toBe('Sample Text'); }); it("should not show or set to editing if it returns false", function() { var editSpy = jasmine.createSpy(); makeEditor(); makeTarget(); editor.on('beforestartedit', spy.andReturn(false)); editor.on('startedit', editSpy); editor.startEdit(target); expect(editor.isVisible()).toBe(false); expect(editor.editing).toBe(false); expect(editSpy).not.toHaveBeenCalled(); }); }); }); describe("completeEdit", function() { it("should not cause an exception if not editing", function() { makeEditor(); expect(function() { editor.completeEdit(); }).not.toThrow(); }); it("should hide the editor and set editing to false", function() { makeEditor(); startEditWithTarget(); editor.completeEdit(); expect(editor.isVisible()).toBe(false); expect(editor.editing).toBe(false); }) describe("validity", function() { describe("with revertInvalid: false", function() { it("should not complete the edit if the field is not valid", function() { makeEditor({ revertInvalid: false, field: { allowBlank: false } }); startEditWithTarget(''); editor.completeEdit(); expect(editor.editing).toBe(true); expect(editor.isVisible()).toBe(true); expect(editor.getValue()).toBe(''); }); }); describe("with revertInvalid: true", function() { it("should cancel the edit if the field is not valid", function() { makeEditor({ revertInvalid: true, field: { allowBlank: false } }); startEditWithTarget(); field.setValue(''); editor.completeEdit(); expect(editor.getValue()).toBe('Sample Text'); expect(editor.editing).toBe(false); expect(editor.isVisible()).toBe(false); }); }); }); describe("hideEl", function() { it("should not show the boundEl if complete is vetoed with revertInvalid: false", function() { makeEditor({ revertInvalid: false, field: { allowBlank: false } }); startEditWithTarget(''); editor.completeEdit(); expect(target.isVisible()).toBe(false); }); it("should show the boundEl if complete is vetoed with revertInvalid: true", function() { makeEditor({ revertInvalid: true, field: { allowBlank: false } }); startEditWithTarget(''); editor.completeEdit(); expect(target.isVisible()).toBe(true); }); it("should show the boundEl if complete is successful", function() { makeEditor({ revertInvalid: true, field: { allowBlank: false } }); startEditWithTarget('Foo'); editor.completeEdit(); expect(target.isVisible()).toBe(true); }); }); describe("remainVisible", function() { it("should leave the editor visible with remainVisible", function() { makeEditor(); startEditWithTarget(); editor.completeEdit(true); expect(editor.isVisible()).toBe(true); expect(editor.editing).toBe(false); }); it("should leave the editor visible with remainVisible when the edit is cancelled for being invalid", function() { makeEditor({ revertInvalid: true, field: { allowBlank: true } }); startEditWithTarget(''); editor.completeEdit(true); expect(editor.isVisible()).toBe(true); expect(editor.editing).toBe(false); }); }); describe("updateEl", function() { it("should set the html if the boundEl with updateEl: true", function() { makeEditor({ updateEl: true }); startEditWithTarget('Foo'); editor.completeEdit(); expect(target.getHtml()).toBe('Foo'); }); it("should not set the html if the boundEl with updateEl: false", function() { makeEditor({ updateEl: false }); startEditWithTarget('Foo'); editor.completeEdit(); expect(target.getHtml()).toBe('Sample Text'); }); }); // FF randomly errors out on focus test in the test runner (Ext.isGecko ? xdescribe : describe)("allowBlur", function() { it("should not complete on blur with allowBlur: false", function() { makeEditor({ allowBlur: false }); startEditWithTarget(); spyOn(editor, 'completeEdit').andCallThrough(); waitsFor(function() { return field.hasFocus; }, "Field never focused"); runs(function() { // Programmatic blur fails on IEs. Focus then remove an input field Ext.getBody().createChild({tag: 'input', type: 'text'}).focus().remove(); }); waitsFor(function() { return !field.hasFocus; }, "Field never blurred"); runs(function() { expect(editor.completeEdit).not.toHaveBeenCalled(); }); }); it("should complete on blur with allowBlur: true", function() { makeEditor({ allowBlur: true }); startEditWithTarget(); spyOn(editor, 'completeEdit').andCallThrough(); waitsFor(function() { return field.hasFocus; }, "Field never focused"); runs(function() { // Programmatic blur fails on IEs. Focus then remove an input field Ext.getBody().createChild({tag: 'input', type: 'text'}).focus().remove(); }); waitsFor(function() { return !field.hasFocus; }, "Field never blurred"); runs(function() { expect(editor.completeEdit).toHaveBeenCalled(); }); }); }); // FF randomly errors out on focus test in the test runner (Ext.isGecko ? xdescribe : describe)("completeOnEnter", function() { it("should not complete on enter with completeOnEnter: false", function() { makeEditor({ completeOnEnter: false }); editor.specialKeyDelay = 0; startEditWithTarget(); spyOn(editor, 'completeEdit').andCallThrough(); waitsFor(function() { return field.hasFocus; }, "Field never focused"); runs(function() { fireKeyOnField(Ext.event.Event.ENTER); expect(editor.completeEdit).not.toHaveBeenCalled(); }); }); it("should complete on enter with completeOnEnter: true", function() { makeEditor({ completeOnEnter: true }); editor.specialKeyDelay = 0; startEditWithTarget(); spyOn(editor, 'completeEdit').andCallThrough(); waitsFor(function() { return field.hasFocus; }, "Field never focused"); runs(function() { fireKeyOnField(Ext.event.Event.ENTER); expect(editor.completeEdit).toHaveBeenCalled(); }); }); }); describe("events", function() { var spy; beforeEach(function() { spy = jasmine.createSpy(); }); afterEach(function() { spy = null; }); it("should fire beforecomplete & pass the editor, value & start value", function() { makeEditor(); editor.on('beforecomplete', spy); startEditWithTarget(); field.setValue('ASDF'); editor.completeEdit(); expect(spy).toHaveBeenCalled(); var args = spy.mostRecentCall.args; expect(args[0]).toBe(editor); expect(args[1]).toBe('ASDF'); expect(args[2]).toBe('Sample Text'); }); it("should fire the complete event & pass the editor, value & start value", function() { makeEditor(); editor.on('complete', spy); startEditWithTarget(); field.setValue('ASDF'); editor.completeEdit(); expect(spy).toHaveBeenCalled(); var args = spy.mostRecentCall.args; expect(args[0]).toBe(editor); expect(args[1]).toBe('ASDF'); expect(args[2]).toBe('Sample Text'); }); it("should not fire beforecomplete/complete if not editing", function() { makeEditor(); editor.on('beforecomplete', spy); editor.on('complete', spy); editor.completeEdit(); expect(spy).not.toHaveBeenCalled(); }); describe("vetoing beforecomplete", function() { it("should not fire complete", function() { var completeSpy = jasmine.createSpy(); makeEditor(); editor.on('beforecomplete', spy.andReturn(false)); editor.on('complete', completeSpy); startEditWithTarget('Value'); editor.completeEdit(); expect(completeSpy).not.toHaveBeenCalled(); }); it("should not update the boundEl", function() { makeEditor(); editor.on('beforecomplete', spy.andReturn(false)); startEditWithTarget('Value'); editor.completeEdit(); expect(target.getHtml()).toBe('Sample Text'); }); }); describe("invalid values", function() { it("should not fire beforecomplete/complete if the value is invalid with revertInvalid: false", function() { makeEditor({ revertInvalid: false, field: { allowBlank: false } }); editor.on('beforecomplete', spy); editor.on('complete', spy); startEditWithTarget(''); editor.completeEdit(); expect(spy).not.toHaveBeenCalled(); }); it("should not fire beforecomplete/complete if the value is invalid with revertInvalid: true", function() { makeEditor({ revertInvalid: true, field: { allowBlank: false } }); editor.on('beforecomplete', spy); editor.on('complete', spy); startEditWithTarget(''); editor.completeEdit(); expect(spy).not.toHaveBeenCalled(); }); }); describe("ignoreNoChange", function() { it("should not fire beforecomplete/complete if the value did not change with ignoreNoChange: true", function() { makeEditor({ ignoreNoChange: true }); editor.on('beforecomplete', spy); editor.on('complete', spy); startEditWithTarget(); editor.completeEdit(); expect(spy).not.toHaveBeenCalled(); }); it("should fire beforecomplete/complete if the value did not change with ignoreNoChange: true", function() { var completeSpy = jasmine.createSpy(); makeEditor({ ignoreNoChange: false }); editor.on('beforecomplete', spy); editor.on('complete', completeSpy); startEditWithTarget(); editor.completeEdit(); expect(spy).toHaveBeenCalled(); expect(completeSpy).toHaveBeenCalled(); }); }); }); }); describe("cancelEdit", function() { it("should not cause an error when not editing", function() { makeEditor(); expect(function() { editor.cancelEdit(); }).not.toThrow(); }); it("should hide the editor & set editing to false", function() { makeEditor(); startEditWithTarget(); editor.cancelEdit(); expect(editor.isVisible()).toBe(false); expect(editor.editing).toBe(false); }); it("should set the original value on the field and not fire the change event", function() { makeEditor(); startEditWithTarget(); editor.setValue('Foo'); var spy = jasmine.createSpy(); field.on('change', spy); editor.cancelEdit(); expect(editor.getValue()).toBe('Sample Text'); expect(spy).not.toHaveBeenCalled(); }); describe("with updateEl", function() { it("should not update the boundEl", function() { makeEditor(); startEditWithTarget(); editor.setValue('Foo') editor.cancelEdit(); expect(target.getHtml()).toBe('Sample Text'); }); }); // FF randomly errors out on focus test in the test runner (Ext.isGecko ? xdescribe : describe)("cancelOnEsc", function() { it("should not cancel on esc key with cancelOnEsc: false", function() { makeEditor({ cancelOnEsc: false }); editor.specialKeyDelay = 0; startEditWithTarget(); spyOn(editor, 'cancelEdit').andCallThrough(); waitsFor(function() { return field.hasFocus; }, "Field never focused"); runs(function() { fireKeyOnField(Ext.event.Event.ESC); expect(editor.cancelEdit).not.toHaveBeenCalled(); }); }); it("should cancel on esc key with cancelOnEsc: true", function() { makeEditor({ cancelOnEsc: true }); editor.specialKeyDelay = 0; startEditWithTarget(); spyOn(editor, 'cancelEdit').andCallThrough(); waitsFor(function() { return field.hasFocus; }, "Field never focused"); runs(function() { fireKeyOnField(Ext.event.Event.ESC); expect(editor.cancelEdit).toHaveBeenCalled(); }); }); }); describe("hideEl", function() { it("should show the boundEl", function() { makeEditor(); startEditWithTarget(); editor.cancelEdit(); expect(target.isVisible()).toBe(true); }); }); describe("remainVisible", function() { it("should leave the editor visible with remainVisible", function() { makeEditor(); startEditWithTarget(); editor.cancelEdit(true); expect(editor.isVisible()).toBe(true); }); }); describe("events", function() { it("should fire canceledit and pass the editor, current value & start value", function() { var spy = jasmine.createSpy(); makeEditor(); startEditWithTarget(); editor.setValue('foo'); editor.on('canceledit', spy); editor.cancelEdit(); expect(spy).toHaveBeenCalled(); var args = spy.mostRecentCall.args; expect(args[0]).toBe(editor); expect(args[1]).toBe('foo'); expect(args[2]).toBe('Sample Text'); }); it("should not fire canceledit if not editing", function() { var spy = jasmine.createSpy(); makeEditor(); editor.on('canceledit', spy); editor.cancelEdit(); expect(spy).not.toHaveBeenCalled(); }); }); }); });
leonelllagumbay/bdg
a/c/iBOSe/ext/classic/classic/test/specs/Editor.js
JavaScript
gpl-2.0
28,018
/* * (C) Copyright David Brownell 2000-2002 * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/usb.h> #include <linux/usb/hcd.h> #include <asm/io.h> #include <asm/irq.h> #ifdef CONFIG_PPC_PMAC #include <asm/machdep.h> #include <asm/pmac_feature.h> #include <asm/pci-bridge.h> #include <asm/prom.h> #endif #include "usb.h" /* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ #ifdef CONFIG_PM_SLEEP /* Coordinate handoffs between EHCI and companion controllers * during system resume */ static DEFINE_MUTEX(companions_mutex); #define CL_UHCI PCI_CLASS_SERIAL_USB_UHCI #define CL_OHCI PCI_CLASS_SERIAL_USB_OHCI #define CL_EHCI PCI_CLASS_SERIAL_USB_EHCI enum companion_action { SET_HS_COMPANION, CLEAR_HS_COMPANION, WAIT_FOR_COMPANIONS }; static void companion_common(struct pci_dev *pdev, struct usb_hcd *hcd, enum companion_action action) { struct pci_dev *companion; struct usb_hcd *companion_hcd; unsigned int slot = PCI_SLOT(pdev->devfn); /* Iterate through other PCI functions in the same slot. * If pdev is OHCI or UHCI then we are looking for EHCI, and * vice versa. */ companion = NULL; for_each_pci_dev(companion) { if (companion->bus != pdev->bus || PCI_SLOT(companion->devfn) != slot) continue; companion_hcd = pci_get_drvdata(companion); if (!companion_hcd) continue; /* For SET_HS_COMPANION, store a pointer to the EHCI bus in * the OHCI/UHCI companion bus structure. * For CLEAR_HS_COMPANION, clear the pointer to the EHCI bus * in the OHCI/UHCI companion bus structure. * For WAIT_FOR_COMPANIONS, wait until the OHCI/UHCI * companion controllers have fully resumed. */ if ((pdev->class == CL_OHCI || pdev->class == CL_UHCI) && companion->class == CL_EHCI) { /* action must be SET_HS_COMPANION */ dev_dbg(&companion->dev, "HS companion for %s\n", dev_name(&pdev->dev)); hcd->self.hs_companion = &companion_hcd->self; } else if (pdev->class == CL_EHCI && (companion->class == CL_OHCI || companion->class == CL_UHCI)) { switch (action) { case SET_HS_COMPANION: dev_dbg(&pdev->dev, "HS companion for %s\n", dev_name(&companion->dev)); companion_hcd->self.hs_companion = &hcd->self; break; case CLEAR_HS_COMPANION: companion_hcd->self.hs_companion = NULL; break; case WAIT_FOR_COMPANIONS: device_pm_wait_for_dev(&pdev->dev, &companion->dev); break; } } } } static void set_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd) { mutex_lock(&companions_mutex); dev_set_drvdata(&pdev->dev, hcd); companion_common(pdev, hcd, SET_HS_COMPANION); mutex_unlock(&companions_mutex); } static void clear_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd) { mutex_lock(&companions_mutex); dev_set_drvdata(&pdev->dev, NULL); /* If pdev is OHCI or UHCI, just clear its hs_companion pointer */ if (pdev->class == CL_OHCI || pdev->class == CL_UHCI) hcd->self.hs_companion = NULL; /* Otherwise search for companion buses and clear their pointers */ else companion_common(pdev, hcd, CLEAR_HS_COMPANION); mutex_unlock(&companions_mutex); } static void wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd) { /* Only EHCI controllers need to wait. * No locking is needed because a controller cannot be resumed * while one of its companions is getting unbound. */ if (pdev->class == CL_EHCI) companion_common(pdev, hcd, WAIT_FOR_COMPANIONS); } #else /* !CONFIG_PM_SLEEP */ static inline void set_hs_companion(struct pci_dev *d, struct usb_hcd *h) {} static inline void clear_hs_companion(struct pci_dev *d, struct usb_hcd *h) {} static inline void wait_for_companions(struct pci_dev *d, struct usb_hcd *h) {} #endif /* !CONFIG_PM_SLEEP */ /*-------------------------------------------------------------------------*/ /* configure so an HC device and id are always provided */ /* always called with process context; sleeping is OK */ /** * usb_hcd_pci_probe - initialize PCI-based HCDs * @dev: USB Host Controller being probed * @id: pci hotplug id connecting controller to HCD framework * Context: !in_interrupt() * * Allocates basic PCI resources for this USB host controller, and * then invokes the start() method for the HCD associated with it * through the hotplug entry's driver_data. * * Store this function in the HCD's struct pci_driver as probe(). */ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { struct hc_driver *driver; struct usb_hcd *hcd; int retval; if (usb_disabled()) return -ENODEV; if (!id) return -EINVAL; driver = (struct hc_driver *)id->driver_data; if (!driver) return -EINVAL; if (pci_enable_device(dev) < 0) return -ENODEV; dev->current_state = PCI_D0; if (!dev->irq) { dev_err(&dev->dev, "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", pci_name(dev)); retval = -ENODEV; goto err1; } hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); if (!hcd) { retval = -ENOMEM; goto err1; } if (driver->flags & HCD_MEMORY) { /* EHCI, OHCI */ hcd->rsrc_start = pci_resource_start(dev, 0); hcd->rsrc_len = pci_resource_len(dev, 0); if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, driver->description)) { dev_dbg(&dev->dev, "controller already in use\n"); retval = -EBUSY; goto err2; } hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); if (hcd->regs == NULL) { dev_dbg(&dev->dev, "error mapping memory\n"); retval = -EFAULT; goto err3; } } else { /* UHCI */ int region; for (region = 0; region < PCI_ROM_RESOURCE; region++) { if (!(pci_resource_flags(dev, region) & IORESOURCE_IO)) continue; hcd->rsrc_start = pci_resource_start(dev, region); hcd->rsrc_len = pci_resource_len(dev, region); if (request_region(hcd->rsrc_start, hcd->rsrc_len, driver->description)) break; } if (region == PCI_ROM_RESOURCE) { dev_dbg(&dev->dev, "no i/o regions available\n"); retval = -EBUSY; goto err2; } } pci_set_master(dev); retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); if (retval != 0) goto err4; set_hs_companion(dev, hcd); if (pci_dev_run_wake(dev)) pm_runtime_put_noidle(&dev->dev); return retval; err4: if (driver->flags & HCD_MEMORY) { iounmap(hcd->regs); err3: release_mem_region(hcd->rsrc_start, hcd->rsrc_len); } else release_region(hcd->rsrc_start, hcd->rsrc_len); err2: clear_hs_companion(dev, hcd); usb_put_hcd(hcd); err1: pci_disable_device(dev); dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); return retval; } EXPORT_SYMBOL_GPL(usb_hcd_pci_probe); /* may be called without controller electrically present */ /* may be called with controller, bus, and devices active */ /** * usb_hcd_pci_remove - shutdown processing for PCI-based HCDs * @dev: USB Host Controller being removed * Context: !in_interrupt() * * Reverses the effect of usb_hcd_pci_probe(), first invoking * the HCD's stop() method. It is always called from a thread * context, normally "rmmod", "apmd", or something similar. * * Store this function in the HCD's struct pci_driver as remove(). */ void usb_hcd_pci_remove(struct pci_dev *dev) { struct usb_hcd *hcd; hcd = pci_get_drvdata(dev); if (!hcd) return; if (pci_dev_run_wake(dev)) pm_runtime_get_noresume(&dev->dev); /* Fake an interrupt request in order to give the driver a chance * to test whether the controller hardware has been removed (e.g., * cardbus physical eject). */ local_irq_disable(); usb_hcd_irq(0, hcd); local_irq_enable(); usb_remove_hcd(hcd); if (hcd->driver->flags & HCD_MEMORY) { iounmap(hcd->regs); release_mem_region(hcd->rsrc_start, hcd->rsrc_len); } else { release_region(hcd->rsrc_start, hcd->rsrc_len); } clear_hs_companion(dev, hcd); usb_put_hcd(hcd); pci_disable_device(dev); } EXPORT_SYMBOL_GPL(usb_hcd_pci_remove); /** * usb_hcd_pci_shutdown - shutdown host controller * @dev: USB Host Controller being shutdown */ void usb_hcd_pci_shutdown(struct pci_dev *dev) { struct usb_hcd *hcd; hcd = pci_get_drvdata(dev); if (!hcd) return; if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && hcd->driver->shutdown) { hcd->driver->shutdown(hcd); pci_disable_device(dev); } } EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); #ifdef CONFIG_PM_OPS #ifdef CONFIG_PPC_PMAC static void powermac_set_asic(struct pci_dev *pci_dev, int enable) { /* Enanble or disable ASIC clocks for USB */ if (machine_is(powermac)) { struct device_node *of_node; of_node = pci_device_to_OF_node(pci_dev); if (of_node) pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, enable); } } #else static inline void powermac_set_asic(struct pci_dev *pci_dev, int enable) {} #endif /* CONFIG_PPC_PMAC */ static int check_root_hub_suspended(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); struct usb_hcd *hcd = pci_get_drvdata(pci_dev); if (!(hcd->state == HC_STATE_SUSPENDED || hcd->state == HC_STATE_HALT)) { dev_warn(dev, "Root hub is not suspended\n"); return -EBUSY; } return 0; } static int suspend_common(struct device *dev, bool do_wakeup) { struct pci_dev *pci_dev = to_pci_dev(dev); struct usb_hcd *hcd = pci_get_drvdata(pci_dev); int retval; /* Root hub suspend should have stopped all downstream traffic, * and all bus master traffic. And done so for both the interface * and the stub usb_device (which we check here). But maybe it * didn't; writing sysfs power/state files ignores such rules... */ retval = check_root_hub_suspended(dev); if (retval) return retval; if (hcd->driver->pci_suspend) { /* Optimization: Don't suspend if a root-hub wakeup is * pending and it would cause the HCD to wake up anyway. */ if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) return -EBUSY; retval = hcd->driver->pci_suspend(hcd, do_wakeup); suspend_report_result(hcd->driver->pci_suspend, retval); /* Check again in case wakeup raced with pci_suspend */ if (retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) { if (hcd->driver->pci_resume) hcd->driver->pci_resume(hcd, false); retval = -EBUSY; } if (retval) return retval; } /* If MSI-X is enabled, the driver will have synchronized all vectors * in pci_suspend(). If MSI or legacy PCI is enabled, that will be * synchronized here. */ if (!hcd->msix_enabled) synchronize_irq(pci_dev->irq); /* Downstream ports from this root hub should already be quiesced, so * there will be no DMA activity. Now we can shut down the upstream * link (except maybe for PME# resume signaling). We'll enter a * low power state during suspend_noirq, if the hardware allows. */ pci_disable_device(pci_dev); return retval; } static int resume_common(struct device *dev, int event) { struct pci_dev *pci_dev = to_pci_dev(dev); struct usb_hcd *hcd = pci_get_drvdata(pci_dev); int retval; if (hcd->state != HC_STATE_SUSPENDED) { dev_dbg(dev, "can't resume, not suspended!\n"); return 0; } retval = pci_enable_device(pci_dev); if (retval < 0) { dev_err(dev, "can't re-enable after resume, %d!\n", retval); return retval; } pci_set_master(pci_dev); clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); if (hcd->driver->pci_resume) { if (event != PM_EVENT_AUTO_RESUME) wait_for_companions(pci_dev, hcd); retval = hcd->driver->pci_resume(hcd, event == PM_EVENT_RESTORE); if (retval) { dev_err(dev, "PCI post-resume error %d!\n", retval); usb_hc_died(hcd); } } return retval; } #ifdef CONFIG_PM_SLEEP static int hcd_pci_suspend(struct device *dev) { return suspend_common(dev, device_may_wakeup(dev)); } static int hcd_pci_suspend_noirq(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); struct usb_hcd *hcd = pci_get_drvdata(pci_dev); int retval; retval = check_root_hub_suspended(dev); if (retval) return retval; pci_save_state(pci_dev); /* If the root hub is HALTed rather than SUSPENDed, * disallow remote wakeup. */ if (hcd->state == HC_STATE_HALT) device_set_wakeup_enable(dev, 0); dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); /* Possibly enable remote wakeup, * choose the appropriate low-power state, and go to that state. */ retval = pci_prepare_to_sleep(pci_dev); if (retval == -EIO) { /* Low-power not supported */ dev_dbg(dev, "--> PCI D0 legacy\n"); retval = 0; } else if (retval == 0) { dev_dbg(dev, "--> PCI %s\n", pci_power_name(pci_dev->current_state)); } else { suspend_report_result(pci_prepare_to_sleep, retval); return retval; } powermac_set_asic(pci_dev, 0); return retval; } static int hcd_pci_resume_noirq(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); powermac_set_asic(pci_dev, 1); /* Go back to D0 and disable remote wakeup */ pci_back_from_sleep(pci_dev); return 0; } static int hcd_pci_resume(struct device *dev) { return resume_common(dev, PM_EVENT_RESUME); } static int hcd_pci_restore(struct device *dev) { return resume_common(dev, PM_EVENT_RESTORE); } #else #define hcd_pci_suspend NULL #define hcd_pci_suspend_noirq NULL #define hcd_pci_resume_noirq NULL #define hcd_pci_resume NULL #define hcd_pci_restore NULL #endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_PM_RUNTIME static int hcd_pci_runtime_suspend(struct device *dev) { int retval; retval = suspend_common(dev, true); if (retval == 0) powermac_set_asic(to_pci_dev(dev), 0); dev_dbg(dev, "hcd_pci_runtime_suspend: %d\n", retval); return retval; } static int hcd_pci_runtime_resume(struct device *dev) { int retval; powermac_set_asic(to_pci_dev(dev), 1); retval = resume_common(dev, PM_EVENT_AUTO_RESUME); dev_dbg(dev, "hcd_pci_runtime_resume: %d\n", retval); return retval; } #else #define hcd_pci_runtime_suspend NULL #define hcd_pci_runtime_resume NULL #endif /* CONFIG_PM_RUNTIME */ const struct dev_pm_ops usb_hcd_pci_pm_ops = { .suspend = hcd_pci_suspend, .suspend_noirq = hcd_pci_suspend_noirq, .resume_noirq = hcd_pci_resume_noirq, .resume = hcd_pci_resume, .freeze = check_root_hub_suspended, .freeze_noirq = check_root_hub_suspended, .thaw_noirq = NULL, .thaw = NULL, .poweroff = hcd_pci_suspend, .poweroff_noirq = hcd_pci_suspend_noirq, .restore_noirq = hcd_pci_resume_noirq, .restore = hcd_pci_restore, .runtime_suspend = hcd_pci_runtime_suspend, .runtime_resume = hcd_pci_runtime_resume, }; EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops); #endif /* CONFIG_PM_OPS */
Motorhead1991/android_kernel_samsung_msm7x27a
drivers/usb/core/hcd-pci.c
C
gpl-2.0
15,239
/** * Product: Posterita Web-Based POS and Adempiere Plugin * Copyright (C) 2007 Posterita Ltd * This file is part of POSterita * * POSterita is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ package org.posterita.exceptions; public class OrganisationAlreadyExistsException extends OperationException { /** * */ private static final long serialVersionUID = 1L; public OrganisationAlreadyExistsException(String exception) { super(exception); } }
braully/adempiere
posterita/posterita/src/main/org/posterita/exceptions/OrganisationAlreadyExistsException.java
Java
gpl-2.0
1,151
/* * MSM MDDI Transport * * Copyright (C) 2007 Google Incorporated * Copyright (C) 2007 QUALCOMM Incorporated * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and * may be copied, distributed, and modified under those terms. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/dma-mapping.h> #include <linux/interrupt.h> #include <linux/platform_device.h> #include <linux/delay.h> #include <linux/gfp.h> #include <linux/spinlock.h> #include <linux/clk.h> #include <linux/io.h> #include <linux/sched.h> #include <mach/msm_iomap.h> #include <mach/irqs.h> #include <mach/board.h> #include <mach/msm_fb.h> #include "mddi_hw.h" #define FLAG_DISABLE_HIBERNATION 0x0001 #define FLAG_HAVE_CAPS 0x0002 #define FLAG_HAS_VSYNC_IRQ 0x0004 #define FLAG_HAVE_STATUS 0x0008 #define CMD_GET_CLIENT_CAP 0x0601 #define CMD_GET_CLIENT_STATUS 0x0602 union mddi_rev { unsigned char raw[MDDI_REV_BUFFER_SIZE]; struct mddi_rev_packet hdr; struct mddi_client_status status; struct mddi_client_caps caps; struct mddi_register_access reg; }; struct reg_read_info { struct completion done; uint32_t reg; uint32_t status; uint32_t result; }; struct mddi_info { uint16_t flags; uint16_t version; char __iomem *base; int irq; struct clk *clk; struct msm_mddi_client_data client_data; /* buffer for rev encap packets */ void *rev_data; dma_addr_t rev_addr; struct mddi_llentry *reg_write_data; dma_addr_t reg_write_addr; struct mddi_llentry *reg_read_data; dma_addr_t reg_read_addr; size_t rev_data_curr; spinlock_t int_lock; uint32_t int_enable; uint32_t got_int; wait_queue_head_t int_wait; struct mutex reg_write_lock; struct mutex reg_read_lock; struct reg_read_info *reg_read; struct mddi_client_caps caps; struct mddi_client_status status; void (*power_client)(struct msm_mddi_client_data *, int); /* client device published to bind us to the * appropriate mddi_client driver */ char client_name[20]; struct platform_device client_pdev; }; static void mddi_init_rev_encap(struct mddi_info *mddi); #define mddi_readl(r) readl(mddi->base + (MDDI_##r)) #define mddi_writel(v, r) writel((v), mddi->base + (MDDI_##r)) void mddi_activate_link(struct msm_mddi_client_data *cdata) { struct mddi_info *mddi = container_of(cdata, struct mddi_info, client_data); mddi_writel(MDDI_CMD_LINK_ACTIVE, CMD); } static void mddi_handle_link_list_done(struct mddi_info *mddi) { } static void mddi_reset_rev_encap_ptr(struct mddi_info *mddi) { printk(KERN_INFO "mddi: resetting rev ptr\n"); mddi->rev_data_curr = 0; mddi_writel(mddi->rev_addr, REV_PTR); mddi_writel(mddi->rev_addr, REV_PTR); mddi_writel(MDDI_CMD_FORCE_NEW_REV_PTR, CMD); } static void mddi_handle_rev_data(struct mddi_info *mddi, union mddi_rev *rev) { int i; struct reg_read_info *ri; if ((rev->hdr.length <= MDDI_REV_BUFFER_SIZE - 2) && (rev->hdr.length >= sizeof(struct mddi_rev_packet) - 2)) { switch (rev->hdr.type) { case TYPE_CLIENT_CAPS: memcpy(&mddi->caps, &rev->caps, sizeof(struct mddi_client_caps)); mddi->flags |= FLAG_HAVE_CAPS; wake_up(&mddi->int_wait); break; case TYPE_CLIENT_STATUS: memcpy(&mddi->status, &rev->status, sizeof(struct mddi_client_status)); mddi->flags |= FLAG_HAVE_STATUS; wake_up(&mddi->int_wait); break; case TYPE_REGISTER_ACCESS: ri = mddi->reg_read; if (ri == 0) { printk(KERN_INFO "rev: got reg %x = %x without " " pending read\n", rev->reg.register_address, rev->reg.register_data_list); break; } if (ri->reg != rev->reg.register_address) { printk(KERN_INFO "rev: got reg %x = %x for " "wrong register, expected " "%x\n", rev->reg.register_address, rev->reg.register_data_list, ri->reg); break; } mddi->reg_read = NULL; ri->status = 0; ri->result = rev->reg.register_data_list; complete(&ri->done); break; default: printk(KERN_INFO "rev: unknown reverse packet: " "len=%04x type=%04x CURR_REV_PTR=%x\n", rev->hdr.length, rev->hdr.type, mddi_readl(CURR_REV_PTR)); for (i = 0; i < rev->hdr.length + 2; i++) { if ((i % 16) == 0) printk(KERN_INFO "\n"); printk(KERN_INFO " %02x", rev->raw[i]); } printk(KERN_INFO "\n"); mddi_reset_rev_encap_ptr(mddi); } } else { printk(KERN_INFO "bad rev length, %d, CURR_REV_PTR %x\n", rev->hdr.length, mddi_readl(CURR_REV_PTR)); mddi_reset_rev_encap_ptr(mddi); } } static void mddi_wait_interrupt(struct mddi_info *mddi, uint32_t intmask); static void mddi_handle_rev_data_avail(struct mddi_info *mddi) { uint32_t rev_data_count; uint32_t rev_crc_err_count; struct reg_read_info *ri; size_t prev_offset; uint16_t length; union mddi_rev *crev = mddi->rev_data + mddi->rev_data_curr; /* clear the interrupt */ mddi_writel(MDDI_INT_REV_DATA_AVAIL, INT); rev_data_count = mddi_readl(REV_PKT_CNT); rev_crc_err_count = mddi_readl(REV_CRC_ERR); if (rev_data_count > 1) printk(KERN_INFO "rev_data_count %d\n", rev_data_count); if (rev_crc_err_count) { printk(KERN_INFO "rev_crc_err_count %d, INT %x\n", rev_crc_err_count, mddi_readl(INT)); ri = mddi->reg_read; if (ri == 0) { printk(KERN_INFO "rev: got crc error without pending " "read\n"); } else { mddi->reg_read = NULL; ri->status = -EIO; ri->result = -1; complete(&ri->done); } } if (rev_data_count == 0) return; prev_offset = mddi->rev_data_curr; length = *((uint8_t *)mddi->rev_data + mddi->rev_data_curr); mddi->rev_data_curr++; if (mddi->rev_data_curr == MDDI_REV_BUFFER_SIZE) mddi->rev_data_curr = 0; length += *((uint8_t *)mddi->rev_data + mddi->rev_data_curr) << 8; mddi->rev_data_curr += 1 + length; if (mddi->rev_data_curr >= MDDI_REV_BUFFER_SIZE) mddi->rev_data_curr = mddi->rev_data_curr % MDDI_REV_BUFFER_SIZE; if (length > MDDI_REV_BUFFER_SIZE - 2) { printk(KERN_INFO "mddi: rev data length greater than buffer" "size\n"); mddi_reset_rev_encap_ptr(mddi); return; } if (prev_offset + 2 + length >= MDDI_REV_BUFFER_SIZE) { union mddi_rev tmprev; size_t rem = MDDI_REV_BUFFER_SIZE - prev_offset; memcpy(&tmprev.raw[0], mddi->rev_data + prev_offset, rem); memcpy(&tmprev.raw[rem], mddi->rev_data, 2 + length - rem); mddi_handle_rev_data(mddi, &tmprev); } else { mddi_handle_rev_data(mddi, crev); } if (prev_offset < MDDI_REV_BUFFER_SIZE / 2 && mddi->rev_data_curr >= MDDI_REV_BUFFER_SIZE / 2) { mddi_writel(mddi->rev_addr, REV_PTR); } } static irqreturn_t mddi_isr(int irq, void *data) { struct msm_mddi_client_data *cdata = data; struct mddi_info *mddi = container_of(cdata, struct mddi_info, client_data); uint32_t active, status; spin_lock(&mddi->int_lock); active = mddi_readl(INT); status = mddi_readl(STAT); mddi_writel(active, INT); /* ignore any interrupts we have disabled */ active &= mddi->int_enable; mddi->got_int |= active; wake_up(&mddi->int_wait); if (active & MDDI_INT_PRI_LINK_LIST_DONE) { mddi->int_enable &= (~MDDI_INT_PRI_LINK_LIST_DONE); mddi_handle_link_list_done(mddi); } if (active & MDDI_INT_REV_DATA_AVAIL) mddi_handle_rev_data_avail(mddi); if (active & ~MDDI_INT_NEED_CLEAR) mddi->int_enable &= ~(active & ~MDDI_INT_NEED_CLEAR); if (active & MDDI_INT_LINK_ACTIVE) { mddi->int_enable &= (~MDDI_INT_LINK_ACTIVE); mddi->int_enable |= MDDI_INT_IN_HIBERNATION; } if (active & MDDI_INT_IN_HIBERNATION) { mddi->int_enable &= (~MDDI_INT_IN_HIBERNATION); mddi->int_enable |= MDDI_INT_LINK_ACTIVE; } mddi_writel(mddi->int_enable, INTEN); spin_unlock(&mddi->int_lock); return IRQ_HANDLED; } static long mddi_wait_interrupt_timeout(struct mddi_info *mddi, uint32_t intmask, int timeout) { unsigned long irq_flags; spin_lock_irqsave(&mddi->int_lock, irq_flags); mddi->got_int &= ~intmask; mddi->int_enable |= intmask; mddi_writel(mddi->int_enable, INTEN); spin_unlock_irqrestore(&mddi->int_lock, irq_flags); return wait_event_timeout(mddi->int_wait, mddi->got_int & intmask, timeout); } static void mddi_wait_interrupt(struct mddi_info *mddi, uint32_t intmask) { if (mddi_wait_interrupt_timeout(mddi, intmask, HZ/10) == 0) printk(KERN_INFO "mddi_wait_interrupt %d, timeout " "waiting for %x, INT = %x, STAT = %x gotint = %x\n", current->pid, intmask, mddi_readl(INT), mddi_readl(STAT), mddi->got_int); } static void mddi_init_rev_encap(struct mddi_info *mddi) { memset(mddi->rev_data, 0xee, MDDI_REV_BUFFER_SIZE); mddi_writel(mddi->rev_addr, REV_PTR); mddi_writel(MDDI_CMD_FORCE_NEW_REV_PTR, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); } void mddi_set_auto_hibernate(struct msm_mddi_client_data *cdata, int on) { struct mddi_info *mddi = container_of(cdata, struct mddi_info, client_data); mddi_writel(MDDI_CMD_POWERDOWN, CMD); mddi_wait_interrupt(mddi, MDDI_INT_IN_HIBERNATION); mddi_writel(MDDI_CMD_HIBERNATE | !!on, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); } static uint16_t mddi_init_registers(struct mddi_info *mddi) { mddi_writel(0x0001, VERSION); mddi_writel(MDDI_HOST_BYTES_PER_SUBFRAME, BPS); mddi_writel(0x0003, SPM); /* subframes per media */ mddi_writel(0x0005, TA1_LEN); mddi_writel(MDDI_HOST_TA2_LEN, TA2_LEN); mddi_writel(0x0096, DRIVE_HI); /* 0x32 normal, 0x50 for Toshiba display */ mddi_writel(0x0050, DRIVE_LO); mddi_writel(0x003C, DISP_WAKE); /* wakeup counter */ mddi_writel(MDDI_HOST_REV_RATE_DIV, REV_RATE_DIV); mddi_writel(MDDI_REV_BUFFER_SIZE, REV_SIZE); mddi_writel(MDDI_MAX_REV_PKT_SIZE, REV_ENCAP_SZ); /* disable periodic rev encap */ mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); if (mddi_readl(PAD_CTL) == 0) { /* If we are turning on band gap, need to wait 5us before * turning on the rest of the PAD */ mddi_writel(0x08000, PAD_CTL); udelay(5); } /* Recommendation from PAD hw team */ mddi_writel(0xa850f, PAD_CTL); /* Need an even number for counts */ mddi_writel(0x60006, DRIVER_START_CNT); mddi_set_auto_hibernate(&mddi->client_data, 0); mddi_writel(MDDI_CMD_DISP_IGNORE, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); mddi_init_rev_encap(mddi); return mddi_readl(CORE_VER) & 0xffff; } static void mddi_suspend(struct msm_mddi_client_data *cdata) { struct mddi_info *mddi = container_of(cdata, struct mddi_info, client_data); /* turn off the client */ if (mddi->power_client) mddi->power_client(&mddi->client_data, 0); /* turn off the link */ mddi_writel(MDDI_CMD_RESET, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); /* turn off the clock */ clk_disable(mddi->clk); } static void mddi_resume(struct msm_mddi_client_data *cdata) { struct mddi_info *mddi = container_of(cdata, struct mddi_info, client_data); mddi_set_auto_hibernate(&mddi->client_data, 0); /* turn on the client */ if (mddi->power_client) mddi->power_client(&mddi->client_data, 1); /* turn on the clock */ clk_enable(mddi->clk); /* set up the local registers */ mddi->rev_data_curr = 0; mddi_init_registers(mddi); mddi_writel(mddi->int_enable, INTEN); mddi_writel(MDDI_CMD_LINK_ACTIVE, CMD); mddi_writel(MDDI_CMD_SEND_RTD, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); mddi_set_auto_hibernate(&mddi->client_data, 1); } static int __init mddi_get_client_caps(struct mddi_info *mddi) { int i, j; /* clear any stale interrupts */ mddi_writel(0xffffffff, INT); mddi->int_enable = MDDI_INT_LINK_ACTIVE | MDDI_INT_IN_HIBERNATION | MDDI_INT_PRI_LINK_LIST_DONE | MDDI_INT_REV_DATA_AVAIL | MDDI_INT_REV_OVERFLOW | MDDI_INT_REV_OVERWRITE | MDDI_INT_RTD_FAILURE; mddi_writel(mddi->int_enable, INTEN); mddi_writel(MDDI_CMD_LINK_ACTIVE, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); for (j = 0; j < 3; j++) { /* the toshiba vga panel does not respond to get * caps unless you SEND_RTD, but the first SEND_RTD * will fail... */ for (i = 0; i < 4; i++) { uint32_t stat; mddi_writel(MDDI_CMD_SEND_RTD, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); stat = mddi_readl(STAT); printk(KERN_INFO "mddi cmd send rtd: int %x, stat %x, " "rtd val %x\n", mddi_readl(INT), stat, mddi_readl(RTD_VAL)); if ((stat & MDDI_STAT_RTD_MEAS_FAIL) == 0) break; msleep(1); } mddi_writel(CMD_GET_CLIENT_CAP, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); wait_event_timeout(mddi->int_wait, mddi->flags & FLAG_HAVE_CAPS, HZ / 100); if (mddi->flags & FLAG_HAVE_CAPS) break; printk(KERN_INFO "mddi_init, timeout waiting for caps\n"); } return mddi->flags & FLAG_HAVE_CAPS; } /* link must be active when this is called */ int mddi_check_status(struct mddi_info *mddi) { int ret = -1, retry = 3; mutex_lock(&mddi->reg_read_lock); mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP | 1, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); do { mddi->flags &= ~FLAG_HAVE_STATUS; mddi_writel(CMD_GET_CLIENT_STATUS, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); wait_event_timeout(mddi->int_wait, mddi->flags & FLAG_HAVE_STATUS, HZ / 100); if (mddi->flags & FLAG_HAVE_STATUS) { if (mddi->status.crc_error_count) printk(KERN_INFO "mddi status: crc_error " "count: %d\n", mddi->status.crc_error_count); else ret = 0; break; } else printk(KERN_INFO "mddi status: failed to get client " "status\n"); mddi_writel(MDDI_CMD_SEND_RTD, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); } while (--retry); mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP | 0, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); mutex_unlock(&mddi->reg_read_lock); return ret; } void mddi_remote_write(struct msm_mddi_client_data *cdata, uint32_t val, uint32_t reg) { struct mddi_info *mddi = container_of(cdata, struct mddi_info, client_data); struct mddi_llentry *ll; struct mddi_register_access *ra; mutex_lock(&mddi->reg_write_lock); ll = mddi->reg_write_data; ra = &(ll->u.r); ra->length = 14 + 4; ra->type = TYPE_REGISTER_ACCESS; ra->client_id = 0; ra->read_write_info = MDDI_WRITE | 1; ra->crc16 = 0; ra->register_address = reg; ra->register_data_list = val; ll->flags = 1; ll->header_count = 14; ll->data_count = 4; ll->data = mddi->reg_write_addr + offsetof(struct mddi_llentry, u.r.register_data_list); ll->next = 0; ll->reserved = 0; mddi_writel(mddi->reg_write_addr, PRI_PTR); mddi_wait_interrupt(mddi, MDDI_INT_PRI_LINK_LIST_DONE); mutex_unlock(&mddi->reg_write_lock); } uint32_t mddi_remote_read(struct msm_mddi_client_data *cdata, uint32_t reg) { struct mddi_info *mddi = container_of(cdata, struct mddi_info, client_data); struct mddi_llentry *ll; struct mddi_register_access *ra; struct reg_read_info ri; unsigned s; int retry_count = 2; unsigned long irq_flags; mutex_lock(&mddi->reg_read_lock); ll = mddi->reg_read_data; ra = &(ll->u.r); ra->length = 14; ra->type = TYPE_REGISTER_ACCESS; ra->client_id = 0; ra->read_write_info = MDDI_READ | 1; ra->crc16 = 0; ra->register_address = reg; ll->flags = 0x11; ll->header_count = 14; ll->data_count = 0; ll->data = 0; ll->next = 0; ll->reserved = 0; s = mddi_readl(STAT); ri.reg = reg; ri.status = -1; do { init_completion(&ri.done); mddi->reg_read = &ri; mddi_writel(mddi->reg_read_addr, PRI_PTR); mddi_wait_interrupt(mddi, MDDI_INT_PRI_LINK_LIST_DONE); /* Enable Periodic Reverse Encapsulation. */ mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP | 1, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); if (wait_for_completion_timeout(&ri.done, HZ/10) == 0 && !ri.done.done) { printk(KERN_INFO "mddi_remote_read(%x) timeout " "(%d %d %d)\n", reg, ri.status, ri.result, ri.done.done); spin_lock_irqsave(&mddi->int_lock, irq_flags); mddi->reg_read = NULL; spin_unlock_irqrestore(&mddi->int_lock, irq_flags); ri.status = -1; ri.result = -1; } if (ri.status == 0) break; mddi_writel(MDDI_CMD_SEND_RTD, CMD); mddi_writel(MDDI_CMD_LINK_ACTIVE, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); printk(KERN_INFO "mddi_remote_read: failed, sent " "MDDI_CMD_SEND_RTD: int %x, stat %x, rtd val %x " "curr_rev_ptr %x\n", mddi_readl(INT), mddi_readl(STAT), mddi_readl(RTD_VAL), mddi_readl(CURR_REV_PTR)); } while (retry_count-- > 0); /* Disable Periodic Reverse Encapsulation. */ mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP | 0, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); mddi->reg_read = NULL; mutex_unlock(&mddi->reg_read_lock); return ri.result; } static struct mddi_info mddi_info[2]; static int __init mddi_clk_setup(struct platform_device *pdev, struct mddi_info *mddi, unsigned long clk_rate) { int ret; /* set up the clocks */ mddi->clk = clk_get(&pdev->dev, "mddi_clk"); if (IS_ERR(mddi->clk)) { printk(KERN_INFO "mddi: failed to get clock\n"); return PTR_ERR(mddi->clk); } ret = clk_enable(mddi->clk); if (ret) goto fail; ret = clk_set_rate(mddi->clk, clk_rate); if (ret) goto fail; return 0; fail: clk_put(mddi->clk); return ret; } static int __init mddi_rev_data_setup(struct mddi_info *mddi) { void *dma; dma_addr_t dma_addr; /* set up dma buffer */ dma = dma_alloc_coherent(NULL, 0x1000, &dma_addr, GFP_KERNEL); if (dma == 0) return -ENOMEM; mddi->rev_data = dma; mddi->rev_data_curr = 0; mddi->rev_addr = dma_addr; mddi->reg_write_data = dma + MDDI_REV_BUFFER_SIZE; mddi->reg_write_addr = dma_addr + MDDI_REV_BUFFER_SIZE; mddi->reg_read_data = mddi->reg_write_data + 1; mddi->reg_read_addr = mddi->reg_write_addr + sizeof(*mddi->reg_write_data); return 0; } static int __devinit mddi_probe(struct platform_device *pdev) { struct msm_mddi_platform_data *pdata = pdev->dev.platform_data; struct mddi_info *mddi = &mddi_info[pdev->id]; struct resource *resource; int ret, i; resource = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!resource) { printk(KERN_ERR "mddi: no associated mem resource!\n"); return -ENOMEM; } mddi->base = ioremap(resource->start, resource_size(resource)); if (!mddi->base) { printk(KERN_ERR "mddi: failed to remap base!\n"); ret = -EINVAL; goto error_ioremap; } resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (!resource) { printk(KERN_ERR "mddi: no associated irq resource!\n"); ret = -EINVAL; goto error_get_irq_resource; } mddi->irq = resource->start; printk(KERN_INFO "mddi: init() base=0x%p irq=%d\n", mddi->base, mddi->irq); mddi->power_client = pdata->power_client; mutex_init(&mddi->reg_write_lock); mutex_init(&mddi->reg_read_lock); spin_lock_init(&mddi->int_lock); init_waitqueue_head(&mddi->int_wait); ret = mddi_clk_setup(pdev, mddi, pdata->clk_rate); if (ret) { printk(KERN_ERR "mddi: failed to setup clock!\n"); goto error_clk_setup; } ret = mddi_rev_data_setup(mddi); if (ret) { printk(KERN_ERR "mddi: failed to setup rev data!\n"); goto error_rev_data; } mddi->int_enable = 0; mddi_writel(mddi->int_enable, INTEN); ret = request_irq(mddi->irq, mddi_isr, 0, "mddi", &mddi->client_data); if (ret) { printk(KERN_ERR "mddi: failed to request enable irq!\n"); goto error_request_irq; } /* turn on the mddi client bridge chip */ if (mddi->power_client) mddi->power_client(&mddi->client_data, 1); /* initialize the mddi registers */ mddi_set_auto_hibernate(&mddi->client_data, 0); mddi_writel(MDDI_CMD_RESET, CMD); mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND); mddi->version = mddi_init_registers(mddi); if (mddi->version < 0x20) { printk(KERN_ERR "mddi: unsupported version 0x%x\n", mddi->version); ret = -ENODEV; goto error_mddi_version; } /* read the capabilities off the client */ if (!mddi_get_client_caps(mddi)) { printk(KERN_INFO "mddi: no client found\n"); /* power down the panel */ mddi_writel(MDDI_CMD_POWERDOWN, CMD); printk(KERN_INFO "mddi powerdown: stat %x\n", mddi_readl(STAT)); msleep(100); printk(KERN_INFO "mddi powerdown: stat %x\n", mddi_readl(STAT)); return 0; } mddi_set_auto_hibernate(&mddi->client_data, 1); if (mddi->caps.Mfr_Name == 0 && mddi->caps.Product_Code == 0) pdata->fixup(&mddi->caps.Mfr_Name, &mddi->caps.Product_Code); mddi->client_pdev.id = 0; for (i = 0; i < pdata->num_clients; i++) { if (pdata->client_platform_data[i].product_id == (mddi->caps.Mfr_Name << 16 | mddi->caps.Product_Code)) { mddi->client_data.private_client_data = pdata->client_platform_data[i].client_data; mddi->client_pdev.name = pdata->client_platform_data[i].name; mddi->client_pdev.id = pdata->client_platform_data[i].id; /* XXX: possibly set clock */ break; } } if (i >= pdata->num_clients) mddi->client_pdev.name = "mddi_c_dummy"; printk(KERN_INFO "mddi: registering panel %s\n", mddi->client_pdev.name); mddi->client_data.suspend = mddi_suspend; mddi->client_data.resume = mddi_resume; mddi->client_data.activate_link = mddi_activate_link; mddi->client_data.remote_write = mddi_remote_write; mddi->client_data.remote_read = mddi_remote_read; mddi->client_data.auto_hibernate = mddi_set_auto_hibernate; mddi->client_data.fb_resource = pdata->fb_resource; if (pdev->id == 0) mddi->client_data.interface_type = MSM_MDDI_PMDH_INTERFACE; else if (pdev->id == 1) mddi->client_data.interface_type = MSM_MDDI_EMDH_INTERFACE; else { printk(KERN_ERR "mddi: can not determine interface %d!\n", pdev->id); ret = -EINVAL; goto error_mddi_interface; } mddi->client_pdev.dev.platform_data = &mddi->client_data; printk(KERN_INFO "mddi: publish: %s\n", mddi->client_name); platform_device_register(&mddi->client_pdev); return 0; error_mddi_interface: error_mddi_version: free_irq(mddi->irq, 0); error_request_irq: dma_free_coherent(NULL, 0x1000, mddi->rev_data, mddi->rev_addr); error_rev_data: error_clk_setup: error_get_irq_resource: iounmap(mddi->base); error_ioremap: printk(KERN_INFO "mddi: mddi_init() failed (%d)\n", ret); return ret; } static struct platform_driver mddi_driver = { .probe = mddi_probe, .driver = { .name = "msm_mddi" }, }; static int __init _mddi_init(void) { return platform_driver_register(&mddi_driver); } module_init(_mddi_init);
janrinze/snowballkernel
drivers/video/msm/mddi.c
C
gpl-2.0
22,851
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #include <linux/err.h> #include <linux/file.h> #include <linux/sched.h> #include <linux/slab.h> #include <linux/uaccess.h> #include <asm/current.h> #include "kgsl_sync.h" struct sync_pt *kgsl_sync_pt_create(struct sync_timeline *timeline, struct kgsl_context *context, unsigned int timestamp) { struct sync_pt *pt; pt = sync_pt_create(timeline, (int) sizeof(struct kgsl_sync_pt)); if (pt) { struct kgsl_sync_pt *kpt = (struct kgsl_sync_pt *) pt; kpt->context = context; kpt->timestamp = timestamp; } return pt; } /* * This should only be called on sync_pts which have been created but * not added to a fence. */ void kgsl_sync_pt_destroy(struct sync_pt *pt) { sync_pt_free(pt); } static struct sync_pt *kgsl_sync_pt_dup(struct sync_pt *pt) { struct kgsl_sync_pt *kpt = (struct kgsl_sync_pt *) pt; return kgsl_sync_pt_create(pt->parent, kpt->context, kpt->timestamp); } static int kgsl_sync_pt_has_signaled(struct sync_pt *pt) { struct kgsl_sync_pt *kpt = (struct kgsl_sync_pt *) pt; struct kgsl_sync_timeline *ktimeline = (struct kgsl_sync_timeline *) pt->parent; unsigned int ts = kpt->timestamp; unsigned int last_ts = ktimeline->last_timestamp; if (timestamp_cmp(last_ts, ts) >= 0) { /* signaled */ return 1; } return 0; } static int kgsl_sync_pt_compare(struct sync_pt *a, struct sync_pt *b) { struct kgsl_sync_pt *kpt_a = (struct kgsl_sync_pt *) a; struct kgsl_sync_pt *kpt_b = (struct kgsl_sync_pt *) b; unsigned int ts_a = kpt_a->timestamp; unsigned int ts_b = kpt_b->timestamp; return timestamp_cmp(ts_a, ts_b); } struct kgsl_fence_event_priv { struct kgsl_context *context; unsigned int timestamp; }; /** * kgsl_fence_event_cb - Event callback for a fence timestamp event * @device - The KGSL device that expired the timestamp * @priv - private data for the event * @context_id - the context id that goes with the timestamp * @timestamp - the timestamp that triggered the event * * Signal a fence following the expiration of a timestamp */ static inline void kgsl_fence_event_cb(struct kgsl_device *device, void *priv, u32 context_id, u32 timestamp, u32 type) { struct kgsl_fence_event_priv *ev = priv; kgsl_sync_timeline_signal(ev->context->timeline, ev->timestamp); kgsl_context_put(ev->context); kfree(ev); } static int _add_fence_event(struct kgsl_device *device, struct kgsl_context *context, unsigned int timestamp) { struct kgsl_fence_event_priv *event; int ret; event = kmalloc(sizeof(*event), GFP_KERNEL); if (event == NULL) return -ENOMEM; /* * Increase the refcount for the context to keep it through the * callback */ _kgsl_context_get(context); event->context = context; event->timestamp = timestamp; event->context = context; ret = kgsl_add_event(device, context->id, timestamp, kgsl_fence_event_cb, event, context->dev_priv); if (ret) { kgsl_context_put(context); kfree(event); } return ret; } /** * kgsl_add_fence_event - Create a new fence event * @device - KGSL device to create the event on * @timestamp - Timestamp to trigger the event * @data - Return fence fd stored in struct kgsl_timestamp_event_fence * @len - length of the fence event * @owner - driver instance that owns this event * @returns 0 on success or error code on error * * Create a fence and register an event to signal the fence when * the timestamp expires */ int kgsl_add_fence_event(struct kgsl_device *device, u32 context_id, u32 timestamp, void __user *data, int len, struct kgsl_device_private *owner) { struct kgsl_timestamp_event_fence priv; struct kgsl_context *context; struct sync_pt *pt; struct sync_fence *fence = NULL; int ret = -EINVAL; char fence_name[sizeof(fence->name)] = {}; unsigned int cur; priv.fence_fd = -1; if (len != sizeof(priv)) return -EINVAL; kgsl_mutex_lock(&device->mutex, &device->mutex_owner); context = kgsl_context_get_owner(owner, context_id); if (context == NULL) goto unlock; pt = kgsl_sync_pt_create(context->timeline, context, timestamp); if (pt == NULL) { KGSL_DRV_ERR(device, "kgsl_sync_pt_create failed\n"); ret = -ENOMEM; goto unlock; } snprintf(fence_name, sizeof(fence_name), "%s-pid-%d-ctx-%d-ts-%d", device->name, current->group_leader->pid, context_id, timestamp); fence = sync_fence_create(fence_name, pt); if (fence == NULL) { /* only destroy pt when not added to fence */ kgsl_sync_pt_destroy(pt); KGSL_DRV_ERR(device, "sync_fence_create failed\n"); ret = -ENOMEM; goto unlock; } priv.fence_fd = get_unused_fd_flags(0); if (priv.fence_fd < 0) { KGSL_DRV_ERR(device, "Unable to get a file descriptor: %d\n", priv.fence_fd); ret = priv.fence_fd; goto unlock; } sync_fence_install(fence, priv.fence_fd); /* * If the timestamp hasn't expired yet create an event to trigger it. * Otherwise, just signal the fence - there is no reason to go through * the effort of creating a fence we don't need. */ cur = kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED); if (timestamp_cmp(cur, timestamp) >= 0) kgsl_sync_timeline_signal(context->timeline, cur); else { ret = _add_fence_event(device, context, timestamp); if (ret) goto unlock; } kgsl_context_put(context); /* Unlock the mutex before copying to user */ kgsl_mutex_unlock(&device->mutex, &device->mutex_owner); if (copy_to_user(data, &priv, sizeof(priv))) { ret = -EFAULT; goto out; } return 0; unlock: kgsl_mutex_unlock(&device->mutex, &device->mutex_owner); out: if (priv.fence_fd >= 0) put_unused_fd(priv.fence_fd); if (fence) sync_fence_put(fence); kgsl_context_put(context); return ret; } static unsigned int kgsl_sync_get_timestamp( struct kgsl_sync_timeline *ktimeline, enum kgsl_timestamp_type type) { unsigned int ret = 0; struct kgsl_context *context = kgsl_context_get(ktimeline->device, ktimeline->context_id); if (context) ret = kgsl_readtimestamp(ktimeline->device, context, type); kgsl_context_put(context); return ret; } static void kgsl_sync_timeline_value_str(struct sync_timeline *sync_timeline, char *str, int size) { struct kgsl_sync_timeline *ktimeline = (struct kgsl_sync_timeline *) sync_timeline; unsigned int timestamp_retired = kgsl_sync_get_timestamp(ktimeline, KGSL_TIMESTAMP_RETIRED); snprintf(str, size, "%u retired:%u", ktimeline->last_timestamp, timestamp_retired); } static void kgsl_sync_pt_value_str(struct sync_pt *sync_pt, char *str, int size) { struct kgsl_sync_pt *kpt = (struct kgsl_sync_pt *) sync_pt; snprintf(str, size, "%u", kpt->timestamp); } static void kgsl_sync_pt_log(struct sync_pt *sync_pt) { struct kgsl_sync_pt *kpt = (struct kgsl_sync_pt *) sync_pt; pr_info("-----\n"); kgsl_context_dump(kpt->context); pr_info("-----\n"); } static void kgsl_sync_timeline_release_obj(struct sync_timeline *sync_timeline) { /* * Make sure to free the timeline only after destroy flag is set. * This is to avoid further accessing to the timeline from KGSL and * also to catch any unbalanced kref of timeline. */ BUG_ON(sync_timeline && (sync_timeline->destroyed != true)); } static const struct sync_timeline_ops kgsl_sync_timeline_ops = { .driver_name = "kgsl-timeline", .dup = kgsl_sync_pt_dup, .has_signaled = kgsl_sync_pt_has_signaled, .compare = kgsl_sync_pt_compare, .timeline_value_str = kgsl_sync_timeline_value_str, .pt_value_str = kgsl_sync_pt_value_str, .release_obj = kgsl_sync_timeline_release_obj, .pt_log = kgsl_sync_pt_log, }; int kgsl_sync_timeline_create(struct kgsl_context *context) { struct kgsl_sync_timeline *ktimeline; /* Generate a name which includes the thread name, thread id, process * name, process id, and context id. This makes it possible to * identify the context of a timeline in the sync dump. */ char ktimeline_name[sizeof(context->timeline->name)] = {}; snprintf(ktimeline_name, sizeof(ktimeline_name), "%s_%.15s(%d)-%.15s(%d)-%d", context->device->name, current->group_leader->comm, current->group_leader->pid, current->comm, current->pid, context->id); context->timeline = sync_timeline_create(&kgsl_sync_timeline_ops, (int) sizeof(struct kgsl_sync_timeline), ktimeline_name); if (context->timeline == NULL) return -EINVAL; ktimeline = (struct kgsl_sync_timeline *) context->timeline; ktimeline->last_timestamp = 0; ktimeline->device = context->device; ktimeline->context_id = context->id; return 0; } void kgsl_sync_timeline_signal(struct sync_timeline *timeline, unsigned int timestamp) { struct kgsl_sync_timeline *ktimeline = (struct kgsl_sync_timeline *) timeline; if (timestamp_cmp(timestamp, ktimeline->last_timestamp) > 0) ktimeline->last_timestamp = timestamp; sync_timeline_signal(timeline); } void kgsl_sync_timeline_destroy(struct kgsl_context *context) { sync_timeline_destroy(context->timeline); } static void kgsl_sync_callback(struct sync_fence *fence, struct sync_fence_waiter *waiter) { struct kgsl_sync_fence_waiter *kwaiter = (struct kgsl_sync_fence_waiter *) waiter; kwaiter->func(kwaiter->priv); sync_fence_put(kwaiter->fence); kfree(kwaiter); } struct kgsl_sync_fence_waiter *kgsl_sync_fence_async_wait(int fd, void (*func)(void *priv), void *priv) { struct kgsl_sync_fence_waiter *kwaiter; struct sync_fence *fence; int status; fence = sync_fence_fdget(fd); if (fence == NULL) return ERR_PTR(-EINVAL); /* create the waiter */ kwaiter = kzalloc(sizeof(*kwaiter), GFP_ATOMIC); if (kwaiter == NULL) { sync_fence_put(fence); return ERR_PTR(-ENOMEM); } kwaiter->fence = fence; kwaiter->priv = priv; kwaiter->func = func; strlcpy(kwaiter->name, fence->name, sizeof(kwaiter->name)); sync_fence_waiter_init((struct sync_fence_waiter *) kwaiter, kgsl_sync_callback); /* if status then error or signaled */ status = sync_fence_wait_async(fence, (struct sync_fence_waiter *) kwaiter); if (status) { kfree(kwaiter); sync_fence_put(fence); if (status < 0) kwaiter = ERR_PTR(status); else kwaiter = NULL; } return kwaiter; } int kgsl_sync_fence_async_cancel(struct kgsl_sync_fence_waiter *kwaiter) { if (kwaiter == NULL) return 0; if (sync_fence_cancel_async(kwaiter->fence, (struct sync_fence_waiter *) kwaiter) == 0) { sync_fence_put(kwaiter->fence); kfree(kwaiter); return 1; } return 0; }
charles1018/kernel_msm
drivers/gpu/msm/kgsl_sync.c
C
gpl-2.0
10,840
/* * hvconsole.c * Copyright (C) 2004 Hollis Blanchard, IBM Corporation * Copyright (C) 2004 IBM Corporation * * Additional Author(s): * Ryan S. Arnold <rsa@us.ibm.com> * * LPAR console support. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/kernel.h> #include <linux/export.h> #include <linux/errno.h> #include <asm/hvcall.h> #include <asm/hvconsole.h> #include <asm/plpar_wrappers.h> /** * hvc_get_chars - retrieve characters from firmware for denoted vterm adapter * @vtermno: The vtermno or unit_address of the adapter from which to fetch the * data. * @buf: The character buffer into which to put the character data fetched from * firmware. * @count: not used? */ int hvc_get_chars(uint32_t vtermno, char *buf, int count) { long ret; unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; unsigned long *lbuf = (unsigned long *)buf; ret = plpar_hcall(H_GET_TERM_CHAR, retbuf, vtermno); lbuf[0] = be64_to_cpu(retbuf[1]); lbuf[1] = be64_to_cpu(retbuf[2]); if (ret == H_SUCCESS) return retbuf[0]; return 0; } EXPORT_SYMBOL(hvc_get_chars); /** * hvc_put_chars: send characters to firmware for denoted vterm adapter * @vtermno: The vtermno or unit_address of the adapter from which the data * originated. * @buf: The character buffer that contains the character data to send to * firmware. * @count: Send this number of characters. */ int hvc_put_chars(uint32_t vtermno, const char *buf, int count) { unsigned long *lbuf = (unsigned long *) buf; long ret; /* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/ if (count > MAX_VIO_PUT_CHARS) count = MAX_VIO_PUT_CHARS; ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count, cpu_to_be64(lbuf[0]), cpu_to_be64(lbuf[1])); if (ret == H_SUCCESS) return count; if (ret == H_BUSY) return -EAGAIN; return -EIO; } EXPORT_SYMBOL(hvc_put_chars);
jderrick/linux-blkdev
arch/powerpc/platforms/pseries/hvconsole.c
C
gpl-2.0
2,546
# -*- coding: utf-8 -*- """ flask.globals ~~~~~~~~~~~~~ Defines all the global objects that are proxies to the current active context. :copyright: (c) 2011 by Armin Ronacher. :license: BSD, see LICENSE for more details. """ from functools import partial from werkzeug.local import LocalStack, LocalProxy def _lookup_req_object(name): top = _request_ctx_stack.top if top is None: raise RuntimeError('working outside of request context') return getattr(top, name) def _lookup_app_object(name): top = _app_ctx_stack.top if top is None: raise RuntimeError('working outside of application context') return getattr(top, name) def _find_app(): top = _app_ctx_stack.top if top is None: raise RuntimeError('working outside of application context') return top.app # context locals _request_ctx_stack = LocalStack() _app_ctx_stack = LocalStack() current_app = LocalProxy(_find_app) request = LocalProxy(partial(_lookup_req_object, 'request')) session = LocalProxy(partial(_lookup_req_object, 'session')) g = LocalProxy(partial(_lookup_app_object, 'g'))
ppmt/Crust
flask/lib/python2.7/site-packages/flask/globals.py
Python
gpl-2.0
1,137
#include <linux/init.h> #include <linux/pci.h> #include <linux/range.h> #include "bus_numa.h" LIST_HEAD(pci_root_infos); static struct pci_root_info *x86_find_pci_root_info(int bus) { struct pci_root_info *info; list_for_each_entry(info, &pci_root_infos, list) if (info->busn.start == bus) return info; return NULL; } int x86_pci_root_bus_node(int bus) { struct pci_root_info *info = x86_find_pci_root_info(bus); if (!info) return NUMA_NO_NODE; return info->node; } void x86_pci_root_bus_resources(int bus, struct list_head *resources) { struct pci_root_info *info = x86_find_pci_root_info(bus); struct pci_root_res *root_res; struct resource_entry *window; bool found = false; if (!info) goto default_resources; printk(KERN_DEBUG "PCI: root bus %02x: hardware-probed resources\n", bus); /* already added by acpi ? */ resource_list_for_each_entry(window, resources) if (window->res->flags & IORESOURCE_BUS) { found = true; break; } if (!found) pci_add_resource(resources, &info->busn); list_for_each_entry(root_res, &info->resources, list) { struct resource *res; struct resource *root; res = &root_res->res; pci_add_resource(resources, res); if (res->flags & IORESOURCE_IO) root = &ioport_resource; else root = &iomem_resource; insert_resource(root, res); } return; default_resources: /* * We don't have any host bridge aperture information from the * "native host bridge drivers," e.g., amd_bus or broadcom_bus, * so fall back to the defaults historically used by pci_create_bus(). */ printk(KERN_DEBUG "PCI: root bus %02x: using default resources\n", bus); pci_add_resource(resources, &ioport_resource); pci_add_resource(resources, &iomem_resource); } struct pci_root_info __init *alloc_pci_root_info(int bus_min, int bus_max, int node, int link) { struct pci_root_info *info; info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) return info; sprintf(info->name, "PCI Bus #%02x", bus_min); INIT_LIST_HEAD(&info->resources); info->busn.name = info->name; info->busn.start = bus_min; info->busn.end = bus_max; info->busn.flags = IORESOURCE_BUS; info->node = node; info->link = link; list_add_tail(&info->list, &pci_root_infos); return info; } void update_res(struct pci_root_info *info, resource_size_t start, resource_size_t end, unsigned long flags, int merge) { struct resource *res; struct pci_root_res *root_res; if (start > end) return; if (start == MAX_RESOURCE) return; if (!merge) goto addit; /* try to merge it with old one */ list_for_each_entry(root_res, &info->resources, list) { resource_size_t final_start, final_end; resource_size_t common_start, common_end; res = &root_res->res; if (res->flags != flags) continue; common_start = max(res->start, start); common_end = min(res->end, end); if (common_start > common_end + 1) continue; final_start = min(res->start, start); final_end = max(res->end, end); res->start = final_start; res->end = final_end; return; } addit: /* need to add that */ root_res = kzalloc(sizeof(*root_res), GFP_KERNEL); if (!root_res) return; res = &root_res->res; res->name = info->name; res->flags = flags; res->start = start; res->end = end; list_add_tail(&root_res->list, &info->resources); }
tifler/linux-mainline
arch/x86/pci/bus_numa.c
C
gpl-2.0
3,334
/* * zbud.c * * Copyright (C) 2013, Seth Jennings, IBM * * Concepts based on zcache internal zbud allocator by Dan Magenheimer. * * zbud is an special purpose allocator for storing compressed pages. Contrary * to what its name may suggest, zbud is not a buddy allocator, but rather an * allocator that "buddies" two compressed pages together in a single memory * page. * * While this design limits storage density, it has simple and deterministic * reclaim properties that make it preferable to a higher density approach when * reclaim will be used. * * zbud works by storing compressed pages, or "zpages", together in pairs in a * single memory page called a "zbud page". The first buddy is "left * justifed" at the beginning of the zbud page, and the last buddy is "right * justified" at the end of the zbud page. The benefit is that if either * buddy is freed, the freed buddy space, coalesced with whatever slack space * that existed between the buddies, results in the largest possible free region * within the zbud page. * * zbud also provides an attractive lower bound on density. The ratio of zpages * to zbud pages can not be less than 1. This ensures that zbud can never "do * harm" by using more pages to store zpages than the uncompressed zpages would * have used on their own. * * zbud pages are divided into "chunks". The size of the chunks is fixed at * compile time and determined by NCHUNKS_ORDER below. Dividing zbud pages * into chunks allows organizing unbuddied zbud pages into a manageable number * of unbuddied lists according to the number of free chunks available in the * zbud page. * * The zbud API differs from that of conventional allocators in that the * allocation function, zbud_alloc(), returns an opaque handle to the user, * not a dereferenceable pointer. The user must map the handle using * zbud_map() in order to get a usable pointer by which to access the * allocation data and unmap the handle with zbud_unmap() when operations * on the allocation data are complete. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/atomic.h> #include <linux/list.h> #include <linux/mm.h> #include <linux/module.h> #include <linux/preempt.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/zbud.h> /***************** * Structures *****************/ /* * NCHUNKS_ORDER determines the internal allocation granularity, effectively * adjusting internal fragmentation. It also determines the number of * freelists maintained in each pool. NCHUNKS_ORDER of 6 means that the * allocation granularity will be in chunks of size PAGE_SIZE/64, and there * will be 64 freelists per pool. */ #define NCHUNKS_ORDER 6 #define CHUNK_SHIFT (PAGE_SHIFT - NCHUNKS_ORDER) #define CHUNK_SIZE (1 << CHUNK_SHIFT) #define NCHUNKS (PAGE_SIZE >> CHUNK_SHIFT) #define ZHDR_SIZE_ALIGNED CHUNK_SIZE /** * struct zbud_pool - stores metadata for each zbud pool * @lock: protects all pool fields and first|last_chunk fields of any * zbud page in the pool * @unbuddied: array of lists tracking zbud pages that only contain one buddy; * the lists each zbud page is added to depends on the size of * its free region. * @buddied: list tracking the zbud pages that contain two buddies; * these zbud pages are full * @lru: list tracking the zbud pages in LRU order by most recently * added buddy. * @pages_nr: number of zbud pages in the pool. * @ops: pointer to a structure of user defined operations specified at * pool creation time. * * This structure is allocated at pool creation time and maintains metadata * pertaining to a particular zbud pool. */ struct zbud_pool { spinlock_t lock; struct list_head unbuddied[NCHUNKS]; struct list_head buddied; struct list_head lru; u64 pages_nr; struct zbud_ops *ops; }; /* * struct zbud_header - zbud page metadata occupying the first chunk of each * zbud page. * @buddy: links the zbud page into the unbuddied/buddied lists in the pool * @lru: links the zbud page into the lru list in the pool * @first_chunks: the size of the first buddy in chunks, 0 if free * @last_chunks: the size of the last buddy in chunks, 0 if free */ struct zbud_header { struct list_head buddy; struct list_head lru; unsigned int first_chunks; unsigned int last_chunks; bool under_reclaim; }; /***************** * Helpers *****************/ /* Just to make the code easier to read */ enum buddy { FIRST, LAST }; /* Converts an allocation size in bytes to size in zbud chunks */ static int size_to_chunks(int size) { return (size + CHUNK_SIZE - 1) >> CHUNK_SHIFT; } #define for_each_unbuddied_list(_iter, _begin) \ for ((_iter) = (_begin); (_iter) < NCHUNKS; (_iter)++) /* Initializes the zbud header of a newly allocated zbud page */ static struct zbud_header *init_zbud_page(struct page *page) { struct zbud_header *zhdr = page_address(page); zhdr->first_chunks = 0; zhdr->last_chunks = 0; INIT_LIST_HEAD(&zhdr->buddy); INIT_LIST_HEAD(&zhdr->lru); zhdr->under_reclaim = 0; return zhdr; } /* Resets the struct page fields and frees the page */ static void free_zbud_page(struct zbud_header *zhdr) { __free_page(virt_to_page(zhdr)); } /* * Encodes the handle of a particular buddy within a zbud page * Pool lock should be held as this function accesses first|last_chunks */ static unsigned long encode_handle(struct zbud_header *zhdr, enum buddy bud) { unsigned long handle; /* * For now, the encoded handle is actually just the pointer to the data * but this might not always be the case. A little information hiding. * Add CHUNK_SIZE to the handle if it is the first allocation to jump * over the zbud header in the first chunk. */ handle = (unsigned long)zhdr; if (bud == FIRST) /* skip over zbud header */ handle += ZHDR_SIZE_ALIGNED; else /* bud == LAST */ handle += PAGE_SIZE - (zhdr->last_chunks << CHUNK_SHIFT); return handle; } /* Returns the zbud page where a given handle is stored */ static struct zbud_header *handle_to_zbud_header(unsigned long handle) { return (struct zbud_header *)(handle & PAGE_MASK); } /* Returns the number of free chunks in a zbud page */ static int num_free_chunks(struct zbud_header *zhdr) { /* * Rather than branch for different situations, just use the fact that * free buddies have a length of zero to simplify everything. -1 at the * end for the zbud header. */ return NCHUNKS - zhdr->first_chunks - zhdr->last_chunks - 1; } /***************** * API Functions *****************/ /** * zbud_create_pool() - create a new zbud pool * @gfp: gfp flags when allocating the zbud pool structure * @ops: user-defined operations for the zbud pool * * Return: pointer to the new zbud pool or NULL if the metadata allocation * failed. */ struct zbud_pool *zbud_create_pool(gfp_t gfp, struct zbud_ops *ops) { struct zbud_pool *pool; int i; pool = kmalloc(sizeof(struct zbud_pool), gfp); if (!pool) return NULL; spin_lock_init(&pool->lock); for_each_unbuddied_list(i, 0) INIT_LIST_HEAD(&pool->unbuddied[i]); INIT_LIST_HEAD(&pool->buddied); INIT_LIST_HEAD(&pool->lru); pool->pages_nr = 0; pool->ops = ops; return pool; } /** * zbud_destroy_pool() - destroys an existing zbud pool * @pool: the zbud pool to be destroyed * * The pool should be emptied before this function is called. */ void zbud_destroy_pool(struct zbud_pool *pool) { kfree(pool); } /** * zbud_alloc() - allocates a region of a given size * @pool: zbud pool from which to allocate * @size: size in bytes of the desired allocation * @gfp: gfp flags used if the pool needs to grow * @handle: handle of the new allocation * * This function will attempt to find a free region in the pool large enough to * satisfy the allocation request. A search of the unbuddied lists is * performed first. If no suitable free region is found, then a new page is * allocated and added to the pool to satisfy the request. * * gfp should not set __GFP_HIGHMEM as highmem pages cannot be used * as zbud pool pages. * * Return: 0 if success and handle is set, otherwise -EINVAL is the size or * gfp arguments are invalid or -ENOMEM if the pool was unable to allocate * a new page. */ int zbud_alloc(struct zbud_pool *pool, int size, gfp_t gfp, unsigned long *handle) { int chunks, i, freechunks; struct zbud_header *zhdr = NULL; enum buddy bud; struct page *page; if (size <= 0 || gfp & __GFP_HIGHMEM) return -EINVAL; if (size > PAGE_SIZE - ZHDR_SIZE_ALIGNED) return -ENOSPC; chunks = size_to_chunks(size); spin_lock(&pool->lock); /* First, try to find an unbuddied zbud page. */ zhdr = NULL; for_each_unbuddied_list(i, chunks) { if (!list_empty(&pool->unbuddied[i])) { zhdr = list_first_entry(&pool->unbuddied[i], struct zbud_header, buddy); list_del(&zhdr->buddy); if (zhdr->first_chunks == 0) bud = FIRST; else bud = LAST; goto found; } } /* Couldn't find unbuddied zbud page, create new one */ spin_unlock(&pool->lock); page = alloc_page(gfp); if (!page) return -ENOMEM; spin_lock(&pool->lock); pool->pages_nr++; zhdr = init_zbud_page(page); bud = FIRST; found: if (bud == FIRST) zhdr->first_chunks = chunks; else zhdr->last_chunks = chunks; if (zhdr->first_chunks == 0 || zhdr->last_chunks == 0) { /* Add to unbuddied list */ freechunks = num_free_chunks(zhdr); list_add(&zhdr->buddy, &pool->unbuddied[freechunks]); } else { /* Add to buddied list */ list_add(&zhdr->buddy, &pool->buddied); } /* Add/move zbud page to beginning of LRU */ if (!list_empty(&zhdr->lru)) list_del(&zhdr->lru); list_add(&zhdr->lru, &pool->lru); *handle = encode_handle(zhdr, bud); spin_unlock(&pool->lock); return 0; } /** * zbud_free() - frees the allocation associated with the given handle * @pool: pool in which the allocation resided * @handle: handle associated with the allocation returned by zbud_alloc() * * In the case that the zbud page in which the allocation resides is under * reclaim, as indicated by the PG_reclaim flag being set, this function * only sets the first|last_chunks to 0. The page is actually freed * once both buddies are evicted (see zbud_reclaim_page() below). */ void zbud_free(struct zbud_pool *pool, unsigned long handle) { struct zbud_header *zhdr; int freechunks; spin_lock(&pool->lock); zhdr = handle_to_zbud_header(handle); /* If first buddy, handle will be page aligned */ if ((handle - ZHDR_SIZE_ALIGNED) & ~PAGE_MASK) zhdr->last_chunks = 0; else zhdr->first_chunks = 0; if (zhdr->under_reclaim) { /* zbud page is under reclaim, reclaim will free */ spin_unlock(&pool->lock); return; } /* Remove from existing buddy list */ list_del(&zhdr->buddy); if (zhdr->first_chunks == 0 && zhdr->last_chunks == 0) { /* zbud page is empty, free */ list_del(&zhdr->lru); free_zbud_page(zhdr); pool->pages_nr--; } else { /* Add to unbuddied list */ freechunks = num_free_chunks(zhdr); list_add(&zhdr->buddy, &pool->unbuddied[freechunks]); } spin_unlock(&pool->lock); } #define list_tail_entry(ptr, type, member) \ list_entry((ptr)->prev, type, member) /** * zbud_reclaim_page() - evicts allocations from a pool page and frees it * @pool: pool from which a page will attempt to be evicted * @retires: number of pages on the LRU list for which eviction will * be attempted before failing * * zbud reclaim is different from normal system reclaim in that the reclaim is * done from the bottom, up. This is because only the bottom layer, zbud, has * information on how the allocations are organized within each zbud page. This * has the potential to create interesting locking situations between zbud and * the user, however. * * To avoid these, this is how zbud_reclaim_page() should be called: * The user detects a page should be reclaimed and calls zbud_reclaim_page(). * zbud_reclaim_page() will remove a zbud page from the pool LRU list and call * the user-defined eviction handler with the pool and handle as arguments. * * If the handle can not be evicted, the eviction handler should return * non-zero. zbud_reclaim_page() will add the zbud page back to the * appropriate list and try the next zbud page on the LRU up to * a user defined number of retries. * * If the handle is successfully evicted, the eviction handler should * return 0 _and_ should have called zbud_free() on the handle. zbud_free() * contains logic to delay freeing the page if the page is under reclaim, * as indicated by the setting of the PG_reclaim flag on the underlying page. * * If all buddies in the zbud page are successfully evicted, then the * zbud page can be freed. * * Returns: 0 if page is successfully freed, otherwise -EINVAL if there are * no pages to evict or an eviction handler is not registered, -EAGAIN if * the retry limit was hit. */ int zbud_reclaim_page(struct zbud_pool *pool, unsigned int retries) { int i, ret, freechunks; struct zbud_header *zhdr; unsigned long first_handle = 0, last_handle = 0; spin_lock(&pool->lock); if (!pool->ops || !pool->ops->evict || list_empty(&pool->lru) || retries == 0) { spin_unlock(&pool->lock); return -EINVAL; } for (i = 0; i < retries; i++) { zhdr = list_tail_entry(&pool->lru, struct zbud_header, lru); list_del(&zhdr->lru); list_del(&zhdr->buddy); /* Protect zbud page against free */ zhdr->under_reclaim = true; /* * We need encode the handles before unlocking, since we can * race with free that will set (first|last)_chunks to 0 */ first_handle = 0; last_handle = 0; if (zhdr->first_chunks) first_handle = encode_handle(zhdr, FIRST); if (zhdr->last_chunks) last_handle = encode_handle(zhdr, LAST); spin_unlock(&pool->lock); /* Issue the eviction callback(s) */ if (first_handle) { ret = pool->ops->evict(pool, first_handle); if (ret) goto next; } if (last_handle) { ret = pool->ops->evict(pool, last_handle); if (ret) goto next; } next: spin_lock(&pool->lock); zhdr->under_reclaim = false; if (zhdr->first_chunks == 0 && zhdr->last_chunks == 0) { /* * Both buddies are now free, free the zbud page and * return success. */ free_zbud_page(zhdr); pool->pages_nr--; spin_unlock(&pool->lock); return 0; } else if (zhdr->first_chunks == 0 || zhdr->last_chunks == 0) { /* add to unbuddied list */ freechunks = num_free_chunks(zhdr); list_add(&zhdr->buddy, &pool->unbuddied[freechunks]); } else { /* add to buddied list */ list_add(&zhdr->buddy, &pool->buddied); } /* add to beginning of LRU */ list_add(&zhdr->lru, &pool->lru); } spin_unlock(&pool->lock); return -EAGAIN; } /** * zbud_map() - maps the allocation associated with the given handle * @pool: pool in which the allocation resides * @handle: handle associated with the allocation to be mapped * * While trivial for zbud, the mapping functions for others allocators * implementing this allocation API could have more complex information encoded * in the handle and could create temporary mappings to make the data * accessible to the user. * * Returns: a pointer to the mapped allocation */ void *zbud_map(struct zbud_pool *pool, unsigned long handle) { return (void *)(handle); } /** * zbud_unmap() - maps the allocation associated with the given handle * @pool: pool in which the allocation resides * @handle: handle associated with the allocation to be unmapped */ void zbud_unmap(struct zbud_pool *pool, unsigned long handle) { } /** * zbud_get_pool_size() - gets the zbud pool size in pages * @pool: pool whose size is being queried * * Returns: size in pages of the given pool. The pool lock need not be * taken to access pages_nr. */ u64 zbud_get_pool_size(struct zbud_pool *pool) { return pool->pages_nr; } static int __init init_zbud(void) { /* Make sure the zbud header will fit in one chunk */ BUILD_BUG_ON(sizeof(struct zbud_header) > ZHDR_SIZE_ALIGNED); pr_info("loaded\n"); return 0; } static void __exit exit_zbud(void) { pr_info("unloaded\n"); } module_init(init_zbud); module_exit(exit_zbud); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Seth Jennings <sjenning@linux.vnet.ibm.com>"); MODULE_DESCRIPTION("Buddy Allocator for Compressed Pages");
isnehalkiran/kernel-msm
mm/zbud.c
C
gpl-2.0
16,273
/* * Button mixin- creates 3d-ish button effect with correct * highlights/shadows, based on a base color. */ html { background: #f1f1f1; } /* Links */ a { color: #0074a2; } a:hover, a:active, a:focus { color: #0099d5; } #media-upload a.del-link:hover, div.dashboard-widget-submit input:hover, .subsubsub a:hover, .subsubsub a.current:hover { color: #0099d5; } /* Forms */ input[type=checkbox]:checked:before { color: #dd823b; } input[type=radio]:checked:before { background: #dd823b; } .wp-core-ui input[type="reset"]:hover, .wp-core-ui input[type="reset"]:active { color: #0099d5; } /* Core UI */ .wp-core-ui .button-primary { background: #dd823b; border-color: #c36822; color: white; -webkit-box-shadow: inset 0 1px 0 #e8ab7c, 0 1px 0 rgba(0, 0, 0, 0.15); box-shadow: inset 0 1px 0 #e8ab7c, 0 1px 0 rgba(0, 0, 0, 0.15); } .wp-core-ui .button-primary:hover, .wp-core-ui .button-primary:focus { background: #d97326; border-color: #ad5c1e; color: white; -webkit-box-shadow: inset 0 1px 0 #e59d66; box-shadow: inset 0 1px 0 #e59d66; } .wp-core-ui .button-primary:focus { -webkit-box-shadow: inset 0 1px 0 #e59d66, 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, 0.8); box-shadow: inset 0 1px 0 #e59d66, 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, 0.8); } .wp-core-ui .button-primary:active { background: #c36822; border-color: #ad5c1e; color: white; -webkit-box-shadow: inset 0 2px 5px -3px rgba(0, 0, 0, 0.5), 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, 0.8); box-shadow: inset 0 2px 5px -3px rgba(0, 0, 0, 0.5), 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, 0.8); } .wp-core-ui .button-primary[disabled], .wp-core-ui .button-primary:disabled, .wp-core-ui .button-primary.button-primary-disabled, .wp-core-ui .button-primary.disabled { color: #d1cbc7 !important; background: #cc6c23 !important; border-color: #ad5c1e !important; text-shadow: none !important; } .wp-core-ui .wp-ui-primary { color: #fff; background-color: #cf4944; } .wp-core-ui .wp-ui-text-primary { color: #cf4944; } .wp-core-ui .wp-ui-highlight { color: #fff; background-color: #dd823b; } .wp-core-ui .wp-ui-text-highlight { color: #dd823b; } .wp-core-ui .wp-ui-notification { color: #fff; background-color: #ccaf0b; } .wp-core-ui .wp-ui-text-notification { color: #ccaf0b; } .wp-core-ui .wp-ui-text-icon { color: #f3f1f1; } /* List tables */ .wrap .add-new-h2:hover, #add-new-comment a:hover, .tablenav .tablenav-pages a:hover, .tablenav .tablenav-pages a:focus { color: #fff; background-color: #cf4944; } .view-switch a.current:before { color: #cf4944; } .view-switch a:hover:before { color: #ccaf0b; } .post-com-count:hover:after { border-top-color: #cf4944; } .post-com-count:hover span { color: #fff; background-color: #cf4944; } strong .post-com-count:after { border-top-color: #ccaf0b; } strong .post-com-count span { background-color: #ccaf0b; } /* Admin Menu */ #adminmenuback, #adminmenuwrap, #adminmenu { background: #cf4944; } #adminmenu a { color: #fff; } #adminmenu div.wp-menu-image:before { color: #f3f1f1; } #adminmenu a:hover, #adminmenu li.menu-top:hover, #adminmenu li.opensub > a.menu-top, #adminmenu li > a.menu-top:focus { color: #fff; background-color: #dd823b; } #adminmenu li.menu-top:hover div.wp-menu-image:before, #adminmenu li.opensub > a.menu-top div.wp-menu-image:before { color: #fff; } /* Active tabs use a bottom border color that matches the page background color. */ .about-wrap h2 .nav-tab-active, .nav-tab-active, .nav-tab-active:hover { background-color: #f1f1f1; border-bottom-color: #f1f1f1; } /* Admin Menu: submenu */ #adminmenu .wp-submenu, #adminmenu .wp-has-current-submenu .wp-submenu, #adminmenu .wp-has-current-submenu.opensub .wp-submenu, .folded #adminmenu .wp-has-current-submenu .wp-submenu, #adminmenu a.wp-has-current-submenu:focus + .wp-submenu { background: #be3631; } #adminmenu li.wp-has-submenu.wp-not-current-submenu.opensub:hover:after { border-right-color: #be3631; } #adminmenu .wp-submenu .wp-submenu-head { color: #f0c8c6; } #adminmenu .wp-submenu a, #adminmenu .wp-has-current-submenu .wp-submenu a, .folded #adminmenu .wp-has-current-submenu .wp-submenu a, #adminmenu a.wp-has-current-submenu:focus + .wp-submenu a, #adminmenu .wp-has-current-submenu.opensub .wp-submenu a { color: #f0c8c6; } #adminmenu .wp-submenu a:focus, #adminmenu .wp-submenu a:hover, #adminmenu .wp-has-current-submenu .wp-submenu a:focus, #adminmenu .wp-has-current-submenu .wp-submenu a:hover, .folded #adminmenu .wp-has-current-submenu .wp-submenu a:focus, .folded #adminmenu .wp-has-current-submenu .wp-submenu a:hover, #adminmenu a.wp-has-current-submenu:focus + .wp-submenu a:focus, #adminmenu a.wp-has-current-submenu:focus + .wp-submenu a:hover, #adminmenu .wp-has-current-submenu.opensub .wp-submenu a:focus, #adminmenu .wp-has-current-submenu.opensub .wp-submenu a:hover { color: #f7e3d3; } /* Admin Menu: current */ #adminmenu .wp-submenu li.current a, #adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a, #adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a { color: #fff; } #adminmenu .wp-submenu li.current a:hover, #adminmenu .wp-submenu li.current a:focus, #adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a:hover, #adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a:focus, #adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a:hover, #adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a:focus { color: #f7e3d3; } ul#adminmenu a.wp-has-current-submenu:after, ul#adminmenu > li.current > a.current:after { border-right-color: #f1f1f1; } #adminmenu li.current a.menu-top, #adminmenu li.wp-has-current-submenu a.wp-has-current-submenu, #adminmenu li.wp-has-current-submenu .wp-submenu .wp-submenu-head, .folded #adminmenu li.current.menu-top { color: #fff; background: #dd823b; } #adminmenu li.wp-has-current-submenu div.wp-menu-image:before { color: #fff; } /* Admin Menu: bubble */ #adminmenu .awaiting-mod, #adminmenu .update-plugins { color: #fff; background: #ccaf0b; } #adminmenu li.current a .awaiting-mod, #adminmenu li a.wp-has-current-submenu .update-plugins, #adminmenu li:hover a .awaiting-mod, #adminmenu li.menu-top:hover > a .update-plugins { color: #fff; background: #be3631; } /* Admin Menu: collapse button */ #collapse-menu { color: #f3f1f1; } #collapse-menu:hover { color: #fff; } #collapse-button div:after { color: #f3f1f1; } #collapse-menu:hover #collapse-button div:after { color: #fff; } /* Admin Bar */ #wpadminbar { color: #fff; background: #cf4944; } #wpadminbar .ab-item, #wpadminbar a.ab-item, #wpadminbar > #wp-toolbar span.ab-label, #wpadminbar > #wp-toolbar span.noticon { color: #fff; } #wpadminbar .ab-icon, #wpadminbar .ab-icon:before, #wpadminbar .ab-item:before, #wpadminbar .ab-item:after { color: #f3f1f1; } #wpadminbar .ab-top-menu > li:hover > .ab-item, #wpadminbar .ab-top-menu > li.hover > .ab-item, #wpadminbar .ab-top-menu > li > .ab-item:focus, #wpadminbar.nojq .quicklinks .ab-top-menu > li > .ab-item:focus, #wpadminbar-nojs .ab-top-menu > li.menupop:hover > .ab-item, #wpadminbar .ab-top-menu > li.menupop.hover > .ab-item { color: #f7e3d3; background: #be3631; } #wpadminbar > #wp-toolbar li:hover span.ab-label, #wpadminbar > #wp-toolbar li.hover span.ab-label, #wpadminbar > #wp-toolbar a:focus span.ab-label { color: #f7e3d3; } #wpadminbar li:hover .ab-icon:before, #wpadminbar li:hover .ab-item:before, #wpadminbar li:hover .ab-item:after, #wpadminbar li:hover #adminbarsearch:before { color: #fff; } /* Admin Bar: submenu */ #wpadminbar .menupop .ab-sub-wrapper { background: #be3631; } #wpadminbar .quicklinks .menupop ul.ab-sub-secondary, #wpadminbar .quicklinks .menupop ul.ab-sub-secondary .ab-submenu { background: #cf6b67; } #wpadminbar .ab-submenu .ab-item, #wpadminbar .quicklinks .menupop ul li a, #wpadminbar .quicklinks .menupop.hover ul li a, #wpadminbar-nojs .quicklinks .menupop:hover ul li a { color: #f0c8c6; } #wpadminbar .quicklinks li .blavatar, #wpadminbar .menupop .menupop > .ab-item:before { color: #f3f1f1; } #wpadminbar .quicklinks .menupop ul li a:hover, #wpadminbar .quicklinks .menupop ul li a:focus, #wpadminbar .quicklinks .menupop ul li a:hover strong, #wpadminbar .quicklinks .menupop ul li a:focus strong, #wpadminbar .quicklinks .menupop.hover ul li a:hover, #wpadminbar .quicklinks .menupop.hover ul li a:focus, #wpadminbar.nojs .quicklinks .menupop:hover ul li a:hover, #wpadminbar.nojs .quicklinks .menupop:hover ul li a:focus, #wpadminbar li:hover .ab-icon:before, #wpadminbar li:hover .ab-item:before, #wpadminbar li a:focus .ab-icon:before, #wpadminbar li .ab-item:focus:before, #wpadminbar li.hover .ab-icon:before, #wpadminbar li.hover .ab-item:before, #wpadminbar li:hover .ab-item:after, #wpadminbar li.hover .ab-item:after, #wpadminbar li:hover #adminbarsearch:before { color: #f7e3d3; } #wpadminbar .quicklinks li a:hover .blavatar, #wpadminbar .menupop .menupop > .ab-item:hover:before { color: #f7e3d3; } /* Admin Bar: search */ #wpadminbar #adminbarsearch:before { color: #f3f1f1; } #wpadminbar > #wp-toolbar > #wp-admin-bar-top-secondary > #wp-admin-bar-search #adminbarsearch input.adminbar-input:focus { color: #fff; background: #d66460; } #wpadminbar #adminbarsearch .adminbar-input::-webkit-input-placeholder { color: #fff; opacity: 0.7; } #wpadminbar #adminbarsearch .adminbar-input:-moz-placeholder { color: #fff; opacity: 0.7; } #wpadminbar #adminbarsearch .adminbar-input::-moz-placeholder { color: #fff; opacity: 0.7; } #wpadminbar #adminbarsearch .adminbar-input:-ms-input-placeholder { color: #fff; opacity: 0.7; } /* Admin Bar: my account */ #wpadminbar .quicklinks li#wp-admin-bar-my-account.with-avatar > a img { border-color: #d66460; background-color: #d66460; } #wpadminbar #wp-admin-bar-user-info .display-name { color: #fff; } #wpadminbar #wp-admin-bar-user-info a:hover .display-name { color: #f7e3d3; } #wpadminbar #wp-admin-bar-user-info .username { color: #f0c8c6; } /* Pointers */ .wp-pointer .wp-pointer-content h3 { background-color: #dd823b; border-color: #d97326; } .wp-pointer .wp-pointer-content h3:before { color: #dd823b; } .wp-pointer.wp-pointer-top .wp-pointer-arrow, .wp-pointer.wp-pointer-undefined .wp-pointer-arrow { border-bottom-color: #dd823b; } /* Media */ .media-item .bar, .media-progress-bar div { background-color: #dd823b; } .details.attachment { -webkit-box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 7px #dd823b; box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 7px #dd823b; } .attachment.details .check { background-color: #dd823b; -webkit-box-shadow: 0 0 0 1px #fff, 0 0 0 2px #dd823b; box-shadow: 0 0 0 1px #fff, 0 0 0 2px #dd823b; } .media-selection .attachment.selection.details .thumbnail { -webkit-box-shadow: 0px 0px 0px 1px #fff, 0px 0px 0px 3px #dd823b; box-shadow: 0px 0px 0px 1px #fff, 0px 0px 0px 3px #dd823b; } /* Themes */ .theme-browser .theme.active .theme-name, .theme-browser .theme.add-new-theme:hover:after { background: #dd823b; } .theme-browser .theme.add-new-theme:hover span:after { color: #dd823b; } .theme-section.current, .theme-filter.current { border-bottom-color: #cf4944; } body.more-filters-opened .more-filters { color: #fff; background-color: #cf4944; } body.more-filters-opened .more-filters:before { color: #fff; } body.more-filters-opened .more-filters:hover, body.more-filters-opened .more-filters:focus { background-color: #dd823b; color: #fff; } body.more-filters-opened .more-filters:hover:before, body.more-filters-opened .more-filters:focus:before { color: #fff; } /* Widgets */ .widgets-chooser li.widgets-chooser-selected { background-color: #dd823b; color: #fff; } .widgets-chooser li.widgets-chooser-selected:before, .widgets-chooser li.widgets-chooser-selected:focus:before { color: #fff; } /* Customize */ #customize-theme-controls .widget-area-select .selected { background-color: #dd823b; color: #fff; } /* jQuery UI Slider */ .wp-slider .ui-slider-handle, .wp-slider .ui-slider-handle.ui-state-hover, .wp-slider .ui-slider-handle.focus { background: #dd823b; border-color: #c36822; -webkit-box-shadow: inset 0 1px 0 #e8ab7c, 0 1px 0 rgba(0, 0, 0, 0.15); box-shadow: inset 0 1px 0 #e8ab7c, 0 1px 0 rgba(0, 0, 0, 0.15); } /* Thickbox: Plugin information */ #sidemenu a.current { background: #f1f1f1; border-bottom-color: #f1f1f1; } #plugin-information .action-button { background: #dd823b; } /* Responsive Component */ div#wp-responsive-toggle a:before { color: #f3f1f1; } .wp-responsive-open div#wp-responsive-toggle a { border-color: transparent; background: #dd823b; } .star-rating .star { color: #dd823b; } .wp-responsive-open #wpadminbar #wp-admin-bar-menu-toggle a { background: #be3631; }
Acens/blackfriday
wp-admin/css/colors/sunrise/colors.css
CSS
gpl-2.0
13,108
#poststuff { padding-top: 10px; min-width: 763px; } #poststuff #post-body { padding: 0; } #poststuff .postbox-container { width: 100%; } #poststuff #post-body.columns-2 { margin-left: 300px; } /*------------------------------------------------------------------------------ 11.0 - Write/Edit Post Screen ------------------------------------------------------------------------------*/ #show-comments { overflow: hidden; } #save-action .spinner, #show-comments a, #show-comments .spinner { float: right; } #lost-connection-notice .spinner { display: block; float: right; margin: 0 0 0 5px; } #titlediv { position: relative; } #titlediv label { cursor: text; } #titlediv div.inside { margin: 0; } #poststuff #titlewrap { border: 0; padding: 0; } #titlediv #title { padding: 3px 8px; font-size: 1.7em; line-height: 100%; height: 1.7em; width: 100%; outline: none; margin: 0; background-color: #fff; } #titlediv #title-prompt-text { color: #777; position: absolute; font-size: 1.7em; padding: 11px 10px; } #wp-fullscreen-save .fs-saved { color: #999; float: left; margin-top: 4px; } #poststuff .inside-submitbox, #side-sortables .inside-submitbox { margin: 0 3px; font-size: 11px; } input#link_description, input#link_url { width: 98%; } #pending { background: 0 none; border: 0 none; padding: 0; font-size: 11px; margin-top: -1px; } #edit-slug-box { line-height: 24px; min-height: 25px; /* Yes, line-height + 1 */ margin-top: 5px; padding: 0 10px; color: #666; } #edit-slug-box .cancel { margin-left: 10px; font-size: 11px; } #editable-post-name-full { display: none; } #editable-post-name { background-color: #fffbcc; } #editable-post-name input { font-size: 13px; height: 22px; margin: 0; width: 16em; } .postarea h3 label { float: right; } .submitbox .submit { text-align: right; padding: 12px 10px 10px; font-size: 11px; background-color: #464646; color: #ccc; } .submitbox .submitdelete { text-decoration: none; padding: 1px 2px; } /* @todo: do we really need this? word on the street is we don't and this stray rule may actually be compensated for elsewhere. */ #normal-sortables .submitbox .submitdelete:hover { color: #000; background-color: #f00; border-bottom-color: #f00; } .submitbox .submit a:hover { text-decoration: underline; } .submitbox .submit input { margin-bottom: 8px; margin-left: 4px; padding: 6px; } .inside-submitbox #post_status { margin: 2px -2px 2px 0; } #post-status-select { margin-top: 3px; } /* Post Screen */ #post-body #normal-sortables { min-height: 50px; } .postbox { position: relative; min-width: 255px; border: 1px solid #e5e5e5; -webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.04); box-shadow: 0 1px 1px rgba(0,0,0,0.04); background: #fff; } #trackback_url { width: 99%; } #normal-sortables .postbox .submit { background: transparent none; border: 0 none; float: left; padding: 0 12px; margin:0; } .category-add input[type="text"], .category-add select { width: 100%; max-width: 260px; vertical-align: baseline; } #side-sortables .category-add input[type="text"], #side-sortables .category-add select { margin: 0 0 1em; } ul.category-tabs li, #side-sortables .add-menu-item-tabs li, .wp-tab-bar li { display: inline; line-height: 1.35em; } .no-js .category-tabs li.hide-if-no-js { display: none; } .category-tabs a, #side-sortables .add-menu-item-tabs a, .wp-tab-bar a { text-decoration: none; } /* @todo: do these really need to be so specific? */ #side-sortables .category-tabs .tabs a, #side-sortables .add-menu-item-tabs .tabs a, .wp-tab-bar .wp-tab-active a, #post-body ul.category-tabs li.tabs a, #post-body ul.add-menu-item-tabs li.tabs a { color: #333; } .category-tabs { margin: 8px 0 5px; } #category-adder h4 { margin: 10px 0; } #side-sortables .add-menu-item-tabs, .wp-tab-bar { margin-bottom: 3px; } #normal-sortables .postbox #replyrow .submit { float: none; margin: 0; padding: 0 7px 5px; } #side-sortables .submitbox .submit input, #side-sortables .submitbox .submit .preview, #side-sortables .submitbox .submit a.preview:hover { border: 0 none; } #side-sortables .inside-submitbox .insidebox, .stuffbox .insidebox { margin: 11px 0; } /* @todo: make this a more generic class */ ul.category-tabs, ul.add-menu-item-tabs, ul.wp-tab-bar { margin-top: 12px; } ul.category-tabs li, ul.add-menu-item-tabs li { border: solid 1px transparent; position: relative; } ul.category-tabs li.tabs, ul.add-menu-item-tabs li.tabs, .wp-tab-active { border: 1px solid #dfdfdf; border-bottom-color: #fdfdfd; background-color: #fdfdfd; } ul.category-tabs li, ul.add-menu-item-tabs li, ul.wp-tab-bar li { padding: 3px 5px 5px; } #postimagediv .inside img { max-width: 100%; height: auto; } form#tags-filter { position: relative; } /* Edit posts */ td.post-title strong, td.plugin-title strong { display: block; margin-bottom: .2em; font-size: 14px; } td.post-title p, td.plugin-title p { margin: 6px 0; } /* Global classes */ .wp-hidden-children .wp-hidden-child, .ui-tabs-hide { display: none; } #post-body .tagsdiv #newtag { margin-left: 5px; width: 16em; } #side-sortables input#post_password { width: 94% } #side-sortables .tagsdiv #newtag { width: 68%; } #post-status-info { width: 100%; border-spacing: 0; border: 1px solid #e5e5e5; border-top: none; background-color: #f7f7f7; -webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.04); box-shadow: 0 1px 1px rgba(0,0,0,0.04); z-index: 999; } #post-status-info td { font-size: 12px; } .autosave-info { padding: 2px 10px; text-align: left; } #editorcontent #post-status-info { border: none; } #content-resize-handle { background: transparent url(../images/resize.gif) no-repeat scroll left bottom; width: 12px; cursor: row-resize; } .rtl #content-resize-handle { background: transparent url(../images/resize-rtl.gif) no-repeat scroll right bottom; } .wp-editor-expand #content-resize-handle { display: none; } #postdivrich #content { resize: none; } #wp-word-count { display: block; padding: 2px 10px; } #wp-content-editor-container { position: relative; } #content-textarea-clone { z-index: -1; position: absolute; top: 0; visibility: hidden; overflow: hidden; max-width: 100%; border: 1px solid transparent; } .wp-fullscreen-wrap #content-textarea-clone { display: none; } /* editor-expand.js override */ .wp-fullscreen-wrap { padding-top: 0 !important; } .wp-fullscreen-wrap .wp-editor-area { margin-top: 0 !important; } .wp-fullscreen-wrap .mce-edit-area { padding-top: 0 !important; } /* end editor-expand.js override */ .wp-editor-expand #wp-content-editor-tools { z-index: 1000; border-bottom: 1px solid #e5e5e5; } .wp-editor-expand #wp-content-editor-container { -webkit-box-shadow: none; box-shadow: none; margin-top: -1px; } .wp-editor-expand #wp-content-editor-container { border-bottom: 0 none; } .wp-editor-expand div.mce-statusbar { z-index: 1; } .wp-editor-expand #post-status-info { border-top: 1px solid #e5e5e5; } .wp-editor-expand div.mce-toolbar-grp { z-index: 999; } #wp-content-editor-tools { background-color: #f1f1f1; padding-top: 20px; } #poststuff #post-body.columns-2 #side-sortables { width: 280px; } #timestampdiv select { height: 21px; line-height: 14px; padding: 0; vertical-align: top; font-size: 12px; } #aa, #jj, #hh, #mn { padding: 1px; font-size: 12px; } #jj, #hh, #mn { width: 2em; } #aa { width: 3.4em; } .curtime #timestamp { padding: 2px 0 1px 0; display: inline !important; height: auto !important; } #misc-publishing-actions label[for="post_status"]:before, #post-body #visibility:before, .curtime #timestamp:before, #post-body .misc-pub-revisions:before, span.wp-media-buttons-icon:before { color: #888; } #post-body #visibility:before, .curtime #timestamp:before, #post-body .misc-pub-revisions:before { font: normal 20px/1 'dashicons'; speak: none; display: inline-block; padding: 0 0 0 2px; top: 0; right: -1px; position: relative; vertical-align: top; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-decoration: none !important; } #post-body #visibility:before { content: '\f177'; } .curtime #timestamp:before { content: '\f145'; top: -1px; } #post-body .misc-pub-revisions:before { content: '\f321'; } #timestampdiv { padding-top: 5px; line-height: 23px; } #timestampdiv p { margin: 8px 0 6px; } #timestampdiv input { border-width: 1px; border-style: solid; } .notification-dialog { position: fixed; top: 30%; right: 50%; width: 450px; margin-right: -225px; background: #fff; -webkit-box-shadow: 0 3px 6px rgba( 0, 0, 0, 0.3 ); box-shadow: 0 3px 6px rgba( 0, 0, 0, 0.3 ); line-height: 1.5; z-index: 1000005; } .notification-dialog-background { position: fixed; top: 0; right: 0; left: 0; bottom: 0; background: #000; opacity: 0.7; filter: alpha(opacity=70); z-index: 1000000; } #post-lock-dialog .post-locked-message, #post-lock-dialog .post-taken-over { margin: 25px; } #post-lock-dialog .post-locked-message a.button { margin-left: 10px; } #post-lock-dialog .post-locked-avatar { float: right; margin: 0 0 20px 20px; } #post-lock-dialog .wp-tab-first { outline: 0; } #post-lock-dialog .locked-saving img { float: right; margin-left: 3px; } #post-lock-dialog.saving .locked-saving, #post-lock-dialog.saved .locked-saved { display: inline; } #excerpt, .attachmentlinks { margin: 0; height: 4em; width: 98%; } .tagchecklist { margin-right: 14px; font-size: 12px; overflow: auto; } .tagchecklist br { display: none; } .tagchecklist strong { margin-right: -8px; position: absolute; } .tagchecklist span { margin-left: 25px; display: block; float: right; font-size: 13px; line-height: 1.8em; white-space: nowrap; cursor: default; } .tagchecklist span a { margin: 1px -17px 0 0; cursor: pointer; width: 20px; height: 20px; display: block; float: right; text-indent: 0; overflow: hidden; position: absolute; } #poststuff h2 { margin-top: 20px; font-size: 1.5em; margin-bottom: 15px; padding: 0 0 3px; clear: right; } #poststuff h3 { font-size: 14px; padding: 8px 12px; margin: 0; line-height: 1.4; } #poststuff .inside { margin: 6px 0 0 0; } #poststuff .inside #parent_id, #poststuff .inside #page_template { max-width: 100%; } #poststuff .inside label.spam, #poststuff .inside label.deleted { color: red; } #poststuff .inside label.waiting { color: orange; } #poststuff .inside label.approved { color: green; } .ie8 #poststuff .inside #parent_id, .ie8 #poststuff .inside #page_template { width: 250px; } #post-visibility-select { line-height: 1.5em; margin-top: 3px; } #poststuff #submitdiv .inside { margin: 0; padding: 0; } #post-body-content, .edit-form-section { margin-bottom: 20px; } /*------------------------------------------------------------------------------ 11.1 - Custom Fields ------------------------------------------------------------------------------*/ #postcustomstuff thead th { padding: 5px 8px 8px; background-color: #f1f1f1; } #postcustom #postcustomstuff .submit { border: 0 none; float: none; padding: 0 8px 8px; } #side-sortables #postcustom #postcustomstuff .submit { margin: 0; padding: 0; } #side-sortables #postcustom #postcustomstuff #the-list textarea { height: 85px; } #side-sortables #postcustom #postcustomstuff td.left input, #side-sortables #postcustom #postcustomstuff td.left select, #side-sortables #postcustomstuff #newmetaleft a { margin: 3px 3px 0; } #postcustomstuff table { margin: 0; width: 100%; border: 1px solid #dfdfdf; border-spacing: 0; background-color: #f9f9f9; } #postcustomstuff tr { vertical-align: top; } #postcustomstuff table input, #postcustomstuff table select, #postcustomstuff table textarea { width: 96%; margin: 8px; } #side-sortables #postcustomstuff table input, #side-sortables #postcustomstuff table select, #side-sortables #postcustomstuff table textarea { margin: 3px; } #postcustomstuff th.left, #postcustomstuff td.left { width: 38%; } #postcustomstuff .submit input { margin: 0; width: auto; } #postcustomstuff #newmetaleft a { display: inline-block; margin: 0 8px 8px; text-decoration: none; } .no-js #postcustomstuff #enternew { display: none; } #post-body-content .compat-attachment-fields { margin-bottom: 20px; } .compat-attachment-fields th { padding-top: 5px; padding-left: 10px; } /*------------------------------------------------------------------------------ 11.3 - Featured Images ------------------------------------------------------------------------------*/ #select-featured-image { padding: 4px 0; overflow: hidden; } #select-featured-image img { max-width: 100%; height: auto; margin-bottom: 10px; } #select-featured-image a { float: right; clear: both; } #select-featured-image .remove { display: none; margin-top: 10px; } .js #select-featured-image.has-featured-image .remove { display: inline-block; } .no-js #select-featured-image .choose { display: none; } /*------------------------------------------------------------------------------ 11.4 - Post formats ------------------------------------------------------------------------------*/ .post-state-format { overflow: hidden; display: inline-block; vertical-align: middle; height: 20px; width: 20px; margin-left: 5px; margin-top: -4px; } .post-state-format:before { display: block; height: 20px; width: 20px; font: normal 20px/1 'dashicons' !important; speak: none; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .post-state-format:before, .post-format-icon:before { color: #ddd; -webkit-transition: all .1s ease-in-out; transition: all .1s ease-in-out; } a.post-state-format:hover:before, a.post-format-icon:hover:before { color: #2ea2cc; } #post-formats-select { line-height: 2em; } #post-formats-select .post-format-icon:before { top: 5px; } input.post-format { margin-top: 1px; } label.post-format-icon { margin-right: 0px; padding: 2px 0px 2px 0; } .post-format-icon:before { position: relative; display: inline-block; margin-left: 7px; font: normal 20px/1 'dashicons'; speak: none; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .post-state-format.post-format-standard:before, .post-format-icon.post-format-standard:before, a.post-state-format.format-standard:before { content: '\f109'; } .post-state-format.post-format-image:before, .post-format-icon.post-format-image:before, a.post-state-format.format-image:before { content: '\f128'; } .post-state-format.post-format-gallery:before, .post-format-icon.post-format-gallery:before, a.post-state-format.format-gallery:before { content: '\f161'; } .post-state-format.post-format-audio:before, .post-format-icon.post-format-audio:before, a.post-state-format.format-audio:before { content: '\f127'; } .post-state-format.post-format-video:before, .post-format-icon.post-format-video:before, a.post-state-format.format-video:before { content: '\f126'; } .post-state-format.post-format-chat:before, .post-format-icon.post-format-chat:before, a.post-state-format.format-chat:before { content: '\f125'; } .post-state-format.post-format-status:before, .post-format-icon.post-format-status:before, a.post-state-format.format-status:before { content: '\f130'; } .post-state-format.post-format-aside:before, .post-format-icon.post-format-aside:before, a.post-state-format.format-aside:before { content: '\f123'; } .post-state-format.post-format-quote:before, .post-format-icon.post-format-quote:before, a.post-state-format.format-quote:before { content: '\f122'; } .post-state-format.post-format-link:before, .post-format-icon.post-format-link:before, a.post-state-format.format-link:before { content: '\f103'; } /*------------------------------------------------------------------------------ 12.0 - Categories ------------------------------------------------------------------------------*/ .category-adder { margin-right: 120px; padding: 4px 0; } .category-adder h4 { margin: 0 0 8px; } #side-sortables .category-adder { margin: 0; } .wp-tab-panel, .categorydiv div.tabs-panel, .customlinkdiv div.tabs-panel, .posttypediv div.tabs-panel, .taxonomydiv div.tabs-panel { min-height: 42px; max-height: 200px; overflow: auto; padding: 0 0.9em; border: solid 1px #dfdfdf; background-color: #fdfdfd; } div.tabs-panel-active { display:block; } div.tabs-panel-inactive { display:none; } #front-page-warning, #front-static-pages ul, ul.export-filters, .inline-editor ul.cat-checklist ul, .categorydiv ul.categorychecklist ul, .customlinkdiv ul.categorychecklist ul, .posttypediv ul.categorychecklist ul, .taxonomydiv ul.categorychecklist ul { margin-right: 18px; } ul.categorychecklist li { margin: 0; padding: 0; line-height: 22px; word-wrap: break-word; } .categorydiv .tabs-panel, .customlinkdiv .tabs-panel, .posttypediv .tabs-panel, .taxonomydiv .tabs-panel { border-width: 3px; border-style: solid; } .form-wrap p, .form-wrap label { font-size: 11px; } .form-wrap label { display: block; padding: 2px; font-size: 12px; } .form-field input[type="text"], .form-field input[type="password"], .form-field input[type="email"], .form-field input[type="number"], .form-field input[type="search"], .form-field input[type="tel"], .form-field input[type="url"], .form-field textarea { border-style: solid; border-width: 1px; width: 95%; } p.description, .form-wrap p { margin: 2px 0 5px; color: #666; } p.help, p.description, span.description, .form-wrap p { font-size: 13px; font-style: italic; } .form-wrap .form-field { margin: 0 0 10px; padding: 8px 0; } .form-wrap .form-field #parent { max-width: 100%; } .col-wrap h3 { margin: 12px 0; font-size: 1.1em; } .col-wrap p.submit { margin-top: -10px; } /*------------------------------------------------------------------------------ 13.0 - Tags ------------------------------------------------------------------------------*/ .tagsdiv { margin-top: -8px; } #poststuff .taghint { color: #aaa; margin: 15px 12px -24px 0; } #poststuff .tagsdiv .howto { margin: 0 0 6px 0; } .ajaxtag .newtag { position: relative; } .tagsdiv .newtag { width: 180px; } .tagsdiv .the-tags { display: block; height: 60px; margin: 0 auto; overflow: auto; width: 260px; } #post-body-content .tagsdiv .the-tags { margin: 0 5px; } /* tag hints */ .taghint { color: #aaa; margin: -17px 7px 0 0; visibility: hidden; } input.newtag ~ div.taghint { visibility: visible; } input.newtag:focus ~ div.taghint { visibility: hidden; } p.popular-tags { border: none; line-height: 2em; padding: 8px 12px 12px; text-align: justify; } p.popular-tags a { padding: 0 3px; } .tagcloud { width: 97%; margin: 0 0 40px; text-align: justify; } .tagcloud h3 { margin: 2px 0 12px; } .ac_results { padding: 0; margin: 0; list-style: none; position: absolute; z-index: 10000; display: none; border: 1px solid #808080; background-color: #fff; } .wp-customizer .ac_results { z-index: 500000; } .ac_results li { padding: 2px 5px; white-space: nowrap; color: #101010; text-align: right; } .ac_over { background-color: #f0f0b8; cursor: pointer; } .ac_match { text-decoration: underline; } /* Comments */ .comment-php .wp-editor-area { height: 200px; } .comment-ays { margin-bottom: 0; border-bottom-style: solid; border-bottom-width: 1px; } .comment-ays .alt { background-color: transparent; } .trash-undo-inside, .spam-undo-inside { margin: 1px 0 1px 8px; line-height: 16px; } .spam-undo-inside .avatar, .trash-undo-inside .avatar { height: 20px; width: 20px; margin-left: 8px; vertical-align: middle; } .stuffbox .editcomment { clear: none; } #comment-status-radio p { margin: 3px 0 5px; } #comment-status-radio input { margin: 2px 0 5px 3px; vertical-align: middle; } #comment-status-radio label { padding: 5px 0; } /* links tables */ table.links-table { width: 100%; border-spacing: 0; } .links-table th { font-weight: normal; text-align: right; vertical-align: top; min-width: 80px; width: 20%; word-wrap: break-word; } .links-table th, .links-table td { padding: 5px 0; } .links-table td label { margin-left: 8px; } .links-table td input[type="text"], .links-table td textarea { width: 100%; } .links-table #link_rel { max-width: 280px; } /* =Media Queries -------------------------------------------------------------- */ /** * HiDPI Displays */ @media print, (-o-min-device-pixel-ratio: 5/4), (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) { #content-resize-handle, #post-body .wp_themeSkin .mceStatusbar a.mceResize { background: transparent url(../images/resize-2x.gif) no-repeat scroll left bottom; -webkit-background-size: 11px 11px; background-size: 11px 11px; } .rtl #content-resize-handle, .rtl #post-body .wp_themeSkin .mceStatusbar a.mceResize { background: transparent url(../images/resize-rtl-2x.gif) no-repeat scroll left bottom; } } /* one column on the post write/edit screen */ @media only screen and (max-width: 850px) { #poststuff { min-width: 0; } #wpbody-content #poststuff #post-body { margin: 0; } #wpbody-content #post-body.columns-2 #postbox-container-1 { margin-left: 0; width: 100%; } #poststuff #postbox-container-1 .empty-container, #poststuff #postbox-container-1 #side-sortables:empty { border: 0 none; height: 0; min-height: 0; } #poststuff #post-body.columns-2 #side-sortables { min-height: 0; width: auto; } /* hide the radio buttons for column prefs */ .screen-layout, .columns-prefs { display: none; } } @media screen and ( max-width: 782px ) { #post-body-content { min-width: 0; } #titlediv #title-prompt-text { padding: 10px 10px; } #poststuff h3 { padding: 12px; } .post-format-options { padding-left: 0; } .post-format-options a { margin-left: 5px; margin-bottom: 5px; min-width: 52px; } .post-format-options .post-format-title { font-size: 11px; } .post-format-options a div { height: 28px; width: 28px; } .post-format-options a div:before { font-size: 26px !important; } /* Publish Metabox Options */ #post-visibility-select { line-height: 280%; } .wp-core-ui .save-post-visibility, .wp-core-ui .save-timestamp { vertical-align: middle; margin-left: 15px; } .timestamp-wrap select#mm { display: block; width: 100%; margin-bottom: 10px; } .timestamp-wrap #jj, .timestamp-wrap #aa, .timestamp-wrap #hh, .timestamp-wrap #mn { padding: 12px 3px; font-size: 14px; margin-bottom: 5px; width: auto; text-align: center; } /* Categories Metabox */ ul.category-tabs { margin: 30px 0 15px; } ul.category-tabs li.tabs { padding: 15px; } ul.categorychecklist li { margin-bottom: 15px; } ul.categorychecklist ul { margin-top: 15px; } .category-add input[type=text], .category-add select { max-width: none; margin-bottom: 15px; } /* Tags Metabox */ .tagsdiv .newtag { width: 100%; height: auto; margin-bottom: 15px; } .tagchecklist { margin: 25px 10px; } .tagchecklist span { font-size: 16px; line-height: 120%; } /* Discussion */ #commentstatusdiv p { line-height: 2.8; } /* TinyMCE Adjustments */ .mceToolbar * { white-space: normal !important; } .mceToolbar tr, .mceToolbar td { float: right !important; } .wp_themeSkin a.mceButton { width: 30px; height: 30px; } .wp_themeSkin .mceButton .mceIcon { margin-top: 5px; margin-right: 5px; } .wp_themeSkin .mceSplitButton { margin-top: 1px; } .wp_themeSkin .mceSplitButton td a.mceAction { padding-top: 6px; padding-bottom: 6px; padding-right: 6px; padding-left: 3px; } .wp_themeSkin .mceSplitButton td a.mceOpen, .wp_themeSkin .mceSplitButtonEnabled:hover td a.mceOpen { padding-top: 6px; padding-bottom: 6px; background-position: 1px 6px; } .wp_themeSkin table.mceListBox { margin: 5px; } div.quicktags-toolbar input { padding: 10px 20px; } a.wp-switch-editor { font-size: 16px; line-height: 1em; margin: 3px 7px 0 0; padding: 12px 15px; } #wp-content-media-buttons a { font-size: 16px; line-height: 37px; height: 39px; padding: 0 15px 0 20px; } .wp-media-buttons span.wp-media-buttons-icon, .wp-media-buttons span.jetpack-contact-form-icon { width: 22px !important; margin-top: -3px !important; margin-right: -5px !important; } .wp-media-buttons .add_media span.wp-media-buttons-icon:before, .wp-media-buttons #insert-jetpack-contact-form span.jetpack-contact-form-icon:before { font-size: 20px !important; } #content_wp_fullscreen { display: none; } .misc-pub-section { padding: 20px 10px 20px; } .misc-pub-section > a { float: left; font-size: 16px; } #delete-action, #publishing-action { line-height: 47px; } /* Moderate Comment */ .comment-ays { border-bottom: none; } /* Links */ .links-table #link_rel { max-width: none; } .links-table th, .links-table td { padding: 10px 0; } } @media only screen and (max-width: 500px) { /* Align Add Media + Visual + Text tabs */ #wp-content-media-buttons a { font-size: 14px; padding: 0 10px 0 10px; } }
jessi1411/hallo
wp-admin/css/edit-rtl.css
CSS
gpl-2.0
25,267
/* * Copyright 2002-2004, Instant802 Networks, Inc. * Copyright 2008, Jouni Malinen <j@w1.fi> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/netdevice.h> #include <linux/types.h> #include <linux/skbuff.h> #include <linux/compiler.h> #include <linux/ieee80211.h> #include <linux/gfp.h> #include <asm/unaligned.h> #include <net/mac80211.h> #include <crypto/aes.h> #include "ieee80211_i.h" #include "michael.h" #include "tkip.h" #include "aes_ccm.h" #include "aes_cmac.h" #include "wpa.h" ieee80211_tx_result ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx) { u8 *data, *key, *mic; size_t data_len; unsigned int hdrlen; struct ieee80211_hdr *hdr; struct sk_buff *skb = tx->skb; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); int tail; hdr = (struct ieee80211_hdr *)skb->data; if (!tx->key || tx->key->conf.cipher != WLAN_CIPHER_SUITE_TKIP || skb->len < 24 || !ieee80211_is_data_present(hdr->frame_control)) return TX_CONTINUE; hdrlen = ieee80211_hdrlen(hdr->frame_control); if (skb->len < hdrlen) return TX_DROP; data = skb->data + hdrlen; data_len = skb->len - hdrlen; if (unlikely(info->flags & IEEE80211_TX_INTFL_TKIP_MIC_FAILURE)) { /* Need to use software crypto for the test */ info->control.hw_key = NULL; } if (info->control.hw_key && (info->flags & IEEE80211_TX_CTL_DONTFRAG || tx->local->ops->set_frag_threshold) && !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC)) { /* hwaccel - with no need for SW-generated MMIC */ return TX_CONTINUE; } tail = MICHAEL_MIC_LEN; if (!info->control.hw_key) tail += TKIP_ICV_LEN; if (WARN_ON(skb_tailroom(skb) < tail || skb_headroom(skb) < TKIP_IV_LEN)) return TX_DROP; key = &tx->key->conf.key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY]; mic = skb_put(skb, MICHAEL_MIC_LEN); michael_mic(key, hdr, data, data_len, mic); if (unlikely(info->flags & IEEE80211_TX_INTFL_TKIP_MIC_FAILURE)) mic[0]++; return TX_CONTINUE; } ieee80211_rx_result ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx) { u8 *data, *key = NULL; size_t data_len; unsigned int hdrlen; u8 mic[MICHAEL_MIC_LEN]; struct sk_buff *skb = rx->skb; struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; /* * it makes no sense to check for MIC errors on anything other * than data frames. */ if (!ieee80211_is_data_present(hdr->frame_control)) return RX_CONTINUE; /* * No way to verify the MIC if the hardware stripped it or * the IV with the key index. In this case we have solely rely * on the driver to set RX_FLAG_MMIC_ERROR in the event of a * MIC failure report. */ if (status->flag & (RX_FLAG_MMIC_STRIPPED | RX_FLAG_IV_STRIPPED)) { if (status->flag & RX_FLAG_MMIC_ERROR) goto mic_fail; if (!(status->flag & RX_FLAG_IV_STRIPPED) && rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_TKIP) goto update_iv; return RX_CONTINUE; } /* * Some hardware seems to generate Michael MIC failure reports; even * though, the frame was not encrypted with TKIP and therefore has no * MIC. Ignore the flag them to avoid triggering countermeasures. */ if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_TKIP || !(status->flag & RX_FLAG_DECRYPTED)) return RX_CONTINUE; if (rx->sdata->vif.type == NL80211_IFTYPE_AP && rx->key->conf.keyidx) { /* * APs with pairwise keys should never receive Michael MIC * errors for non-zero keyidx because these are reserved for * group keys and only the AP is sending real multicast * frames in the BSS. ( */ return RX_DROP_UNUSABLE; } if (status->flag & RX_FLAG_MMIC_ERROR) goto mic_fail; hdrlen = ieee80211_hdrlen(hdr->frame_control); if (skb->len < hdrlen + MICHAEL_MIC_LEN) return RX_DROP_UNUSABLE; if (skb_linearize(rx->skb)) return RX_DROP_UNUSABLE; hdr = (void *)skb->data; data = skb->data + hdrlen; data_len = skb->len - hdrlen - MICHAEL_MIC_LEN; key = &rx->key->conf.key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]; michael_mic(key, hdr, data, data_len, mic); if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0) goto mic_fail; /* remove Michael MIC from payload */ skb_trim(skb, skb->len - MICHAEL_MIC_LEN); update_iv: /* update IV in key information to be able to detect replays */ rx->key->u.tkip.rx[rx->security_idx].iv32 = rx->tkip_iv32; rx->key->u.tkip.rx[rx->security_idx].iv16 = rx->tkip_iv16; return RX_CONTINUE; mic_fail: /* * In some cases the key can be unset - e.g. a multicast packet, in * a driver that supports HW encryption. Send up the key idx only if * the key is set. */ mac80211_ev_michael_mic_failure(rx->sdata, rx->key ? rx->key->conf.keyidx : -1, (void *) skb->data, NULL, GFP_ATOMIC); return RX_DROP_UNUSABLE; } static int tkip_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; struct ieee80211_key *key = tx->key; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); unsigned long flags; unsigned int hdrlen; int len, tail; u8 *pos; if (info->control.hw_key && !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { /* hwaccel - with no need for software-generated IV */ return 0; } hdrlen = ieee80211_hdrlen(hdr->frame_control); len = skb->len - hdrlen; if (info->control.hw_key) tail = 0; else tail = TKIP_ICV_LEN; if (WARN_ON(skb_tailroom(skb) < tail || skb_headroom(skb) < TKIP_IV_LEN)) return -1; pos = skb_push(skb, TKIP_IV_LEN); memmove(pos, pos + TKIP_IV_LEN, hdrlen); pos += hdrlen; /* Increase IV for the frame */ spin_lock_irqsave(&key->u.tkip.txlock, flags); key->u.tkip.tx.iv16++; if (key->u.tkip.tx.iv16 == 0) key->u.tkip.tx.iv32++; pos = ieee80211_tkip_add_iv(pos, key); spin_unlock_irqrestore(&key->u.tkip.txlock, flags); /* hwaccel - with software IV */ if (info->control.hw_key) return 0; /* Add room for ICV */ skb_put(skb, TKIP_ICV_LEN); return ieee80211_tkip_encrypt_data(tx->local->wep_tx_tfm, key, skb, pos, len); } ieee80211_tx_result ieee80211_crypto_tkip_encrypt(struct ieee80211_tx_data *tx) { struct sk_buff *skb; ieee80211_tx_set_protected(tx); skb_queue_walk(&tx->skbs, skb) { if (tkip_encrypt_skb(tx, skb) < 0) return TX_DROP; } return TX_CONTINUE; } ieee80211_rx_result ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; int hdrlen, res, hwaccel = 0; struct ieee80211_key *key = rx->key; struct sk_buff *skb = rx->skb; struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); hdrlen = ieee80211_hdrlen(hdr->frame_control); if (!ieee80211_is_data(hdr->frame_control)) return RX_CONTINUE; if (!rx->sta || skb->len - hdrlen < 12) return RX_DROP_UNUSABLE; /* it may be possible to optimize this a bit more */ if (skb_linearize(rx->skb)) return RX_DROP_UNUSABLE; hdr = (void *)skb->data; /* * Let TKIP code verify IV, but skip decryption. * In the case where hardware checks the IV as well, * we don't even get here, see ieee80211_rx_h_decrypt() */ if (status->flag & RX_FLAG_DECRYPTED) hwaccel = 1; res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm, key, skb->data + hdrlen, skb->len - hdrlen, rx->sta->sta.addr, hdr->addr1, hwaccel, rx->security_idx, &rx->tkip_iv32, &rx->tkip_iv16); if (res != TKIP_DECRYPT_OK) return RX_DROP_UNUSABLE; /* Trim ICV */ skb_trim(skb, skb->len - TKIP_ICV_LEN); /* Remove IV */ memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen); skb_pull(skb, TKIP_IV_LEN); return RX_CONTINUE; } static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *scratch, int encrypted) { __le16 mask_fc; int a4_included, mgmt; u8 qos_tid; u8 *b_0, *aad; u16 data_len, len_a; unsigned int hdrlen; struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; memset(scratch, 0, 6 * AES_BLOCK_SIZE); b_0 = scratch + 3 * AES_BLOCK_SIZE; aad = scratch + 4 * AES_BLOCK_SIZE; /* * Mask FC: zero subtype b4 b5 b6 (if not mgmt) * Retry, PwrMgt, MoreData; set Protected */ mgmt = ieee80211_is_mgmt(hdr->frame_control); mask_fc = hdr->frame_control; mask_fc &= ~cpu_to_le16(IEEE80211_FCTL_RETRY | IEEE80211_FCTL_PM | IEEE80211_FCTL_MOREDATA); if (!mgmt) mask_fc &= ~cpu_to_le16(0x0070); mask_fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); hdrlen = ieee80211_hdrlen(hdr->frame_control); len_a = hdrlen - 2; a4_included = ieee80211_has_a4(hdr->frame_control); if (ieee80211_is_data_qos(hdr->frame_control)) qos_tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK; else qos_tid = 0; data_len = skb->len - hdrlen - CCMP_HDR_LEN; if (encrypted) data_len -= CCMP_MIC_LEN; /* First block, b_0 */ b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */ /* Nonce: Nonce Flags | A2 | PN * Nonce Flags: Priority (b0..b3) | Management (b4) | Reserved (b5..b7) */ b_0[1] = qos_tid | (mgmt << 4); memcpy(&b_0[2], hdr->addr2, ETH_ALEN); memcpy(&b_0[8], pn, CCMP_PN_LEN); /* l(m) */ put_unaligned_be16(data_len, &b_0[14]); /* AAD (extra authenticate-only data) / masked 802.11 header * FC | A1 | A2 | A3 | SC | [A4] | [QC] */ put_unaligned_be16(len_a, &aad[0]); put_unaligned(mask_fc, (__le16 *)&aad[2]); memcpy(&aad[4], &hdr->addr1, 3 * ETH_ALEN); /* Mask Seq#, leave Frag# */ aad[22] = *((u8 *) &hdr->seq_ctrl) & 0x0f; aad[23] = 0; if (a4_included) { memcpy(&aad[24], hdr->addr4, ETH_ALEN); aad[30] = qos_tid; aad[31] = 0; } else { memset(&aad[24], 0, ETH_ALEN + IEEE80211_QOS_CTL_LEN); aad[24] = qos_tid; } } static inline void ccmp_pn2hdr(u8 *hdr, u8 *pn, int key_id) { hdr[0] = pn[5]; hdr[1] = pn[4]; hdr[2] = 0; hdr[3] = 0x20 | (key_id << 6); hdr[4] = pn[3]; hdr[5] = pn[2]; hdr[6] = pn[1]; hdr[7] = pn[0]; } static inline void ccmp_hdr2pn(u8 *pn, u8 *hdr) { pn[0] = hdr[7]; pn[1] = hdr[6]; pn[2] = hdr[5]; pn[3] = hdr[4]; pn[4] = hdr[1]; pn[5] = hdr[0]; } static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; struct ieee80211_key *key = tx->key; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); int hdrlen, len, tail; u8 *pos; u8 pn[6]; u64 pn64; u8 scratch[6 * AES_BLOCK_SIZE]; if (info->control.hw_key && !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV) && !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)) { /* * hwaccel has no need for preallocated room for CCMP * header or MIC fields */ return 0; } hdrlen = ieee80211_hdrlen(hdr->frame_control); len = skb->len - hdrlen; if (info->control.hw_key) tail = 0; else tail = CCMP_MIC_LEN; if (WARN_ON(skb_tailroom(skb) < tail || skb_headroom(skb) < CCMP_HDR_LEN)) return -1; pos = skb_push(skb, CCMP_HDR_LEN); memmove(pos, pos + CCMP_HDR_LEN, hdrlen); /* the HW only needs room for the IV, but not the actual IV */ if (info->control.hw_key && (info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)) return 0; hdr = (struct ieee80211_hdr *) pos; pos += hdrlen; pn64 = atomic64_inc_return(&key->u.ccmp.tx_pn); pn[5] = pn64; pn[4] = pn64 >> 8; pn[3] = pn64 >> 16; pn[2] = pn64 >> 24; pn[1] = pn64 >> 32; pn[0] = pn64 >> 40; ccmp_pn2hdr(pos, pn, key->conf.keyidx); /* hwaccel - with software CCMP header */ if (info->control.hw_key) return 0; pos += CCMP_HDR_LEN; ccmp_special_blocks(skb, pn, scratch, 0); ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, scratch, pos, len, pos, skb_put(skb, CCMP_MIC_LEN)); return 0; } ieee80211_tx_result ieee80211_crypto_ccmp_encrypt(struct ieee80211_tx_data *tx) { struct sk_buff *skb; ieee80211_tx_set_protected(tx); skb_queue_walk(&tx->skbs, skb) { if (ccmp_encrypt_skb(tx, skb) < 0) return TX_DROP; } return TX_CONTINUE; } ieee80211_rx_result ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; int hdrlen; struct ieee80211_key *key = rx->key; struct sk_buff *skb = rx->skb; struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); u8 pn[CCMP_PN_LEN]; int data_len; int queue; hdrlen = ieee80211_hdrlen(hdr->frame_control); if (!ieee80211_is_data(hdr->frame_control) && !ieee80211_is_robust_mgmt_frame(hdr)) return RX_CONTINUE; data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN; if (!rx->sta || data_len < 0) return RX_DROP_UNUSABLE; if (status->flag & RX_FLAG_DECRYPTED) { if (!pskb_may_pull(rx->skb, hdrlen + CCMP_HDR_LEN)) return RX_DROP_UNUSABLE; } else { if (skb_linearize(rx->skb)) return RX_DROP_UNUSABLE; } ccmp_hdr2pn(pn, skb->data + hdrlen); queue = rx->security_idx; if (memcmp(pn, key->u.ccmp.rx_pn[queue], CCMP_PN_LEN) <= 0) { key->u.ccmp.replays++; return RX_DROP_UNUSABLE; } if (!(status->flag & RX_FLAG_DECRYPTED)) { u8 scratch[6 * AES_BLOCK_SIZE]; /* hardware didn't decrypt/verify MIC */ ccmp_special_blocks(skb, pn, scratch, 1); if (ieee80211_aes_ccm_decrypt( key->u.ccmp.tfm, scratch, skb->data + hdrlen + CCMP_HDR_LEN, data_len, skb->data + skb->len - CCMP_MIC_LEN, skb->data + hdrlen + CCMP_HDR_LEN)) return RX_DROP_UNUSABLE; } memcpy(key->u.ccmp.rx_pn[queue], pn, CCMP_PN_LEN); /* Remove CCMP header and MIC */ if (pskb_trim(skb, skb->len - CCMP_MIC_LEN)) return RX_DROP_UNUSABLE; memmove(skb->data + CCMP_HDR_LEN, skb->data, hdrlen); skb_pull(skb, CCMP_HDR_LEN); return RX_CONTINUE; } static void bip_aad(struct sk_buff *skb, u8 *aad) { /* BIP AAD: FC(masked) || A1 || A2 || A3 */ /* FC type/subtype */ aad[0] = skb->data[0]; /* Mask FC Retry, PwrMgt, MoreData flags to zero */ aad[1] = skb->data[1] & ~(BIT(4) | BIT(5) | BIT(6)); /* A1 || A2 || A3 */ memcpy(aad + 2, skb->data + 4, 3 * ETH_ALEN); } static inline void bip_ipn_set64(u8 *d, u64 pn) { *d++ = pn; *d++ = pn >> 8; *d++ = pn >> 16; *d++ = pn >> 24; *d++ = pn >> 32; *d = pn >> 40; } static inline void bip_ipn_swap(u8 *d, const u8 *s) { *d++ = s[5]; *d++ = s[4]; *d++ = s[3]; *d++ = s[2]; *d++ = s[1]; *d = s[0]; } ieee80211_tx_result ieee80211_crypto_aes_cmac_encrypt(struct ieee80211_tx_data *tx) { struct sk_buff *skb; struct ieee80211_tx_info *info; struct ieee80211_key *key = tx->key; struct ieee80211_mmie *mmie; u8 aad[20]; u64 pn64; if (WARN_ON(skb_queue_len(&tx->skbs) != 1)) return TX_DROP; skb = skb_peek(&tx->skbs); info = IEEE80211_SKB_CB(skb); if (info->control.hw_key) return TX_CONTINUE; if (WARN_ON(skb_tailroom(skb) < sizeof(*mmie))) return TX_DROP; mmie = (struct ieee80211_mmie *) skb_put(skb, sizeof(*mmie)); mmie->element_id = WLAN_EID_MMIE; mmie->length = sizeof(*mmie) - 2; mmie->key_id = cpu_to_le16(key->conf.keyidx); /* PN = PN + 1 */ pn64 = atomic64_inc_return(&key->u.aes_cmac.tx_pn); bip_ipn_set64(mmie->sequence_number, pn64); bip_aad(skb, aad); /* * MIC = AES-128-CMAC(IGTK, AAD || Management Frame Body || MMIE, 64) */ ieee80211_aes_cmac(key->u.aes_cmac.tfm, aad, skb->data + 24, skb->len - 24, mmie->mic); return TX_CONTINUE; } ieee80211_rx_result ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx) { struct sk_buff *skb = rx->skb; struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); struct ieee80211_key *key = rx->key; struct ieee80211_mmie *mmie; u8 aad[20], mic[8], ipn[6]; struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; if (!ieee80211_is_mgmt(hdr->frame_control)) return RX_CONTINUE; /* management frames are already linear */ if (skb->len < 24 + sizeof(*mmie)) return RX_DROP_UNUSABLE; mmie = (struct ieee80211_mmie *) (skb->data + skb->len - sizeof(*mmie)); if (mmie->element_id != WLAN_EID_MMIE || mmie->length != sizeof(*mmie) - 2) return RX_DROP_UNUSABLE; /* Invalid MMIE */ bip_ipn_swap(ipn, mmie->sequence_number); if (memcmp(ipn, key->u.aes_cmac.rx_pn, 6) <= 0) { key->u.aes_cmac.replays++; return RX_DROP_UNUSABLE; } if (!(status->flag & RX_FLAG_DECRYPTED)) { /* hardware didn't decrypt/verify MIC */ bip_aad(skb, aad); ieee80211_aes_cmac(key->u.aes_cmac.tfm, aad, skb->data + 24, skb->len - 24, mic); if (memcmp(mic, mmie->mic, sizeof(mmie->mic)) != 0) { key->u.aes_cmac.icverrors++; return RX_DROP_UNUSABLE; } } memcpy(key->u.aes_cmac.rx_pn, ipn, 6); /* Remove MMIE */ skb_trim(skb, skb->len - sizeof(*mmie)); return RX_CONTINUE; } ieee80211_tx_result ieee80211_crypto_hw_encrypt(struct ieee80211_tx_data *tx) { struct sk_buff *skb; struct ieee80211_tx_info *info = NULL; skb_queue_walk(&tx->skbs, skb) { info = IEEE80211_SKB_CB(skb); /* handle hw-only algorithm */ if (!info->control.hw_key) return TX_DROP; } ieee80211_tx_set_protected(tx); return TX_CONTINUE; }
Arc-Team/android_kernel_samsung_jflte
net/mac80211/wpa.c
C
gpl-2.0
17,101
/* * linux/sound/oss/dmasound/dmasound_core.c * * * OSS/Free compatible Atari TT/Falcon and Amiga DMA sound driver for * Linux/m68k * Extended to support Power Macintosh for Linux/ppc by Paul Mackerras * * (c) 1995 by Michael Schlueter & Michael Marte * * Michael Schlueter (michael@duck.syd.de) did the basic structure of the VFS * interface and the u-law to signed byte conversion. * * Michael Marte (marte@informatik.uni-muenchen.de) did the sound queue, * /dev/mixer, /dev/sndstat and complemented the VFS interface. He would like * to thank: * - Michael Schlueter for initial ideas and documentation on the MFP and * the DMA sound hardware. * - Therapy? for their CD 'Troublegum' which really made me rock. * * /dev/sndstat is based on code by Hannu Savolainen, the author of the * VoxWare family of drivers. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details. * * History: * * 1995/8/25 First release * * 1995/9/02 Roman Hodek: * - Fixed atari_stram_alloc() call, the timer * programming and several race conditions * 1995/9/14 Roman Hodek: * - After some discussion with Michael Schlueter, * revised the interrupt disabling * - Slightly speeded up U8->S8 translation by using * long operations where possible * - Added 4:3 interpolation for /dev/audio * * 1995/9/20 Torsten Scherer: * - Fixed a bug in sq_write and changed /dev/audio * converting to play at 12517Hz instead of 6258Hz. * * 1995/9/23 Torsten Scherer: * - Changed sq_interrupt() and sq_play() to pre-program * the DMA for another frame while there's still one * running. This allows the IRQ response to be * arbitrarily delayed and playing will still continue. * * 1995/10/14 Guenther Kelleter, Torsten Scherer: * - Better support for Falcon audio (the Falcon doesn't * raise an IRQ at the end of a frame, but at the * beginning instead!). uses 'if (codec_dma)' in lots * of places to simply switch between Falcon and TT * code. * * 1995/11/06 Torsten Scherer: * - Started introducing a hardware abstraction scheme * (may perhaps also serve for Amigas?) * - Can now play samples at almost all frequencies by * means of a more generalized expand routine * - Takes a good deal of care to cut data only at * sample sizes * - Buffer size is now a kernel runtime option * - Implemented fsync() & several minor improvements * Guenther Kelleter: * - Useful hints and bug fixes * - Cross-checked it for Falcons * * 1996/3/9 Geert Uytterhoeven: * - Support added for Amiga, A-law, 16-bit little * endian. * - Unification to drivers/sound/dmasound.c. * * 1996/4/6 Martin Mitchell: * - Updated to 1.3 kernel. * * 1996/6/13 Topi Kanerva: * - Fixed things that were broken (mainly the amiga * 14-bit routines) * - /dev/sndstat shows now the real hardware frequency * - The lowpass filter is disabled by default now * * 1996/9/25 Geert Uytterhoeven: * - Modularization * * 1998/6/10 Andreas Schwab: * - Converted to use sound_core * * 1999/12/28 Richard Zidlicky: * - Added support for Q40 * * 2000/2/27 Geert Uytterhoeven: * - Clean up and split the code into 4 parts: * o dmasound_core: machine-independent code * o dmasound_atari: Atari TT and Falcon support * o dmasound_awacs: Apple PowerMac support * o dmasound_paula: Amiga support * * 2000/3/25 Geert Uytterhoeven: * - Integration of dmasound_q40 * - Small clean ups * * 2001/01/26 [1.0] Iain Sandoe * - make /dev/sndstat show revision & edition info. * - since dmasound.mach.sq_setup() can fail on pmac * its type has been changed to int and the returns * are checked. * [1.1] - stop missing translations from being called. * 2001/02/08 [1.2] - remove unused translation tables & move machine- * specific tables to low-level. * - return correct info. for SNDCTL_DSP_GETFMTS. * [1.3] - implement SNDCTL_DSP_GETCAPS fully. * [1.4] - make /dev/sndstat text length usage deterministic. * - make /dev/sndstat call to low-level * dmasound.mach.state_info() pass max space to ll driver. * - tidy startup banners and output info. * [1.5] - tidy up a little (removed some unused #defines in * dmasound.h) * - fix up HAS_RECORD conditionalisation. * - add record code in places it is missing... * - change buf-sizes to bytes to allow < 1kb for pmac * if user param entry is < 256 the value is taken to * be in kb > 256 is taken to be in bytes. * - make default buff/frag params conditional on * machine to allow smaller values for pmac. * - made the ioctls, read & write comply with the OSS * rules on setting params. * - added parsing of _setup() params for record. * 2001/04/04 [1.6] - fix bug where sample rates higher than maximum were * being reported as OK. * - fix open() to return -EBUSY as per OSS doc. when * audio is in use - this is independent of O_NOBLOCK. * - fix bug where SNDCTL_DSP_POST was blocking. */ /* Record capability notes 30/01/2001: * At present these observations apply only to pmac LL driver (the only one * that can do record, at present). However, if other LL drivers for machines * with record are added they may apply. * * The fragment parameters for the record and play channels are separate. * However, if the driver is opened O_RDWR there is no way (in the current OSS * API) to specify their values independently for the record and playback * channels. Since the only common factor between the input & output is the * sample rate (on pmac) it should be possible to open /dev/dspX O_WRONLY and * /dev/dspY O_RDONLY. The input & output channels could then have different * characteristics (other than the first that sets sample rate claiming the * right to set it for ever). As it stands, the format, channels, number of * bits & sample rate are assumed to be common. In the future perhaps these * should be the responsibility of the LL driver - and then if a card really * does not share items between record & playback they can be specified * separately. */ /* Thread-safeness of shared_resources notes: 31/01/2001 * If the user opens O_RDWR and then splits record & play between two threads * both of which inherit the fd - and then starts changing things from both * - we will have difficulty telling. * * It's bad application coding - but ... * TODO: think about how to sort this out... without bogging everything down in * semaphores. * * Similarly, the OSS spec says "all changes to parameters must be between * open() and the first read() or write(). - and a bit later on (by * implication) "between SNDCTL_DSP_RESET and the first read() or write() after * it". If the app is multi-threaded and this rule is broken between threads * we will have trouble spotting it - and the fault will be rather obscure :-( * * We will try and put out at least a kmsg if we see it happen... but I think * it will be quite hard to trap it with an -EXXX return... because we can't * see the fault until after the damage is done. */ #include <linux/module.h> #include <linux/slab.h> #include <linux/sound.h> #include <linux/init.h> #include <linux/soundcard.h> #include <linux/poll.h> #include <linux/mutex.h> #include <asm/uaccess.h> #include "dmasound.h" #define DMASOUND_CORE_REVISION 1 #define DMASOUND_CORE_EDITION 6 /* * Declarations */ static DEFINE_MUTEX(dmasound_core_mutex); int dmasound_catchRadius = 0; module_param(dmasound_catchRadius, int, 0); static unsigned int numWriteBufs = DEFAULT_N_BUFFERS; module_param(numWriteBufs, int, 0); static unsigned int writeBufSize = DEFAULT_BUFF_SIZE ; /* in bytes */ module_param(writeBufSize, int, 0); MODULE_LICENSE("GPL"); #ifdef MODULE static int sq_unit = -1; static int mixer_unit = -1; static int state_unit = -1; static int irq_installed; #endif /* MODULE */ /* control over who can modify resources shared between play/record */ static fmode_t shared_resource_owner; static int shared_resources_initialised; /* * Mid level stuff */ struct sound_settings dmasound = { .lock = __SPIN_LOCK_UNLOCKED(dmasound.lock) }; static inline void sound_silence(void) { dmasound.mach.silence(); /* _MUST_ stop DMA */ } static inline int sound_set_format(int format) { return dmasound.mach.setFormat(format); } static int sound_set_speed(int speed) { if (speed < 0) return dmasound.soft.speed; /* trap out-of-range speed settings. at present we allow (arbitrarily) low rates - using soft up-conversion - but we can't allow > max because there is no soft down-conversion. */ if (dmasound.mach.max_dsp_speed && (speed > dmasound.mach.max_dsp_speed)) speed = dmasound.mach.max_dsp_speed ; dmasound.soft.speed = speed; if (dmasound.minDev == SND_DEV_DSP) dmasound.dsp.speed = dmasound.soft.speed; return dmasound.soft.speed; } static int sound_set_stereo(int stereo) { if (stereo < 0) return dmasound.soft.stereo; stereo = !!stereo; /* should be 0 or 1 now */ dmasound.soft.stereo = stereo; if (dmasound.minDev == SND_DEV_DSP) dmasound.dsp.stereo = stereo; return stereo; } static ssize_t sound_copy_translate(TRANS *trans, const u_char __user *userPtr, size_t userCount, u_char frame[], ssize_t *frameUsed, ssize_t frameLeft) { ssize_t (*ct_func)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t); switch (dmasound.soft.format) { case AFMT_MU_LAW: ct_func = trans->ct_ulaw; break; case AFMT_A_LAW: ct_func = trans->ct_alaw; break; case AFMT_S8: ct_func = trans->ct_s8; break; case AFMT_U8: ct_func = trans->ct_u8; break; case AFMT_S16_BE: ct_func = trans->ct_s16be; break; case AFMT_U16_BE: ct_func = trans->ct_u16be; break; case AFMT_S16_LE: ct_func = trans->ct_s16le; break; case AFMT_U16_LE: ct_func = trans->ct_u16le; break; default: return 0; } /* if the user has requested a non-existent translation don't try to call it but just return 0 bytes moved */ if (ct_func) return ct_func(userPtr, userCount, frame, frameUsed, frameLeft); return 0; } /* * /dev/mixer abstraction */ static struct { int busy; int modify_counter; } mixer; static int mixer_open(struct inode *inode, struct file *file) { mutex_lock(&dmasound_core_mutex); if (!try_module_get(dmasound.mach.owner)) { mutex_unlock(&dmasound_core_mutex); return -ENODEV; } mixer.busy = 1; mutex_unlock(&dmasound_core_mutex); return 0; } static int mixer_release(struct inode *inode, struct file *file) { mutex_lock(&dmasound_core_mutex); mixer.busy = 0; module_put(dmasound.mach.owner); mutex_unlock(&dmasound_core_mutex); return 0; } static int mixer_ioctl(struct file *file, u_int cmd, u_long arg) { if (_SIOC_DIR(cmd) & _SIOC_WRITE) mixer.modify_counter++; switch (cmd) { case OSS_GETVERSION: return IOCTL_OUT(arg, SOUND_VERSION); case SOUND_MIXER_INFO: { mixer_info info; memset(&info, 0, sizeof(info)); strlcpy(info.id, dmasound.mach.name2, sizeof(info.id)); strlcpy(info.name, dmasound.mach.name2, sizeof(info.name)); info.modify_counter = mixer.modify_counter; if (copy_to_user((void __user *)arg, &info, sizeof(info))) return -EFAULT; return 0; } } if (dmasound.mach.mixer_ioctl) return dmasound.mach.mixer_ioctl(cmd, arg); return -EINVAL; } static long mixer_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) { int ret; mutex_lock(&dmasound_core_mutex); ret = mixer_ioctl(file, cmd, arg); mutex_unlock(&dmasound_core_mutex); return ret; } static const struct file_operations mixer_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .unlocked_ioctl = mixer_unlocked_ioctl, .open = mixer_open, .release = mixer_release, }; static void mixer_init(void) { #ifndef MODULE int mixer_unit; #endif mixer_unit = register_sound_mixer(&mixer_fops, -1); if (mixer_unit < 0) return; mixer.busy = 0; dmasound.treble = 0; dmasound.bass = 0; if (dmasound.mach.mixer_init) dmasound.mach.mixer_init(); } /* * Sound queue stuff, the heart of the driver */ struct sound_queue dmasound_write_sq; static void sq_reset_output(void) ; static int sq_allocate_buffers(struct sound_queue *sq, int num, int size) { int i; if (sq->buffers) return 0; sq->numBufs = num; sq->bufSize = size; sq->buffers = kmalloc (num * sizeof(char *), GFP_KERNEL); if (!sq->buffers) return -ENOMEM; for (i = 0; i < num; i++) { sq->buffers[i] = dmasound.mach.dma_alloc(size, GFP_KERNEL); if (!sq->buffers[i]) { while (i--) dmasound.mach.dma_free(sq->buffers[i], size); kfree(sq->buffers); sq->buffers = NULL; return -ENOMEM; } } return 0; } static void sq_release_buffers(struct sound_queue *sq) { int i; if (sq->buffers) { for (i = 0; i < sq->numBufs; i++) dmasound.mach.dma_free(sq->buffers[i], sq->bufSize); kfree(sq->buffers); sq->buffers = NULL; } } static int sq_setup(struct sound_queue *sq) { int (*setup_func)(void) = NULL; int hard_frame ; if (sq->locked) { /* are we already set? - and not changeable */ #ifdef DEBUG_DMASOUND printk("dmasound_core: tried to sq_setup a locked queue\n") ; #endif return -EINVAL ; } sq->locked = 1 ; /* don't think we have a race prob. here _check_ */ /* make sure that the parameters are set up This should have been done already... */ dmasound.mach.init(); /* OK. If the user has set fragment parameters explicitly, then we should leave them alone... as long as they are valid. Invalid user fragment params can occur if we allow the whole buffer to be used when the user requests the fragments sizes (with no soft x-lation) and then the user subsequently sets a soft x-lation that requires increased internal buffering. Othwerwise (if the user did not set them) OSS says that we should select frag params on the basis of 0.5 s output & 0.1 s input latency. (TODO. For now we will copy in the defaults.) */ if (sq->user_frags <= 0) { sq->max_count = sq->numBufs ; sq->max_active = sq->numBufs ; sq->block_size = sq->bufSize; /* set up the user info */ sq->user_frags = sq->numBufs ; sq->user_frag_size = sq->bufSize ; sq->user_frag_size *= (dmasound.soft.size * (dmasound.soft.stereo+1) ) ; sq->user_frag_size /= (dmasound.hard.size * (dmasound.hard.stereo+1) ) ; } else { /* work out requested block size */ sq->block_size = sq->user_frag_size ; sq->block_size *= (dmasound.hard.size * (dmasound.hard.stereo+1) ) ; sq->block_size /= (dmasound.soft.size * (dmasound.soft.stereo+1) ) ; /* the user wants to write frag-size chunks */ sq->block_size *= dmasound.hard.speed ; sq->block_size /= dmasound.soft.speed ; /* this only works for size values which are powers of 2 */ hard_frame = (dmasound.hard.size * (dmasound.hard.stereo+1))/8 ; sq->block_size += (hard_frame - 1) ; sq->block_size &= ~(hard_frame - 1) ; /* make sure we are aligned */ /* let's just check for obvious mistakes */ if ( sq->block_size <= 0 || sq->block_size > sq->bufSize) { #ifdef DEBUG_DMASOUND printk("dmasound_core: invalid frag size (user set %d)\n", sq->user_frag_size) ; #endif sq->block_size = sq->bufSize ; } if ( sq->user_frags <= sq->numBufs ) { sq->max_count = sq->user_frags ; /* if user has set max_active - then use it */ sq->max_active = (sq->max_active <= sq->max_count) ? sq->max_active : sq->max_count ; } else { #ifdef DEBUG_DMASOUND printk("dmasound_core: invalid frag count (user set %d)\n", sq->user_frags) ; #endif sq->max_count = sq->max_active = sq->numBufs ; } } sq->front = sq->count = sq->rear_size = 0; sq->syncing = 0; sq->active = 0; if (sq == &write_sq) { sq->rear = -1; setup_func = dmasound.mach.write_sq_setup; } if (setup_func) return setup_func(); return 0 ; } static inline void sq_play(void) { dmasound.mach.play(); } static ssize_t sq_write(struct file *file, const char __user *src, size_t uLeft, loff_t *ppos) { ssize_t uWritten = 0; u_char *dest; ssize_t uUsed = 0, bUsed, bLeft; unsigned long flags ; /* ++TeSche: Is something like this necessary? * Hey, that's an honest question! Or does any other part of the * filesystem already checks this situation? I really don't know. */ if (uLeft == 0) return 0; /* implement any changes we have made to the soft/hard params. this is not satisfactory really, all we have done up to now is to say what we would like - there hasn't been any real checking of capability */ if (shared_resources_initialised == 0) { dmasound.mach.init() ; shared_resources_initialised = 1 ; } /* set up the sq if it is not already done. This may seem a dumb place to do it - but it is what OSS requires. It means that write() can return memory allocation errors. To avoid this possibility use the GETBLKSIZE or GETOSPACE ioctls (after you've fiddled with all the params you want to change) - these ioctls also force the setup. */ if (write_sq.locked == 0) { if ((uWritten = sq_setup(&write_sq)) < 0) return uWritten ; uWritten = 0 ; } /* FIXME: I think that this may be the wrong behaviour when we get strapped for time and the cpu is close to being (or actually) behind in sending data. - because we've lost the time that the N samples, already in the buffer, would have given us to get here with the next lot from the user. */ /* The interrupt doesn't start to play the last, incomplete frame. * Thus we can append to it without disabling the interrupts! (Note * also that write_sq.rear isn't affected by the interrupt.) */ /* as of 1.6 this behaviour changes if SNDCTL_DSP_POST has been issued: this will mimic the behaviour of syncing and allow the sq_play() to queue a partial fragment. Since sq_play() may/will be called from the IRQ handler - at least on Pmac we have to deal with it. The strategy - possibly not optimum - is to kill _POST status if we get here. This seems, at least, reasonable - in the sense that POST is supposed to indicate that we might not write before the queue is drained - and if we get here in time then it does not apply. */ spin_lock_irqsave(&dmasound.lock, flags); write_sq.syncing &= ~2 ; /* take out POST status */ spin_unlock_irqrestore(&dmasound.lock, flags); if (write_sq.count > 0 && (bLeft = write_sq.block_size-write_sq.rear_size) > 0) { dest = write_sq.buffers[write_sq.rear]; bUsed = write_sq.rear_size; uUsed = sound_copy_translate(dmasound.trans_write, src, uLeft, dest, &bUsed, bLeft); if (uUsed <= 0) return uUsed; src += uUsed; uWritten += uUsed; uLeft = (uUsed <= uLeft) ? (uLeft - uUsed) : 0 ; /* paranoia */ write_sq.rear_size = bUsed; } while (uLeft) { while (write_sq.count >= write_sq.max_active) { sq_play(); if (write_sq.non_blocking) return uWritten > 0 ? uWritten : -EAGAIN; SLEEP(write_sq.action_queue); if (signal_pending(current)) return uWritten > 0 ? uWritten : -EINTR; } /* Here, we can avoid disabling the interrupt by first * copying and translating the data, and then updating * the write_sq variables. Until this is done, the interrupt * won't see the new frame and we can work on it * undisturbed. */ dest = write_sq.buffers[(write_sq.rear+1) % write_sq.max_count]; bUsed = 0; bLeft = write_sq.block_size; uUsed = sound_copy_translate(dmasound.trans_write, src, uLeft, dest, &bUsed, bLeft); if (uUsed <= 0) break; src += uUsed; uWritten += uUsed; uLeft = (uUsed <= uLeft) ? (uLeft - uUsed) : 0 ; /* paranoia */ if (bUsed) { write_sq.rear = (write_sq.rear+1) % write_sq.max_count; write_sq.rear_size = bUsed; write_sq.count++; } } /* uUsed may have been 0 */ sq_play(); return uUsed < 0? uUsed: uWritten; } static unsigned int sq_poll(struct file *file, struct poll_table_struct *wait) { unsigned int mask = 0; int retVal; if (write_sq.locked == 0) { if ((retVal = sq_setup(&write_sq)) < 0) return retVal; return 0; } if (file->f_mode & FMODE_WRITE ) poll_wait(file, &write_sq.action_queue, wait); if (file->f_mode & FMODE_WRITE) if (write_sq.count < write_sq.max_active || write_sq.block_size - write_sq.rear_size > 0) mask |= POLLOUT | POLLWRNORM; return mask; } static inline void sq_init_waitqueue(struct sound_queue *sq) { init_waitqueue_head(&sq->action_queue); init_waitqueue_head(&sq->open_queue); init_waitqueue_head(&sq->sync_queue); sq->busy = 0; } #if 0 /* blocking open() */ static inline void sq_wake_up(struct sound_queue *sq, struct file *file, fmode_t mode) { if (file->f_mode & mode) { sq->busy = 0; /* CHECK: IS THIS OK??? */ WAKE_UP(sq->open_queue); } } #endif static int sq_open2(struct sound_queue *sq, struct file *file, fmode_t mode, int numbufs, int bufsize) { int rc = 0; if (file->f_mode & mode) { if (sq->busy) { #if 0 /* blocking open() */ rc = -EBUSY; if (file->f_flags & O_NONBLOCK) return rc; rc = -EINTR; while (sq->busy) { SLEEP(sq->open_queue); if (signal_pending(current)) return rc; } rc = 0; #else /* OSS manual says we will return EBUSY regardless of O_NOBLOCK. */ return -EBUSY ; #endif } sq->busy = 1; /* Let's play spot-the-race-condition */ /* allocate the default number & size of buffers. (i.e. specified in _setup() or as module params) can't be changed at the moment - but _could_ be perhaps in the setfragments ioctl. */ if (( rc = sq_allocate_buffers(sq, numbufs, bufsize))) { #if 0 /* blocking open() */ sq_wake_up(sq, file, mode); #else sq->busy = 0 ; #endif return rc; } sq->non_blocking = file->f_flags & O_NONBLOCK; } return rc; } #define write_sq_init_waitqueue() sq_init_waitqueue(&write_sq) #if 0 /* blocking open() */ #define write_sq_wake_up(file) sq_wake_up(&write_sq, file, FMODE_WRITE) #endif #define write_sq_release_buffers() sq_release_buffers(&write_sq) #define write_sq_open(file) \ sq_open2(&write_sq, file, FMODE_WRITE, numWriteBufs, writeBufSize ) static int sq_open(struct inode *inode, struct file *file) { int rc; mutex_lock(&dmasound_core_mutex); if (!try_module_get(dmasound.mach.owner)) { mutex_unlock(&dmasound_core_mutex); return -ENODEV; } rc = write_sq_open(file); /* checks the f_mode */ if (rc) goto out; if (file->f_mode & FMODE_READ) { /* TODO: if O_RDWR, release any resources grabbed by write part */ rc = -ENXIO ; /* I think this is what is required by open(2) */ goto out; } if (dmasound.mach.sq_open) dmasound.mach.sq_open(file->f_mode); /* CHECK whether this is sensible - in the case that dsp0 could be opened O_RDONLY and dsp1 could be opened O_WRONLY */ dmasound.minDev = iminor(inode) & 0x0f; /* OK. - we should make some attempt at consistency. At least the H'ware options should be set with a valid mode. We will make it that the LL driver must supply defaults for hard & soft params. */ if (shared_resource_owner == 0) { /* you can make this AFMT_U8/mono/8K if you want to mimic old OSS behaviour - while we still have soft translations ;-) */ dmasound.soft = dmasound.mach.default_soft ; dmasound.dsp = dmasound.mach.default_soft ; dmasound.hard = dmasound.mach.default_hard ; } #ifndef DMASOUND_STRICT_OSS_COMPLIANCE /* none of the current LL drivers can actually do this "native" at the moment OSS does not really require us to supply /dev/audio if we can't do it. */ if (dmasound.minDev == SND_DEV_AUDIO) { sound_set_speed(8000); sound_set_stereo(0); sound_set_format(AFMT_MU_LAW); } #endif mutex_unlock(&dmasound_core_mutex); return 0; out: module_put(dmasound.mach.owner); mutex_unlock(&dmasound_core_mutex); return rc; } static void sq_reset_output(void) { sound_silence(); /* this _must_ stop DMA, we might be about to lose the buffers */ write_sq.active = 0; write_sq.count = 0; write_sq.rear_size = 0; /* write_sq.front = (write_sq.rear+1) % write_sq.max_count;*/ write_sq.front = 0 ; write_sq.rear = -1 ; /* same as for set-up */ /* OK - we can unlock the parameters and fragment settings */ write_sq.locked = 0 ; write_sq.user_frags = 0 ; write_sq.user_frag_size = 0 ; } static void sq_reset(void) { sq_reset_output() ; /* we could consider resetting the shared_resources_owner here... but I think it is probably still rather non-obvious to application writer */ /* we release everything else though */ shared_resources_initialised = 0 ; } static int sq_fsync(void) { int rc = 0; int timeout = 5; write_sq.syncing |= 1; sq_play(); /* there may be an incomplete frame waiting */ while (write_sq.active) { SLEEP(write_sq.sync_queue); if (signal_pending(current)) { /* While waiting for audio output to drain, an * interrupt occurred. Stop audio output immediately * and clear the queue. */ sq_reset_output(); rc = -EINTR; break; } if (!--timeout) { printk(KERN_WARNING "dmasound: Timeout draining output\n"); sq_reset_output(); rc = -EIO; break; } } /* flag no sync regardless of whether we had a DSP_POST or not */ write_sq.syncing = 0 ; return rc; } static int sq_release(struct inode *inode, struct file *file) { int rc = 0; mutex_lock(&dmasound_core_mutex); if (file->f_mode & FMODE_WRITE) { if (write_sq.busy) rc = sq_fsync(); sq_reset_output() ; /* make sure dma is stopped and all is quiet */ write_sq_release_buffers(); write_sq.busy = 0; } if (file->f_mode & shared_resource_owner) { /* it's us that has them */ shared_resource_owner = 0 ; shared_resources_initialised = 0 ; dmasound.hard = dmasound.mach.default_hard ; } module_put(dmasound.mach.owner); #if 0 /* blocking open() */ /* Wake up a process waiting for the queue being released. * Note: There may be several processes waiting for a call * to open() returning. */ /* Iain: hmm I don't understand this next comment ... */ /* There is probably a DOS atack here. They change the mode flag. */ /* XXX add check here,*/ read_sq_wake_up(file); /* checks f_mode */ write_sq_wake_up(file); /* checks f_mode */ #endif /* blocking open() */ mutex_unlock(&dmasound_core_mutex); return rc; } /* here we see if we have a right to modify format, channels, size and so on if no-one else has claimed it already then we do... TODO: We might change this to mask O_RDWR such that only one or the other channel is the owner - if we have problems. */ static int shared_resources_are_mine(fmode_t md) { if (shared_resource_owner) return (shared_resource_owner & md) != 0; else { shared_resource_owner = md ; return 1 ; } } /* if either queue is locked we must deny the right to change shared params */ static int queues_are_quiescent(void) { if (write_sq.locked) return 0 ; return 1 ; } /* check and set a queue's fragments per user's wishes... we will check against the pre-defined literals and the actual sizes. This is a bit fraught - because soft translations can mess with our buffer requirements *after* this call - OSS says "call setfrags first" */ /* It is possible to replace all the -EINVAL returns with an override that just puts the allowable value in. This may be what many OSS apps require */ static int set_queue_frags(struct sound_queue *sq, int bufs, int size) { if (sq->locked) { #ifdef DEBUG_DMASOUND printk("dmasound_core: tried to set_queue_frags on a locked queue\n") ; #endif return -EINVAL ; } if ((size < MIN_FRAG_SIZE) || (size > MAX_FRAG_SIZE)) return -EINVAL ; size = (1<<size) ; /* now in bytes */ if (size > sq->bufSize) return -EINVAL ; /* this might still not work */ if (bufs <= 0) return -EINVAL ; if (bufs > sq->numBufs) /* the user is allowed say "don't care" with 0x7fff */ bufs = sq->numBufs ; /* there is, currently, no way to specify max_active separately from max_count. This could be a LL driver issue - I guess if there is a requirement for these values to be different then we will have to pass that info. up to this level. */ sq->user_frags = sq->max_active = bufs ; sq->user_frag_size = size ; return 0 ; } static int sq_ioctl(struct file *file, u_int cmd, u_long arg) { int val, result; u_long fmt; int data; int size, nbufs; audio_buf_info info; switch (cmd) { case SNDCTL_DSP_RESET: sq_reset(); return 0; break ; case SNDCTL_DSP_GETFMTS: fmt = dmasound.mach.hardware_afmts ; /* this is what OSS says.. */ return IOCTL_OUT(arg, fmt); break ; case SNDCTL_DSP_GETBLKSIZE: /* this should tell the caller about bytes that the app can read/write - the app doesn't care about our internal buffers. We force sq_setup() here as per OSS 1.1 (which should compute the values necessary). Since there is no mechanism to specify read/write separately, for fds opened O_RDWR, the write_sq values will, arbitrarily, overwrite the read_sq ones. */ size = 0 ; if (file->f_mode & FMODE_WRITE) { if ( !write_sq.locked ) sq_setup(&write_sq) ; size = write_sq.user_frag_size ; } return IOCTL_OUT(arg, size); break ; case SNDCTL_DSP_POST: /* all we are going to do is to tell the LL that any partial frags can be queued for output. The LL will have to clear this flag when last output is queued. */ write_sq.syncing |= 0x2 ; sq_play() ; return 0 ; case SNDCTL_DSP_SYNC: /* This call, effectively, has the same behaviour as SNDCTL_DSP_RESET except that it waits for output to finish before resetting everything - read, however, is killed immediately. */ result = 0 ; if (file->f_mode & FMODE_WRITE) { result = sq_fsync(); sq_reset_output() ; } /* if we are the shared resource owner then release them */ if (file->f_mode & shared_resource_owner) shared_resources_initialised = 0 ; return result ; break ; case SOUND_PCM_READ_RATE: return IOCTL_OUT(arg, dmasound.soft.speed); case SNDCTL_DSP_SPEED: /* changing this on the fly will have weird effects on the sound. Where there are rate conversions implemented in soft form - it will cause the _ctx_xxx() functions to be substituted. However, there doesn't appear to be any reason to dis-allow it from a driver pov. */ if (shared_resources_are_mine(file->f_mode)) { IOCTL_IN(arg, data); data = sound_set_speed(data) ; shared_resources_initialised = 0 ; return IOCTL_OUT(arg, data); } else return -EINVAL ; break ; /* OSS says these next 4 actions are undefined when the device is busy/active - we will just return -EINVAL. To be allowed to change one - (a) you have to own the right (b) the queue(s) must be quiescent */ case SNDCTL_DSP_STEREO: if (shared_resources_are_mine(file->f_mode) && queues_are_quiescent()) { IOCTL_IN(arg, data); shared_resources_initialised = 0 ; return IOCTL_OUT(arg, sound_set_stereo(data)); } else return -EINVAL ; break ; case SOUND_PCM_WRITE_CHANNELS: if (shared_resources_are_mine(file->f_mode) && queues_are_quiescent()) { IOCTL_IN(arg, data); /* the user might ask for 20 channels, we will return 1 or 2 */ shared_resources_initialised = 0 ; return IOCTL_OUT(arg, sound_set_stereo(data-1)+1); } else return -EINVAL ; break ; case SNDCTL_DSP_SETFMT: if (shared_resources_are_mine(file->f_mode) && queues_are_quiescent()) { int format; IOCTL_IN(arg, data); shared_resources_initialised = 0 ; format = sound_set_format(data); result = IOCTL_OUT(arg, format); if (result < 0) return result; if (format != data && data != AFMT_QUERY) return -EINVAL; return 0; } else return -EINVAL ; case SNDCTL_DSP_SUBDIVIDE: return -EINVAL ; case SNDCTL_DSP_SETFRAGMENT: /* we can do this independently for the two queues - with the proviso that for fds opened O_RDWR we cannot separate the actions and both queues will be set per the last call. NOTE: this does *NOT* actually set the queue up - merely registers our intentions. */ IOCTL_IN(arg, data); result = 0 ; nbufs = (data >> 16) & 0x7fff ; /* 0x7fff is 'use maximum' */ size = data & 0xffff; if (file->f_mode & FMODE_WRITE) { result = set_queue_frags(&write_sq, nbufs, size) ; if (result) return result ; } /* NOTE: this return value is irrelevant - OSS specifically says that the value is 'random' and that the user _must_ check the actual frags values using SNDCTL_DSP_GETBLKSIZE or similar */ return IOCTL_OUT(arg, data); break ; case SNDCTL_DSP_GETOSPACE: /* */ if (file->f_mode & FMODE_WRITE) { if ( !write_sq.locked ) sq_setup(&write_sq) ; info.fragments = write_sq.max_active - write_sq.count; info.fragstotal = write_sq.max_active; info.fragsize = write_sq.user_frag_size; info.bytes = info.fragments * info.fragsize; if (copy_to_user((void __user *)arg, &info, sizeof(info))) return -EFAULT; return 0; } else return -EINVAL ; break ; case SNDCTL_DSP_GETCAPS: val = dmasound.mach.capabilities & 0xffffff00; return IOCTL_OUT(arg,val); default: return mixer_ioctl(file, cmd, arg); } return -EINVAL; } static long sq_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) { int ret; mutex_lock(&dmasound_core_mutex); ret = sq_ioctl(file, cmd, arg); mutex_unlock(&dmasound_core_mutex); return ret; } static const struct file_operations sq_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .write = sq_write, .poll = sq_poll, .unlocked_ioctl = sq_unlocked_ioctl, .open = sq_open, .release = sq_release, }; static int sq_init(void) { const struct file_operations *fops = &sq_fops; #ifndef MODULE int sq_unit; #endif sq_unit = register_sound_dsp(fops, -1); if (sq_unit < 0) { printk(KERN_ERR "dmasound_core: couldn't register fops\n") ; return sq_unit ; } write_sq_init_waitqueue(); /* These parameters will be restored for every clean open() * in the case of multiple open()s (e.g. dsp0 & dsp1) they * will be set so long as the shared resources have no owner. */ if (shared_resource_owner == 0) { dmasound.soft = dmasound.mach.default_soft ; dmasound.hard = dmasound.mach.default_hard ; dmasound.dsp = dmasound.mach.default_soft ; shared_resources_initialised = 0 ; } return 0 ; } /* * /dev/sndstat */ /* we allow more space for record-enabled because there are extra output lines. the number here must include the amount we are prepared to give to the low-level driver. */ #define STAT_BUFF_LEN 768 /* this is how much space we will allow the low-level driver to use in the stat buffer. Currently, 2 * (80 character line + <NL>). We do not police this (it is up to the ll driver to be honest). */ #define LOW_LEVEL_STAT_ALLOC 162 static struct { int busy; char buf[STAT_BUFF_LEN]; /* state.buf should not overflow! */ int len, ptr; } state; /* publish this function for use by low-level code, if required */ static char *get_afmt_string(int afmt) { switch(afmt) { case AFMT_MU_LAW: return "mu-law"; break; case AFMT_A_LAW: return "A-law"; break; case AFMT_U8: return "unsigned 8 bit"; break; case AFMT_S8: return "signed 8 bit"; break; case AFMT_S16_BE: return "signed 16 bit BE"; break; case AFMT_U16_BE: return "unsigned 16 bit BE"; break; case AFMT_S16_LE: return "signed 16 bit LE"; break; case AFMT_U16_LE: return "unsigned 16 bit LE"; break; case 0: return "format not set" ; break ; default: break ; } return "ERROR: Unsupported AFMT_XXXX code" ; } static int state_open(struct inode *inode, struct file *file) { char *buffer = state.buf; int len = 0; int ret; mutex_lock(&dmasound_core_mutex); ret = -EBUSY; if (state.busy) goto out; ret = -ENODEV; if (!try_module_get(dmasound.mach.owner)) goto out; state.ptr = 0; state.busy = 1; len += sprintf(buffer+len, "%sDMA sound driver rev %03d :\n", dmasound.mach.name, (DMASOUND_CORE_REVISION<<4) + ((dmasound.mach.version>>8) & 0x0f)); len += sprintf(buffer+len, "Core driver edition %02d.%02d : %s driver edition %02d.%02d\n", DMASOUND_CORE_REVISION, DMASOUND_CORE_EDITION, dmasound.mach.name2, (dmasound.mach.version >> 8), (dmasound.mach.version & 0xff)) ; /* call the low-level module to fill in any stat info. that it has if present. Maximum buffer usage is specified. */ if (dmasound.mach.state_info) len += dmasound.mach.state_info(buffer+len, (size_t) LOW_LEVEL_STAT_ALLOC) ; /* make usage of the state buffer as deterministic as poss. exceptional conditions could cause overrun - and this is flagged as a kernel error. */ /* formats and settings */ len += sprintf(buffer+len,"\t\t === Formats & settings ===\n") ; len += sprintf(buffer+len,"Parameter %20s%20s\n","soft","hard") ; len += sprintf(buffer+len,"Format :%20s%20s\n", get_afmt_string(dmasound.soft.format), get_afmt_string(dmasound.hard.format)); len += sprintf(buffer+len,"Samp Rate:%14d s/sec%14d s/sec\n", dmasound.soft.speed, dmasound.hard.speed); len += sprintf(buffer+len,"Channels :%20s%20s\n", dmasound.soft.stereo ? "stereo" : "mono", dmasound.hard.stereo ? "stereo" : "mono" ); /* sound queue status */ len += sprintf(buffer+len,"\t\t === Sound Queue status ===\n"); len += sprintf(buffer+len,"Allocated:%8s%6s\n","Buffers","Size") ; len += sprintf(buffer+len,"%9s:%8d%6d\n", "write", write_sq.numBufs, write_sq.bufSize) ; len += sprintf(buffer+len, "Current : MaxFrg FragSiz MaxAct Frnt Rear " "Cnt RrSize A B S L xruns\n") ; len += sprintf(buffer+len,"%9s:%7d%8d%7d%5d%5d%4d%7d%2d%2d%2d%2d%7d\n", "write", write_sq.max_count, write_sq.block_size, write_sq.max_active, write_sq.front, write_sq.rear, write_sq.count, write_sq.rear_size, write_sq.active, write_sq.busy, write_sq.syncing, write_sq.locked, write_sq.xruns) ; #ifdef DEBUG_DMASOUND printk("dmasound: stat buffer used %d bytes\n", len) ; #endif if (len >= STAT_BUFF_LEN) printk(KERN_ERR "dmasound_core: stat buffer overflowed!\n"); state.len = len; ret = 0; out: mutex_unlock(&dmasound_core_mutex); return ret; } static int state_release(struct inode *inode, struct file *file) { mutex_lock(&dmasound_core_mutex); state.busy = 0; module_put(dmasound.mach.owner); mutex_unlock(&dmasound_core_mutex); return 0; } static ssize_t state_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { int n = state.len - state.ptr; if (n > count) n = count; if (n <= 0) return 0; if (copy_to_user(buf, &state.buf[state.ptr], n)) return -EFAULT; state.ptr += n; return n; } static const struct file_operations state_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .read = state_read, .open = state_open, .release = state_release, }; static int state_init(void) { #ifndef MODULE int state_unit; #endif state_unit = register_sound_special(&state_fops, SND_DEV_STATUS); if (state_unit < 0) return state_unit ; state.busy = 0; return 0 ; } /* * Config & Setup * * This function is called by _one_ chipset-specific driver */ int dmasound_init(void) { int res ; #ifdef MODULE if (irq_installed) return -EBUSY; #endif /* Set up sound queue, /dev/audio and /dev/dsp. */ /* Set default settings. */ if ((res = sq_init()) < 0) return res ; /* Set up /dev/sndstat. */ if ((res = state_init()) < 0) return res ; /* Set up /dev/mixer. */ mixer_init(); if (!dmasound.mach.irqinit()) { printk(KERN_ERR "DMA sound driver: Interrupt initialization failed\n"); return -ENODEV; } #ifdef MODULE irq_installed = 1; #endif printk(KERN_INFO "%s DMA sound driver rev %03d installed\n", dmasound.mach.name, (DMASOUND_CORE_REVISION<<4) + ((dmasound.mach.version>>8) & 0x0f)); printk(KERN_INFO "Core driver edition %02d.%02d : %s driver edition %02d.%02d\n", DMASOUND_CORE_REVISION, DMASOUND_CORE_EDITION, dmasound.mach.name2, (dmasound.mach.version >> 8), (dmasound.mach.version & 0xff)) ; printk(KERN_INFO "Write will use %4d fragments of %7d bytes as default\n", numWriteBufs, writeBufSize) ; return 0; } #ifdef MODULE void dmasound_deinit(void) { if (irq_installed) { sound_silence(); dmasound.mach.irqcleanup(); irq_installed = 0; } write_sq_release_buffers(); if (mixer_unit >= 0) unregister_sound_mixer(mixer_unit); if (state_unit >= 0) unregister_sound_special(state_unit); if (sq_unit >= 0) unregister_sound_dsp(sq_unit); } #else /* !MODULE */ static int dmasound_setup(char *str) { int ints[6], size; str = get_options(str, ARRAY_SIZE(ints), ints); /* check the bootstrap parameter for "dmasound=" */ /* FIXME: other than in the most naive of cases there is no sense in these * buffers being other than powers of two. This is not checked yet. */ switch (ints[0]) { case 3: if ((ints[3] < 0) || (ints[3] > MAX_CATCH_RADIUS)) printk("dmasound_setup: invalid catch radius, using default = %d\n", catchRadius); else catchRadius = ints[3]; /* fall through */ case 2: if (ints[1] < MIN_BUFFERS) printk("dmasound_setup: invalid number of buffers, using default = %d\n", numWriteBufs); else numWriteBufs = ints[1]; /* fall through */ case 1: if ((size = ints[2]) < 256) /* check for small buffer specs */ size <<= 10 ; if (size < MIN_BUFSIZE || size > MAX_BUFSIZE) printk("dmasound_setup: invalid write buffer size, using default = %d\n", writeBufSize); else writeBufSize = size; case 0: break; default: printk("dmasound_setup: invalid number of arguments\n"); return 0; } return 1; } __setup("dmasound=", dmasound_setup); #endif /* !MODULE */ /* * Conversion tables */ #ifdef HAS_8BIT_TABLES /* 8 bit mu-law */ char dmasound_ulaw2dma8[] = { -126, -122, -118, -114, -110, -106, -102, -98, -94, -90, -86, -82, -78, -74, -70, -66, -63, -61, -59, -57, -55, -53, -51, -49, -47, -45, -43, -41, -39, -37, -35, -33, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -16, -15, -15, -14, -14, -13, -13, -12, -12, -11, -11, -10, -10, -9, -9, -8, -8, -8, -7, -7, -7, -7, -6, -6, -6, -6, -5, -5, -5, -5, -4, -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 125, 121, 117, 113, 109, 105, 101, 97, 93, 89, 85, 81, 77, 73, 69, 65, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* 8 bit A-law */ char dmasound_alaw2dma8[] = { -22, -21, -24, -23, -18, -17, -20, -19, -30, -29, -32, -31, -26, -25, -28, -27, -11, -11, -12, -12, -9, -9, -10, -10, -15, -15, -16, -16, -13, -13, -14, -14, -86, -82, -94, -90, -70, -66, -78, -74, -118, -114, -126, -122, -102, -98, -110, -106, -43, -41, -47, -45, -35, -33, -39, -37, -59, -57, -63, -61, -51, -49, -55, -53, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -6, -6, -6, -6, -5, -5, -5, -5, -8, -8, -8, -8, -7, -7, -7, -7, -3, -3, -3, -3, -3, -3, -3, -3, -4, -4, -4, -4, -4, -4, -4, -4, 21, 20, 23, 22, 17, 16, 19, 18, 29, 28, 31, 30, 25, 24, 27, 26, 10, 10, 11, 11, 8, 8, 9, 9, 14, 14, 15, 15, 12, 12, 13, 13, 86, 82, 94, 90, 70, 66, 78, 74, 118, 114, 126, 122, 102, 98, 110, 106, 43, 41, 47, 45, 35, 33, 39, 37, 59, 57, 63, 61, 51, 49, 55, 53, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 4, 4, 4, 4, 7, 7, 7, 7, 6, 6, 6, 6, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 }; #endif /* HAS_8BIT_TABLES */ /* * Visible symbols for modules */ EXPORT_SYMBOL(dmasound); EXPORT_SYMBOL(dmasound_init); #ifdef MODULE EXPORT_SYMBOL(dmasound_deinit); #endif EXPORT_SYMBOL(dmasound_write_sq); EXPORT_SYMBOL(dmasound_catchRadius); #ifdef HAS_8BIT_TABLES EXPORT_SYMBOL(dmasound_ulaw2dma8); EXPORT_SYMBOL(dmasound_alaw2dma8); #endif
chinghanyu/Cognet-RPi-linux
sound/oss/dmasound/dmasound_core.c
C
gpl-2.0
45,319
/* * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * Communication to userspace based on kernel/printk.c */ #include <linux/types.h> #include <linux/errno.h> #include <linux/sched.h> #include <linux/kernel.h> #include <linux/poll.h> #include <linux/proc_fs.h> #include <linux/init.h> #include <linux/vmalloc.h> #include <linux/spinlock.h> #include <linux/cpu.h> #include <linux/workqueue.h> #include <linux/slab.h> #include <asm/uaccess.h> #include <asm/io.h> #include <asm/rtas.h> #include <asm/prom.h> #include <asm/nvram.h> #include <asm/atomic.h> #include <asm/machdep.h> static DEFINE_SPINLOCK(rtasd_log_lock); static DECLARE_WAIT_QUEUE_HEAD(rtas_log_wait); static char *rtas_log_buf; static unsigned long rtas_log_start; static unsigned long rtas_log_size; static int surveillance_timeout = -1; static unsigned int rtas_error_log_max; static unsigned int rtas_error_log_buffer_max; /* RTAS service tokens */ static unsigned int event_scan; static unsigned int rtas_event_scan_rate; static int full_rtas_msgs = 0; /* Stop logging to nvram after first fatal error */ static int logging_enabled; /* Until we initialize everything, * make sure we don't try logging * anything */ static int error_log_cnt; /* * Since we use 32 bit RTAS, the physical address of this must be below * 4G or else bad things happen. Allocate this in the kernel data and * make it big enough. */ static unsigned char logdata[RTAS_ERROR_LOG_MAX]; static char *rtas_type[] = { "Unknown", "Retry", "TCE Error", "Internal Device Failure", "Timeout", "Data Parity", "Address Parity", "Cache Parity", "Address Invalid", "ECC Uncorrected", "ECC Corrupted", }; static char *rtas_event_type(int type) { if ((type > 0) && (type < 11)) return rtas_type[type]; switch (type) { case RTAS_TYPE_EPOW: return "EPOW"; case RTAS_TYPE_PLATFORM: return "Platform Error"; case RTAS_TYPE_IO: return "I/O Event"; case RTAS_TYPE_INFO: return "Platform Information Event"; case RTAS_TYPE_DEALLOC: return "Resource Deallocation Event"; case RTAS_TYPE_DUMP: return "Dump Notification Event"; } return rtas_type[0]; } /* To see this info, grep RTAS /var/log/messages and each entry * will be collected together with obvious begin/end. * There will be a unique identifier on the begin and end lines. * This will persist across reboots. * * format of error logs returned from RTAS: * bytes (size) : contents * -------------------------------------------------------- * 0-7 (8) : rtas_error_log * 8-47 (40) : extended info * 48-51 (4) : vendor id * 52-1023 (vendor specific) : location code and debug data */ static void printk_log_rtas(char *buf, int len) { int i,j,n = 0; int perline = 16; char buffer[64]; char * str = "RTAS event"; if (full_rtas_msgs) { printk(RTAS_DEBUG "%d -------- %s begin --------\n", error_log_cnt, str); /* * Print perline bytes on each line, each line will start * with RTAS and a changing number, so syslogd will * print lines that are otherwise the same. Separate every * 4 bytes with a space. */ for (i = 0; i < len; i++) { j = i % perline; if (j == 0) { memset(buffer, 0, sizeof(buffer)); n = sprintf(buffer, "RTAS %d:", i/perline); } if ((i % 4) == 0) n += sprintf(buffer+n, " "); n += sprintf(buffer+n, "%02x", (unsigned char)buf[i]); if (j == (perline-1)) printk(KERN_DEBUG "%s\n", buffer); } if ((i % perline) != 0) printk(KERN_DEBUG "%s\n", buffer); printk(RTAS_DEBUG "%d -------- %s end ----------\n", error_log_cnt, str); } else { struct rtas_error_log *errlog = (struct rtas_error_log *)buf; printk(RTAS_DEBUG "event: %d, Type: %s, Severity: %d\n", error_log_cnt, rtas_event_type(errlog->type), errlog->severity); } } static int log_rtas_len(char * buf) { int len; struct rtas_error_log *err; /* rtas fixed header */ len = 8; err = (struct rtas_error_log *)buf; if (err->extended && err->extended_log_length) { /* extended header */ len += err->extended_log_length; } if (rtas_error_log_max == 0) rtas_error_log_max = rtas_get_error_log_max(); if (len > rtas_error_log_max) len = rtas_error_log_max; return len; } /* * First write to nvram, if fatal error, that is the only * place we log the info. The error will be picked up * on the next reboot by rtasd. If not fatal, run the * method for the type of error. Currently, only RTAS * errors have methods implemented, but in the future * there might be a need to store data in nvram before a * call to panic(). * * XXX We write to nvram periodically, to indicate error has * been written and sync'd, but there is a possibility * that if we don't shutdown correctly, a duplicate error * record will be created on next reboot. */ void pSeries_log_error(char *buf, unsigned int err_type, int fatal) { unsigned long offset; unsigned long s; int len = 0; pr_debug("rtasd: logging event\n"); if (buf == NULL) return; spin_lock_irqsave(&rtasd_log_lock, s); /* get length and increase count */ switch (err_type & ERR_TYPE_MASK) { case ERR_TYPE_RTAS_LOG: len = log_rtas_len(buf); if (!(err_type & ERR_FLAG_BOOT)) error_log_cnt++; break; case ERR_TYPE_KERNEL_PANIC: default: WARN_ON_ONCE(!irqs_disabled()); /* @@@ DEBUG @@@ */ spin_unlock_irqrestore(&rtasd_log_lock, s); return; } #ifdef CONFIG_PPC64 /* Write error to NVRAM */ if (logging_enabled && !(err_type & ERR_FLAG_BOOT)) nvram_write_error_log(buf, len, err_type, error_log_cnt); #endif /* CONFIG_PPC64 */ /* * rtas errors can occur during boot, and we do want to capture * those somewhere, even if nvram isn't ready (why not?), and even * if rtasd isn't ready. Put them into the boot log, at least. */ if ((err_type & ERR_TYPE_MASK) == ERR_TYPE_RTAS_LOG) printk_log_rtas(buf, len); /* Check to see if we need to or have stopped logging */ if (fatal || !logging_enabled) { logging_enabled = 0; WARN_ON_ONCE(!irqs_disabled()); /* @@@ DEBUG @@@ */ spin_unlock_irqrestore(&rtasd_log_lock, s); return; } /* call type specific method for error */ switch (err_type & ERR_TYPE_MASK) { case ERR_TYPE_RTAS_LOG: offset = rtas_error_log_buffer_max * ((rtas_log_start+rtas_log_size) & LOG_NUMBER_MASK); /* First copy over sequence number */ memcpy(&rtas_log_buf[offset], (void *) &error_log_cnt, sizeof(int)); /* Second copy over error log data */ offset += sizeof(int); memcpy(&rtas_log_buf[offset], buf, len); if (rtas_log_size < LOG_NUMBER) rtas_log_size += 1; else rtas_log_start += 1; WARN_ON_ONCE(!irqs_disabled()); /* @@@ DEBUG @@@ */ spin_unlock_irqrestore(&rtasd_log_lock, s); wake_up_interruptible(&rtas_log_wait); break; case ERR_TYPE_KERNEL_PANIC: default: WARN_ON_ONCE(!irqs_disabled()); /* @@@ DEBUG @@@ */ spin_unlock_irqrestore(&rtasd_log_lock, s); return; } } static int rtas_log_open(struct inode * inode, struct file * file) { return 0; } static int rtas_log_release(struct inode * inode, struct file * file) { return 0; } /* This will check if all events are logged, if they are then, we * know that we can safely clear the events in NVRAM. * Next we'll sit and wait for something else to log. */ static ssize_t rtas_log_read(struct file * file, char __user * buf, size_t count, loff_t *ppos) { int error; char *tmp; unsigned long s; unsigned long offset; if (!buf || count < rtas_error_log_buffer_max) return -EINVAL; count = rtas_error_log_buffer_max; if (!access_ok(VERIFY_WRITE, buf, count)) return -EFAULT; tmp = kmalloc(count, GFP_KERNEL); if (!tmp) return -ENOMEM; spin_lock_irqsave(&rtasd_log_lock, s); /* if it's 0, then we know we got the last one (the one in NVRAM) */ while (rtas_log_size == 0) { if (file->f_flags & O_NONBLOCK) { spin_unlock_irqrestore(&rtasd_log_lock, s); error = -EAGAIN; goto out; } if (!logging_enabled) { spin_unlock_irqrestore(&rtasd_log_lock, s); error = -ENODATA; goto out; } #ifdef CONFIG_PPC64 nvram_clear_error_log(); #endif /* CONFIG_PPC64 */ spin_unlock_irqrestore(&rtasd_log_lock, s); error = wait_event_interruptible(rtas_log_wait, rtas_log_size); if (error) goto out; spin_lock_irqsave(&rtasd_log_lock, s); } offset = rtas_error_log_buffer_max * (rtas_log_start & LOG_NUMBER_MASK); memcpy(tmp, &rtas_log_buf[offset], count); rtas_log_start += 1; rtas_log_size -= 1; spin_unlock_irqrestore(&rtasd_log_lock, s); error = copy_to_user(buf, tmp, count) ? -EFAULT : count; out: kfree(tmp); return error; } static unsigned int rtas_log_poll(struct file *file, poll_table * wait) { poll_wait(file, &rtas_log_wait, wait); if (rtas_log_size) return POLLIN | POLLRDNORM; return 0; } static const struct file_operations proc_rtas_log_operations = { .read = rtas_log_read, .poll = rtas_log_poll, .open = rtas_log_open, .release = rtas_log_release, .llseek = noop_llseek, }; static int enable_surveillance(int timeout) { int error; error = rtas_set_indicator(SURVEILLANCE_TOKEN, 0, timeout); if (error == 0) return 0; if (error == -EINVAL) { printk(KERN_DEBUG "rtasd: surveillance not supported\n"); return 0; } printk(KERN_ERR "rtasd: could not update surveillance\n"); return -1; } static void do_event_scan(void) { int error; do { memset(logdata, 0, rtas_error_log_max); error = rtas_call(event_scan, 4, 1, NULL, RTAS_EVENT_SCAN_ALL_EVENTS, 0, __pa(logdata), rtas_error_log_max); if (error == -1) { printk(KERN_ERR "event-scan failed\n"); break; } if (error == 0) pSeries_log_error(logdata, ERR_TYPE_RTAS_LOG, 0); } while(error == 0); } static void rtas_event_scan(struct work_struct *w); DECLARE_DELAYED_WORK(event_scan_work, rtas_event_scan); /* * Delay should be at least one second since some machines have problems if * we call event-scan too quickly. */ static unsigned long event_scan_delay = 1*HZ; static int first_pass = 1; static void rtas_event_scan(struct work_struct *w) { unsigned int cpu; do_event_scan(); get_online_cpus(); /* raw_ OK because just using CPU as starting point. */ cpu = cpumask_next(raw_smp_processor_id(), cpu_online_mask); if (cpu >= nr_cpu_ids) { cpu = cpumask_first(cpu_online_mask); if (first_pass) { first_pass = 0; event_scan_delay = 30*HZ/rtas_event_scan_rate; if (surveillance_timeout != -1) { pr_debug("rtasd: enabling surveillance\n"); enable_surveillance(surveillance_timeout); pr_debug("rtasd: surveillance enabled\n"); } } } schedule_delayed_work_on(cpu, &event_scan_work, __round_jiffies_relative(event_scan_delay, cpu)); put_online_cpus(); } #ifdef CONFIG_PPC64 static void retreive_nvram_error_log(void) { unsigned int err_type ; int rc ; /* See if we have any error stored in NVRAM */ memset(logdata, 0, rtas_error_log_max); rc = nvram_read_error_log(logdata, rtas_error_log_max, &err_type, &error_log_cnt); /* We can use rtas_log_buf now */ logging_enabled = 1; if (!rc) { if (err_type != ERR_FLAG_ALREADY_LOGGED) { pSeries_log_error(logdata, err_type | ERR_FLAG_BOOT, 0); } } } #else /* CONFIG_PPC64 */ static void retreive_nvram_error_log(void) { } #endif /* CONFIG_PPC64 */ static void start_event_scan(void) { printk(KERN_DEBUG "RTAS daemon started\n"); pr_debug("rtasd: will sleep for %d milliseconds\n", (30000 / rtas_event_scan_rate)); /* Retrieve errors from nvram if any */ retreive_nvram_error_log(); schedule_delayed_work_on(cpumask_first(cpu_online_mask), &event_scan_work, event_scan_delay); } static int __init rtas_init(void) { struct proc_dir_entry *entry; if (!machine_is(pseries) && !machine_is(chrp)) return 0; /* No RTAS */ event_scan = rtas_token("event-scan"); if (event_scan == RTAS_UNKNOWN_SERVICE) { printk(KERN_INFO "rtasd: No event-scan on system\n"); return -ENODEV; } rtas_event_scan_rate = rtas_token("rtas-event-scan-rate"); if (rtas_event_scan_rate == RTAS_UNKNOWN_SERVICE) { printk(KERN_ERR "rtasd: no rtas-event-scan-rate on system\n"); return -ENODEV; } if (!rtas_event_scan_rate) { /* Broken firmware: take a rate of zero to mean don't scan */ printk(KERN_DEBUG "rtasd: scan rate is 0, not scanning\n"); return 0; } /* Make room for the sequence number */ rtas_error_log_max = rtas_get_error_log_max(); rtas_error_log_buffer_max = rtas_error_log_max + sizeof(int); rtas_log_buf = vmalloc(rtas_error_log_buffer_max*LOG_NUMBER); if (!rtas_log_buf) { printk(KERN_ERR "rtasd: no memory\n"); return -ENOMEM; } entry = proc_create("powerpc/rtas/error_log", S_IRUSR, NULL, &proc_rtas_log_operations); if (!entry) printk(KERN_ERR "Failed to create error_log proc entry\n"); start_event_scan(); return 0; } __initcall(rtas_init); static int __init surveillance_setup(char *str) { int i; /* We only do surveillance on pseries */ if (!machine_is(pseries)) return 0; if (get_option(&str,&i)) { if (i >= 0 && i <= 255) surveillance_timeout = i; } return 1; } __setup("surveillance=", surveillance_setup); static int __init rtasmsgs_setup(char *str) { if (strcmp(str, "on") == 0) full_rtas_msgs = 1; else if (strcmp(str, "off") == 0) full_rtas_msgs = 0; return 1; } __setup("rtasmsgs=", rtasmsgs_setup);
173210/linux
arch/powerpc/kernel/rtasd.c
C
gpl-2.0
13,654
/* * HD audio interface patch for Conexant HDA audio codec * * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> * Takashi Iwai <tiwai@suse.de> * Tobin Davis <tdavis@dsl-only.net> * * This driver is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This driver is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/init.h> #include <linux/delay.h> #include <linux/slab.h> #include <linux/pci.h> #include <linux/module.h> #include <sound/core.h> #include <sound/jack.h> #include "hda_codec.h" #include "hda_local.h" #include "hda_beep.h" #include "hda_jack.h" #define CXT_PIN_DIR_IN 0x00 #define CXT_PIN_DIR_OUT 0x01 #define CXT_PIN_DIR_INOUT 0x02 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 #define CONEXANT_HP_EVENT 0x37 #define CONEXANT_MIC_EVENT 0x38 #define CONEXANT_LINE_EVENT 0x39 /* Conexant 5051 specific */ #define CXT5051_SPDIF_OUT 0x12 #define CXT5051_PORTB_EVENT 0x38 #define CXT5051_PORTC_EVENT 0x39 #define AUTO_MIC_PORTB (1 << 1) #define AUTO_MIC_PORTC (1 << 2) struct pin_dac_pair { hda_nid_t pin; hda_nid_t dac; int type; }; struct imux_info { hda_nid_t pin; /* input pin NID */ hda_nid_t adc; /* connected ADC NID */ hda_nid_t boost; /* optional boost volume NID */ int index; /* corresponding to autocfg.input */ }; struct conexant_spec { const struct snd_kcontrol_new *mixers[5]; int num_mixers; hda_nid_t vmaster_nid; struct hda_vmaster_mute_hook vmaster_mute; bool vmaster_mute_led; const struct hda_verb *init_verbs[5]; /* initialization verbs * don't forget NULL * termination! */ unsigned int num_init_verbs; /* playback */ struct hda_multi_out multiout; /* playback set-up * max_channels, dacs must be set * dig_out_nid and hp_nid are optional */ unsigned int cur_eapd; unsigned int hp_present; unsigned int line_present; unsigned int auto_mic; int auto_mic_ext; /* imux_pins[] index for ext mic */ int auto_mic_dock; /* imux_pins[] index for dock mic */ int auto_mic_int; /* imux_pins[] index for int mic */ unsigned int need_dac_fix; hda_nid_t slave_dig_outs[2]; /* capture */ unsigned int num_adc_nids; const hda_nid_t *adc_nids; hda_nid_t dig_in_nid; /* digital-in NID; optional */ unsigned int cur_adc_idx; hda_nid_t cur_adc; unsigned int cur_adc_stream_tag; unsigned int cur_adc_format; const struct hda_pcm_stream *capture_stream; /* capture source */ const struct hda_input_mux *input_mux; const hda_nid_t *capsrc_nids; unsigned int cur_mux[3]; /* channel model */ const struct hda_channel_mode *channel_mode; int num_channel_mode; /* PCM information */ struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ unsigned int spdif_route; /* dynamic controls, init_verbs and input_mux */ struct auto_pin_cfg autocfg; struct hda_input_mux private_imux; struct imux_info imux_info[HDA_MAX_NUM_INPUTS]; hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS]; hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; struct pin_dac_pair dac_info[8]; int dac_info_filled; unsigned int port_d_mode; unsigned int auto_mute:1; /* used in auto-parser */ unsigned int detect_line:1; /* Line-out detection enabled */ unsigned int automute_lines:1; /* automute line-out as well */ unsigned int automute_hp_lo:1; /* both HP and LO available */ unsigned int dell_automute:1; unsigned int dell_vostro:1; unsigned int ideapad:1; unsigned int thinkpad:1; unsigned int hp_laptop:1; unsigned int asus:1; unsigned int pin_eapd_ctrls:1; unsigned int adc_switching:1; unsigned int ext_mic_present; unsigned int recording; void (*capture_prepare)(struct hda_codec *codec); void (*capture_cleanup)(struct hda_codec *codec); /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) * through the microphone jack. * When the user enables this through a mixer switch, both internal and * external microphones are disabled. Gain is fixed at 0dB. In this mode, * we also allow the bias to be configured through a separate mixer * control. */ unsigned int dc_enable; unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ unsigned int beep_amp; /* extra EAPD pins */ unsigned int num_eapds; hda_nid_t eapds[4]; }; static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, hinfo); } static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream); } static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); } /* * Digital out */ static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_dig_open(codec, &spec->multiout); } static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_dig_close(codec, &spec->multiout); } static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, format, substream); } /* * Analog capture */ static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; if (spec->capture_prepare) spec->capture_prepare(codec); snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], stream_tag, 0, format); return 0; } static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); if (spec->capture_cleanup) spec->capture_cleanup(codec); return 0; } static const struct hda_pcm_stream conexant_pcm_analog_playback = { .substreams = 1, .channels_min = 2, .channels_max = 2, .nid = 0, /* fill later */ .ops = { .open = conexant_playback_pcm_open, .prepare = conexant_playback_pcm_prepare, .cleanup = conexant_playback_pcm_cleanup }, }; static const struct hda_pcm_stream conexant_pcm_analog_capture = { .substreams = 1, .channels_min = 2, .channels_max = 2, .nid = 0, /* fill later */ .ops = { .prepare = conexant_capture_pcm_prepare, .cleanup = conexant_capture_pcm_cleanup }, }; static const struct hda_pcm_stream conexant_pcm_digital_playback = { .substreams = 1, .channels_min = 2, .channels_max = 2, .nid = 0, /* fill later */ .ops = { .open = conexant_dig_playback_pcm_open, .close = conexant_dig_playback_pcm_close, .prepare = conexant_dig_playback_pcm_prepare }, }; static const struct hda_pcm_stream conexant_pcm_digital_capture = { .substreams = 1, .channels_min = 2, .channels_max = 2, /* NID is set in alc_build_pcms */ }; static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; spec->cur_adc_stream_tag = stream_tag; spec->cur_adc_format = format; snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); return 0; } static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; snd_hda_codec_cleanup_stream(codec, spec->cur_adc); spec->cur_adc = 0; return 0; } static const struct hda_pcm_stream cx5051_pcm_analog_capture = { .substreams = 1, .channels_min = 2, .channels_max = 2, .nid = 0, /* fill later */ .ops = { .prepare = cx5051_capture_pcm_prepare, .cleanup = cx5051_capture_pcm_cleanup }, }; static int conexant_build_pcms(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct hda_pcm *info = spec->pcm_rec; codec->num_pcms = 1; codec->pcm_info = info; info->name = "CONEXANT Analog"; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; if (spec->capture_stream) info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; else { if (codec->vendor_id == 0x14f15051) info->stream[SNDRV_PCM_STREAM_CAPTURE] = cx5051_pcm_analog_capture; else { info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; } } info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; if (spec->multiout.dig_out_nid) { info++; codec->num_pcms++; info->name = "Conexant Digital"; info->pcm_type = HDA_PCM_TYPE_SPDIF; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_digital_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; if (spec->dig_in_nid) { info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_digital_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; } if (spec->slave_dig_outs[0]) codec->slave_dig_outs = spec->slave_dig_outs; } return 0; } static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; return snd_hda_input_mux_info(spec->input_mux, uinfo); } static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; return 0; } static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, spec->capsrc_nids[adc_idx], &spec->cur_mux[adc_idx]); } static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, unsigned int power_state) { if (power_state == AC_PWRST_D3) msleep(100); snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state); /* partial workaround for "azx_get_response timeout" */ if (power_state == AC_PWRST_D0) msleep(10); snd_hda_codec_set_power_to_all(codec, fg, power_state, true); } static int conexant_init(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; int i; for (i = 0; i < spec->num_init_verbs; i++) snd_hda_sequence_write(codec, spec->init_verbs[i]); return 0; } static void conexant_free(struct hda_codec *codec) { snd_hda_detach_beep_device(codec); kfree(codec->spec); } static const struct snd_kcontrol_new cxt_capture_mixers[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Capture Source", .info = conexant_mux_enum_info, .get = conexant_mux_enum_get, .put = conexant_mux_enum_put }, {} }; #ifdef CONFIG_SND_HDA_INPUT_BEEP /* additional beep mixers; the actual parameters are overwritten at build */ static const struct snd_kcontrol_new cxt_beep_mixer[] = { HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), { } /* end */ }; #endif static const char * const slave_pfxs[] = { "Headphone", "Speaker", "Front", "Surround", "CLFE", NULL }; static int conexant_build_controls(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; unsigned int i; int err; for (i = 0; i < spec->num_mixers; i++) { err = snd_hda_add_new_ctls(codec, spec->mixers[i]); if (err < 0) return err; } if (spec->multiout.dig_out_nid) { err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid, spec->multiout.dig_out_nid); if (err < 0) return err; err = snd_hda_create_spdif_share_sw(codec, &spec->multiout); if (err < 0) return err; spec->multiout.share_spdif = 1; } if (spec->dig_in_nid) { err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); if (err < 0) return err; } /* if we have no master control, let's create it */ if (spec->vmaster_nid && !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { unsigned int vmaster_tlv[4]; snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, HDA_OUTPUT, vmaster_tlv); err = snd_hda_add_vmaster(codec, "Master Playback Volume", vmaster_tlv, slave_pfxs, "Playback Volume"); if (err < 0) return err; } if (spec->vmaster_nid && !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { err = __snd_hda_add_vmaster(codec, "Master Playback Switch", NULL, slave_pfxs, "Playback Switch", true, &spec->vmaster_mute.sw_kctl); if (err < 0) return err; } if (spec->input_mux) { err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); if (err < 0) return err; } #ifdef CONFIG_SND_HDA_INPUT_BEEP /* create beep controls if needed */ if (spec->beep_amp) { const struct snd_kcontrol_new *knew; for (knew = cxt_beep_mixer; knew->name; knew++) { struct snd_kcontrol *kctl; kctl = snd_ctl_new1(knew, codec); if (!kctl) return -ENOMEM; kctl->private_value = spec->beep_amp; err = snd_hda_ctl_add(codec, 0, kctl); if (err < 0) return err; } } #endif return 0; } #ifdef CONFIG_SND_HDA_POWER_SAVE static int conexant_suspend(struct hda_codec *codec, pm_message_t state) { snd_hda_shutup_pins(codec); return 0; } #endif static const struct hda_codec_ops conexant_patch_ops = { .build_controls = conexant_build_controls, .build_pcms = conexant_build_pcms, .init = conexant_init, .free = conexant_free, .set_power_state = conexant_set_power, #ifdef CONFIG_SND_HDA_POWER_SAVE .suspend = conexant_suspend, #endif .reboot_notify = snd_hda_shutup_pins, }; #ifdef CONFIG_SND_HDA_INPUT_BEEP #define set_beep_amp(spec, nid, idx, dir) \ ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) #else #define set_beep_amp(spec, nid, idx, dir) /* NOP */ #endif static int patch_conexant_auto(struct hda_codec *codec); /* * EAPD control * the private value = nid | (invert << 8) */ #define cxt_eapd_info snd_ctl_boolean_mono_info static int cxt_eapd_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; int invert = (kcontrol->private_value >> 8) & 1; if (invert) ucontrol->value.integer.value[0] = !spec->cur_eapd; else ucontrol->value.integer.value[0] = spec->cur_eapd; return 0; } static int cxt_eapd_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; int invert = (kcontrol->private_value >> 8) & 1; hda_nid_t nid = kcontrol->private_value & 0xff; unsigned int eapd; eapd = !!ucontrol->value.integer.value[0]; if (invert) eapd = !eapd; if (eapd == spec->cur_eapd) return 0; spec->cur_eapd = eapd; snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, eapd ? 0x02 : 0x00); return 1; } /* controls for test mode */ #ifdef CONFIG_SND_DEBUG #define CXT_EAPD_SWITCH(xname, nid, mask) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ .info = cxt_eapd_info, \ .get = cxt_eapd_get, \ .put = cxt_eapd_put, \ .private_value = nid | (mask<<16) } static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, spec->num_channel_mode); } static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, spec->num_channel_mode, spec->multiout.max_channels); } static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, spec->num_channel_mode, &spec->multiout.max_channels); if (err >= 0 && spec->need_dac_fix) spec->multiout.num_dacs = spec->multiout.max_channels / 2; return err; } #define CXT_PIN_MODE(xname, nid, dir) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ .info = conexant_ch_mode_info, \ .get = conexant_ch_mode_get, \ .put = conexant_ch_mode_put, \ .private_value = nid | (dir<<16) } #endif /* CONFIG_SND_DEBUG */ /* Conexant 5045 specific */ static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; #define CXT5045_SPDIF_OUT 0x18 static const struct hda_channel_mode cxt5045_modes[1] = { { 2, NULL }, }; static const struct hda_input_mux cxt5045_capture_source = { .num_items = 2, .items = { { "Internal Mic", 0x1 }, { "Mic", 0x2 }, } }; static const struct hda_input_mux cxt5045_capture_source_benq = { .num_items = 4, .items = { { "Internal Mic", 0x1 }, { "Mic", 0x2 }, { "Line", 0x3 }, { "Mixer", 0x0 }, } }; static const struct hda_input_mux cxt5045_capture_source_hp530 = { .num_items = 2, .items = { { "Mic", 0x1 }, { "Internal Mic", 0x2 }, } }; /* turn on/off EAPD (+ mute HP) as a master switch */ static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; unsigned int bits; if (!cxt_eapd_put(kcontrol, ucontrol)) return 0; /* toggle internal speakers mute depending of presence of * the headphone jack */ bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits); bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits); return 1; } /* bind volumes of both NID 0x10 and 0x11 */ static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { .ops = &snd_hda_bind_vol, .values = { HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 0 }, }; /* toggle input of built-in and mic jack appropriately */ static void cxt5045_hp_automic(struct hda_codec *codec) { static const struct hda_verb mic_jack_on[] = { {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, {} }; static const struct hda_verb mic_jack_off[] = { {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, {} }; unsigned int present; present = snd_hda_jack_detect(codec, 0x12); if (present) snd_hda_sequence_write(codec, mic_jack_on); else snd_hda_sequence_write(codec, mic_jack_off); } /* mute internal speaker if HP is plugged */ static void cxt5045_hp_automute(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; unsigned int bits; spec->hp_present = snd_hda_jack_detect(codec, 0x11); bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits); } /* unsolicited event for HP jack sensing */ static void cxt5045_hp_unsol_event(struct hda_codec *codec, unsigned int res) { res >>= 26; switch (res) { case CONEXANT_HP_EVENT: cxt5045_hp_automute(codec); break; case CONEXANT_MIC_EVENT: cxt5045_hp_automic(codec); break; } } static const struct snd_kcontrol_new cxt5045_mixers[] = { HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Switch", .info = cxt_eapd_info, .get = cxt_eapd_get, .put = cxt5045_hp_master_sw_put, .private_value = 0x10, }, {} }; static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT), HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT), {} }; static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Switch", .info = cxt_eapd_info, .get = cxt_eapd_get, .put = cxt5045_hp_master_sw_put, .private_value = 0x10, }, {} }; static const struct hda_verb cxt5045_init_verbs[] = { /* Line in, Mic */ {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, /* HP, Amp */ {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* Record selector: Internal mic */ {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, /* SPDIF route: PCM */ {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, /* EAPD */ {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ { } /* end */ }; static const struct hda_verb cxt5045_benq_init_verbs[] = { /* Internal Mic, Mic */ {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, /* Line In,HP, Amp */ {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* Record selector: Internal mic */ {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, /* SPDIF route: PCM */ {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* EAPD */ {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ { } /* end */ }; static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { /* pin sensing on HP jack */ {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, { } /* end */ }; static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { /* pin sensing on HP jack */ {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, { } /* end */ }; #ifdef CONFIG_SND_DEBUG /* Test configuration for debugging, modelled after the ALC260 test * configuration. */ static const struct hda_input_mux cxt5045_test_capture_source = { .num_items = 5, .items = { { "MIXER", 0x0 }, { "MIC1 pin", 0x1 }, { "LINE1 pin", 0x2 }, { "HP-OUT pin", 0x3 }, { "CD pin", 0x4 }, }, }; static const struct snd_kcontrol_new cxt5045_test_mixer[] = { /* Output controls */ HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT), HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT), /* Modes for retasking pin widgets */ CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), /* EAPD Switch Control */ CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), /* Loopback mixer controls */ HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT), HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT), HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT), HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT), HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT), HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT), HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT), HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT), HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT), HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Input Source", .info = conexant_mux_enum_info, .get = conexant_mux_enum_get, .put = conexant_mux_enum_put, }, /* Audio input controls */ HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT), HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), { } /* end */ }; static const struct hda_verb cxt5045_test_init_verbs[] = { /* Set connections */ { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, /* Enable retasking pins as output, initially without power amp */ {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Disable digital (SPDIF) pins initially, but users can enable * them via a mixer switch. In the case of SPDIF-out, this initverb * payload also sets the generation to 0, output to be in "consumer" * PCM format, copyright asserted, no pre-emphasis and no validity * control. */ {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, /* Unmute retasking pin widget output buffers since the default * state appears to be output. As the pin mode is changed by the * user the pin mode control will take care of enabling the pin's * input/output buffers as needed. */ {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mute capture amp left and right */ {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Set ADC connection select to match default mixer setting (mic1 * pin) */ {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, {0x17, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Mute all inputs to mixer widget (even unconnected ones) */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ { } }; #endif /* initialize jack-sensing, too */ static int cxt5045_init(struct hda_codec *codec) { conexant_init(codec); cxt5045_hp_automute(codec); return 0; } enum { CXT5045_LAPTOP_HPSENSE, CXT5045_LAPTOP_MICSENSE, CXT5045_LAPTOP_HPMICSENSE, CXT5045_BENQ, CXT5045_LAPTOP_HP530, #ifdef CONFIG_SND_DEBUG CXT5045_TEST, #endif CXT5045_AUTO, CXT5045_MODELS }; static const char * const cxt5045_models[CXT5045_MODELS] = { [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", [CXT5045_BENQ] = "benq", [CXT5045_LAPTOP_HP530] = "laptop-hp530", #ifdef CONFIG_SND_DEBUG [CXT5045_TEST] = "test", #endif [CXT5045_AUTO] = "auto", }; static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPMICSENSE), SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE), SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), {} }; static int patch_cxt5045(struct hda_codec *codec) { struct conexant_spec *spec; int board_config; board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, cxt5045_models, cxt5045_cfg_tbl); if (board_config < 0) board_config = CXT5045_AUTO; /* model=auto as default */ if (board_config == CXT5045_AUTO) return patch_conexant_auto(codec); spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (!spec) return -ENOMEM; codec->spec = spec; codec->single_adc_amp = 1; spec->multiout.max_channels = 2; spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); spec->multiout.dac_nids = cxt5045_dac_nids; spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; spec->num_adc_nids = 1; spec->adc_nids = cxt5045_adc_nids; spec->capsrc_nids = cxt5045_capsrc_nids; spec->input_mux = &cxt5045_capture_source; spec->num_mixers = 1; spec->mixers[0] = cxt5045_mixers; spec->num_init_verbs = 1; spec->init_verbs[0] = cxt5045_init_verbs; spec->spdif_route = 0; spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); spec->channel_mode = cxt5045_modes; set_beep_amp(spec, 0x16, 0, 1); codec->patch_ops = conexant_patch_ops; switch (board_config) { case CXT5045_LAPTOP_HPSENSE: codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; spec->input_mux = &cxt5045_capture_source; spec->num_init_verbs = 2; spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; spec->mixers[0] = cxt5045_mixers; codec->patch_ops.init = cxt5045_init; break; case CXT5045_LAPTOP_MICSENSE: codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; spec->input_mux = &cxt5045_capture_source; spec->num_init_verbs = 2; spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; spec->mixers[0] = cxt5045_mixers; codec->patch_ops.init = cxt5045_init; break; default: case CXT5045_LAPTOP_HPMICSENSE: codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; spec->input_mux = &cxt5045_capture_source; spec->num_init_verbs = 3; spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; spec->mixers[0] = cxt5045_mixers; codec->patch_ops.init = cxt5045_init; break; case CXT5045_BENQ: codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; spec->input_mux = &cxt5045_capture_source_benq; spec->num_init_verbs = 1; spec->init_verbs[0] = cxt5045_benq_init_verbs; spec->mixers[0] = cxt5045_mixers; spec->mixers[1] = cxt5045_benq_mixers; spec->num_mixers = 2; codec->patch_ops.init = cxt5045_init; break; case CXT5045_LAPTOP_HP530: codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; spec->input_mux = &cxt5045_capture_source_hp530; spec->num_init_verbs = 2; spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; spec->mixers[0] = cxt5045_mixers_hp530; codec->patch_ops.init = cxt5045_init; break; #ifdef CONFIG_SND_DEBUG case CXT5045_TEST: spec->input_mux = &cxt5045_test_capture_source; spec->mixers[0] = cxt5045_test_mixer; spec->init_verbs[0] = cxt5045_test_init_verbs; break; #endif } switch (codec->subsystem_id >> 16) { case 0x103c: case 0x1631: case 0x1734: case 0x17aa: /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have * really bad sound over 0dB on NID 0x17. Fix max PCM level to * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) */ snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, (0x14 << AC_AMPCAP_OFFSET_SHIFT) | (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | (1 << AC_AMPCAP_MUTE_SHIFT)); break; } if (spec->beep_amp) snd_hda_attach_beep_device(codec, spec->beep_amp); return 0; } /* Conexant 5047 specific */ #define CXT5047_SPDIF_OUT 0x11 static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; static const struct hda_channel_mode cxt5047_modes[1] = { { 2, NULL }, }; static const struct hda_input_mux cxt5047_toshiba_capture_source = { .num_items = 2, .items = { { "ExtMic", 0x2 }, { "Line-In", 0x1 }, } }; /* turn on/off EAPD (+ mute HP) as a master switch */ static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; unsigned int bits; if (!cxt_eapd_put(kcontrol, ucontrol)) return 0; /* toggle internal speakers mute depending of presence of * the headphone jack */ bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; /* NOTE: Conexat codec needs the index for *OUTPUT* amp of * pin widgets unlike other codecs. In this case, we need to * set index 0x01 for the volume from the mixer amp 0x19. */ snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, HDA_AMP_MUTE, bits); bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits); return 1; } /* mute internal speaker if HP is plugged */ static void cxt5047_hp_automute(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; unsigned int bits; spec->hp_present = snd_hda_jack_detect(codec, 0x13); bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; /* See the note in cxt5047_hp_master_sw_put */ snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, HDA_AMP_MUTE, bits); } /* toggle input of built-in and mic jack appropriately */ static void cxt5047_hp_automic(struct hda_codec *codec) { static const struct hda_verb mic_jack_on[] = { {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, {} }; static const struct hda_verb mic_jack_off[] = { {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, {} }; unsigned int present; present = snd_hda_jack_detect(codec, 0x15); if (present) snd_hda_sequence_write(codec, mic_jack_on); else snd_hda_sequence_write(codec, mic_jack_off); } /* unsolicited event for HP jack sensing */ static void cxt5047_hp_unsol_event(struct hda_codec *codec, unsigned int res) { switch (res >> 26) { case CONEXANT_HP_EVENT: cxt5047_hp_automute(codec); break; case CONEXANT_MIC_EVENT: cxt5047_hp_automic(codec); break; } } static const struct snd_kcontrol_new cxt5047_base_mixers[] = { HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Switch", .info = cxt_eapd_info, .get = cxt_eapd_get, .put = cxt5047_hp_master_sw_put, .private_value = 0x13, }, {} }; static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { /* See the note in cxt5047_hp_master_sw_put */ HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), {} }; static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), { } /* end */ }; static const struct hda_verb cxt5047_init_verbs[] = { /* Line in, Mic, Built-in Mic */ {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, /* HP, Speaker */ {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ /* Record selector: Mic */ {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, /* SPDIF route: PCM */ { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, /* Enable unsolicited events */ {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, { } /* end */ }; /* configuration for Toshiba Laptops */ static const struct hda_verb cxt5047_toshiba_init_verbs[] = { {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ {} }; /* Test configuration for debugging, modelled after the ALC260 test * configuration. */ #ifdef CONFIG_SND_DEBUG static const struct hda_input_mux cxt5047_test_capture_source = { .num_items = 4, .items = { { "LINE1 pin", 0x0 }, { "MIC1 pin", 0x1 }, { "MIC2 pin", 0x2 }, { "CD pin", 0x3 }, }, }; static const struct snd_kcontrol_new cxt5047_test_mixer[] = { /* Output only controls */ HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), /* Modes for retasking pin widgets */ CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), /* EAPD Switch Control */ CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), /* Loopback mixer controls */ HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Input Source", .info = conexant_mux_enum_info, .get = conexant_mux_enum_get, .put = conexant_mux_enum_put, }, HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), { } /* end */ }; static const struct hda_verb cxt5047_test_init_verbs[] = { /* Enable retasking pins as output, initially without power amp */ {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Disable digital (SPDIF) pins initially, but users can enable * them via a mixer switch. In the case of SPDIF-out, this initverb * payload also sets the generation to 0, output to be in "consumer" * PCM format, copyright asserted, no pre-emphasis and no validity * control. */ {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, /* Ensure mic1, mic2, line1 pin widgets take input from the * OUT1 sum bus when acting as an output. */ {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, /* Start with output sum widgets muted and their output gains at min */ {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Unmute retasking pin widget output buffers since the default * state appears to be output. As the pin mode is changed by the * user the pin mode control will take care of enabling the pin's * input/output buffers as needed. */ {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mute capture amp left and right */ {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Set ADC connection select to match default mixer setting (mic1 * pin) */ {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Mute all inputs to mixer widget (even unconnected ones) */ {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ { } }; #endif /* initialize jack-sensing, too */ static int cxt5047_hp_init(struct hda_codec *codec) { conexant_init(codec); cxt5047_hp_automute(codec); return 0; } enum { CXT5047_LAPTOP, /* Laptops w/o EAPD support */ CXT5047_LAPTOP_HP, /* Some HP laptops */ CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ #ifdef CONFIG_SND_DEBUG CXT5047_TEST, #endif CXT5047_AUTO, CXT5047_MODELS }; static const char * const cxt5047_models[CXT5047_MODELS] = { [CXT5047_LAPTOP] = "laptop", [CXT5047_LAPTOP_HP] = "laptop-hp", [CXT5047_LAPTOP_EAPD] = "laptop-eapd", #ifdef CONFIG_SND_DEBUG [CXT5047_TEST] = "test", #endif [CXT5047_AUTO] = "auto", }; static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", CXT5047_LAPTOP), SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), {} }; static int patch_cxt5047(struct hda_codec *codec) { struct conexant_spec *spec; int board_config; board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, cxt5047_models, cxt5047_cfg_tbl); if (board_config < 0) board_config = CXT5047_AUTO; /* model=auto as default */ if (board_config == CXT5047_AUTO) return patch_conexant_auto(codec); spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (!spec) return -ENOMEM; codec->spec = spec; codec->pin_amp_workaround = 1; spec->multiout.max_channels = 2; spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); spec->multiout.dac_nids = cxt5047_dac_nids; spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; spec->num_adc_nids = 1; spec->adc_nids = cxt5047_adc_nids; spec->capsrc_nids = cxt5047_capsrc_nids; spec->num_mixers = 1; spec->mixers[0] = cxt5047_base_mixers; spec->num_init_verbs = 1; spec->init_verbs[0] = cxt5047_init_verbs; spec->spdif_route = 0; spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), spec->channel_mode = cxt5047_modes, codec->patch_ops = conexant_patch_ops; switch (board_config) { case CXT5047_LAPTOP: spec->num_mixers = 2; spec->mixers[1] = cxt5047_hp_spk_mixers; codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; break; case CXT5047_LAPTOP_HP: spec->num_mixers = 2; spec->mixers[1] = cxt5047_hp_only_mixers; codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; codec->patch_ops.init = cxt5047_hp_init; break; case CXT5047_LAPTOP_EAPD: spec->input_mux = &cxt5047_toshiba_capture_source; spec->num_mixers = 2; spec->mixers[1] = cxt5047_hp_spk_mixers; spec->num_init_verbs = 2; spec->init_verbs[1] = cxt5047_toshiba_init_verbs; codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; break; #ifdef CONFIG_SND_DEBUG case CXT5047_TEST: spec->input_mux = &cxt5047_test_capture_source; spec->mixers[0] = cxt5047_test_mixer; spec->init_verbs[0] = cxt5047_test_init_verbs; codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; #endif } spec->vmaster_nid = 0x13; switch (codec->subsystem_id >> 16) { case 0x103c: /* HP laptops have really bad sound over 0 dB on NID 0x10. * Fix max PCM level to 0 dB (originally it has 0x1e steps * with 0 dB offset 0x17) */ snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, (0x17 << AC_AMPCAP_OFFSET_SHIFT) | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | (1 << AC_AMPCAP_MUTE_SHIFT)); break; } return 0; } /* Conexant 5051 specific */ static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; static const struct hda_channel_mode cxt5051_modes[1] = { { 2, NULL }, }; static void cxt5051_update_speaker(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; unsigned int pinctl; /* headphone pin */ pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); /* speaker pin */ pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); /* on ideapad there is an additional speaker (subwoofer) to mute */ if (spec->ideapad) snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); } /* turn on/off EAPD (+ mute HP) as a master switch */ static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); if (!cxt_eapd_put(kcontrol, ucontrol)) return 0; cxt5051_update_speaker(codec); return 1; } /* toggle input of built-in and mic jack appropriately */ static void cxt5051_portb_automic(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; unsigned int present; if (!(spec->auto_mic & AUTO_MIC_PORTB)) return; present = snd_hda_jack_detect(codec, 0x17); snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_CONNECT_SEL, present ? 0x01 : 0x00); } /* switch the current ADC according to the jack state */ static void cxt5051_portc_automic(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; unsigned int present; hda_nid_t new_adc; if (!(spec->auto_mic & AUTO_MIC_PORTC)) return; present = snd_hda_jack_detect(codec, 0x18); if (present) spec->cur_adc_idx = 1; else spec->cur_adc_idx = 0; new_adc = spec->adc_nids[spec->cur_adc_idx]; if (spec->cur_adc && spec->cur_adc != new_adc) { /* stream is running, let's swap the current ADC */ __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); spec->cur_adc = new_adc; snd_hda_codec_setup_stream(codec, new_adc, spec->cur_adc_stream_tag, 0, spec->cur_adc_format); } } /* mute internal speaker if HP is plugged */ static void cxt5051_hp_automute(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; spec->hp_present = snd_hda_jack_detect(codec, 0x16); cxt5051_update_speaker(codec); } /* unsolicited event for HP jack sensing */ static void cxt5051_hp_unsol_event(struct hda_codec *codec, unsigned int res) { switch (res >> 26) { case CONEXANT_HP_EVENT: cxt5051_hp_automute(codec); break; case CXT5051_PORTB_EVENT: cxt5051_portb_automic(codec); break; case CXT5051_PORTC_EVENT: cxt5051_portc_automic(codec); break; } } static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Switch", .info = cxt_eapd_info, .get = cxt_eapd_get, .put = cxt5051_hp_master_sw_put, .private_value = 0x1a, }, {} }; static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), {} }; static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), {} }; static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), {} }; static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), {} }; static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), {} }; static const struct hda_verb cxt5051_init_verbs[] = { /* Line in, Mic */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, /* SPK */ {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP, Amp */ {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Record selector: Internal mic */ {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, /* SPDIF route: PCM */ {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, /* EAPD */ {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, { } /* end */ }; static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { /* Line in, Mic */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, /* SPK */ {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP, Amp */ {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Record selector: Internal mic */ {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, /* SPDIF route: PCM */ {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, /* EAPD */ {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, { } /* end */ }; static const struct hda_verb cxt5051_f700_init_verbs[] = { /* Line in, Mic */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, /* SPK */ {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP, Amp */ {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Record selector: Internal mic */ {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, /* SPDIF route: PCM */ {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, /* EAPD */ {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, { } /* end */ }; static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, unsigned int event) { snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | event); } static const struct hda_verb cxt5051_ideapad_init_verbs[] = { /* Subwoofer */ {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, { } /* end */ }; /* initialize jack-sensing, too */ static int cxt5051_init(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; conexant_init(codec); if (spec->auto_mic & AUTO_MIC_PORTB) cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); if (spec->auto_mic & AUTO_MIC_PORTC) cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); if (codec->patch_ops.unsol_event) { cxt5051_hp_automute(codec); cxt5051_portb_automic(codec); cxt5051_portc_automic(codec); } return 0; } enum { CXT5051_LAPTOP, /* Laptops w/ EAPD support */ CXT5051_HP, /* no docking */ CXT5051_HP_DV6736, /* HP without mic switch */ CXT5051_F700, /* HP Compaq Presario F700 */ CXT5051_TOSHIBA, /* Toshiba M300 & co */ CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ CXT5051_AUTO, /* auto-parser */ CXT5051_MODELS }; static const char *const cxt5051_models[CXT5051_MODELS] = { [CXT5051_LAPTOP] = "laptop", [CXT5051_HP] = "hp", [CXT5051_HP_DV6736] = "hp-dv6736", [CXT5051_F700] = "hp-700", [CXT5051_TOSHIBA] = "toshiba", [CXT5051_IDEAPAD] = "ideapad", [CXT5051_AUTO] = "auto", }; static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", CXT5051_LAPTOP), SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), {} }; static int patch_cxt5051(struct hda_codec *codec) { struct conexant_spec *spec; int board_config; board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, cxt5051_models, cxt5051_cfg_tbl); if (board_config < 0) board_config = CXT5051_AUTO; /* model=auto as default */ if (board_config == CXT5051_AUTO) return patch_conexant_auto(codec); spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (!spec) return -ENOMEM; codec->spec = spec; codec->pin_amp_workaround = 1; codec->patch_ops = conexant_patch_ops; codec->patch_ops.init = cxt5051_init; spec->multiout.max_channels = 2; spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); spec->multiout.dac_nids = cxt5051_dac_nids; spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ spec->adc_nids = cxt5051_adc_nids; spec->num_mixers = 2; spec->mixers[0] = cxt5051_capture_mixers; spec->mixers[1] = cxt5051_playback_mixers; spec->num_init_verbs = 1; spec->init_verbs[0] = cxt5051_init_verbs; spec->spdif_route = 0; spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); spec->channel_mode = cxt5051_modes; spec->cur_adc = 0; spec->cur_adc_idx = 0; set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; switch (board_config) { case CXT5051_HP: spec->mixers[0] = cxt5051_hp_mixers; break; case CXT5051_HP_DV6736: spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; spec->mixers[0] = cxt5051_hp_dv6736_mixers; spec->auto_mic = 0; break; case CXT5051_F700: spec->init_verbs[0] = cxt5051_f700_init_verbs; spec->mixers[0] = cxt5051_f700_mixers; spec->auto_mic = 0; break; case CXT5051_TOSHIBA: spec->mixers[0] = cxt5051_toshiba_mixers; spec->auto_mic = AUTO_MIC_PORTB; break; case CXT5051_IDEAPAD: spec->init_verbs[spec->num_init_verbs++] = cxt5051_ideapad_init_verbs; spec->ideapad = 1; break; } if (spec->beep_amp) snd_hda_attach_beep_device(codec, spec->beep_amp); return 0; } /* Conexant 5066 specific */ static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; /* OLPC's microphone port is DC coupled for use with external sensors, * therefore we use a 50% mic bias in order to center the input signal with * the DC input range of the codec. */ #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 static const struct hda_channel_mode cxt5066_modes[1] = { { 2, NULL }, }; #define HP_PRESENT_PORT_A (1 << 0) #define HP_PRESENT_PORT_D (1 << 1) #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) static void cxt5066_update_speaker(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; unsigned int pinctl; snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", spec->hp_present, spec->cur_eapd); /* Port A (HP) */ pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); /* Port D (HP/LO) */ pinctl = spec->cur_eapd ? spec->port_d_mode : 0; if (spec->dell_automute || spec->thinkpad) { /* Mute if Port A is connected */ if (hp_port_a_present(spec)) pinctl = 0; } else { /* Thinkpad/Dell doesn't give pin-D status */ if (!hp_port_d_present(spec)) pinctl = 0; } snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); /* CLASS_D AMP */ pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); } /* turn on/off EAPD (+ mute HP) as a master switch */ static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); if (!cxt_eapd_put(kcontrol, ucontrol)) return 0; cxt5066_update_speaker(codec); return 1; } static const struct hda_input_mux cxt5066_olpc_dc_bias = { .num_items = 3, .items = { { "Off", PIN_IN }, { "50%", PIN_VREF50 }, { "80%", PIN_VREF80 }, }, }; static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; /* Even though port F is the DC input, the bias is controlled on port B. * we also leave that port as an active input (but unselected) in DC mode * just in case that is necessary to make the bias setting take effect. */ return snd_hda_codec_write_cache(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); } /* OLPC defers mic widget control until when capture is started because the * microphone LED comes on as soon as these settings are put in place. if we * did this before recording, it would give the false indication that recording * is happening when it is not. */ static void cxt5066_olpc_select_mic(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; if (!spec->recording) return; if (spec->dc_enable) { /* in DC mode we ignore presence detection and just use the jack * through our special DC port */ const struct hda_verb enable_dc_mode[] = { /* disble internal mic, port C */ {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* enable DC capture, port F */ {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, {}, }; snd_hda_sequence_write(codec, enable_dc_mode); /* port B input disabled (and bias set) through the following call */ cxt5066_set_olpc_dc_bias(codec); return; } /* disable DC (port F) */ snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); /* external mic, port B */ snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); /* internal mic, port C */ snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_present ? 0 : PIN_VREF80); } /* toggle input of built-in and mic jack appropriately */ static void cxt5066_olpc_automic(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; unsigned int present; if (spec->dc_enable) /* don't do presence detection in DC mode */ return; present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; if (present) snd_printdd("CXT5066: external microphone detected\n"); else snd_printdd("CXT5066: external microphone absent\n"); snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, present ? 0 : 1); spec->ext_mic_present = !!present; cxt5066_olpc_select_mic(codec); } /* toggle input of built-in digital mic and mic jack appropriately */ static void cxt5066_vostro_automic(struct hda_codec *codec) { unsigned int present; struct hda_verb ext_mic_present[] = { /* enable external mic, port B */ {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* switch to external mic input */ {0x17, AC_VERB_SET_CONNECT_SEL, 0}, {0x14, AC_VERB_SET_CONNECT_SEL, 0}, /* disable internal digital mic */ {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {} }; static const struct hda_verb ext_mic_absent[] = { /* enable internal mic, port C */ {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* switch to internal mic input */ {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* disable external mic, port B */ {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {} }; present = snd_hda_jack_detect(codec, 0x1a); if (present) { snd_printdd("CXT5066: external microphone detected\n"); snd_hda_sequence_write(codec, ext_mic_present); } else { snd_printdd("CXT5066: external microphone absent\n"); snd_hda_sequence_write(codec, ext_mic_absent); } } /* toggle input of built-in digital mic and mic jack appropriately */ static void cxt5066_ideapad_automic(struct hda_codec *codec) { unsigned int present; struct hda_verb ext_mic_present[] = { {0x14, AC_VERB_SET_CONNECT_SEL, 0}, {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {} }; static const struct hda_verb ext_mic_absent[] = { {0x14, AC_VERB_SET_CONNECT_SEL, 2}, {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {} }; present = snd_hda_jack_detect(codec, 0x1b); if (present) { snd_printdd("CXT5066: external microphone detected\n"); snd_hda_sequence_write(codec, ext_mic_present); } else { snd_printdd("CXT5066: external microphone absent\n"); snd_hda_sequence_write(codec, ext_mic_absent); } } /* toggle input of built-in digital mic and mic jack appropriately */ static void cxt5066_asus_automic(struct hda_codec *codec) { unsigned int present; present = snd_hda_jack_detect(codec, 0x1b); snd_printdd("CXT5066: external microphone present=%d\n", present); snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, present ? 1 : 0); } /* toggle input of built-in digital mic and mic jack appropriately */ static void cxt5066_hp_laptop_automic(struct hda_codec *codec) { unsigned int present; present = snd_hda_jack_detect(codec, 0x1b); snd_printdd("CXT5066: external microphone present=%d\n", present); snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, present ? 1 : 3); } /* toggle input of built-in digital mic and mic jack appropriately order is: external mic -> dock mic -> interal mic */ static void cxt5066_thinkpad_automic(struct hda_codec *codec) { unsigned int ext_present, dock_present; static const struct hda_verb ext_mic_present[] = { {0x14, AC_VERB_SET_CONNECT_SEL, 0}, {0x17, AC_VERB_SET_CONNECT_SEL, 1}, {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {} }; static const struct hda_verb dock_mic_present[] = { {0x14, AC_VERB_SET_CONNECT_SEL, 0}, {0x17, AC_VERB_SET_CONNECT_SEL, 0}, {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {} }; static const struct hda_verb ext_mic_absent[] = { {0x14, AC_VERB_SET_CONNECT_SEL, 2}, {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {} }; ext_present = snd_hda_jack_detect(codec, 0x1b); dock_present = snd_hda_jack_detect(codec, 0x1a); if (ext_present) { snd_printdd("CXT5066: external microphone detected\n"); snd_hda_sequence_write(codec, ext_mic_present); } else if (dock_present) { snd_printdd("CXT5066: dock microphone detected\n"); snd_hda_sequence_write(codec, dock_mic_present); } else { snd_printdd("CXT5066: external microphone absent\n"); snd_hda_sequence_write(codec, ext_mic_absent); } } /* mute internal speaker if HP is plugged */ static void cxt5066_hp_automute(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; unsigned int portA, portD; /* Port A */ portA = snd_hda_jack_detect(codec, 0x19); /* Port D */ portD = snd_hda_jack_detect(codec, 0x1c); spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", portA, portD, spec->hp_present); cxt5066_update_speaker(codec); } /* Dispatch the right mic autoswitch function */ static void cxt5066_automic(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; if (spec->dell_vostro) cxt5066_vostro_automic(codec); else if (spec->ideapad) cxt5066_ideapad_automic(codec); else if (spec->thinkpad) cxt5066_thinkpad_automic(codec); else if (spec->hp_laptop) cxt5066_hp_laptop_automic(codec); else if (spec->asus) cxt5066_asus_automic(codec); } /* unsolicited event for jack sensing */ static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) { struct conexant_spec *spec = codec->spec; snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); switch (res >> 26) { case CONEXANT_HP_EVENT: cxt5066_hp_automute(codec); break; case CONEXANT_MIC_EVENT: /* ignore mic events in DC mode; we're always using the jack */ if (!spec->dc_enable) cxt5066_olpc_automic(codec); break; } } /* unsolicited event for jack sensing */ static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) { snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); switch (res >> 26) { case CONEXANT_HP_EVENT: cxt5066_hp_automute(codec); break; case CONEXANT_MIC_EVENT: cxt5066_automic(codec); break; } } static const struct hda_input_mux cxt5066_analog_mic_boost = { .num_items = 5, .items = { { "0dB", 0 }, { "10dB", 1 }, { "20dB", 2 }, { "30dB", 3 }, { "40dB", 4 }, }, }; static void cxt5066_set_mic_boost(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; snd_hda_codec_write_cache(codec, 0x17, 0, AC_VERB_SET_AMP_GAIN_MUTE, AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | cxt5066_analog_mic_boost.items[spec->mic_boost].index); if (spec->ideapad || spec->thinkpad) { /* adjust the internal mic as well...it is not through 0x17 */ snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE, AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | cxt5066_analog_mic_boost. items[spec->mic_boost].index); } } static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); } static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; ucontrol->value.enumerated.item[0] = spec->mic_boost; return 0; } static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; unsigned int idx; idx = ucontrol->value.enumerated.item[0]; if (idx >= imux->num_items) idx = imux->num_items - 1; spec->mic_boost = idx; if (!spec->dc_enable) cxt5066_set_mic_boost(codec); return 1; } static void cxt5066_enable_dc(struct hda_codec *codec) { const struct hda_verb enable_dc_mode[] = { /* disable gain */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* switch to DC input */ {0x17, AC_VERB_SET_CONNECT_SEL, 3}, {} }; /* configure as input source */ snd_hda_sequence_write(codec, enable_dc_mode); cxt5066_olpc_select_mic(codec); /* also sets configured bias */ } static void cxt5066_disable_dc(struct hda_codec *codec) { /* reconfigure input source */ cxt5066_set_mic_boost(codec); /* automic also selects the right mic if we're recording */ cxt5066_olpc_automic(codec); } static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; ucontrol->value.integer.value[0] = spec->dc_enable; return 0; } static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; int dc_enable = !!ucontrol->value.integer.value[0]; if (dc_enable == spec->dc_enable) return 0; spec->dc_enable = dc_enable; if (dc_enable) cxt5066_enable_dc(codec); else cxt5066_disable_dc(codec); return 1; } static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); } static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; ucontrol->value.enumerated.item[0] = spec->dc_input_bias; return 0; } static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; unsigned int idx; idx = ucontrol->value.enumerated.item[0]; if (idx >= imux->num_items) idx = imux->num_items - 1; spec->dc_input_bias = idx; if (spec->dc_enable) cxt5066_set_olpc_dc_bias(codec); return 1; } static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; /* mark as recording and configure the microphone widget so that the * recording LED comes on. */ spec->recording = 1; cxt5066_olpc_select_mic(codec); } static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; const struct hda_verb disable_mics[] = { /* disable external mic, port B */ {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* disble internal mic, port C */ {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* disable DC capture, port F */ {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {}, }; snd_hda_sequence_write(codec, disable_mics); spec->recording = 0; } static void conexant_check_dig_outs(struct hda_codec *codec, const hda_nid_t *dig_pins, int num_pins) { struct conexant_spec *spec = codec->spec; hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; int i; for (i = 0; i < num_pins; i++, dig_pins++) { unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) continue; if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) continue; if (spec->slave_dig_outs[0]) nid_loc++; else nid_loc = spec->slave_dig_outs; } } static const struct hda_input_mux cxt5066_capture_source = { .num_items = 4, .items = { { "Mic B", 0 }, { "Mic C", 1 }, { "Mic E", 2 }, { "Mic F", 3 }, }, }; static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { .ops = &snd_hda_bind_vol, .values = { HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 0 }, }; static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { .ops = &snd_hda_bind_sw, .values = { HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 0 }, }; static const struct snd_kcontrol_new cxt5066_mixer_master[] = { HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), {} }; static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Volume", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, .subdevice = HDA_SUBDEV_AMP_FLAG, .info = snd_hda_mixer_amp_volume_info, .get = snd_hda_mixer_amp_volume_get, .put = snd_hda_mixer_amp_volume_put, .tlv = { .c = snd_hda_mixer_amp_tlv }, /* offset by 28 volume steps to limit minimum gain to -46dB */ .private_value = HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), }, {} }; static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "DC Mode Enable Switch", .info = snd_ctl_boolean_mono_info, .get = cxt5066_olpc_dc_get, .put = cxt5066_olpc_dc_put, }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "DC Input Bias Enum", .info = cxt5066_olpc_dc_bias_enum_info, .get = cxt5066_olpc_dc_bias_enum_get, .put = cxt5066_olpc_dc_bias_enum_put, }, {} }; static const struct snd_kcontrol_new cxt5066_mixers[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Switch", .info = cxt_eapd_info, .get = cxt_eapd_get, .put = cxt5066_hp_master_sw_put, .private_value = 0x1d, }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Analog Mic Boost Capture Enum", .info = cxt5066_mic_boost_mux_enum_info, .get = cxt5066_mic_boost_mux_enum_get, .put = cxt5066_mic_boost_mux_enum_put, }, HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), {} }; static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Internal Mic Boost Capture Enum", .info = cxt5066_mic_boost_mux_enum_info, .get = cxt5066_mic_boost_mux_enum_get, .put = cxt5066_mic_boost_mux_enum_put, .private_value = 0x23 | 0x100, }, {} }; static const struct hda_verb cxt5066_init_verbs[] = { {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ /* Speakers */ {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* HP, Amp */ {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* DAC1 */ {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* no digital microphone support yet */ {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Audio input selector */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, /* SPDIF route: PCM */ {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* EAPD */ {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ /* not handling these yet */ {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, { } /* end */ }; static const struct hda_verb cxt5066_init_verbs_olpc[] = { /* Port A: headphones */ {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* Port B: external microphone */ {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Port C: internal microphone */ {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Port D: unused */ {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Port E: unused, but has primary EAPD */ {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ /* Port F: external DC input through microphone port */ {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Port G: internal speakers */ {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* DAC1 */ {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* DAC2: unused */ {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* Disable digital microphone port */ {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Audio input selectors */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, /* Disable SPDIF */ {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* enable unsolicited events for Port A and B */ {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, { } /* end */ }; static const struct hda_verb cxt5066_init_verbs_vostro[] = { /* Port A: headphones */ {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* Port B: external microphone */ {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Port C: unused */ {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Port D: unused */ {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Port E: unused, but has primary EAPD */ {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ /* Port F: unused */ {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Port G: internal speakers */ {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* DAC1 */ {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* DAC2: unused */ {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* Digital microphone port */ {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Audio input selectors */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, /* Disable SPDIF */ {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* enable unsolicited events for Port A and B */ {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, { } /* end */ }; static const struct hda_verb cxt5066_init_verbs_ideapad[] = { {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ /* Speakers */ {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* HP, Amp */ {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* DAC1 */ {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ /* Audio input selector */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ /* SPDIF route: PCM */ {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* internal microphone */ {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ /* EAPD */ {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, { } /* end */ }; static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ /* Port G: internal speakers */ {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* Port A: HP, Amp */ {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* Port B: Mic Dock */ {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Port C: Mic */ {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, /* Port D: HP Dock, Amp */ {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ /* DAC1 */ {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ /* Audio input selector */ {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ /* SPDIF route: PCM */ {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* internal microphone */ {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ /* EAPD */ {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ /* enable unsolicited events for Port A, B, C and D */ {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, { } /* end */ }; static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, { } /* end */ }; static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, { } /* end */ }; /* initialize jack-sensing, too */ static int cxt5066_init(struct hda_codec *codec) { snd_printdd("CXT5066: init\n"); conexant_init(codec); if (codec->patch_ops.unsol_event) { cxt5066_hp_automute(codec); cxt5066_automic(codec); } cxt5066_set_mic_boost(codec); return 0; } static int cxt5066_olpc_init(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; snd_printdd("CXT5066: init\n"); conexant_init(codec); cxt5066_hp_automute(codec); if (!spec->dc_enable) { cxt5066_set_mic_boost(codec); cxt5066_olpc_automic(codec); } else { cxt5066_enable_dc(codec); } return 0; } enum { CXT5066_LAPTOP, /* Laptops w/ EAPD support */ CXT5066_DELL_LAPTOP, /* Dell Laptop */ CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ CXT5066_HP_LAPTOP, /* HP Laptop */ CXT5066_AUTO, /* BIOS auto-parser */ CXT5066_MODELS }; static const char * const cxt5066_models[CXT5066_MODELS] = { [CXT5066_LAPTOP] = "laptop", [CXT5066_DELL_LAPTOP] = "dell-laptop", [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", [CXT5066_DELL_VOSTRO] = "dell-vostro", [CXT5066_IDEAPAD] = "ideapad", [CXT5066_THINKPAD] = "thinkpad", [CXT5066_ASUS] = "asus", [CXT5066_HP_LAPTOP] = "hp-laptop", [CXT5066_AUTO] = "auto", }; static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO), SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", CXT5066_LAPTOP), SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO), SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO), SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO), SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO), {} }; static int patch_cxt5066(struct hda_codec *codec) { struct conexant_spec *spec; int board_config; board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, cxt5066_models, cxt5066_cfg_tbl); if (board_config < 0) board_config = CXT5066_AUTO; /* model=auto as default */ if (board_config == CXT5066_AUTO) return patch_conexant_auto(codec); spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (!spec) return -ENOMEM; codec->spec = spec; codec->patch_ops = conexant_patch_ops; codec->patch_ops.init = conexant_init; spec->dell_automute = 0; spec->multiout.max_channels = 2; spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); spec->multiout.dac_nids = cxt5066_dac_nids; conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, ARRAY_SIZE(cxt5066_digout_pin_nids)); spec->num_adc_nids = 1; spec->adc_nids = cxt5066_adc_nids; spec->capsrc_nids = cxt5066_capsrc_nids; spec->input_mux = &cxt5066_capture_source; spec->port_d_mode = PIN_HP; spec->num_init_verbs = 1; spec->init_verbs[0] = cxt5066_init_verbs; spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); spec->channel_mode = cxt5066_modes; spec->cur_adc = 0; spec->cur_adc_idx = 0; set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); switch (board_config) { default: case CXT5066_LAPTOP: spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; spec->mixers[spec->num_mixers++] = cxt5066_mixers; break; case CXT5066_DELL_LAPTOP: spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; spec->mixers[spec->num_mixers++] = cxt5066_mixers; spec->port_d_mode = PIN_OUT; spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; spec->num_init_verbs++; spec->dell_automute = 1; break; case CXT5066_ASUS: case CXT5066_HP_LAPTOP: codec->patch_ops.init = cxt5066_init; codec->patch_ops.unsol_event = cxt5066_unsol_event; spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_hp_laptop; spec->num_init_verbs++; spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; spec->asus = board_config == CXT5066_ASUS; spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; spec->mixers[spec->num_mixers++] = cxt5066_mixers; /* no S/PDIF out */ if (board_config == CXT5066_HP_LAPTOP) spec->multiout.dig_out_nid = 0; /* input source automatically selected */ spec->input_mux = NULL; spec->port_d_mode = 0; spec->mic_boost = 3; /* default 30dB gain */ break; case CXT5066_OLPC_XO_1_5: codec->patch_ops.init = cxt5066_olpc_init; codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; spec->init_verbs[0] = cxt5066_init_verbs_olpc; spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; spec->mixers[spec->num_mixers++] = cxt5066_mixers; spec->port_d_mode = 0; spec->mic_boost = 3; /* default 30dB gain */ /* no S/PDIF out */ spec->multiout.dig_out_nid = 0; /* input source automatically selected */ spec->input_mux = NULL; /* our capture hooks which allow us to turn on the microphone LED * at the right time */ spec->capture_prepare = cxt5066_olpc_capture_prepare; spec->capture_cleanup = cxt5066_olpc_capture_cleanup; break; case CXT5066_DELL_VOSTRO: codec->patch_ops.init = cxt5066_init; codec->patch_ops.unsol_event = cxt5066_unsol_event; spec->init_verbs[0] = cxt5066_init_verbs_vostro; spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; spec->mixers[spec->num_mixers++] = cxt5066_mixers; spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; spec->port_d_mode = 0; spec->dell_vostro = 1; spec->mic_boost = 3; /* default 30dB gain */ /* no S/PDIF out */ spec->multiout.dig_out_nid = 0; /* input source automatically selected */ spec->input_mux = NULL; break; case CXT5066_IDEAPAD: codec->patch_ops.init = cxt5066_init; codec->patch_ops.unsol_event = cxt5066_unsol_event; spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; spec->mixers[spec->num_mixers++] = cxt5066_mixers; spec->init_verbs[0] = cxt5066_init_verbs_ideapad; spec->port_d_mode = 0; spec->ideapad = 1; spec->mic_boost = 2; /* default 20dB gain */ /* no S/PDIF out */ spec->multiout.dig_out_nid = 0; /* input source automatically selected */ spec->input_mux = NULL; break; case CXT5066_THINKPAD: codec->patch_ops.init = cxt5066_init; codec->patch_ops.unsol_event = cxt5066_unsol_event; spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; spec->mixers[spec->num_mixers++] = cxt5066_mixers; spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; spec->thinkpad = 1; spec->port_d_mode = PIN_OUT; spec->mic_boost = 2; /* default 20dB gain */ /* no S/PDIF out */ spec->multiout.dig_out_nid = 0; /* input source automatically selected */ spec->input_mux = NULL; break; } if (spec->beep_amp) snd_hda_attach_beep_device(codec, spec->beep_amp); return 0; } /* * Automatic parser for CX20641 & co */ static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; if (spec->adc_switching) { spec->cur_adc = adc; spec->cur_adc_stream_tag = stream_tag; spec->cur_adc_format = format; } snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); return 0; } static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct conexant_spec *spec = codec->spec; snd_hda_codec_cleanup_stream(codec, spec->cur_adc); spec->cur_adc = 0; return 0; } static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { .substreams = 1, .channels_min = 2, .channels_max = 2, .nid = 0, /* fill later */ .ops = { .prepare = cx_auto_capture_pcm_prepare, .cleanup = cx_auto_capture_pcm_cleanup }, }; static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; #define get_connection_index(codec, mux, nid)\ snd_hda_get_conn_index(codec, mux, nid, 0) /* get an unassigned DAC from the given list. * Return the nid if found and reduce the DAC list, or return zero if * not found */ static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, hda_nid_t *dacs, int *num_dacs) { int i, nums = *num_dacs; hda_nid_t ret = 0; for (i = 0; i < nums; i++) { if (get_connection_index(codec, pin, dacs[i]) >= 0) { ret = dacs[i]; break; } } if (!ret) return 0; if (--nums > 0) memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); *num_dacs = nums; return ret; } #define MAX_AUTO_DACS 5 #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */ /* fill analog DAC list from the widget tree */ static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) { hda_nid_t nid, end_nid; int nums = 0; end_nid = codec->start_nid + codec->num_nodes; for (nid = codec->start_nid; nid < end_nid; nid++) { unsigned int wcaps = get_wcaps(codec, nid); unsigned int type = get_wcaps_type(wcaps); if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { dacs[nums++] = nid; if (nums >= MAX_AUTO_DACS) break; } } return nums; } /* fill pin_dac_pair list from the pin and dac list */ static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, int num_pins, hda_nid_t *dacs, int *rest, struct pin_dac_pair *filled, int nums, int type) { int i, start = nums; for (i = 0; i < num_pins; i++, nums++) { filled[nums].pin = pins[i]; filled[nums].type = type; filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); if (filled[nums].dac) continue; if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) { filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG; continue; } if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) { filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG; continue; } snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]); } return nums; } /* parse analog output paths */ static void cx_auto_parse_output(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; hda_nid_t dacs[MAX_AUTO_DACS]; int i, j, nums, rest; rest = fill_cx_auto_dacs(codec, dacs); /* parse all analog output pins */ nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, dacs, &rest, spec->dac_info, 0, AUTO_PIN_LINE_OUT); nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, dacs, &rest, spec->dac_info, nums, AUTO_PIN_HP_OUT); nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, dacs, &rest, spec->dac_info, nums, AUTO_PIN_SPEAKER_OUT); spec->dac_info_filled = nums; /* fill multiout struct */ for (i = 0; i < nums; i++) { hda_nid_t dac = spec->dac_info[i].dac; if (!dac || (dac & DAC_SLAVE_FLAG)) continue; switch (spec->dac_info[i].type) { case AUTO_PIN_LINE_OUT: spec->private_dac_nids[spec->multiout.num_dacs] = dac; spec->multiout.num_dacs++; break; case AUTO_PIN_HP_OUT: case AUTO_PIN_SPEAKER_OUT: if (!spec->multiout.hp_nid) { spec->multiout.hp_nid = dac; break; } for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) if (!spec->multiout.extra_out_nid[j]) { spec->multiout.extra_out_nid[j] = dac; break; } break; } } spec->multiout.dac_nids = spec->private_dac_nids; spec->multiout.max_channels = spec->multiout.num_dacs * 2; for (i = 0; i < cfg->hp_outs; i++) { if (is_jack_detectable(codec, cfg->hp_pins[i])) { spec->auto_mute = 1; break; } } if (spec->auto_mute && cfg->line_out_pins[0] && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && cfg->line_out_pins[0] != cfg->hp_pins[0] && cfg->line_out_pins[0] != cfg->speaker_pins[0]) { for (i = 0; i < cfg->line_outs; i++) { if (is_jack_detectable(codec, cfg->line_out_pins[i])) { spec->detect_line = 1; break; } } spec->automute_lines = spec->detect_line; } spec->vmaster_nid = spec->private_dac_nids[0]; } static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, hda_nid_t *pins, bool on); static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, bool on) { struct conexant_spec *spec = codec->spec; int i; for (i = 0; i < num_pins; i++) snd_hda_codec_write(codec, pins[i], 0, AC_VERB_SET_PIN_WIDGET_CONTROL, on ? PIN_OUT : 0); if (spec->pin_eapd_ctrls) cx_auto_turn_eapd(codec, num_pins, pins, on); } static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) { int i, present = 0; for (i = 0; i < num_pins; i++) { hda_nid_t nid = pins[i]; if (!nid || !is_jack_detectable(codec, nid)) break; present |= snd_hda_jack_detect(codec, nid); } return present; } /* auto-mute/unmute speaker and line outs according to headphone jack */ static void cx_auto_update_speakers(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; int on = 1; /* turn on HP EAPD when HP jacks are present */ if (spec->pin_eapd_ctrls) { if (spec->auto_mute) on = spec->hp_present; cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); } /* mute speakers in auto-mode if HP or LO jacks are plugged */ if (spec->auto_mute) on = !(spec->hp_present || (spec->detect_line && spec->line_present)); do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); /* toggle line-out mutes if needed, too */ /* if LO is a copy of either HP or Speaker, don't need to handle it */ if (cfg->line_out_pins[0] == cfg->hp_pins[0] || cfg->line_out_pins[0] == cfg->speaker_pins[0]) return; if (spec->auto_mute) { /* mute LO in auto-mode when HP jack is present */ if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || spec->automute_lines) on = !spec->hp_present; else on = 1; } do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); } static void cx_auto_hp_automute(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; if (!spec->auto_mute) return; spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); cx_auto_update_speakers(codec); } static void cx_auto_line_automute(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; if (!spec->auto_mute || !spec->detect_line) return; spec->line_present = detect_jacks(codec, cfg->line_outs, cfg->line_out_pins); cx_auto_update_speakers(codec); } static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; static const char * const texts2[] = { "Disabled", "Enabled" }; static const char * const texts3[] = { "Disabled", "Speaker Only", "Line Out+Speaker" }; const char * const *texts; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; if (spec->automute_hp_lo) { uinfo->value.enumerated.items = 3; texts = texts3; } else { uinfo->value.enumerated.items = 2; texts = texts2; } if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0; } static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; unsigned int val; if (!spec->auto_mute) val = 0; else if (!spec->automute_lines) val = 1; else val = 2; ucontrol->value.enumerated.item[0] = val; return 0; } static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; switch (ucontrol->value.enumerated.item[0]) { case 0: if (!spec->auto_mute) return 0; spec->auto_mute = 0; break; case 1: if (spec->auto_mute && !spec->automute_lines) return 0; spec->auto_mute = 1; spec->automute_lines = 0; break; case 2: if (!spec->automute_hp_lo) return -EINVAL; if (spec->auto_mute && spec->automute_lines) return 0; spec->auto_mute = 1; spec->automute_lines = 1; break; default: return -EINVAL; } cx_auto_update_speakers(codec); return 1; } static const struct snd_kcontrol_new cx_automute_mode_enum[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Auto-Mute Mode", .info = cx_automute_mode_info, .get = cx_automute_mode_get, .put = cx_automute_mode_put, }, { } }; static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; return snd_hda_input_mux_info(&spec->private_imux, uinfo); } static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; return 0; } /* look for the route the given pin from mux and return the index; * if do_select is set, actually select the route. */ static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, hda_nid_t pin, hda_nid_t *srcp, bool do_select, int depth) { hda_nid_t conn[HDA_MAX_NUM_INPUTS]; int i, nums; switch (get_wcaps_type(get_wcaps(codec, mux))) { case AC_WID_AUD_IN: case AC_WID_AUD_SEL: case AC_WID_AUD_MIX: break; default: return -1; } nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); for (i = 0; i < nums; i++) if (conn[i] == pin) { if (do_select) snd_hda_codec_write(codec, mux, 0, AC_VERB_SET_CONNECT_SEL, i); if (srcp) *srcp = mux; return i; } depth++; if (depth == 2) return -1; for (i = 0; i < nums; i++) { int ret = __select_input_connection(codec, conn[i], pin, srcp, do_select, depth); if (ret >= 0) { if (do_select) snd_hda_codec_write(codec, mux, 0, AC_VERB_SET_CONNECT_SEL, i); return i; } } return -1; } static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, hda_nid_t pin) { __select_input_connection(codec, mux, pin, NULL, true, 0); } static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, hda_nid_t pin) { return __select_input_connection(codec, mux, pin, NULL, false, 0); } static int cx_auto_mux_enum_update(struct hda_codec *codec, const struct hda_input_mux *imux, unsigned int idx) { struct conexant_spec *spec = codec->spec; hda_nid_t adc; int changed = 1; if (!imux->num_items) return 0; if (idx >= imux->num_items) idx = imux->num_items - 1; if (spec->cur_mux[0] == idx) changed = 0; adc = spec->imux_info[idx].adc; select_input_connection(codec, spec->imux_info[idx].adc, spec->imux_info[idx].pin); if (spec->cur_adc && spec->cur_adc != adc) { /* stream is running, let's swap the current ADC */ __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); spec->cur_adc = adc; snd_hda_codec_setup_stream(codec, adc, spec->cur_adc_stream_tag, 0, spec->cur_adc_format); } spec->cur_mux[0] = idx; return changed; } static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; return cx_auto_mux_enum_update(codec, &spec->private_imux, ucontrol->value.enumerated.item[0]); } static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Capture Source", .info = cx_auto_mux_enum_info, .get = cx_auto_mux_enum_get, .put = cx_auto_mux_enum_put }, {} }; static bool select_automic(struct hda_codec *codec, int idx, bool detect) { struct conexant_spec *spec = codec->spec; if (idx < 0) return false; if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) return false; cx_auto_mux_enum_update(codec, &spec->private_imux, idx); return true; } /* automatic switch internal and external mic */ static void cx_auto_automic(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; if (!spec->auto_mic) return; if (!select_automic(codec, spec->auto_mic_ext, true)) if (!select_automic(codec, spec->auto_mic_dock, true)) select_automic(codec, spec->auto_mic_int, false); } static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) { switch (snd_hda_jack_get_action(codec, res >> 26)) { case CONEXANT_HP_EVENT: cx_auto_hp_automute(codec); break; case CONEXANT_LINE_EVENT: cx_auto_line_automute(codec); break; case CONEXANT_MIC_EVENT: cx_auto_automic(codec); break; } snd_hda_jack_report_sync(codec); } /* check whether the pin config is suitable for auto-mic switching; * auto-mic is enabled only when one int-mic and one ext- and/or * one dock-mic exist */ static void cx_auto_check_auto_mic(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; int pset[INPUT_PIN_ATTR_NORMAL + 1]; int i; for (i = 0; i < ARRAY_SIZE(pset); i++) pset[i] = -1; for (i = 0; i < spec->private_imux.num_items; i++) { hda_nid_t pin = spec->imux_info[i].pin; unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); int type, attr; attr = snd_hda_get_input_pin_attr(def_conf); if (attr == INPUT_PIN_ATTR_UNUSED) return; /* invalid entry */ if (attr > INPUT_PIN_ATTR_NORMAL) attr = INPUT_PIN_ATTR_NORMAL; if (attr != INPUT_PIN_ATTR_INT && !is_jack_detectable(codec, pin)) return; /* non-detectable pin */ type = get_defcfg_device(def_conf); if (type != AC_JACK_MIC_IN && (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) return; /* no valid input type */ if (pset[attr] >= 0) return; /* already occupied */ pset[attr] = i; } if (pset[INPUT_PIN_ATTR_INT] < 0 || (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) return; /* no input to switch*/ spec->auto_mic = 1; spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; } static void cx_auto_parse_input(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; struct hda_input_mux *imux; int i, j; imux = &spec->private_imux; for (i = 0; i < cfg->num_inputs; i++) { for (j = 0; j < spec->num_adc_nids; j++) { hda_nid_t adc = spec->adc_nids[j]; int idx = get_input_connection(codec, adc, cfg->inputs[i].pin); if (idx >= 0) { const char *label; label = hda_get_autocfg_input_label(codec, cfg, i); spec->imux_info[imux->num_items].index = i; spec->imux_info[imux->num_items].boost = 0; spec->imux_info[imux->num_items].adc = adc; spec->imux_info[imux->num_items].pin = cfg->inputs[i].pin; snd_hda_add_imux_item(imux, label, idx, NULL); break; } } } if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) cx_auto_check_auto_mic(codec); if (imux->num_items > 1) { for (i = 1; i < imux->num_items; i++) { if (spec->imux_info[i].adc != spec->imux_info[0].adc) { spec->adc_switching = 1; break; } } } } /* get digital-input audio widget corresponding to the given pin */ static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) { hda_nid_t nid, end_nid; end_nid = codec->start_nid + codec->num_nodes; for (nid = codec->start_nid; nid < end_nid; nid++) { unsigned int wcaps = get_wcaps(codec, nid); unsigned int type = get_wcaps_type(wcaps); if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { if (get_connection_index(codec, nid, pin) >= 0) return nid; } } return 0; } static void cx_auto_parse_digital(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; hda_nid_t nid; if (cfg->dig_outs && snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) spec->multiout.dig_out_nid = nid; if (cfg->dig_in_pin) spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); } #ifdef CONFIG_SND_HDA_INPUT_BEEP static void cx_auto_parse_beep(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; hda_nid_t nid, end_nid; end_nid = codec->start_nid + codec->num_nodes; for (nid = codec->start_nid; nid < end_nid; nid++) if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { set_beep_amp(spec, nid, 0, HDA_OUTPUT); break; } } #else #define cx_auto_parse_beep(codec) #endif /* parse EAPDs */ static void cx_auto_parse_eapd(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; hda_nid_t nid, end_nid; end_nid = codec->start_nid + codec->num_nodes; for (nid = codec->start_nid; nid < end_nid; nid++) { if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) continue; if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) continue; spec->eapds[spec->num_eapds++] = nid; if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) break; } /* NOTE: below is a wild guess; if we have more than two EAPDs, * it's a new chip, where EAPDs are supposed to be associated to * pins, and we can control EAPD per pin. * OTOH, if only one or two EAPDs are found, it's an old chip, * thus it might control over all pins. */ spec->pin_eapd_ctrls = spec->num_eapds > 2; } static int cx_auto_parse_auto_config(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; int err; err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); if (err < 0) return err; cx_auto_parse_output(codec); cx_auto_parse_input(codec); cx_auto_parse_digital(codec); cx_auto_parse_beep(codec); cx_auto_parse_eapd(codec); return 0; } static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, hda_nid_t *pins, bool on) { int i; for (i = 0; i < num_pins; i++) { if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) snd_hda_codec_write(codec, pins[i], 0, AC_VERB_SET_EAPD_BTLENABLE, on ? 0x02 : 0); } } static void select_connection(struct hda_codec *codec, hda_nid_t pin, hda_nid_t src) { int idx = get_connection_index(codec, pin, src); if (idx >= 0) snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_CONNECT_SEL, idx); } static void mute_outputs(struct hda_codec *codec, int num_nids, const hda_nid_t *nids) { int i, val; for (i = 0; i < num_nids; i++) { hda_nid_t nid = nids[i]; if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) continue; if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) val = AMP_OUT_MUTE; else val = AMP_OUT_ZERO; snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, val); } } static void enable_unsol_pins(struct hda_codec *codec, int num_pins, hda_nid_t *pins, unsigned int action) { int i; for (i = 0; i < num_pins; i++) snd_hda_jack_detect_enable(codec, pins[i], action); } static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) { int i; for (i = 0; i < nums; i++) if (list[i] == nid) return true; return false; } /* is the given NID found in any of autocfg items? */ static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid) { int i; if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) || found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) || found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) || found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs)) return true; for (i = 0; i < cfg->num_inputs; i++) if (cfg->inputs[i].pin == nid) return true; if (cfg->dig_in_pin == nid) return true; return false; } /* clear unsol-event tags on unused pins; Conexant codecs seem to leave * invalid unsol tags by some reason */ static void clear_unsol_on_unused_pins(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; int i; for (i = 0; i < codec->init_pins.used; i++) { struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); if (!found_in_autocfg(cfg, pin->nid)) snd_hda_codec_write(codec, pin->nid, 0, AC_VERB_SET_UNSOLICITED_ENABLE, 0); } } /* turn on/off EAPD according to Master switch */ static void cx_auto_vmaster_hook(void *private_data, int enabled) { struct hda_codec *codec = private_data; struct conexant_spec *spec = codec->spec; if (enabled && spec->pin_eapd_ctrls) { cx_auto_update_speakers(codec); return; } cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); } static void cx_auto_init_output(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; hda_nid_t nid; int i; mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); for (i = 0; i < cfg->hp_outs; i++) { unsigned int val = PIN_OUT; if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) & AC_PINCAP_HP_DRV) val |= AC_PINCTL_HP_EN; snd_hda_codec_write(codec, cfg->hp_pins[i], 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val); } mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); for (i = 0; i < spec->dac_info_filled; i++) { nid = spec->dac_info[i].dac; if (!nid) nid = spec->multiout.dac_nids[0]; else if (nid & DAC_SLAVE_FLAG) nid &= ~DAC_SLAVE_FLAG; select_connection(codec, spec->dac_info[i].pin, nid); } if (spec->auto_mute) { enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, CONEXANT_HP_EVENT); spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); if (spec->detect_line) { enable_unsol_pins(codec, cfg->line_outs, cfg->line_out_pins, CONEXANT_LINE_EVENT); spec->line_present = detect_jacks(codec, cfg->line_outs, cfg->line_out_pins); } } cx_auto_update_speakers(codec); /* turn on all EAPDs if no individual EAPD control is available */ if (!spec->pin_eapd_ctrls) cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); clear_unsol_on_unused_pins(codec); } static void cx_auto_init_input(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; int i, val; for (i = 0; i < spec->num_adc_nids; i++) { hda_nid_t nid = spec->adc_nids[i]; if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) continue; if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) val = AMP_IN_MUTE(0); else val = AMP_IN_UNMUTE(0); snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, val); } for (i = 0; i < cfg->num_inputs; i++) { unsigned int type; if (cfg->inputs[i].type == AUTO_PIN_MIC) type = PIN_VREF80; else type = PIN_IN; snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, type); } if (spec->auto_mic) { if (spec->auto_mic_ext >= 0) { snd_hda_jack_detect_enable(codec, cfg->inputs[spec->auto_mic_ext].pin, CONEXANT_MIC_EVENT); } if (spec->auto_mic_dock >= 0) { snd_hda_jack_detect_enable(codec, cfg->inputs[spec->auto_mic_dock].pin, CONEXANT_MIC_EVENT); } cx_auto_automic(codec); } else { select_input_connection(codec, spec->imux_info[0].adc, spec->imux_info[0].pin); } } static void cx_auto_init_digital(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; if (spec->multiout.dig_out_nid) snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); if (spec->dig_in_nid) snd_hda_codec_write(codec, cfg->dig_in_pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); } static int cx_auto_init(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ cx_auto_init_output(codec); cx_auto_init_input(codec); cx_auto_init_digital(codec); snd_hda_jack_report_sync(codec); snd_hda_sync_vmaster_hook(&spec->vmaster_mute); return 0; } static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, const char *dir, int cidx, hda_nid_t nid, int hda_dir, int amp_idx) { static char name[32]; static struct snd_kcontrol_new knew[] = { HDA_CODEC_VOLUME(name, 0, 0, 0), HDA_CODEC_MUTE(name, 0, 0, 0), }; static const char * const sfx[2] = { "Volume", "Switch" }; int i, err; for (i = 0; i < 2; i++) { struct snd_kcontrol *kctl; knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, hda_dir); knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; knew[i].index = cidx; snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); kctl = snd_ctl_new1(&knew[i], codec); if (!kctl) return -ENOMEM; err = snd_hda_ctl_add(codec, nid, kctl); if (err < 0) return err; if (!(query_amp_caps(codec, nid, hda_dir) & (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))) break; } return 0; } #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) #define cx_auto_add_pb_volume(codec, nid, str, idx) \ cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, hda_nid_t pin, const char *name, int idx) { unsigned int caps; if (dac && !(dac & DAC_SLAVE_FLAG)) { caps = query_amp_caps(codec, dac, HDA_OUTPUT); if (caps & AC_AMPCAP_NUM_STEPS) return cx_auto_add_pb_volume(codec, dac, name, idx); } caps = query_amp_caps(codec, pin, HDA_OUTPUT); if (caps & AC_AMPCAP_NUM_STEPS) return cx_auto_add_pb_volume(codec, pin, name, idx); return 0; } static int cx_auto_build_output_controls(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; int i, err; int num_line = 0, num_hp = 0, num_spk = 0; static const char * const texts[3] = { "Front", "Surround", "CLFE" }; if (spec->dac_info_filled == 1) return try_add_pb_volume(codec, spec->dac_info[0].dac, spec->dac_info[0].pin, "Master", 0); for (i = 0; i < spec->dac_info_filled; i++) { const char *label; int idx, type; hda_nid_t dac = spec->dac_info[i].dac; type = spec->dac_info[i].type; if (type == AUTO_PIN_LINE_OUT) type = spec->autocfg.line_out_type; switch (type) { case AUTO_PIN_LINE_OUT: default: label = texts[num_line++]; idx = 0; break; case AUTO_PIN_HP_OUT: label = "Headphone"; idx = num_hp++; break; case AUTO_PIN_SPEAKER_OUT: label = "Speaker"; idx = num_spk++; break; } err = try_add_pb_volume(codec, dac, spec->dac_info[i].pin, label, idx); if (err < 0) return err; } if (spec->auto_mute) { err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); if (err < 0) return err; } return 0; } static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, const char *label, const char *pfx, int cidx) { struct conexant_spec *spec = codec->spec; int i; for (i = 0; i < spec->num_adc_nids; i++) { hda_nid_t adc_nid = spec->adc_nids[i]; int idx = get_input_connection(codec, adc_nid, nid); if (idx < 0) continue; if (codec->single_adc_amp) idx = 0; return cx_auto_add_volume_idx(codec, label, pfx, cidx, adc_nid, HDA_INPUT, idx); } return 0; } static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, const char *label, int cidx) { struct conexant_spec *spec = codec->spec; hda_nid_t mux, nid; int i, con; nid = spec->imux_info[idx].pin; if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) return cx_auto_add_volume(codec, label, " Boost", cidx, nid, HDA_INPUT); con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, &mux, false, 0); if (con < 0) return 0; for (i = 0; i < idx; i++) { if (spec->imux_info[i].boost == mux) return 0; /* already present */ } if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { spec->imux_info[idx].boost = mux; return cx_auto_add_volume(codec, label, " Boost", 0, mux, HDA_OUTPUT); } return 0; } static int cx_auto_build_input_controls(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; struct hda_input_mux *imux = &spec->private_imux; const char *prev_label; int input_conn[HDA_MAX_NUM_INPUTS]; int i, j, err, cidx; int multi_connection; if (!imux->num_items) return 0; multi_connection = 0; for (i = 0; i < imux->num_items; i++) { cidx = get_input_connection(codec, spec->imux_info[i].adc, spec->imux_info[i].pin); if (cidx < 0) continue; input_conn[i] = spec->imux_info[i].adc; if (!codec->single_adc_amp) input_conn[i] |= cidx << 8; if (i > 0 && input_conn[i] != input_conn[0]) multi_connection = 1; } prev_label = NULL; cidx = 0; for (i = 0; i < imux->num_items; i++) { hda_nid_t nid = spec->imux_info[i].pin; const char *label; label = hda_get_autocfg_input_label(codec, &spec->autocfg, spec->imux_info[i].index); if (label == prev_label) cidx++; else cidx = 0; prev_label = label; err = cx_auto_add_boost_volume(codec, i, label, cidx); if (err < 0) return err; if (!multi_connection) { if (i > 0) continue; err = cx_auto_add_capture_volume(codec, nid, "Capture", "", cidx); } else { bool dup_found = false; for (j = 0; j < i; j++) { if (input_conn[j] == input_conn[i]) { dup_found = true; break; } } if (dup_found) continue; err = cx_auto_add_capture_volume(codec, nid, label, " Capture", cidx); } if (err < 0) return err; } if (spec->private_imux.num_items > 1 && !spec->auto_mic) { err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); if (err < 0) return err; } return 0; } static int cx_auto_build_controls(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; int err; err = cx_auto_build_output_controls(codec); if (err < 0) return err; err = cx_auto_build_input_controls(codec); if (err < 0) return err; err = conexant_build_controls(codec); if (err < 0) return err; err = snd_hda_jack_add_kctls(codec, &spec->autocfg); if (err < 0) return err; if (spec->vmaster_mute.sw_kctl) { spec->vmaster_mute.hook = cx_auto_vmaster_hook; err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, spec->vmaster_mute_led); if (err < 0) return err; } return 0; } static int cx_auto_search_adcs(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; hda_nid_t nid, end_nid; end_nid = codec->start_nid + codec->num_nodes; for (nid = codec->start_nid; nid < end_nid; nid++) { unsigned int caps = get_wcaps(codec, nid); if (get_wcaps_type(caps) != AC_WID_AUD_IN) continue; if (caps & AC_WCAP_DIGITAL) continue; if (snd_BUG_ON(spec->num_adc_nids >= ARRAY_SIZE(spec->private_adc_nids))) break; spec->private_adc_nids[spec->num_adc_nids++] = nid; } spec->adc_nids = spec->private_adc_nids; return 0; } static const struct hda_codec_ops cx_auto_patch_ops = { .build_controls = cx_auto_build_controls, .build_pcms = conexant_build_pcms, .init = cx_auto_init, .free = conexant_free, .unsol_event = cx_auto_unsol_event, #ifdef CONFIG_SND_HDA_POWER_SAVE .suspend = conexant_suspend, #endif .reboot_notify = snd_hda_shutup_pins, }; /* * pin fix-up */ struct cxt_pincfg { hda_nid_t nid; u32 val; }; static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg) { for (; cfg->nid; cfg++) snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); } static void apply_pin_fixup(struct hda_codec *codec, const struct snd_pci_quirk *quirk, const struct cxt_pincfg **table) { quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); if (quirk) { snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n", quirk->name); apply_pincfg(codec, table[quirk->value]); } } enum { CXT_PINCFG_LENOVO_X200, CXT_PINCFG_LENOVO_TP410, }; /* ThinkPad X200 & co with cxt5051 */ static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { { 0x16, 0x042140ff }, /* HP (seq# overridden) */ { 0x17, 0x21a11000 }, /* dock-mic */ { 0x19, 0x2121103f }, /* dock-HP */ { 0x1c, 0x21440100 }, /* dock SPDIF out */ {} }; /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = { { 0x19, 0x042110ff }, /* HP (seq# overridden) */ { 0x1a, 0x21a190f0 }, /* dock-mic */ { 0x1c, 0x212140ff }, /* dock-HP */ {} }; static const struct cxt_pincfg *cxt_pincfg_tbl[] = { [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410, }; static const struct snd_pci_quirk cxt5051_fixups[] = { SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), {} }; static const struct snd_pci_quirk cxt5066_fixups[] = { SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), {} }; /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches * can be created (bko#42825) */ static void add_cx5051_fake_mutes(struct hda_codec *codec) { static hda_nid_t out_nids[] = { 0x10, 0x11, 0 }; hda_nid_t *p; for (p = out_nids; *p; p++) snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT, AC_AMPCAP_MIN_MUTE | query_amp_caps(codec, *p, HDA_OUTPUT)); } static int patch_conexant_auto(struct hda_codec *codec) { struct conexant_spec *spec; int err; printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", codec->chip_name); spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (!spec) return -ENOMEM; codec->spec = spec; switch (codec->vendor_id) { case 0x14f15045: codec->single_adc_amp = 1; break; case 0x14f15051: add_cx5051_fake_mutes(codec); codec->pin_amp_workaround = 1; apply_pin_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl); break; default: codec->pin_amp_workaround = 1; apply_pin_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl); } /* Show mute-led control only on HP laptops * This is a sort of white-list: on HP laptops, EAPD corresponds * only to the mute-LED without actualy amp function. Meanwhile, * others may use EAPD really as an amp switch, so it might be * not good to expose it blindly. */ switch (codec->subsystem_id >> 16) { case 0x103c: spec->vmaster_mute_led = 1; break; } err = cx_auto_search_adcs(codec); if (err < 0) return err; err = cx_auto_parse_auto_config(codec); if (err < 0) { kfree(codec->spec); codec->spec = NULL; return err; } spec->capture_stream = &cx_auto_pcm_analog_capture; codec->patch_ops = cx_auto_patch_ops; if (spec->beep_amp) snd_hda_attach_beep_device(codec, spec->beep_amp); /* Some laptops with Conexant chips show stalls in S3 resume, * which falls into the single-cmd mode. * Better to make reset, then. */ if (!codec->bus->sync_write) { snd_printd("hda_codec: " "Enable sync_write for stable communication\n"); codec->bus->sync_write = 1; codec->bus->allow_bus_reset = 1; } return 0; } /* */ static const struct hda_codec_preset snd_hda_preset_conexant[] = { { .id = 0x14f15045, .name = "CX20549 (Venice)", .patch = patch_cxt5045 }, { .id = 0x14f15047, .name = "CX20551 (Waikiki)", .patch = patch_cxt5047 }, { .id = 0x14f15051, .name = "CX20561 (Hermosa)", .patch = patch_cxt5051 }, { .id = 0x14f15066, .name = "CX20582 (Pebble)", .patch = patch_cxt5066 }, { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", .patch = patch_cxt5066 }, { .id = 0x14f15068, .name = "CX20584", .patch = patch_cxt5066 }, { .id = 0x14f15069, .name = "CX20585", .patch = patch_cxt5066 }, { .id = 0x14f1506c, .name = "CX20588", .patch = patch_cxt5066 }, { .id = 0x14f1506e, .name = "CX20590", .patch = patch_cxt5066 }, { .id = 0x14f15097, .name = "CX20631", .patch = patch_conexant_auto }, { .id = 0x14f15098, .name = "CX20632", .patch = patch_conexant_auto }, { .id = 0x14f150a1, .name = "CX20641", .patch = patch_conexant_auto }, { .id = 0x14f150a2, .name = "CX20642", .patch = patch_conexant_auto }, { .id = 0x14f150ab, .name = "CX20651", .patch = patch_conexant_auto }, { .id = 0x14f150ac, .name = "CX20652", .patch = patch_conexant_auto }, { .id = 0x14f150b8, .name = "CX20664", .patch = patch_conexant_auto }, { .id = 0x14f150b9, .name = "CX20665", .patch = patch_conexant_auto }, {} /* terminator */ }; MODULE_ALIAS("snd-hda-codec-id:14f15045"); MODULE_ALIAS("snd-hda-codec-id:14f15047"); MODULE_ALIAS("snd-hda-codec-id:14f15051"); MODULE_ALIAS("snd-hda-codec-id:14f15066"); MODULE_ALIAS("snd-hda-codec-id:14f15067"); MODULE_ALIAS("snd-hda-codec-id:14f15068"); MODULE_ALIAS("snd-hda-codec-id:14f15069"); MODULE_ALIAS("snd-hda-codec-id:14f1506c"); MODULE_ALIAS("snd-hda-codec-id:14f1506e"); MODULE_ALIAS("snd-hda-codec-id:14f15097"); MODULE_ALIAS("snd-hda-codec-id:14f15098"); MODULE_ALIAS("snd-hda-codec-id:14f150a1"); MODULE_ALIAS("snd-hda-codec-id:14f150a2"); MODULE_ALIAS("snd-hda-codec-id:14f150ab"); MODULE_ALIAS("snd-hda-codec-id:14f150ac"); MODULE_ALIAS("snd-hda-codec-id:14f150b8"); MODULE_ALIAS("snd-hda-codec-id:14f150b9"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Conexant HD-audio codec"); static struct hda_codec_preset_list conexant_list = { .preset = snd_hda_preset_conexant, .owner = THIS_MODULE, }; static int __init patch_conexant_init(void) { return snd_hda_add_codec_preset(&conexant_list); } static void __exit patch_conexant_exit(void) { snd_hda_delete_codec_preset(&conexant_list); } module_init(patch_conexant_init) module_exit(patch_conexant_exit)
McBane87/Sony_Tablet_Z_LP.454_Kernel
sound/pci/hda/patch_conexant.c
C
gpl-2.0
137,621
/* * Copyright 2010 Analog Devices Inc. * Copyright (C) 2008 Jonathan Cameron * * Licensed under the GPL-2 or later. * * ad7476_ring.c */ #include <linux/interrupt.h> #include <linux/device.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/spi/spi.h> #include "../iio.h" #include "../buffer.h" #include "../ring_sw.h" #include "../trigger_consumer.h" #include "ad7476.h" /** * ad7476_ring_preenable() setup the parameters of the ring before enabling * * The complex nature of the setting of the number of bytes per datum is due * to this driver currently ensuring that the timestamp is stored at an 8 * byte boundary. **/ static int ad7476_ring_preenable(struct iio_dev *indio_dev) { struct ad7476_state *st = iio_priv(indio_dev); struct iio_buffer *ring = indio_dev->buffer; st->d_size = bitmap_weight(indio_dev->active_scan_mask, indio_dev->masklength) * st->chip_info->channel[0].scan_type.storagebits / 8; if (ring->scan_timestamp) { st->d_size += sizeof(s64); if (st->d_size % sizeof(s64)) st->d_size += sizeof(s64) - (st->d_size % sizeof(s64)); } if (indio_dev->buffer->access->set_bytes_per_datum) indio_dev->buffer->access-> set_bytes_per_datum(indio_dev->buffer, st->d_size); return 0; } static irqreturn_t ad7476_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct ad7476_state *st = iio_priv(indio_dev); s64 time_ns; __u8 *rxbuf; int b_sent; rxbuf = kzalloc(st->d_size, GFP_KERNEL); if (rxbuf == NULL) return -ENOMEM; b_sent = spi_read(st->spi, rxbuf, st->chip_info->channel[0].scan_type.storagebits / 8); if (b_sent < 0) goto done; time_ns = iio_get_time_ns(); if (indio_dev->buffer->scan_timestamp) memcpy(rxbuf + st->d_size - sizeof(s64), &time_ns, sizeof(time_ns)); indio_dev->buffer->access->store_to(indio_dev->buffer, rxbuf, time_ns); done: iio_trigger_notify_done(indio_dev->trig); kfree(rxbuf); return IRQ_HANDLED; } static const struct iio_buffer_setup_ops ad7476_ring_setup_ops = { .preenable = &ad7476_ring_preenable, .postenable = &iio_triggered_buffer_postenable, .predisable = &iio_triggered_buffer_predisable, }; int ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev) { struct ad7476_state *st = iio_priv(indio_dev); int ret = 0; indio_dev->buffer = iio_sw_rb_allocate(indio_dev); if (!indio_dev->buffer) { ret = -ENOMEM; goto error_ret; } indio_dev->pollfunc = iio_alloc_pollfunc(NULL, &ad7476_trigger_handler, IRQF_ONESHOT, indio_dev, "%s_consumer%d", spi_get_device_id(st->spi)->name, indio_dev->id); if (indio_dev->pollfunc == NULL) { ret = -ENOMEM; goto error_deallocate_sw_rb; } /* Ring buffer functions - here trigger setup related */ indio_dev->setup_ops = &ad7476_ring_setup_ops; indio_dev->buffer->scan_timestamp = true; /* Flag that polled ring buffering is possible */ indio_dev->modes |= INDIO_BUFFER_TRIGGERED; return 0; error_deallocate_sw_rb: iio_sw_rb_free(indio_dev->buffer); error_ret: return ret; } void ad7476_ring_cleanup(struct iio_dev *indio_dev) { iio_dealloc_pollfunc(indio_dev->pollfunc); iio_sw_rb_free(indio_dev->buffer); }
Cpasjuste/kernel_amazon_hdx-common
drivers/staging/iio/adc/ad7476_ring.c
C
gpl-2.0
3,255
/* * Copyright (C) ST-Ericsson AB 2010 * Author: Sjur Brendeland/sjur.brandeland@stericsson.com * License terms: GNU General Public License (GPL) version 2 */ #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__ #include <linux/string.h> #include <linux/skbuff.h> #include <linux/hardirq.h> #include <linux/export.h> #include <net/caif/cfpkt.h> #define PKT_PREFIX 48 #define PKT_POSTFIX 2 #define PKT_LEN_WHEN_EXTENDING 128 #define PKT_ERROR(pkt, errmsg) \ do { \ cfpkt_priv(pkt)->erronous = true; \ skb_reset_tail_pointer(&pkt->skb); \ pr_warn(errmsg); \ } while (0) struct cfpktq { struct sk_buff_head head; atomic_t count; /* Lock protects count updates */ spinlock_t lock; }; /* * net/caif/ is generic and does not * understand SKB, so we do this typecast */ struct cfpkt { struct sk_buff skb; }; /* Private data inside SKB */ struct cfpkt_priv_data { struct dev_info dev_info; bool erronous; }; static inline struct cfpkt_priv_data *cfpkt_priv(struct cfpkt *pkt) { return (struct cfpkt_priv_data *) pkt->skb.cb; } static inline bool is_erronous(struct cfpkt *pkt) { return cfpkt_priv(pkt)->erronous; } static inline struct sk_buff *pkt_to_skb(struct cfpkt *pkt) { return &pkt->skb; } static inline struct cfpkt *skb_to_pkt(struct sk_buff *skb) { return (struct cfpkt *) skb; } struct cfpkt *cfpkt_fromnative(enum caif_direction dir, void *nativepkt) { struct cfpkt *pkt = skb_to_pkt(nativepkt); cfpkt_priv(pkt)->erronous = false; return pkt; } EXPORT_SYMBOL(cfpkt_fromnative); void *cfpkt_tonative(struct cfpkt *pkt) { return (void *) pkt; } EXPORT_SYMBOL(cfpkt_tonative); static struct cfpkt *cfpkt_create_pfx(u16 len, u16 pfx) { struct sk_buff *skb; if (likely(in_interrupt())) skb = alloc_skb(len + pfx, GFP_ATOMIC); else skb = alloc_skb(len + pfx, GFP_KERNEL); if (unlikely(skb == NULL)) return NULL; skb_reserve(skb, pfx); return skb_to_pkt(skb); } inline struct cfpkt *cfpkt_create(u16 len) { return cfpkt_create_pfx(len + PKT_POSTFIX, PKT_PREFIX); } void cfpkt_destroy(struct cfpkt *pkt) { struct sk_buff *skb = pkt_to_skb(pkt); kfree_skb(skb); } inline bool cfpkt_more(struct cfpkt *pkt) { struct sk_buff *skb = pkt_to_skb(pkt); return skb->len > 0; } int cfpkt_peek_head(struct cfpkt *pkt, void *data, u16 len) { struct sk_buff *skb = pkt_to_skb(pkt); if (skb_headlen(skb) >= len) { memcpy(data, skb->data, len); return 0; } return !cfpkt_extr_head(pkt, data, len) && !cfpkt_add_head(pkt, data, len); } int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len) { struct sk_buff *skb = pkt_to_skb(pkt); u8 *from; if (unlikely(is_erronous(pkt))) return -EPROTO; if (unlikely(len > skb->len)) { PKT_ERROR(pkt, "read beyond end of packet\n"); return -EPROTO; } if (unlikely(len > skb_headlen(skb))) { if (unlikely(skb_linearize(skb) != 0)) { PKT_ERROR(pkt, "linearize failed\n"); return -EPROTO; } } from = skb_pull(skb, len); from -= len; if (data) memcpy(data, from, len); return 0; } EXPORT_SYMBOL(cfpkt_extr_head); int cfpkt_extr_trail(struct cfpkt *pkt, void *dta, u16 len) { struct sk_buff *skb = pkt_to_skb(pkt); u8 *data = dta; u8 *from; if (unlikely(is_erronous(pkt))) return -EPROTO; if (unlikely(skb_linearize(skb) != 0)) { PKT_ERROR(pkt, "linearize failed\n"); return -EPROTO; } if (unlikely(skb->data + len > skb_tail_pointer(skb))) { PKT_ERROR(pkt, "read beyond end of packet\n"); return -EPROTO; } from = skb_tail_pointer(skb) - len; skb_trim(skb, skb->len - len); memcpy(data, from, len); return 0; } int cfpkt_pad_trail(struct cfpkt *pkt, u16 len) { return cfpkt_add_body(pkt, NULL, len); } int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len) { struct sk_buff *skb = pkt_to_skb(pkt); struct sk_buff *lastskb; u8 *to; u16 addlen = 0; if (unlikely(is_erronous(pkt))) return -EPROTO; lastskb = skb; /* Check whether we need to add space at the tail */ if (unlikely(skb_tailroom(skb) < len)) { if (likely(len < PKT_LEN_WHEN_EXTENDING)) addlen = PKT_LEN_WHEN_EXTENDING; else addlen = len; } /* Check whether we need to change the SKB before writing to the tail */ if (unlikely((addlen > 0) || skb_cloned(skb) || skb_shared(skb))) { /* Make sure data is writable */ if (unlikely(skb_cow_data(skb, addlen, &lastskb) < 0)) { PKT_ERROR(pkt, "cow failed\n"); return -EPROTO; } /* * Is the SKB non-linear after skb_cow_data()? If so, we are * going to add data to the last SKB, so we need to adjust * lengths of the top SKB. */ if (lastskb != skb) { pr_warn("Packet is non-linear\n"); skb->len += len; skb->data_len += len; } } /* All set to put the last SKB and optionally write data there. */ to = skb_put(lastskb, len); if (likely(data)) memcpy(to, data, len); return 0; } inline int cfpkt_addbdy(struct cfpkt *pkt, u8 data) { return cfpkt_add_body(pkt, &data, 1); } int cfpkt_add_head(struct cfpkt *pkt, const void *data2, u16 len) { struct sk_buff *skb = pkt_to_skb(pkt); struct sk_buff *lastskb; u8 *to; const u8 *data = data2; int ret; if (unlikely(is_erronous(pkt))) return -EPROTO; if (unlikely(skb_headroom(skb) < len)) { PKT_ERROR(pkt, "no headroom\n"); return -EPROTO; } /* Make sure data is writable */ ret = skb_cow_data(skb, 0, &lastskb); if (unlikely(ret < 0)) { PKT_ERROR(pkt, "cow failed\n"); return ret; } to = skb_push(skb, len); memcpy(to, data, len); return 0; } EXPORT_SYMBOL(cfpkt_add_head); inline int cfpkt_add_trail(struct cfpkt *pkt, const void *data, u16 len) { return cfpkt_add_body(pkt, data, len); } inline u16 cfpkt_getlen(struct cfpkt *pkt) { struct sk_buff *skb = pkt_to_skb(pkt); return skb->len; } inline u16 cfpkt_iterate(struct cfpkt *pkt, u16 (*iter_func)(u16, void *, u16), u16 data) { /* * Don't care about the performance hit of linearizing, * Checksum should not be used on high-speed interfaces anyway. */ if (unlikely(is_erronous(pkt))) return -EPROTO; if (unlikely(skb_linearize(&pkt->skb) != 0)) { PKT_ERROR(pkt, "linearize failed\n"); return -EPROTO; } return iter_func(data, pkt->skb.data, cfpkt_getlen(pkt)); } int cfpkt_setlen(struct cfpkt *pkt, u16 len) { struct sk_buff *skb = pkt_to_skb(pkt); if (unlikely(is_erronous(pkt))) return -EPROTO; if (likely(len <= skb->len)) { if (unlikely(skb->data_len)) ___pskb_trim(skb, len); else skb_trim(skb, len); return cfpkt_getlen(pkt); } /* Need to expand SKB */ if (unlikely(!cfpkt_pad_trail(pkt, len - skb->len))) PKT_ERROR(pkt, "skb_pad_trail failed\n"); return cfpkt_getlen(pkt); } struct cfpkt *cfpkt_append(struct cfpkt *dstpkt, struct cfpkt *addpkt, u16 expectlen) { struct sk_buff *dst = pkt_to_skb(dstpkt); struct sk_buff *add = pkt_to_skb(addpkt); u16 addlen = skb_headlen(add); u16 neededtailspace; struct sk_buff *tmp; u16 dstlen; u16 createlen; if (unlikely(is_erronous(dstpkt) || is_erronous(addpkt))) { return dstpkt; } if (expectlen > addlen) neededtailspace = expectlen; else neededtailspace = addlen; if (dst->tail + neededtailspace > dst->end) { /* Create a dumplicate of 'dst' with more tail space */ struct cfpkt *tmppkt; dstlen = skb_headlen(dst); createlen = dstlen + neededtailspace; tmppkt = cfpkt_create(createlen + PKT_PREFIX + PKT_POSTFIX); if (tmppkt == NULL) return NULL; tmp = pkt_to_skb(tmppkt); skb_set_tail_pointer(tmp, dstlen); tmp->len = dstlen; memcpy(tmp->data, dst->data, dstlen); cfpkt_destroy(dstpkt); dst = tmp; } memcpy(skb_tail_pointer(dst), add->data, skb_headlen(add)); cfpkt_destroy(addpkt); dst->tail += addlen; dst->len += addlen; return skb_to_pkt(dst); } struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos) { struct sk_buff *skb2; struct sk_buff *skb = pkt_to_skb(pkt); struct cfpkt *tmppkt; u8 *split = skb->data + pos; u16 len2nd = skb_tail_pointer(skb) - split; if (unlikely(is_erronous(pkt))) return NULL; if (skb->data + pos > skb_tail_pointer(skb)) { PKT_ERROR(pkt, "trying to split beyond end of packet\n"); return NULL; } /* Create a new packet for the second part of the data */ tmppkt = cfpkt_create_pfx(len2nd + PKT_PREFIX + PKT_POSTFIX, PKT_PREFIX); if (tmppkt == NULL) return NULL; skb2 = pkt_to_skb(tmppkt); if (skb2 == NULL) return NULL; /* Reduce the length of the original packet */ skb_set_tail_pointer(skb, pos); skb->len = pos; memcpy(skb2->data, split, len2nd); skb2->tail += len2nd; skb2->len += len2nd; return skb_to_pkt(skb2); } bool cfpkt_erroneous(struct cfpkt *pkt) { return cfpkt_priv(pkt)->erronous; } struct caif_payload_info *cfpkt_info(struct cfpkt *pkt) { return (struct caif_payload_info *)&pkt_to_skb(pkt)->cb; } EXPORT_SYMBOL(cfpkt_info);
tarunkapadia93/android_kernel_xiaomi_cancro
net/caif/cfpkt_skbuff.c
C
gpl-2.0
8,802
/* * AD7291 8-Channel, I2C, 12-Bit SAR ADC with Temperature Sensor * * Copyright 2010-2011 Analog Devices Inc. * * Licensed under the GPL-2 or later. */ #include <linux/interrupt.h> #include <linux/device.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/sysfs.h> #include <linux/i2c.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/regulator/consumer.h> #include <linux/err.h> #include "../iio.h" #include "../sysfs.h" #include "../events.h" /* * Simplified handling * * If no events enabled - single polled channel read * If event enabled direct reads disable unless channel * is in the read mask. * * The noise-delayed bit as per datasheet suggestion is always enabled. * */ /* * AD7291 registers definition */ #define AD7291_COMMAND 0x00 #define AD7291_VOLTAGE 0x01 #define AD7291_T_SENSE 0x02 #define AD7291_T_AVERAGE 0x03 #define AD7291_CH0_DATA_HIGH 0x04 #define AD7291_CH0_DATA_LOW 0x05 #define AD7291_CH0_HYST 0x06 #define AD7291_CH1_DATA_HIGH 0x07 #define AD7291_CH1_DATA_LOW 0x08 #define AD7291_CH1_HYST 0x09 #define AD7291_CH2_DATA_HIGH 0x0A #define AD7291_CH2_DATA_LOW 0x0B #define AD7291_CH2_HYST 0x0C #define AD7291_CH3_DATA_HIGH 0x0D #define AD7291_CH3_DATA_LOW 0x0E #define AD7291_CH3_HYST 0x0F #define AD7291_CH4_DATA_HIGH 0x10 #define AD7291_CH4_DATA_LOW 0x11 #define AD7291_CH4_HYST 0x12 #define AD7291_CH5_DATA_HIGH 0x13 #define AD7291_CH5_DATA_LOW 0x14 #define AD7291_CH5_HYST 0x15 #define AD7291_CH6_DATA_HIGH 0x16 #define AD7291_CH6_DATA_LOW 0x17 #define AD7291_CH6_HYST 0x18 #define AD7291_CH7_DATA_HIGH 0x19 #define AD7291_CH7_DATA_LOW 0x1A #define AD7291_CH7_HYST 0x2B #define AD7291_T_SENSE_HIGH 0x1C #define AD7291_T_SENSE_LOW 0x1D #define AD7291_T_SENSE_HYST 0x1E #define AD7291_VOLTAGE_ALERT_STATUS 0x1F #define AD7291_T_ALERT_STATUS 0x20 #define AD7291_VOLTAGE_LIMIT_COUNT 8 /* * AD7291 command */ #define AD7291_AUTOCYCLE (1 << 0) #define AD7291_RESET (1 << 1) #define AD7291_ALERT_CLEAR (1 << 2) #define AD7291_ALERT_POLARITY (1 << 3) #define AD7291_EXT_REF (1 << 4) #define AD7291_NOISE_DELAY (1 << 5) #define AD7291_T_SENSE_MASK (1 << 7) #define AD7291_VOLTAGE_MASK 0xFF00 #define AD7291_VOLTAGE_OFFSET 0x8 /* * AD7291 value masks */ #define AD7291_CHANNEL_MASK 0xF000 #define AD7291_BITS 12 #define AD7291_VALUE_MASK 0xFFF #define AD7291_T_VALUE_SIGN 0x400 #define AD7291_T_VALUE_FLOAT_OFFSET 2 #define AD7291_T_VALUE_FLOAT_MASK 0x2 #define AD7291_BITS 12 struct ad7291_chip_info { struct i2c_client *client; struct regulator *reg; u16 int_vref_mv; u16 command; u16 c_mask; /* Active voltage channels for events */ struct mutex state_lock; }; static int ad7291_i2c_read(struct ad7291_chip_info *chip, u8 reg, u16 *data) { struct i2c_client *client = chip->client; int ret = 0; ret = i2c_smbus_read_word_data(client, reg); if (ret < 0) { dev_err(&client->dev, "I2C read error\n"); return ret; } *data = swab16((u16)ret); return 0; } static int ad7291_i2c_write(struct ad7291_chip_info *chip, u8 reg, u16 data) { return i2c_smbus_write_word_data(chip->client, reg, swab16(data)); } static ssize_t ad7291_store_reset(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad7291_chip_info *chip = iio_priv(indio_dev); return ad7291_i2c_write(chip, AD7291_COMMAND, chip->command | AD7291_RESET); } static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, ad7291_store_reset, 0); static struct attribute *ad7291_attributes[] = { &iio_dev_attr_reset.dev_attr.attr, NULL, }; static const struct attribute_group ad7291_attribute_group = { .attrs = ad7291_attributes, }; static irqreturn_t ad7291_event_handler(int irq, void *private) { struct iio_dev *indio_dev = private; struct ad7291_chip_info *chip = iio_priv(private); u16 t_status, v_status; u16 command; int i; s64 timestamp = iio_get_time_ns(); if (ad7291_i2c_read(chip, AD7291_T_ALERT_STATUS, &t_status)) return IRQ_HANDLED; if (ad7291_i2c_read(chip, AD7291_VOLTAGE_ALERT_STATUS, &v_status)) return IRQ_HANDLED; if (!(t_status || v_status)) return IRQ_HANDLED; command = chip->command | AD7291_ALERT_CLEAR; ad7291_i2c_write(chip, AD7291_COMMAND, command); command = chip->command & ~AD7291_ALERT_CLEAR; ad7291_i2c_write(chip, AD7291_COMMAND, command); /* For now treat t_sense and t_sense_average the same */ if ((t_status & (1 << 0)) || (t_status & (1 << 2))) iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), timestamp); if ((t_status & (1 << 1)) || (t_status & (1 << 3))) iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), timestamp); for (i = 0; i < AD7291_VOLTAGE_LIMIT_COUNT*2; i += 2) { if (v_status & (1 << i)) iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, i/2, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), timestamp); if (v_status & (1 << (i + 1))) iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, i/2, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), timestamp); } return IRQ_HANDLED; } static inline ssize_t ad7291_show_hyst(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad7291_chip_info *chip = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); u16 data; int ret; ret = ad7291_i2c_read(chip, this_attr->address, &data); if (ret < 0) return ret; return sprintf(buf, "%d\n", data & AD7291_VALUE_MASK); } static inline ssize_t ad7291_set_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad7291_chip_info *chip = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); u16 data; int ret; ret = kstrtou16(buf, 10, &data); if (ret < 0) return ret; if (data > AD7291_VALUE_MASK) return -EINVAL; ret = ad7291_i2c_write(chip, this_attr->address, data); if (ret < 0) return ret; return len; } static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad7291_show_hyst, ad7291_set_hyst, AD7291_T_SENSE_HYST); static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad7291_show_hyst, ad7291_set_hyst, AD7291_CH0_HYST); static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad7291_show_hyst, ad7291_set_hyst, AD7291_CH1_HYST); static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad7291_show_hyst, ad7291_set_hyst, AD7291_CH2_HYST); static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad7291_show_hyst, ad7291_set_hyst, AD7291_CH3_HYST); static IIO_DEVICE_ATTR(in_voltage4_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad7291_show_hyst, ad7291_set_hyst, AD7291_CH4_HYST); static IIO_DEVICE_ATTR(in_voltage5_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad7291_show_hyst, ad7291_set_hyst, AD7291_CH5_HYST); static IIO_DEVICE_ATTR(in_voltage6_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad7291_show_hyst, ad7291_set_hyst, AD7291_CH6_HYST); static IIO_DEVICE_ATTR(in_voltage7_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad7291_show_hyst, ad7291_set_hyst, AD7291_CH7_HYST); static struct attribute *ad7291_event_attributes[] = { &iio_dev_attr_in_temp0_thresh_both_hyst_raw.dev_attr.attr, &iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr, &iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr, &iio_dev_attr_in_voltage2_thresh_both_hyst_raw.dev_attr.attr, &iio_dev_attr_in_voltage3_thresh_both_hyst_raw.dev_attr.attr, &iio_dev_attr_in_voltage4_thresh_both_hyst_raw.dev_attr.attr, &iio_dev_attr_in_voltage5_thresh_both_hyst_raw.dev_attr.attr, &iio_dev_attr_in_voltage6_thresh_both_hyst_raw.dev_attr.attr, &iio_dev_attr_in_voltage7_thresh_both_hyst_raw.dev_attr.attr, NULL, }; /* high / low */ static u8 ad7291_limit_regs[9][2] = { { AD7291_CH0_DATA_HIGH, AD7291_CH0_DATA_LOW }, { AD7291_CH1_DATA_HIGH, AD7291_CH1_DATA_LOW }, { AD7291_CH2_DATA_HIGH, AD7291_CH2_DATA_LOW }, { AD7291_CH3_DATA_HIGH, AD7291_CH3_DATA_LOW }, /* FIXME: ? */ { AD7291_CH4_DATA_HIGH, AD7291_CH4_DATA_LOW }, { AD7291_CH5_DATA_HIGH, AD7291_CH5_DATA_LOW }, { AD7291_CH6_DATA_HIGH, AD7291_CH6_DATA_LOW }, { AD7291_CH7_DATA_HIGH, AD7291_CH7_DATA_LOW }, /* temp */ { AD7291_T_SENSE_HIGH, AD7291_T_SENSE_LOW }, }; static int ad7291_read_event_value(struct iio_dev *indio_dev, u64 event_code, int *val) { struct ad7291_chip_info *chip = iio_priv(indio_dev); int ret; u8 reg; u16 uval; s16 signval; switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) { case IIO_VOLTAGE: reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)] [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)]; ret = ad7291_i2c_read(chip, reg, &uval); if (ret < 0) return ret; *val = uval & AD7291_VALUE_MASK; return 0; case IIO_TEMP: reg = ad7291_limit_regs[8] [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)]; ret = ad7291_i2c_read(chip, reg, &signval); if (ret < 0) return ret; signval = (s16)((signval & AD7291_VALUE_MASK) << 4) >> 4; *val = signval; return 0; default: return -EINVAL; }; } static int ad7291_write_event_value(struct iio_dev *indio_dev, u64 event_code, int val) { struct ad7291_chip_info *chip = iio_priv(indio_dev); u8 reg; s16 signval; switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) { case IIO_VOLTAGE: if (val > AD7291_VALUE_MASK || val < 0) return -EINVAL; reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)] [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)]; return ad7291_i2c_write(chip, reg, val); case IIO_TEMP: if (val > 2047 || val < -2048) return -EINVAL; reg = ad7291_limit_regs[8] [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)]; signval = val; return ad7291_i2c_write(chip, reg, *(u16 *)&signval); default: return -EINVAL; }; } static int ad7291_read_event_config(struct iio_dev *indio_dev, u64 event_code) { struct ad7291_chip_info *chip = iio_priv(indio_dev); /* To be enabled the channel must simply be on. If any are enabled we are in continuous sampling mode */ switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) { case IIO_VOLTAGE: if (chip->c_mask & (1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN(event_code)))) return 1; else return 0; case IIO_TEMP: /* always on */ return 1; default: return -EINVAL; } } static int ad7291_write_event_config(struct iio_dev *indio_dev, u64 event_code, int state) { int ret = 0; struct ad7291_chip_info *chip = iio_priv(indio_dev); u16 regval; mutex_lock(&chip->state_lock); regval = chip->command; /* * To be enabled the channel must simply be on. If any are enabled * use continuous sampling mode. * Possible to disable temp as well but that makes single read tricky. */ switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) { case IIO_VOLTAGE: if ((!state) && (chip->c_mask & (1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN(event_code))))) chip->c_mask &= ~(1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN (event_code))); else if (state && (!(chip->c_mask & (1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN(event_code)))))) chip->c_mask |= (1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN (event_code))); else break; regval &= ~AD7291_AUTOCYCLE; regval |= chip->c_mask; if (chip->c_mask) /* Enable autocycle? */ regval |= AD7291_AUTOCYCLE; ret = ad7291_i2c_write(chip, AD7291_COMMAND, regval); if (ret < 0) goto error_ret; chip->command = regval; break; default: ret = -EINVAL; } error_ret: mutex_unlock(&chip->state_lock); return ret; } static int ad7291_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { int ret; struct ad7291_chip_info *chip = iio_priv(indio_dev); unsigned int scale_uv; u16 regval; s16 signval; switch (mask) { case 0: switch (chan->type) { case IIO_VOLTAGE: mutex_lock(&chip->state_lock); /* If in autocycle mode drop through */ if (chip->command & AD7291_AUTOCYCLE) { mutex_unlock(&chip->state_lock); return -EBUSY; } /* Enable this channel alone */ regval = chip->command & (~AD7291_VOLTAGE_MASK); regval |= 1 << (15 - chan->channel); ret = ad7291_i2c_write(chip, AD7291_COMMAND, regval); if (ret < 0) { mutex_unlock(&chip->state_lock); return ret; } /* Read voltage */ ret = i2c_smbus_read_word_data(chip->client, AD7291_VOLTAGE); if (ret < 0) { mutex_unlock(&chip->state_lock); return ret; } *val = swab16((u16)ret) & AD7291_VALUE_MASK; mutex_unlock(&chip->state_lock); return IIO_VAL_INT; case IIO_TEMP: /* Assumes tsense bit of command register always set */ ret = i2c_smbus_read_word_data(chip->client, AD7291_T_SENSE); if (ret < 0) return ret; signval = (s16)((swab16((u16)ret) & AD7291_VALUE_MASK) << 4) >> 4; *val = signval; return IIO_VAL_INT; default: return -EINVAL; } case IIO_CHAN_INFO_AVERAGE_RAW: ret = i2c_smbus_read_word_data(chip->client, AD7291_T_AVERAGE); if (ret < 0) return ret; signval = (s16)((swab16((u16)ret) & AD7291_VALUE_MASK) << 4) >> 4; *val = signval; return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: scale_uv = (chip->int_vref_mv * 1000) >> AD7291_BITS; *val = scale_uv / 1000; *val2 = (scale_uv % 1000) * 1000; return IIO_VAL_INT_PLUS_MICRO; case IIO_TEMP: /* * One LSB of the ADC corresponds to 0.25 deg C. * The temperature reading is in 12-bit twos * complement format */ *val = 250; return IIO_VAL_INT; default: return -EINVAL; } default: return -EINVAL; } } #define AD7291_VOLTAGE_CHAN(_chan) \ { \ .type = IIO_VOLTAGE, \ .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT, \ .indexed = 1, \ .channel = _chan, \ .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)|\ IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) \ } static const struct iio_chan_spec ad7291_channels[] = { AD7291_VOLTAGE_CHAN(0), AD7291_VOLTAGE_CHAN(1), AD7291_VOLTAGE_CHAN(2), AD7291_VOLTAGE_CHAN(3), AD7291_VOLTAGE_CHAN(4), AD7291_VOLTAGE_CHAN(5), AD7291_VOLTAGE_CHAN(6), AD7291_VOLTAGE_CHAN(7), { .type = IIO_TEMP, .info_mask = IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, .indexed = 1, .channel = 0, .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)| IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) } }; static struct attribute_group ad7291_event_attribute_group = { .attrs = ad7291_event_attributes, }; static const struct iio_info ad7291_info = { .attrs = &ad7291_attribute_group, .read_raw = &ad7291_read_raw, .read_event_config = &ad7291_read_event_config, .write_event_config = &ad7291_write_event_config, .read_event_value = &ad7291_read_event_value, .write_event_value = &ad7291_write_event_value, .event_attrs = &ad7291_event_attribute_group, }; static int __devinit ad7291_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ad7291_chip_info *chip; struct iio_dev *indio_dev; int ret = 0, voltage_uv = 0; indio_dev = iio_allocate_device(sizeof(*chip)); if (indio_dev == NULL) { ret = -ENOMEM; goto error_ret; } chip = iio_priv(indio_dev); chip->reg = regulator_get(&client->dev, "vcc"); if (!IS_ERR(chip->reg)) { ret = regulator_enable(chip->reg); if (ret) goto error_put_reg; voltage_uv = regulator_get_voltage(chip->reg); } mutex_init(&chip->state_lock); /* this is only used for device removal purposes */ i2c_set_clientdata(client, indio_dev); chip->client = client; chip->command = AD7291_NOISE_DELAY | AD7291_T_SENSE_MASK | /* Tsense always enabled */ AD7291_ALERT_POLARITY; /* set irq polarity low level */ if (voltage_uv) { chip->int_vref_mv = voltage_uv / 1000; chip->command |= AD7291_EXT_REF; } else { chip->int_vref_mv = 2500; /* Build-in ref */ } indio_dev->name = id->name; indio_dev->channels = ad7291_channels; indio_dev->num_channels = ARRAY_SIZE(ad7291_channels); indio_dev->dev.parent = &client->dev; indio_dev->info = &ad7291_info; indio_dev->modes = INDIO_DIRECT_MODE; ret = ad7291_i2c_write(chip, AD7291_COMMAND, AD7291_RESET); if (ret) { ret = -EIO; goto error_disable_reg; } ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command); if (ret) { ret = -EIO; goto error_disable_reg; } if (client->irq > 0) { ret = request_threaded_irq(client->irq, NULL, &ad7291_event_handler, IRQF_TRIGGER_LOW | IRQF_ONESHOT, id->name, indio_dev); if (ret) goto error_disable_reg; } ret = iio_device_register(indio_dev); if (ret) goto error_unreg_irq; dev_info(&client->dev, "%s ADC registered.\n", id->name); return 0; error_unreg_irq: if (client->irq) free_irq(client->irq, indio_dev); error_disable_reg: if (!IS_ERR(chip->reg)) regulator_disable(chip->reg); error_put_reg: if (!IS_ERR(chip->reg)) regulator_put(chip->reg); iio_free_device(indio_dev); error_ret: return ret; } static int __devexit ad7291_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); struct ad7291_chip_info *chip = iio_priv(indio_dev); iio_device_unregister(indio_dev); if (client->irq) free_irq(client->irq, indio_dev); if (!IS_ERR(chip->reg)) { regulator_disable(chip->reg); regulator_put(chip->reg); } iio_free_device(indio_dev); return 0; } static const struct i2c_device_id ad7291_id[] = { { "ad7291", 0 }, {} }; MODULE_DEVICE_TABLE(i2c, ad7291_id); static struct i2c_driver ad7291_driver = { .driver = { .name = KBUILD_MODNAME, }, .probe = ad7291_probe, .remove = __devexit_p(ad7291_remove), .id_table = ad7291_id, }; module_i2c_driver(ad7291_driver); MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>"); MODULE_DESCRIPTION("Analog Devices AD7291 ADC driver"); MODULE_LICENSE("GPL v2");
G2Mini-DevTeam/android_kernel_lge_msm8226
drivers/staging/iio/adc/ad7291.c
C
gpl-2.0
18,704
div.vertical-tabs { margin: 1em 0 1em 15em; /* LTR */ border: 1px solid #ccc; position: relative; /* IE6/7 */ } .vertical-tabs ul.vertical-tabs-list { width: 15em; list-style: none; list-style-image: none; /* IE6 */ border-top: 1px solid #ccc; padding: 0; position: relative; /* IE6 */ margin: -1px 0 -1px -15em; /* LTR */ float: left; /* LTR */ } .vertical-tabs fieldset.vertical-tabs-pane { margin: 0 !important; padding: 0 1em; border: 0; } fieldset.vertical-tabs-pane legend { display: none; } fieldset.vertical-tabs-pane fieldset legend { display: block; } /* Layout of each tab */ .vertical-tabs ul.vertical-tabs-list li { background: #eee; border: 1px solid #ccc; border-top: 0; padding: 0; margin: 0; min-width: 0; /* IE7 */ } .vertical-tabs ul.vertical-tabs-list li a { display: block; text-decoration: none; padding: 0.5em 0.6em; } .vertical-tabs ul.vertical-tabs-list li a:focus strong, .vertical-tabs ul.vertical-tabs-list li a:active strong, .vertical-tabs ul.vertical-tabs-list li a:hover strong { text-decoration: underline; } .vertical-tabs ul.vertical-tabs-list li a:hover { outline: 1px dotted; } .vertical-tabs ul.vertical-tabs-list li.selected { background-color: #fff; border-right-width: 0; /* LTR */ } .vertical-tabs ul.vertical-tabs-list .selected strong { color: #000; } .vertical-tabs ul.vertical-tabs-list .summary { display: block; } .vertical-tabs ul.vertical-tabs ul.vertical-tabs-list .summary { line-height: normal; margin-bottom: 0; } /** * Prevent text inputs from overflowing when container is too narrow. "width" is * applied to override hardcoded cols or size attributes and used in conjunction * with "box-sizing" to prevent box model issues from occurring in most browsers. */ .vertical-tabs .form-type-textfield input { width: 100%; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; } * html .vertical-tabs .form-type-textfield, * html .vertical-tabs .form-textarea-wrapper { width: 95%; /* IE6 */ }
dunderjeep/drupalmedi
misc/vertical-tabs.css
CSS
gpl-2.0
2,057
/* * Callbacks for the FSM * * Copyright (C) 1996 Universidade de Lisboa * * Written by Pedro Roque Marques (roque@di.fc.ul.pt) * * This software may be used and distributed according to the terms of * the GNU General Public License, incorporated herein by reference. */ /* * Fix: 19981230 - Carlos Morgado <chbm@techie.com> * Port of Nelson Escravana's <nelson.escravana@usa.net> fix to CalledPN * NULL pointer dereference in cb_in_1 (originally fixed in 2.0) */ #include <linux/string.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/mm.h> #include <linux/skbuff.h> #include <asm/io.h> #include <linux/isdnif.h> #include "pcbit.h" #include "layer2.h" #include "edss1.h" #include "callbacks.h" #include "capi.h" ushort last_ref_num = 1; /* * send_conn_req * */ void cb_out_1(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *cbdata) { struct sk_buff *skb; int len; ushort refnum; #ifdef DEBUG printk(KERN_DEBUG "Called Party Number: %s\n", cbdata->data.setup.CalledPN); #endif /* * hdr - kmalloc in capi_conn_req * - kfree when msg has been sent */ if ((len = capi_conn_req(cbdata->data.setup.CalledPN, &skb, chan->proto)) < 0) { printk("capi_conn_req failed\n"); return; } refnum = last_ref_num++ & 0x7fffU; chan->callref = 0; chan->layer2link = 0; chan->snum = 0; chan->s_refnum = refnum; pcbit_l2_write(dev, MSG_CONN_REQ, refnum, skb, len); } /* * rcv CONNECT * will go into ACTIVE state * send CONN_ACTIVE_RESP * send Select protocol request */ void cb_out_2(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *data) { isdn_ctrl ictl; struct sk_buff *skb; int len; ushort refnum; if ((len = capi_conn_active_resp(chan, &skb)) < 0) { printk("capi_conn_active_req failed\n"); return; } refnum = last_ref_num++ & 0x7fffU; chan->s_refnum = refnum; pcbit_l2_write(dev, MSG_CONN_ACTV_RESP, refnum, skb, len); ictl.command = ISDN_STAT_DCONN; ictl.driver = dev->id; ictl.arg = chan->id; dev->dev_if->statcallb(&ictl); /* ACTIVE D-channel */ /* Select protocol */ if ((len = capi_select_proto_req(chan, &skb, 1 /*outgoing*/)) < 0) { printk("capi_select_proto_req failed\n"); return; } refnum = last_ref_num++ & 0x7fffU; chan->s_refnum = refnum; pcbit_l2_write(dev, MSG_SELP_REQ, refnum, skb, len); } /* * Incoming call received * inform user */ void cb_in_1(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *cbdata) { isdn_ctrl ictl; unsigned short refnum; struct sk_buff *skb; int len; ictl.command = ISDN_STAT_ICALL; ictl.driver = dev->id; ictl.arg = chan->id; /* * ictl.num >= strlen() + strlen() + 5 */ if (cbdata->data.setup.CallingPN == NULL) { printk(KERN_DEBUG "NULL CallingPN to phone; using 0\n"); strcpy(ictl.parm.setup.phone, "0"); } else { strcpy(ictl.parm.setup.phone, cbdata->data.setup.CallingPN); } if (cbdata->data.setup.CalledPN == NULL) { printk(KERN_DEBUG "NULL CalledPN to eazmsn; using 0\n"); strcpy(ictl.parm.setup.eazmsn, "0"); } else { strcpy(ictl.parm.setup.eazmsn, cbdata->data.setup.CalledPN); } ictl.parm.setup.si1 = 7; ictl.parm.setup.si2 = 0; ictl.parm.setup.plan = 0; ictl.parm.setup.screen = 0; #ifdef DEBUG printk(KERN_DEBUG "statstr: %s\n", ictl.num); #endif dev->dev_if->statcallb(&ictl); if ((len = capi_conn_resp(chan, &skb)) < 0) { printk(KERN_DEBUG "capi_conn_resp failed\n"); return; } refnum = last_ref_num++ & 0x7fffU; chan->s_refnum = refnum; pcbit_l2_write(dev, MSG_CONN_RESP, refnum, skb, len); } /* * user has replied * open the channel * send CONNECT message CONNECT_ACTIVE_REQ in CAPI */ void cb_in_2(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *data) { unsigned short refnum; struct sk_buff *skb; int len; if ((len = capi_conn_active_req(chan, &skb)) < 0) { printk(KERN_DEBUG "capi_conn_active_req failed\n"); return; } refnum = last_ref_num++ & 0x7fffU; chan->s_refnum = refnum; printk(KERN_DEBUG "sending MSG_CONN_ACTV_REQ\n"); pcbit_l2_write(dev, MSG_CONN_ACTV_REQ, refnum, skb, len); } /* * CONN_ACK arrived * start b-proto selection * */ void cb_in_3(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *data) { unsigned short refnum; struct sk_buff *skb; int len; if ((len = capi_select_proto_req(chan, &skb, 0 /*incoming*/)) < 0) { printk("capi_select_proto_req failed\n"); return; } refnum = last_ref_num++ & 0x7fffU; chan->s_refnum = refnum; pcbit_l2_write(dev, MSG_SELP_REQ, refnum, skb, len); } /* * Received disconnect ind on active state * send disconnect resp * send msg to user */ void cb_disc_1(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *data) { struct sk_buff *skb; int len; ushort refnum; isdn_ctrl ictl; if ((len = capi_disc_resp(chan, &skb)) < 0) { printk("capi_disc_resp failed\n"); return; } refnum = last_ref_num++ & 0x7fffU; chan->s_refnum = refnum; pcbit_l2_write(dev, MSG_DISC_RESP, refnum, skb, len); ictl.command = ISDN_STAT_BHUP; ictl.driver = dev->id; ictl.arg = chan->id; dev->dev_if->statcallb(&ictl); } /* * User HANGUP on active/call proceeding state * send disc.req */ void cb_disc_2(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *data) { struct sk_buff *skb; int len; ushort refnum; if ((len = capi_disc_req(chan->callref, &skb, CAUSE_NORMAL)) < 0) { printk("capi_disc_req failed\n"); return; } refnum = last_ref_num++ & 0x7fffU; chan->s_refnum = refnum; pcbit_l2_write(dev, MSG_DISC_REQ, refnum, skb, len); } /* * Disc confirm received send BHUP * Problem: when the HL driver sends the disc req itself * LL receives BHUP */ void cb_disc_3(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *data) { isdn_ctrl ictl; ictl.command = ISDN_STAT_BHUP; ictl.driver = dev->id; ictl.arg = chan->id; dev->dev_if->statcallb(&ictl); } void cb_notdone(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *data) { } /* * send activate b-chan protocol */ void cb_selp_1(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *data) { struct sk_buff *skb; int len; ushort refnum; if ((len = capi_activate_transp_req(chan, &skb)) < 0) { printk("capi_conn_activate_transp_req failed\n"); return; } refnum = last_ref_num++ & 0x7fffU; chan->s_refnum = refnum; pcbit_l2_write(dev, MSG_ACT_TRANSP_REQ, refnum, skb, len); } /* * Inform User that the B-channel is available */ void cb_open(struct pcbit_dev *dev, struct pcbit_chan *chan, struct callb_data *data) { isdn_ctrl ictl; ictl.command = ISDN_STAT_BCONN; ictl.driver = dev->id; ictl.arg = chan->id; dev->dev_if->statcallb(&ictl); }
jmztaylor/android_kernel_htc_operaul
drivers/isdn/pcbit/callbacks.c
C
gpl-2.0
6,852
/* * Sample kobject implementation * * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com> * Copyright (C) 2007 Novell Inc. * * Released under the GPL version 2 only. * */ #include <linux/kobject.h> #include <linux/string.h> #include <linux/sysfs.h> #include <linux/module.h> #include <linux/init.h> /* * This module shows how to create a simple subdirectory in sysfs called * /sys/kernel/kobject-example In that directory, 3 files are created: * "foo", "baz", and "bar". If an integer is written to these files, it can be * later read out of it. */ static int foo; static int baz; static int bar; /* * The "foo" file where a static variable is read from and written to. */ static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%d\n", foo); } static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { sscanf(buf, "%du", &foo); return count; } static struct kobj_attribute foo_attribute = __ATTR(foo, 0666, foo_show, foo_store); /* * More complex function where we determine which variable is being accessed by * looking at the attribute for the "baz" and "bar" files. */ static ssize_t b_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { int var; if (strcmp(attr->attr.name, "baz") == 0) var = baz; else var = bar; return sprintf(buf, "%d\n", var); } static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { int var; sscanf(buf, "%du", &var); if (strcmp(attr->attr.name, "baz") == 0) baz = var; else bar = var; return count; } static struct kobj_attribute baz_attribute = __ATTR(baz, 0666, b_show, b_store); static struct kobj_attribute bar_attribute = __ATTR(bar, 0666, b_show, b_store); /* * Create a group of attributes so that we can create and destroy them all * at once. */ static struct attribute *attrs[] = { &foo_attribute.attr, &baz_attribute.attr, &bar_attribute.attr, NULL, /* need to NULL terminate the list of attributes */ }; /* * An unnamed attribute group will put all of the attributes directly in * the kobject directory. If we specify a name, a subdirectory will be * created for the attributes with the directory being the name of the * attribute group. */ static struct attribute_group attr_group = { .attrs = attrs, }; static struct kobject *example_kobj; static int __init example_init(void) { int retval; /* * Create a simple kobject with the name of "kobject_example", * located under /sys/kernel/ * * As this is a simple directory, no uevent will be sent to * userspace. That is why this function should not be used for * any type of dynamic kobjects, where the name and number are * not known ahead of time. */ example_kobj = kobject_create_and_add("kobject_example", kernel_kobj); if (!example_kobj) return -ENOMEM; /* Create the files associated with this kobject */ retval = sysfs_create_group(example_kobj, &attr_group); if (retval) kobject_put(example_kobj); return retval; } static void __exit example_exit(void) { kobject_put(example_kobj); } module_init(example_init); module_exit(example_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Greg Kroah-Hartman <greg@kroah.com>");
Multirom-mi4i/android_kernel_xiaomi_ferrari
samples/kobject/kobject-example.c
C
gpl-2.0
3,323
/* * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com> * * This file is part of barebox. * See file CREDITS for list of people who contributed to this project. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #include <common.h> #include <malloc.h> #include <errno.h> #include <io.h> #include <gpio.h> #include <init.h> /* * See http://magiclantern.wikia.com/wiki/Register_Map#GPIO_Ports */ #define DIGIC_GPIO_IN_LVL 1 #define DIGIC_GPIO_OUT_LVL 2 #define DIGIC_GPIO_DIR 4 #define DIGIC_GPIO_TRISTATE 8 struct digic_gpio_chip { void __iomem *base; struct gpio_chip gc; }; #define to_digic_gpio_chip(c) container_of(c, struct digic_gpio_chip, gc) static inline uint32_t digic_gpio_readl(struct digic_gpio_chip *chip, uint32_t offset) { return readl(chip->base + 4 * offset); } static inline void digic_gpio_writel(struct digic_gpio_chip *chip, uint32_t value, uint32_t offset) { writel(value, chip->base + 4 * offset); } static int digic_gpio_get_value(struct gpio_chip *gc, unsigned offset) { struct digic_gpio_chip *chip = to_digic_gpio_chip(gc); if (offset >= gc->ngpio) return -EINVAL; return digic_gpio_readl(chip, offset) & DIGIC_GPIO_IN_LVL; } static void digic_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value) { struct digic_gpio_chip *chip = to_digic_gpio_chip(gc); uint32_t t; if (offset >= gc->ngpio) return; t = digic_gpio_readl(chip, offset); /* Port direction (1 = OUT, 0 = IN) */ if (value) t |= DIGIC_GPIO_OUT_LVL; else t &= ~(DIGIC_GPIO_OUT_LVL); digic_gpio_writel(chip, t, offset); } static int digic_gpio_direction_input(struct gpio_chip *gc, unsigned offset) { struct digic_gpio_chip *chip = to_digic_gpio_chip(gc); uint32_t t; if (offset >= gc->ngpio) return -EINVAL; t = digic_gpio_readl(chip, offset); /* Port direction (1 = OUT, 0 = IN) */ t &= ~(DIGIC_GPIO_DIR); digic_gpio_writel(chip, t, offset); return 0; } static int digic_gpio_direction_output(struct gpio_chip *gc, unsigned offset, int value) { struct digic_gpio_chip *chip = to_digic_gpio_chip(gc); uint32_t t; if (offset >= gc->ngpio) return -EINVAL; t = digic_gpio_readl(chip, offset); /* Port direction (1 = OUT, 0 = IN) */ t |= DIGIC_GPIO_DIR; digic_gpio_writel(chip, t, offset); digic_gpio_set_value(gc, offset, value); return 0; } static struct gpio_ops digic_gpio_ops = { .direction_input = digic_gpio_direction_input, .direction_output = digic_gpio_direction_output, .get = digic_gpio_get_value, .set = digic_gpio_set_value, }; static int digic_gpio_probe(struct device_d *dev) { struct digic_gpio_chip *chip; struct resource *res; resource_size_t rsize; int ret = -EINVAL; chip = xzalloc(sizeof(*chip)); res = dev_get_resource(dev, IORESOURCE_MEM, 0); if (!res) goto err; rsize = resource_size(res); chip->gc.ngpio = rsize / sizeof(int32_t); chip->base = dev_request_mem_region(dev, 0); chip->gc.ops = &digic_gpio_ops; chip->gc.base = 0; chip->gc.dev = dev; ret = gpiochip_add(&chip->gc); if (ret) { dev_err(dev, "couldn't add gpiochip, ret = %d\n", ret); goto err; } dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, chip->gc.base); return 0; err: kfree(chip); return ret; } static __maybe_unused struct of_device_id digic_gpio_dt_ids[] = { { .compatible = "canon,digic-gpio", }, { /* sentinel */ } }; static struct driver_d digic_gpio_driver = { .name = "digic-gpio", .probe = digic_gpio_probe, .of_compatible = DRV_OF_COMPAT(digic_gpio_dt_ids), }; static int digic_gpio_init(void) { return platform_driver_register(&digic_gpio_driver); } coredevice_initcall(digic_gpio_init);
SayCV/barebox-at91
drivers/gpio/gpio-digic.c
C
gpl-2.0
4,050
/* Tree-based target query functions relating to optabs Copyright (C) 1987-2016 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ #include "config.h" #include "system.h" #include "coretypes.h" #include "target.h" #include "insn-codes.h" #include "tree.h" #include "optabs-tree.h" #include "stor-layout.h" /* Return the optab used for computing the operation given by the tree code, CODE and the tree EXP. This function is not always usable (for example, it cannot give complete results for multiplication or division) but probably ought to be relied on more widely throughout the expander. */ optab optab_for_tree_code (enum tree_code code, const_tree type, enum optab_subtype subtype) { bool trapv; switch (code) { case BIT_AND_EXPR: return and_optab; case BIT_IOR_EXPR: return ior_optab; case BIT_NOT_EXPR: return one_cmpl_optab; case BIT_XOR_EXPR: return xor_optab; case MULT_HIGHPART_EXPR: return TYPE_UNSIGNED (type) ? umul_highpart_optab : smul_highpart_optab; case TRUNC_MOD_EXPR: case CEIL_MOD_EXPR: case FLOOR_MOD_EXPR: case ROUND_MOD_EXPR: return TYPE_UNSIGNED (type) ? umod_optab : smod_optab; case RDIV_EXPR: case TRUNC_DIV_EXPR: case CEIL_DIV_EXPR: case FLOOR_DIV_EXPR: case ROUND_DIV_EXPR: case EXACT_DIV_EXPR: if (TYPE_SATURATING (type)) return TYPE_UNSIGNED (type) ? usdiv_optab : ssdiv_optab; return TYPE_UNSIGNED (type) ? udiv_optab : sdiv_optab; case LSHIFT_EXPR: if (TREE_CODE (type) == VECTOR_TYPE) { if (subtype == optab_vector) return TYPE_SATURATING (type) ? unknown_optab : vashl_optab; gcc_assert (subtype == optab_scalar); } if (TYPE_SATURATING (type)) return TYPE_UNSIGNED (type) ? usashl_optab : ssashl_optab; return ashl_optab; case RSHIFT_EXPR: if (TREE_CODE (type) == VECTOR_TYPE) { if (subtype == optab_vector) return TYPE_UNSIGNED (type) ? vlshr_optab : vashr_optab; gcc_assert (subtype == optab_scalar); } return TYPE_UNSIGNED (type) ? lshr_optab : ashr_optab; case LROTATE_EXPR: if (TREE_CODE (type) == VECTOR_TYPE) { if (subtype == optab_vector) return vrotl_optab; gcc_assert (subtype == optab_scalar); } return rotl_optab; case RROTATE_EXPR: if (TREE_CODE (type) == VECTOR_TYPE) { if (subtype == optab_vector) return vrotr_optab; gcc_assert (subtype == optab_scalar); } return rotr_optab; case MAX_EXPR: return TYPE_UNSIGNED (type) ? umax_optab : smax_optab; case MIN_EXPR: return TYPE_UNSIGNED (type) ? umin_optab : smin_optab; case REALIGN_LOAD_EXPR: return vec_realign_load_optab; case WIDEN_SUM_EXPR: return TYPE_UNSIGNED (type) ? usum_widen_optab : ssum_widen_optab; case DOT_PROD_EXPR: return TYPE_UNSIGNED (type) ? udot_prod_optab : sdot_prod_optab; case SAD_EXPR: return TYPE_UNSIGNED (type) ? usad_optab : ssad_optab; case WIDEN_MULT_PLUS_EXPR: return (TYPE_UNSIGNED (type) ? (TYPE_SATURATING (type) ? usmadd_widen_optab : umadd_widen_optab) : (TYPE_SATURATING (type) ? ssmadd_widen_optab : smadd_widen_optab)); case WIDEN_MULT_MINUS_EXPR: return (TYPE_UNSIGNED (type) ? (TYPE_SATURATING (type) ? usmsub_widen_optab : umsub_widen_optab) : (TYPE_SATURATING (type) ? ssmsub_widen_optab : smsub_widen_optab)); case FMA_EXPR: return fma_optab; case REDUC_MAX_EXPR: return TYPE_UNSIGNED (type) ? reduc_umax_scal_optab : reduc_smax_scal_optab; case REDUC_MIN_EXPR: return TYPE_UNSIGNED (type) ? reduc_umin_scal_optab : reduc_smin_scal_optab; case REDUC_PLUS_EXPR: return reduc_plus_scal_optab; case VEC_WIDEN_MULT_HI_EXPR: return TYPE_UNSIGNED (type) ? vec_widen_umult_hi_optab : vec_widen_smult_hi_optab; case VEC_WIDEN_MULT_LO_EXPR: return TYPE_UNSIGNED (type) ? vec_widen_umult_lo_optab : vec_widen_smult_lo_optab; case VEC_WIDEN_MULT_EVEN_EXPR: return TYPE_UNSIGNED (type) ? vec_widen_umult_even_optab : vec_widen_smult_even_optab; case VEC_WIDEN_MULT_ODD_EXPR: return TYPE_UNSIGNED (type) ? vec_widen_umult_odd_optab : vec_widen_smult_odd_optab; case VEC_WIDEN_LSHIFT_HI_EXPR: return TYPE_UNSIGNED (type) ? vec_widen_ushiftl_hi_optab : vec_widen_sshiftl_hi_optab; case VEC_WIDEN_LSHIFT_LO_EXPR: return TYPE_UNSIGNED (type) ? vec_widen_ushiftl_lo_optab : vec_widen_sshiftl_lo_optab; case VEC_UNPACK_HI_EXPR: return TYPE_UNSIGNED (type) ? vec_unpacku_hi_optab : vec_unpacks_hi_optab; case VEC_UNPACK_LO_EXPR: return TYPE_UNSIGNED (type) ? vec_unpacku_lo_optab : vec_unpacks_lo_optab; case VEC_UNPACK_FLOAT_HI_EXPR: /* The signedness is determined from input operand. */ return TYPE_UNSIGNED (type) ? vec_unpacku_float_hi_optab : vec_unpacks_float_hi_optab; case VEC_UNPACK_FLOAT_LO_EXPR: /* The signedness is determined from input operand. */ return TYPE_UNSIGNED (type) ? vec_unpacku_float_lo_optab : vec_unpacks_float_lo_optab; case VEC_PACK_TRUNC_EXPR: return vec_pack_trunc_optab; case VEC_PACK_SAT_EXPR: return TYPE_UNSIGNED (type) ? vec_pack_usat_optab : vec_pack_ssat_optab; case VEC_PACK_FIX_TRUNC_EXPR: /* The signedness is determined from output operand. */ return TYPE_UNSIGNED (type) ? vec_pack_ufix_trunc_optab : vec_pack_sfix_trunc_optab; default: break; } trapv = INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_TRAPS (type); switch (code) { case POINTER_PLUS_EXPR: case PLUS_EXPR: if (TYPE_SATURATING (type)) return TYPE_UNSIGNED (type) ? usadd_optab : ssadd_optab; return trapv ? addv_optab : add_optab; case MINUS_EXPR: if (TYPE_SATURATING (type)) return TYPE_UNSIGNED (type) ? ussub_optab : sssub_optab; return trapv ? subv_optab : sub_optab; case MULT_EXPR: if (TYPE_SATURATING (type)) return TYPE_UNSIGNED (type) ? usmul_optab : ssmul_optab; return trapv ? smulv_optab : smul_optab; case NEGATE_EXPR: if (TYPE_SATURATING (type)) return TYPE_UNSIGNED (type) ? usneg_optab : ssneg_optab; return trapv ? negv_optab : neg_optab; case ABS_EXPR: return trapv ? absv_optab : abs_optab; default: return unknown_optab; } } /* Function supportable_convert_operation Check whether an operation represented by the code CODE is a convert operation that is supported by the target platform in vector form (i.e., when operating on arguments of type VECTYPE_IN producing a result of type VECTYPE_OUT). Convert operations we currently support directly are FIX_TRUNC and FLOAT. This function checks if these operations are supported by the target platform either directly (via vector tree-codes), or via target builtins. Output: - CODE1 is code of vector operation to be used when vectorizing the operation, if available. - DECL is decl of target builtin functions to be used when vectorizing the operation, if available. In this case, CODE1 is CALL_EXPR. */ bool supportable_convert_operation (enum tree_code code, tree vectype_out, tree vectype_in, tree *decl, enum tree_code *code1) { machine_mode m1,m2; bool truncp; m1 = TYPE_MODE (vectype_out); m2 = TYPE_MODE (vectype_in); /* First check if we can done conversion directly. */ if ((code == FIX_TRUNC_EXPR && can_fix_p (m1,m2,TYPE_UNSIGNED (vectype_out), &truncp) != CODE_FOR_nothing) || (code == FLOAT_EXPR && can_float_p (m1,m2,TYPE_UNSIGNED (vectype_in)) != CODE_FOR_nothing)) { *code1 = code; return true; } /* Now check for builtin. */ if (targetm.vectorize.builtin_conversion && targetm.vectorize.builtin_conversion (code, vectype_out, vectype_in)) { *code1 = CALL_EXPR; *decl = targetm.vectorize.builtin_conversion (code, vectype_out, vectype_in); return true; } return false; } /* Return TRUE if appropriate vector insn is available for vector comparison expr with vector type VALUE_TYPE and resulting mask with MASK_TYPE. */ bool expand_vec_cmp_expr_p (tree value_type, tree mask_type) { enum insn_code icode = get_vec_cmp_icode (TYPE_MODE (value_type), TYPE_MODE (mask_type), TYPE_UNSIGNED (value_type)); return (icode != CODE_FOR_nothing); } /* Return TRUE iff, appropriate vector insns are available for vector cond expr with vector type VALUE_TYPE and a comparison with operand vector types in CMP_OP_TYPE. */ bool expand_vec_cond_expr_p (tree value_type, tree cmp_op_type) { machine_mode value_mode = TYPE_MODE (value_type); machine_mode cmp_op_mode = TYPE_MODE (cmp_op_type); if (VECTOR_BOOLEAN_TYPE_P (cmp_op_type) && get_vcond_mask_icode (TYPE_MODE (value_type), TYPE_MODE (cmp_op_type)) != CODE_FOR_nothing) return true; if (GET_MODE_SIZE (value_mode) != GET_MODE_SIZE (cmp_op_mode) || GET_MODE_NUNITS (value_mode) != GET_MODE_NUNITS (cmp_op_mode) || get_vcond_icode (TYPE_MODE (value_type), TYPE_MODE (cmp_op_type), TYPE_UNSIGNED (cmp_op_type)) == CODE_FOR_nothing) return false; return true; } /* Use the current target and options to initialize TREE_OPTIMIZATION_OPTABS (OPTNODE). */ void init_tree_optimization_optabs (tree optnode) { /* Quick exit if we have already computed optabs for this target. */ if (TREE_OPTIMIZATION_BASE_OPTABS (optnode) == this_target_optabs) return; /* Forget any previous information and set up for the current target. */ TREE_OPTIMIZATION_BASE_OPTABS (optnode) = this_target_optabs; struct target_optabs *tmp_optabs = (struct target_optabs *) TREE_OPTIMIZATION_OPTABS (optnode); if (tmp_optabs) memset (tmp_optabs, 0, sizeof (struct target_optabs)); else tmp_optabs = ggc_alloc<target_optabs> (); /* Generate a new set of optabs into tmp_optabs. */ init_all_optabs (tmp_optabs); /* If the optabs changed, record it. */ if (memcmp (tmp_optabs, this_target_optabs, sizeof (struct target_optabs))) TREE_OPTIMIZATION_OPTABS (optnode) = tmp_optabs; else { TREE_OPTIMIZATION_OPTABS (optnode) = NULL; ggc_free (tmp_optabs); } }
adrian17/gcc
gcc/optabs-tree.c
C
gpl-2.0
10,985
<?php /** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage * @package Mage_Eav * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Entity attribute backend interface * * Backend is responsible for saving the values of the attribute * and performing pre and post actions * */ interface Mage_Eav_Model_Entity_Attribute_Backend_Interface { public function getTable(); public function isStatic(); public function getType(); public function getEntityIdField(); public function setValueId($valueId); public function getValueId(); public function afterLoad($object); public function beforeSave($object); public function afterSave($object); public function beforeDelete($object); public function afterDelete($object); /** * Get entity value id * * @param Varien_Object $entity */ public function getEntityValueId($entity); /** * Set entity value id * * @param Varien_Object $entity * @param int $valueId */ public function setEntityValueId($entity, $valueId); }
MaxYaroshenko/3rdarea
app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Interface.php
PHP
gpl-2.0
1,903
/** * editor_plugin_src.js * * Copyright 2009, Moxiecode Systems AB * Released under LGPL License. * * License: http://tinymce.moxiecode.com/license * Contributing: http://tinymce.moxiecode.com/contributing */ (function() { tinymce.create('tinymce.plugins.VisualChars', { init : function(ed, url) { var t = this; t.editor = ed; // Register commands ed.addCommand('mceVisualChars', t._toggleVisualChars, t); // Register buttons ed.addButton('visualchars', {title : 'visualchars.desc', cmd : 'mceVisualChars'}); ed.onBeforeGetContent.add(function(ed, o) { if (t.state && o.format != 'raw' && !o.draft) { t.state = true; t._toggleVisualChars(false); } }); }, getInfo : function() { return { longname : 'Visual characters', author : 'Moxiecode Systems AB', authorurl : 'http://tinymce.moxiecode.com', infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/visualchars', version : tinymce.majorVersion + "." + tinymce.minorVersion }; }, // Private methods _toggleVisualChars : function(bookmark) { var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo, div, bm; t.state = !t.state; ed.controlManager.setActive('visualchars', t.state); if (bookmark) bm = s.getBookmark(); if (t.state) { nl = []; tinymce.walk(b, function(n) { if (n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1) nl.push(n); }, 'childNodes'); for (i = 0; i < nl.length; i++) { nv = nl[i].nodeValue; nv = nv.replace(/(\u00a0)/g, '<span data-mce-bogus="1" class="mceItemHidden mceItemNbsp">$1</span>'); div = ed.dom.create('div', null, nv); while (node = div.lastChild) ed.dom.insertAfter(node, nl[i]); ed.dom.remove(nl[i]); } } else { nl = ed.dom.select('span.mceItemNbsp', b); for (i = nl.length - 1; i >= 0; i--) ed.dom.remove(nl[i], 1); } s.moveToBookmark(bm); } }); // Register plugin tinymce.PluginManager.add('visualchars', tinymce.plugins.VisualChars); })();
amirkoklan/hollywood
extension/ezoe/design/standard/javascript/plugins/visualchars/editor_plugin_src.js
JavaScript
gpl-2.0
3,437
/* JCE Editor - 2.4.2 | 28 July 2014 | http://www.joomlacontenteditor.net | Copyright (C) 2006 - 2014 Ryan Demmer. All rights reserved | GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html */ var StyleDialog={settings:{},defaults:{'Fonts':""+"Arial, Helvetica, sans-serif=Arial, Helvetica, sans-serif;"+"Times New Roman, Times, serif=Times New Roman, Times, serif;"+"Courier New, Courier, mono=Courier New, Courier, mono;"+"Times New Roman, Times, serif=Times New Roman, Times, serif;"+"Georgia, Times New Roman, Times, serif=Georgia, Times New Roman, Times, serif;"+"Verdana, Arial, Helvetica, sans-serif=Verdana, Arial, Helvetica, sans-serif;"+"Geneva, Arial, Helvetica, sans-serif=Geneva, Arial, Helvetica, sans-serif",'Sizes':"9;10;12;14;16;18;24;xx-small;x-small;small;medium;large;x-large;xx-large;smaller;larger",'Measurement':"+pixels=px;points=pt;inches=in;centimetres=cm;millimetres=mm;picas=pc;ems=em;exs=ex;%",'SpacingMeasurement':"pixels=px;points=pt;inches=in;centimetres=cm;millimetres=mm;picas=pc;+ems=em;exs=ex;%",'IndentMeasurement':"pixels=px;+points=pt;inches=in;centimetres=cm;millimetres=mm;picas=pc;ems=em;exs=ex;%",'Weight':"normal;bold;bolder;lighter;100;200;300;400;500;600;700;800;900",'TextStyle':"normal;italic;oblique",'Variant':"normal;small-caps",'LineHeight':"normal",'Attachment':"fixed;scroll",'Repeat':"no-repeat;repeat;repeat-x;repeat-y",'PosH':"left;center;right",'PosV':"top;center;bottom",'VAlign':"baseline;sub;super;top;text-top;middle;bottom;text-bottom",'Display':"inline;block;list-item;run-in;compact;marker;table;inline-table;table-row-group;table-header-group;table-footer-group;table-row;table-column-group;table-column;table-cell;table-caption;none",'BorderStyle':"none;solid;dashed;dotted;double;groove;ridge;inset;outset",'BorderWidth':"thin;medium;thick",'ListType':"disc;circle;square;decimal;lower-roman;upper-roman;lower-alpha;upper-alpha;none"},aggregateStyles:function(allStyles){var mergedStyles={};tinymce.each(allStyles,function(style){if(style!==''){var parsedStyles=tinyMCEPopup.editor.dom.parseStyle(style);for(var name in parsedStyles){if(parsedStyles.hasOwnProperty(name)){if(mergedStyles[name]===undefined){mergedStyles[name]=parsedStyles[name];} else if(name==='text-decoration'){if(mergedStyles[name].indexOf(parsedStyles[name])===-1){mergedStyles[name]=mergedStyles[name]+' '+parsedStyles[name];}}}}}});return mergedStyles;},init:function(){var ed=tinyMCEPopup.editor,ce=document.getElementById('container'),h;if(!this.settings.file_browser){$('input.browser').removeClass('browser');} this.existingStyles=this.aggregateStyles(tinyMCEPopup.getWindowArg('styles'));ce.style.cssText=ed.dom.serializeStyle(this.existingStyles);this.applyActionIsInsert=ed.getParam("edit_css_style_insert_span",false);$('#toggle_insert_span').prop('checked',this.applyActionIsInsert);this.fillSelect(0,'text_font','style_font',ed.getParam('theme_advanced_fonts',this.defaults.Fonts),';',true);this.fillSelect(0,'text_size','style_font_size',this.defaults.Sizes,';',true);this.fillSelect(0,'text_size_measurement','style_font_size_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'text_case','style_text_case',"capitalize;uppercase;lowercase",';',true);this.fillSelect(0,'text_weight','style_font_weight',this.defaults.Weight,';',true);this.fillSelect(0,'text_style','style_font_style',this.defaults.TextStyle,';',true);this.fillSelect(0,'text_variant','style_font_variant',this.defaults.Variant,';',true);this.fillSelect(0,'text_lineheight','style_font_line_height',this.defaults.LineHeight,';',true);this.fillSelect(0,'text_lineheight_measurement','style_font_line_height_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'background_attachment','style_background_attachment',this.defaults.Attachment,';',true);this.fillSelect(0,'background_repeat','style_background_repeat',this.defaults.Repeat,';',true);this.fillSelect(0,'background_hpos_measurement','style_background_hpos_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'background_vpos_measurement','style_background_vpos_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'background_hpos','style_background_hpos',this.defaults.PosH,';',true);this.fillSelect(0,'background_vpos','style_background_vpos',this.defaults.PosV,';',true);this.fillSelect(0,'block_wordspacing','style_wordspacing','normal',';',true);this.fillSelect(0,'block_wordspacing_measurement','style_wordspacing_measurement',this.defaults.SpacingMeasurement,';',true);this.fillSelect(0,'block_letterspacing','style_letterspacing','normal',';',true);this.fillSelect(0,'block_letterspacing_measurement','style_letterspacing_measurement',this.defaults.SpacingMeasurement,';',true);this.fillSelect(0,'block_vertical_alignment','style_vertical_alignment',this.defaults.VAlign,';',true);this.fillSelect(0,'block_text_align','style_text_align',"left;right;center;justify",';',true);this.fillSelect(0,'block_whitespace','style_whitespace',"normal;pre;nowrap",';',true);this.fillSelect(0,'block_display','style_display',this.defaults.Display,';',true);this.fillSelect(0,'block_text_indent_measurement','style_text_indent_measurement',this.defaults.IndentMeasurement,';',true);this.fillSelect(0,'box_width_measurement','style_box_width_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'box_height_measurement','style_box_height_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'box_float','style_float','left;right;none',';',true);this.fillSelect(0,'box_clear','style_clear','left;right;both;none',';',true);this.fillSelect(0,'box_padding_left_measurement','style_padding_left_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'box_padding_top_measurement','style_padding_top_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'box_padding_bottom_measurement','style_padding_bottom_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'box_padding_right_measurement','style_padding_right_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'box_margin_left_measurement','style_margin_left_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'box_margin_top_measurement','style_margin_top_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'box_margin_bottom_measurement','style_margin_bottom_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'box_margin_right_measurement','style_margin_right_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'border_style_top','style_border_style_top',this.defaults.BorderStyle,';',true);this.fillSelect(0,'border_style_right','style_border_style_right',this.defaults.BorderStyle,';',true);this.fillSelect(0,'border_style_bottom','style_border_style_bottom',this.defaults.BorderStyle,';',true);this.fillSelect(0,'border_style_left','style_border_style_left',this.defaults.BorderStyle,';',true);this.fillSelect(0,'border_width_top','style_border_width_top',this.defaults.BorderWidth,';',true);this.fillSelect(0,'border_width_right','style_border_width_right',this.defaults.BorderWidth,';',true);this.fillSelect(0,'border_width_bottom','style_border_width_bottom',this.defaults.BorderWidth,';',true);this.fillSelect(0,'border_width_left','style_border_width_left',this.defaults.BorderWidth,';',true);this.fillSelect(0,'border_width_top_measurement','style_border_width_top_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'border_width_right_measurement','style_border_width_right_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'border_width_bottom_measurement','style_border_width_bottom_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'border_width_left_measurement','style_border_width_left_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'list_type','style_list_type',this.defaults.ListType,';',true);this.fillSelect(0,'list_position','style_list_position',"inside;outside",';',true);this.fillSelect(0,'positioning_type','style_positioning_type',"absolute;relative;static",';',true);this.fillSelect(0,'positioning_visibility','style_positioning_visibility',"inherit;visible;hidden",';',true);this.fillSelect(0,'positioning_width_measurement','style_positioning_width_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'positioning_height_measurement','style_positioning_height_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'positioning_overflow','style_positioning_overflow',"visible;hidden;scroll;auto",';',true);this.fillSelect(0,'positioning_placement_top_measurement','style_positioning_placement_top_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'positioning_placement_right_measurement','style_positioning_placement_right_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'positioning_placement_bottom_measurement','style_positioning_placement_bottom_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'positioning_placement_left_measurement','style_positioning_placement_left_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'positioning_clip_top_measurement','style_positioning_clip_top_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'positioning_clip_right_measurement','style_positioning_clip_right_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'positioning_clip_bottom_measurement','style_positioning_clip_bottom_measurement',this.defaults.Measurement,';',true);this.fillSelect(0,'positioning_clip_left_measurement','style_positioning_clip_left_measurement',this.defaults.Measurement,';',true);this.setupFormData();this.showDisabledControls();$.Plugin.init();},setupFormData:function(){var ed=tinyMCEPopup.editor,ce=document.getElementById('container'),f=document.forms[0],s,b,i;selectByValue(f,'text_font',ce.style.fontFamily,true,true);selectByValue(f,'text_size',this.getNum(ce.style.fontSize),true,true);selectByValue(f,'text_size_measurement',this.getMeasurement(ce.style.fontSize));selectByValue(f,'text_weight',ce.style.fontWeight,true,true);selectByValue(f,'text_style',ce.style.fontStyle,true,true);selectByValue(f,'text_lineheight',this.getNum(ce.style.lineHeight),true,true);selectByValue(f,'text_lineheight_measurement',this.getMeasurement(ce.style.lineHeight));selectByValue(f,'text_case',ce.style.textTransform,true,true);selectByValue(f,'text_variant',ce.style.fontVariant,true,true);f.text_color.value=tinyMCEPopup.editor.dom.toHex(ce.style.color);f.text_underline.checked=this.inStr(ce.style.textDecoration,'underline');f.text_overline.checked=this.inStr(ce.style.textDecoration,'overline');f.text_linethrough.checked=this.inStr(ce.style.textDecoration,'line-through');f.text_blink.checked=this.inStr(ce.style.textDecoration,'blink');f.text_none.checked=this.inStr(ce.style.textDecoration,'none');this.updateTextDecorations();f.background_color.value=tinyMCEPopup.editor.dom.toHex(ce.style.backgroundColor);f.background_image.value=ce.style.backgroundImage.replace(new RegExp("url\\('?([^']*)'?\\)",'gi'),function(a,b){return ed.convertURL(b);});selectByValue(f,'background_repeat',ce.style.backgroundRepeat,true,true);selectByValue(f,'background_attachment',ce.style.backgroundAttachment,true,true);selectByValue(f,'background_hpos',this.getNum(this.getVal(ce.style.backgroundPosition,0)),true,true);selectByValue(f,'background_hpos_measurement',this.getMeasurement(this.getVal(ce.style.backgroundPosition,0)));selectByValue(f,'background_vpos',this.getNum(this.getVal(ce.style.backgroundPosition,1)),true,true);selectByValue(f,'background_vpos_measurement',this.getMeasurement(this.getVal(ce.style.backgroundPosition,1)));selectByValue(f,'block_wordspacing',this.getNum(ce.style.wordSpacing),true,true);selectByValue(f,'block_wordspacing_measurement',this.getMeasurement(ce.style.wordSpacing));selectByValue(f,'block_letterspacing',this.getNum(ce.style.letterSpacing),true,true);selectByValue(f,'block_letterspacing_measurement',this.getMeasurement(ce.style.letterSpacing));selectByValue(f,'block_vertical_alignment',ce.style.verticalAlign,true,true);selectByValue(f,'block_text_align',ce.style.textAlign,true,true);f.block_text_indent.value=this.getNum(ce.style.textIndent);selectByValue(f,'block_text_indent_measurement',this.getMeasurement(ce.style.textIndent));selectByValue(f,'block_whitespace',ce.style.whiteSpace,true,true);selectByValue(f,'block_display',ce.style.display,true,true);f.box_width.value=this.getNum(ce.style.width);selectByValue(f,'box_width_measurement',this.getMeasurement(ce.style.width));f.box_height.value=this.getNum(ce.style.height);selectByValue(f,'box_height_measurement',this.getMeasurement(ce.style.height));if(tinymce.isGecko) selectByValue(f,'box_float',ce.style.cssFloat,true,true);else selectByValue(f,'box_float',ce.style.styleFloat,true,true);selectByValue(f,'box_clear',ce.style.clear,true,true);this.setupBox(f,ce,'box_padding','padding','');this.setupBox(f,ce,'box_margin','margin','');this.setupBox(f,ce,'border_style','border','Style');this.setupBox(f,ce,'border_width','border','Width');this.setupBox(f,ce,'border_color','border','Color');f.elements.border_color_top.value=tinyMCEPopup.editor.dom.toHex(f.elements.border_color_top.value);f.elements.border_color_right.value=tinyMCEPopup.editor.dom.toHex(f.elements.border_color_right.value);f.elements.border_color_bottom.value=tinyMCEPopup.editor.dom.toHex(f.elements.border_color_bottom.value);f.elements.border_color_left.value=tinyMCEPopup.editor.dom.toHex(f.elements.border_color_left.value);selectByValue(f,'list_type',ce.style.listStyleType,true,true);selectByValue(f,'list_position',ce.style.listStylePosition,true,true);f.list_bullet_image.value=ce.style.listStyleImage.replace(new RegExp("url\\('?([^']*)'?\\)",'gi'),"$1");selectByValue(f,'positioning_type',ce.style.position,true,true);selectByValue(f,'positioning_visibility',ce.style.visibility,true,true);selectByValue(f,'positioning_overflow',ce.style.overflow,true,true);f.positioning_zindex.value=ce.style.zIndex?ce.style.zIndex:"";f.positioning_width.value=this.getNum(ce.style.width);selectByValue(f,'positioning_width_measurement',this.getMeasurement(ce.style.width));f.positioning_height.value=this.getNum(ce.style.height);selectByValue(f,'positioning_height_measurement',this.getMeasurement(ce.style.height));this.setupBox(f,ce,'positioning_placement','','',['top','right','bottom','left']);s=ce.style.clip.replace(new RegExp("rect\\('?([^']*)'?\\)",'gi'),"$1");s=s.replace(/,/g,' ');if(!this.hasEqualValues([this.getVal(s,0),this.getVal(s,1),this.getVal(s,2),this.getVal(s,3)])){f.positioning_clip_top.value=this.getNum(this.getVal(s,0));selectByValue(f,'positioning_clip_top_measurement',this.getMeasurement(this.getVal(s,0)));f.positioning_clip_right.value=this.getNum(this.getVal(s,1));selectByValue(f,'positioning_clip_right_measurement',this.getMeasurement(this.getVal(s,1)));f.positioning_clip_bottom.value=this.getNum(this.getVal(s,2));selectByValue(f,'positioning_clip_bottom_measurement',this.getMeasurement(this.getVal(s,2)));f.positioning_clip_left.value=this.getNum(this.getVal(s,3));selectByValue(f,'positioning_clip_left_measurement',this.getMeasurement(this.getVal(s,3)));}else{f.positioning_clip_top.value=this.getNum(this.getVal(s,0));selectByValue(f,'positioning_clip_top_measurement',this.getMeasurement(this.getVal(s,0)));f.positioning_clip_right.value=f.positioning_clip_bottom.value=f.positioning_clip_left.value;}},getMeasurement:function(s){return s.replace(/^([0-9.]+)(.*)$/,"$2");},getNum:function(s){if(new RegExp('^(?:[0-9.]+)(?:[a-z%]+)$','gi').test(s)) return s.replace(/[^0-9.]/g,'');return s;},inStr:function(s,n){return new RegExp(n,'gi').test(s);},getVal:function(s,i){var a=s.split(' ');if(a.length>1) return a[i];return"";},setValue:function(f,n,v){if(f.elements[n].type=="text") f.elements[n].value=v;else selectByValue(f,n,v,true,true);},setupBox:function(f,ce,fp,pr,sf,b){if(typeof(b)=="undefined") b=['Top','Right','Bottom','Left'];if(this.isSame(ce,pr,sf,b)){f.elements[fp+"_same"].checked=true;this.setValue(f,fp+"_top",this.getNum(ce.style[pr+b[0]+sf]));f.elements[fp+"_top"].disabled=false;f.elements[fp+"_right"].value="";f.elements[fp+"_right"].disabled=true;f.elements[fp+"_bottom"].value="";f.elements[fp+"_bottom"].disabled=true;f.elements[fp+"_left"].value="";f.elements[fp+"_left"].disabled=true;if(f.elements[fp+"_top_measurement"]){selectByValue(f,fp+'_top_measurement',this.getMeasurement(ce.style[pr+b[0]+sf]));f.elements[fp+"_left_measurement"].disabled=true;f.elements[fp+"_bottom_measurement"].disabled=true;f.elements[fp+"_right_measurement"].disabled=true;}}else{f.elements[fp+"_same"].checked=false;this.setValue(f,fp+"_top",this.getNum(ce.style[pr+b[0]+sf]));f.elements[fp+"_top"].disabled=false;this.setValue(f,fp+"_right",this.getNum(ce.style[pr+b[1]+sf]));f.elements[fp+"_right"].disabled=false;this.setValue(f,fp+"_bottom",this.getNum(ce.style[pr+b[2]+sf]));f.elements[fp+"_bottom"].disabled=false;this.setValue(f,fp+"_left",this.getNum(ce.style[pr+b[3]+sf]));f.elements[fp+"_left"].disabled=false;if(f.elements[fp+"_top_measurement"]){selectByValue(f,fp+'_top_measurement',this.getMeasurement(ce.style[pr+b[0]+sf]));selectByValue(f,fp+'_right_measurement',this.getMeasurement(ce.style[pr+b[1]+sf]));selectByValue(f,fp+'_bottom_measurement',this.getMeasurement(ce.style[pr+b[2]+sf]));selectByValue(f,fp+'_left_measurement',this.getMeasurement(ce.style[pr+b[3]+sf]));f.elements[fp+"_left_measurement"].disabled=false;f.elements[fp+"_bottom_measurement"].disabled=false;f.elements[fp+"_right_measurement"].disabled=false;}}},isSame:function(e,pr,sf,b){var a=[],i,x;if(typeof(b)=="undefined") b=['Top','Right','Bottom','Left'];if(typeof(sf)=="undefined"||sf==null) sf="";a[0]=e.style[pr+b[0]+sf];a[1]=e.style[pr+b[1]+sf];a[2]=e.style[pr+b[2]+sf];a[3]=e.style[pr+b[3]+sf];for(i=0;i<a.length;i++){if(a[i]==null) return false;for(x=0;x<a.length;x++){if(a[x]!=a[i]) return false;}} return true;},hasEqualValues:function(a){var i,x;for(i=0;i<a.length;i++){if(a[i]==null) return false;for(x=0;x<a.length;x++){if(a[x]!=a[i]) return false;}} return true;},toggleApplyAction:function(){this.applyActionIsInsert=!this.applyActionIsInsert;},applyAction:function(){var ce=document.getElementById('container'),ed=tinyMCEPopup.editor;this.generateCSS();tinyMCEPopup.restoreSelection();ed.dom.setAttrib(ed.selection.getNode(),'style',tinyMCEPopup.editor.dom.serializeStyle(tinyMCEPopup.editor.dom.parseStyle(ce.style.cssText)));var newStyles=tinyMCEPopup.editor.dom.parseStyle(ce.style.cssText);if(this.applyActionIsInsert){ed.formatter.register('plugin_style',{inline:'span',styles:this.existingStyles});ed.formatter.remove('plugin_style');ed.formatter.register('plugin_style',{inline:'span',styles:newStyles});ed.formatter.apply('plugin_style');}else{var nodes;if(tinyMCEPopup.getWindowArg('applyStyleToBlocks')){nodes=ed.selection.getSelectedBlocks();} else{nodes=ed.selection.getNode();} ed.dom.setAttrib(nodes,'style',tinyMCEPopup.editor.dom.serializeStyle(newStyles));}},updateAction:function(){this.applyAction();tinyMCEPopup.close();},generateCSS:function(){var ce=document.getElementById('container'),f=document.forms[0],num=new RegExp('[0-9]+','g'),s,t;ce.style.cssText="";ce.style.fontFamily=f.text_font.value;ce.style.fontSize=f.text_size.value+(this.isNum(f.text_size.value)?(f.text_size_measurement.value||'px'):"");ce.style.fontStyle=f.text_style.value;ce.style.lineHeight=f.text_lineheight.value+(this.isNum(f.text_lineheight.value)?f.text_lineheight_measurement.value:"");ce.style.textTransform=f.text_case.value;ce.style.fontWeight=f.text_weight.value;ce.style.fontVariant=f.text_variant.value;ce.style.color=f.text_color.value;s="";s+=f.text_underline.checked?" underline":"";s+=f.text_overline.checked?" overline":"";s+=f.text_linethrough.checked?" line-through":"";s+=f.text_blink.checked?" blink":"";s=s.length>0?s.substring(1):s;if(f.text_none.checked) s="none";ce.style.textDecoration=s;ce.style.backgroundColor=f.background_color.value;ce.style.backgroundImage=f.background_image.value!=""?"url("+f.background_image.value+")":"";ce.style.backgroundRepeat=f.background_repeat.value;ce.style.backgroundAttachment=f.background_attachment.value;if(f.background_hpos.value!=""){s="";s+=f.background_hpos.value+(this.isNum(f.background_hpos.value)?f.background_hpos_measurement.value:"")+" ";s+=f.background_vpos.value+(this.isNum(f.background_vpos.value)?f.background_vpos_measurement.value:"");ce.style.backgroundPosition=s;} ce.style.wordSpacing=f.block_wordspacing.value+(this.isNum(f.block_wordspacing.value)?f.block_wordspacing_measurement.value:"");ce.style.letterSpacing=f.block_letterspacing.value+(this.isNum(f.block_letterspacing.value)?f.block_letterspacing_measurement.value:"");ce.style.verticalAlign=f.block_vertical_alignment.value;ce.style.textAlign=f.block_text_align.value;ce.style.textIndent=f.block_text_indent.value+(this.isNum(f.block_text_indent.value)?f.block_text_indent_measurement.value:"");ce.style.whiteSpace=f.block_whitespace.value;ce.style.display=f.block_display.value;ce.style.width=f.box_width.value+(this.isNum(f.box_width.value)?f.box_width_measurement.value:"");ce.style.height=f.box_height.value+(this.isNum(f.box_height.value)?f.box_height_measurement.value:"");if(tinymce.isIE){ce.style.styleFloat=f.box_float.value;}else{ce.style.cssFloat=f.box_float.value;} ce.style.clear=f.box_clear.value;if(!f.box_padding_same.checked){ce.style.paddingTop=f.box_padding_top.value+(this.isNum(f.box_padding_top.value)?f.box_padding_top_measurement.value:"");ce.style.paddingRight=f.box_padding_right.value+(this.isNum(f.box_padding_right.value)?f.box_padding_right_measurement.value:"");ce.style.paddingBottom=f.box_padding_bottom.value+(this.isNum(f.box_padding_bottom.value)?f.box_padding_bottom_measurement.value:"");ce.style.paddingLeft=f.box_padding_left.value+(this.isNum(f.box_padding_left.value)?f.box_padding_left_measurement.value:"");}else ce.style.padding=f.box_padding_top.value+(this.isNum(f.box_padding_top.value)?f.box_padding_top_measurement.value:"");if(!f.box_margin_same.checked){ce.style.marginTop=f.box_margin_top.value+(this.isNum(f.box_margin_top.value)?f.box_margin_top_measurement.value:"");ce.style.marginRight=f.box_margin_right.value+(this.isNum(f.box_margin_right.value)?f.box_margin_right_measurement.value:"");ce.style.marginBottom=f.box_margin_bottom.value+(this.isNum(f.box_margin_bottom.value)?f.box_margin_bottom_measurement.value:"");ce.style.marginLeft=f.box_margin_left.value+(this.isNum(f.box_margin_left.value)?f.box_margin_left_measurement.value:"");}else ce.style.margin=f.box_margin_top.value+(this.isNum(f.box_margin_top.value)?f.box_margin_top_measurement.value:"");if(!f.border_style_same.checked){ce.style.borderTopStyle=f.border_style_top.value;ce.style.borderRightStyle=f.border_style_right.value;ce.style.borderBottomStyle=f.border_style_bottom.value;ce.style.borderLeftStyle=f.border_style_left.value;}else ce.style.borderStyle=f.border_style_top.value;if(!f.border_width_same.checked){ce.style.borderTopWidth=f.border_width_top.value+(this.isNum(f.border_width_top.value)?f.border_width_top_measurement.value:"");ce.style.borderRightWidth=f.border_width_right.value+(this.isNum(f.border_width_right.value)?f.border_width_right_measurement.value:"");ce.style.borderBottomWidth=f.border_width_bottom.value+(this.isNum(f.border_width_bottom.value)?f.border_width_bottom_measurement.value:"");ce.style.borderLeftWidth=f.border_width_left.value+(this.isNum(f.border_width_left.value)?f.border_width_left_measurement.value:"");}else ce.style.borderWidth=f.border_width_top.value+(this.isNum(f.border_width_top.value)?f.border_width_top_measurement.value:"");if(!f.border_color_same.checked){ce.style.borderTopColor=f.border_color_top.value;ce.style.borderRightColor=f.border_color_right.value;ce.style.borderBottomColor=f.border_color_bottom.value;ce.style.borderLeftColor=f.border_color_left.value;}else ce.style.borderColor=f.border_color_top.value;ce.style.listStyleType=f.list_type.value;ce.style.listStylePosition=f.list_position.value;ce.style.listStyleImage=f.list_bullet_image.value!=""?"url("+f.list_bullet_image.value+")":"";ce.style.position=f.positioning_type.value;ce.style.visibility=f.positioning_visibility.value;if(ce.style.width=="") ce.style.width=f.positioning_width.value+(this.isNum(f.positioning_width.value)?f.positioning_width_measurement.value:"");if(ce.style.height=="") ce.style.height=f.positioning_height.value+(this.isNum(f.positioning_height.value)?f.positioning_height_measurement.value:"");ce.style.zIndex=f.positioning_zindex.value;ce.style.overflow=f.positioning_overflow.value;if(!f.positioning_placement_same.checked){ce.style.top=f.positioning_placement_top.value+(this.isNum(f.positioning_placement_top.value)?f.positioning_placement_top_measurement.value:"");ce.style.right=f.positioning_placement_right.value+(this.isNum(f.positioning_placement_right.value)?f.positioning_placement_right_measurement.value:"");ce.style.bottom=f.positioning_placement_bottom.value+(this.isNum(f.positioning_placement_bottom.value)?f.positioning_placement_bottom_measurement.value:"");ce.style.left=f.positioning_placement_left.value+(this.isNum(f.positioning_placement_left.value)?f.positioning_placement_left_measurement.value:"");}else{s=f.positioning_placement_top.value+(this.isNum(f.positioning_placement_top.value)?f.positioning_placement_top_measurement.value:"");ce.style.top=s;ce.style.right=s;ce.style.bottom=s;ce.style.left=s;} if(!f.positioning_clip_same.checked){s="rect(";s+=(this.isNum(f.positioning_clip_top.value)?f.positioning_clip_top.value+f.positioning_clip_top_measurement.value:"auto")+" ";s+=(this.isNum(f.positioning_clip_right.value)?f.positioning_clip_right.value+f.positioning_clip_right_measurement.value:"auto")+" ";s+=(this.isNum(f.positioning_clip_bottom.value)?f.positioning_clip_bottom.value+f.positioning_clip_bottom_measurement.value:"auto")+" ";s+=(this.isNum(f.positioning_clip_left.value)?f.positioning_clip_left.value+f.positioning_clip_left_measurement.value:"auto");s+=")";if(s!="rect(auto auto auto auto)") ce.style.clip=s;}else{s="rect(";t=this.isNum(f.positioning_clip_top.value)?f.positioning_clip_top.value+f.positioning_clip_top_measurement.value:"auto";s+=t+" ";s+=t+" ";s+=t+" ";s+=t+")";if(s!="rect(auto auto auto auto)") ce.style.clip=s;} ce.style.cssText=ce.style.cssText;},isNum:function(s){return new RegExp('[0-9]+','g').test(s);},showDisabledControls:function(){var f=document.forms,i,a;for(i=0;i<f.length;i++){for(a=0;a<f[i].elements.length;a++){if(f[i].elements[a].disabled) tinyMCEPopup.editor.dom.addClass(f[i].elements[a],"disabled");else tinyMCEPopup.editor.dom.removeClass(f[i].elements[a],"disabled");}}},fillSelect:function(f,s,param,dval,sep,em){var i,ar,p,se;f=document.forms[f];sep=typeof(sep)=="undefined"?";":sep;if(em) addSelectValue(f,s,"","");ar=tinyMCEPopup.getParam(param,dval).split(sep);for(i=0;i<ar.length;i++){se=false;if(ar[i].charAt(0)=='+'){ar[i]=ar[i].substring(1);se=true;} p=ar[i].split('=');if(p.length>1){addSelectValue(f,s,p[0],p[1]);if(se) selectByValue(f,s,p[1]);}else{addSelectValue(f,s,p[0],p[0]);if(se) selectByValue(f,s,p[0]);}}},toggleSame:function(ce,pre){var s=ce.checked;$('#'+pre+'_right, #'+pre+'_bottom, #'+pre+'_left').attr('disabled',s).toggleClass('disabled',s).next('span.pickcolor_icon, span.browser_icon, span.select-edit').toggleClass('disabled',s);$('#'+pre+'_right_measurement, #'+pre+'_bottom_measurement, #'+pre+'_left_measurement').attr('disabled',s).toggleClass('disabled',s);},synch:function(fr,to){var f=document.forms[0];f.elements[to].value=f.elements[fr].value;if(f.elements[fr+"_measurement"]) selectByValue(f,to+"_measurement",f.elements[fr+"_measurement"].value);},updateTextDecorations:function(){var noneChecked=$("#text_none").is(':checked');$("#text_underline, #text_overline, #text_linethrough, #text_blink").each(function(){$(this).prop('disabled',noneChecked);if(noneChecked){$(this).prop('checked',false);}});}};tinyMCEPopup.onInit.add(StyleDialog.init,StyleDialog);
unrealprojects/moto
components/com_jce/editor/tiny_mce/plugins/style/js/style.js
JavaScript
gpl-2.0
28,140
<?php /** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage * @package Mage_CatalogInventory * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * CatalogInventory Stock source model * * @category Mage * @package Mage_CatalogInventory * @author Magento Core Team <core@magentocommerce.com> */ class Mage_CatalogInventory_Model_Source_Stock { /** * Retrieve option array * * @return array */ public function toOptionArray() { return array( array( 'value' => Mage_CatalogInventory_Model_Stock::STOCK_IN_STOCK, 'label' => Mage::helper('cataloginventory')->__('In Stock') ), array( 'value' => Mage_CatalogInventory_Model_Stock::STOCK_OUT_OF_STOCK, 'label' => Mage::helper('cataloginventory')->__('Out of Stock') ), ); } }
MaxYaroshenko/3rdarea
app/code/core/Mage/CatalogInventory/Model/Source/Stock.php
PHP
gpl-2.0
1,730
/* * Intel & MS High Precision Event Timer Implementation. * * Copyright (C) 2003 Intel Corporation * Venki Pallipadi * (c) Copyright 2004 Hewlett-Packard Development Company, L.P. * Bob Picco <robert.picco@hp.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/config.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/miscdevice.h> #include <linux/major.h> #include <linux/ioport.h> #include <linux/fcntl.h> #include <linux/init.h> #include <linux/poll.h> #include <linux/proc_fs.h> #include <linux/spinlock.h> #include <linux/sysctl.h> #include <linux/wait.h> #include <linux/bcd.h> #include <linux/seq_file.h> #include <linux/bitops.h> #include <asm/current.h> #include <asm/uaccess.h> #include <asm/system.h> #include <asm/io.h> #include <asm/irq.h> #include <asm/div64.h> #include <linux/acpi.h> #include <acpi/acpi_bus.h> #include <linux/hpet.h> /* * The High Precision Event Timer driver. * This driver is closely modelled after the rtc.c driver. * http://www.intel.com/labs/platcomp/hpet/hpetspec.htm */ #define HPET_USER_FREQ (64) #define HPET_DRIFT (500) static u32 hpet_ntimer, hpet_nhpet, hpet_max_freq = HPET_USER_FREQ; /* A lock for concurrent access by app and isr hpet activity. */ static DEFINE_SPINLOCK(hpet_lock); /* A lock for concurrent intermodule access to hpet and isr hpet activity. */ static DEFINE_SPINLOCK(hpet_task_lock); #define HPET_DEV_NAME (7) struct hpet_dev { struct hpets *hd_hpets; struct hpet __iomem *hd_hpet; struct hpet_timer __iomem *hd_timer; unsigned long hd_ireqfreq; unsigned long hd_irqdata; wait_queue_head_t hd_waitqueue; struct fasync_struct *hd_async_queue; struct hpet_task *hd_task; unsigned int hd_flags; unsigned int hd_irq; unsigned int hd_hdwirq; char hd_name[HPET_DEV_NAME]; }; struct hpets { struct hpets *hp_next; struct hpet __iomem *hp_hpet; unsigned long hp_hpet_phys; struct time_interpolator *hp_interpolator; unsigned long hp_period; unsigned long hp_delta; unsigned int hp_ntimer; unsigned int hp_which; struct hpet_dev hp_dev[1]; }; static struct hpets *hpets; #define HPET_OPEN 0x0001 #define HPET_IE 0x0002 /* interrupt enabled */ #define HPET_PERIODIC 0x0004 #if BITS_PER_LONG == 64 #define write_counter(V, MC) writeq(V, MC) #define read_counter(MC) readq(MC) #else #define write_counter(V, MC) writel(V, MC) #define read_counter(MC) readl(MC) #endif #ifndef readq static unsigned long long __inline readq(void __iomem *addr) { return readl(addr) | (((unsigned long long)readl(addr + 4)) << 32LL); } #endif #ifndef writeq static void __inline writeq(unsigned long long v, void __iomem *addr) { writel(v & 0xffffffff, addr); writel(v >> 32, addr + 4); } #endif static irqreturn_t hpet_interrupt(int irq, void *data, struct pt_regs *regs) { struct hpet_dev *devp; unsigned long isr; devp = data; spin_lock(&hpet_lock); devp->hd_irqdata++; /* * For non-periodic timers, increment the accumulator. * This has the effect of treating non-periodic like periodic. */ if ((devp->hd_flags & (HPET_IE | HPET_PERIODIC)) == HPET_IE) { unsigned long m, t; t = devp->hd_ireqfreq; m = read_counter(&devp->hd_hpet->hpet_mc); write_counter(t + m + devp->hd_hpets->hp_delta, &devp->hd_timer->hpet_compare); } isr = (1 << (devp - devp->hd_hpets->hp_dev)); writeq(isr, &devp->hd_hpet->hpet_isr); spin_unlock(&hpet_lock); spin_lock(&hpet_task_lock); if (devp->hd_task) devp->hd_task->ht_func(devp->hd_task->ht_data); spin_unlock(&hpet_task_lock); wake_up_interruptible(&devp->hd_waitqueue); kill_fasync(&devp->hd_async_queue, SIGIO, POLL_IN); return IRQ_HANDLED; } static int hpet_open(struct inode *inode, struct file *file) { struct hpet_dev *devp; struct hpets *hpetp; int i; if (file->f_mode & FMODE_WRITE) return -EINVAL; spin_lock_irq(&hpet_lock); for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next) for (i = 0; i < hpetp->hp_ntimer; i++) if (hpetp->hp_dev[i].hd_flags & HPET_OPEN || hpetp->hp_dev[i].hd_task) continue; else { devp = &hpetp->hp_dev[i]; break; } if (!devp) { spin_unlock_irq(&hpet_lock); return -EBUSY; } file->private_data = devp; devp->hd_irqdata = 0; devp->hd_flags |= HPET_OPEN; spin_unlock_irq(&hpet_lock); return 0; } static ssize_t hpet_read(struct file *file, char __user *buf, size_t count, loff_t * ppos) { DECLARE_WAITQUEUE(wait, current); unsigned long data; ssize_t retval; struct hpet_dev *devp; devp = file->private_data; if (!devp->hd_ireqfreq) return -EIO; if (count < sizeof(unsigned long)) return -EINVAL; add_wait_queue(&devp->hd_waitqueue, &wait); for ( ; ; ) { set_current_state(TASK_INTERRUPTIBLE); spin_lock_irq(&hpet_lock); data = devp->hd_irqdata; devp->hd_irqdata = 0; spin_unlock_irq(&hpet_lock); if (data) break; else if (file->f_flags & O_NONBLOCK) { retval = -EAGAIN; goto out; } else if (signal_pending(current)) { retval = -ERESTARTSYS; goto out; } schedule(); } retval = put_user(data, (unsigned long __user *)buf); if (!retval) retval = sizeof(unsigned long); out: __set_current_state(TASK_RUNNING); remove_wait_queue(&devp->hd_waitqueue, &wait); return retval; } static unsigned int hpet_poll(struct file *file, poll_table * wait) { unsigned long v; struct hpet_dev *devp; devp = file->private_data; if (!devp->hd_ireqfreq) return 0; poll_wait(file, &devp->hd_waitqueue, wait); spin_lock_irq(&hpet_lock); v = devp->hd_irqdata; spin_unlock_irq(&hpet_lock); if (v != 0) return POLLIN | POLLRDNORM; return 0; } static int hpet_mmap(struct file *file, struct vm_area_struct *vma) { #ifdef CONFIG_HPET_MMAP struct hpet_dev *devp; unsigned long addr; if (((vma->vm_end - vma->vm_start) != PAGE_SIZE) || vma->vm_pgoff) return -EINVAL; devp = file->private_data; addr = devp->hd_hpets->hp_hpet_phys; if (addr & (PAGE_SIZE - 1)) return -ENOSYS; vma->vm_flags |= VM_IO; vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); addr = __pa(addr); if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT, PAGE_SIZE, vma->vm_page_prot)) { printk(KERN_ERR "remap_pfn_range failed in hpet.c\n"); return -EAGAIN; } return 0; #else return -ENOSYS; #endif } static int hpet_fasync(int fd, struct file *file, int on) { struct hpet_dev *devp; devp = file->private_data; if (fasync_helper(fd, file, on, &devp->hd_async_queue) >= 0) return 0; else return -EIO; } static int hpet_release(struct inode *inode, struct file *file) { struct hpet_dev *devp; struct hpet_timer __iomem *timer; int irq = 0; devp = file->private_data; timer = devp->hd_timer; spin_lock_irq(&hpet_lock); writeq((readq(&timer->hpet_config) & ~Tn_INT_ENB_CNF_MASK), &timer->hpet_config); irq = devp->hd_irq; devp->hd_irq = 0; devp->hd_ireqfreq = 0; if (devp->hd_flags & HPET_PERIODIC && readq(&timer->hpet_config) & Tn_TYPE_CNF_MASK) { unsigned long v; v = readq(&timer->hpet_config); v ^= Tn_TYPE_CNF_MASK; writeq(v, &timer->hpet_config); } devp->hd_flags &= ~(HPET_OPEN | HPET_IE | HPET_PERIODIC); spin_unlock_irq(&hpet_lock); if (irq) free_irq(irq, devp); if (file->f_flags & FASYNC) hpet_fasync(-1, file, 0); file->private_data = NULL; return 0; } static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int); static int hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { struct hpet_dev *devp; devp = file->private_data; return hpet_ioctl_common(devp, cmd, arg, 0); } static int hpet_ioctl_ieon(struct hpet_dev *devp) { struct hpet_timer __iomem *timer; struct hpet __iomem *hpet; struct hpets *hpetp; int irq; unsigned long g, v, t, m; unsigned long flags, isr; timer = devp->hd_timer; hpet = devp->hd_hpet; hpetp = devp->hd_hpets; v = readq(&timer->hpet_config); spin_lock_irq(&hpet_lock); if (devp->hd_flags & HPET_IE) { spin_unlock_irq(&hpet_lock); return -EBUSY; } devp->hd_flags |= HPET_IE; spin_unlock_irq(&hpet_lock); t = readq(&timer->hpet_config); irq = devp->hd_hdwirq; if (irq) { sprintf(devp->hd_name, "hpet%d", (int)(devp - hpetp->hp_dev)); if (request_irq (irq, hpet_interrupt, SA_INTERRUPT, devp->hd_name, (void *)devp)) { printk(KERN_ERR "hpet: IRQ %d is not free\n", irq); irq = 0; } } if (irq == 0) { spin_lock_irq(&hpet_lock); devp->hd_flags ^= HPET_IE; spin_unlock_irq(&hpet_lock); return -EIO; } devp->hd_irq = irq; t = devp->hd_ireqfreq; v = readq(&timer->hpet_config); g = v | Tn_INT_ENB_CNF_MASK; if (devp->hd_flags & HPET_PERIODIC) { write_counter(t, &timer->hpet_compare); g |= Tn_TYPE_CNF_MASK; v |= Tn_TYPE_CNF_MASK; writeq(v, &timer->hpet_config); v |= Tn_VAL_SET_CNF_MASK; writeq(v, &timer->hpet_config); local_irq_save(flags); m = read_counter(&hpet->hpet_mc); write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare); } else { local_irq_save(flags); m = read_counter(&hpet->hpet_mc); write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare); } isr = (1 << (devp - hpets->hp_dev)); writeq(isr, &hpet->hpet_isr); writeq(g, &timer->hpet_config); local_irq_restore(flags); return 0; } static inline unsigned long hpet_time_div(unsigned long dis) { unsigned long long m = 1000000000000000ULL; do_div(m, dis); return (unsigned long)m; } static int hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel) { struct hpet_timer __iomem *timer; struct hpet __iomem *hpet; struct hpets *hpetp; int err; unsigned long v; switch (cmd) { case HPET_IE_OFF: case HPET_INFO: case HPET_EPI: case HPET_DPI: case HPET_IRQFREQ: timer = devp->hd_timer; hpet = devp->hd_hpet; hpetp = devp->hd_hpets; break; case HPET_IE_ON: return hpet_ioctl_ieon(devp); default: return -EINVAL; } err = 0; switch (cmd) { case HPET_IE_OFF: if ((devp->hd_flags & HPET_IE) == 0) break; v = readq(&timer->hpet_config); v &= ~Tn_INT_ENB_CNF_MASK; writeq(v, &timer->hpet_config); if (devp->hd_irq) { free_irq(devp->hd_irq, devp); devp->hd_irq = 0; } devp->hd_flags ^= HPET_IE; break; case HPET_INFO: { struct hpet_info info; info.hi_ireqfreq = hpet_time_div(hpetp->hp_period * devp->hd_ireqfreq); info.hi_flags = readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK; info.hi_hpet = devp->hd_hpets->hp_which; info.hi_timer = devp - devp->hd_hpets->hp_dev; if (copy_to_user((void __user *)arg, &info, sizeof(info))) err = -EFAULT; break; } case HPET_EPI: v = readq(&timer->hpet_config); if ((v & Tn_PER_INT_CAP_MASK) == 0) { err = -ENXIO; break; } devp->hd_flags |= HPET_PERIODIC; break; case HPET_DPI: v = readq(&timer->hpet_config); if ((v & Tn_PER_INT_CAP_MASK) == 0) { err = -ENXIO; break; } if (devp->hd_flags & HPET_PERIODIC && readq(&timer->hpet_config) & Tn_TYPE_CNF_MASK) { v = readq(&timer->hpet_config); v ^= Tn_TYPE_CNF_MASK; writeq(v, &timer->hpet_config); } devp->hd_flags &= ~HPET_PERIODIC; break; case HPET_IRQFREQ: if (!kernel && (arg > hpet_max_freq) && !capable(CAP_SYS_RESOURCE)) { err = -EACCES; break; } if (arg & (arg - 1)) { err = -EINVAL; break; } devp->hd_ireqfreq = hpet_time_div(hpetp->hp_period * arg); } return err; } static struct file_operations hpet_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .read = hpet_read, .poll = hpet_poll, .ioctl = hpet_ioctl, .open = hpet_open, .release = hpet_release, .fasync = hpet_fasync, .mmap = hpet_mmap, }; EXPORT_SYMBOL(hpet_alloc); EXPORT_SYMBOL(hpet_register); EXPORT_SYMBOL(hpet_unregister); EXPORT_SYMBOL(hpet_control); int hpet_register(struct hpet_task *tp, int periodic) { unsigned int i; u64 mask; struct hpet_timer __iomem *timer; struct hpet_dev *devp; struct hpets *hpetp; switch (periodic) { case 1: mask = Tn_PER_INT_CAP_MASK; break; case 0: mask = 0; break; default: return -EINVAL; } spin_lock_irq(&hpet_task_lock); spin_lock(&hpet_lock); for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next) for (timer = hpetp->hp_hpet->hpet_timers, i = 0; i < hpetp->hp_ntimer; i++, timer++) { if ((readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK) != mask) continue; devp = &hpetp->hp_dev[i]; if (devp->hd_flags & HPET_OPEN || devp->hd_task) { devp = NULL; continue; } tp->ht_opaque = devp; devp->hd_task = tp; break; } spin_unlock(&hpet_lock); spin_unlock_irq(&hpet_task_lock); if (tp->ht_opaque) return 0; else return -EBUSY; } static inline int hpet_tpcheck(struct hpet_task *tp) { struct hpet_dev *devp; struct hpets *hpetp; devp = tp->ht_opaque; if (!devp) return -ENXIO; for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next) if (devp >= hpetp->hp_dev && devp < (hpetp->hp_dev + hpetp->hp_ntimer) && devp->hd_hpet == hpetp->hp_hpet) return 0; return -ENXIO; } int hpet_unregister(struct hpet_task *tp) { struct hpet_dev *devp; struct hpet_timer __iomem *timer; int err; if ((err = hpet_tpcheck(tp))) return err; spin_lock_irq(&hpet_task_lock); spin_lock(&hpet_lock); devp = tp->ht_opaque; if (devp->hd_task != tp) { spin_unlock(&hpet_lock); spin_unlock_irq(&hpet_task_lock); return -ENXIO; } timer = devp->hd_timer; writeq((readq(&timer->hpet_config) & ~Tn_INT_ENB_CNF_MASK), &timer->hpet_config); devp->hd_flags &= ~(HPET_IE | HPET_PERIODIC); devp->hd_task = NULL; spin_unlock(&hpet_lock); spin_unlock_irq(&hpet_task_lock); return 0; } int hpet_control(struct hpet_task *tp, unsigned int cmd, unsigned long arg) { struct hpet_dev *devp; int err; if ((err = hpet_tpcheck(tp))) return err; spin_lock_irq(&hpet_lock); devp = tp->ht_opaque; if (devp->hd_task != tp) { spin_unlock_irq(&hpet_lock); return -ENXIO; } spin_unlock_irq(&hpet_lock); return hpet_ioctl_common(devp, cmd, arg, 1); } static ctl_table hpet_table[] = { { .ctl_name = 1, .procname = "max-user-freq", .data = &hpet_max_freq, .maxlen = sizeof(int), .mode = 0644, .proc_handler = &proc_dointvec, }, {.ctl_name = 0} }; static ctl_table hpet_root[] = { { .ctl_name = 1, .procname = "hpet", .maxlen = 0, .mode = 0555, .child = hpet_table, }, {.ctl_name = 0} }; static ctl_table dev_root[] = { { .ctl_name = CTL_DEV, .procname = "dev", .maxlen = 0, .mode = 0555, .child = hpet_root, }, {.ctl_name = 0} }; static struct ctl_table_header *sysctl_header; static void hpet_register_interpolator(struct hpets *hpetp) { #ifdef CONFIG_TIME_INTERPOLATION struct time_interpolator *ti; ti = kmalloc(sizeof(*ti), GFP_KERNEL); if (!ti) return; memset(ti, 0, sizeof(*ti)); ti->source = TIME_SOURCE_MMIO64; ti->shift = 10; ti->addr = &hpetp->hp_hpet->hpet_mc; ti->frequency = hpet_time_div(hpets->hp_period); ti->drift = ti->frequency * HPET_DRIFT / 1000000; ti->mask = -1; hpetp->hp_interpolator = ti; register_time_interpolator(ti); #endif } /* * Adjustment for when arming the timer with * initial conditions. That is, main counter * ticks expired before interrupts are enabled. */ #define TICK_CALIBRATE (1000UL) static unsigned long hpet_calibrate(struct hpets *hpetp) { struct hpet_timer __iomem *timer = NULL; unsigned long t, m, count, i, flags, start; struct hpet_dev *devp; int j; struct hpet __iomem *hpet; for (j = 0, devp = hpetp->hp_dev; j < hpetp->hp_ntimer; j++, devp++) if ((devp->hd_flags & HPET_OPEN) == 0) { timer = devp->hd_timer; break; } if (!timer) return 0; hpet = hpets->hp_hpet; t = read_counter(&timer->hpet_compare); i = 0; count = hpet_time_div(hpetp->hp_period * TICK_CALIBRATE); local_irq_save(flags); start = read_counter(&hpet->hpet_mc); do { m = read_counter(&hpet->hpet_mc); write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare); } while (i++, (m - start) < count); local_irq_restore(flags); return (m - start) / i; } int hpet_alloc(struct hpet_data *hdp) { u64 cap, mcfg; struct hpet_dev *devp; u32 i, ntimer; struct hpets *hpetp; size_t siz; struct hpet __iomem *hpet; static struct hpets *last = (struct hpets *)0; unsigned long ns; /* * hpet_alloc can be called by platform dependent code. * if platform dependent code has allocated the hpet * ACPI also reports hpet, then we catch it here. */ for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next) if (hpetp->hp_hpet == hdp->hd_address) return 0; siz = sizeof(struct hpets) + ((hdp->hd_nirqs - 1) * sizeof(struct hpet_dev)); hpetp = kmalloc(siz, GFP_KERNEL); if (!hpetp) return -ENOMEM; memset(hpetp, 0, siz); hpetp->hp_which = hpet_nhpet++; hpetp->hp_hpet = hdp->hd_address; hpetp->hp_hpet_phys = hdp->hd_phys_address; hpetp->hp_ntimer = hdp->hd_nirqs; for (i = 0; i < hdp->hd_nirqs; i++) hpetp->hp_dev[i].hd_hdwirq = hdp->hd_irq[i]; hpet = hpetp->hp_hpet; cap = readq(&hpet->hpet_cap); ntimer = ((cap & HPET_NUM_TIM_CAP_MASK) >> HPET_NUM_TIM_CAP_SHIFT) + 1; if (hpetp->hp_ntimer != ntimer) { printk(KERN_WARNING "hpet: number irqs doesn't agree" " with number of timers\n"); kfree(hpetp); return -ENODEV; } if (last) last->hp_next = hpetp; else hpets = hpetp; last = hpetp; hpetp->hp_period = (cap & HPET_COUNTER_CLK_PERIOD_MASK) >> HPET_COUNTER_CLK_PERIOD_SHIFT; printk(KERN_INFO "hpet%d: at MMIO 0x%lx, IRQ%s", hpetp->hp_which, hdp->hd_phys_address, hpetp->hp_ntimer > 1 ? "s" : ""); for (i = 0; i < hpetp->hp_ntimer; i++) printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]); printk("\n"); ns = hpetp->hp_period; /* femptoseconds, 10^-15 */ do_div(ns, 1000000); /* convert to nanoseconds, 10^-9 */ printk(KERN_INFO "hpet%d: %ldns tick, %d %d-bit timers\n", hpetp->hp_which, ns, hpetp->hp_ntimer, cap & HPET_COUNTER_SIZE_MASK ? 64 : 32); mcfg = readq(&hpet->hpet_config); if ((mcfg & HPET_ENABLE_CNF_MASK) == 0) { write_counter(0L, &hpet->hpet_mc); mcfg |= HPET_ENABLE_CNF_MASK; writeq(mcfg, &hpet->hpet_config); } for (i = 0, devp = hpetp->hp_dev; i < hpetp->hp_ntimer; i++, hpet_ntimer++, devp++) { unsigned long v; struct hpet_timer __iomem *timer; timer = &hpet->hpet_timers[devp - hpetp->hp_dev]; v = readq(&timer->hpet_config); devp->hd_hpets = hpetp; devp->hd_hpet = hpet; devp->hd_timer = timer; /* * If the timer was reserved by platform code, * then make timer unavailable for opens. */ if (hdp->hd_state & (1 << i)) { devp->hd_flags = HPET_OPEN; continue; } init_waitqueue_head(&devp->hd_waitqueue); } hpetp->hp_delta = hpet_calibrate(hpetp); hpet_register_interpolator(hpetp); return 0; } static acpi_status hpet_resources(struct acpi_resource *res, void *data) { struct hpet_data *hdp; acpi_status status; struct acpi_resource_address64 addr; struct hpets *hpetp; hdp = data; status = acpi_resource_to_address64(res, &addr); if (ACPI_SUCCESS(status)) { unsigned long size; size = addr.max_address_range - addr.min_address_range + 1; hdp->hd_phys_address = addr.min_address_range; hdp->hd_address = ioremap(addr.min_address_range, size); for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next) if (hpetp->hp_hpet == hdp->hd_address) return -EBUSY; } else if (res->id == ACPI_RSTYPE_EXT_IRQ) { struct acpi_resource_ext_irq *irqp; int i; irqp = &res->data.extended_irq; if (irqp->number_of_interrupts > 0) { hdp->hd_nirqs = irqp->number_of_interrupts; for (i = 0; i < hdp->hd_nirqs; i++) hdp->hd_irq[i] = acpi_register_gsi(irqp->interrupts[i], irqp->edge_level, irqp->active_high_low); } } return AE_OK; } static int hpet_acpi_add(struct acpi_device *device) { acpi_status result; struct hpet_data data; memset(&data, 0, sizeof(data)); result = acpi_walk_resources(device->handle, METHOD_NAME__CRS, hpet_resources, &data); if (ACPI_FAILURE(result)) return -ENODEV; if (!data.hd_address || !data.hd_nirqs) { printk("%s: no address or irqs in _CRS\n", __FUNCTION__); return -ENODEV; } return hpet_alloc(&data); } static int hpet_acpi_remove(struct acpi_device *device, int type) { /* XXX need to unregister interpolator, dealloc mem, etc */ return -EINVAL; } static struct acpi_driver hpet_acpi_driver = { .name = "hpet", .ids = "PNP0103", .ops = { .add = hpet_acpi_add, .remove = hpet_acpi_remove, }, }; static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops }; static int __init hpet_init(void) { int result; result = misc_register(&hpet_misc); if (result < 0) return -ENODEV; sysctl_header = register_sysctl_table(dev_root, 0); result = acpi_bus_register_driver(&hpet_acpi_driver); if (result < 0) { if (sysctl_header) unregister_sysctl_table(sysctl_header); misc_deregister(&hpet_misc); return result; } return 0; } static void __exit hpet_exit(void) { acpi_bus_unregister_driver(&hpet_acpi_driver); if (sysctl_header) unregister_sysctl_table(sysctl_header); misc_deregister(&hpet_misc); return; } module_init(hpet_init); module_exit(hpet_exit); MODULE_AUTHOR("Bob Picco <Robert.Picco@hp.com>"); MODULE_LICENSE("GPL");
heesub/tglx
drivers/char/hpet.c
C
gpl-2.0
21,475
<?php /** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage * @package Mage_Sales * @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Sales order view items block * * @category Mage * @package Mage_Sales * @author Magento Core Team <core@magentocommerce.com> */ class Mage_Sales_Block_Order_Creditmemo_Items extends Mage_Sales_Block_Items_Abstract { /** * Retrieve current order model instance * * @return Mage_Sales_Model_Order */ public function getOrder() { return Mage::registry('current_order'); } public function getPrintCreditmemoUrl($creditmemo) { return Mage::getUrl('*/*/printCreditmemo', array('creditmemo_id' => $creditmemo->getId())); } public function getPrintAllCreditmemosUrl($order) { return Mage::getUrl('*/*/printCreditmemo', array('order_id' => $order->getId())); } /** * Get creditmemo totals block html * * @param Mage_Sales_Model_Order_Creditmemo $creditmemo * @return string */ public function getTotalsHtml($creditmemo) { $totals = $this->getChild('creditmemo_totals'); $html = ''; if ($totals) { $totals->setCreditmemo($creditmemo); $html = $totals->toHtml(); } return $html; } /** * Get html of creditmemo comments block * * @param Mage_Sales_Model_Order_Creditmemo $creditmemo * @return string */ public function getCommentsHtml($creditmemo) { $html = ''; $comments = $this->getChild('creditmemo_comments'); if ($comments) { $comments->setEntity($creditmemo) ->setTitle(Mage::helper('sales')->__('About Your Refund')); $html = $comments->toHtml(); } return $html; } }
Eristoff47/P2
src/public/app/code/core/Mage/Sales/Block/Order/Creditmemo/Items.php
PHP
gpl-2.0
2,665
/*! buddypress - v2.3.1 - 2015-06-05 1:48:13 PM UTC - https://wordpress.org/plugins/buddypress/ */ window.bp=window.bp||{},function(a,b){"undefined"!=typeof BP_Uploader&&(bp.Models=bp.Models||{},bp.Collections=bp.Collections||{},bp.Views=bp.Views||{},bp.Avatar={start:function(){this.removeLegacyUI(),this.views=new Backbone.Collection,this.jcropapi={},this.warning=null,this.setupNav(),this.avatars=bp.Uploader.filesUploaded,bp.Uploader.filesQueue.on("reset",this.cropView,this),b("body.wp-admin").on("tb_unload","#TB_window",function(){bp.Avatar.nav.trigger("bp-avatar-view:changed","upload"),_.each(bp.Avatar.navItems.models,function(a){a.set("upload"===a.id?{active:1}:{active:0})})})},removeLegacyUI:function(){b("#avatar-upload-form").length?(b("#avatar-upload").remove(),b("#avatar-upload-form p").remove()):b("#group-settings-form").length?(b("#group-settings-form p").each(function(a){0!==a&&b(this).remove()}),b("#delete-group-avatar-button").length&&b("#delete-group-avatar-button").remove()):b("#group-create-body").length?(b(".main-column p #file").remove(),b(".main-column p #upload").remove()):b("#bp_xprofile_user_admin_avatar a.bp-xprofile-avatar-user-admin").length&&b("#bp_xprofile_user_admin_avatar a.bp-xprofile-avatar-user-admin").remove()},setView:function(a){switch(_.isUndefined(this.views.models)||_.each(this.views.models,function(a){a.get("view").remove()},this),this.views.reset(),_.isUndefined(this.avatars)||this.avatars.reset(),_.isEmpty(this.jcropapi)||(this.jcropapi.destroy(),this.jcropapi={}),a){case"upload":this.uploaderView();break;case"delete":this.deleteView()}},setupNav:function(){var a,b,c=this;this.navItems=new Backbone.Collection,_.each(BP_Uploader.settings.nav,function(d,e){_.isObject(d)&&(b=0,0===e&&(a=d.id,b=1),c.navItems.add({id:d.id,name:d.caption,href:"#",active:b,hide:_.isUndefined(d.hide)?0:d.hide}))}),this.nav=new bp.Views.Nav({collection:this.navItems}),this.nav.inject(".bp-avatar-nav"),this.setView(a),this.nav.on("bp-avatar-view:changed",_.bind(this.setView,this))},uploaderView:function(){bp.Uploader.filesQueue.on("add",this.uploadProgress,this);var a=new bp.Views.Uploader;this.views.add({id:"upload",view:a}),a.inject(".bp-avatar")},uploadProgress:function(){var a=new bp.Views.uploaderStatus({collection:bp.Uploader.filesQueue});_.isUndefined(this.views.get("status"))?this.views.add({id:"status",view:a}):this.views.set({id:"status",view:a}),a.inject(".bp-avatar-status")},cropView:function(){var a;if(!_.isEmpty(this.avatars.models)){_.isUndefined(this.views.get("status"))||(a=this.views.get("status"),a.get("view").remove(),this.views.remove({id:"status",view:a}));var b=new bp.Views.Avatars({collection:this.avatars});this.views.add({id:"crop",view:b}),b.inject(".bp-avatar")}},setAvatar:function(a){var c,d=this;_.isUndefined(this.views.get("crop"))||(_.isEmpty(this.jcropapi)||(this.jcropapi.destroy(),this.jcropapi={}),c=this.views.get("crop"),c.get("view").remove(),this.views.remove({id:"crop",view:c})),bp.ajax.post("bp_avatar_set",{json:!0,original_file:a.get("url"),crop_w:a.get("w"),crop_h:a.get("h"),crop_x:a.get("x"),crop_y:a.get("y"),item_id:a.get("item_id"),object:a.get("object"),type:_.isUndefined(a.get("type"))?"crop":a.get("type"),nonce:a.get("nonces").set}).done(function(c){var e=new bp.Views.AvatarStatus({value:BP_Uploader.strings.feedback_messages[c.feedback_code],type:"success"});d.views.add({id:"status",view:e}),e.inject(".bp-avatar-status"),b("."+a.get("object")+"-"+c.item_id+"-avatar").each(function(){b(this).prop("src",c.avatar)}),bp.Avatar.navItems.get("delete").set({hide:0})}).fail(function(a){var b=BP_Uploader.strings.default_error;_.isUndefined(a)||(b=BP_Uploader.strings.feedback_messages[a.feedback_code]);var c=new bp.Views.AvatarStatus({value:b,type:"error"});d.views.add({id:"status",view:c}),c.inject(".bp-avatar-status")})},deleteView:function(){var a=new Backbone.Model(_.pick(BP_Uploader.settings.defaults.multipart_params.bp_params,"object","item_id","nonces")),b=new bp.Views.DeleteAvatar({model:a});this.views.add({id:"delete",view:b}),b.inject(".bp-avatar")},deleteAvatar:function(a){var c,d=this;_.isUndefined(this.views.get("delete"))||(c=this.views.get("delete"),c.get("view").remove(),this.views.remove({id:"delete",view:c})),bp.ajax.post("bp_avatar_delete",{json:!0,item_id:a.get("item_id"),object:a.get("object"),nonce:a.get("nonces").remove}).done(function(c){var e=new bp.Views.AvatarStatus({value:BP_Uploader.strings.feedback_messages[c.feedback_code],type:"success"});d.views.add({id:"status",view:e}),e.inject(".bp-avatar-status"),b("."+a.get("object")+"-"+c.item_id+"-avatar").each(function(){b(this).prop("src",c.avatar)}),bp.Avatar.navItems.get("delete").set({active:0,hide:1})}).fail(function(a){var b=BP_Uploader.strings.default_error;_.isUndefined(a)||(b=BP_Uploader.strings.feedback_messages[a.feedback_code]);var c=new bp.Views.AvatarStatus({value:b,type:"error"});d.views.add({id:"status",view:c}),c.inject(".bp-avatar-status")})},removeWarning:function(){_.isNull(this.warning)||this.warning.remove()},displayWarning:function(a){this.removeWarning(),this.warning=new bp.Views.uploaderWarning({value:a}),this.warning.inject(".bp-avatar-status")}},bp.Views.Nav=bp.View.extend({tagName:"ul",className:"avatar-nav-items",events:{"click .bp-avatar-nav-item":"toggleView"},initialize:function(){var a=_.findWhere(this.collection.models,{id:"delete"});1!==a.get("hide")&&bp.Avatar.displayWarning(BP_Uploader.strings.has_avatar_warning),_.each(this.collection.models,this.addNavItem,this),this.collection.on("change:hide",this.showHideNavItem,this)},addNavItem:function(a){1!==a.get("hide")&&this.views.add(new bp.Views.NavItem({model:a}))},showHideNavItem:function(a){var b=null;_.each(this.views._views[""],function(c){1===c.model.get("hide")&&c.remove(),a.get("id")===c.model.get("id")&&(b=!0)}),_.isBoolean(b)||this.addNavItem(a)},toggleView:function(a){a.preventDefault(),bp.Avatar.removeWarning();var c=b(a.target).data("nav");_.each(this.collection.models,function(a){a.id===c?(a.set({active:1}),this.trigger("bp-avatar-view:changed",a.id)):a.set({active:0})},this)}}),bp.Views.NavItem=bp.View.extend({tagName:"li",className:"avatar-nav-item",template:bp.template("bp-avatar-nav"),initialize:function(){1===this.model.get("active")&&(this.el.className+=" current"),this.el.id+="bp-avatar-"+this.model.get("id"),this.model.on("change:active",this.setCurrentNav,this)},setCurrentNav:function(a){1===a.get("active")?this.$el.addClass("current"):this.$el.removeClass("current")}}),bp.Views.Avatars=bp.View.extend({className:"items",initialize:function(){_.each(this.collection.models,this.addItemView,this)},addItemView:function(a){var b={full_h:150,full_w:150};_.isUndefined(BP_Uploader.settings.crop.full_h)||_.isUndefined(BP_Uploader.settings.crop.full_w)||(b.full_h=BP_Uploader.settings.crop.full_h,b.full_w=BP_Uploader.settings.crop.full_w),a.set(_.extend(_.pick(BP_Uploader.settings.defaults.multipart_params.bp_params,"object","item_id","nonces"),b)),this.views.add(new bp.Views.Avatar({model:a}))}}),bp.Views.Avatar=bp.View.extend({className:"item",template:bp.template("bp-avatar-item"),events:{"click .avatar-crop-submit":"cropAvatar"},initialize:function(){_.defaults(this.options,{full_h:BP_Uploader.settings.crop.full_h,full_w:BP_Uploader.settings.crop.full_w,aspectRatio:1}),!1!==this.model.get("feedback")&&bp.Avatar.displayWarning(this.model.get("feedback")),this.on("ready",this.initCropper)},initCropper:function(){var a,c,d,e,f,g,h=this,i=this.$el.find("#avatar-to-crop img"),j=this.$el.width(),k={};_.isUndefined(this.options.full_h)||_.isUndefined(this.options.full_w)||(this.options.aspectRatio=this.options.full_h/this.options.full_w),k.w=this.model.get("width"),k.h=this.model.get("height"),this.options.full_w+k.w+20<j&&(b("#avatar-to-crop").addClass("adjust"),this.$el.find(".avatar-crop-management").addClass("adjust")),k.h<=k.w?(a=Math.round(k.h/4),f=g=Math.round(k.h/2),c=f+a,d=(k.w-g)/2,e=g+d):(d=Math.round(k.w/4),f=g=Math.round(k.w/2),e=g+d,a=(k.h-f)/2,c=f+a),i.Jcrop({onChange:_.bind(h.showPreview,h),onSelect:_.bind(h.showPreview,h),aspectRatio:h.options.aspectRatio,setSelect:[d,a,e,c]},function(){bp.Avatar.jcropapi=this})},cropAvatar:function(a){a.preventDefault(),bp.Avatar.setAvatar(this.model)},showPreview:function(a){if(a.w&&a.h&&parseInt(a.w,10)>0){var c=this.options.full_w,d=this.options.full_h,e=c/a.w,f=d/a.h;this.model.set({x:a.x,y:a.y,w:a.w,h:a.h}),b("#avatar-crop-preview").css({maxWidth:"none",width:Math.round(e*this.model.get("width"))+"px",height:Math.round(f*this.model.get("height"))+"px",marginLeft:"-"+Math.round(e*this.model.get("x"))+"px",marginTop:"-"+Math.round(f*this.model.get("y"))+"px"})}}}),bp.Views.AvatarStatus=bp.View.extend({tagName:"p",className:"updated",id:"bp-avatar-feedback",initialize:function(){this.el.className+=" "+this.options.type,this.value=this.options.value},render:function(){return this.$el.html(this.value),this}}),bp.Views.DeleteAvatar=bp.View.extend({tagName:"div",id:"bp-delete-avatar-container",template:bp.template("bp-avatar-delete"),events:{"click #bp-delete-avatar":"deleteAvatar"},deleteAvatar:function(a){a.preventDefault(),bp.Avatar.deleteAvatar(this.model)}}),bp.Avatar.start())}(bp,jQuery);
prdanielmota/faama-debug
wp-content/plugins/buddypress/bp-core/js/avatar.min.js
JavaScript
gpl-2.0
9,234
<?php /** * Display notices in admin. * * @author WooThemes * @category Admin * @package WooCommerce/Admin * @version 2.1.0 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! class_exists( 'WC_Admin_Notices' ) ) : /** * WC_Admin_Notices Class */ class WC_Admin_Notices { /** * Hook in tabs. */ public function __construct() { add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) ); add_action( 'woocommerce_updated', array( $this, 'reset_admin_notices' ) ); add_action( 'admin_print_styles', array( $this, 'add_notices' ) ); } /** * Reset notices for themes when switched or a new version of WC is installed */ public function reset_admin_notices() { update_option( 'woocommerce_admin_notices', array( 'template_files', 'theme_support' ) ); } /** * Add notices + styles if needed. */ public function add_notices() { if ( get_option( '_wc_needs_update' ) == 1 || get_option( '_wc_needs_pages' ) == 1 ) { wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) ); add_action( 'admin_notices', array( $this, 'install_notice' ) ); } $notices = get_option( 'woocommerce_admin_notices', array() ); if ( ! empty( $_GET['hide_theme_support_notice'] ) ) { $notices = array_diff( $notices, array( 'theme_support' ) ); update_option( 'woocommerce_admin_notices', $notices ); } if ( ! empty( $_GET['hide_template_files_notice'] ) ) { $notices = array_diff( $notices, array( 'template_files' ) ); update_option( 'woocommerce_admin_notices', $notices ); } if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'woocommerce' ) ) { $template = get_option( 'template' ); if ( ! in_array( $template, wc_get_core_supported_themes() ) ) { wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) ); add_action( 'admin_notices', array( $this, 'theme_check_notice' ) ); } } if ( in_array( 'template_files', $notices ) ) { wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) ); add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) ); } if ( in_array( 'translation_upgrade', $notices ) ) { wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) ); add_action( 'admin_notices', array( $this, 'translation_upgrade_notice' ) ); } if ( ! class_exists( 'WC_Mijireh_Checkout' ) && ( $mijireh = get_option( 'woocommerce_mijireh_checkout_settings', false ) ) && ! empty( $mijireh['enabled'] ) && $mijireh['enabled'] === 'yes' && empty( $_GET['action'] ) ) { add_action( 'admin_notices', array( $this, 'mijireh_notice' ) ); } } /** * Show the install notices */ public function install_notice() { // If we need to update, include a message with the update button if ( get_option( '_wc_needs_update' ) == 1 ) { include( 'views/html-notice-update.php' ); } // If we have just installed, show a message with the install pages button elseif ( get_option( '_wc_needs_pages' ) == 1 ) { include( 'views/html-notice-install.php' ); } } /** * Show the Theme Check notice */ public function theme_check_notice() { include( 'views/html-notice-theme-support.php' ); } /** * Show the translation upgrade notice */ public function translation_upgrade_notice() { $screen = get_current_screen(); if ( 'update-core' !== $screen->id ) { include( 'views/html-notice-translation-upgrade.php' ); } } /** * Show a notice highlighting bad template files */ public function template_file_check_notice() { if ( isset( $_GET['page'] ) && 'wc-status' == $_GET['page'] ) { return; } $core_templates = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates' ); $outdated = false; foreach ( $core_templates as $file ) { $theme_file = false; if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { $theme_file = get_stylesheet_directory() . '/' . $file; } elseif ( file_exists( get_stylesheet_directory() . '/woocommerce/' . $file ) ) { $theme_file = get_stylesheet_directory() . '/woocommerce/' . $file; } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { $theme_file = get_template_directory() . '/' . $file; } elseif( file_exists( get_template_directory() . '/woocommerce/' . $file ) ) { $theme_file = get_template_directory() . '/woocommerce/' . $file; } if ( $theme_file ) { $core_version = WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file ); $theme_version = WC_Admin_Status::get_file_version( $theme_file ); if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) { $outdated = true; break; } } } if ( $outdated ) { include( 'views/html-notice-template-check.php' ); } } /** * Notice to say Mijireh has been deprecated in 2.2 */ public function mijireh_notice() { include( 'views/html-notice-mijireh.php' ); } } endif; return new WC_Admin_Notices();
tayralf/wp-4-br
wp-content/plugins/woocommerce/includes/admin/class-wc-admin-notices.php
PHP
gpl-2.0
5,197
<?php /** * @version $Id: edit.php 21321 2011-05-11 01:05:59Z dextercowley $ * @package Joomla.Site * @subpackage com_users * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @since 1.6 */ defined('_JEXEC') or die; JHtml::_('behavior.keepalive'); JHtml::_('behavior.tooltip'); JHtml::_('behavior.formvalidation'); //load user_profile plugin language $lang = JFactory::getLanguage(); $lang->load( 'plg_user_profile', JPATH_ADMINISTRATOR ); ?> <div class="profile-edit<?php echo $this->pageclass_sfx?>"> <?php if ($this->params->get('show_page_heading')) : ?> <h1><?php echo $this->escape($this->params->get('page_heading')); ?></h1> <?php endif; ?> <form id="member-profile" action="<?php echo JRoute::_('index.php?option=com_users&task=profile.save'); ?>" method="post" class="form-validate"> <?php foreach ($this->form->getFieldsets() as $group => $fieldset):// Iterate through the form fieldsets and display each one.?> <?php $fields = $this->form->getFieldset($group);?> <?php if (count($fields)):?> <fieldset> <?php if (isset($fieldset->label)):// If the fieldset has a label set, display it as the legend.?> <legend><?php echo JText::_($fieldset->label); ?></legend> <?php endif;?> <dl> <?php foreach ($fields as $field):// Iterate through the fields in the set and display them.?> <?php if ($field->hidden):// If the field is hidden, just display the input.?> <?php echo $field->input;?> <?php else:?> <dt> <?php echo $field->label; ?> <?php if (!$field->required && $field->type!='Spacer'): ?> <span class="optional"><?php echo JText::_('COM_USERS_OPTIONAL'); ?></span> <?php endif; ?> </dt> <dd><?php echo $field->input; ?></dd> <?php endif;?> <?php endforeach;?> </dl> </fieldset> <?php endif;?> <?php endforeach;?> <div> <button type="submit" class="validate"><span><?php echo JText::_('JSUBMIT'); ?></span></button> <?php echo JText::_('COM_USERS_OR'); ?> <a href="<?php echo JRoute::_(''); ?>" title="<?php echo JText::_('JCANCEL'); ?>"><?php echo JText::_('JCANCEL'); ?></a> <input type="hidden" name="option" value="com_users" /> <input type="hidden" name="task" value="profile.save" /> <?php echo JHtml::_('form.token'); ?> </div> </form> </div>
lukjack92/joomla
components/com_users/views/profile/tmpl/edit.php
PHP
gpl-2.0
2,376
<?php /** * @package Admin */ /** * This class handles the pointers used in the introduction tour. * * @todo Add an introductory pointer on the edit post page too. */ class WPSEO_Pointers { /** * @var object Instance of this class */ public static $instance; /** * Class constructor. */ private function __construct() { if ( current_user_can( 'manage_options' ) ) { $options = get_option( 'wpseo' ); if ( $options['tracking_popup_done'] === false || $options['ignore_tour'] === false ) { wp_enqueue_style( 'wp-pointer' ); wp_enqueue_script( 'jquery-ui' ); wp_enqueue_script( 'wp-pointer' ); wp_enqueue_script( 'utils' ); } if ( $options['tracking_popup_done'] === false && ! isset( $_GET['allow_tracking'] ) ) { add_action( 'admin_print_footer_scripts', array( $this, 'tracking_request' ) ); } elseif ( $options['ignore_tour'] === false ) { add_action( 'admin_print_footer_scripts', array( $this, 'intro_tour' ) ); } } } /** * Get the singleton instance of this class * * @return object */ public static function get_instance() { if ( ! ( self::$instance instanceof self ) ) { self::$instance = new self(); } return self::$instance; } /** * Shows a popup that asks for permission to allow tracking. */ function tracking_request() { $id = '#wpadminbar'; $nonce = wp_create_nonce( 'wpseo_activate_tracking' ); $content = '<h3>' . __( 'Help improve WordPress SEO', 'wordpress-seo' ) . '</h3>'; $content .= '<p>' . __( 'You&#8217;ve just installed WordPress SEO by Yoast. Please helps us improve it by allowing us to gather anonymous usage stats so we know which configurations, plugins and themes to test with.', 'wordpress-seo' ) . '</p>'; $opt_arr = array( 'content' => $content, 'position' => array( 'edge' => 'top', 'align' => 'center' ) ); $button_array = array( 'button1' => array( 'text' => __( 'Do not allow tracking', 'wordpress-seo' ), 'function' => 'wpseo_store_answer("no","' . $nonce . '")', ), 'button2' => array( 'text' => __( 'Allow tracking', 'wordpress-seo' ), 'function' => 'wpseo_store_answer("yes","' . $nonce . '")', ), ); $this->print_scripts( $id, $opt_arr, $button_array ); } /** * Load the introduction tour */ function intro_tour() { global $pagenow, $current_user; // @FIXME: Links to tabs only work with target="_blank" and thus open in a new window $adminpages = array( 'wpseo_dashboard' => array( 'content' => '<h3>' . __( 'Dashboard', 'wordpress-seo' ) . '</h3><p>' . __( 'This is the WordPress SEO Dashboard, here you can restart this tour or revert the WP SEO settings to default.', 'wordpress-seo' ) . '</p>' . '<p><strong>' . __( 'More WordPress SEO', 'wordpress-seo' ) . '</strong><br/>' . sprintf( __( 'There&#8217;s more to learn about WordPress &amp; SEO than just using this plugin. A great start is our article %1$sthe definitive guide to WordPress SEO%2$s.', 'wordpress-seo' ), '<a target="_blank" href="' . esc_url( 'https://yoast.com/articles/wordpress-seo/#utm_source=wpseo_dashboard&utm_medium=wpseo_tour&utm_campaign=tour' ) . '">', '</a>' ) . '</p>' . '<p><strong>' . __( 'Tracking', 'wordpress-seo' ) . '</strong><br/>' . __( 'To provide you with the best experience possible, we need your help. Please enable tracking to help us gather anonymous usage data.', 'wordpress-seo' ) . '</p>' . '<p><strong>' . __( 'Webmaster Tools', 'wordpress-seo' ) . '</strong><br/>' . __( 'You can also add the verification codes for the different Webmaster Tools programs here, we highly encourage you to check out both Google and Bing&#8217;s Webmaster Tools.', 'wordpress-seo' ) . '</p>' . '<p><strong>' . __( 'WordPress SEO Tour', 'wordpress-seo' ) . '</strong><br/>' . __( 'This tour will show you around in the plugin, to give you a general overview of the plugin.', 'wordpress-seo' ) . '</p>' . '<p><strong>' . __( 'Newsletter', 'wordpress-seo' ) . '</strong><br/>' . __( 'If you would like us to keep you up-to-date regarding WordPress SEO and other plugins by Yoast, subscribe to our newsletter:', 'wordpress-seo' ) . '</p>' . '<form action="http://yoast.us1.list-manage1.com/subscribe/post?u=ffa93edfe21752c921f860358&amp;id=972f1c9122" method="post" id="newsletter-form" accept-charset="' . esc_attr( get_bloginfo( 'charset' ) ) . '">' . '<p>' . '<label for="newsletter-email">' . __( 'Email', 'wordpress-seo' ) . ':</label> <input style="margin: 5px; color:#666" name="EMAIL" value="' . esc_attr( $current_user->user_email ) . '" id="newsletter-email" placeholder="' . __( 'Email', 'wordpress-seo' ) . '"/><br/>' . '<input type="hidden" name="group" value="2"/>' . '<button type="submit" class="button-primary">' . __( 'Subscribe', 'wordpress-seo' ) . '</button>' . '</p></form>', 'next' => __( 'Next', 'wordpress-seo' ), 'next_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_titles' ) . '";', 'position' => array( 'edge' => 'top', 'align' => 'center' ), ), 'wpseo_titles' => array( 'content' => '<h3>' . __( 'Title &amp; Metas settings', 'wordpress-seo' ) . '</h3>' . '<p>' . __( 'This is where you set the titles and meta-information for all your post types, taxonomies, archives, special pages and for your homepage. The page is divided into different tabs. Make sure you check &#8217;em all out!', 'wordpress-seo' ) . '</p>' . '<p><strong>' . __( 'Sitewide settings', 'wordpress-seo' ) . '</strong><br/>' . __( 'The first tab will show you site-wide settings. You can also set some settings for the entire site here to add specific meta tags or to remove some unneeded cruft.', 'wordpress-seo' ) . '</p>' . '<p><strong>' . __( 'Templates and settings', 'wordpress-seo' ) . '</strong><br/>' . sprintf( __( 'Now click on the &#8216;%1$sPost Types%2$s&#8217;-tab, as this will be our example.', 'wordpress-seo' ), '<a target="_blank" href="' . esc_url( admin_url( 'admin.php?page=wpseo_titles#top#post_types' ) ) . '">', '</a>' ) . '<br />' . __( 'The templates are built using variables. You can find all these variables in the help tab (in the top-right corner of the page). The settings allow you to set specific behavior for the post types.', 'wordpress-seo' ) . '</p>', 'next' => __( 'Next', 'wordpress-seo' ), 'next_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_social' ) . '";', 'prev' => __( 'Previous', 'wordpress-seo' ), 'prev_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_dashboard' ) . '";', ), 'wpseo_social' => array( 'content' => '<h3>' . __( 'Social settings', 'wordpress-seo' ) . '</h3>' . '<p><strong>' . __( 'Facebook', 'wordpress-seo' ) . '</strong><br/>' . sprintf( __( 'On this tab you can enable the %1$sFacebook Open Graph%2$s functionality from this plugin, as well as assign a Facebook user or Application to be the admin of your site, so you can view the Facebook insights.', 'wordpress-seo' ), '<a target="_blank" href="' . esc_url( 'https://yoast.com/facebook-open-graph-protocol/#utm_source=wpseo_social&utm_medium=wpseo_tour&utm_campaign=tour' ) . '">', '</a>' ) . '</p><p>' . __( 'The frontpage settings allow you to set meta-data for your homepage, whereas the default settings allow you to set a fallback for all posts/pages without images. ', 'wordpress-seo' ) . '</p>' . '<p><strong>' . __( 'Twitter', 'wordpress-seo' ) . '</strong><br/>' . sprintf( __( 'With %1$sTwitter Cards%2$s, you can attach rich photos, videos and media experience to tweets that drive traffic to your website. Simply check the box, sign up for the service, and users who Tweet links to your content will have a &#8220;Card&#8221; added to the tweet that&#8217;s visible to all of their followers.', 'wordpress-seo' ), '<a target="_blank" href="' . esc_url( 'https://yoast.com/twitter-cards/#utm_source=wpseo_social&utm_medium=wpseo_tour&utm_campaign=tour' ) . '">', '</a>' ) . '</p>' . '<p><strong>' . __( 'Google+', 'wordpress-seo' ) . '</strong><br/>' . sprintf( __( 'This tab allows you to add specific post meta data for Google+. And if you have a Google+ page for your business, add that URL here and link it on your %1$sGoogle+%2$s page&#8217;s about page.', 'wordpress-seo' ), '<a target="_blank" href="' . esc_url( 'https://plus.google.com/' ) . '">', '</a>' ) . '</p>', 'next' => __( 'Next', 'wordpress-seo' ), 'next_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_xml' ) . '";', 'prev' => __( 'Previous', 'wordpress-seo' ), 'prev_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_titles' ) . '";', ), 'wpseo_xml' => array( 'content' => '<h3>' . __( 'XML Sitemaps', 'wordpress-seo' ) . '</h3>' . '<p><strong>' . __( 'What are XML sitemaps?', 'wordpress-seo' ) . '</strong><br/>' . __( 'A Sitemap is an XML file that lists the URLs for a site. It allows webmasters to include additional information about each URL: when it was last updated, how often it changes, and how important it is in relation to other URLs in the site. This allows search engines to crawl the site more intelligently.', 'wordpress-seo' ) . '</p>' . '<p><strong>' . __( 'What does the plugin do with XML Sitemaps?', 'wordpress-seo' ) . '</strong><br/>' . __( 'This plugin adds XML sitemaps to your site. The sitemaps are automatically updated when you publish a new post, page or custom post and Google and Bing will be automatically notified. You can also have the plugin automatically notify Yahoo! and Ask.com.', 'wordpress-seo' ) . '</p><p>' . __( 'If you want to exclude certain post types and/or taxonomies, you can also set that on this page.', 'wordpress-seo' ) . '</p><p>' . __( 'Is your webserver low on memory? Decrease the entries per sitemap (default: 1000) to reduce load.', 'wordpress-seo' ) . '</p>', 'next' => __( 'Next', 'wordpress-seo' ), 'next_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_permalinks' ) . '";', 'prev' => __( 'Previous', 'wordpress-seo' ), 'prev_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_social' ) . '";', ), 'wpseo_permalinks' => array( 'content' => '<h3>' . __( 'Permalink Settings', 'wordpress-seo' ) . '</h3><p>' . __( 'All of the options here are for advanced users only, if you don&#8217;t know whether you should check any, don&#8217;t touch them.', 'wordpress-seo' ) . '</p>', 'next' => __( 'Next', 'wordpress-seo' ), 'next_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_internal-links' ) . '";', 'prev' => __( 'Previous', 'wordpress-seo' ), 'prev_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_xml' ) . '";', ), 'wpseo_internal-links' => array( 'content' => '<h3>' . __( 'Breadcrumbs Settings', 'wordpress-seo' ) . '</h3><p>' . sprintf( __( 'If your theme supports my breadcrumbs, as all Genesis and WooThemes themes as well as a couple of other ones do, you can change the settings for those here. If you want to modify your theme to support them, %sfollow these instructions%s.', 'wordpress-seo' ), '<a target="_blank" href="' . esc_url( 'https://yoast.com/wordpress/plugins/breadcrumbs/#utm_source=wpseo_permalinks&utm_medium=wpseo_tour&utm_campaign=tour' ) . '">', '</a>' ) . '</p>', 'next' => __( 'Next', 'wordpress-seo' ), 'next_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_rss' ) . '";', 'prev' => __( 'Previous', 'wordpress-seo' ), 'prev_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_permalinks' ) . '";', ), 'wpseo_rss' => array( 'content' => '<h3>' . __( 'RSS Settings', 'wordpress-seo' ) . '</h3><p>' . __( 'This incredibly powerful function allows you to add content to the beginning and end of your posts in your RSS feed. This helps you gain links from people who steal your content!', 'wordpress-seo' ) . '</p>', 'next' => __( 'Next', 'wordpress-seo' ), 'next_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_import' ) . '";', 'prev' => __( 'Previous', 'wordpress-seo' ), 'prev_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_internal-links' ) . '";', ), 'wpseo_import' => array( 'content' => '<h3>' . esc_html__( 'Import & Export', 'wordpress-seo' ) . '</h3>' . '<p><strong>' . __( 'Import from other (SEO) plugins', 'wordpress-seo' ) . '</strong><br/>' . __( 'We can imagine that you switch from another SEO plugin to WordPress SEO. If you just did, you can use these options to transfer your SEO-data. If you were using one of my older plugins like Robots Meta &amp; RSS Footer, you can import the settings here too.', 'wordpress-seo' ) . '</p>' . '<p><strong>' . __( 'Other imports', 'wordpress-seo' ) . '</strong><br/>' . sprintf( __( 'If you&#8217;re using one of our premium plugins, such as %1$sLocal SEO%2$s, you can also find specific import-options for that plugin here.', 'wordpress-seo' ), '<a target="_blank" href="' . esc_url( 'https://yoast.com/wordpress/plugins/local-seo/#utm_source=wpseo_import&utm_medium=wpseo_tour&utm_campaign=tour' ) . '">', '</a>' ) . '</p>' . '<p><strong>' . __( 'Export', 'wordpress-seo' ) . '</strong><br/>' . __( 'If you have multiple blogs and you&#8217;re happy with how you&#8217;ve configured this blog, you can export the settings and import them on another blog so you don&#8217;t have to go through this process twice!', 'wordpress-seo' ) . '</p>', 'next' => __( 'Next', 'wordpress-seo' ), 'next_function' => 'window.location="' . network_admin_url( 'admin.php?page=wpseo_bulk-editor' ) . '";', // will auto-use admin_url if not on multi-site 'prev' => __( 'Previous', 'wordpress-seo' ), 'prev_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_rss' ) . '";', ), 'wpseo_bulk-editor' => array( 'content' => '<h3>' . __( 'Bulk Editor', 'wordpress-seo' ) . '</h3><p>' . __( 'This page lets you view and edit the titles and meta descriptions of all posts and pages on your site. This allows you to edit the title or meta description of all your pages in one place, rather than having to edit each individual page.', 'wordpress-seo' ) . '</p>', 'next' => __( 'Next', 'wordpress-seo' ), 'next_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_files' ) . '";', 'prev' => __( 'Previous', 'wordpress-seo' ), 'prev_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_import' ) . '";', ), 'wpseo_files' => array( 'content' => '<h3>' . __( 'File Editor', 'wordpress-seo' ) . '</h3><p>' . __( 'Here you can edit the .htaccess and robots.txt files, two of the most powerful files in your WordPress install, if your WordPress installation has write-access to the files. But please, only touch these files if you know what you&#8217;re doing!', 'wordpress-seo' ) . '</p>', 'next' => __( 'Next', 'wordpress-seo' ), 'next_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_licenses' ) . '";', 'prev' => __( 'Previous', 'wordpress-seo' ), 'prev_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_bulk-editor' ) . '";', ), 'wpseo_licenses' => array( 'content' => '<h3>' . __( 'Extensions and Licenses', 'wordpress-seo' ) . '</h3>' . '<p><strong>' . __( 'Extensions', 'wordpress-seo' ) . '</strong><br/>' . sprintf( __( 'The powerful functions of WordPress SEO can be extended with %1$sYoast premium plugins%2$s. These premium plugins require the installation of WordPress SEO or WordPress SEO Premium and add specific functionality. You can read all about the Yoast Premium Plugins on %1$shttp://yoast.com/wordpress/plugins/%2$s.', 'wordpress-seo' ), '<a target="_blank" href="' . esc_url( 'https://yoast.com/wordpress/plugins/#utm_source=wpseo_licenses&utm_medium=wpseo_tour&utm_campaign=tour' ) . '">', '</a>' ) . '</p>' . '<p><strong>' . __( 'Licenses', 'wordpress-seo' ) . '</strong><br/>' . __( 'Once you&#8217;ve purchased WordPress SEO Premium or any other premium Yoast plugin, you&#8217;ll have to enter a license key. You can do so on the Licenses-tab. Once you&#8217;ve activated your premium plugin, you can use all its powerful features.', 'wordpress-seo' ) . '</p>' . '<p><strong>' . __( 'Like this plugin?', 'wordpress-seo' ) . '</strong><br/>' . sprintf( __( 'So, we&#8217;ve come to the end of the tour. If you like the plugin, please %srate it 5 stars on WordPress.org%s!', 'wordpress-seo' ), '<a target="_blank" href="https://wordpress.org/plugins/wordpress-seo/">', '</a>' ) . '</p>' . '<p>' . sprintf( __( 'Thank you for using my plugin and good luck with your SEO!<br/><br/>Best,<br/>Team Yoast - %1$sYoast.com%2$s', 'wordpress-seo' ), '<a target="_blank" href="' . esc_url( 'https://yoast.com/#utm_source=wpseo_licenses&utm_medium=wpseo_tour&utm_campaign=tour' ) . '">', '</a>' ) . '</p>', 'prev' => __( 'Previous', 'wordpress-seo' ), 'prev_function' => 'window.location="' . admin_url( 'admin.php?page=wpseo_files' ) . '";', ), ); // Skip tour about wpseo_files page if file editing is disallowed or if the site is a multisite and the current user isn't a superadmin if ( false === WPSEO_Utils::allow_system_file_edit() ) { unset( $adminpages['wpseo_files'] ); $adminpages['wpseo_bulk-editor']['function'] = 'window.location="' . admin_url( 'admin.php?page=wpseo_licenses' ) . '";'; } $page = ''; if ( isset( $_GET['page'] ) ) { $page = $_GET['page']; } $button_array = array( 'button1' => array( 'text' => __( 'Close', 'wordpress-seo' ), 'function' => '', ) ); $opt_arr = array(); $id = '#wpseo-title'; if ( 'admin.php' != $pagenow || ! array_key_exists( $page, $adminpages ) ) { $id = 'li.toplevel_page_wpseo_dashboard'; $content = '<h3>' . __( 'Congratulations!', 'wordpress-seo' ) . '</h3>'; $content .= '<p>' . __( 'You&#8217;ve just installed WordPress SEO by Yoast! Click &#8220;Start Tour&#8221; to view a quick introduction of this plugin&#8217;s core functionality.', 'wordpress-seo' ) . '</p>'; $opt_arr = array( 'content' => $content, 'position' => array( 'edge' => 'bottom', 'align' => 'center' ) ); $button_array['button2']['text'] = __( 'Start Tour', 'wordpress-seo' ); $button_array['button2']['function'] = 'document.location="' . admin_url( 'admin.php?page=wpseo_dashboard' ) . '";'; } else { if ( '' != $page && in_array( $page, array_keys( $adminpages ) ) ) { $align = ( is_rtl() ) ? 'left' : 'right'; $opt_arr = array( 'content' => $adminpages[ $page ]['content'], 'position' => ( isset ( $adminpages[ $page ]['position'] ) ) ? ( $adminpages[ $page ]['position'] ) : array( 'edge' => 'top', 'align' => $align, ), 'pointerWidth' => 450, ); if ( isset( $adminpages[ $page ]['next'] ) && isset( $adminpages[ $page ]['next_function'] ) ) { $button_array['button2'] = array( 'text' => $adminpages[ $page ]['next'], 'function' => $adminpages[ $page ]['next_function'], ); } if ( isset( $adminpages[ $page ]['prev'] ) && isset( $adminpages[ $page ]['prev_function'] ) ) { $button_array['button3'] = array( 'text' => $adminpages[ $page ]['prev'], 'function' => $adminpages[ $page ]['prev_function'], ); } } } $this->print_scripts( $id, $opt_arr, $button_array ); } /** * Prints the pointer script * * @param string $selector The CSS selector the pointer is attached to. * @param array $options The options for the pointer. * @param array $button_array The options for the buttons. */ function print_scripts( $selector, $options, $button_array ) { $button_array_defaults = array( 'button1' => array( 'text' => false, 'function' => '', ), 'button2' => array( 'text' => false, 'function' => '', ), 'button3' => array( 'text' => false, 'function' => '', ), ); $button_array = wp_parse_args( $button_array, $button_array_defaults ); ?> <script type="text/javascript"> //<![CDATA[ (function ($) { // Don't show the tour on screens with an effective width smaller than 1024px or an effective height smaller than 768px. if (jQuery(window).width() < 1024 || jQuery(window).availWidth < 1024) { return; } var wpseo_pointer_options = <?php echo json_encode( $options ); ?>, setup; function wpseo_store_answer(input, nonce) { var wpseo_tracking_data = { action : 'wpseo_allow_tracking', allow_tracking: input, nonce : nonce }; jQuery.post(ajaxurl, wpseo_tracking_data, function () { jQuery('#wp-pointer-0').remove(); }); } wpseo_pointer_options = $.extend(wpseo_pointer_options, { buttons: function (event, t) { var button = jQuery('<a id="pointer-close" style="margin:0 5px;" class="button-secondary">' + '<?php echo $button_array['button1']['text']; ?>' + '</a>'); button.bind('click.pointer', function () { t.element.pointer('close'); }); return button; }, close : function () { } }); setup = function () { $('<?php echo $selector; ?>').pointer(wpseo_pointer_options).pointer('open'); <?php if ( $button_array['button2']['text'] ) { ?> jQuery('#pointer-close').after('<a id="pointer-primary" class="button-primary">' + '<?php echo $button_array['button2']['text']; ?>' + '</a>'); jQuery('#pointer-primary').click(function () { <?php echo $button_array['button2']['function']; ?> }); <?php if ( $button_array['button3']['text'] ) { ?> jQuery('#pointer-primary').after('<a id="pointer-ternary" style="float: left;" class="button-secondary">' + '<?php echo $button_array['button3']['text']; ?>' + '</a>'); jQuery('#pointer-ternary').click(function () { <?php echo $button_array['button3']['function']; ?> }); <?php } ?> jQuery('#pointer-close').click(function () { <?php if ( $button_array['button1']['function'] == '' ) { ?> wpseo_setIgnore("tour", "wp-pointer-0", "<?php echo esc_js( wp_create_nonce( 'wpseo-ignore' ) ); ?>"); <?php } else { ?> <?php echo $button_array['button1']['function']; ?> <?php } ?> }); <?php } else if ( $button_array['button3']['text'] ) { ?> jQuery('#pointer-close').after('<a id="pointer-ternary" style="float: left;" class="button-secondary">' + '<?php echo $button_array['button3']['text']; ?>' + '</a>'); jQuery('#pointer-ternary').click(function () { <?php echo $button_array['button3']['function']; ?> }); <?php } ?> }; if (wpseo_pointer_options.position && wpseo_pointer_options.position.defer_loading) $(window).bind('load.wp-pointers', setup); else $(document).ready(setup); })(jQuery); //]]> </script> <?php } /** * Load a tiny bit of CSS in the head * * @deprecated 1.5.0, now handled by css */ function admin_head() { _deprecated_function( __METHOD__, 'WPSEO 1.5.0' ); return; } } /* End of class */
ashchat404/wordpress
wp-content/plugins/wordpress-seo/admin/class-pointers.php
PHP
gpl-2.0
23,594
<?php /** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage * @package Mage_Catalog * @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Entity/Attribute/Model - select product design options container from config * * @category Mage * @package Mage_Eav * @author Magento Core Team <core@magentocommerce.com> */ class Mage_Catalog_Model_Entity_Product_Attribute_Design_Options_Container extends Mage_Eav_Model_Entity_Attribute_Source_Config { protected $_configNodePath; public function __construct() { $this->_configNodePath = 'global/catalog/product/design/options_container'; } /** * Get a text for option value * * @param string|integer $value * @return string */ public function getOptionText($value) { $options = $this->getAllOptions(); if (sizeof($options) > 0) { foreach ($options as $option) { if (isset($option['value']) && $option['value'] == $value) { return $option['label']; } } } if (isset($options[$value])) { return $option[$value]; } return false; } }
boy1dur/bfm-magento
app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Design/Options/Container.php
PHP
gpl-2.0
2,021
/* vi: set sw=4 ts=4: */ /* * universal getopt32 implementation for busybox * * Copyright (C) 2003-2005 Vladimir Oleynik <dzo@simtreas.ru> * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ #if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG # include <getopt.h> #endif #include "libbb.h" /* Documentation uint32_t getopt32(char **argv, const char *applet_opts, ...) The command line options must be declared in const char *applet_opts as a string of chars, for example: flags = getopt32(argv, "rnug"); If one of the given options is found, a flag value is added to the return value (an unsigned long). The flag value is determined by the position of the char in applet_opts string. For example, in the above case: flags = getopt32(argv, "rnug"); "r" will add 1 (bit 0) "n" will add 2 (bit 1) "u" will add 4 (bit 2) "g" will add 8 (bit 3) and so on. You can also look at the return value as a bit field and each option sets one bit. On exit, global variable optind is set so that if you will do argc -= optind; argv += optind; then argc will be equal to number of remaining non-option arguments, first one would be in argv[0], next in argv[1] and so on (options and their parameters will be moved into argv[] positions prior to argv[optind]). ":" If one of the options requires an argument, then add a ":" after the char in applet_opts and provide a pointer to store the argument. For example: char *pointer_to_arg_for_a; char *pointer_to_arg_for_b; char *pointer_to_arg_for_c; char *pointer_to_arg_for_d; flags = getopt32(argv, "a:b:c:d:", &pointer_to_arg_for_a, &pointer_to_arg_for_b, &pointer_to_arg_for_c, &pointer_to_arg_for_d); The type of the pointer (char* or llist_t*) may be controlled by the "::" special separator that is set in the external string opt_complementary (see below for more info). "::" If option can have an *optional* argument, then add a "::" after its char in applet_opts and provide a pointer to store the argument. Note that optional arguments _must_ immediately follow the option: -oparam, not -o param. "+" If the first character in the applet_opts string is a plus, then option processing will stop as soon as a non-option is encountered in the argv array. Useful for applets like env which should not process arguments to subprograms: env -i ls -d / Here we want env to process just the '-i', not the '-d'. "!" Report bad option, missing required options, inconsistent options with all-ones return value (instead of abort). const char *applet_long_options This struct allows you to define long options: static const char applet_longopts[] ALIGN1 = //"name\0" has_arg val "verbose\0" No_argument "v" ; applet_long_options = applet_longopts; The last member of struct option (val) typically is set to matching short option from applet_opts. If there is no matching char in applet_opts, then: - return bit have next position after short options - if has_arg is not "No_argument", use ptr for arg also - opt_complementary affects it too Note: a good applet will make long options configurable via the config process and not a required feature. The current standard is to name the config option CONFIG_FEATURE_<applet>_LONG_OPTIONS. const char *opt_complementary ":" The colon (":") is used to separate groups of two or more chars and/or groups of chars and special characters (stating some conditions to be checked). "abc" If groups of two or more chars are specified, the first char is the main option and the other chars are secondary options. Their flags will be turned on if the main option is found even if they are not specifed on the command line. For example: opt_complementary = "abc"; flags = getopt32(argv, "abcd") If getopt() finds "-a" on the command line, then getopt32's return value will be as if "-a -b -c" were found. "ww" Adjacent double options have a counter associated which indicates the number of occurrences of the option. For example the ps applet needs: if w is given once, GNU ps sets the width to 132, if w is given more than once, it is "unlimited" int w_counter = 0; // must be initialized! opt_complementary = "ww"; getopt32(argv, "w", &w_counter); if (w_counter) width = (w_counter == 1) ? 132 : INT_MAX; else get_terminal_width(...&width...); w_counter is a pointer to an integer. It has to be passed to getopt32() after all other option argument sinks. For example: accept multiple -v to indicate the level of verbosity and for each -b optarg, add optarg to my_b. Finally, if b is given, turn off c and vice versa: llist_t *my_b = NULL; int verbose_level = 0; opt_complementary = "vv:b::b-c:c-b"; f = getopt32(argv, "vb:c", &my_b, &verbose_level); if (f & 2) // -c after -b unsets -b flag while (my_b) dosomething_with(llist_pop(&my_b)); if (my_b) // but llist is stored if -b is specified free_llist(my_b); if (verbose_level) printf("verbose level is %d\n", verbose_level); Special characters: "-" A group consisting of just a dash forces all arguments to be treated as options, even if they have no leading dashes. Next char in this case can't be a digit (0-9), use ':' or end of line. Example: opt_complementary = "-:w-x:x-w"; // "-w-x:x-w" would also work, getopt32(argv, "wx"); // but is less readable This makes it possible to use options without a dash (./program w x) as well as with a dash (./program -x). NB: getopt32() will leak a small amount of memory if you use this option! Do not use it if there is a possibility of recursive getopt32() calls. "--" A double dash at the beginning of opt_complementary means the argv[1] string should always be treated as options, even if it isn't prefixed with a "-". This is useful for special syntax in applets such as "ar" and "tar": tar xvf foo.tar NB: getopt32() will leak a small amount of memory if you use this option! Do not use it if there is a possibility of recursive getopt32() calls. "-N" A dash as the first char in a opt_complementary group followed by a single digit (0-9) means that at least N non-option arguments must be present on the command line "=N" An equal sign as the first char in a opt_complementary group followed by a single digit (0-9) means that exactly N non-option arguments must be present on the command line "?N" A "?" as the first char in a opt_complementary group followed by a single digit (0-9) means that at most N arguments must be present on the command line. "V-" An option with dash before colon or end-of-line results in bb_show_usage() being called if this option is encountered. This is typically used to implement "print verbose usage message and exit" option. "a-b" A dash between two options causes the second of the two to be unset (and ignored) if it is given on the command line. [FIXME: what if they are the same? like "x-x"? Is it ever useful?] For example: The du applet has the options "-s" and "-d depth". If getopt32 finds -s, then -d is unset or if it finds -d then -s is unset. (Note: busybox implements the GNU "--max-depth" option as "-d".) To obtain this behavior, you set opt_complementary = "s-d:d-s". Only one flag value is added to getopt32's return value depending on the position of the options on the command line. If one of the two options requires an argument pointer (":" in applet_opts as in "d:") optarg is set accordingly. char *smax_print_depth; opt_complementary = "s-d:d-s:x-x"; opt = getopt32(argv, "sd:x", &smax_print_depth); if (opt & 2) max_print_depth = atoi(smax_print_depth); if (opt & 4) printf("Detected odd -x usage\n"); "a--b" A double dash between two options, or between an option and a group of options, means that they are mutually exclusive. Unlike the "-" case above, an error will be forced if the options are used together. For example: The cut applet must have only one type of list specified, so -b, -c and -f are mutually exclusive and should raise an error if specified together. In this case you must set opt_complementary = "b--cf:c--bf:f--bc". If two of the mutually exclusive options are found, getopt32 will call bb_show_usage() and die. "x--x" Variation of the above, it means that -x option should occur at most once. "a+" A plus after a char in opt_complementary means that the parameter for this option is a nonnegative integer. It will be processed with xatoi_positive() - allowed range is 0..INT_MAX. int param; // "unsigned param;" will also work opt_complementary = "p+"; getopt32(argv, "p:", &param); "a::" A double colon after a char in opt_complementary means that the option can occur multiple times. Each occurrence will be saved as a llist_t element instead of char*. For example: The grep applet can have one or more "-e pattern" arguments. In this case you should use getopt32() as follows: llist_t *patterns = NULL; (this pointer must be initializated to NULL if the list is empty as required by llist_add_to_end(llist_t **old_head, char *new_item).) opt_complementary = "e::"; getopt32(argv, "e:", &patterns); $ grep -e user -e root /etc/passwd root:x:0:0:root:/root:/bin/bash user:x:500:500::/home/user:/bin/bash "a?b" A "?" between an option and a group of options means that at least one of them is required to occur if the first option occurs in preceding command line arguments. For example from "id" applet: // Don't allow -n -r -rn -ug -rug -nug -rnug opt_complementary = "r?ug:n?ug:u--g:g--u"; flags = getopt32(argv, "rnug"); This example allowed only: $ id; id -u; id -g; id -ru; id -nu; id -rg; id -ng; id -rnu; id -rng "X" A opt_complementary group with just a single letter means that this option is required. If more than one such group exists, at least one option is required to occur (not all of them). For example from "start-stop-daemon" applet: // Don't allow -KS -SK, but -S or -K is required opt_complementary = "K:S:K--S:S--K"; flags = getopt32(argv, "KS...); Don't forget to use ':'. For example, "?322-22-23X-x-a" is interpreted as "?3:22:-2:2-2:2-3Xa:2--x" - max 3 args; count uses of '-2'; min 2 args; if there is a '-2' option then unset '-3', '-X' and '-a'; if there is a '-2' and after it a '-x' then error out. But it's far too obfuscated. Use ':' to separate groups. */ /* Code here assumes that 'unsigned' is at least 32 bits wide */ const char *const bb_argv_dash[] = { "-", NULL }; const char *opt_complementary; enum { PARAM_STRING, PARAM_LIST, PARAM_INT, }; typedef struct { unsigned char opt_char; smallint param_type; unsigned switch_on; unsigned switch_off; unsigned incongruously; unsigned requires; void **optarg; /* char**, llist_t** or int *. */ int *counter; } t_complementary; /* You can set applet_long_options for parse called long options */ #if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG static const struct option bb_null_long_options[1] = { { 0, 0, 0, 0 } }; const char *applet_long_options; #endif uint32_t option_mask32; uint32_t FAST_FUNC getopt32(char **argv, const char *applet_opts, ...) { int argc; unsigned flags = 0; unsigned requires = 0; t_complementary complementary[33]; /* last stays zero-filled */ char first_char; int c; const unsigned char *s; t_complementary *on_off; va_list p; #if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG const struct option *l_o; struct option *long_options = (struct option *) &bb_null_long_options; #endif unsigned trigger; char **pargv; int min_arg = 0; int max_arg = -1; #define SHOW_USAGE_IF_ERROR 1 #define ALL_ARGV_IS_OPTS 2 #define FIRST_ARGV_IS_OPT 4 int spec_flgs = 0; /* skip 0: some applets cheat: they do not actually HAVE argv[0] */ argc = 1; while (argv[argc]) argc++; va_start(p, applet_opts); c = 0; on_off = complementary; memset(on_off, 0, sizeof(complementary)); /* skip bbox extension */ first_char = applet_opts[0]; if (first_char == '!') applet_opts++; /* skip GNU extension */ s = (const unsigned char *)applet_opts; if (*s == '+' || *s == '-') s++; while (*s) { if (c >= 32) break; on_off->opt_char = *s; on_off->switch_on = (1 << c); if (*++s == ':') { on_off->optarg = va_arg(p, void **); while (*++s == ':') continue; } on_off++; c++; } #if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG if (applet_long_options) { const char *optstr; unsigned i, count; count = 1; optstr = applet_long_options; while (optstr[0]) { optstr += strlen(optstr) + 3; /* skip NUL, has_arg, val */ count++; } /* count == no. of longopts + 1 */ long_options = alloca(count * sizeof(*long_options)); memset(long_options, 0, count * sizeof(*long_options)); i = 0; optstr = applet_long_options; while (--count) { long_options[i].name = optstr; optstr += strlen(optstr) + 1; long_options[i].has_arg = (unsigned char)(*optstr++); /* long_options[i].flag = NULL; */ long_options[i].val = (unsigned char)(*optstr++); i++; } for (l_o = long_options; l_o->name; l_o++) { if (l_o->flag) continue; for (on_off = complementary; on_off->opt_char; on_off++) if (on_off->opt_char == l_o->val) goto next_long; if (c >= 32) break; on_off->opt_char = l_o->val; on_off->switch_on = (1 << c); if (l_o->has_arg != no_argument) on_off->optarg = va_arg(p, void **); c++; next_long: ; } /* Make it unnecessary to clear applet_long_options * by hand after each call to getopt32 */ applet_long_options = NULL; } #endif /* ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG */ for (s = (const unsigned char *)opt_complementary; s && *s; s++) { t_complementary *pair; unsigned *pair_switch; if (*s == ':') continue; c = s[1]; if (*s == '?') { if (c < '0' || c > '9') { spec_flgs |= SHOW_USAGE_IF_ERROR; } else { max_arg = c - '0'; s++; } continue; } if (*s == '-') { if (c < '0' || c > '9') { if (c == '-') { spec_flgs |= FIRST_ARGV_IS_OPT; s++; } else spec_flgs |= ALL_ARGV_IS_OPTS; } else { min_arg = c - '0'; s++; } continue; } if (*s == '=') { min_arg = max_arg = c - '0'; s++; continue; } for (on_off = complementary; on_off->opt_char; on_off++) if (on_off->opt_char == *s) goto found_opt; /* Without this, diagnostic of such bugs is not easy */ bb_error_msg_and_die("NO OPT %c!", *s); found_opt: if (c == ':' && s[2] == ':') { on_off->param_type = PARAM_LIST; continue; } if (c == '+' && (s[2] == ':' || s[2] == '\0')) { on_off->param_type = PARAM_INT; s++; continue; } if (c == ':' || c == '\0') { requires |= on_off->switch_on; continue; } if (c == '-' && (s[2] == ':' || s[2] == '\0')) { flags |= on_off->switch_on; on_off->incongruously |= on_off->switch_on; s++; continue; } if (c == *s) { on_off->counter = va_arg(p, int *); s++; } pair = on_off; pair_switch = &pair->switch_on; for (s++; *s && *s != ':'; s++) { if (*s == '?') { pair_switch = &pair->requires; } else if (*s == '-') { if (pair_switch == &pair->switch_off) pair_switch = &pair->incongruously; else pair_switch = &pair->switch_off; } else { for (on_off = complementary; on_off->opt_char; on_off++) if (on_off->opt_char == *s) { *pair_switch |= on_off->switch_on; break; } } } s--; } opt_complementary = NULL; va_end(p); if (spec_flgs & (FIRST_ARGV_IS_OPT | ALL_ARGV_IS_OPTS)) { pargv = argv + 1; while (*pargv) { if (pargv[0][0] != '-' && pargv[0][0] != '\0') { /* Can't use alloca: opts with params will * return pointers to stack! * NB: we leak these allocations... */ char *pp = xmalloc(strlen(*pargv) + 2); *pp = '-'; strcpy(pp + 1, *pargv); *pargv = pp; } if (!(spec_flgs & ALL_ARGV_IS_OPTS)) break; pargv++; } } /* In case getopt32 was already called: * reset the libc getopt() function, which keeps internal state. * run_nofork_applet() does this, but we might end up here * also via gunzip_main() -> gzip_main(). Play safe. */ #ifdef __GLIBC__ optind = 0; #else /* BSD style */ optind = 1; /* optreset = 1; */ #endif /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */ /* Note: just "getopt() <= 0" will not work well for * "fake" short options, like this one: * wget $'-\203' "Test: test" http://kernel.org/ * (supposed to act as --header, but doesn't) */ #if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG while ((c = getopt_long(argc, argv, applet_opts, long_options, NULL)) != -1) { #else while ((c = getopt(argc, argv, applet_opts)) != -1) { #endif /* getopt prints "option requires an argument -- X" * and returns '?' if an option has no arg, but one is reqd */ c &= 0xff; /* fight libc's sign extension */ for (on_off = complementary; on_off->opt_char != c; on_off++) { /* c can be NUL if long opt has non-NULL ->flag, * but we construct long opts so that flag * is always NULL (see above) */ if (on_off->opt_char == '\0' /* && c != '\0' */) { /* c is probably '?' - "bad option" */ goto error; } } if (flags & on_off->incongruously) goto error; trigger = on_off->switch_on & on_off->switch_off; flags &= ~(on_off->switch_off ^ trigger); flags |= on_off->switch_on ^ trigger; flags ^= trigger; if (on_off->counter) (*(on_off->counter))++; if (optarg) { if (on_off->param_type == PARAM_LIST) { llist_add_to_end((llist_t **)(on_off->optarg), optarg); } else if (on_off->param_type == PARAM_INT) { //TODO: xatoi_positive indirectly pulls in printf machinery *(unsigned*)(on_off->optarg) = xatoi_positive(optarg); } else if (on_off->optarg) { *(char **)(on_off->optarg) = optarg; } } } /* check depending requires for given options */ for (on_off = complementary; on_off->opt_char; on_off++) { if (on_off->requires && (flags & on_off->switch_on) && (flags & on_off->requires) == 0 ) { goto error; } } if (requires && (flags & requires) == 0) goto error; argc -= optind; if (argc < min_arg || (max_arg >= 0 && argc > max_arg)) goto error; option_mask32 = flags; return flags; error: if (first_char != '!') bb_show_usage(); return (int32_t)-1; }
rovo89/android_external_busybox
libbb/getopt32.c
C
gpl-2.0
19,826
/* * uvc_queue.c -- USB Video Class driver - Buffers management * * Copyright (C) 2005-2010 * Laurent Pinchart (laurent.pinchart@ideasonboard.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * */ #include <linux/atomic.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/list.h> #include <linux/module.h> #include <linux/usb.h> #include <linux/videodev2.h> #include <linux/vmalloc.h> #include <linux/wait.h> #include <media/videobuf2-vmalloc.h> #include "uvcvideo.h" /* ------------------------------------------------------------------------ * Video buffers queue management. * * Video queues is initialized by uvc_queue_init(). The function performs * basic initialization of the uvc_video_queue struct and never fails. * * Video buffers are managed by videobuf2. The driver uses a mutex to protect * the videobuf2 queue operations by serializing calls to videobuf2 and a * spinlock to protect the IRQ queue that holds the buffers to be processed by * the driver. */ /* ----------------------------------------------------------------------------- * videobuf2 queue operations */ static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, unsigned int *nbuffers, unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[]) { struct uvc_video_queue *queue = vb2_get_drv_priv(vq); struct uvc_streaming *stream = container_of(queue, struct uvc_streaming, queue); /* Make sure the image size is large enough. */ if (fmt && fmt->fmt.pix.sizeimage < stream->ctrl.dwMaxVideoFrameSize) return -EINVAL; *nplanes = 1; sizes[0] = fmt ? fmt->fmt.pix.sizeimage : stream->ctrl.dwMaxVideoFrameSize; return 0; } static int uvc_buffer_prepare(struct vb2_buffer *vb) { struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue); struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf); if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT && vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) { uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n"); return -EINVAL; } if (unlikely(queue->flags & UVC_QUEUE_DISCONNECTED)) return -ENODEV; buf->state = UVC_BUF_STATE_QUEUED; buf->error = 0; buf->mem = vb2_plane_vaddr(vb, 0); buf->length = vb2_plane_size(vb, 0); if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) buf->bytesused = 0; else buf->bytesused = vb2_get_plane_payload(vb, 0); return 0; } static void uvc_buffer_queue(struct vb2_buffer *vb) { struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue); struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf); unsigned long flags; spin_lock_irqsave(&queue->irqlock, flags); if (likely(!(queue->flags & UVC_QUEUE_DISCONNECTED))) { list_add_tail(&buf->queue, &queue->irqqueue); } else { /* If the device is disconnected return the buffer to userspace * directly. The next QBUF call will fail with -ENODEV. */ buf->state = UVC_BUF_STATE_ERROR; vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR); } spin_unlock_irqrestore(&queue->irqlock, flags); } static void uvc_buffer_finish(struct vb2_buffer *vb) { struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue); struct uvc_streaming *stream = container_of(queue, struct uvc_streaming, queue); struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf); if (vb->state == VB2_BUF_STATE_DONE) uvc_video_clock_update(stream, &vb->v4l2_buf, buf); } static void uvc_wait_prepare(struct vb2_queue *vq) { struct uvc_video_queue *queue = vb2_get_drv_priv(vq); mutex_unlock(&queue->mutex); } static void uvc_wait_finish(struct vb2_queue *vq) { struct uvc_video_queue *queue = vb2_get_drv_priv(vq); mutex_lock(&queue->mutex); } static struct vb2_ops uvc_queue_qops = { .queue_setup = uvc_queue_setup, .buf_prepare = uvc_buffer_prepare, .buf_queue = uvc_buffer_queue, .buf_finish = uvc_buffer_finish, .wait_prepare = uvc_wait_prepare, .wait_finish = uvc_wait_finish, }; int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, int drop_corrupted) { int ret; queue->queue.type = type; queue->queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; queue->queue.drv_priv = queue; queue->queue.buf_struct_size = sizeof(struct uvc_buffer); queue->queue.ops = &uvc_queue_qops; queue->queue.mem_ops = &vb2_vmalloc_memops; queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC | V4L2_BUF_FLAG_TSTAMP_SRC_SOE; ret = vb2_queue_init(&queue->queue); if (ret) return ret; mutex_init(&queue->mutex); spin_lock_init(&queue->irqlock); INIT_LIST_HEAD(&queue->irqqueue); queue->flags = drop_corrupted ? UVC_QUEUE_DROP_CORRUPTED : 0; return 0; } /* ----------------------------------------------------------------------------- * V4L2 queue operations */ int uvc_alloc_buffers(struct uvc_video_queue *queue, struct v4l2_requestbuffers *rb) { int ret; mutex_lock(&queue->mutex); ret = vb2_reqbufs(&queue->queue, rb); mutex_unlock(&queue->mutex); return ret ? ret : rb->count; } void uvc_free_buffers(struct uvc_video_queue *queue) { mutex_lock(&queue->mutex); vb2_queue_release(&queue->queue); mutex_unlock(&queue->mutex); } int uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf) { int ret; mutex_lock(&queue->mutex); ret = vb2_querybuf(&queue->queue, buf); mutex_unlock(&queue->mutex); return ret; } int uvc_create_buffers(struct uvc_video_queue *queue, struct v4l2_create_buffers *cb) { int ret; mutex_lock(&queue->mutex); ret = vb2_create_bufs(&queue->queue, cb); mutex_unlock(&queue->mutex); return ret; } int uvc_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf) { int ret; mutex_lock(&queue->mutex); ret = vb2_qbuf(&queue->queue, buf); mutex_unlock(&queue->mutex); return ret; } int uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf, int nonblocking) { int ret; mutex_lock(&queue->mutex); ret = vb2_dqbuf(&queue->queue, buf, nonblocking); mutex_unlock(&queue->mutex); return ret; } int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) { int ret; mutex_lock(&queue->mutex); ret = vb2_mmap(&queue->queue, vma); mutex_unlock(&queue->mutex); return ret; } #ifndef CONFIG_MMU unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, unsigned long pgoff) { unsigned long ret; mutex_lock(&queue->mutex); ret = vb2_get_unmapped_area(&queue->queue, 0, 0, pgoff, 0); mutex_unlock(&queue->mutex); return ret; } #endif unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, poll_table *wait) { unsigned int ret; mutex_lock(&queue->mutex); ret = vb2_poll(&queue->queue, file, wait); mutex_unlock(&queue->mutex); return ret; } /* ----------------------------------------------------------------------------- * */ /* * Check if buffers have been allocated. */ int uvc_queue_allocated(struct uvc_video_queue *queue) { int allocated; mutex_lock(&queue->mutex); allocated = vb2_is_busy(&queue->queue); mutex_unlock(&queue->mutex); return allocated; } /* * Enable or disable the video buffers queue. * * The queue must be enabled before starting video acquisition and must be * disabled after stopping it. This ensures that the video buffers queue * state can be properly initialized before buffers are accessed from the * interrupt handler. * * Enabling the video queue returns -EBUSY if the queue is already enabled. * * Disabling the video queue cancels the queue and removes all buffers from * the main queue. * * This function can't be called from interrupt context. Use * uvc_queue_cancel() instead. */ int uvc_queue_enable(struct uvc_video_queue *queue, int enable) { unsigned long flags; int ret; mutex_lock(&queue->mutex); if (enable) { ret = vb2_streamon(&queue->queue, queue->queue.type); if (ret < 0) goto done; queue->buf_used = 0; } else { ret = vb2_streamoff(&queue->queue, queue->queue.type); if (ret < 0) goto done; spin_lock_irqsave(&queue->irqlock, flags); INIT_LIST_HEAD(&queue->irqqueue); spin_unlock_irqrestore(&queue->irqlock, flags); } done: mutex_unlock(&queue->mutex); return ret; } /* * Cancel the video buffers queue. * * Cancelling the queue marks all buffers on the irq queue as erroneous, * wakes them up and removes them from the queue. * * If the disconnect parameter is set, further calls to uvc_queue_buffer will * fail with -ENODEV. * * This function acquires the irq spinlock and can be called from interrupt * context. */ void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) { struct uvc_buffer *buf; unsigned long flags; spin_lock_irqsave(&queue->irqlock, flags); while (!list_empty(&queue->irqqueue)) { buf = list_first_entry(&queue->irqqueue, struct uvc_buffer, queue); list_del(&buf->queue); buf->state = UVC_BUF_STATE_ERROR; vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR); } /* This must be protected by the irqlock spinlock to avoid race * conditions between uvc_buffer_queue and the disconnection event that * could result in an interruptible wait in uvc_dequeue_buffer. Do not * blindly replace this logic by checking for the UVC_QUEUE_DISCONNECTED * state outside the queue code. */ if (disconnect) queue->flags |= UVC_QUEUE_DISCONNECTED; spin_unlock_irqrestore(&queue->irqlock, flags); } struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf) { struct uvc_buffer *nextbuf; unsigned long flags; if ((queue->flags & UVC_QUEUE_DROP_CORRUPTED) && buf->error) { buf->error = 0; buf->state = UVC_BUF_STATE_QUEUED; buf->bytesused = 0; vb2_set_plane_payload(&buf->buf, 0, 0); return buf; } spin_lock_irqsave(&queue->irqlock, flags); list_del(&buf->queue); if (!list_empty(&queue->irqqueue)) nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer, queue); else nextbuf = NULL; spin_unlock_irqrestore(&queue->irqlock, flags); buf->state = buf->error ? VB2_BUF_STATE_ERROR : UVC_BUF_STATE_DONE; vb2_set_plane_payload(&buf->buf, 0, buf->bytesused); vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE); return nextbuf; }
vidyaravipati/net-next-rocker
drivers/media/usb/uvc/uvc_queue.c
C
gpl-2.0
10,491
/** * @file * * Implement a modal form. * * @see modal.inc for documentation. * * This javascript relies on the CTools ajax responder. */ (function ($) { // Make sure our objects are defined. Drupal.CTools = Drupal.CTools || {}; Drupal.CTools.Modal = Drupal.CTools.Modal || {}; /** * Display the modal * * @todo -- document the settings. */ Drupal.CTools.Modal.show = function(choice) { var opts = {}; if (choice && typeof choice == 'string' && Drupal.settings[choice]) { // This notation guarantees we are actually copying it. $.extend(true, opts, Drupal.settings[choice]); } else if (choice) { $.extend(true, opts, choice); } var defaults = { modalTheme: 'CToolsModalDialog', throbberTheme: 'CToolsModalThrobber', animation: 'show', animationSpeed: 'fast', modalSize: { type: 'scale', width: .8, height: .8, addWidth: 0, addHeight: 0, // How much to remove from the inner content to make space for the // theming. contentRight: 25, contentBottom: 45 }, modalOptions: { opacity: .55, background: '#fff' } }; var settings = {}; $.extend(true, settings, defaults, Drupal.settings.CToolsModal, opts); if (Drupal.CTools.Modal.currentSettings && Drupal.CTools.Modal.currentSettings != settings) { Drupal.CTools.Modal.modal.remove(); Drupal.CTools.Modal.modal = null; } Drupal.CTools.Modal.currentSettings = settings; var resize = function(e) { // When creating the modal, it actually exists only in a theoretical // place that is not in the DOM. But once the modal exists, it is in the // DOM so the context must be set appropriately. var context = e ? document : Drupal.CTools.Modal.modal; if (Drupal.CTools.Modal.currentSettings.modalSize.type == 'scale') { var width = $(window).width() * Drupal.CTools.Modal.currentSettings.modalSize.width; var height = $(window).height() * Drupal.CTools.Modal.currentSettings.modalSize.height; } else { var width = Drupal.CTools.Modal.currentSettings.modalSize.width; var height = Drupal.CTools.Modal.currentSettings.modalSize.height; } // Use the additionol pixels for creating the width and height. $('div.ctools-modal-content', context).css({ 'width': width + Drupal.CTools.Modal.currentSettings.modalSize.addWidth + 'px', 'height': height + Drupal.CTools.Modal.currentSettings.modalSize.addHeight + 'px' }); $('div.ctools-modal-content .modal-content', context).css({ 'width': (width - Drupal.CTools.Modal.currentSettings.modalSize.contentRight) + 'px', 'height': (height - Drupal.CTools.Modal.currentSettings.modalSize.contentBottom) + 'px' }); } if (!Drupal.CTools.Modal.modal) { Drupal.CTools.Modal.modal = $(Drupal.theme(settings.modalTheme)); if (settings.modalSize.type == 'scale') { $(window).bind('resize', resize); } } resize(); $('span.modal-title', Drupal.CTools.Modal.modal).html(Drupal.CTools.Modal.currentSettings.loadingText); Drupal.CTools.Modal.modalContent(Drupal.CTools.Modal.modal, settings.modalOptions, settings.animation, settings.animationSpeed); $('#modalContent .modal-content').html(Drupal.theme(settings.throbberTheme)); }; /** * Hide the modal */ Drupal.CTools.Modal.dismiss = function() { if (Drupal.CTools.Modal.modal) { Drupal.CTools.Modal.unmodalContent(Drupal.CTools.Modal.modal); } }; /** * Provide the HTML to create the modal dialog. */ Drupal.theme.prototype.CToolsModalDialog = function () { var html = '' html += ' <div id="ctools-modal">' html += ' <div class="ctools-modal-content">' // panels-modal-content html += ' <div class="modal-header">'; html += ' <a class="close" href="#">'; html += Drupal.CTools.Modal.currentSettings.closeText + Drupal.CTools.Modal.currentSettings.closeImage; html += ' </a>'; html += ' <span id="modal-title" class="modal-title">&nbsp;</span>'; html += ' </div>'; html += ' <div id="modal-content" class="modal-content">'; html += ' </div>'; html += ' </div>'; html += ' </div>'; return html; } /** * Provide the HTML to create the throbber. */ Drupal.theme.prototype.CToolsModalThrobber = function () { var html = ''; html += ' <div id="modal-throbber">'; html += ' <div class="modal-throbber-wrapper">'; html += Drupal.CTools.Modal.currentSettings.throbber; html += ' </div>'; html += ' </div>'; return html; }; /** * Figure out what settings string to use to display a modal. */ Drupal.CTools.Modal.getSettings = function (object) { var match = $(object).attr('class').match(/ctools-modal-(\S+)/); if (match) { return match[1]; } } /** * Click function for modals that can be cached. */ Drupal.CTools.Modal.clickAjaxCacheLink = function () { Drupal.CTools.Modal.show(Drupal.CTools.Modal.getSettings(this)); return Drupal.CTools.AJAX.clickAJAXCacheLink.apply(this); }; /** * Handler to prepare the modal for the response */ Drupal.CTools.Modal.clickAjaxLink = function () { Drupal.CTools.Modal.show(Drupal.CTools.Modal.getSettings(this)); return false; }; /** * Submit responder to do an AJAX submit on all modal forms. */ Drupal.CTools.Modal.submitAjaxForm = function(e) { var $form = $(this); var url = $form.attr('action'); setTimeout(function() { Drupal.CTools.AJAX.ajaxSubmit($form, url); }, 1); return false; } /** * Bind links that will open modals to the appropriate function. */ Drupal.behaviors.ZZCToolsModal = { attach: function(context) { // Bind links // Note that doing so in this order means that the two classes can be // used together safely. /* * @todo remimplement the warm caching feature $('a.ctools-use-modal-cache', context).once('ctools-use-modal', function() { $(this).click(Drupal.CTools.Modal.clickAjaxCacheLink); Drupal.CTools.AJAX.warmCache.apply(this); }); */ $('area.ctools-use-modal, a.ctools-use-modal', context).once('ctools-use-modal', function() { var $this = $(this); $this.click(Drupal.CTools.Modal.clickAjaxLink); // Create a drupal ajax object var element_settings = {}; if ($this.attr('href')) { element_settings.url = $this.attr('href'); element_settings.event = 'click'; element_settings.progress = { type: 'throbber' }; } var base = $this.attr('href'); Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); }); // Bind buttons $('input.ctools-use-modal, button.ctools-use-modal', context).once('ctools-use-modal', function() { var $this = $(this); $this.click(Drupal.CTools.Modal.clickAjaxLink); var button = this; var element_settings = {}; // AJAX submits specified in this manner automatically submit to the // normal form action. element_settings.url = Drupal.CTools.Modal.findURL(this); element_settings.event = 'click'; var base = $this.attr('id'); Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); // Make sure changes to settings are reflected in the URL. $('.' + $(button).attr('id') + '-url').change(function() { Drupal.ajax[base].options.url = Drupal.CTools.Modal.findURL(button); }); }); // Bind our custom event to the form submit $('#modal-content form', context).once('ctools-use-modal', function() { var $this = $(this); var element_settings = {}; element_settings.url = $this.attr('action'); element_settings.event = 'submit'; element_settings.progress = { 'type': 'throbber' } var base = $this.attr('id'); Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); Drupal.ajax[base].form = $this; $('input[type=submit], button', this).click(function(event) { Drupal.ajax[base].element = this; this.form.clk = this; // An empty event means we were triggered via .click() and // in jquery 1.4 this won't trigger a submit. if (event.bubbles == undefined) { $(this.form).trigger('submit'); return false; } }); }); // Bind a click handler to allow elements with the 'ctools-close-modal' // class to close the modal. $('.ctools-close-modal', context).once('ctools-close-modal') .click(function() { Drupal.CTools.Modal.dismiss(); return false; }); } }; // The following are implementations of AJAX responder commands. /** * AJAX responder command to place HTML within the modal. */ Drupal.CTools.Modal.modal_display = function(ajax, response, status) { if ($('#modalContent').length == 0) { Drupal.CTools.Modal.show(Drupal.CTools.Modal.getSettings(ajax.element)); } $('#modal-title').html(response.title); // Simulate an actual page load by scrolling to the top after adding the // content. This is helpful for allowing users to see error messages at the // top of a form, etc. $('#modal-content').html(response.output).scrollTop(0); Drupal.attachBehaviors(); } /** * AJAX responder command to dismiss the modal. */ Drupal.CTools.Modal.modal_dismiss = function(command) { Drupal.CTools.Modal.dismiss(); $('link.ctools-temporary-css').remove(); } /** * Display loading */ //Drupal.CTools.AJAX.commands.modal_loading = function(command) { Drupal.CTools.Modal.modal_loading = function(command) { Drupal.CTools.Modal.modal_display({ output: Drupal.theme(Drupal.CTools.Modal.currentSettings.throbberTheme), title: Drupal.CTools.Modal.currentSettings.loadingText }); } /** * Find a URL for an AJAX button. * * The URL for this gadget will be composed of the values of items by * taking the ID of this item and adding -url and looking for that * class. They need to be in the form in order since we will * concat them all together using '/'. */ Drupal.CTools.Modal.findURL = function(item) { var url = ''; var url_class = '.' + $(item).attr('id') + '-url'; $(url_class).each( function() { var $this = $(this); if (url && $this.val()) { url += '/'; } url += $this.val(); }); return url; }; /** * modalContent * @param content string to display in the content box * @param css obj of css attributes * @param animation (fadeIn, slideDown, show) * @param speed (valid animation speeds slow, medium, fast or # in ms) */ Drupal.CTools.Modal.modalContent = function(content, css, animation, speed) { // If our animation isn't set, make it just show/pop if (!animation) { animation = 'show'; } else { // If our animation isn't "fadeIn" or "slideDown" then it always is show if (animation != 'fadeIn' && animation != 'slideDown') { animation = 'show'; } } if (!speed) { speed = 'fast'; } // Build our base attributes and allow them to be overriden css = jQuery.extend({ position: 'absolute', left: '0px', margin: '0px', background: '#000', opacity: '.55' }, css); // Add opacity handling for IE. css.filter = 'alpha(opacity=' + (100 * css.opacity) + ')'; content.hide(); // if we already ahve a modalContent, remove it if ( $('#modalBackdrop')) $('#modalBackdrop').remove(); if ( $('#modalContent')) $('#modalContent').remove(); // position code lifted from http://www.quirksmode.org/viewport/compatibility.html if (self.pageYOffset) { // all except Explorer var wt = self.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict var wt = document.documentElement.scrollTop; } else if (document.body) { // all other Explorers var wt = document.body.scrollTop; } // Get our dimensions // Get the docHeight and (ugly hack) add 50 pixels to make sure we dont have a *visible* border below our div var docHeight = $(document).height() + 50; var docWidth = $(document).width(); var winHeight = $(window).height(); var winWidth = $(window).width(); if( docHeight < winHeight ) docHeight = winHeight; // Create our divs $('body').append('<div id="modalBackdrop" style="z-index: 1000; display: none;"></div><div id="modalContent" style="z-index: 1001; position: absolute;">' + $(content).html() + '</div>'); // Keyboard and focus event handler ensures focus stays on modal elements only modalEventHandler = function( event ) { target = null; if ( event ) { //Mozilla target = event.target; } else { //IE event = window.event; target = event.srcElement; } var parents = $(target).parents().get(); for (var i = 0; i < parents.length; ++i) { var position = $(parents[i]).css('position'); if (position == 'absolute' || position == 'fixed') { return true; } } if( $(target).filter('*:visible').parents('#modalContent').size()) { // allow the event only if target is a visible child node of #modalContent return true; } if ( $('#modalContent')) $('#modalContent').get(0).focus(); return false; }; $('body').bind( 'focus', modalEventHandler ); $('body').bind( 'keypress', modalEventHandler ); // Create our content div, get the dimensions, and hide it var modalContent = $('#modalContent').css('top','-1000px'); var mdcTop = wt + ( winHeight / 2 ) - ( modalContent.outerHeight() / 2); var mdcLeft = ( winWidth / 2 ) - ( modalContent.outerWidth() / 2); $('#modalBackdrop').css(css).css('top', 0).css('height', docHeight + 'px').css('width', docWidth + 'px').show(); modalContent.css({top: mdcTop + 'px', left: mdcLeft + 'px'}).hide()[animation](speed); // Bind a click for closing the modalContent modalContentClose = function(){close(); return false;}; $('.close').bind('click', modalContentClose); // Bind a keypress on escape for closing the modalContent modalEventEscapeCloseHandler = function(event) { if (event.keyCode == 27) { close(); return false; } }; $(document).bind('keydown', modalEventEscapeCloseHandler); // Close the open modal content and backdrop function close() { // Unbind the events $(window).unbind('resize', modalContentResize); $('body').unbind( 'focus', modalEventHandler); $('body').unbind( 'keypress', modalEventHandler ); $('.close').unbind('click', modalContentClose); $('body').unbind('keypress', modalEventEscapeCloseHandler); $(document).trigger('CToolsDetachBehaviors', $('#modalContent')); // Set our animation parameters and use them if ( animation == 'fadeIn' ) animation = 'fadeOut'; if ( animation == 'slideDown' ) animation = 'slideUp'; if ( animation == 'show' ) animation = 'hide'; // Close the content modalContent.hide()[animation](speed); // Remove the content $('#modalContent').remove(); $('#modalBackdrop').remove(); }; // Move and resize the modalBackdrop and modalContent on resize of the window modalContentResize = function(){ // Get our heights var docHeight = $(document).height(); var docWidth = $(document).width(); var winHeight = $(window).height(); var winWidth = $(window).width(); if( docHeight < winHeight ) docHeight = winHeight; // Get where we should move content to var modalContent = $('#modalContent'); var mdcTop = ( winHeight / 2 ) - ( modalContent.outerHeight() / 2); var mdcLeft = ( winWidth / 2 ) - ( modalContent.outerWidth() / 2); // Apply the changes $('#modalBackdrop').css('height', docHeight + 'px').css('width', docWidth + 'px').show(); modalContent.css('top', mdcTop + 'px').css('left', mdcLeft + 'px').show(); }; $(window).bind('resize', modalContentResize); $('#modalContent').focus(); }; /** * unmodalContent * @param content (The jQuery object to remove) * @param animation (fadeOut, slideUp, show) * @param speed (valid animation speeds slow, medium, fast or # in ms) */ Drupal.CTools.Modal.unmodalContent = function(content, animation, speed) { // If our animation isn't set, make it just show/pop if (!animation) { var animation = 'show'; } else { // If our animation isn't "fade" then it always is show if (( animation != 'fadeOut' ) && ( animation != 'slideUp')) animation = 'show'; } // Set a speed if we dont have one if ( !speed ) var speed = 'fast'; // Unbind the events we bound $(window).unbind('resize', modalContentResize); $('body').unbind('focus', modalEventHandler); $('body').unbind('keypress', modalEventHandler); $('.close').unbind('click', modalContentClose); $(document).trigger('CToolsDetachBehaviors', $('#modalContent')); // jQuery magic loop through the instances and run the animations or removal. content.each(function(){ if ( animation == 'fade' ) { $('#modalContent').fadeOut(speed, function() { $('#modalBackdrop').fadeOut(speed, function() { $(this).remove(); }); $(this).remove(); }); } else { if ( animation == 'slide' ) { $('#modalContent').slideUp(speed,function() { $('#modalBackdrop').slideUp(speed, function() { $(this).remove(); }); $(this).remove(); }); } else { $('#modalContent').remove(); $('#modalBackdrop').remove(); } } }); }; $(function() { Drupal.ajax.prototype.commands.modal_display = Drupal.CTools.Modal.modal_display; Drupal.ajax.prototype.commands.modal_dismiss = Drupal.CTools.Modal.modal_dismiss; }); })(jQuery);
mhettler/accuratelockandhardware.com
sites/all/modules/contrib/ctools/js/modal.js
JavaScript
gpl-2.0
18,535
/* * OpenRISC irq.c * * Linux architectural port borrowing liberally from similar works of * others. All original copyrights apply as per the original source * declaration. * * Modifications for the OpenRISC architecture: * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/interrupt.h> #include <linux/init.h> #include <linux/ftrace.h> #include <linux/irq.h> #include <linux/irqchip.h> #include <linux/export.h> #include <linux/irqflags.h> /* read interrupt enabled status */ unsigned long arch_local_save_flags(void) { return mfspr(SPR_SR) & (SPR_SR_IEE|SPR_SR_TEE); } EXPORT_SYMBOL(arch_local_save_flags); /* set interrupt enabled status */ void arch_local_irq_restore(unsigned long flags) { mtspr(SPR_SR, ((mfspr(SPR_SR) & ~(SPR_SR_IEE|SPR_SR_TEE)) | flags)); } EXPORT_SYMBOL(arch_local_irq_restore); void __init init_IRQ(void) { irqchip_init(); } static void (*handle_arch_irq)(struct pt_regs *); void __init set_handle_irq(void (*handle_irq)(struct pt_regs *)) { handle_arch_irq = handle_irq; } void __irq_entry do_IRQ(struct pt_regs *regs) { handle_arch_irq(regs); }
andrewoko-odion/linux
arch/openrisc/kernel/irq.c
C
gpl-2.0
1,396
/* drivers/input/touchscreen/gt9xx_update.c * * 2010 - 2012 Goodix Technology. * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be a reference * to you, when you are integrating the GOODiX's CTP IC into your system, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * Latest Version:1.6 * Author: andrew@goodix.com * Revision Record: * V1.0: * first release. By Andrew, 2012/08/31 * V1.2: * add force update,GT9110P pid map. By Andrew, 2012/10/15 * V1.4: * 1. add config auto update function; * 2. modify enter_update_mode; * 3. add update file cal checksum. * By Andrew, 2012/12/12 * V1.6: * 1. replace guitar_client with i2c_connect_client; * 2. support firmware header array update. * By Meta, 2013/03/11 */ #include "gt9xx.h" #include <linux/firmware.h> #include <linux/workqueue.h> #include <linux/kernel.h> #define FIRMWARE_NAME_LEN_MAX 256 #define GUP_REG_HW_INFO 0x4220 #define GUP_REG_FW_MSG 0x41E4 #define GUP_REG_PID_VID 0x8140 #define GOODIX_FIRMWARE_FILE_NAME "_goodix_update_.bin" #define GOODIX_CONFIG_FILE_NAME "_goodix_config_.cfg" #define FW_HEAD_LENGTH 14 #define FW_SECTION_LENGTH 0x2000 #define FW_DSP_ISP_LENGTH 0x1000 #define FW_DSP_LENGTH 0x1000 #define FW_BOOT_LENGTH 0x800 #define PACK_SIZE 256 #define MAX_FRAME_CHECK_TIME 5 #define _bRW_MISCTL__SRAM_BANK 0x4048 #define _bRW_MISCTL__MEM_CD_EN 0x4049 #define _bRW_MISCTL__CACHE_EN 0x404B #define _bRW_MISCTL__TMR0_EN 0x40B0 #define _rRW_MISCTL__SWRST_B0_ 0x4180 #define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184 #define _rRW_MISCTL__BOOTCTL_B0_ 0x4190 #define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218 #define _rRW_MISCTL__BOOT_CTL_ 0x5094 #define FAIL 0 #define SUCCESS 1 struct st_fw_head { u8 hw_info[4]; /* hardware info */ u8 pid[8]; /* product id */ u16 vid; /* version id */ } __packed; struct st_update_msg { u8 force_update; u8 fw_flag; bool need_free; u8 *fw_data; u32 fw_len; struct st_fw_head ic_fw_msg; }; static struct st_update_msg update_msg; u16 show_len; u16 total_len; u8 got_file_flag; u8 searching_file; /******************************************************* Function: Read data from the i2c slave device. Input: client: i2c device. buf[0~1]: read start address. buf[2~len-1]: read data buffer. len: GTP_ADDR_LENGTH + read bytes count Output: numbers of i2c_msgs to transfer: 2: succeed, otherwise: failed *********************************************************/ static s32 gup_i2c_read(struct i2c_client *client, u8 *buf, s32 len) { s32 ret = -1; u8 retries = 0; struct i2c_msg msgs[2] = { { .flags = !I2C_M_RD, .addr = client->addr, .len = GTP_ADDR_LENGTH, .buf = &buf[0], }, { .flags = I2C_M_RD, .addr = client->addr, .len = len - GTP_ADDR_LENGTH, .buf = &buf[GTP_ADDR_LENGTH], }, }; while (retries < 5) { ret = i2c_transfer(client->adapter, msgs, 2); if (ret == 2) break; retries++; } if (retries == 5) { dev_err(&client->dev, "I2C read retry limit over.\n"); ret = -EIO; } return ret; } /******************************************************* Function: Write data to the i2c slave device. Input: client: i2c device. buf[0~1]: write start address. buf[2~len-1]: data buffer len: GTP_ADDR_LENGTH + write bytes count Output: numbers of i2c_msgs to transfer: 1: succeed, otherwise: failed *********************************************************/ s32 gup_i2c_write(struct i2c_client *client, u8 *buf, s32 len) { s32 ret = -1; u8 retries = 0; struct i2c_msg msg = { .flags = !I2C_M_RD, .addr = client->addr, .len = len, .buf = buf, }; while (retries < 5) { ret = i2c_transfer(client->adapter, &msg, 1); if (ret == 1) break; retries++; } if (retries == 5) { dev_err(&client->dev, "I2C write retry limit over.\n"); ret = -EIO; } return ret; } static s32 gup_init_panel(struct goodix_ts_data *ts) { struct i2c_client *client = ts->client; u8 *config_data; s32 ret = 0; s32 i = 0; u8 check_sum = 0; u8 opr_buf[16]; u8 sensor_id = 0; for (i = 0; i < GOODIX_MAX_CFG_GROUP; i++) if (ts->pdata->config_data_len[i]) break; if (i == GOODIX_MAX_CFG_GROUP) { sensor_id = 0; } else { ret = gtp_i2c_read_dbl_check(client, GTP_REG_SENSOR_ID, &sensor_id, 1); if (SUCCESS == ret) { if (sensor_id >= GOODIX_MAX_CFG_GROUP) { pr_err("Invalid sensor_id(0x%02X), No Config Sent!", sensor_id); return -EINVAL; } } else { pr_err("Failed to get sensor_id, No config sent!"); return -EINVAL; } } pr_debug("Sensor ID selected: %d", sensor_id); if (ts->pdata->config_data_len[sensor_id] < GTP_CONFIG_MIN_LENGTH || !ts->pdata->config_data_len[sensor_id]) { pr_err("Sensor_ID(%d) matches with NULL or INVALID CONFIG GROUP!", sensor_id); return -EINVAL; } ret = gtp_i2c_read_dbl_check(client, GTP_REG_CONFIG_DATA, &opr_buf[0], 1); if (ret == SUCCESS) { pr_debug("CFG_GROUP%d Config Version: %d, IC Config Version: %d", sensor_id + 1, ts->pdata->config_data[sensor_id][0], opr_buf[0]); ts->pdata->config_data[sensor_id][0] = opr_buf[0]; ts->fixed_cfg = 0; } else { pr_err("Failed to get ic config version!No config sent!"); return -EINVAL; } config_data = ts->pdata->config_data[sensor_id]; ts->config_data = ts->pdata->config_data[sensor_id]; ts->gtp_cfg_len = ts->pdata->config_data_len[sensor_id]; pr_debug("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x", ts->abs_x_max, ts->abs_y_max, ts->int_trigger_type); config_data[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH; config_data[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8); config_data[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT; config_data[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8); if (GTP_INT_TRIGGER == 0) /* RISING */ config_data[TRIGGER_LOC] &= 0xfe; else if (GTP_INT_TRIGGER == 1) /* FALLING */ config_data[TRIGGER_LOC] |= 0x01; check_sum = 0; for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++) check_sum += config_data[i]; config_data[ts->gtp_cfg_len] = (~check_sum) + 1; ret = gtp_send_cfg(ts); if (ret < 0) pr_err("Send config error."); ts->config_data = NULL; ts->gtp_cfg_len = 0; msleep(20); return 0; } static u8 gup_get_ic_msg(struct i2c_client *client, u16 addr, u8 *msg, s32 len) { u8 i = 0; msg[0] = (addr >> 8) & 0xff; msg[1] = addr & 0xff; for (i = 0; i < 5; i++) if (gup_i2c_read(client, msg, GTP_ADDR_LENGTH + len) > 0) break; if (i >= 5) { pr_err("Read data from 0x%02x%02x failed!", msg[0], msg[1]); return FAIL; } return SUCCESS; } static u8 gup_set_ic_msg(struct i2c_client *client, u16 addr, u8 val) { u8 i = 0; u8 msg[3] = { (addr >> 8) & 0xff, addr & 0xff, val, }; for (i = 0; i < 5; i++) if (gup_i2c_write(client, msg, GTP_ADDR_LENGTH + 1) > 0) break; if (i >= 5) { pr_err("Set data to 0x%02x%02x failed!", msg[0], msg[1]); return FAIL; } return SUCCESS; } static u8 gup_get_ic_fw_msg(struct i2c_client *client) { s32 ret = -1; u8 retry = 0; u8 buf[16]; u8 i; /* step1:get hardware info */ ret = gtp_i2c_read_dbl_check(client, GUP_REG_HW_INFO, &buf[GTP_ADDR_LENGTH], 4); if (ret == FAIL) { pr_err("get hw_info failed,exit"); return FAIL; } /* buf[2~5]: 00 06 90 00 */ /* hw_info: 00 90 06 00 */ for (i = 0; i < 4; i++) update_msg.ic_fw_msg.hw_info[i] = buf[GTP_ADDR_LENGTH + 3 - i]; pr_debug("IC Hardware info:%02x%02x%02x%02x", update_msg.ic_fw_msg.hw_info[0], update_msg.ic_fw_msg.hw_info[1], update_msg.ic_fw_msg.hw_info[2], update_msg.ic_fw_msg.hw_info[3]); /* step2:get firmware message */ for (retry = 0; retry < 2; retry++) { ret = gup_get_ic_msg(client, GUP_REG_FW_MSG, buf, 1); if (ret == FAIL) { pr_err("Read firmware message fail."); return ret; } update_msg.force_update = buf[GTP_ADDR_LENGTH]; if ((0xBE != update_msg.force_update) && (!retry)) { pr_info("The check sum in ic is error."); pr_info("The IC will be updated by force."); continue; } break; } pr_debug("IC force update flag:0x%x", update_msg.force_update); /* step3:get pid & vid */ ret = gtp_i2c_read_dbl_check(client, GUP_REG_PID_VID, &buf[GTP_ADDR_LENGTH], 6); if (ret == FAIL) { pr_err("get pid & vid failed,exit"); return FAIL; } memset(update_msg.ic_fw_msg.pid, 0, sizeof(update_msg.ic_fw_msg.pid)); memcpy(update_msg.ic_fw_msg.pid, &buf[GTP_ADDR_LENGTH], 4); pr_debug("IC Product id:%s", update_msg.ic_fw_msg.pid); /* GT9XX PID MAPPING |-----FLASH-----RAM-----| |------918------918-----| |------968------968-----| |------913------913-----| |------913P-----913P----| |------927------927-----| |------927P-----927P----| |------9110-----9110----| |------9110P----9111----|*/ if (update_msg.ic_fw_msg.pid[0] != 0) { if (!memcmp(update_msg.ic_fw_msg.pid, "9111", 4)) { pr_debug("IC Mapping Product id:%s", update_msg.ic_fw_msg.pid); memcpy(update_msg.ic_fw_msg.pid, "9110P", 5); } } update_msg.ic_fw_msg.vid = buf[GTP_ADDR_LENGTH + 4] + (buf[GTP_ADDR_LENGTH + 5] << 8); pr_debug("IC version id:%04x", update_msg.ic_fw_msg.vid); return SUCCESS; } s32 gup_enter_update_mode(struct i2c_client *client) { s32 ret = -1; u8 retry = 0; u8 rd_buf[3]; struct goodix_ts_data *ts = i2c_get_clientdata(client); /* step1:RST output low last at least 2ms */ gpio_direction_output(ts->pdata->reset_gpio, 0); usleep(20000); /* step2:select I2C slave addr,INT:0--0xBA;1--0x28. */ gpio_direction_output(ts->pdata->irq_gpio, (client->addr == GTP_I2C_ADDRESS_HIGH)); msleep(20); /* step3:RST output high reset guitar */ gpio_direction_output(ts->pdata->reset_gpio, 1); /* 20121211 modify start */ msleep(20); while (retry++ < 200) { /* step4:Hold ss51 & dsp */ ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); if (ret <= 0) { pr_debug("Hold ss51 & dsp I2C error,retry:%d", retry); continue; } /* step5:Confirm hold */ ret = gup_get_ic_msg(client, _rRW_MISCTL__SWRST_B0_, rd_buf, 1); if (ret <= 0) { pr_debug("Hold ss51 & dsp I2C error,retry:%d", retry); continue; } if (rd_buf[GTP_ADDR_LENGTH] == 0x0C) { pr_debug("Hold ss51 & dsp confirm SUCCESS"); break; } pr_debug("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf[GTP_ADDR_LENGTH]); } if (retry >= 200) { pr_err("Enter update Hold ss51 failed."); return FAIL; } /* step6:DSP_CK and DSP_ALU_CK PowerOn */ ret = gup_set_ic_msg(client, 0x4010, 0x00); /* 20121211 modify end */ return ret; } void gup_leave_update_mode(struct i2c_client *client) { struct goodix_ts_data *ts = i2c_get_clientdata(client); gpio_direction_input(ts->pdata->irq_gpio); pr_debug("reset chip."); gtp_reset_guitar(ts, 20); } /* Get the correct nvram data The correct conditions: 1. the hardware info is the same 2. the product id is the same 3. the firmware version in update file is greater than the firmware version in ic or the check sum in ic is wrong Update Conditions: 1. Same hardware info 2. Same PID 3. File PID > IC PID Force Update Conditions: 1. Wrong ic firmware checksum 2. INVALID IC PID or VID 3. IC PID == 91XX || File PID == 91XX */ static u8 gup_enter_update_judge(struct i2c_client *client, struct st_fw_head *fw_head) { u16 u16_tmp; s32 i = 0; u16_tmp = fw_head->vid; fw_head->vid = (u16)(u16_tmp>>8) + (u16)(u16_tmp<<8); pr_debug("FILE HARDWARE INFO:%02x%02x%02x%02x", fw_head->hw_info[0], fw_head->hw_info[1], fw_head->hw_info[2], fw_head->hw_info[3]); pr_debug("FILE PID:%s", fw_head->pid); pr_debug("FILE VID:%04x", fw_head->vid); pr_debug("IC HARDWARE INFO:%02x%02x%02x%02x", update_msg.ic_fw_msg.hw_info[0], update_msg.ic_fw_msg.hw_info[1], update_msg.ic_fw_msg.hw_info[2], update_msg.ic_fw_msg.hw_info[3]); pr_debug("IC PID:%s", update_msg.ic_fw_msg.pid); pr_debug("IC VID:%04x", update_msg.ic_fw_msg.vid); /* First two conditions */ if (!memcmp(fw_head->hw_info, update_msg.ic_fw_msg.hw_info, sizeof(update_msg.ic_fw_msg.hw_info))) { pr_debug("Get the same hardware info."); if (update_msg.force_update != 0xBE) { pr_info("FW chksum error,need enter update."); return SUCCESS; } /* 20130523 start */ if (strlen(update_msg.ic_fw_msg.pid) < 3) { pr_info("Illegal IC pid, need enter update"); return SUCCESS; } else { for (i = 0; i < 3; i++) { if ((update_msg.ic_fw_msg.pid[i] < 0x30) || (update_msg.ic_fw_msg.pid[i] > 0x39)) { pr_info("Illegal IC pid, out of bound, need enter update"); return SUCCESS; } } } /* 20130523 end */ if ((!memcmp(fw_head->pid, update_msg.ic_fw_msg.pid, (strlen(fw_head->pid) < 3 ? 3 : strlen(fw_head->pid)))) || (!memcmp(update_msg.ic_fw_msg.pid, "91XX", 4)) || (!memcmp(fw_head->pid, "91XX", 4))) { if (!memcmp(fw_head->pid, "91XX", 4)) pr_debug("Force none same pid update mode."); else pr_debug("Get the same pid."); /* The third condition */ if (fw_head->vid > update_msg.ic_fw_msg.vid) { pr_info("Need enter update."); return SUCCESS; } pr_err("Don't meet the third condition."); pr_err("File VID <= Ic VID, update aborted!"); } else { pr_err("File PID != Ic PID, update aborted!"); } } else { pr_err("Different Hardware, update aborted!"); } return FAIL; } static s8 gup_update_config(struct i2c_client *client, const struct firmware *cfg) { s32 ret = 0; s32 i = 0; s32 file_cfg_len = 0; u32 chip_cfg_len = 0; s32 count = 0; u8 *buf; u8 *file_config; u8 pid[8]; u8 high, low; if (!cfg || !cfg->data) { pr_err("No need to upgrade config!"); return FAIL; } ret = gup_get_ic_msg(client, GUP_REG_PID_VID, pid, 6); if (ret == FAIL) { pr_err("Read product id & version id fail."); return FAIL; } pid[5] = '\0'; pr_debug("update cfg get pid:%s", &pid[GTP_ADDR_LENGTH]); chip_cfg_len = 186; if (!memcmp(&pid[GTP_ADDR_LENGTH], "968", 3) || !memcmp(&pid[GTP_ADDR_LENGTH], "910", 3) || !memcmp(&pid[GTP_ADDR_LENGTH], "960", 3)) { chip_cfg_len = 228; } pr_debug("config file ASCII len:%d", cfg->size); pr_debug("need config binary len:%d", chip_cfg_len); if ((cfg->size + 5) < chip_cfg_len * 5) { pr_err("Config length error"); return -EINVAL; } buf = devm_kzalloc(&client->dev, cfg->size, GFP_KERNEL); if (!buf) { dev_err(&client->dev, "Memory allocation failed for buf."); return -ENOMEM; } file_config = devm_kzalloc(&client->dev, chip_cfg_len + GTP_ADDR_LENGTH, GFP_KERNEL); if (!file_config) { dev_err(&client->dev, "Memory allocation failed."); return -ENOMEM; } pr_debug("Delete illgal charactor."); for (i = 0, count = 0; i < cfg->size; i++) { if (cfg->data[i] == ' ' || cfg->data[i] == '\r' || cfg->data[i] == '\n') continue; buf[count++] = cfg->data[i]; } pr_debug("Ascii to hex."); file_config[0] = GTP_REG_CONFIG_DATA >> 8; file_config[1] = GTP_REG_CONFIG_DATA & 0xff; for (i = 0, file_cfg_len = GTP_ADDR_LENGTH; i < count; i = i + 5) { if ((buf[i] == '0') && ((buf[i + 1] == 'x') || (buf[i + 1] == 'X'))) { ret = hex2bin(&high, &buf[i + 2], 1); if (ret) { pr_err("Failed to convert high address from hex2bin"); return ret; } ret = hex2bin(&low, &buf[i + 3], 1); if (ret) { pr_err("Failed to convert low address from hex2bin"); return ret; } if ((high == 0xFF) || (low == 0xFF)) { ret = 0; pr_err("Illegal config file."); return ret; } file_config[file_cfg_len++] = (high<<4) + low; } else { ret = 0; pr_err("Illegal config file."); return ret; } } i = 0; while (i++ < 5) { ret = gup_i2c_write(client, file_config, file_cfg_len); if (ret > 0) { pr_info("Send config SUCCESS."); break; } pr_err("Send config i2c error."); } return ret; } static s32 gup_get_firmware_file(struct i2c_client *client, struct st_update_msg *msg, u8 *path) { s32 ret; const struct firmware *fw = NULL; ret = request_firmware(&fw, path, &client->dev); if (ret < 0) { dev_info(&client->dev, "Cannot get firmware - %s (%d)\n", path, ret); return -EEXIST; } dev_dbg(&client->dev, "Config File: %s size=%d", path, fw->size); msg->fw_data = devm_kzalloc(&client->dev, fw->size, GFP_KERNEL); if (!msg->fw_data) { dev_err(&client->dev, "Not enough memory for firmware data."); release_firmware(fw); return -ENOMEM; } memcpy(msg->fw_data, fw->data, fw->size); msg->fw_len = fw->size; msg->need_free = true; release_firmware(fw); return 0; } static u8 gup_check_firmware_name(struct i2c_client *client, u8 **path_p) { u8 len; u8 *fname; if (!(*path_p)) { *path_p = GOODIX_FIRMWARE_FILE_NAME; return 0; } len = strnlen(*path_p, FIRMWARE_NAME_LEN_MAX); if (len >= FIRMWARE_NAME_LEN_MAX) { dev_err(&client->dev, "firmware name too long!"); return -EINVAL; } fname = strrchr(*path_p, '/'); if (fname) { fname = fname + 1; *path_p = fname; } return 0; } static u8 gup_check_update_file(struct i2c_client *client, struct st_fw_head *fw_head, u8 *path) { s32 ret = 0; s32 i = 0; s32 fw_checksum = 0; u16 temp; const struct firmware *fw = NULL; ret = request_firmware(&fw, GOODIX_CONFIG_FILE_NAME, &client->dev); if (ret < 0) { dev_info(&client->dev, "Cannot get config file - %s (%d)\n", GOODIX_CONFIG_FILE_NAME, ret); } else { dev_dbg(&client->dev, "Update config File: %s", GOODIX_CONFIG_FILE_NAME); ret = gup_update_config(client, fw); if (ret <= 0) dev_err(&client->dev, "Update config failed."); release_firmware(fw); } update_msg.need_free = false; update_msg.fw_len = 0; if (gup_check_firmware_name(client, &path)) goto load_failed; if (gup_get_firmware_file(client, &update_msg, path)) goto load_failed; memcpy(fw_head, update_msg.fw_data, FW_HEAD_LENGTH); /* check firmware legality */ fw_checksum = 0; for (i = 0; i < FW_SECTION_LENGTH * 4 + FW_DSP_ISP_LENGTH + FW_DSP_LENGTH + FW_BOOT_LENGTH; i += 2) { temp = (update_msg.fw_data[FW_HEAD_LENGTH + i] << 8) + update_msg.fw_data[FW_HEAD_LENGTH + i + 1]; fw_checksum += temp; } pr_debug("firmware checksum:%x", fw_checksum & 0xFFFF); if (fw_checksum & 0xFFFF) { dev_err(&client->dev, "Illegal firmware file."); goto load_failed; } return SUCCESS; load_failed: if (update_msg.need_free) { devm_kfree(&client->dev, update_msg.fw_data); update_msg.need_free = false; } return FAIL; } static u8 gup_burn_proc(struct i2c_client *client, u8 *burn_buf, u16 start_addr, u16 total_length) { s32 ret = 0; u16 burn_addr = start_addr; u16 frame_length = 0; u16 burn_length = 0; u8 wr_buf[PACK_SIZE + GTP_ADDR_LENGTH]; u8 rd_buf[PACK_SIZE + GTP_ADDR_LENGTH]; u8 retry = 0; pr_debug("Begin burn %dk data to addr 0x%x", (total_length / 1024), start_addr); while (burn_length < total_length) { pr_debug("B/T:%04d/%04d", burn_length, total_length); frame_length = ((total_length - burn_length) > PACK_SIZE) ? PACK_SIZE : (total_length - burn_length); wr_buf[0] = (u8)(burn_addr>>8); rd_buf[0] = wr_buf[0]; wr_buf[1] = (u8)burn_addr; rd_buf[1] = wr_buf[1]; memcpy(&wr_buf[GTP_ADDR_LENGTH], &burn_buf[burn_length], frame_length); for (retry = 0; retry < MAX_FRAME_CHECK_TIME; retry++) { ret = gup_i2c_write(client, wr_buf, GTP_ADDR_LENGTH + frame_length); if (ret <= 0) { pr_err("Write frame data i2c error."); continue; } ret = gup_i2c_read(client, rd_buf, GTP_ADDR_LENGTH + frame_length); if (ret <= 0) { pr_err("Read back frame data i2c error."); continue; } if (memcmp(&wr_buf[GTP_ADDR_LENGTH], &rd_buf[GTP_ADDR_LENGTH], frame_length)) { pr_err("Check frame data fail,not equal."); continue; } else { break; } } if (retry >= MAX_FRAME_CHECK_TIME) { pr_err("Burn frame data time out,exit."); return FAIL; } burn_length += frame_length; burn_addr += frame_length; } return SUCCESS; } static u8 gup_load_section_file(u8 *buf, u16 offset, u16 length) { if (!update_msg.fw_data || update_msg.fw_len < FW_HEAD_LENGTH + offset + length) { pr_err( "<<-GTP->> cannot load section data. fw_len=%d read end=%d\n", update_msg.fw_len , FW_HEAD_LENGTH + offset + length); return FAIL; } memcpy(buf, &update_msg.fw_data[FW_HEAD_LENGTH + offset], length); return SUCCESS; } static u8 gup_recall_check(struct i2c_client *client, u8 *chk_src, u16 start_rd_addr, u16 chk_length) { u8 rd_buf[PACK_SIZE + GTP_ADDR_LENGTH]; s32 ret = 0; u16 recall_addr = start_rd_addr; u16 recall_length = 0; u16 frame_length = 0; while (recall_length < chk_length) { frame_length = ((chk_length - recall_length) > PACK_SIZE) ? PACK_SIZE : (chk_length - recall_length); ret = gup_get_ic_msg(client, recall_addr, rd_buf, frame_length); if (ret <= 0) { pr_err("recall i2c error,exit"); return FAIL; } if (memcmp(&rd_buf[GTP_ADDR_LENGTH], &chk_src[recall_length], frame_length)) { pr_err("Recall frame data fail,not equal."); return FAIL; } recall_length += frame_length; recall_addr += frame_length; } pr_debug("Recall check %dk firmware success.", (chk_length/1024)); return SUCCESS; } static u8 gup_burn_fw_section(struct i2c_client *client, u8 *fw_section, u16 start_addr, u8 bank_cmd) { s32 ret = 0; u8 rd_buf[5]; /* step1:hold ss51 & dsp */ ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); if (ret <= 0) { pr_err("hold ss51 & dsp fail."); return FAIL; } /* step2:set scramble */ ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); if (ret <= 0) { pr_err("set scramble fail."); return FAIL; } /* step3:select bank */ ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, (bank_cmd >> 4)&0x0F); if (ret <= 0) { pr_err("select bank %d fail.", (bank_cmd >> 4)&0x0F); return FAIL; } /* step4:enable accessing code */ ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01); if (ret <= 0) { pr_err("enable accessing code fail."); return FAIL; } /* step5:burn 8k fw section */ ret = gup_burn_proc(client, fw_section, start_addr, FW_SECTION_LENGTH); if (ret == FAIL) { pr_err("burn fw_section fail."); return FAIL; } /* step6:hold ss51 & release dsp */ ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04); if (ret <= 0) { pr_err("hold ss51 & release dsp fail."); return FAIL; } /* must delay */ msleep(20); /* step7:send burn cmd to move data to flash from sram */ ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, bank_cmd&0x0f); if (ret <= 0) { pr_err("send burn cmd fail."); return FAIL; } pr_debug("Wait for the burn is complete."); do { ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1); if (ret <= 0) { pr_err("Get burn state fail"); return FAIL; } msleep(20); } while (rd_buf[GTP_ADDR_LENGTH]); /* step8:select bank */ ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, (bank_cmd >> 4)&0x0F); if (ret <= 0) { pr_err("select bank %d fail.", (bank_cmd >> 4)&0x0F); return FAIL; } /* step9:enable accessing code */ ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01); if (ret <= 0) { pr_err("enable accessing code fail."); return FAIL; } /* step10:recall 8k fw section */ ret = gup_recall_check(client, fw_section, start_addr, FW_SECTION_LENGTH); if (ret == FAIL) { pr_err("recall check 8k firmware fail."); return FAIL; } /* step11:disable accessing code */ ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x00); if (ret <= 0) { pr_err("disable accessing code fail."); return FAIL; } return SUCCESS; } static u8 gup_burn_dsp_isp(struct i2c_client *client) { s32 ret = 0; u8 *fw_dsp_isp = NULL; u8 retry = 0; pr_debug("Begin burn dsp isp."); /* step1:alloc memory */ pr_debug("step1:alloc memory"); while (retry++ < 5) { fw_dsp_isp = devm_kzalloc(&client->dev, FW_DSP_ISP_LENGTH, GFP_KERNEL); if (fw_dsp_isp == NULL) { continue; } else { pr_info("Alloc %dk byte memory success.", (FW_DSP_ISP_LENGTH/1024)); break; } } if (retry == 5) { pr_err("Alloc memory fail,exit."); return FAIL; } /* step2:load dsp isp file data */ pr_debug("step2:load dsp isp file data"); ret = gup_load_section_file(fw_dsp_isp, (4 * FW_SECTION_LENGTH + FW_DSP_LENGTH + FW_BOOT_LENGTH), FW_DSP_ISP_LENGTH); if (ret == FAIL) { pr_err("load firmware dsp_isp fail."); return FAIL; } /* step3:disable wdt,clear cache enable */ pr_debug("step3:disable wdt,clear cache enable"); ret = gup_set_ic_msg(client, _bRW_MISCTL__TMR0_EN, 0x00); if (ret <= 0) { pr_err("disable wdt fail."); return FAIL; } ret = gup_set_ic_msg(client, _bRW_MISCTL__CACHE_EN, 0x00); if (ret <= 0) { pr_err("clear cache enable fail."); return FAIL; } /* step4:hold ss51 & dsp */ pr_debug("step4:hold ss51 & dsp"); ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); if (ret <= 0) { pr_err("hold ss51 & dsp fail."); return FAIL; } /* step5:set boot from sram */ pr_debug("step5:set boot from sram"); ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOTCTL_B0_, 0x02); if (ret <= 0) { pr_err("set boot from sram fail."); return FAIL; } /* step6:software reboot */ pr_debug("step6:software reboot"); ret = gup_set_ic_msg(client, _bWO_MISCTL__CPU_SWRST_PULSE, 0x01); if (ret <= 0) { pr_err("software reboot fail."); return FAIL; } /* step7:select bank2 */ pr_debug("step7:select bank2"); ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x02); if (ret <= 0) { pr_err("select bank2 fail."); return FAIL; } /* step8:enable accessing code */ pr_debug("step8:enable accessing code"); ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01); if (ret <= 0) { pr_err("enable accessing code fail."); return FAIL; } /* step9:burn 4k dsp_isp */ pr_debug("step9:burn 4k dsp_isp"); ret = gup_burn_proc(client, fw_dsp_isp, 0xC000, FW_DSP_ISP_LENGTH); if (ret == FAIL) { pr_err("burn dsp_isp fail."); return FAIL; } /* step10:set scramble */ pr_debug("step10:set scramble"); ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); if (ret <= 0) { pr_err("set scramble fail."); return FAIL; } return SUCCESS; } static u8 gup_burn_fw_ss51(struct i2c_client *client) { u8 *fw_ss51 = NULL; u8 retry = 0; s32 ret = 0; pr_debug("Begin burn ss51 firmware."); /* step1:alloc memory */ pr_debug("step1:alloc memory"); while (retry++ < 5) { fw_ss51 = devm_kzalloc(&client->dev, FW_SECTION_LENGTH, GFP_KERNEL); if (fw_ss51 == NULL) { continue; } else { pr_info("Alloc %dk byte memory success.", (FW_SECTION_LENGTH/1024)); break; } } if (retry == 5) { pr_err("Alloc memory fail,exit."); return FAIL; } /* step2:load ss51 firmware section 1 file data */ pr_debug("step2:load ss51 firmware section 1 file data"); ret = gup_load_section_file(fw_ss51, 0, FW_SECTION_LENGTH); if (ret == FAIL) { pr_err("load ss51 firmware section 1 fail."); return FAIL; } /* step3:clear control flag */ pr_debug("step3:clear control flag"); ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x00); if (ret <= 0) { pr_err("clear control flag fail."); return FAIL; } /* step4:burn ss51 firmware section 1 */ pr_debug("step4:burn ss51 firmware section 1"); ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x01); if (ret == FAIL) { pr_err("burn ss51 firmware section 1 fail."); return FAIL; } /* step5:load ss51 firmware section 2 file data */ pr_debug("step5:load ss51 firmware section 2 file data"); ret = gup_load_section_file(fw_ss51, FW_SECTION_LENGTH, FW_SECTION_LENGTH); if (ret == FAIL) { pr_err("[burn_fw_ss51]load ss51 firmware section 2 fail."); return FAIL; } /* step6:burn ss51 firmware section 2 */ pr_debug("step6:burn ss51 firmware section 2"); ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x02); if (ret == FAIL) { pr_err("burn ss51 firmware section 2 fail."); return FAIL; } /* step7:load ss51 firmware section 3 file data */ pr_debug("step7:load ss51 firmware section 3 file data"); ret = gup_load_section_file(fw_ss51, 2*FW_SECTION_LENGTH, FW_SECTION_LENGTH); if (ret == FAIL) { pr_err("load ss51 firmware section 3 fail."); return FAIL; } /* step8:burn ss51 firmware section 3 */ pr_debug("step8:burn ss51 firmware section 3"); ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x13); if (ret == FAIL) { pr_err("burn ss51 firmware section 3 fail."); return FAIL; } /* step9:load ss51 firmware section 4 file data */ pr_debug("step9:load ss51 firmware section 4 file data"); ret = gup_load_section_file(fw_ss51, 3*FW_SECTION_LENGTH, FW_SECTION_LENGTH); if (ret == FAIL) { pr_err("load ss51 firmware section 4 fail."); return FAIL; } /* step10:burn ss51 firmware section 4 */ pr_debug("step10:burn ss51 firmware section 4"); ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x14); if (ret == FAIL) { pr_err("burn ss51 firmware section 4 fail."); return FAIL; } return SUCCESS; } static u8 gup_burn_fw_dsp(struct i2c_client *client) { s32 ret = 0; u8 *fw_dsp = NULL; u8 retry = 0; u8 rd_buf[5]; pr_debug("Begin burn dsp firmware."); /* step1:alloc memory */ pr_debug("step1:alloc memory"); while (retry++ < 5) { fw_dsp = devm_kzalloc(&client->dev, FW_DSP_LENGTH, GFP_KERNEL); if (fw_dsp == NULL) { continue; } else { pr_info("Alloc %dk byte memory success.", (FW_SECTION_LENGTH/1024)); break; } } if (retry == 5) { pr_err("Alloc memory fail,exit."); return FAIL; } /* step2:load firmware dsp */ pr_debug("step2:load firmware dsp"); ret = gup_load_section_file(fw_dsp, 4*FW_SECTION_LENGTH, FW_DSP_LENGTH); if (ret == FAIL) { pr_err("load firmware dsp fail."); return ret; } /* step3:select bank3 */ pr_debug("step3:select bank3"); ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03); if (ret <= 0) { pr_err("select bank3 fail."); return FAIL; } /* Step4:hold ss51 & dsp */ pr_debug("step4:hold ss51 & dsp"); ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); if (ret <= 0) { pr_err("hold ss51 & dsp fail."); return FAIL; } /* step5:set scramble */ pr_debug("step5:set scramble"); ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); if (ret <= 0) { pr_err("set scramble fail."); return FAIL; } /* step6:release ss51 & dsp */ pr_debug("step6:release ss51 & dsp"); ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04); if (ret <= 0) { pr_err("release ss51 & dsp fail."); return FAIL; } /* must delay */ msleep(20); /* step7:burn 4k dsp firmware */ pr_debug("step7:burn 4k dsp firmware"); ret = gup_burn_proc(client, fw_dsp, 0x9000, FW_DSP_LENGTH); if (ret == FAIL) { pr_err("[burn_fw_dsp]burn fw_section fail."); return ret; } /* step8:send burn cmd to move data to flash from sram */ pr_debug("step8:send burn cmd to move data to flash from sram"); ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x05); if (ret <= 0) { pr_err("send burn cmd fail."); return ret; } pr_debug("Wait for the burn is complete."); do { ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1); if (ret <= 0) { pr_err("Get burn state fail"); return ret; } msleep(20); } while (rd_buf[GTP_ADDR_LENGTH]); /* step9:recall check 4k dsp firmware */ pr_debug("step9:recall check 4k dsp firmware"); ret = gup_recall_check(client, fw_dsp, 0x9000, FW_DSP_LENGTH); if (ret == FAIL) { pr_err("recall check 4k dsp firmware fail."); return ret; } return SUCCESS; } static u8 gup_burn_fw_boot(struct i2c_client *client) { s32 ret = 0; u8 *fw_boot = NULL; u8 retry = 0; u8 rd_buf[5]; pr_debug("Begin burn bootloader firmware."); /* step1:Alloc memory */ pr_debug("step1:Alloc memory"); while (retry++ < 5) { fw_boot = devm_kzalloc(&client->dev, FW_BOOT_LENGTH, GFP_KERNEL); if (fw_boot == NULL) { continue; } else { pr_info("Alloc %dk byte memory success.", (FW_BOOT_LENGTH/1024)); break; } } if (retry == 5) { pr_err("Alloc memory fail,exit."); return FAIL; } /* step2:load firmware bootloader */ pr_debug("step2:load firmware bootloader"); ret = gup_load_section_file(fw_boot, (4 * FW_SECTION_LENGTH + FW_DSP_LENGTH), FW_BOOT_LENGTH); if (ret == FAIL) { pr_err("load firmware dsp fail."); return ret; } /* step3:hold ss51 & dsp */ pr_debug("step3:hold ss51 & dsp"); ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); if (ret <= 0) { pr_err("hold ss51 & dsp fail."); return FAIL; } /* step4:set scramble */ pr_debug("step4:set scramble"); ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); if (ret <= 0) { pr_err("set scramble fail."); return FAIL; } /* step5:release ss51 & dsp */ pr_debug("step5:release ss51 & dsp"); ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04); if (ret <= 0) { pr_err("release ss51 & dsp fail."); return FAIL; } /* must delay */ msleep(20); /* step6:select bank3 */ pr_debug("step6:select bank3"); ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03); if (ret <= 0) { pr_err("select bank3 fail."); return FAIL; } /* step7:burn 2k bootloader firmware */ pr_debug("step7:burn 2k bootloader firmware"); ret = gup_burn_proc(client, fw_boot, 0x9000, FW_BOOT_LENGTH); if (ret == FAIL) { pr_err("burn fw_section fail."); return ret; } /* step7:send burn cmd to move data to flash from sram */ pr_debug("step7:send burn cmd to flash data from sram"); ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x06); if (ret <= 0) { pr_err("send burn cmd fail."); return ret; } pr_debug("Wait for the burn is complete."); do { ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1); if (ret <= 0) { pr_err("Get burn state fail"); return ret; } msleep(20); } while (rd_buf[GTP_ADDR_LENGTH]); /* step8:recall check 2k bootloader firmware */ pr_debug("step8:recall check 2k bootloader firmware"); ret = gup_recall_check(client, fw_boot, 0x9000, FW_BOOT_LENGTH); if (ret == FAIL) { pr_err("recall check 4k dsp firmware fail."); return ret; } /* step9:enable download DSP code */ pr_debug("step9:enable download DSP code "); ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x99); if (ret <= 0) { pr_err("enable download DSP code fail."); return FAIL; } /* step10:release ss51 & hold dsp */ pr_debug("step10:release ss51 & hold dsp"); ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x08); if (ret <= 0) { pr_err("release ss51 & hold dsp fail."); return FAIL; } return SUCCESS; } s32 gup_update_proc(void *dir) { s32 ret = 0; u8 retry = 0; struct st_fw_head fw_head; struct goodix_ts_data *ts = NULL; pr_debug("Begin update."); if (!i2c_connect_client) { pr_err("No i2c connect client for %s\n", __func__); return -EIO; } show_len = 1; total_len = 100; ts = i2c_get_clientdata(i2c_connect_client); if (searching_file) { /* exit .bin update file searching */ searching_file = 0; pr_info("Exiting searching .bin update file."); /* wait for auto update quitted completely */ while ((show_len != 200) && (show_len != 100)) msleep(100); } ret = gup_check_update_file(i2c_connect_client, &fw_head, (u8 *)dir); if (ret == FAIL) { pr_err("check update file fail."); goto file_fail; } /* gtp_reset_guitar(i2c_connect_client, 20); */ ret = gup_get_ic_fw_msg(i2c_connect_client); if (ret == FAIL) { pr_err("get ic message fail."); goto file_fail; } if (ts->force_update) { dev_dbg(&ts->client->dev, "Enter force update."); } else { ret = gup_enter_update_judge(ts->client, &fw_head); if (ret == FAIL) { dev_err(&ts->client->dev, "Check *.bin file fail."); goto file_fail; } } ts->enter_update = 1; gtp_irq_disable(ts); #if GTP_ESD_PROTECT gtp_esd_switch(ts->client, SWITCH_OFF); #endif ret = gup_enter_update_mode(i2c_connect_client); if (ret == FAIL) { pr_err("enter update mode fail."); goto update_fail; } while (retry++ < 5) { show_len = 10; total_len = 100; ret = gup_burn_dsp_isp(i2c_connect_client); if (ret == FAIL) { pr_err("burn dsp isp fail."); continue; } show_len += 10; ret = gup_burn_fw_ss51(i2c_connect_client); if (ret == FAIL) { pr_err("burn ss51 firmware fail."); continue; } show_len += 40; ret = gup_burn_fw_dsp(i2c_connect_client); if (ret == FAIL) { pr_err("burn dsp firmware fail."); continue; } show_len += 20; ret = gup_burn_fw_boot(i2c_connect_client); if (ret == FAIL) { pr_err("burn bootloader fw fail."); continue; } show_len += 10; pr_info("UPDATE SUCCESS."); break; } if (retry >= 5) { pr_err("retry timeout,UPDATE FAIL."); goto update_fail; } pr_debug("leave update mode."); gup_leave_update_mode(i2c_connect_client); msleep(100); if (ts->fw_error) { pr_info("firmware error auto update, resent config!"); gup_init_panel(ts); } show_len = 100; total_len = 100; ts->enter_update = 0; gtp_irq_enable(ts); #if GTP_ESD_PROTECT gtp_esd_switch(ts->client, SWITCH_ON); #endif if (update_msg.need_free) { devm_kfree(&ts->client->dev, update_msg.fw_data); update_msg.need_free = false; } return SUCCESS; update_fail: ts->enter_update = 0; gtp_irq_enable(ts); #if GTP_ESD_PROTECT gtp_esd_switch(ts->client, SWITCH_ON); #endif file_fail: show_len = 200; total_len = 100; if (update_msg.need_free) { devm_kfree(&ts->client->dev, update_msg.fw_data); update_msg.need_free = false; } return FAIL; } static void gup_update_work(struct work_struct *work) { if (gup_update_proc(NULL) == FAIL) pr_err("Goodix update work fail!\n"); } u8 gup_init_update_proc(struct goodix_ts_data *ts) { dev_dbg(&ts->client->dev, "Ready to run update work."); INIT_DELAYED_WORK(&ts->goodix_update_work, gup_update_work); schedule_delayed_work(&ts->goodix_update_work, msecs_to_jiffies(3000)); return 0; }
rastomanchik/android_kernel_xiaomi_armani
drivers/input/touchscreen/gt9xx/gt9xx_update.c
C
gpl-2.0
38,692
/* * linux/arch/arm/mach-realview/realview_pb1176.c * * Copyright (C) 2008 ARM Limited * Copyright (C) 2000 Deep Blue Solutions Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/init.h> #include <linux/platform_device.h> #include <linux/sysdev.h> #include <linux/amba/bus.h> #include <linux/amba/pl061.h> #include <linux/amba/mmci.h> #include <linux/amba/pl022.h> #include <linux/io.h> #include <mach/hardware.h> #include <asm/irq.h> #include <asm/leds.h> #include <asm/mach-types.h> #include <asm/pmu.h> #include <asm/pgtable.h> #include <asm/hardware/gic.h> #include <asm/hardware/cache-l2x0.h> #include <asm/mach/arch.h> #include <asm/mach/flash.h> #include <asm/mach/map.h> #include <asm/mach/time.h> #include <mach/board-pb1176.h> #include <mach/irqs.h> #include "core.h" static struct map_desc realview_pb1176_io_desc[] __initdata = { { .virtual = IO_ADDRESS(REALVIEW_SYS_BASE), .pfn = __phys_to_pfn(REALVIEW_SYS_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_PB1176_GIC_CPU_BASE), .pfn = __phys_to_pfn(REALVIEW_PB1176_GIC_CPU_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_PB1176_GIC_DIST_BASE), .pfn = __phys_to_pfn(REALVIEW_PB1176_GIC_DIST_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_DC1176_GIC_CPU_BASE), .pfn = __phys_to_pfn(REALVIEW_DC1176_GIC_CPU_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_DC1176_GIC_DIST_BASE), .pfn = __phys_to_pfn(REALVIEW_DC1176_GIC_DIST_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_SCTL_BASE), .pfn = __phys_to_pfn(REALVIEW_SCTL_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_PB1176_TIMER0_1_BASE), .pfn = __phys_to_pfn(REALVIEW_PB1176_TIMER0_1_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_PB1176_TIMER2_3_BASE), .pfn = __phys_to_pfn(REALVIEW_PB1176_TIMER2_3_BASE), .length = SZ_4K, .type = MT_DEVICE, }, { .virtual = IO_ADDRESS(REALVIEW_PB1176_L220_BASE), .pfn = __phys_to_pfn(REALVIEW_PB1176_L220_BASE), .length = SZ_8K, .type = MT_DEVICE, }, #ifdef CONFIG_DEBUG_LL { .virtual = IO_ADDRESS(REALVIEW_PB1176_UART0_BASE), .pfn = __phys_to_pfn(REALVIEW_PB1176_UART0_BASE), .length = SZ_4K, .type = MT_DEVICE, }, #endif }; static void __init realview_pb1176_map_io(void) { iotable_init(realview_pb1176_io_desc, ARRAY_SIZE(realview_pb1176_io_desc)); } static struct pl061_platform_data gpio0_plat_data = { .gpio_base = 0, .irq_base = -1, }; static struct pl061_platform_data gpio1_plat_data = { .gpio_base = 8, .irq_base = -1, }; static struct pl061_platform_data gpio2_plat_data = { .gpio_base = 16, .irq_base = -1, }; static struct pl022_ssp_controller ssp0_plat_data = { .bus_id = 0, .enable_dma = 0, .num_chipselect = 1, }; /* * RealView PB1176 AMBA devices */ #define GPIO2_IRQ { IRQ_PB1176_GPIO2, NO_IRQ } #define GPIO3_IRQ { IRQ_PB1176_GPIO3, NO_IRQ } #define AACI_IRQ { IRQ_PB1176_AACI, NO_IRQ } #define MMCI0_IRQ { IRQ_PB1176_MMCI0A, IRQ_PB1176_MMCI0B } #define KMI0_IRQ { IRQ_PB1176_KMI0, NO_IRQ } #define KMI1_IRQ { IRQ_PB1176_KMI1, NO_IRQ } #define PB1176_SMC_IRQ { NO_IRQ, NO_IRQ } #define MPMC_IRQ { NO_IRQ, NO_IRQ } #define PB1176_CLCD_IRQ { IRQ_DC1176_CLCD, NO_IRQ } #define SCTL_IRQ { NO_IRQ, NO_IRQ } #define PB1176_WATCHDOG_IRQ { IRQ_DC1176_WATCHDOG, NO_IRQ } #define PB1176_GPIO0_IRQ { IRQ_PB1176_GPIO0, NO_IRQ } #define GPIO1_IRQ { IRQ_PB1176_GPIO1, NO_IRQ } #define PB1176_RTC_IRQ { IRQ_DC1176_RTC, NO_IRQ } #define SCI_IRQ { IRQ_PB1176_SCI, NO_IRQ } #define PB1176_UART0_IRQ { IRQ_DC1176_UART0, NO_IRQ } #define PB1176_UART1_IRQ { IRQ_DC1176_UART1, NO_IRQ } #define PB1176_UART2_IRQ { IRQ_DC1176_UART2, NO_IRQ } #define PB1176_UART3_IRQ { IRQ_DC1176_UART3, NO_IRQ } #define PB1176_UART4_IRQ { IRQ_PB1176_UART4, NO_IRQ } #define PB1176_SSP_IRQ { IRQ_DC1176_SSP, NO_IRQ } /* FPGA Primecells */ AMBA_DEVICE(aaci, "fpga:aaci", AACI, NULL); AMBA_DEVICE(mmc0, "fpga:mmc0", MMCI0, &realview_mmc0_plat_data); AMBA_DEVICE(kmi0, "fpga:kmi0", KMI0, NULL); AMBA_DEVICE(kmi1, "fpga:kmi1", KMI1, NULL); AMBA_DEVICE(uart4, "fpga:uart4", PB1176_UART4, NULL); /* DevChip Primecells */ AMBA_DEVICE(smc, "dev:smc", PB1176_SMC, NULL); AMBA_DEVICE(sctl, "dev:sctl", SCTL, NULL); AMBA_DEVICE(wdog, "dev:wdog", PB1176_WATCHDOG, NULL); AMBA_DEVICE(gpio0, "dev:gpio0", PB1176_GPIO0, &gpio0_plat_data); AMBA_DEVICE(gpio1, "dev:gpio1", GPIO1, &gpio1_plat_data); AMBA_DEVICE(gpio2, "dev:gpio2", GPIO2, &gpio2_plat_data); AMBA_DEVICE(rtc, "dev:rtc", PB1176_RTC, NULL); AMBA_DEVICE(sci0, "dev:sci0", SCI, NULL); AMBA_DEVICE(uart0, "dev:uart0", PB1176_UART0, NULL); AMBA_DEVICE(uart1, "dev:uart1", PB1176_UART1, NULL); AMBA_DEVICE(uart2, "dev:uart2", PB1176_UART2, NULL); AMBA_DEVICE(uart3, "dev:uart3", PB1176_UART3, NULL); AMBA_DEVICE(ssp0, "dev:ssp0", PB1176_SSP, &ssp0_plat_data); AMBA_DEVICE(clcd, "dev:clcd", PB1176_CLCD, &clcd_plat_data); static struct amba_device *amba_devs[] __initdata = { &uart0_device, &uart1_device, &uart2_device, &uart3_device, &uart4_device, &smc_device, &clcd_device, &sctl_device, &wdog_device, &gpio0_device, &gpio1_device, &gpio2_device, &rtc_device, &sci0_device, &ssp0_device, &aaci_device, &mmc0_device, &kmi0_device, &kmi1_device, }; /* * RealView PB1176 platform devices */ static struct resource realview_pb1176_flash_resources[] = { [0] = { .start = REALVIEW_PB1176_FLASH_BASE, .end = REALVIEW_PB1176_FLASH_BASE + REALVIEW_PB1176_FLASH_SIZE - 1, .flags = IORESOURCE_MEM, }, [1] = { .start = REALVIEW_PB1176_SEC_FLASH_BASE, .end = REALVIEW_PB1176_SEC_FLASH_BASE + REALVIEW_PB1176_SEC_FLASH_SIZE - 1, .flags = IORESOURCE_MEM, }, }; #ifdef CONFIG_REALVIEW_PB1176_SECURE_FLASH #define PB1176_FLASH_BLOCKS 2 #else #define PB1176_FLASH_BLOCKS 1 #endif static struct resource realview_pb1176_smsc911x_resources[] = { [0] = { .start = REALVIEW_PB1176_ETH_BASE, .end = REALVIEW_PB1176_ETH_BASE + SZ_64K - 1, .flags = IORESOURCE_MEM, }, [1] = { .start = IRQ_PB1176_ETH, .end = IRQ_PB1176_ETH, .flags = IORESOURCE_IRQ, }, }; static struct resource realview_pb1176_isp1761_resources[] = { [0] = { .start = REALVIEW_PB1176_USB_BASE, .end = REALVIEW_PB1176_USB_BASE + SZ_128K - 1, .flags = IORESOURCE_MEM, }, [1] = { .start = IRQ_PB1176_USB, .end = IRQ_PB1176_USB, .flags = IORESOURCE_IRQ, }, }; static struct resource pmu_resource = { .start = IRQ_DC1176_CORE_PMU, .end = IRQ_DC1176_CORE_PMU, .flags = IORESOURCE_IRQ, }; static struct platform_device pmu_device = { .name = "arm-pmu", .id = ARM_PMU_DEVICE_CPU, .num_resources = 1, .resource = &pmu_resource, }; static struct resource char_lcd_resources[] = { { .start = REALVIEW_CHAR_LCD_BASE, .end = (REALVIEW_CHAR_LCD_BASE + SZ_4K - 1), .flags = IORESOURCE_MEM, }, { .start = IRQ_PB1176_CHARLCD, .end = IRQ_PB1176_CHARLCD, .flags = IORESOURCE_IRQ, }, }; static struct platform_device char_lcd_device = { .name = "arm-charlcd", .id = -1, .num_resources = ARRAY_SIZE(char_lcd_resources), .resource = char_lcd_resources, }; static void __init gic_init_irq(void) { /* ARM1176 DevChip GIC, primary */ gic_init(0, IRQ_DC1176_GIC_START, __io_address(REALVIEW_DC1176_GIC_DIST_BASE), __io_address(REALVIEW_DC1176_GIC_CPU_BASE)); /* board GIC, secondary */ gic_init(1, IRQ_PB1176_GIC_START, __io_address(REALVIEW_PB1176_GIC_DIST_BASE), __io_address(REALVIEW_PB1176_GIC_CPU_BASE)); gic_cascade_irq(1, IRQ_DC1176_PB_IRQ1); } static void __init realview_pb1176_timer_init(void) { timer0_va_base = __io_address(REALVIEW_PB1176_TIMER0_1_BASE); timer1_va_base = __io_address(REALVIEW_PB1176_TIMER0_1_BASE) + 0x20; timer2_va_base = __io_address(REALVIEW_PB1176_TIMER2_3_BASE); timer3_va_base = __io_address(REALVIEW_PB1176_TIMER2_3_BASE) + 0x20; realview_timer_init(IRQ_DC1176_TIMER0); } static struct sys_timer realview_pb1176_timer = { .init = realview_pb1176_timer_init, }; static void realview_pb1176_reset(char mode) { void __iomem *reset_ctrl = __io_address(REALVIEW_SYS_RESETCTL); void __iomem *lock_ctrl = __io_address(REALVIEW_SYS_LOCK); __raw_writel(REALVIEW_SYS_LOCK_VAL, lock_ctrl); __raw_writel(REALVIEW_PB1176_SYS_SOFT_RESET, reset_ctrl); } static void realview_pb1176_fixup(struct machine_desc *mdesc, struct tag *tags, char **from, struct meminfo *meminfo) { /* * RealView PB1176 only has 128MB of RAM mapped at 0. */ meminfo->bank[0].start = 0; meminfo->bank[0].size = SZ_128M; meminfo->nr_banks = 1; } static void __init realview_pb1176_init(void) { int i; #ifdef CONFIG_CACHE_L2X0 /* 128Kb (16Kb/way) 8-way associativity. evmon/parity/share enabled. */ l2x0_init(__io_address(REALVIEW_PB1176_L220_BASE), 0x00730000, 0xfe000fff); #endif realview_flash_register(realview_pb1176_flash_resources, PB1176_FLASH_BLOCKS); realview_eth_register(NULL, realview_pb1176_smsc911x_resources); platform_device_register(&realview_i2c_device); realview_usb_register(realview_pb1176_isp1761_resources); platform_device_register(&pmu_device); platform_device_register(&char_lcd_device); for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { struct amba_device *d = amba_devs[i]; amba_device_register(d, &iomem_resource); } #ifdef CONFIG_LEDS leds_event = realview_leds_event; #endif realview_reset = realview_pb1176_reset; } MACHINE_START(REALVIEW_PB1176, "ARM-RealView PB1176") /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */ .boot_params = PLAT_PHYS_OFFSET + 0x00000100, .fixup = realview_pb1176_fixup, .map_io = realview_pb1176_map_io, .init_early = realview_init_early, .init_irq = gic_init_irq, .timer = &realview_pb1176_timer, .init_machine = realview_pb1176_init, MACHINE_END
gromaudio/linux-imx6
arch/arm/mach-realview/realview_pb1176.c
C
gpl-2.0
10,585
#include <linux/dcache.h> #include <linux/debugfs.h> #include <linux/delay.h> #include <linux/mm.h> #include <linux/string.h> #include <linux/slab.h> #include "decl.h" #include "cmd.h" #include "debugfs.h" static struct dentry *lbs_dir; static char *szStates[] = { "Connected", "Disconnected" }; #ifdef PROC_DEBUG static void lbs_debug_init(struct lbs_private *priv); #endif static int open_file_generic(struct inode *inode, struct file *file) { file->private_data = inode->i_private; return 0; } static ssize_t write_file_dummy(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { return -EINVAL; } static const size_t len = PAGE_SIZE; static ssize_t lbs_dev_info(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; size_t pos = 0; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; ssize_t res; if (!buf) return -ENOMEM; pos += snprintf(buf+pos, len-pos, "state = %s\n", szStates[priv->connect_status]); pos += snprintf(buf+pos, len-pos, "region_code = %02x\n", (u32) priv->regioncode); res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); free_page(addr); return res; } static ssize_t lbs_sleepparams_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t buf_size, ret; struct sleep_params sp; int p1, p2, p3, p4, p5, p6; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, user_buf, buf_size)) { ret = -EFAULT; goto out_unlock; } ret = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6); if (ret != 6) { ret = -EINVAL; goto out_unlock; } sp.sp_error = p1; sp.sp_offset = p2; sp.sp_stabletime = p3; sp.sp_calcontrol = p4; sp.sp_extsleepclk = p5; sp.sp_reserved = p6; ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_SET, &sp); if (!ret) ret = count; else if (ret > 0) ret = -EINVAL; out_unlock: free_page(addr); return ret; } static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t ret; size_t pos = 0; struct sleep_params sp; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_GET, &sp); if (ret) goto out_unlock; pos += snprintf(buf, len, "%d %d %d %d %d %d\n", sp.sp_error, sp.sp_offset, sp.sp_stabletime, sp.sp_calcontrol, sp.sp_extsleepclk, sp.sp_reserved); ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); out_unlock: free_page(addr); return ret; } static ssize_t lbs_host_sleep_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t buf_size, ret; int host_sleep; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, user_buf, buf_size)) { ret = -EFAULT; goto out_unlock; } ret = sscanf(buf, "%d", &host_sleep); if (ret != 1) { ret = -EINVAL; goto out_unlock; } if (host_sleep == 0) ret = lbs_set_host_sleep(priv, 0); else if (host_sleep == 1) { if (priv->wol_criteria == EHS_REMOVE_WAKEUP) { netdev_info(priv->dev, "wake parameters not configured\n"); ret = -EINVAL; goto out_unlock; } ret = lbs_set_host_sleep(priv, 1); } else { netdev_err(priv->dev, "invalid option\n"); ret = -EINVAL; } if (!ret) ret = count; out_unlock: free_page(addr); return ret; } static ssize_t lbs_host_sleep_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t ret; size_t pos = 0; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; pos += snprintf(buf, len, "%d\n", priv->is_host_sleep_activated); ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); free_page(addr); return ret; } /* * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the * firmware. Here's an example: * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length, * 00 00 are the data bytes of this TLV. For this TLV, their meaning is * defined in mrvlietypes_thresholds * * This function searches in this TLV data chunk for a given TLV type * and returns a pointer to the first data byte of the TLV, or to NULL * if the TLV hasn't been found. */ static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size) { struct mrvl_ie_header *tlv_h; uint16_t length; ssize_t pos = 0; while (pos < size) { tlv_h = (struct mrvl_ie_header *) tlv; if (!tlv_h->len) return NULL; if (tlv_h->type == cpu_to_le16(tlv_type)) return tlv_h; length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h); pos += length; tlv += length; } return NULL; } static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask, struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct cmd_ds_802_11_subscribe_event *subscribed; struct mrvl_ie_thresholds *got; struct lbs_private *priv = file->private_data; ssize_t ret = 0; size_t pos = 0; char *buf; u8 value; u8 freq; int events = 0; buf = (char *)get_zeroed_page(GFP_KERNEL); if (!buf) return -ENOMEM; subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL); if (!subscribed) { ret = -ENOMEM; goto out_page; } subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed)); subscribed->action = cpu_to_le16(CMD_ACT_GET); ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed); if (ret) goto out_cmd; got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv)); if (got) { value = got->value; freq = got->freq; events = le16_to_cpu(subscribed->events); pos += snprintf(buf, len, "%d %d %d\n", value, freq, !!(events & event_mask)); } ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); out_cmd: kfree(subscribed); out_page: free_page((unsigned long)buf); return ret; } static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask, struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct cmd_ds_802_11_subscribe_event *events; struct mrvl_ie_thresholds *tlv; struct lbs_private *priv = file->private_data; ssize_t buf_size; int value, freq, new_mask; uint16_t curr_mask; char *buf; int ret; buf = (char *)get_zeroed_page(GFP_KERNEL); if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { ret = -EFAULT; goto out_page; } ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask); if (ret != 3) { ret = -EINVAL; goto out_page; } events = kzalloc(sizeof(*events), GFP_KERNEL); if (!events) { ret = -ENOMEM; goto out_page; } events->hdr.size = cpu_to_le16(sizeof(*events)); events->action = cpu_to_le16(CMD_ACT_GET); ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events); if (ret) goto out_events; curr_mask = le16_to_cpu(events->events); if (new_mask) new_mask = curr_mask | event_mask; else new_mask = curr_mask & ~event_mask; /* Now everything is set and we can send stuff down to the firmware */ tlv = (void *)events->tlv; events->action = cpu_to_le16(CMD_ACT_SET); events->events = cpu_to_le16(new_mask); tlv->header.type = cpu_to_le16(tlv_type); tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header)); tlv->value = value; if (tlv_type != TLV_TYPE_BCNMISS) tlv->freq = freq; /* The command header, the action, the event mask, and one TLV */ events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv)); ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events); if (!ret) ret = count; out_events: kfree(events); out_page: free_page((unsigned long)buf); return ret; } static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW, file, userbuf, count, ppos); } static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW, file, userbuf, count, ppos); } static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW, file, userbuf, count, ppos); } static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW, file, userbuf, count, ppos); } static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT, file, userbuf, count, ppos); } static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT, file, userbuf, count, ppos); } static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH, file, userbuf, count, ppos); } static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH, file, userbuf, count, ppos); } static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH, file, userbuf, count, ppos); } static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH, file, userbuf, count, ppos); } static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS, file, userbuf, count, ppos); } static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS, file, userbuf, count, ppos); } static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t pos = 0; int ret; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; u32 val = 0; if (!buf) return -ENOMEM; ret = lbs_get_reg(priv, CMD_MAC_REG_ACCESS, priv->mac_offset, &val); mdelay(10); if (!ret) { pos = snprintf(buf, len, "MAC[0x%x] = 0x%08x\n", priv->mac_offset, val); ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); } free_page(addr); return ret; } static ssize_t lbs_rdmac_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } priv->mac_offset = simple_strtoul((char *)buf, NULL, 16); res = count; out_unlock: free_page(addr); return res; } static ssize_t lbs_wrmac_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; u32 offset, value; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } res = sscanf(buf, "%x %x", &offset, &value); if (res != 2) { res = -EFAULT; goto out_unlock; } res = lbs_set_reg(priv, CMD_MAC_REG_ACCESS, offset, value); mdelay(10); if (!res) res = count; out_unlock: free_page(addr); return res; } static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t pos = 0; int ret; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; u32 val; if (!buf) return -ENOMEM; ret = lbs_get_reg(priv, CMD_BBP_REG_ACCESS, priv->bbp_offset, &val); mdelay(10); if (!ret) { pos = snprintf(buf, len, "BBP[0x%x] = 0x%08x\n", priv->bbp_offset, val); ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); } free_page(addr); return ret; } static ssize_t lbs_rdbbp_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16); res = count; out_unlock: free_page(addr); return res; } static ssize_t lbs_wrbbp_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; u32 offset, value; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } res = sscanf(buf, "%x %x", &offset, &value); if (res != 2) { res = -EFAULT; goto out_unlock; } res = lbs_set_reg(priv, CMD_BBP_REG_ACCESS, offset, value); mdelay(10); if (!res) res = count; out_unlock: free_page(addr); return res; } static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t pos = 0; int ret; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; u32 val; if (!buf) return -ENOMEM; ret = lbs_get_reg(priv, CMD_RF_REG_ACCESS, priv->rf_offset, &val); mdelay(10); if (!ret) { pos = snprintf(buf, len, "RF[0x%x] = 0x%08x\n", priv->rf_offset, val); ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); } free_page(addr); return ret; } static ssize_t lbs_rdrf_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } priv->rf_offset = simple_strtoul(buf, NULL, 16); res = count; out_unlock: free_page(addr); return res; } static ssize_t lbs_wrrf_write(struct file *file, const char __user *userbuf, size_t count, loff_t *ppos) { struct lbs_private *priv = file->private_data; ssize_t res, buf_size; u32 offset, value; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; buf_size = min(count, len - 1); if (copy_from_user(buf, userbuf, buf_size)) { res = -EFAULT; goto out_unlock; } res = sscanf(buf, "%x %x", &offset, &value); if (res != 2) { res = -EFAULT; goto out_unlock; } res = lbs_set_reg(priv, CMD_RF_REG_ACCESS, offset, value); mdelay(10); if (!res) res = count; out_unlock: free_page(addr); return res; } #define FOPS(fread, fwrite) { \ .owner = THIS_MODULE, \ .open = open_file_generic, \ .read = (fread), \ .write = (fwrite), \ .llseek = generic_file_llseek, \ } struct lbs_debugfs_files { const char *name; int perm; struct file_operations fops; }; static const struct lbs_debugfs_files debugfs_files[] = { { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), }, { "sleepparams", 0644, FOPS(lbs_sleepparams_read, lbs_sleepparams_write), }, { "hostsleep", 0644, FOPS(lbs_host_sleep_read, lbs_host_sleep_write), }, }; static const struct lbs_debugfs_files debugfs_events_files[] = { {"low_rssi", 0644, FOPS(lbs_lowrssi_read, lbs_lowrssi_write), }, {"low_snr", 0644, FOPS(lbs_lowsnr_read, lbs_lowsnr_write), }, {"failure_count", 0644, FOPS(lbs_failcount_read, lbs_failcount_write), }, {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read, lbs_bcnmiss_write), }, {"high_rssi", 0644, FOPS(lbs_highrssi_read, lbs_highrssi_write), }, {"high_snr", 0644, FOPS(lbs_highsnr_read, lbs_highsnr_write), }, }; static const struct lbs_debugfs_files debugfs_regs_files[] = { {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), }, {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), }, {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), }, {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), }, {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), }, {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), }, }; void lbs_debugfs_init(void) { if (!lbs_dir) lbs_dir = debugfs_create_dir("lbs_wireless", NULL); } void lbs_debugfs_remove(void) { if (lbs_dir) debugfs_remove(lbs_dir); } void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev) { int i; const struct lbs_debugfs_files *files; if (!lbs_dir) goto exit; priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir); if (!priv->debugfs_dir) goto exit; for (i=0; i<ARRAY_SIZE(debugfs_files); i++) { files = &debugfs_files[i]; priv->debugfs_files[i] = debugfs_create_file(files->name, files->perm, priv->debugfs_dir, priv, &files->fops); } priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir); if (!priv->events_dir) goto exit; for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) { files = &debugfs_events_files[i]; priv->debugfs_events_files[i] = debugfs_create_file(files->name, files->perm, priv->events_dir, priv, &files->fops); } priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir); if (!priv->regs_dir) goto exit; for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) { files = &debugfs_regs_files[i]; priv->debugfs_regs_files[i] = debugfs_create_file(files->name, files->perm, priv->regs_dir, priv, &files->fops); } #ifdef PROC_DEBUG lbs_debug_init(priv); #endif exit: return; } void lbs_debugfs_remove_one(struct lbs_private *priv) { int i; for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) debugfs_remove(priv->debugfs_regs_files[i]); debugfs_remove(priv->regs_dir); for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++) debugfs_remove(priv->debugfs_events_files[i]); debugfs_remove(priv->events_dir); #ifdef PROC_DEBUG debugfs_remove(priv->debugfs_debug); #endif for(i=0; i<ARRAY_SIZE(debugfs_files); i++) debugfs_remove(priv->debugfs_files[i]); debugfs_remove(priv->debugfs_dir); } /* debug entry */ #ifdef PROC_DEBUG #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n)) #define item_addr(n) (offsetof(struct lbs_private, n)) struct debug_data { char name[32]; u32 size; size_t addr; }; /* To debug any member of struct lbs_private, simply add one line here. */ static struct debug_data items[] = { {"psmode", item_size(psmode), item_addr(psmode)}, {"psstate", item_size(psstate), item_addr(psstate)}, }; static int num_of_items = ARRAY_SIZE(items); /** * lbs_debugfs_read - proc read function * * @file: file to read * @userbuf: pointer to buffer * @count: number of bytes to read * @ppos: read data starting position * * returns: amount of data read or negative error code */ static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { int val = 0; size_t pos = 0; ssize_t res; char *p; int i; struct debug_data *d; unsigned long addr = get_zeroed_page(GFP_KERNEL); char *buf = (char *)addr; if (!buf) return -ENOMEM; p = buf; d = file->private_data; for (i = 0; i < num_of_items; i++) { if (d[i].size == 1) val = *((u8 *) d[i].addr); else if (d[i].size == 2) val = *((u16 *) d[i].addr); else if (d[i].size == 4) val = *((u32 *) d[i].addr); else if (d[i].size == 8) val = *((u64 *) d[i].addr); pos += sprintf(p + pos, "%s=%d\n", d[i].name, val); } res = simple_read_from_buffer(userbuf, count, ppos, p, pos); free_page(addr); return res; } /** * lbs_debugfs_write - proc write function * * @f: file pointer * @buf: pointer to data buffer * @cnt: data number to write * @ppos: file position * * returns: amount of data written */ static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf, size_t cnt, loff_t *ppos) { int r, i; char *pdata; char *p; char *p0; char *p1; char *p2; struct debug_data *d = f->private_data; pdata = kmalloc(cnt, GFP_KERNEL); if (pdata == NULL) return 0; if (copy_from_user(pdata, buf, cnt)) { lbs_deb_debugfs("Copy from user failed\n"); kfree(pdata); return 0; } p0 = pdata; for (i = 0; i < num_of_items; i++) { do { p = strstr(p0, d[i].name); if (p == NULL) break; p1 = strchr(p, '\n'); if (p1 == NULL) break; p0 = p1++; p2 = strchr(p, '='); if (!p2) break; p2++; r = simple_strtoul(p2, NULL, 0); if (d[i].size == 1) *((u8 *) d[i].addr) = (u8) r; else if (d[i].size == 2) *((u16 *) d[i].addr) = (u16) r; else if (d[i].size == 4) *((u32 *) d[i].addr) = (u32) r; else if (d[i].size == 8) *((u64 *) d[i].addr) = (u64) r; break; } while (1); } kfree(pdata); return (ssize_t)cnt; } static const struct file_operations lbs_debug_fops = { .owner = THIS_MODULE, .open = open_file_generic, .write = lbs_debugfs_write, .read = lbs_debugfs_read, .llseek = default_llseek, }; /** * lbs_debug_init - create debug proc file * * @priv: pointer to &struct lbs_private * * returns: N/A */ static void lbs_debug_init(struct lbs_private *priv) { int i; if (!priv->debugfs_dir) return; for (i = 0; i < num_of_items; i++) items[i].addr += (size_t) priv; priv->debugfs_debug = debugfs_create_file("debug", 0644, priv->debugfs_dir, &items[0], &lbs_debug_fops); } #endif
byeonggonlee/lynx-jb
drivers/net/wireless/libertas/debugfs.c
C
gpl-2.0
23,261
#include <linux/kernel.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/init.h> #include <linux/usb/input.h> #include <asm/unaligned.h> /* * Version Information * v0.0.1 - Original, extremely basic version, 2.4.xx only * v0.0.2 - Updated, works with 2.5.62 and 2.4.20; * - added pressure-threshold modules param code from * Alex Perry <alex.perry@ieee.org> */ #define DRIVER_VERSION "v0.0.2" #define DRIVER_AUTHOR "Josh Myer <josh@joshisanerd.com>" #define DRIVER_DESC "USB KB Gear JamStudio Tablet driver" #define DRIVER_LICENSE "GPL" MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE(DRIVER_LICENSE); #define USB_VENDOR_ID_KBGEAR 0x084e static int kb_pressure_click = 0x10; module_param(kb_pressure_click, int, 0); MODULE_PARM_DESC(kb_pressure_click, "pressure threshold for clicks"); struct kbtab { unsigned char *data; dma_addr_t data_dma; struct input_dev *dev; struct usb_device *usbdev; struct usb_interface *intf; struct urb *irq; char phys[32]; }; static void kbtab_irq(struct urb *urb) { struct kbtab *kbtab = urb->context; unsigned char *data = kbtab->data; struct input_dev *dev = kbtab->dev; int pressure; int retval; switch (urb->status) { case 0: /* success */ break; case -ECONNRESET: case -ENOENT: case -ESHUTDOWN: /* this urb is terminated, clean up */ dev_dbg(&kbtab->intf->dev, "%s - urb shutting down with status: %d\n", __func__, urb->status); return; default: dev_dbg(&kbtab->intf->dev, "%s - nonzero urb status received: %d\n", __func__, urb->status); goto exit; } input_report_key(dev, BTN_TOOL_PEN, 1); input_report_abs(dev, ABS_X, get_unaligned_le16(&data[1])); input_report_abs(dev, ABS_Y, get_unaligned_le16(&data[3])); /*input_report_key(dev, BTN_TOUCH , data[0] & 0x01);*/ input_report_key(dev, BTN_RIGHT, data[0] & 0x02); pressure = data[5]; if (kb_pressure_click == -1) input_report_abs(dev, ABS_PRESSURE, pressure); else input_report_key(dev, BTN_LEFT, pressure > kb_pressure_click ? 1 : 0); input_sync(dev); exit: retval = usb_submit_urb(urb, GFP_ATOMIC); if (retval) dev_err(&kbtab->intf->dev, "%s - usb_submit_urb failed with result %d\n", __func__, retval); } static struct usb_device_id kbtab_ids[] = { { USB_DEVICE(USB_VENDOR_ID_KBGEAR, 0x1001), .driver_info = 0 }, { } }; MODULE_DEVICE_TABLE(usb, kbtab_ids); static int kbtab_open(struct input_dev *dev) { struct kbtab *kbtab = input_get_drvdata(dev); kbtab->irq->dev = kbtab->usbdev; if (usb_submit_urb(kbtab->irq, GFP_KERNEL)) return -EIO; return 0; } static void kbtab_close(struct input_dev *dev) { struct kbtab *kbtab = input_get_drvdata(dev); usb_kill_urb(kbtab->irq); } static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *dev = interface_to_usbdev(intf); struct usb_endpoint_descriptor *endpoint; struct kbtab *kbtab; struct input_dev *input_dev; int error = -ENOMEM; kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL); input_dev = input_allocate_device(); if (!kbtab || !input_dev) goto fail1; kbtab->data = usb_alloc_coherent(dev, 8, GFP_KERNEL, &kbtab->data_dma); if (!kbtab->data) goto fail1; kbtab->irq = usb_alloc_urb(0, GFP_KERNEL); if (!kbtab->irq) goto fail2; kbtab->usbdev = dev; kbtab->intf = intf; kbtab->dev = input_dev; usb_make_path(dev, kbtab->phys, sizeof(kbtab->phys)); strlcat(kbtab->phys, "/input0", sizeof(kbtab->phys)); input_dev->name = "KB Gear Tablet"; input_dev->phys = kbtab->phys; usb_to_input_id(dev, &input_dev->id); input_dev->dev.parent = &intf->dev; input_set_drvdata(input_dev, kbtab); input_dev->open = kbtab_open; input_dev->close = kbtab_close; input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_LEFT)] |= BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_TOUCH); input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0); input_set_abs_params(input_dev, ABS_Y, 0, 0x1750, 4, 0); input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xff, 0, 0); endpoint = &intf->cur_altsetting->endpoint[0].desc; usb_fill_int_urb(kbtab->irq, dev, usb_rcvintpipe(dev, endpoint->bEndpointAddress), kbtab->data, 8, kbtab_irq, kbtab, endpoint->bInterval); kbtab->irq->transfer_dma = kbtab->data_dma; kbtab->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; error = input_register_device(kbtab->dev); if (error) goto fail3; usb_set_intfdata(intf, kbtab); return 0; fail3: usb_free_urb(kbtab->irq); fail2: usb_free_coherent(dev, 8, kbtab->data, kbtab->data_dma); fail1: input_free_device(input_dev); kfree(kbtab); return error; } static void kbtab_disconnect(struct usb_interface *intf) { struct kbtab *kbtab = usb_get_intfdata(intf); usb_set_intfdata(intf, NULL); input_unregister_device(kbtab->dev); usb_free_urb(kbtab->irq); usb_free_coherent(kbtab->usbdev, 8, kbtab->data, kbtab->data_dma); kfree(kbtab); } static struct usb_driver kbtab_driver = { .name = "kbtab", .probe = kbtab_probe, .disconnect = kbtab_disconnect, .id_table = kbtab_ids, }; module_usb_driver(kbtab_driver);
quancao/kernel-imx-controlboard
drivers/input/tablet/kbtab.c
C
gpl-2.0
5,228
/* Styles for the media library iframe (not used on the Library screen) */ div#media-upload-header { margin: 0; padding: 5px 5px 0; font-weight: bold; position: relative; border-bottom: 1px solid #dfdfdf; background: #f9f9f9; } body#media-upload ul#sidemenu { font-weight: normal; margin: 0 5px; left: 0; bottom: -1px; float: none; overflow: hidden; } #media-upload:after { /* clearfix */ content: ""; display: table; clear: both; } #media-upload .slidetoggle { border-top-color: #dfdfdf; } #media-upload input[type="radio"] { padding: 0; } form { margin: 1em; } #search-filter { text-align: right; } th { position: relative; } .media-upload-form label.form-help, td.help { font-family: sans-serif; font-style: italic; font-weight: normal; } .media-upload-form p.help { margin: 0; padding: 0; } .media-upload-form fieldset { width: 100%; border: none; text-align: justify; margin: 0 0 1em 0; padding: 0; } /* specific to the image upload form */ .image-align-none-label { background: url(../images/align-none.png) no-repeat center left; } .image-align-left-label { background: url(../images/align-left.png) no-repeat center left; } .image-align-center-label { background: url(../images/align-center.png) no-repeat center left; } .image-align-right-label { background: url(../images/align-right.png) no-repeat center left; } tr.image-size td { width: 460px; } tr.image-size div.image-size-item { margin: 0 0 5px; } #library-form .progress, #gallery-form .progress, .insert-gallery, .describe.startopen, .describe.startclosed { display: none; } .media-item .thumbnail { max-width: 128px; max-height: 128px; } thead.media-item-info tr { background-color: transparent; } .form-table thead.media-item-info { border: 8px solid #fff; } abbr.required { text-decoration: none; border: none; } .describe label { display: inline; } .describe td.error { padding: 2px 8px; } .describe td.A1 { width: 132px; } .describe input[type="text"], .describe textarea { width: 460px; border-width: 1px; border-style: solid; } /* Specific to Uploader */ #media-upload p.ml-submit { padding: 1em 0; } #media-upload p.help, #media-upload label.help { font-family: sans-serif; font-style: italic; font-weight: normal; } #media-upload .ui-sortable .media-item { cursor: move; } #media-upload tr.image-size { margin-bottom: 1em; height: 3em; } #media-upload #filter { width: 623px; } #media-upload #filter .subsubsub { margin: 8px 0; } #filter .tablenav select { border-style: solid; border-width: 1px; padding: 2px; vertical-align: top; width: auto; } #media-upload .del-attachment { display: none; margin: 5px 0; } .menu_order { float: right; font-size: 11px; margin: 8px 10px 0; } .menu_order_input { border: 1px solid #ddd; font-size: 10px; padding: 1px; width: 23px; } .ui-sortable-helper { background-color: #fff; border: 1px solid #aaa; opacity: 0.6; filter: alpha(opacity=60); } #media-upload th.order-head { width: 20%; text-align: center; } #media-upload th.actions-head { width: 25%; text-align: center; } #media-upload a.wp-post-thumbnail { margin: 0 20px; } #media-upload .widefat { border-style: solid solid none; } .sorthelper { height: 37px; width: 623px; display: block; } #gallery-settings th.label { width: 160px; } #gallery-settings #basic th.label { padding: 5px 5px 5px 0; } #gallery-settings .title { clear: both; padding: 0 0 3px; font-size: 1.6em; border-bottom: 1px solid #DADADA; } h3.media-title { font-size: 1.6em; } h4.media-sub-title { border-bottom: 1px solid #DADADA; font-size: 1.3em; margin: 12px; padding: 0 0 3px; } #gallery-settings .title, h3.media-title, h4.media-sub-title { font-family: Georgia,"Times New Roman",Times,serif; font-weight: normal; color: #5A5A5A; } #gallery-settings .describe td { vertical-align: middle; height: 3em; } #gallery-settings .describe th.label { padding-top: .5em; text-align: left; } #gallery-settings .describe { padding: 5px; width: 100%; clear: both; cursor: default; background: #fff; } #gallery-settings .describe select { width: 15em; } #gallery-settings .describe select option, #gallery-settings .describe td { padding: 0; } #gallery-settings label, #gallery-settings legend { font-size: 13px; color: #464646; margin-right: 15px; } #gallery-settings .align .field label { margin: 0 1em 0 3px; } #gallery-settings p.ml-submit { border-top: 1px solid #dfdfdf; } #gallery-settings select#columns { width: 6em; } #sort-buttons { font-size: 0.8em; margin: 3px 25px -8px 0; text-align: right; max-width: 625px; } #sort-buttons a { text-decoration: none; } #sort-buttons #asc, #sort-buttons #showall { padding-left: 5px; } #sort-buttons span { margin-right: 25px; } p.media-types { padding: 1em; } tr.not-image { display: none; } table.not-image tr.not-image { display: table-row; } table.not-image tr.image-only { display: none; } /** * HiDPI Displays */ @media print, (-o-min-device-pixel-ratio: 5/4), (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) { .image-align-none-label { background-image: url(../images/align-none-2x.png?ver=20120916); -webkit-background-size: 21px 15px; background-size: 21px 15px; } .image-align-left-label { background-image: url(../images/align-left-2x.png?ver=20120916); -webkit-background-size: 22px 15px; background-size: 22px 15px; } .image-align-center-label { background-image: url(../images/align-center-2x.png?ver=20120916); -webkit-background-size: 21px 15px; background-size: 21px 15px; } .image-align-right-label { background-image: url(../images/align-right-2x.png?ver=20120916); -webkit-background-size: 22px 15px; background-size: 22px 15px; } }
rick-maclean/rick_wordpress
wp-admin/css/deprecated-media.css
CSS
gpl-2.0
5,793
/* * Device driver for the via-pmu on Apple Powermacs. * * The VIA (versatile interface adapter) interfaces to the PMU, * a 6805 microprocessor core whose primary function is to control * battery charging and system power on the PowerBook 3400 and 2400. * The PMU also controls the ADB (Apple Desktop Bus) which connects * to the keyboard and mouse, as well as the non-volatile RAM * and the RTC (real time clock) chip. * * Copyright (C) 1998 Paul Mackerras and Fabio Riccardi. * Copyright (C) 2001-2002 Benjamin Herrenschmidt * Copyright (C) 2006-2007 Johannes Berg * * THIS DRIVER IS BECOMING A TOTAL MESS ! * - Cleanup atomically disabling reply to PMU events after * a sleep or a freq. switch * */ #include <stdarg.h> #include <linux/mutex.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/delay.h> #include <linux/sched.h> #include <linux/miscdevice.h> #include <linux/blkdev.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/poll.h> #include <linux/adb.h> #include <linux/pmu.h> #include <linux/cuda.h> #include <linux/module.h> #include <linux/spinlock.h> #include <linux/pm.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/device.h> #include <linux/syscore_ops.h> #include <linux/freezer.h> #include <linux/syscalls.h> #include <linux/suspend.h> #include <linux/cpu.h> #include <linux/compat.h> #include <asm/prom.h> #include <asm/machdep.h> #include <asm/io.h> #include <asm/pgtable.h> #include <asm/sections.h> #include <asm/irq.h> #include <asm/pmac_feature.h> #include <asm/pmac_pfunc.h> #include <asm/pmac_low_i2c.h> #include <asm/uaccess.h> #include <asm/mmu_context.h> #include <asm/cputable.h> #include <asm/time.h> #include <asm/backlight.h> #include "via-pmu-event.h" /* Some compile options */ #undef DEBUG_SLEEP /* Misc minor number allocated for /dev/pmu */ #define PMU_MINOR 154 /* How many iterations between battery polls */ #define BATTERY_POLLING_COUNT 2 static DEFINE_MUTEX(pmu_info_proc_mutex); static volatile unsigned char __iomem *via; /* VIA registers - spaced 0x200 bytes apart */ #define RS 0x200 /* skip between registers */ #define B 0 /* B-side data */ #define A RS /* A-side data */ #define DIRB (2*RS) /* B-side direction (1=output) */ #define DIRA (3*RS) /* A-side direction (1=output) */ #define T1CL (4*RS) /* Timer 1 ctr/latch (low 8 bits) */ #define T1CH (5*RS) /* Timer 1 counter (high 8 bits) */ #define T1LL (6*RS) /* Timer 1 latch (low 8 bits) */ #define T1LH (7*RS) /* Timer 1 latch (high 8 bits) */ #define T2CL (8*RS) /* Timer 2 ctr/latch (low 8 bits) */ #define T2CH (9*RS) /* Timer 2 counter (high 8 bits) */ #define SR (10*RS) /* Shift register */ #define ACR (11*RS) /* Auxiliary control register */ #define PCR (12*RS) /* Peripheral control register */ #define IFR (13*RS) /* Interrupt flag register */ #define IER (14*RS) /* Interrupt enable register */ #define ANH (15*RS) /* A-side data, no handshake */ /* Bits in B data register: both active low */ #define TACK 0x08 /* Transfer acknowledge (input) */ #define TREQ 0x10 /* Transfer request (output) */ /* Bits in ACR */ #define SR_CTRL 0x1c /* Shift register control bits */ #define SR_EXT 0x0c /* Shift on external clock */ #define SR_OUT 0x10 /* Shift out if 1 */ /* Bits in IFR and IER */ #define IER_SET 0x80 /* set bits in IER */ #define IER_CLR 0 /* clear bits in IER */ #define SR_INT 0x04 /* Shift register full/empty */ #define CB2_INT 0x08 #define CB1_INT 0x10 /* transition on CB1 input */ static volatile enum pmu_state { idle, sending, intack, reading, reading_intr, locked, } pmu_state; static volatile enum int_data_state { int_data_empty, int_data_fill, int_data_ready, int_data_flush } int_data_state[2] = { int_data_empty, int_data_empty }; static struct adb_request *current_req; static struct adb_request *last_req; static struct adb_request *req_awaiting_reply; static unsigned char interrupt_data[2][32]; static int interrupt_data_len[2]; static int int_data_last; static unsigned char *reply_ptr; static int data_index; static int data_len; static volatile int adb_int_pending; static volatile int disable_poll; static struct device_node *vias; static int pmu_kind = PMU_UNKNOWN; static int pmu_fully_inited; static int pmu_has_adb; static struct device_node *gpio_node; static unsigned char __iomem *gpio_reg; static int gpio_irq = NO_IRQ; static int gpio_irq_enabled = -1; static volatile int pmu_suspended; static spinlock_t pmu_lock; static u8 pmu_intr_mask; static int pmu_version; static int drop_interrupts; #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) static int option_lid_wakeup = 1; #endif /* CONFIG_SUSPEND && CONFIG_PPC32 */ static unsigned long async_req_locks; static unsigned int pmu_irq_stats[11]; static struct proc_dir_entry *proc_pmu_root; static struct proc_dir_entry *proc_pmu_info; static struct proc_dir_entry *proc_pmu_irqstats; static struct proc_dir_entry *proc_pmu_options; static int option_server_mode; int pmu_battery_count; int pmu_cur_battery; unsigned int pmu_power_flags = PMU_PWR_AC_PRESENT; struct pmu_battery_info pmu_batteries[PMU_MAX_BATTERIES]; static int query_batt_timer = BATTERY_POLLING_COUNT; static struct adb_request batt_req; static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES]; int __fake_sleep; int asleep; #ifdef CONFIG_ADB static int adb_dev_map; static int pmu_adb_flags; static int pmu_probe(void); static int pmu_init(void); static int pmu_send_request(struct adb_request *req, int sync); static int pmu_adb_autopoll(int devs); static int pmu_adb_reset_bus(void); #endif /* CONFIG_ADB */ static int init_pmu(void); static void pmu_start(void); static irqreturn_t via_pmu_interrupt(int irq, void *arg); static irqreturn_t gpio1_interrupt(int irq, void *arg); static const struct file_operations pmu_info_proc_fops; static const struct file_operations pmu_irqstats_proc_fops; static void pmu_pass_intr(unsigned char *data, int len); static const struct file_operations pmu_battery_proc_fops; static const struct file_operations pmu_options_proc_fops; #ifdef CONFIG_ADB struct adb_driver via_pmu_driver = { "PMU", pmu_probe, pmu_init, pmu_send_request, pmu_adb_autopoll, pmu_poll_adb, pmu_adb_reset_bus }; #endif /* CONFIG_ADB */ extern void low_sleep_handler(void); extern void enable_kernel_altivec(void); extern void enable_kernel_fp(void); #ifdef DEBUG_SLEEP int pmu_polled_request(struct adb_request *req); void pmu_blink(int n); #endif /* * This table indicates for each PMU opcode: * - the number of data bytes to be sent with the command, or -1 * if a length byte should be sent, * - the number of response bytes which the PMU will return, or * -1 if it will send a length byte. */ static const s8 pmu_data_len[256][2] = { /* 0 1 2 3 4 5 6 7 */ /*00*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*08*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, /*10*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*18*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0, 0}, /*20*/ {-1, 0},{ 0, 0},{ 2, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0}, /*28*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0,-1}, /*30*/ { 4, 0},{20, 0},{-1, 0},{ 3, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*38*/ { 0, 4},{ 0,20},{ 2,-1},{ 2, 1},{ 3,-1},{-1,-1},{-1,-1},{ 4, 0}, /*40*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*48*/ { 0, 1},{ 0, 1},{-1,-1},{ 1, 0},{ 1, 0},{-1,-1},{-1,-1},{-1,-1}, /*50*/ { 1, 0},{ 0, 0},{ 2, 0},{ 2, 0},{-1, 0},{ 1, 0},{ 3, 0},{ 1, 0}, /*58*/ { 0, 1},{ 1, 0},{ 0, 2},{ 0, 2},{ 0,-1},{-1,-1},{-1,-1},{-1,-1}, /*60*/ { 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*68*/ { 0, 3},{ 0, 3},{ 0, 2},{ 0, 8},{ 0,-1},{ 0,-1},{-1,-1},{-1,-1}, /*70*/ { 1, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*78*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{ 5, 1},{ 4, 1},{ 4, 1}, /*80*/ { 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*88*/ { 0, 5},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, /*90*/ { 1, 0},{ 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*98*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, /*a0*/ { 2, 0},{ 2, 0},{ 2, 0},{ 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0}, /*a8*/ { 1, 1},{ 1, 0},{ 3, 0},{ 2, 0},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, /*b0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*b8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, /*c0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*c8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, /*d0*/ { 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*d8*/ { 1, 1},{ 1, 1},{-1,-1},{-1,-1},{ 0, 1},{ 0,-1},{-1,-1},{-1,-1}, /*e0*/ {-1, 0},{ 4, 0},{ 0, 1},{-1, 0},{-1, 0},{ 4, 0},{-1, 0},{-1, 0}, /*e8*/ { 3,-1},{-1,-1},{ 0, 1},{-1,-1},{ 0,-1},{-1,-1},{-1,-1},{ 0, 0}, /*f0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, /*f8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, }; static char *pbook_type[] = { "Unknown PowerBook", "PowerBook 2400/3400/3500(G3)", "PowerBook G3 Series", "1999 PowerBook G3", "Core99" }; int __init find_via_pmu(void) { u64 taddr; const u32 *reg; if (via != 0) return 1; vias = of_find_node_by_name(NULL, "via-pmu"); if (vias == NULL) return 0; reg = of_get_property(vias, "reg", NULL); if (reg == NULL) { printk(KERN_ERR "via-pmu: No \"reg\" property !\n"); goto fail; } taddr = of_translate_address(vias, reg); if (taddr == OF_BAD_ADDR) { printk(KERN_ERR "via-pmu: Can't translate address !\n"); goto fail; } spin_lock_init(&pmu_lock); pmu_has_adb = 1; pmu_intr_mask = PMU_INT_PCEJECT | PMU_INT_SNDBRT | PMU_INT_ADB | PMU_INT_TICK; if (vias->parent->name && ((strcmp(vias->parent->name, "ohare") == 0) || of_device_is_compatible(vias->parent, "ohare"))) pmu_kind = PMU_OHARE_BASED; else if (of_device_is_compatible(vias->parent, "paddington")) pmu_kind = PMU_PADDINGTON_BASED; else if (of_device_is_compatible(vias->parent, "heathrow")) pmu_kind = PMU_HEATHROW_BASED; else if (of_device_is_compatible(vias->parent, "Keylargo") || of_device_is_compatible(vias->parent, "K2-Keylargo")) { struct device_node *gpiop; struct device_node *adbp; u64 gaddr = OF_BAD_ADDR; pmu_kind = PMU_KEYLARGO_BASED; adbp = of_find_node_by_type(NULL, "adb"); pmu_has_adb = (adbp != NULL); of_node_put(adbp); pmu_intr_mask = PMU_INT_PCEJECT | PMU_INT_SNDBRT | PMU_INT_ADB | PMU_INT_TICK | PMU_INT_ENVIRONMENT; gpiop = of_find_node_by_name(NULL, "gpio"); if (gpiop) { reg = of_get_property(gpiop, "reg", NULL); if (reg) gaddr = of_translate_address(gpiop, reg); if (gaddr != OF_BAD_ADDR) gpio_reg = ioremap(gaddr, 0x10); } if (gpio_reg == NULL) { printk(KERN_ERR "via-pmu: Can't find GPIO reg !\n"); goto fail_gpio; } } else pmu_kind = PMU_UNKNOWN; via = ioremap(taddr, 0x2000); if (via == NULL) { printk(KERN_ERR "via-pmu: Can't map address !\n"); goto fail; } out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */ out_8(&via[IFR], 0x7f); /* clear IFR */ pmu_state = idle; if (!init_pmu()) { via = NULL; return 0; } printk(KERN_INFO "PMU driver v%d initialized for %s, firmware: %02x\n", PMU_DRIVER_VERSION, pbook_type[pmu_kind], pmu_version); sys_ctrler = SYS_CTRLER_PMU; return 1; fail: of_node_put(vias); iounmap(gpio_reg); gpio_reg = NULL; fail_gpio: vias = NULL; return 0; } #ifdef CONFIG_ADB static int pmu_probe(void) { return vias == NULL? -ENODEV: 0; } static int __init pmu_init(void) { if (vias == NULL) return -ENODEV; return 0; } #endif /* CONFIG_ADB */ /* * We can't wait until pmu_init gets called, that happens too late. * It happens after IDE and SCSI initialization, which can take a few * seconds, and by that time the PMU could have given up on us and * turned us off. * Thus this is called with arch_initcall rather than device_initcall. */ static int __init via_pmu_start(void) { unsigned int irq; if (vias == NULL) return -ENODEV; batt_req.complete = 1; irq = irq_of_parse_and_map(vias, 0); if (irq == NO_IRQ) { printk(KERN_ERR "via-pmu: can't map interrupt\n"); return -ENODEV; } /* We set IRQF_NO_SUSPEND because we don't want the interrupt * to be disabled between the 2 passes of driver suspend, we * control our own disabling for that one */ if (request_irq(irq, via_pmu_interrupt, IRQF_NO_SUSPEND, "VIA-PMU", (void *)0)) { printk(KERN_ERR "via-pmu: can't request irq %d\n", irq); return -ENODEV; } if (pmu_kind == PMU_KEYLARGO_BASED) { gpio_node = of_find_node_by_name(NULL, "extint-gpio1"); if (gpio_node == NULL) gpio_node = of_find_node_by_name(NULL, "pmu-interrupt"); if (gpio_node) gpio_irq = irq_of_parse_and_map(gpio_node, 0); if (gpio_irq != NO_IRQ) { if (request_irq(gpio_irq, gpio1_interrupt, IRQF_TIMER, "GPIO1 ADB", (void *)0)) printk(KERN_ERR "pmu: can't get irq %d" " (GPIO1)\n", gpio_irq); else gpio_irq_enabled = 1; } } /* Enable interrupts */ out_8(&via[IER], IER_SET | SR_INT | CB1_INT); pmu_fully_inited = 1; /* Make sure PMU settle down before continuing. This is _very_ important * since the IDE probe may shut interrupts down for quite a bit of time. If * a PMU communication is pending while this happens, the PMU may timeout * Not that on Core99 machines, the PMU keeps sending us environement * messages, we should find a way to either fix IDE or make it call * pmu_suspend() before masking interrupts. This can also happens while * scolling with some fbdevs. */ do { pmu_poll(); } while (pmu_state != idle); return 0; } arch_initcall(via_pmu_start); /* * This has to be done after pci_init, which is a subsys_initcall. */ static int __init via_pmu_dev_init(void) { if (vias == NULL) return -ENODEV; #ifdef CONFIG_PMAC_BACKLIGHT /* Initialize backlight */ pmu_backlight_init(); #endif #ifdef CONFIG_PPC32 if (of_machine_is_compatible("AAPL,3400/2400") || of_machine_is_compatible("AAPL,3500")) { int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_MODEL, 0); pmu_battery_count = 1; if (mb == PMAC_TYPE_COMET) pmu_batteries[0].flags |= PMU_BATT_TYPE_COMET; else pmu_batteries[0].flags |= PMU_BATT_TYPE_HOOPER; } else if (of_machine_is_compatible("AAPL,PowerBook1998") || of_machine_is_compatible("PowerBook1,1")) { pmu_battery_count = 2; pmu_batteries[0].flags |= PMU_BATT_TYPE_SMART; pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART; } else { struct device_node* prim = of_find_node_by_name(NULL, "power-mgt"); const u32 *prim_info = NULL; if (prim) prim_info = of_get_property(prim, "prim-info", NULL); if (prim_info) { /* Other stuffs here yet unknown */ pmu_battery_count = (prim_info[6] >> 16) & 0xff; pmu_batteries[0].flags |= PMU_BATT_TYPE_SMART; if (pmu_battery_count > 1) pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART; } of_node_put(prim); } #endif /* CONFIG_PPC32 */ /* Create /proc/pmu */ proc_pmu_root = proc_mkdir("pmu", NULL); if (proc_pmu_root) { long i; for (i=0; i<pmu_battery_count; i++) { char title[16]; sprintf(title, "battery_%ld", i); proc_pmu_batt[i] = proc_create_data(title, 0, proc_pmu_root, &pmu_battery_proc_fops, (void *)i); } proc_pmu_info = proc_create("info", 0, proc_pmu_root, &pmu_info_proc_fops); proc_pmu_irqstats = proc_create("interrupts", 0, proc_pmu_root, &pmu_irqstats_proc_fops); proc_pmu_options = proc_create("options", 0600, proc_pmu_root, &pmu_options_proc_fops); } return 0; } device_initcall(via_pmu_dev_init); static int init_pmu(void) { int timeout; struct adb_request req; out_8(&via[B], via[B] | TREQ); /* negate TREQ */ out_8(&via[DIRB], (via[DIRB] | TREQ) & ~TACK); /* TACK in, TREQ out */ pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask); timeout = 100000; while (!req.complete) { if (--timeout < 0) { printk(KERN_ERR "init_pmu: no response from PMU\n"); return 0; } udelay(10); pmu_poll(); } /* ack all pending interrupts */ timeout = 100000; interrupt_data[0][0] = 1; while (interrupt_data[0][0] || pmu_state != idle) { if (--timeout < 0) { printk(KERN_ERR "init_pmu: timed out acking intrs\n"); return 0; } if (pmu_state == idle) adb_int_pending = 1; via_pmu_interrupt(0, NULL); udelay(10); } /* Tell PMU we are ready. */ if (pmu_kind == PMU_KEYLARGO_BASED) { pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2); while (!req.complete) pmu_poll(); } /* Read PMU version */ pmu_request(&req, NULL, 1, PMU_GET_VERSION); pmu_wait_complete(&req); if (req.reply_len > 0) pmu_version = req.reply[0]; /* Read server mode setting */ if (pmu_kind == PMU_KEYLARGO_BASED) { pmu_request(&req, NULL, 2, PMU_POWER_EVENTS, PMU_PWR_GET_POWERUP_EVENTS); pmu_wait_complete(&req); if (req.reply_len == 2) { if (req.reply[1] & PMU_PWR_WAKEUP_AC_INSERT) option_server_mode = 1; printk(KERN_INFO "via-pmu: Server Mode is %s\n", option_server_mode ? "enabled" : "disabled"); } } return 1; } int pmu_get_model(void) { return pmu_kind; } static void pmu_set_server_mode(int server_mode) { struct adb_request req; if (pmu_kind != PMU_KEYLARGO_BASED) return; option_server_mode = server_mode; pmu_request(&req, NULL, 2, PMU_POWER_EVENTS, PMU_PWR_GET_POWERUP_EVENTS); pmu_wait_complete(&req); if (req.reply_len < 2) return; if (server_mode) pmu_request(&req, NULL, 4, PMU_POWER_EVENTS, PMU_PWR_SET_POWERUP_EVENTS, req.reply[0], PMU_PWR_WAKEUP_AC_INSERT); else pmu_request(&req, NULL, 4, PMU_POWER_EVENTS, PMU_PWR_CLR_POWERUP_EVENTS, req.reply[0], PMU_PWR_WAKEUP_AC_INSERT); pmu_wait_complete(&req); } /* This new version of the code for 2400/3400/3500 powerbooks * is inspired from the implementation in gkrellm-pmu */ static void done_battery_state_ohare(struct adb_request* req) { /* format: * [0] : flags * 0x01 : AC indicator * 0x02 : charging * 0x04 : battery exist * 0x08 : * 0x10 : * 0x20 : full charged * 0x40 : pcharge reset * 0x80 : battery exist * * [1][2] : battery voltage * [3] : CPU temperature * [4] : battery temperature * [5] : current * [6][7] : pcharge * --tkoba */ unsigned int bat_flags = PMU_BATT_TYPE_HOOPER; long pcharge, charge, vb, vmax, lmax; long vmax_charging, vmax_charged; long amperage, voltage, time, max; int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_MODEL, 0); if (req->reply[0] & 0x01) pmu_power_flags |= PMU_PWR_AC_PRESENT; else pmu_power_flags &= ~PMU_PWR_AC_PRESENT; if (mb == PMAC_TYPE_COMET) { vmax_charged = 189; vmax_charging = 213; lmax = 6500; } else { vmax_charged = 330; vmax_charging = 330; lmax = 6500; } vmax = vmax_charged; /* If battery installed */ if (req->reply[0] & 0x04) { bat_flags |= PMU_BATT_PRESENT; if (req->reply[0] & 0x02) bat_flags |= PMU_BATT_CHARGING; vb = (req->reply[1] << 8) | req->reply[2]; voltage = (vb * 265 + 72665) / 10; amperage = req->reply[5]; if ((req->reply[0] & 0x01) == 0) { if (amperage > 200) vb += ((amperage - 200) * 15)/100; } else if (req->reply[0] & 0x02) { vb = (vb * 97) / 100; vmax = vmax_charging; } charge = (100 * vb) / vmax; if (req->reply[0] & 0x40) { pcharge = (req->reply[6] << 8) + req->reply[7]; if (pcharge > lmax) pcharge = lmax; pcharge *= 100; pcharge = 100 - pcharge / lmax; if (pcharge < charge) charge = pcharge; } if (amperage > 0) time = (charge * 16440) / amperage; else time = 0; max = 100; amperage = -amperage; } else charge = max = amperage = voltage = time = 0; pmu_batteries[pmu_cur_battery].flags = bat_flags; pmu_batteries[pmu_cur_battery].charge = charge; pmu_batteries[pmu_cur_battery].max_charge = max; pmu_batteries[pmu_cur_battery].amperage = amperage; pmu_batteries[pmu_cur_battery].voltage = voltage; pmu_batteries[pmu_cur_battery].time_remaining = time; clear_bit(0, &async_req_locks); } static void done_battery_state_smart(struct adb_request* req) { /* format: * [0] : format of this structure (known: 3,4,5) * [1] : flags * * format 3 & 4: * * [2] : charge * [3] : max charge * [4] : current * [5] : voltage * * format 5: * * [2][3] : charge * [4][5] : max charge * [6][7] : current * [8][9] : voltage */ unsigned int bat_flags = PMU_BATT_TYPE_SMART; int amperage; unsigned int capa, max, voltage; if (req->reply[1] & 0x01) pmu_power_flags |= PMU_PWR_AC_PRESENT; else pmu_power_flags &= ~PMU_PWR_AC_PRESENT; capa = max = amperage = voltage = 0; if (req->reply[1] & 0x04) { bat_flags |= PMU_BATT_PRESENT; switch(req->reply[0]) { case 3: case 4: capa = req->reply[2]; max = req->reply[3]; amperage = *((signed char *)&req->reply[4]); voltage = req->reply[5]; break; case 5: capa = (req->reply[2] << 8) | req->reply[3]; max = (req->reply[4] << 8) | req->reply[5]; amperage = *((signed short *)&req->reply[6]); voltage = (req->reply[8] << 8) | req->reply[9]; break; default: printk(KERN_WARNING "pmu.c : unrecognized battery info, len: %d, %02x %02x %02x %02x\n", req->reply_len, req->reply[0], req->reply[1], req->reply[2], req->reply[3]); break; } } if ((req->reply[1] & 0x01) && (amperage > 0)) bat_flags |= PMU_BATT_CHARGING; pmu_batteries[pmu_cur_battery].flags = bat_flags; pmu_batteries[pmu_cur_battery].charge = capa; pmu_batteries[pmu_cur_battery].max_charge = max; pmu_batteries[pmu_cur_battery].amperage = amperage; pmu_batteries[pmu_cur_battery].voltage = voltage; if (amperage) { if ((req->reply[1] & 0x01) && (amperage > 0)) pmu_batteries[pmu_cur_battery].time_remaining = ((max-capa) * 3600) / amperage; else pmu_batteries[pmu_cur_battery].time_remaining = (capa * 3600) / (-amperage); } else pmu_batteries[pmu_cur_battery].time_remaining = 0; pmu_cur_battery = (pmu_cur_battery + 1) % pmu_battery_count; clear_bit(0, &async_req_locks); } static void query_battery_state(void) { if (test_and_set_bit(0, &async_req_locks)) return; if (pmu_kind == PMU_OHARE_BASED) pmu_request(&batt_req, done_battery_state_ohare, 1, PMU_BATTERY_STATE); else pmu_request(&batt_req, done_battery_state_smart, 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1); } static int pmu_info_proc_show(struct seq_file *m, void *v) { seq_printf(m, "PMU driver version : %d\n", PMU_DRIVER_VERSION); seq_printf(m, "PMU firmware version : %02x\n", pmu_version); seq_printf(m, "AC Power : %d\n", ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0) || pmu_battery_count == 0); seq_printf(m, "Battery count : %d\n", pmu_battery_count); return 0; } static int pmu_info_proc_open(struct inode *inode, struct file *file) { return single_open(file, pmu_info_proc_show, NULL); } static const struct file_operations pmu_info_proc_fops = { .owner = THIS_MODULE, .open = pmu_info_proc_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; static int pmu_irqstats_proc_show(struct seq_file *m, void *v) { int i; static const char *irq_names[] = { "Total CB1 triggered events", "Total GPIO1 triggered events", "PC-Card eject button", "Sound/Brightness button", "ADB message", "Battery state change", "Environment interrupt", "Tick timer", "Ghost interrupt (zero len)", "Empty interrupt (empty mask)", "Max irqs in a row" }; for (i=0; i<11; i++) { seq_printf(m, " %2u: %10u (%s)\n", i, pmu_irq_stats[i], irq_names[i]); } return 0; } static int pmu_irqstats_proc_open(struct inode *inode, struct file *file) { return single_open(file, pmu_irqstats_proc_show, NULL); } static const struct file_operations pmu_irqstats_proc_fops = { .owner = THIS_MODULE, .open = pmu_irqstats_proc_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; static int pmu_battery_proc_show(struct seq_file *m, void *v) { long batnum = (long)m->private; seq_putc(m, '\n'); seq_printf(m, "flags : %08x\n", pmu_batteries[batnum].flags); seq_printf(m, "charge : %d\n", pmu_batteries[batnum].charge); seq_printf(m, "max_charge : %d\n", pmu_batteries[batnum].max_charge); seq_printf(m, "current : %d\n", pmu_batteries[batnum].amperage); seq_printf(m, "voltage : %d\n", pmu_batteries[batnum].voltage); seq_printf(m, "time rem. : %d\n", pmu_batteries[batnum].time_remaining); return 0; } static int pmu_battery_proc_open(struct inode *inode, struct file *file) { return single_open(file, pmu_battery_proc_show, PDE(inode)->data); } static const struct file_operations pmu_battery_proc_fops = { .owner = THIS_MODULE, .open = pmu_battery_proc_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; static int pmu_options_proc_show(struct seq_file *m, void *v) { #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) if (pmu_kind == PMU_KEYLARGO_BASED && pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) seq_printf(m, "lid_wakeup=%d\n", option_lid_wakeup); #endif if (pmu_kind == PMU_KEYLARGO_BASED) seq_printf(m, "server_mode=%d\n", option_server_mode); return 0; } static int pmu_options_proc_open(struct inode *inode, struct file *file) { return single_open(file, pmu_options_proc_show, NULL); } static ssize_t pmu_options_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *pos) { char tmp[33]; char *label, *val; size_t fcount = count; if (!count) return -EINVAL; if (count > 32) count = 32; if (copy_from_user(tmp, buffer, count)) return -EFAULT; tmp[count] = 0; label = tmp; while(*label == ' ') label++; val = label; while(*val && (*val != '=')) { if (*val == ' ') *val = 0; val++; } if ((*val) == 0) return -EINVAL; *(val++) = 0; while(*val == ' ') val++; #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) if (pmu_kind == PMU_KEYLARGO_BASED && pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) if (!strcmp(label, "lid_wakeup")) option_lid_wakeup = ((*val) == '1'); #endif if (pmu_kind == PMU_KEYLARGO_BASED && !strcmp(label, "server_mode")) { int new_value; new_value = ((*val) == '1'); if (new_value != option_server_mode) pmu_set_server_mode(new_value); } return fcount; } static const struct file_operations pmu_options_proc_fops = { .owner = THIS_MODULE, .open = pmu_options_proc_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, .write = pmu_options_proc_write, }; #ifdef CONFIG_ADB /* Send an ADB command */ static int pmu_send_request(struct adb_request *req, int sync) { int i, ret; if ((vias == NULL) || (!pmu_fully_inited)) { req->complete = 1; return -ENXIO; } ret = -EINVAL; switch (req->data[0]) { case PMU_PACKET: for (i = 0; i < req->nbytes - 1; ++i) req->data[i] = req->data[i+1]; --req->nbytes; if (pmu_data_len[req->data[0]][1] != 0) { req->reply[0] = ADB_RET_OK; req->reply_len = 1; } else req->reply_len = 0; ret = pmu_queue_request(req); break; case CUDA_PACKET: switch (req->data[1]) { case CUDA_GET_TIME: if (req->nbytes != 2) break; req->data[0] = PMU_READ_RTC; req->nbytes = 1; req->reply_len = 3; req->reply[0] = CUDA_PACKET; req->reply[1] = 0; req->reply[2] = CUDA_GET_TIME; ret = pmu_queue_request(req); break; case CUDA_SET_TIME: if (req->nbytes != 6) break; req->data[0] = PMU_SET_RTC; req->nbytes = 5; for (i = 1; i <= 4; ++i) req->data[i] = req->data[i+1]; req->reply_len = 3; req->reply[0] = CUDA_PACKET; req->reply[1] = 0; req->reply[2] = CUDA_SET_TIME; ret = pmu_queue_request(req); break; } break; case ADB_PACKET: if (!pmu_has_adb) return -ENXIO; for (i = req->nbytes - 1; i > 1; --i) req->data[i+2] = req->data[i]; req->data[3] = req->nbytes - 2; req->data[2] = pmu_adb_flags; /*req->data[1] = req->data[1];*/ req->data[0] = PMU_ADB_CMD; req->nbytes += 2; req->reply_expected = 1; req->reply_len = 0; ret = pmu_queue_request(req); break; } if (ret) { req->complete = 1; return ret; } if (sync) while (!req->complete) pmu_poll(); return 0; } /* Enable/disable autopolling */ static int __pmu_adb_autopoll(int devs) { struct adb_request req; if (devs) { pmu_request(&req, NULL, 5, PMU_ADB_CMD, 0, 0x86, adb_dev_map >> 8, adb_dev_map); pmu_adb_flags = 2; } else { pmu_request(&req, NULL, 1, PMU_ADB_POLL_OFF); pmu_adb_flags = 0; } while (!req.complete) pmu_poll(); return 0; } static int pmu_adb_autopoll(int devs) { if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb) return -ENXIO; adb_dev_map = devs; return __pmu_adb_autopoll(devs); } /* Reset the ADB bus */ static int pmu_adb_reset_bus(void) { struct adb_request req; int save_autopoll = adb_dev_map; if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb) return -ENXIO; /* anyone got a better idea?? */ __pmu_adb_autopoll(0); req.nbytes = 4; req.done = NULL; req.data[0] = PMU_ADB_CMD; req.data[1] = ADB_BUSRESET; req.data[2] = 0; req.data[3] = 0; req.data[4] = 0; req.reply_len = 0; req.reply_expected = 1; if (pmu_queue_request(&req) != 0) { printk(KERN_ERR "pmu_adb_reset_bus: pmu_queue_request failed\n"); return -EIO; } pmu_wait_complete(&req); if (save_autopoll != 0) __pmu_adb_autopoll(save_autopoll); return 0; } #endif /* CONFIG_ADB */ /* Construct and send a pmu request */ int pmu_request(struct adb_request *req, void (*done)(struct adb_request *), int nbytes, ...) { va_list list; int i; if (vias == NULL) return -ENXIO; if (nbytes < 0 || nbytes > 32) { printk(KERN_ERR "pmu_request: bad nbytes (%d)\n", nbytes); req->complete = 1; return -EINVAL; } req->nbytes = nbytes; req->done = done; va_start(list, nbytes); for (i = 0; i < nbytes; ++i) req->data[i] = va_arg(list, int); va_end(list); req->reply_len = 0; req->reply_expected = 0; return pmu_queue_request(req); } int pmu_queue_request(struct adb_request *req) { unsigned long flags; int nsend; if (via == NULL) { req->complete = 1; return -ENXIO; } if (req->nbytes <= 0) { req->complete = 1; return 0; } nsend = pmu_data_len[req->data[0]][0]; if (nsend >= 0 && req->nbytes != nsend + 1) { req->complete = 1; return -EINVAL; } req->next = NULL; req->sent = 0; req->complete = 0; spin_lock_irqsave(&pmu_lock, flags); if (current_req != 0) { last_req->next = req; last_req = req; } else { current_req = req; last_req = req; if (pmu_state == idle) pmu_start(); } spin_unlock_irqrestore(&pmu_lock, flags); return 0; } static inline void wait_for_ack(void) { /* Sightly increased the delay, I had one occurrence of the message * reported */ int timeout = 4000; while ((in_8(&via[B]) & TACK) == 0) { if (--timeout < 0) { printk(KERN_ERR "PMU not responding (!ack)\n"); return; } udelay(10); } } /* New PMU seems to be very sensitive to those timings, so we make sure * PCI is flushed immediately */ static inline void send_byte(int x) { volatile unsigned char __iomem *v = via; out_8(&v[ACR], in_8(&v[ACR]) | SR_OUT | SR_EXT); out_8(&v[SR], x); out_8(&v[B], in_8(&v[B]) & ~TREQ); /* assert TREQ */ (void)in_8(&v[B]); } static inline void recv_byte(void) { volatile unsigned char __iomem *v = via; out_8(&v[ACR], (in_8(&v[ACR]) & ~SR_OUT) | SR_EXT); in_8(&v[SR]); /* resets SR */ out_8(&v[B], in_8(&v[B]) & ~TREQ); (void)in_8(&v[B]); } static inline void pmu_done(struct adb_request *req) { void (*done)(struct adb_request *) = req->done; mb(); req->complete = 1; /* Here, we assume that if the request has a done member, the * struct request will survive to setting req->complete to 1 */ if (done) (*done)(req); } static void pmu_start(void) { struct adb_request *req; /* assert pmu_state == idle */ /* get the packet to send */ req = current_req; if (req == 0 || pmu_state != idle || (/*req->reply_expected && */req_awaiting_reply)) return; pmu_state = sending; data_index = 1; data_len = pmu_data_len[req->data[0]][0]; /* Sounds safer to make sure ACK is high before writing. This helped * kill a problem with ADB and some iBooks */ wait_for_ack(); /* set the shift register to shift out and send a byte */ send_byte(req->data[0]); } void pmu_poll(void) { if (!via) return; if (disable_poll) return; via_pmu_interrupt(0, NULL); } void pmu_poll_adb(void) { if (!via) return; if (disable_poll) return; /* Kicks ADB read when PMU is suspended */ adb_int_pending = 1; do { via_pmu_interrupt(0, NULL); } while (pmu_suspended && (adb_int_pending || pmu_state != idle || req_awaiting_reply)); } void pmu_wait_complete(struct adb_request *req) { if (!via) return; while((pmu_state != idle && pmu_state != locked) || !req->complete) via_pmu_interrupt(0, NULL); } /* This function loops until the PMU is idle and prevents it from * anwsering to ADB interrupts. pmu_request can still be called. * This is done to avoid spurrious shutdowns when we know we'll have * interrupts switched off for a long time */ void pmu_suspend(void) { unsigned long flags; if (!via) return; spin_lock_irqsave(&pmu_lock, flags); pmu_suspended++; if (pmu_suspended > 1) { spin_unlock_irqrestore(&pmu_lock, flags); return; } do { spin_unlock_irqrestore(&pmu_lock, flags); if (req_awaiting_reply) adb_int_pending = 1; via_pmu_interrupt(0, NULL); spin_lock_irqsave(&pmu_lock, flags); if (!adb_int_pending && pmu_state == idle && !req_awaiting_reply) { if (gpio_irq >= 0) disable_irq_nosync(gpio_irq); out_8(&via[IER], CB1_INT | IER_CLR); spin_unlock_irqrestore(&pmu_lock, flags); break; } } while (1); } void pmu_resume(void) { unsigned long flags; if (!via || (pmu_suspended < 1)) return; spin_lock_irqsave(&pmu_lock, flags); pmu_suspended--; if (pmu_suspended > 0) { spin_unlock_irqrestore(&pmu_lock, flags); return; } adb_int_pending = 1; if (gpio_irq >= 0) enable_irq(gpio_irq); out_8(&via[IER], CB1_INT | IER_SET); spin_unlock_irqrestore(&pmu_lock, flags); pmu_poll(); } /* Interrupt data could be the result data from an ADB cmd */ static void pmu_handle_data(unsigned char *data, int len) { unsigned char ints, pirq; int i = 0; asleep = 0; if (drop_interrupts || len < 1) { adb_int_pending = 0; pmu_irq_stats[8]++; return; } /* Get PMU interrupt mask */ ints = data[0]; /* Record zero interrupts for stats */ if (ints == 0) pmu_irq_stats[9]++; /* Hack to deal with ADB autopoll flag */ if (ints & PMU_INT_ADB) ints &= ~(PMU_INT_ADB_AUTO | PMU_INT_AUTO_SRQ_POLL); next: if (ints == 0) { if (i > pmu_irq_stats[10]) pmu_irq_stats[10] = i; return; } for (pirq = 0; pirq < 8; pirq++) if (ints & (1 << pirq)) break; pmu_irq_stats[pirq]++; i++; ints &= ~(1 << pirq); /* Note: for some reason, we get an interrupt with len=1, * data[0]==0 after each normal ADB interrupt, at least * on the Pismo. Still investigating... --BenH */ if ((1 << pirq) & PMU_INT_ADB) { if ((data[0] & PMU_INT_ADB_AUTO) == 0) { struct adb_request *req = req_awaiting_reply; if (req == 0) { printk(KERN_ERR "PMU: extra ADB reply\n"); return; } req_awaiting_reply = NULL; if (len <= 2) req->reply_len = 0; else { memcpy(req->reply, data + 1, len - 1); req->reply_len = len - 1; } pmu_done(req); } else { if (len == 4 && data[1] == 0x2c) { extern int xmon_wants_key, xmon_adb_keycode; if (xmon_wants_key) { xmon_adb_keycode = data[2]; return; } } #ifdef CONFIG_ADB /* * XXX On the [23]400 the PMU gives us an up * event for keycodes 0x74 or 0x75 when the PC * card eject buttons are released, so we * ignore those events. */ if (!(pmu_kind == PMU_OHARE_BASED && len == 4 && data[1] == 0x2c && data[3] == 0xff && (data[2] & ~1) == 0xf4)) adb_input(data+1, len-1, 1); #endif /* CONFIG_ADB */ } } /* Sound/brightness button pressed */ else if ((1 << pirq) & PMU_INT_SNDBRT) { #ifdef CONFIG_PMAC_BACKLIGHT if (len == 3) pmac_backlight_set_legacy_brightness_pmu(data[1] >> 4); #endif } /* Tick interrupt */ else if ((1 << pirq) & PMU_INT_TICK) { /* Environement or tick interrupt, query batteries */ if (pmu_battery_count) { if ((--query_batt_timer) == 0) { query_battery_state(); query_batt_timer = BATTERY_POLLING_COUNT; } } } else if ((1 << pirq) & PMU_INT_ENVIRONMENT) { if (pmu_battery_count) query_battery_state(); pmu_pass_intr(data, len); /* len == 6 is probably a bad check. But how do I * know what PMU versions send what events here? */ if (len == 6) { via_pmu_event(PMU_EVT_POWER, !!(data[1]&8)); via_pmu_event(PMU_EVT_LID, data[1]&1); } } else { pmu_pass_intr(data, len); } goto next; } static struct adb_request* pmu_sr_intr(void) { struct adb_request *req; int bite = 0; if (via[B] & TREQ) { printk(KERN_ERR "PMU: spurious SR intr (%x)\n", via[B]); out_8(&via[IFR], SR_INT); return NULL; } /* The ack may not yet be low when we get the interrupt */ while ((in_8(&via[B]) & TACK) != 0) ; /* if reading grab the byte, and reset the interrupt */ if (pmu_state == reading || pmu_state == reading_intr) bite = in_8(&via[SR]); /* reset TREQ and wait for TACK to go high */ out_8(&via[B], in_8(&via[B]) | TREQ); wait_for_ack(); switch (pmu_state) { case sending: req = current_req; if (data_len < 0) { data_len = req->nbytes - 1; send_byte(data_len); break; } if (data_index <= data_len) { send_byte(req->data[data_index++]); break; } req->sent = 1; data_len = pmu_data_len[req->data[0]][1]; if (data_len == 0) { pmu_state = idle; current_req = req->next; if (req->reply_expected) req_awaiting_reply = req; else return req; } else { pmu_state = reading; data_index = 0; reply_ptr = req->reply + req->reply_len; recv_byte(); } break; case intack: data_index = 0; data_len = -1; pmu_state = reading_intr; reply_ptr = interrupt_data[int_data_last]; recv_byte(); if (gpio_irq >= 0 && !gpio_irq_enabled) { enable_irq(gpio_irq); gpio_irq_enabled = 1; } break; case reading: case reading_intr: if (data_len == -1) { data_len = bite; if (bite > 32) printk(KERN_ERR "PMU: bad reply len %d\n", bite); } else if (data_index < 32) { reply_ptr[data_index++] = bite; } if (data_index < data_len) { recv_byte(); break; } if (pmu_state == reading_intr) { pmu_state = idle; int_data_state[int_data_last] = int_data_ready; interrupt_data_len[int_data_last] = data_len; } else { req = current_req; /* * For PMU sleep and freq change requests, we lock the * PMU until it's explicitly unlocked. This avoids any * spurrious event polling getting in */ current_req = req->next; req->reply_len += data_index; if (req->data[0] == PMU_SLEEP || req->data[0] == PMU_CPU_SPEED) pmu_state = locked; else pmu_state = idle; return req; } break; default: printk(KERN_ERR "via_pmu_interrupt: unknown state %d?\n", pmu_state); } return NULL; } static irqreturn_t via_pmu_interrupt(int irq, void *arg) { unsigned long flags; int intr; int nloop = 0; int int_data = -1; struct adb_request *req = NULL; int handled = 0; /* This is a bit brutal, we can probably do better */ spin_lock_irqsave(&pmu_lock, flags); ++disable_poll; for (;;) { intr = in_8(&via[IFR]) & (SR_INT | CB1_INT); if (intr == 0) break; handled = 1; if (++nloop > 1000) { printk(KERN_DEBUG "PMU: stuck in intr loop, " "intr=%x, ier=%x pmu_state=%d\n", intr, in_8(&via[IER]), pmu_state); break; } out_8(&via[IFR], intr); if (intr & CB1_INT) { adb_int_pending = 1; pmu_irq_stats[0]++; } if (intr & SR_INT) { req = pmu_sr_intr(); if (req) break; } } recheck: if (pmu_state == idle) { if (adb_int_pending) { if (int_data_state[0] == int_data_empty) int_data_last = 0; else if (int_data_state[1] == int_data_empty) int_data_last = 1; else goto no_free_slot; pmu_state = intack; int_data_state[int_data_last] = int_data_fill; /* Sounds safer to make sure ACK is high before writing. * This helped kill a problem with ADB and some iBooks */ wait_for_ack(); send_byte(PMU_INT_ACK); adb_int_pending = 0; } else if (current_req) pmu_start(); } no_free_slot: /* Mark the oldest buffer for flushing */ if (int_data_state[!int_data_last] == int_data_ready) { int_data_state[!int_data_last] = int_data_flush; int_data = !int_data_last; } else if (int_data_state[int_data_last] == int_data_ready) { int_data_state[int_data_last] = int_data_flush; int_data = int_data_last; } --disable_poll; spin_unlock_irqrestore(&pmu_lock, flags); /* Deal with completed PMU requests outside of the lock */ if (req) { pmu_done(req); req = NULL; } /* Deal with interrupt datas outside of the lock */ if (int_data >= 0) { pmu_handle_data(interrupt_data[int_data], interrupt_data_len[int_data]); spin_lock_irqsave(&pmu_lock, flags); ++disable_poll; int_data_state[int_data] = int_data_empty; int_data = -1; goto recheck; } return IRQ_RETVAL(handled); } void pmu_unlock(void) { unsigned long flags; spin_lock_irqsave(&pmu_lock, flags); if (pmu_state == locked) pmu_state = idle; adb_int_pending = 1; spin_unlock_irqrestore(&pmu_lock, flags); } static irqreturn_t gpio1_interrupt(int irq, void *arg) { unsigned long flags; if ((in_8(gpio_reg + 0x9) & 0x02) == 0) { spin_lock_irqsave(&pmu_lock, flags); if (gpio_irq_enabled > 0) { disable_irq_nosync(gpio_irq); gpio_irq_enabled = 0; } pmu_irq_stats[1]++; adb_int_pending = 1; spin_unlock_irqrestore(&pmu_lock, flags); via_pmu_interrupt(0, NULL); return IRQ_HANDLED; } return IRQ_NONE; } void pmu_enable_irled(int on) { struct adb_request req; if (vias == NULL) return ; if (pmu_kind == PMU_KEYLARGO_BASED) return ; pmu_request(&req, NULL, 2, PMU_POWER_CTRL, PMU_POW_IRLED | (on ? PMU_POW_ON : PMU_POW_OFF)); pmu_wait_complete(&req); } void pmu_restart(void) { struct adb_request req; if (via == NULL) return; local_irq_disable(); drop_interrupts = 1; if (pmu_kind != PMU_KEYLARGO_BASED) { pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, PMU_INT_ADB | PMU_INT_TICK ); while(!req.complete) pmu_poll(); } pmu_request(&req, NULL, 1, PMU_RESET); pmu_wait_complete(&req); for (;;) ; } void pmu_shutdown(void) { struct adb_request req; if (via == NULL) return; local_irq_disable(); drop_interrupts = 1; if (pmu_kind != PMU_KEYLARGO_BASED) { pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, PMU_INT_ADB | PMU_INT_TICK ); pmu_wait_complete(&req); } else { /* Disable server mode on shutdown or we'll just * wake up again */ pmu_set_server_mode(0); } pmu_request(&req, NULL, 5, PMU_SHUTDOWN, 'M', 'A', 'T', 'T'); pmu_wait_complete(&req); for (;;) ; } int pmu_present(void) { return via != 0; } #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) /* * Put the powerbook to sleep. */ static u32 save_via[8]; static void save_via_state(void) { save_via[0] = in_8(&via[ANH]); save_via[1] = in_8(&via[DIRA]); save_via[2] = in_8(&via[B]); save_via[3] = in_8(&via[DIRB]); save_via[4] = in_8(&via[PCR]); save_via[5] = in_8(&via[ACR]); save_via[6] = in_8(&via[T1CL]); save_via[7] = in_8(&via[T1CH]); } static void restore_via_state(void) { out_8(&via[ANH], save_via[0]); out_8(&via[DIRA], save_via[1]); out_8(&via[B], save_via[2]); out_8(&via[DIRB], save_via[3]); out_8(&via[PCR], save_via[4]); out_8(&via[ACR], save_via[5]); out_8(&via[T1CL], save_via[6]); out_8(&via[T1CH], save_via[7]); out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */ out_8(&via[IFR], 0x7f); /* clear IFR */ out_8(&via[IER], IER_SET | SR_INT | CB1_INT); } #define GRACKLE_PM (1<<7) #define GRACKLE_DOZE (1<<5) #define GRACKLE_NAP (1<<4) #define GRACKLE_SLEEP (1<<3) static int powerbook_sleep_grackle(void) { unsigned long save_l2cr; unsigned short pmcr1; struct adb_request req; struct pci_dev *grackle; grackle = pci_get_bus_and_slot(0, 0); if (!grackle) return -ENODEV; /* Turn off various things. Darwin does some retry tests here... */ pmu_request(&req, NULL, 2, PMU_POWER_CTRL0, PMU_POW0_OFF|PMU_POW0_HARD_DRIVE); pmu_wait_complete(&req); pmu_request(&req, NULL, 2, PMU_POWER_CTRL, PMU_POW_OFF|PMU_POW_BACKLIGHT|PMU_POW_IRLED|PMU_POW_MEDIABAY); pmu_wait_complete(&req); /* For 750, save backside cache setting and disable it */ save_l2cr = _get_L2CR(); /* (returns -1 if not available) */ if (!__fake_sleep) { /* Ask the PMU to put us to sleep */ pmu_request(&req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T'); pmu_wait_complete(&req); } /* The VIA is supposed not to be restored correctly*/ save_via_state(); /* We shut down some HW */ pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,1); pci_read_config_word(grackle, 0x70, &pmcr1); /* Apparently, MacOS uses NAP mode for Grackle ??? */ pmcr1 &= ~(GRACKLE_DOZE|GRACKLE_SLEEP); pmcr1 |= GRACKLE_PM|GRACKLE_NAP; pci_write_config_word(grackle, 0x70, pmcr1); /* Call low-level ASM sleep handler */ if (__fake_sleep) mdelay(5000); else low_sleep_handler(); /* We're awake again, stop grackle PM */ pci_read_config_word(grackle, 0x70, &pmcr1); pmcr1 &= ~(GRACKLE_PM|GRACKLE_DOZE|GRACKLE_SLEEP|GRACKLE_NAP); pci_write_config_word(grackle, 0x70, pmcr1); pci_dev_put(grackle); /* Make sure the PMU is idle */ pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,0); restore_via_state(); /* Restore L2 cache */ if (save_l2cr != 0xffffffff && (save_l2cr & L2CR_L2E) != 0) _set_L2CR(save_l2cr); /* Restore userland MMU context */ switch_mmu_context(NULL, current->active_mm); /* Power things up */ pmu_unlock(); pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask); pmu_wait_complete(&req); pmu_request(&req, NULL, 2, PMU_POWER_CTRL0, PMU_POW0_ON|PMU_POW0_HARD_DRIVE); pmu_wait_complete(&req); pmu_request(&req, NULL, 2, PMU_POWER_CTRL, PMU_POW_ON|PMU_POW_BACKLIGHT|PMU_POW_CHARGER|PMU_POW_IRLED|PMU_POW_MEDIABAY); pmu_wait_complete(&req); return 0; } static int powerbook_sleep_Core99(void) { unsigned long save_l2cr; unsigned long save_l3cr; struct adb_request req; if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0) { printk(KERN_ERR "Sleep mode not supported on this machine\n"); return -ENOSYS; } if (num_online_cpus() > 1 || cpu_is_offline(0)) return -EAGAIN; /* Stop environment and ADB interrupts */ pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, 0); pmu_wait_complete(&req); /* Tell PMU what events will wake us up */ pmu_request(&req, NULL, 4, PMU_POWER_EVENTS, PMU_PWR_CLR_WAKEUP_EVENTS, 0xff, 0xff); pmu_wait_complete(&req); pmu_request(&req, NULL, 4, PMU_POWER_EVENTS, PMU_PWR_SET_WAKEUP_EVENTS, 0, PMU_PWR_WAKEUP_KEY | (option_lid_wakeup ? PMU_PWR_WAKEUP_LID_OPEN : 0)); pmu_wait_complete(&req); /* Save the state of the L2 and L3 caches */ save_l3cr = _get_L3CR(); /* (returns -1 if not available) */ save_l2cr = _get_L2CR(); /* (returns -1 if not available) */ if (!__fake_sleep) { /* Ask the PMU to put us to sleep */ pmu_request(&req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T'); pmu_wait_complete(&req); } /* The VIA is supposed not to be restored correctly*/ save_via_state(); /* Shut down various ASICs. There's a chance that we can no longer * talk to the PMU after this, so I moved it to _after_ sending the * sleep command to it. Still need to be checked. */ pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 1); /* Call low-level ASM sleep handler */ if (__fake_sleep) mdelay(5000); else low_sleep_handler(); /* Restore Apple core ASICs state */ pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 0); /* Restore VIA */ restore_via_state(); /* tweak LPJ before cpufreq is there */ loops_per_jiffy *= 2; /* Restore video */ pmac_call_early_video_resume(); /* Restore L2 cache */ if (save_l2cr != 0xffffffff && (save_l2cr & L2CR_L2E) != 0) _set_L2CR(save_l2cr); /* Restore L3 cache */ if (save_l3cr != 0xffffffff && (save_l3cr & L3CR_L3E) != 0) _set_L3CR(save_l3cr); /* Restore userland MMU context */ switch_mmu_context(NULL, current->active_mm); /* Tell PMU we are ready */ pmu_unlock(); pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2); pmu_wait_complete(&req); pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask); pmu_wait_complete(&req); /* Restore LPJ, cpufreq will adjust the cpu frequency */ loops_per_jiffy /= 2; return 0; } #define PB3400_MEM_CTRL 0xf8000000 #define PB3400_MEM_CTRL_SLEEP 0x70 static void __iomem *pb3400_mem_ctrl; static void powerbook_sleep_init_3400(void) { /* map in the memory controller registers */ pb3400_mem_ctrl = ioremap(PB3400_MEM_CTRL, 0x100); if (pb3400_mem_ctrl == NULL) printk(KERN_WARNING "ioremap failed: sleep won't be possible"); } static int powerbook_sleep_3400(void) { int i, x; unsigned int hid0; unsigned long msr; struct adb_request sleep_req; unsigned int __iomem *mem_ctrl_sleep; if (pb3400_mem_ctrl == NULL) return -ENOMEM; mem_ctrl_sleep = pb3400_mem_ctrl + PB3400_MEM_CTRL_SLEEP; /* Set the memory controller to keep the memory refreshed while we're asleep */ for (i = 0x403f; i >= 0x4000; --i) { out_be32(mem_ctrl_sleep, i); do { x = (in_be32(mem_ctrl_sleep) >> 16) & 0x3ff; } while (x == 0); if (x >= 0x100) break; } /* Ask the PMU to put us to sleep */ pmu_request(&sleep_req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T'); pmu_wait_complete(&sleep_req); pmu_unlock(); pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 1); asleep = 1; /* Put the CPU into sleep mode */ hid0 = mfspr(SPRN_HID0); hid0 = (hid0 & ~(HID0_NAP | HID0_DOZE)) | HID0_SLEEP; mtspr(SPRN_HID0, hid0); local_irq_enable(); msr = mfmsr() | MSR_POW; while (asleep) { mb(); mtmsr(msr); isync(); } local_irq_disable(); /* OK, we're awake again, start restoring things */ out_be32(mem_ctrl_sleep, 0x3f); pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 0); return 0; } #endif /* CONFIG_SUSPEND && CONFIG_PPC32 */ /* * Support for /dev/pmu device */ #define RB_SIZE 0x10 struct pmu_private { struct list_head list; int rb_get; int rb_put; struct rb_entry { unsigned short len; unsigned char data[16]; } rb_buf[RB_SIZE]; wait_queue_head_t wait; spinlock_t lock; #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) int backlight_locker; #endif }; static LIST_HEAD(all_pmu_pvt); static DEFINE_SPINLOCK(all_pvt_lock); static void pmu_pass_intr(unsigned char *data, int len) { struct pmu_private *pp; struct list_head *list; int i; unsigned long flags; if (len > sizeof(pp->rb_buf[0].data)) len = sizeof(pp->rb_buf[0].data); spin_lock_irqsave(&all_pvt_lock, flags); for (list = &all_pmu_pvt; (list = list->next) != &all_pmu_pvt; ) { pp = list_entry(list, struct pmu_private, list); spin_lock(&pp->lock); i = pp->rb_put + 1; if (i >= RB_SIZE) i = 0; if (i != pp->rb_get) { struct rb_entry *rp = &pp->rb_buf[pp->rb_put]; rp->len = len; memcpy(rp->data, data, len); pp->rb_put = i; wake_up_interruptible(&pp->wait); } spin_unlock(&pp->lock); } spin_unlock_irqrestore(&all_pvt_lock, flags); } static int pmu_open(struct inode *inode, struct file *file) { struct pmu_private *pp; unsigned long flags; pp = kmalloc(sizeof(struct pmu_private), GFP_KERNEL); if (pp == 0) return -ENOMEM; pp->rb_get = pp->rb_put = 0; spin_lock_init(&pp->lock); init_waitqueue_head(&pp->wait); mutex_lock(&pmu_info_proc_mutex); spin_lock_irqsave(&all_pvt_lock, flags); #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) pp->backlight_locker = 0; #endif list_add(&pp->list, &all_pmu_pvt); spin_unlock_irqrestore(&all_pvt_lock, flags); file->private_data = pp; mutex_unlock(&pmu_info_proc_mutex); return 0; } static ssize_t pmu_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { struct pmu_private *pp = file->private_data; DECLARE_WAITQUEUE(wait, current); unsigned long flags; int ret = 0; if (count < 1 || pp == 0) return -EINVAL; if (!access_ok(VERIFY_WRITE, buf, count)) return -EFAULT; spin_lock_irqsave(&pp->lock, flags); add_wait_queue(&pp->wait, &wait); current->state = TASK_INTERRUPTIBLE; for (;;) { ret = -EAGAIN; if (pp->rb_get != pp->rb_put) { int i = pp->rb_get; struct rb_entry *rp = &pp->rb_buf[i]; ret = rp->len; spin_unlock_irqrestore(&pp->lock, flags); if (ret > count) ret = count; if (ret > 0 && copy_to_user(buf, rp->data, ret)) ret = -EFAULT; if (++i >= RB_SIZE) i = 0; spin_lock_irqsave(&pp->lock, flags); pp->rb_get = i; } if (ret >= 0) break; if (file->f_flags & O_NONBLOCK) break; ret = -ERESTARTSYS; if (signal_pending(current)) break; spin_unlock_irqrestore(&pp->lock, flags); schedule(); spin_lock_irqsave(&pp->lock, flags); } current->state = TASK_RUNNING; remove_wait_queue(&pp->wait, &wait); spin_unlock_irqrestore(&pp->lock, flags); return ret; } static ssize_t pmu_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { return 0; } static unsigned int pmu_fpoll(struct file *filp, poll_table *wait) { struct pmu_private *pp = filp->private_data; unsigned int mask = 0; unsigned long flags; if (pp == 0) return 0; poll_wait(filp, &pp->wait, wait); spin_lock_irqsave(&pp->lock, flags); if (pp->rb_get != pp->rb_put) mask |= POLLIN; spin_unlock_irqrestore(&pp->lock, flags); return mask; } static int pmu_release(struct inode *inode, struct file *file) { struct pmu_private *pp = file->private_data; unsigned long flags; if (pp != 0) { file->private_data = NULL; spin_lock_irqsave(&all_pvt_lock, flags); list_del(&pp->list); spin_unlock_irqrestore(&all_pvt_lock, flags); #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) if (pp->backlight_locker) pmac_backlight_enable(); #endif kfree(pp); } return 0; } #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) static void pmac_suspend_disable_irqs(void) { /* Call platform functions marked "on sleep" */ pmac_pfunc_i2c_suspend(); pmac_pfunc_base_suspend(); } static int powerbook_sleep(suspend_state_t state) { int error = 0; /* Wait for completion of async requests */ while (!batt_req.complete) pmu_poll(); /* Giveup the lazy FPU & vec so we don't have to back them * up from the low level code */ enable_kernel_fp(); #ifdef CONFIG_ALTIVEC if (cpu_has_feature(CPU_FTR_ALTIVEC)) enable_kernel_altivec(); #endif /* CONFIG_ALTIVEC */ switch (pmu_kind) { case PMU_OHARE_BASED: error = powerbook_sleep_3400(); break; case PMU_HEATHROW_BASED: case PMU_PADDINGTON_BASED: error = powerbook_sleep_grackle(); break; case PMU_KEYLARGO_BASED: error = powerbook_sleep_Core99(); break; default: return -ENOSYS; } if (error) return error; mdelay(100); return 0; } static void pmac_suspend_enable_irqs(void) { /* Force a poll of ADB interrupts */ adb_int_pending = 1; via_pmu_interrupt(0, NULL); mdelay(10); /* Call platform functions marked "on wake" */ pmac_pfunc_base_resume(); pmac_pfunc_i2c_resume(); } static int pmu_sleep_valid(suspend_state_t state) { return state == PM_SUSPEND_MEM && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0); } static const struct platform_suspend_ops pmu_pm_ops = { .enter = powerbook_sleep, .valid = pmu_sleep_valid, }; static int register_pmu_pm_ops(void) { if (pmu_kind == PMU_OHARE_BASED) powerbook_sleep_init_3400(); ppc_md.suspend_disable_irqs = pmac_suspend_disable_irqs; ppc_md.suspend_enable_irqs = pmac_suspend_enable_irqs; suspend_set_ops(&pmu_pm_ops); return 0; } device_initcall(register_pmu_pm_ops); #endif static int pmu_ioctl(struct file *filp, u_int cmd, u_long arg) { __u32 __user *argp = (__u32 __user *)arg; int error = -EINVAL; switch (cmd) { case PMU_IOC_SLEEP: if (!capable(CAP_SYS_ADMIN)) return -EACCES; return pm_suspend(PM_SUSPEND_MEM); case PMU_IOC_CAN_SLEEP: if (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) < 0) return put_user(0, argp); else return put_user(1, argp); #ifdef CONFIG_PMAC_BACKLIGHT_LEGACY /* Compatibility ioctl's for backlight */ case PMU_IOC_GET_BACKLIGHT: { int brightness; brightness = pmac_backlight_get_legacy_brightness(); if (brightness < 0) return brightness; else return put_user(brightness, argp); } case PMU_IOC_SET_BACKLIGHT: { int brightness; error = get_user(brightness, argp); if (error) return error; return pmac_backlight_set_legacy_brightness(brightness); } #ifdef CONFIG_INPUT_ADBHID case PMU_IOC_GRAB_BACKLIGHT: { struct pmu_private *pp = filp->private_data; if (pp->backlight_locker) return 0; pp->backlight_locker = 1; pmac_backlight_disable(); return 0; } #endif /* CONFIG_INPUT_ADBHID */ #endif /* CONFIG_PMAC_BACKLIGHT_LEGACY */ case PMU_IOC_GET_MODEL: return put_user(pmu_kind, argp); case PMU_IOC_HAS_ADB: return put_user(pmu_has_adb, argp); } return error; } static long pmu_unlocked_ioctl(struct file *filp, u_int cmd, u_long arg) { int ret; mutex_lock(&pmu_info_proc_mutex); ret = pmu_ioctl(filp, cmd, arg); mutex_unlock(&pmu_info_proc_mutex); return ret; } #ifdef CONFIG_COMPAT #define PMU_IOC_GET_BACKLIGHT32 _IOR('B', 1, compat_size_t) #define PMU_IOC_SET_BACKLIGHT32 _IOW('B', 2, compat_size_t) #define PMU_IOC_GET_MODEL32 _IOR('B', 3, compat_size_t) #define PMU_IOC_HAS_ADB32 _IOR('B', 4, compat_size_t) #define PMU_IOC_CAN_SLEEP32 _IOR('B', 5, compat_size_t) #define PMU_IOC_GRAB_BACKLIGHT32 _IOR('B', 6, compat_size_t) static long compat_pmu_ioctl (struct file *filp, u_int cmd, u_long arg) { switch (cmd) { case PMU_IOC_SLEEP: break; case PMU_IOC_GET_BACKLIGHT32: cmd = PMU_IOC_GET_BACKLIGHT; break; case PMU_IOC_SET_BACKLIGHT32: cmd = PMU_IOC_SET_BACKLIGHT; break; case PMU_IOC_GET_MODEL32: cmd = PMU_IOC_GET_MODEL; break; case PMU_IOC_HAS_ADB32: cmd = PMU_IOC_HAS_ADB; break; case PMU_IOC_CAN_SLEEP32: cmd = PMU_IOC_CAN_SLEEP; break; case PMU_IOC_GRAB_BACKLIGHT32: cmd = PMU_IOC_GRAB_BACKLIGHT; break; default: return -ENOIOCTLCMD; } return pmu_unlocked_ioctl(filp, cmd, (unsigned long)compat_ptr(arg)); } #endif static const struct file_operations pmu_device_fops = { .read = pmu_read, .write = pmu_write, .poll = pmu_fpoll, .unlocked_ioctl = pmu_unlocked_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = compat_pmu_ioctl, #endif .open = pmu_open, .release = pmu_release, .llseek = noop_llseek, }; static struct miscdevice pmu_device = { PMU_MINOR, "pmu", &pmu_device_fops }; static int pmu_device_init(void) { if (!via) return 0; if (misc_register(&pmu_device) < 0) printk(KERN_ERR "via-pmu: cannot register misc device.\n"); return 0; } device_initcall(pmu_device_init); #ifdef DEBUG_SLEEP static inline void polled_handshake(volatile unsigned char __iomem *via) { via[B] &= ~TREQ; eieio(); while ((via[B] & TACK) != 0) ; via[B] |= TREQ; eieio(); while ((via[B] & TACK) == 0) ; } static inline void polled_send_byte(volatile unsigned char __iomem *via, int x) { via[ACR] |= SR_OUT | SR_EXT; eieio(); via[SR] = x; eieio(); polled_handshake(via); } static inline int polled_recv_byte(volatile unsigned char __iomem *via) { int x; via[ACR] = (via[ACR] & ~SR_OUT) | SR_EXT; eieio(); x = via[SR]; eieio(); polled_handshake(via); x = via[SR]; eieio(); return x; } int pmu_polled_request(struct adb_request *req) { unsigned long flags; int i, l, c; volatile unsigned char __iomem *v = via; req->complete = 1; c = req->data[0]; l = pmu_data_len[c][0]; if (l >= 0 && req->nbytes != l + 1) return -EINVAL; local_irq_save(flags); while (pmu_state != idle) pmu_poll(); while ((via[B] & TACK) == 0) ; polled_send_byte(v, c); if (l < 0) { l = req->nbytes - 1; polled_send_byte(v, l); } for (i = 1; i <= l; ++i) polled_send_byte(v, req->data[i]); l = pmu_data_len[c][1]; if (l < 0) l = polled_recv_byte(v); for (i = 0; i < l; ++i) req->reply[i + req->reply_len] = polled_recv_byte(v); if (req->done) (*req->done)(req); local_irq_restore(flags); return 0; } /* N.B. This doesn't work on the 3400 */ void pmu_blink(int n) { struct adb_request req; memset(&req, 0, sizeof(req)); for (; n > 0; --n) { req.nbytes = 4; req.done = NULL; req.data[0] = 0xee; req.data[1] = 4; req.data[2] = 0; req.data[3] = 1; req.reply[0] = ADB_RET_OK; req.reply_len = 1; req.reply_expected = 0; pmu_polled_request(&req); mdelay(50); req.nbytes = 4; req.done = NULL; req.data[0] = 0xee; req.data[1] = 4; req.data[2] = 0; req.data[3] = 0; req.reply[0] = ADB_RET_OK; req.reply_len = 1; req.reply_expected = 0; pmu_polled_request(&req); mdelay(50); } mdelay(50); } #endif /* DEBUG_SLEEP */ #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) int pmu_sys_suspended; static int pmu_syscore_suspend(void) { /* Suspend PMU event interrupts */ pmu_suspend(); pmu_sys_suspended = 1; #ifdef CONFIG_PMAC_BACKLIGHT /* Tell backlight code not to muck around with the chip anymore */ pmu_backlight_set_sleep(1); #endif return 0; } static void pmu_syscore_resume(void) { struct adb_request req; if (!pmu_sys_suspended) return; /* Tell PMU we are ready */ pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2); pmu_wait_complete(&req); #ifdef CONFIG_PMAC_BACKLIGHT /* Tell backlight code it can use the chip again */ pmu_backlight_set_sleep(0); #endif /* Resume PMU event interrupts */ pmu_resume(); pmu_sys_suspended = 0; } static struct syscore_ops pmu_syscore_ops = { .suspend = pmu_syscore_suspend, .resume = pmu_syscore_resume, }; static int pmu_syscore_register(void) { register_syscore_ops(&pmu_syscore_ops); return 0; } subsys_initcall(pmu_syscore_register); #endif /* CONFIG_SUSPEND && CONFIG_PPC32 */ EXPORT_SYMBOL(pmu_request); EXPORT_SYMBOL(pmu_queue_request); EXPORT_SYMBOL(pmu_poll); EXPORT_SYMBOL(pmu_poll_adb); EXPORT_SYMBOL(pmu_wait_complete); EXPORT_SYMBOL(pmu_suspend); EXPORT_SYMBOL(pmu_resume); EXPORT_SYMBOL(pmu_unlock); #if defined(CONFIG_PPC32) EXPORT_SYMBOL(pmu_enable_irled); EXPORT_SYMBOL(pmu_battery_count); EXPORT_SYMBOL(pmu_batteries); EXPORT_SYMBOL(pmu_power_flags); #endif /* CONFIG_SUSPEND && CONFIG_PPC32 */
GuneetAtwal/Blaze.Kernel-MT6589
drivers/macintosh/via-pmu.c
C
gpl-2.0
63,175
/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * (C) Copyright 1995 1996 Linus Torvalds * (C) Copyright 2001, 2002 Ralf Baechle */ #include <linux/module.h> #include <asm/addrspace.h> #include <asm/byteorder.h> #include <linux/sched.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <asm/cacheflush.h> #include <asm/io.h> #include <asm/tlbflush.h> static inline void remap_area_pte(pte_t * pte, unsigned long address, phys_t size, phys_t phys_addr, unsigned long flags) { phys_t end; unsigned long pfn; pgprot_t pgprot = __pgprot(_PAGE_GLOBAL | _PAGE_PRESENT | __READABLE | __WRITEABLE | flags); address &= ~PMD_MASK; end = address + size; if (end > PMD_SIZE) end = PMD_SIZE; BUG_ON(address >= end); pfn = phys_addr >> PAGE_SHIFT; do { if (!pte_none(*pte)) { printk("remap_area_pte: page already exists\n"); BUG(); } set_pte(pte, pfn_pte(pfn, pgprot)); address += PAGE_SIZE; pfn++; pte++; } while (address && (address < end)); } static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, phys_t size, phys_t phys_addr, unsigned long flags) { phys_t end; address &= ~PGDIR_MASK; end = address + size; if (end > PGDIR_SIZE) end = PGDIR_SIZE; phys_addr -= address; BUG_ON(address >= end); do { pte_t * pte = pte_alloc_kernel(pmd, address); if (!pte) return -ENOMEM; remap_area_pte(pte, address, end - address, address + phys_addr, flags); address = (address + PMD_SIZE) & PMD_MASK; pmd++; } while (address && (address < end)); return 0; } static int remap_area_pages(unsigned long address, phys_t phys_addr, phys_t size, unsigned long flags) { int error; pgd_t * dir; unsigned long end = address + size; phys_addr -= address; dir = pgd_offset(&init_mm, address); flush_cache_all(); BUG_ON(address >= end); do { pud_t *pud; pmd_t *pmd; error = -ENOMEM; pud = pud_alloc(&init_mm, dir, address); if (!pud) break; pmd = pmd_alloc(&init_mm, pud, address); if (!pmd) break; if (remap_area_pmd(pmd, address, end - address, phys_addr + address, flags)) break; error = 0; address = (address + PGDIR_SIZE) & PGDIR_MASK; dir++; } while (address && (address < end)); flush_tlb_all(); return error; } /* * Generic mapping function (not visible outside): */ /* * Remap an arbitrary physical address space into the kernel virtual * address space. Needed when the kernel wants to access high addresses * directly. * * NOTE! We need to allow non-page-aligned mappings too: we will obviously * have to convert them into an offset in a page-aligned mapping, but the * caller shouldn't need to know that small detail. */ #define IS_LOW512(addr) (!((phys_t)(addr) & (phys_t) ~0x1fffffffULL)) void __iomem * __ioremap(phys_t phys_addr, phys_t size, unsigned long flags) { struct vm_struct * area; unsigned long offset; phys_t last_addr; void * addr; phys_addr = fixup_bigphys_addr(phys_addr, size); /* Don't allow wraparound or zero size */ last_addr = phys_addr + size - 1; if (!size || last_addr < phys_addr) return NULL; /* * Map uncached objects in the low 512mb of address space using KSEG1, * otherwise map using page tables. */ if (IS_LOW512(phys_addr) && IS_LOW512(last_addr) && flags == _CACHE_UNCACHED) return (void __iomem *) CKSEG1ADDR(phys_addr); /* * Don't allow anybody to remap normal RAM that we're using.. */ if (phys_addr < virt_to_phys(high_memory)) { char *t_addr, *t_end; struct page *page; t_addr = __va(phys_addr); t_end = t_addr + (size - 1); for(page = virt_to_page(t_addr); page <= virt_to_page(t_end); page++) if(!PageReserved(page)) return NULL; } /* * Mappings have to be page-aligned */ offset = phys_addr & ~PAGE_MASK; phys_addr &= PAGE_MASK; size = PAGE_ALIGN(last_addr + 1) - phys_addr; /* * Ok, go for it.. */ area = get_vm_area(size, VM_IOREMAP); if (!area) return NULL; addr = area->addr; if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) { vunmap(addr); return NULL; } return (void __iomem *) (offset + (char *)addr); } #define IS_KSEG1(addr) (((unsigned long)(addr) & ~0x1fffffffUL) == CKSEG1) void __iounmap(const volatile void __iomem *addr) { struct vm_struct *p; if (IS_KSEG1(addr)) return; p = remove_vm_area((void *) (PAGE_MASK & (unsigned long __force) addr)); if (!p) printk(KERN_ERR "iounmap: bad address %p\n", addr); kfree(p); } EXPORT_SYMBOL(__ioremap); EXPORT_SYMBOL(__iounmap);
ShivangDave/android_kernel_sony_msm7x27a-Mesona
arch/mips/mm/ioremap.c
C
gpl-2.0
4,641
/****************************************************************************** AudioScience HPI driver Copyright (C) 1997-2012 AudioScience Inc. <support@audioscience.com> This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation; This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA HPI Operating System function implementation for Linux (C) Copyright AudioScience Inc. 1997-2003 ******************************************************************************/ #define SOURCEFILE_NAME "hpios.c" #include "hpi_internal.h" #include "hpidebug.h" #include <linux/delay.h> #include <linux/sched.h> void hpios_delay_micro_seconds(u32 num_micro_sec) { if ((usecs_to_jiffies(num_micro_sec) > 1) && !in_interrupt()) { /* MUST NOT SCHEDULE IN INTERRUPT CONTEXT! */ schedule_timeout_uninterruptible(usecs_to_jiffies (num_micro_sec)); } else if (num_micro_sec <= 2000) udelay(num_micro_sec); else mdelay(num_micro_sec / 1000); } /** Allocate an area of locked memory for bus master DMA operations. If allocation fails, return 1, and *pMemArea.size = 0 */ u16 hpios_locked_mem_alloc(struct consistent_dma_area *p_mem_area, u32 size, struct pci_dev *pdev) { /*?? any benefit in using managed dmam_alloc_coherent? */ p_mem_area->vaddr = dma_alloc_coherent(&pdev->dev, size, &p_mem_area->dma_handle, GFP_DMA32 | GFP_KERNEL); if (p_mem_area->vaddr) { HPI_DEBUG_LOG(DEBUG, "allocated %d bytes, dma 0x%x vma %p\n", size, (unsigned int)p_mem_area->dma_handle, p_mem_area->vaddr); p_mem_area->pdev = &pdev->dev; p_mem_area->size = size; return 0; } else { HPI_DEBUG_LOG(WARNING, "failed to allocate %d bytes locked memory\n", size); p_mem_area->size = 0; return 1; } } u16 hpios_locked_mem_free(struct consistent_dma_area *p_mem_area) { if (p_mem_area->size) { dma_free_coherent(p_mem_area->pdev, p_mem_area->size, p_mem_area->vaddr, p_mem_area->dma_handle); HPI_DEBUG_LOG(DEBUG, "freed %lu bytes, dma 0x%x vma %p\n", (unsigned long)p_mem_area->size, (unsigned int)p_mem_area->dma_handle, p_mem_area->vaddr); p_mem_area->size = 0; return 0; } else { return 1; } }
mathkid95/linux_motorola_lollipop
sound/pci/asihpi/hpios.c
C
gpl-2.0
2,680
/* * NET3: 802.3 data link hooks used for IPX 802.3 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * 802.3 isn't really a protocol data link layer. Some old IPX stuff * uses it however. Note that there is only one 802.3 protocol layer * in the system. We don't currently support different protocols * running raw 802.3 on different devices. Thankfully nobody else * has done anything like the old IPX. */ #include <linux/in.h> #include <linux/mm.h> #include <linux/module.h> #include <linux/netdevice.h> #include <linux/skbuff.h> #include <linux/slab.h> #include <net/datalink.h> #include <net/p8022.h> /* * Place an 802.3 header on a packet. The driver will do the mac * addresses, we just need to give it the buffer length. */ static int p8023_request(struct datalink_proto *dl, struct sk_buff *skb, unsigned char *dest_node) { struct net_device *dev = skb->dev; dev_hard_header(skb, dev, ETH_P_802_3, dest_node, NULL, skb->len); return dev_queue_xmit(skb); } /* * Create an 802.3 client. Note there can be only one 802.3 client */ struct datalink_proto *make_8023_client(void) { struct datalink_proto *proto = kmalloc(sizeof(*proto), GFP_ATOMIC); if (proto) { proto->header_length = 0; proto->request = p8023_request; } return proto; } /* * Destroy the 802.3 client. */ void destroy_8023_client(struct datalink_proto *dl) { kfree(dl); } EXPORT_SYMBOL(destroy_8023_client); EXPORT_SYMBOL(make_8023_client); MODULE_LICENSE("GPL");
bigbiff/android_device_samsung_mondrianwfiue
net/802/p8023.c
C
gpl-2.0
1,687
<?php /** * SimplePie * * A PHP-Based RSS and Atom Feed Framework. * Takes the hard work out of managing a complete RSS/Atom solution. * * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * * 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. * * * Neither the name of the SimplePie Team nor the names of its contributors may be used * to endorse or promote products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDERS * AND CONTRIBUTORS 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. * * @package SimplePie * @version 1.3.1 * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue * @author Ryan Parman * @author Geoffrey Sneddon * @author Ryan McCue * @link http://simplepie.org/ SimplePie * @license http://www.opensource.org/licenses/bsd-license.php BSD License */ /** * Content-type sniffing * * Based on the rules in http://tools.ietf.org/html/draft-abarth-mime-sniff-06 * * This is used since we can't always trust Content-Type headers, and is based * upon the HTML5 parsing rules. * * * This class can be overloaded with {@see SimplePie::set_content_type_sniffer_class()} * * @package SimplePie * @subpackage HTTP */ class SimplePie_Content_Type_Sniffer { /** * File object * * @var SimplePie_File */ var $file; /** * Create an instance of the class with the input file * * @param SimplePie_Content_Type_Sniffer $file Input file */ public function __construct($file) { $this->file = $file; } /** * Get the Content-Type of the specified file * * @return string Actual Content-Type */ public function get_type() { if (isset($this->file->headers['content-type'])) { if (!isset($this->file->headers['content-encoding']) && ($this->file->headers['content-type'] === 'text/plain' || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1' || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1' || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8')) { return $this->text_or_binary(); } if (($pos = strpos($this->file->headers['content-type'], ';')) !== false) { $official = substr($this->file->headers['content-type'], 0, $pos); } else { $official = $this->file->headers['content-type']; } $official = trim(strtolower($official)); if ($official === 'unknown/unknown' || $official === 'application/unknown') { return $this->unknown(); } elseif (substr($official, -4) === '+xml' || $official === 'text/xml' || $official === 'application/xml') { return $official; } elseif (substr($official, 0, 6) === 'image/') { if ($return = $this->image()) { return $return; } else { return $official; } } elseif ($official === 'text/html') { return $this->feed_or_html(); } else { return $official; } } else { return $this->unknown(); } } /** * Sniff text or binary * * @return string Actual Content-Type */ public function text_or_binary() { if (substr($this->file->body, 0, 2) === "\xFE\xFF" || substr($this->file->body, 0, 2) === "\xFF\xFE" || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF" || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF") { return 'text/plain'; } elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body)) { return 'application/octect-stream'; } else { return 'text/plain'; } } /** * Sniff unknown * * @return string Actual Content-Type */ public function unknown() { $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20"); if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html' || strtolower(substr($this->file->body, $ws, 5)) === '<html' || strtolower(substr($this->file->body, $ws, 7)) === '<script') { return 'text/html'; } elseif (substr($this->file->body, 0, 5) === '%PDF-') { return 'application/pdf'; } elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-') { return 'application/postscript'; } elseif (substr($this->file->body, 0, 6) === 'GIF87a' || substr($this->file->body, 0, 6) === 'GIF89a') { return 'image/gif'; } elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") { return 'image/png'; } elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") { return 'image/jpeg'; } elseif (substr($this->file->body, 0, 2) === "\x42\x4D") { return 'image/bmp'; } elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") { return 'image/vnd.microsoft.icon'; } else { return $this->text_or_binary(); } } /** * Sniff images * * @return string Actual Content-Type */ public function image() { if (substr($this->file->body, 0, 6) === 'GIF87a' || substr($this->file->body, 0, 6) === 'GIF89a') { return 'image/gif'; } elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") { return 'image/png'; } elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") { return 'image/jpeg'; } elseif (substr($this->file->body, 0, 2) === "\x42\x4D") { return 'image/bmp'; } elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") { return 'image/vnd.microsoft.icon'; } else { return false; } } /** * Sniff HTML * * @return string Actual Content-Type */ public function feed_or_html() { $len = strlen($this->file->body); $pos = strspn($this->file->body, "\x09\x0A\x0D\x20"); while ($pos < $len) { switch ($this->file->body[$pos]) { case "\x09": case "\x0A": case "\x0D": case "\x20": $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos); continue 2; case '<': $pos++; break; default: return 'text/html'; } if (substr($this->file->body, $pos, 3) === '!--') { $pos += 3; if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false) { $pos += 3; } else { return 'text/html'; } } elseif (substr($this->file->body, $pos, 1) === '!') { if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false) { $pos++; } else { return 'text/html'; } } elseif (substr($this->file->body, $pos, 1) === '?') { if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false) { $pos += 2; } else { return 'text/html'; } } elseif (substr($this->file->body, $pos, 3) === 'rss' || substr($this->file->body, $pos, 7) === 'rdf:RDF') { return 'application/rss+xml'; } elseif (substr($this->file->body, $pos, 4) === 'feed') { return 'application/atom+xml'; } else { return 'text/html'; } } return 'text/html'; } }
ernandesferreira/casorio
wp-includes/SimplePie/Content/Type/Sniffer.php
PHP
gpl-2.0
8,137
/* * Generate devlist.h from the Zorro ID file. * * (c) 2000 Geert Uytterhoeven <geert@linux-m68k.org> * * Based on the PCI version: * * (c) 1999--2000 Martin Mares <mj@ucw.cz> */ #include <stdio.h> #include <string.h> #define MAX_NAME_SIZE 63 static void pq(FILE *f, const char *c) { while (*c) { if (*c == '"') fprintf(f, "\\\""); else fputc(*c, f); c++; } } int main(void) { char line[1024], *c, *bra, manuf[8]; int manufs = 0; int mode = 0; int lino = 0; int manuf_len = 0; FILE *devf; devf = fopen("devlist.h", "w"); if (!devf) { fprintf(stderr, "Cannot create output file!\n"); return 1; } while (fgets(line, sizeof(line)-1, stdin)) { lino++; if ((c = strchr(line, '\n'))) *c = 0; if (!line[0] || line[0] == '#') continue; if (line[0] == '\t') { switch (mode) { case 1: if (strlen(line) > 5 && line[5] == ' ') { c = line + 5; while (*c == ' ') *c++ = 0; if (manuf_len + strlen(c) + 1 > MAX_NAME_SIZE) { /* Too long, try cutting off long description */ bra = strchr(c, '['); if (bra && bra > c && bra[-1] == ' ') bra[-1] = 0; if (manuf_len + strlen(c) + 1 > MAX_NAME_SIZE) { fprintf(stderr, "Line %d: Product name too long\n", lino); return 1; } } fprintf(devf, "\tPRODUCT(%s,%s,\"", manuf, line+1); pq(devf, c); fputs("\")\n", devf); } else goto err; break; default: goto err; } } else if (strlen(line) > 4 && line[4] == ' ') { c = line + 4; while (*c == ' ') *c++ = 0; if (manufs) fputs("ENDMANUF()\n\n", devf); manufs++; strcpy(manuf, line); manuf_len = strlen(c); if (manuf_len + 24 > MAX_NAME_SIZE) { fprintf(stderr, "Line %d: manufacturer name too long\n", lino); return 1; } fprintf(devf, "MANUF(%s,\"", manuf); pq(devf, c); fputs("\")\n", devf); mode = 1; } else { err: fprintf(stderr, "Line %d: Syntax error in mode %d: %s\n", lino, mode, line); return 1; } } fputs("ENDMANUF()\n\ \n\ #undef MANUF\n\ #undef PRODUCT\n\ #undef ENDMANUF\n", devf); fclose(devf); return 0; }
mtitinger/acme-linux
drivers/zorro/gen-devlist.c
C
gpl-2.0
2,134
/* * Apple Onboard Audio driver core * * Copyright 2006 Johannes Berg <johannes@sipsolutions.net> * * GPL v2, can be found in COPYING. */ #include <linux/init.h> #include <linux/module.h> #include <linux/list.h> #include "../aoa.h" #include "alsa.h" MODULE_DESCRIPTION("Apple Onboard Audio Sound Driver"); MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>"); MODULE_LICENSE("GPL"); /* We allow only one fabric. This simplifies things, * and more don't really make that much sense */ static struct aoa_fabric *fabric; static LIST_HEAD(codec_list); static int attach_codec_to_fabric(struct aoa_codec *c) { int err; if (!try_module_get(c->owner)) return -EBUSY; /* found_codec has to be assigned */ err = -ENOENT; if (fabric->found_codec) err = fabric->found_codec(c); if (err) { module_put(c->owner); printk(KERN_ERR "snd-aoa: fabric didn't like codec %s\n", c->name); return err; } c->fabric = fabric; err = 0; if (c->init) err = c->init(c); if (err) { printk(KERN_ERR "snd-aoa: codec %s didn't init\n", c->name); c->fabric = NULL; if (fabric->remove_codec) fabric->remove_codec(c); module_put(c->owner); return err; } if (fabric->attached_codec) fabric->attached_codec(c); return 0; } int aoa_codec_register(struct aoa_codec *codec) { int err = 0; /* if there's a fabric already, we can tell if we * will want to have this codec, so propagate error * through. Otherwise, this will happen later... */ if (fabric) err = attach_codec_to_fabric(codec); if (!err) list_add(&codec->list, &codec_list); return err; } EXPORT_SYMBOL_GPL(aoa_codec_register); void aoa_codec_unregister(struct aoa_codec *codec) { list_del(&codec->list); if (codec->fabric && codec->exit) codec->exit(codec); if (fabric && fabric->remove_codec) fabric->remove_codec(codec); codec->fabric = NULL; module_put(codec->owner); } EXPORT_SYMBOL_GPL(aoa_codec_unregister); int aoa_fabric_register(struct aoa_fabric *new_fabric, struct device *dev) { struct aoa_codec *c; int err; /* allow querying for presence of fabric * (i.e. do this test first!) */ if (new_fabric == fabric) { err = -EALREADY; goto attach; } if (fabric) return -EEXIST; if (!new_fabric) return -EINVAL; err = aoa_alsa_init(new_fabric->name, new_fabric->owner, dev); if (err) return err; fabric = new_fabric; attach: list_for_each_entry(c, &codec_list, list) { if (c->fabric != fabric) attach_codec_to_fabric(c); } return err; } EXPORT_SYMBOL_GPL(aoa_fabric_register); void aoa_fabric_unregister(struct aoa_fabric *old_fabric) { struct aoa_codec *c; if (fabric != old_fabric) return; list_for_each_entry(c, &codec_list, list) { if (c->fabric) aoa_fabric_unlink_codec(c); } aoa_alsa_cleanup(); fabric = NULL; } EXPORT_SYMBOL_GPL(aoa_fabric_unregister); void aoa_fabric_unlink_codec(struct aoa_codec *codec) { if (!codec->fabric) { printk(KERN_ERR "snd-aoa: fabric unassigned " "in aoa_fabric_unlink_codec\n"); dump_stack(); return; } if (codec->exit) codec->exit(codec); if (codec->fabric->remove_codec) codec->fabric->remove_codec(codec); codec->fabric = NULL; module_put(codec->owner); } EXPORT_SYMBOL_GPL(aoa_fabric_unlink_codec); static int __init aoa_init(void) { return 0; } static void __exit aoa_exit(void) { aoa_alsa_cleanup(); } module_init(aoa_init); module_exit(aoa_exit);
engine95/exynos5433-BPB1-gts28-210wifi
sound/aoa/core/core.c
C
gpl-2.0
3,387
/* Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckfinder.com/license */ html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent;}body{line-height:1;}ol,ul{list-style:none;}blockquote,q{quotes:none;}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none;}:focus{outline:0;}ins{text-decoration:none;}del{text-decoration:line-through;}table{border-collapse:collapse;border-spacing:0;}body{font:9pt/1.5em Arial,Helvetica,sans-serif;}pre,code,tt{font:1em/1.5em 'Andale Mono','Lucida Console',monospace;}h1,h2,h3,h4,h5,h6,b,strong{font-weight:bold;}em,i,dfn{font-style:italic;}dfn{font-weight:bold;}p,code,pre,kbd{margin:0 0 1.5em 0;}blockquote{margin:0 1.5em 1.5em 1.5em;}li ul,li ol{margin:0 1.5em;}ul,ol{margin:0 1.5em 1.5em 1.5em;}ul,ul li{list-style-type:disc;}ol,ol li{list-style-type:decimal;}dl{margin:0 0 1.5em 0;}dl dt{font-weight:bold;}dd{margin-left:1.5em;}table{margin-bottom:1.4em;width:100%;}th{font-weight:bold;}th,td,caption{padding:4px 10px 4px 5px;}tfoot{font-style:italic;}sup,sub{line-height:0;}abbr,acronym{border-bottom:1px dotted;}address{margin:0 0 1.5em;font-style:italic;}del{text-decoration:line-through;}pre{margin:1.5em 0;white-space:pre;}img.centered,.aligncenter,div.aligncenter{display:block;margin-left:auto;margin-right:auto;}img.alignright{display:inline;}img.alignleft{display:inline;}.alignright{float:right;margin-left:10px;}.alignleft{float:left;margin-right:10px;}.clearfix::after,.group::after{content:".";display:block;height:0;clear:both;visibility:hidden;}*:first-child+html .clearfix{zoom:1;display:block;}* html .clearfix{zoom:1;display:block;}*:first-child+html .group{zoom:1;display:block;}* html .group{zoom:1;display:block;}html,body,.fake_wrapper,#ckfinder{height:100%;width:100%;overflow:hidden;}#ckfinder_view{text-align:left;width:100%;height:100%;margin:auto;}.container{vertical-align:top;padding:0;height:100%;overflow:hidden;}.columns_1 #sidebar_container{display:none;}.columns_2 #sidebar_container{width:200px;}#sidebar_wrapper{height:100%;}#sidebar_container{float:left;}#folder_view,.tools_view{overflow:hidden;}#status_view{height:2em;}#panel_view{overflow:auto;}#panel_view,#files_view{clear:both;}.cke_compatibility a,.cke_compatibility a:hover,.cke_compatibility a:active,.cke_compatibility a:visited{color:black;text-decoration:none;}.cke_compatibility,.cke_compatibility td,.cke_compatibility td *{font-size:11px;font-family:'Microsoft Sans Serif',Tahoma,Arial,Verdana,Sans-Serif;line-height:1;}.cke_compatibility tbody{border:0;}.cke_compatibility .cke_accessibility{display:none;}.cke_compatibility table{width:auto;}.cke_compatibility{background-color:#FFF;}.cke_compatibility *{color:black;height:auto;border-collapse:collapse;padding:0;margin:0;vertical-align:baseline;white-space:nowrap;}.cke_compatibility pre,.cke_compatibility textarea{white-space:pre;}.cke_compatibility code,.cke_compatibility font{white-space:normal;}@media print{.cke_skin_v1 .cke_toolbox{display:none;}}.cke_skin_v1 .cke_browser_webkit .cke_toolbox,.cke_skin_v1 .cke_browser_webkit .cke_toolbox>span{white-space:normal;}.cke_skin_v1 a.cke_toolbox_collapser,.cke_skin_v1 a:hover.cke_toolbox_collapser{background-image:url(images/sprites.png);_background-image:url(images/sprites_ie6.png);background-position:3px -739px;background-repeat:no-repeat;width:11px;height:11px;float:right;border:outset 1px;margin:11px 2px 2px;cursor:pointer;}.cke_skin_v1 .cke_rtl a.cke_toolbox_collapser,.cke_skin_v1 .cke_rtl a:hover.cke_toolbox_collapser{float:left;}.cke_skin_v1 a.cke_toolbox_collapser_min,.cke_skin_v1 a:hover.cke_toolbox_collapser_min{background-image:url(images/sprites.png);_background-image:url(images/sprites_ie6.png);background-position:4px -760px;background-repeat:no-repeat;margin:2px;}.cke_skin_v1 .cke_rtl a.cke_toolbox_collapser_min,.cke_skin_v1 .cke_rtl a:hover.cke_toolbox_collapser_min{background-position:4px -781px;} .cke_skin_v1 .cke_toolbar{padding-top:1px;padding-bottom:1px;display:inline-block;float:left;}.cke_skin_v1 .cke_rtl .cke_toolbar{float:right;}.cke_skin_v1 .cke_toolgroup{display:inline-block;float:left;}.cke_skin_v1 .cke_browser_ie .cke_toolgroup{#float:none;#display:inline;}.cke_skin_v1 .cke_rtl .cke_toolgroup{float:right;}.cke_skin_v1 .cke_browser_ie .cke_rtl .cke_toolgroup{#float:none;}.cke_skin_v1 .cke_separator{display:inline-block;float:left;border-left:solid 1px #999;margin:0 2px;height:16px;}.cke_skin_v1 .cke_browser_ie .cke_separator{#float:none;#display:inline;}.cke_skin_v1 .cke_rtl .cke_separator{float:right;}.cke_skin_v1 .cke_browser_ie .cke_rtl .cke_separator{#float:none;}.cke_skin_v1 .cke_break{clear:left;}.cke_skin_v1 .cke_rtl .cke_break{clear:right;}.cke_skin_v1 .cke_toolbar_start{display:inline-block;background-image:url(images/toolbar_start.gif);background-repeat:no-repeat;margin:4px 2px 0 2px;width:3px;height:16px;float:left;}.cke_skin_v1 .cke_browser_ie .cke_toolbar_start{#float:none;#display:inline;}.cke_skin_v1 .cke_rtl .cke_toolbar_start{float:right;}.cke_skin_v1 .cke_browser_ie .cke_rtl .cke_toolbar_start{#float:none;}.cke_skin_v1 .cke_toolbar_end{display:inline-block;float:left;}.cke_skin_v1 .cke_browser_ie .cke_toolbar_end{#float:none;#display:inline;}.cke_skin_v1 .cke_rtl .cke_toolbar_end{float:right;}.cke_skin_v1 .cke_browser_ie .cke_rtl .cke_toolbar_end{#float:none;}.cke_skin_v1 .cke_button a,.cke_skin_v1 .cke_button a:hover,.cke_skin_v1 .cke_button a:focus,.cke_skin_v1 .cke_button a:active,.cke_skin_v1 .cke_button a.cke_off{border:solid 1px #efefde;display:inline-block;border-radius:3px;outline:none;padding-top:2px;padding-left:4px;padding-right:4px;padding-bottom:2px;height:18px;cursor:default;}.cke_skin_v1 .cke_button a,.cke_skin_v1 .cke_button a.cke_off{background-color:#efefde;filter:alpha(opacity=70);opacity:.70;-moz-border-radius:3px;-webkit-border-radius:3px;}.cke_skin_v1 .cke_hc .cke_button a,.cke_skin_v1 .cke_hc .cke_button a.cke_off{opacity:1.0;filter:alpha(opacity=100);}.cke_skin_v1 .cke_button a.cke_on{border:solid 1px #316ac5;background-color:#a3d7ff;filter:alpha(opacity=100);opacity:1;}.cke_skin_v1 .cke_hc .cke_button a.cke_on{padding:0 2px!important;border-width:3px;}.cke_skin_v1 .cke_button a.cke_disabled,.cke_skin_v1 .cke_browser_ie a:hover.cke_button .cke_disabled{border:solid 1px #efefde;background-color:#efefde;filter:alpha(opacity=30);opacity:.3;}.cke_skin_v1 .cke_hc .cke_button a.cke_disabled,.cke_skin_v1 .cke_browser_ie.cke_hc a:hover.cke_button .cke_disabled{filter:alpha(opacity=60);opacity:.6;}.cke_skin_v1 .cke_button a:hover.cke_on,.cke_skin_v1 .cke_button a:focus.cke_on,.cke_skin_v1 .cke_button a:active.cke_on,.cke_skin_v1 .cke_button a:hover.cke_off,.cke_skin_v1 .cke_button a:focus.cke_off,.cke_skin_v1 .cke_button a:active.cke_off{border:solid 1px #316ac5;background-color:#dff1ff;filter:alpha(opacity=100);opacity:1;padding:2px 4px;}.cke_skin_v1 .cke_hc .cke_button a:hover.cke_on,.cke_skin_v1 .cke_hc .cke_button a:focus.cke_on,.cke_skin_v1 .cke_hc .cke_button a:active.cke_on,.cke_skin_v1 .cke_hc .cke_button a:hover.cke_off,.cke_skin_v1 .cke_hc .cke_button a:focus.cke_off,.cke_skin_v1 .cke_hc .cke_button a:active.cke_off{padding:0 2px!important;border-width:3px;}.cke_skin_v1 .cke_button .cke_icon{margin-top:1px;width:16px;height:16px;display:inline-block;}.cke_skin_v1 .cke_button .cke_label{cursor:default;display:none;padding-left:3px;vertical-align:3px;}.cke_skin_v1 .cke_hc .cke_button .cke_label{padding:0;display:inline-block;}.cke_skin_v1 .cke_hc .cke_button .cke_icon{display:none;}.cke_skin_v1 .cke_accessibility{position:absolute;display:block;width:0;height:0;overflow:hidden;}.cke_skin_v1 .cke_button .cke_buttonarrow{display:inline-block;height:17px;width:8px;background-position:2px -717px;background-image:url(images/sprites.png);_background-image:url(images/sprites_ie6.png);background-repeat:no-repeat;}.cke_skin_v1 .cke_rtl .cke_button .cke_buttonarrow{background-position:0 -717px;background-image:url(images/sprites.png);_background-image:url(images/sprites_ie6.png);} .cke_skin_v1 .cke_browser_gecko18 .cke_toolbar,.cke_skin_v1 .cke_browser_gecko18 .cke_button a,.cke_skin_v1 .cke_browser_gecko18 .cke_button a.cke_off,.cke_skin_v1 .cke_browser_gecko18 .cke_button .cke_icon,.cke_skin_v1 .cke_browser_gecko18 .cke_button .cke_buttonarrow,.cke_skin_v1 .cke_browser_gecko18 .cke_separator,.cke_skin_v1 .cke_browser_gecko18 .cke_toolbar_start{display:block;float:left;}.cke_skin_v1 .cke_browser_gecko18 .cke_hc .cke_button .cke_icon{display:none;}.cke_skin_v1 .cke_browser_gecko18 .cke_rtl .cke_toolbar,.cke_skin_v1 .cke_browser_gecko18 .cke_rtl .cke_button a,.cke_skin_v1 .cke_browser_gecko18 .cke_rtl .cke_button a.cke_off,.cke_skin_v1 .cke_browser_gecko18 .cke_rtl .cke_button .cke_icon,.cke_skin_v1 .cke_browser_gecko18 .cke_rtl .cke_button .cke_buttonarrow,.cke_skin_v1 .cke_browser_gecko18 .cke_rtl .cke_separator,.cke_skin_v1 .cke_browser_gecko18 .cke_rtl .cke_toolbar_start{float:right;}.cke_skin_v1 .cke_browser_gecko18 .cke_button .cke_label,.cke_skin_v1 .cke_browser_gecko18 .cke_break{float:left;}.cke_skin_v1 .cke_browser_gecko18 .cke_rtl span.cke_inline_label{float:right;}.cke_skin_v1 .cke_browser_gecko18 .cke_rtl .cke_button .cke_label,.cke_skin_v1 .cke_browser_gecko18 .cke_rtl .cke_break{float:right;}.cke_skin_v1 .cke_browser_gecko18 .cke_separator{margin-top:4px;}.cke_skin_v1 .cke_browser_gecko18 .cke_button .cke_label{padding-top:3px;}.cke_skin_v1 .cke_browser_ie .cke_rtl .cke_toolgroup,.cke_skin_v1 .cke_browser_ie .cke_rtl .cke_separator,.cke_skin_v1 .cke_browser_ie .cke_rtl .cke_toolbar_start,.cke_skin_v1 .cke_browser_ie .cke_rtl .cke_toolbar_end{float:none;}.cke_skin_v1 .cke_browser_ie8 .cke_toolbar,.cke_skin_v1 .cke_browser_ie8 .cke_toolgroup{vertical-align:top;}.cke_skin_v1 .cke_browser_iequirks.cke_browser_ie8 .cke_toolbar,.cke_skin_v1 .cke_browser_iequirks.cke_browser_ie8 .cke_toolgroup{vertical-align:baseline;}.cke_skin_v1 .cke_button_TruncateBasket .cke_icon{background:url('images/toolbar/clear_basket.gif') no-repeat 0 0;}.cke_skin_v1 .cke_button_settings .cke_icon{background:url('images/toolbar/settings.gif') no-repeat 0 0;}.cke_skin_v1 .cke_button_refresh .cke_icon{background:url('images/toolbar/refresh.gif') no-repeat 0 0;}.cke_skin_v1 .cke_button_upload .cke_icon{background:url('images/toolbar/add.gif') no-repeat 0 0;}.cke_skin_v1 .cke_button_help .cke_icon{background:url('images/toolbar/help.gif') no-repeat 0 0;}.cke_skin_v1 .cke_button_downloadFile .cke_icon{background:url('images/toolbar/download.gif') no-repeat 0 0;}.cke_skin_v1 .cke_button_viewFile .cke_icon{background:url('images/toolbar/view.gif') no-repeat 0 0;}.cke_skin_v1 .cke_button_deleteFile .cke_icon{background:url('images/toolbar/delete.gif') no-repeat 0 0;}.cke_skin_v1 .cke_button_removeFolder .cke_icon{background:url('images/toolbar/delete.gif') no-repeat 0 0;}#folders_view .folder_tree li a{background:url('images/ckffolder.gif') 3px 0 no-repeat;}#folders_view .folder_tree li.closable a{background-image:url('images/ckffolderopened.gif');}#folders_view .folder_tree li.openable a{background-image:url('images/ckffolder.gif');}#folders_view .folder_tree li.nochildren a{background-image:url('images/ckffolder.gif');}#folders_view .folder_tree li a.processing{background-image:url('images/loaders/16x16.gif');}#folders_view .folder_tree li.closable .expander{background-image:url('images/ckfminus.gif');}#folders_view .folder_tree li.openable .expander{background-image:url('images/ckfplus.gif');}#files_view .files_thumbnails .processing div.image{background:url("images/loaders/32x32.gif") 50% 50% no-repeat;}.cke_skin_v1 .cke_contextmenu{padding:2px;}.cke_skin_v1 .cke_menuitem a{display:block;}.cke_skin_v1 .cke_menuitem span{cursor:default;}.cke_skin_v1 .cke_menuitem a:hover,.cke_skin_v1 .cke_menuitem a:focus,.cke_skin_v1 .cke_menuitem a:active{background-color:#8f8f73;display:block;}.cke_skin_v1 .cke_menuitem a.cke_disabled:hover,.cke_skin_v1 .cke_menuitem a.cke_disabled:focus,.cke_skin_v1 .cke_menuitem a.cke_disabled:active{background-color:transparent!important;}.cke_skin_v1 .cke_menuitem .cke_icon{width:16px;height:16px;float:left;} .cke_skin_v1 .cke_menuitem .cke_disabled .cke_icon{filter:alpha(opacity=70);opacity:.70;}.cke_skin_v1 .cke_menuitem .cke_icon_wrapper{background-color:#e3e3c7;border:solid 4px #e3e3c7;width:16px;height:16px;float:left;filter:alpha(opacity=70);opacity:.70;}.cke_rtl .cke_skin_v1 .cke_menuitem .cke_icon_wrapper{float:right;}.cke_skin_v1 .cke_menuitem a:hover .cke_icon_wrapper,.cke_skin_v1 .cke_menuitem a:focus .cke_icon_wrapper,.cke_skin_v1 .cke_menuitem a:active .cke_icon_wrapper{background-color:#9d9d9d;border:solid 4px #9d9d9d;filter:alpha(opacity=70);opacity:.70;}.cke_skin_v1 .cke_menuitem a:hover.cke_disabled .cke_icon_wrapper,.cke_skin_v1 .cke_menuitem a:focus.cke_disabled .cke_icon_wrapper,.cke_skin_v1 .cke_menuitem a:active.cke_disabled .cke_icon_wrapper{background-color:#e3e3c7;border:solid 4px #e3e3c7;}.cke_skin_v1 .cke_menuitem .cke_label{display:block;padding-right:3px;padding-top:5px;padding-left:4px;height:19px;margin-left:24px;background-color:#fff;}.cke_skin_v1 .cke_frameLoaded .cke_menuitem .cke_label{filter:alpha(opacity=70);opacity:.70;}.cke_rtl .cke_skin_v1 .cke_menuitem .cke_label{padding-right:0;margin-left:0;padding-left:3px;margin-right:28px;}.cke_skin_v1 .cke_menuitem a.cke_disabled .cke_label{filter:alpha(opacity=30);opacity:.30;}.cke_skin_v1 .cke_menuitem a:hover .cke_label,.cke_skin_v1 .cke_menuitem a:focus .cke_label,.cke_skin_v1 .cke_menuitem a:active .cke_label{background-color:#8f8f73;color:white;}.cke_skin_v1 .cke_menuitem a.cke_disabled:hover .cke_label,.cke_skin_v1 .cke_menuitem a.cke_disabled:focus .cke_label,.cke_skin_v1 .cke_menuitem a.cke_disabled:active .cke_label{background-color:transparent;color:black;}.cke_skin_v1 .cke_menuseparator{background-color:#e3e3c7;height:2px;filter:alpha(opacity=70);opacity:.70;_font-size:0;}.cke_skin_v1 .cke_menuarrow{background-image:url(images/sprites.png);_background-image:url(images/sprites_ie6.png);background-position:0 -784px;background-repeat:no-repeat;height:5px;width:3px;float:right;margin-right:2px;margin-top:3px;}.cke_rtl .cke_skin_v1 .cke_menuarrow{float:left;margin-right:0;margin-left:2px;background-position:0 -763px;}.cke_browser_ie.cke_ltr .cke_skin_v1 .cke_menuarrow{position:absolute;right:2px;}.cke_browser_ie.cke_rtl .cke_skin_v1 .cke_menuarrow{position:absolute;left:2px;}.cke_skin_v1 .cke_panel{border:1px solid #8f8f73;background-color:#fff;width:120px;height:100px;overflow:hidden;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;}.cke_skin_v1 .cke_panel iframe{width:100%;height:100%;}html.cke_skin_v1_container{overflow:auto;overflow-x:hidden;}body.cke_panel_frame{overflow:auto;overflow-x:hidden;}ul.cke_panel_list{list-style-type:none;margin:3px;padding:0;white-space:nowrap;}li.cke_panel_listItem{margin:0;}.cke_panel_listItem a{padding:2px;display:block;border:1px solid #fff;color:inherit;text-decoration:none;overflow:hidden;text-overflow:ellipsis;}* html .cke_panel_listItem a{width:100%;color:#000;}*:first-child+html .cke_panel_listItem a{color:#000;}.cke_panel_listItem.cke_selected a{border:1px solid #ccc;background-color:#e9f5ff;}.cke_panel_listItem a:hover,.cke_panel_listItem a:focus,.cke_panel_listItem a:active{border-color:#316ac5;background-color:#dff1ff;}.cke_panel_grouptitle{font-size:11px;font-family:'Microsoft Sans Serif',Tahoma,Arial,Verdana,Sans-Serif;font-weight:bold;white-space:nowrap;background-color:#dcdcdc;color:#000;margin:0;padding:3px;}html.cke_skin_v1_container{visibility:visible;}body .cke_dialog{visibility:visible;}.cke_skin_v1 table.cke_dialog.cke_browser_gecko{display:block;}.cke_skin_v1 .cke_dialog_body{margin-left:16px;margin-right:16px;margin-top:2px;margin-bottom:20px;z-index:1;position:relative;_position:static;}.cke_skin_v1 .cke_dialog_tl,.cke_skin_v1 .cke_dialog_tr,.cke_skin_v1 .cke_dialog_tc,.cke_skin_v1 .cke_dialog_bl,.cke_skin_v1 .cke_dialog_br,.cke_skin_v1 .cke_dialog_bc{background-image:url(images/sprites.png);background-repeat:no-repeat;position:absolute;_background-image:url(images/sprites_ie6.png);_z-index:-1;}.cke_skin_v1 .cke_dialog_tl{background-position:-16px -16px;height:16px;width:16px;top:0;left:0;} .cke_skin_v1 .cke_rtl .cke_dialog_tl{background-position:-16px -397px;}.cke_skin_v1 .cke_dialog_tr{background-position:-16px -76px;height:16px;width:16px;top:0;right:0;}.cke_skin_v1 .cke_rtl .cke_dialog_tr{background-position:-16px -457px;}.cke_skin_v1 .cke_dialog_tc{background-position:0 -136px;background-repeat:repeat-x;height:16px;top:0;left:16px;right:16px;}.cke_skin_v1 .cke_dialog_bl{background-position:-16px -196px;height:51px;width:30px;bottom:0;left:0;}.cke_skin_v1 .cke_rtl .cke_dialog_bl{background-position:-16px -517px;}.cke_skin_v1 .cke_dialog_br{background-position:-16px -263px;height:51px;width:30px;bottom:0;right:0;}.cke_skin_v1 .cke_rtl .cke_dialog_br{background-position:-16px -584px;}.cke_skin_v1 .cke_dialog_bc{background-position:0 -330px;background-repeat:repeat-x;height:51px;bottom:0;left:30px;right:30px;}.cke_skin_v1 .cke_dialog_ml,.cke_skin_v1 .cke_dialog_mr{background-image:url(images/dialog_sides.png);background-repeat:repeat-y;position:absolute;width:16px;top:16px;bottom:51px;_background-image:url(images/dialog_sides.gif);_top:auto;}.cke_skin_v1 .cke_rtl .cke_dialog_ml,.cke_skin_v1 .cke_rtl .cke_dialog_mr{background-image:url(images/dialog_sides_rtl.png);_background-image:url(images/dialog_sides.gif);}.cke_skin_v1 .cke_dialog_ml{background-position:0 0;left:0;}.cke_skin_v1 .cke_dialog_mr{background-position:-16px 0;right:0;}.cke_skin_v1 .cke_browser_iequirks .cke_dialog_ml,.cke_skin_v1 .cke_browser_iequirks .cke_dialog_mr{margin-top:3px;}.cke_skin_v1 .cke_dialog_title{font-weight:bold;font-size:14pt;color:#737357;background-color:#e3e3c7;padding:3px 10px 26px 10px;cursor:move;position:relative;}.cke_skin_v1 .cke_dialog_contents{background-color:#f1f1e3;border:#d5d59d 1px solid;overflow:auto;padding:5px 10px;}.cke_skin_v1 .cke_dialog_footer{background-color:#e3e3c7;text-align:right;}.cke_skin_v1 .cke_rtl .cke_dialog_footer{text-align:left;}.cke_skin_v1 .cke_dialog_page_contents{position:relative;}.cke_skin_v1 .cke_dialog_footer .cke_resizer{margin-top:21px;}.cke_skin_v1 .cke_dialog_tabs{height:23px;background-color:#e3e3c7;display:inline-block;margin-left:10px;margin-right:10px;margin-top:-23px;position:absolute;z-index:2;}.cke_skin_v1 .cke_rtl .cke_dialog_tabs{right:10px;}.cke_skin_v1 a.cke_dialog_tab,.cke_skin_v1 a:link.cke_dialog_tab,.cke_skin_v1 a:active.cke_dialog_tab,.cke_skin_v1 a:hover.cke_dialog_tab,.cke_skin_v1 a:visited.cke_dialog_tab{color:#737357;border-left:1px solid #d5d59d;border-right:1px solid #d5d59d;border-top:1px solid #d5d59d;height:14px;padding:4px 5px;display:inline-block;cursor:pointer;}.cke_skin_v1 .cke_browser_gecko18 a.cke_dialog_tab,.cke_skin_v1 .cke_browser_gecko18 a:link.cke_dialog_tab,.cke_skin_v1 .cke_browser_gecko18 a:active.cke_dialog_tab,.cke_skin_v1 .cke_browser_gecko18 a:hover.cke_dialog_tab,.cke_skin_v1 .cke_browser_gecko18 a:visited.cke_dialog_tab{display:inline;position:relative;top:6px;}.cke_skin_v1 a:hover.cke_dialog_tab{background-color:#f1f1e3;}.cke_skin_v1 a.cke_dialog_tab_selected,.cke_skin_v1 a:link.cke_dialog_tab_selected,.cke_skin_v1 a:active.cke_dialog_tab_selected,.cke_skin_v1 a:hover.cke_dialog_tab_selected,.cke_skin_v1 a:visited.cke_dialog_tab_selected{border-bottom:1px solid #f1f1e3;background-color:#f1f1e3;font-weight:bold;cursor:default;}.cke_skin_v1 .cke_single_page .cke_dialog_tabs{display:none;}.cke_skin_v1 .cke_single_page .cke_dialog_title{padding-bottom:3px;}.cke_skin_v1 .cke_dialog_ui_vbox table,.cke_skin_v1 .cke_dialog_ui_hbox table{margin:auto;}.cke_skin_v1 .cke_dialog_ui_vbox_child{padding:5px 0;}.cke_skin_v1 input.cke_dialog_ui_input_text,.cke_skin_v1 input.cke_dialog_ui_input_password{background-color:white;border:none;padding:0;width:100%;height:14px;}.cke_skin_v1 div.cke_dialog_ui_input_text,.cke_skin_v1 div.cke_dialog_ui_input_password{background-color:white;border:1px solid #a0a0a0;padding:1px 0;}.cke_skin_v1 textarea.cke_dialog_ui_input_textarea{background-color:white;border:none;padding:0;width:100%;_width:99%;overflow:auto;resize:none;}.cke_skin_v1 div.cke_dialog_ui_input_textarea{background-color:white;border:1px solid #a0a0a0;padding:1px 0;} .cke_skin_v1 div.cke_disabled .cke_dialog_ui_labeled_content *{background-color:#a0a0a0;cursor:default;}.cke_skin_v1 .cke_dialog_ui_hbox{width:100%;}.cke_skin_v1 .cke_dialog_ui_hbox_first,.cke_skin_v1 .cke_dialog_ui_hbox_child,.cke_skin_v1 .cke_dialog_ui_hbox_last{vertical-align:top;}.cke_skin_v1 .cke_ltr .cke_dialog_ui_hbox_first,.cke_skin_v1 .cke_ltr .cke_dialog_ui_hbox_child{padding-right:10px;}.cke_skin_v1 .cke_rtl .cke_dialog_ui_hbox_first,.cke_skin_v1 .cke_rtl .cke_dialog_ui_hbox_child{padding-left:10px;}.cke_skin_v1 a.cke_dialog_ui_button{border-collapse:separate;cursor:default;}.cke_skin_v1 span.cke_dialog_ui_button{border:#737357 1px solid;padding:2px 10px;text-align:center;color:#3b3b1f;background-color:#c7c78f;display:inline-block;cursor:default;}.cke_skin_v1 .cke_browser_gecko18 .cke_dialog_footer_buttons span.cke_dialog_ui_button{display:block;}.cke_skin_v1 a.cke_dialog_ui_button span.cke_disabled{border:#898980 1px solid;color:#5e5e55;background-color:#c5c5b3;}.cke_skin_v1 a:focus span.cke_dialog_ui_button,.cke_skin_v1 a:active span.cke_dialog_ui_button{background-color:#e3e3c7;}.cke_skin_v1 .cke_dialog_footer_buttons{display:inline-table;margin-right:12px;margin-left:12px;width:auto;position:relative;}.cke_skin_v1 .cke_browser_gecko18 .cke_dialog_footer_buttons{display:inline;}.cke_skin_v1 .cke_dialog_footer_buttons span.cke_dialog_ui_button{width:60px;margin:7px 0;}.cke_skin_v1 strong{font-weight:bold;}.cke_skin_v1 .cke_dialog_close_button{background-image:url(images/sprites.png);background-repeat:no-repeat;background-position:-16px -651px;position:absolute;cursor:pointer;text-align:center;height:20px;width:20px;top:5px;_background-image:url(images/sprites_ie6.png);}.cke_skin_v1 .cke_dialog_close_button span{display:none;}.cke_skin_v1 .cke_dialog_close_button:hover{background-position:-16px -687px;}.cke_skin_v1 .cke_ltr .cke_dialog_close_button{right:10px;_right:22px;}.cke_skin_v1 .cke_rtl .cke_dialog_close_button{left:10px;_left:16px;_top:7px;}.cke_skin_v1 .cke_browser_ie6.cke_rtl .cke_dialog_close_button{position:relative;float:left;margin-top:-55px;margin-left:-7px;}.cke_skin_v1 .cke_browser_iequirks.cke_rtl.cke_single_page .cke_dialog_close_button{margin-top:-32px;}.cke_skin_v1 .cke_browser_iequirks.cke_ltr .cke_dialog_close_button{margin-top:0;}.cke_skin_v1 .cke_dialog_ui_input_select{border:1px solid #a0a0a0;background-color:white;}.cke_skin_v1 iframe.cke_dialog_ui_input_file{width:100%;height:25px;}.cke_skin_v1 .cke_dialog .cke_dark_background{background-color:#eaead1;}.cke_skin_v1 .cke_dialog .cke_hand{cursor:pointer;}.cke_skin_v1 .cke_dialog .cke_centered{text-align:center;}.cke_skin_v1 .cke_dialog a.cke_btn_reset{float:right;background-position:0 -32px;background-image:url(images/mini.gif);width:16px;height:16px;background-repeat:no-repeat;border:1px none;font-size:1px;}.cke_skin_v1 .cke_rtl .cke_dialog a.cke_btn_reset{float:left;}.cke_skin_v1 .cke_dialog a.cke_btn_locked,.cke_skin_v1 .cke_dialog a.cke_btn_unlocked{float:left;background-position:0 0;background-image:url(images/mini.gif);width:16px;height:16px;background-repeat:no-repeat;border:none 1px;font-size:1px;}.cke_skin_v1 .cke_rtl .cke_dialog a.cke_btn_locked,.cke_skin_v1 .cke_rtl .cke_dialog a.cke_btn_unlocked{float:right;}.cke_skin_v1 .cke_dialog a.cke_btn_unlocked{background-position:0 -16px;background-image:url(images/mini.gif);}.cke_skin_v1 .cke_dialog .cke_btn_over{border:outset 1px;cursor:pointer;cursor:hand;}.cke_skin_v1 .cke_dialog #ImagePreviewBox{white-space:normal;border:2px ridge black;overflow:scroll;height:160px;width:230px;padding:2px;background-color:white;}.cke_skin_v1 .cke_dialog #ImagePreviewLoader{position:absolute;white-space:normal;overflow:hidden;height:160px;width:230px;margin:2px;padding:2px;opacity:.9;filter:alpha(opacity=90);background-color:#e4e4e4;}.cke_skin_v1 .cke_dialog #FlashPreviewBox{white-space:normal;border:2px ridge black;overflow:auto;height:160px;width:390px;padding:2px;background-color:white;}.cke_skin_v1 .cke_dialog .cke_dark_background{text-align:center;background-color:#eaead1;font-size:14px;} .cke_skin_v1 .cke_dialog .cke_light_background{text-align:center;background-color:#ffffbe;}.cke_skin_v1 .cke_dialog .cke_hand{cursor:pointer;cursor:hand;}.cke_skin_v1 .cke_disabled,.cke_skin_v1 .cke_disabled label{color:#a0a0a0;}.cke_skin_v1 .cke_hc .cke_dialog_title,.cke_skin_v1 .cke_hc .cke_dialog_tabs,.cke_skin_v1 .cke_hc .cke_dialog_contents,.cke_skin_v1 .cke_hc .cke_dialog_footer{border-left:1px solid;border-right:1px solid;}.cke_skin_v1 .cke_hc .cke_dialog_title{border-top:1px solid;}.cke_skin_v1 .cke_hc .cke_dialog_footer{border-bottom:1px solid;}.cke_skin_v1 .cke_hc .cke_dialog_close_button span{display:inline;cursor:pointer;cursor:hand;font-weight:bold;position:relative;top:3px;}.cke_skin_v1 .cke_hc a.cke_btn_locked,.cke_skin_v1 .cke_hc a.cke_btn_unlocked,.cke_skin_v1 .cke_hc a.cke_btn_reset{border-style:solid;}.cke_skin_v1 a.cke_smile img{border:2px solid #eaead1;}.cke_skin_v1 a.cke_smile:focus img,.cke_skin_v1 a.cke_smile:active img,.cke_skin_v1 a.cke_smile:hover img{border-color:#C7C78F;}.ckfinder_loader_32{background:url("images/loaders/32x32.gif") 50% 50% no-repeat;}.cke_skin_v1 .cke_dialog_file_exist_options table{margin-bottom:10px;}.cke_skin_v1 .cke_dialog_remember_decision td{padding:10px;}.cke_skin_v1 .cke_dialog_error_msg strong{color:red;border:1px solid #FFF;padding:10px;margin-bottom:20px;display:block;}.cke_skin_v1 .cke_files_list{padding:10px 10% 0;line-height:1.2em;}.cke_skin_v1 .cke_files_list_many{height:5em;overflow:auto;}.cke_skin_v1 .cke_dialog_file_exist_options .cke_dialog_ui_labeled_label{margin-bottom:10px;}.cke_skin_v1 .cke_resizer{width:12px;height:12px;margin-top:16px;display:block;float:right;background-image:url(images/sprites.png);_background-image:url(images/sprites_ie6.png);background-position:0 -801px;background-repeat:no-repeat;cursor:se-resize;}.cke_skin_v1 .cke_browser_air .cke_resizer,.cke_skin_v1 .cke_browser_air .cke_rtl .cke_resizer{cursor:move;}.cke_skin_v1 .cke_rtl .cke_resizer{cursor:sw-resize;background-position:0 -828px;float:left;}.cke_skin_v1 .cke_resizer_horizontal,.cke_skin_v1 .cke_rtl .cke_resizer_horizontal{cursor:e-resize;}.cke_skin_v1 .cke_resizer_vertical,.cke_skin_v1 .cke_rtl .cke_resizer_vertical{cursor:n-resize;}.cke_skin_v1 .cke_maximized .cke_resizer{display:none;}body{font-size:8pt;}.no_list,.no_list li{list-style-type:none;margin:0;}.view h2{padding:.3em .5em;font-size:2em;_zoom:1;}.dragged_source{filter:alpha(opacity=50);opacity:.50;}#dragged_container{filter:alpha(opacity=75);opacity:.75;z-index:999;}body.dragging a,body.dragging a:hover,body.dragging a:active,body.dragging a:visited{color:inherit!important;text-decoration:none;cursor:default!important;}body.dragging .drop_target,body.dragging .drop_target a{cursor:pointer!important;}body.dragging .cke_skin_kama .cke_button a.cke_off:hover,body.dragging .cke_skin_kama .cke_button a:hover,body.dragging .cke_skin_kama .cke_button a:active{background-color:inherit!important;filter:alpha(opacity=70);opacity:.70;}body.during_sidebar_resize *{cursor:e-resize!important;}body.during_sidebar_resize .browser_webkit *{-webkit-user-select:none;}#sidebar_wrapper,#sidebar_container{_position:relative;}#sidebar_container{cursor:e-resize;}#sidebar_wrapper{cursor:default;}#folders_view{overflow:auto;overflow-x:hidden;position:relative;}#folders_view .folder_tree_wrapper{position:relative;z-index:1;}#folders_view .folder_tree{padding-bottom:5px;position:relative;z-index:2;}#folders_view .folder_tree ul{margin:0;padding-left:15px;}#folders_view .folder_tree li{white-space:nowrap;}#folders_view .folder_tree li.drop_target ul a{color:inherit;}#folders_view .folder_tree li.loading{padding-left:23px;font-style:italic;}#folders_view .folder_tree li.openable ul{display:none;}#folders_view .folder_tree li a{padding-left:23px;padding-bottom:3px;}#folders_view .folder_tree li .expander{float:left;_zoom:1;_float:none;height:16px;width:16px;background:0 2px no-repeat;}#folders_view .folder_tree li.nochildren .expander{background-image:none;}#folders_view .folder_tree li.nochildren ul{display:none;}#folders_view .folder_tree_wrapper .selection{position:absolute;left:0;width:100%;display:none;margin-top:-2px;padding-top:2px;} #folders_view .folder_tree li.drop_target a{font-weight:bold!important;text-decoration:none!important;}#folders_view .folder_tree li.drop_target ul a{font-weight:inherit!important;cursor:default!important;}#folders_view .folder_tree a.processing{filter:alpha(opacity=50);opacity:.50;}#folders_view .folder_tree .dropdown{padding-left:5px;padding-right:5px;display:none;}#folders_view .selected ul .dropdown{display:none;}#folders_view .selected .dropdown{display:inline;}#sidebar_container .tool_panel ul li img{vertical-align:middle;margin-right:.3em;}#sidebar_container .tool_panel ul{padding-left:.5em;padding-right:.5em;}#sidebar_container .tool_panel p{margin:0 1em .5em 1em;}#sidebar_container .tool,#sidebar_container .tool *{overflow:auto;}#toolbar_view{float:left;width:100%;border-bottom:1px solid;}#toolbar_view .cke_button .cke_label{display:inline;}#toolbar_view .cke_toolgroup{margin-bottom:0;}#panel_view{clear:left;position:relative;}#panel_view .panel_widget form{text-align:center;}#panel_view .panel_widget h2{text-align:left;}#panel_view .panel_widget table{width:auto;margin:0 auto 1em;text-align:left;}#panel_view .panel_widget dl{padding:5px;margin:0;white-space:nowrap;}#panel_view .panel_widget dd{margin:0;}#panel_view .panel_widget dd input{vertical-align:middle;}#panel_view .panel_widget .buttons{width:100%;text-align:right;}#panel_view .panel_widget .buttons input{margin:.5em;}#panel_view .panel_widget{border:1px solid;-moz-border-radius:5px;-webkit-border-radius:5px;}#upload_form .progress_bar{display:none;}#upload_form.progress_visible .progress_bar{display:block;}#upload_form .progress_bar_container div{height:1em;background:black;width:0;}#upload_form.progress_visible .progress_bar span{padding:0 1em;}#upload_form.progress_visible .progress_bar .count{font-weight:bold;}#files_view{clear:left;height:auto;overflow:auto;_width:99.9%;overflow-x:hidden;border:1px solid transparent;}#files_view .message_content{display:none;}#files_view.files_message .message_content{display:block;}#files_view .message_content{float:left;margin:1em;padding:1em;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;}#files_view .files_thumbnails{height:auto;clear:left;}#files_view.files_thumbnails table.files_details{display:none;}#files_view.files_details .files_thumbnails{display:none;}#files_view .files_thumbnails .file_entry,#dragged_container.file_entry{float:left;width:110px;border:1px solid;margin:5px;padding:5px;overflow:hidden;text-align:center;}#files_view .files_thumbnails .file_entry h5,#dragged_container.file_entry h5{display:block;font-weight:normal;overflow:hidden;white-space:nowrap;}#files_view .files_thumbnails .file_entry .image div,#dragged_container.file_entry .image div,#files_view .files_thumbnails .processing .image{margin:auto;overflow:hidden;height:100px;width:100px;background:50% 50% no-repeat;}#files_view .files_thumbnails .processing .image div{display:none;}#files_view .files_thumbnails .file_entry .details span,#dragged_container.file_entry .details span{display:block;}#files_view .files_thumbnails .extra,#dragged_container.file_entry .extra{height:1.3em;overflow:hidden;}.files_thumbnails .dropdown{position:absolute;top:0;left:0;padding:2px 20px 20px 3px;}.files_details .dropdown{padding:.3em 5px;}#dragged_container .dropdown{display:none;}#files_view .files_thumbnails .file_entry{position:relative;}.browser_ie6 .files_thumbnails .dropdown,.browser_ie7 .files_thumbnails .dropdown{position:static;display:block;width:100%;padding:0;text-align:left;cursor:hand;}.browser_ie6 #files_view .files_thumbnails .file_entry,.browser_ie7 #files_view .files_thumbnails .file_entry{position:static;}#files_view .files_details{width:100%;clear:left;}#files_view .files_details thead td{text-align:center;font-weight:bold;}#files_view .files_details td.image img{vertical-align:middle;}#files_view .files_details td.name{width:100%;}#files_view .files_details td{vertical-align:middle;padding:.3em .5em;white-space:nowrap;border:1px solid;}#files_view .files_details td.extra{text-align:right;padding-right:2em;}#files_view .files_details td.last{padding-right:1em;border-right:0;} #status_view p{padding:5px;margin:0;vertical-align:middle;}#sidebar_container{border-right:5px solid;}.cke_skin_v1 .cke_browser_ie .cke_toolbar_start{vertical-align:top;}#sidebar_container .view{border-bottom:1px solid transparent;}#upload_form p{margin:1em 0;}#ckfinder_view{color:black;background:#F1F1E3;}#files_view .files_thumbnails .file_entry,#dragged_container.file_entry{background:white;border-color:#D3D3D3;}#files_view{_border-color:#F1F1E3;}.view h2{background:#E3E3C7;color:#737357;}#sidebar_container{border-color:#E3E3C7;}#panel_view .panel_widget .buttons{background-color:#E3E3C7;}#folders_view .folder_tree li a,#folders_view .folder_tree li a:hover,#folders_view .folder_tree li a:active,#folders_view .folder_tree li a:visited,#files_view .files_thumbnails a.file_entry,#files_view .files_thumbnails a.file_entry:hover,#files_view .files_thumbnails a.file_entry:active,#files_view .files_thumbnails a.file_entry:visited{color:black;text-decoration:none;}#folders_view .folder_tree li a:hover{color:blue;text-decoration:underline;}#status_view{background-color:#E3E3C7;}#toolbar_view{border-color:black;}#files_view .files_thumbnails .file_entry:hover{background-color:#FFFACD;border-color:#F93;}#files_view .files_thumbnails .file_entry.selected{background-color:#9CF;border-color:#00F;_background-color:#9CF!important;_border-color:#00F!important;}.dropdown{color:#666;background:none!important;text-decoration:none;}body.dragging #files_view .file_entry{background:white!important;border-color:#D3D3D3!important;}body.dragging #files_view .dragged_source{background-color:#9CF!important;border-color:#00F!important;}#files_view .files_details tbody tr:hover,#files_view .files_details tbody tr:hover td,#files_view .files_details tbody tr.hover td,#files_view .files_details tbody tr:hover td.name,#files_view .files_details tbody tr.hover td.name{background-color:#FFFACD;}#files_view .files_details tr.selected,#files_view .files_details tr.selected td{background-color:#9CF;}#folders_view .folder_tree_wrapper .selection{background-color:antiquewhite;}#files_view .files_details td.name{background-color:white;}#files_view .files_details td{border-color:#F1F1E3;}#files_view .message_content{background-color:#9CF;}.focus_inside{border-color:#5cacfd!important;}#panel_view .panel_widget{border-width:0;}#panel_view .focus_inside{border-width:0;}
shellshocked59/t1m_internal_collab
sites/all/modules/ckeditor/ckfinder/skins/v1/app.css
CSS
gpl-2.0
35,594
<?php /** * @version $Id: view.feed.php 11782 2009-04-24 17:25:58Z kdevine $ * @package Joomla * @subpackage Contact * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. * @license GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant to the * GNU General Public License, and as distributed it includes or is derivative * of works licensed under the GNU General Public License or other free or open * source software licenses. See COPYRIGHT.php for copyright notices and * details. */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die( 'Restricted access' ); jimport('joomla.application.component.view'); /** * @pacakge Joomla * @subpackage Contacts */ class ContactViewCategory extends JView { function display() { global $mainframe; $db =& JFactory::getDBO(); $document =& JFactory::getDocument(); $document->link = JRoute::_('index.php?option=com_contact&view=category&catid='.JRequest::getVar('catid',null, '', 'int')); $siteEmail = $mainframe->getCfg('mailfrom'); $fromName = $mainframe->getCfg('fromname'); $document->editor = $fromName; $document->editorEmail = $siteEmail; $limit = JRequest::getVar('limit', $mainframe->getCfg('feed_limit'), '', 'int'); $limitstart = JRequest::getVar('limitstart', 0, '', 'int'); $catid = JRequest::getVar('catid', 0, '', 'int'); $where = ' WHERE a.published = 1'; if ( $catid ) { $where .= ' AND a.catid = '. (int) $catid; } $query = 'SELECT' . ' a.name AS title,' . ' CONCAT( a.con_position, \' - \', a.misc ) AS description,' . ' "" AS date,' . ' c.title AS category,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as catslug' . ' FROM #__contact_details AS a' . ' LEFT JOIN #__categories AS c ON c.id = a.catid' . $where . ' ORDER BY a.catid, a.ordering' ; $db->setQuery( $query, 0, $limit ); $rows = $db->loadObjectList(); foreach ( $rows as $row ) { // strip html from feed item title $title = $this->escape( $row->title ); $title = html_entity_decode( $title ); // url link to article $link = JRoute::_('index.php?option=com_contact&view=contact&id='. $row->slug .'&catid='.$row->catslug ); // strip html from feed item description text $description = $row->description; $date = ( $row->date ? date( 'r', strtotime($row->date) ) : '' ); // load individual item creator class $item = new JFeedItem(); $item->title = $title; $item->link = $link; $item->description = $description; $item->date = $date; $item->category = $row->category; // loads item info into rss array $document->addItem( $item ); } } }
sowmynarayan/joomla-website
components/com_contact/views/category/view.feed.php
PHP
gpl-2.0
2,856
/* event calendar table styles */ .event-calendar table { border: 1px solid #242; border-collapse: collapse; border-spacing: 0; width: 98%; /* Setting at 100% causes problem in Internet Explorer. */ margin-bottom: 1em; } .event-calendar tr { padding: 0; margin: 0; background: white; } .event-calendar th { color: #000; background: #aac; text-align: center; padding: 1px 0.33em; border: 1px solid #242; } .event-calendar .month-view td, .event-calendar .week-view td { width: 14%; /* 14% is about 1/7 of total table width */ } .event-calendar td { border: 1px solid #bbb; color: #777; text-align: right; vertical-align: top; margin: 0; padding: 0; } .event-calendar th.heading { border-width: 1px 0px; } /* head navigation */ .event-calendar caption span { font-weight: bold; font-size: 1.5em; } .event-calendar span a { text-decoration: none; } .event-calendar span a:hover, .event-calendar span a:active, .event-calendar span a:focus { background-color: #363636; color: #fff; } .event-calendar .prev { text-align: left; border-width: 1px 0px 1px 1px; } .event-calendar .next { text-align: right; border-width: 1px 1px 1px 0px; } .event-calendar .stop { color: #ccc; } .event-calendar th a { font-weight: bold; color: #363636; } .event-calendar td a { color: #222244; font-weight: bold; text-decoration: none; } .event-calendar td a:hover { text-decoration: underline; } .event-calendar td.sat, .event-calendar td.sun { background: #fdd; } .event-calendar td.selected { background: #99f; } .event-calendar td.today { background: #f99; } .event-calendar td.year, .event-calendar td.month { text-align: center; border-width: 1px 0px; } /* days of the week header cells */ .event-calendar td.days { color: #cce; background: #224; text-align: center; border: 1px solid #242; border-width: 0 1px 1px 0; } /* floating day number div */ .event-calendar div.day { float: right; text-align: center; border: 1px solid gray; border-width: 0 0 1px 1px; padding: 0.125em 0.25em 0 0.25em; margin: 0; background: #f3f3f3; } /* event node times for the body */ .event-nodeapi div { color: #000; padding: 0.5em 1em 0 0; } .event-nodeapi div label { color: #999; } /* individual node container */ .event-calendar div.event { font-style: italic; background-color: #fff; border: solid 1px #555; text-align: left; margin: 0.25em 0 0.5em 0.25em; } .event-calendar div.title { padding-left: 3px; } .event-calendar div.title a { color: #000; } .event-calendar div.title a:hover { color: #c00; } .event-calendar .content { margin: 5px; padding: 3px; border-left: solid 2px #ddd; padding-left: 5px; } .event-calendar div.type { margin-left: 5px; font-size: 0.8em; } .event-calendar div.type a { color: #00c; } .event-calendar div.type a:hover { color: #c00; } .event-calendar div.links { padding-left: 3px; } .event-calendar div.links a { color: #00c; } .event-calendar div.links a:hover { color: #c00; } .event-calendar .start { font-style: normal; color: #555; margin: 2px 0 2px 0; padding-left: 3px; font-size: 0.8em; } .event-calendar .end { font-style: normal; color: #555; margin: 2px 0 2px 0; padding-left: 9px; font-size: 0.8em; } .event-calendar .ongoing { font-style: normal; color: #555; margin: 2px 0 2px 0; padding-left: 9px; font-size: 0.8em; } .event-calendar div.info { visibility: hidden; height: 0px; overflow:hidden; padding-left: 3px; } /* individual node view styles */ .event-calendar div.monthview .title { font-size: 0.8em; } .event-calendar div.dayview { width: auto; } .event-calendar div.tableview { width: auto; } .event-calendar div.tableview .links { } .event-calendar .event-empty { min-height: 6em; } /* hack to make Internet Explorer for Windows display calendar height correctly \*/ * html .event-calendar .event-empty { height: 6em; } /* end of hack */ .container-inline .day input { width: auto; display: inline; } /* multi-day event top stripes */ .event-calendar .event .stripe { height: 5px; } .event-calendar .event .stripe-1 { background-color: #FF6; height: 5px; width: 100%; } .event-calendar .event .stripe-2 { background-color: #F66; height: 5px; width: 100%; } .event-calendar .event .stripe-3 { background-color: #668CFF; height: 5px; width: 100%; } .event-calendar .event .stripe-4 { background-color: #FFB366; height: 5px; width: 100%; } .event-calendar .event .stripe-5 { background-color: #85FF66; height: 5px; width: 100%; } .event-calendar .event .stripe-6 { background-color: #A666FF; height: 5px; width: 100%; } .event-calendar .event .stripe-7 { background-color: #FFE066; height: 5px; width: 100%; } .event-calendar .event .stripe-8 { background-color: #66FFFF; height: 5px; width: 100%; } .event-calendar .event .stripe-9 { background-color: #FF66D9; height: 5px; width: 100%; } .event-calendar .event .stripe-10 { background-color: #DDD; height: 5px; width: 100%; } .event-calendar div.month-view table.event-block thead, .event-calendar div.month-view table.event-block tbody { font-size: .9em; } .event-calendar div.month-view table.event-block th { font-weight: normal; } #block-event-1 .item-list ul li a { margin-top: 8px; } span.event-timeleft { padding-bottom: 3px; text-align: right; width: auto; display: block; } span.event-nodetype { padding: 0px 0px 0px 5px; display: block; width: auto; text-align: right; float: right; } .ical-link { text-align: right; } .event div.form-item { white-space: normal; }
mikeusry/lwunravel
sites/all/modules/event/event.css
CSS
gpl-2.0
5,677
<div class="container" id="mainContent"> <div id="topOfPage"> </div> <h1> Student Details </h1> <br> <div id="statusMessagesToUser" style="display: none;"> </div> <div class="row"> <div class="col-xs-12"> <div class="row" id="studentProfile"> <div class="col-md-2 col-xs-3 block-center"> <img class="profile-pic pull-right" src="/images/profile_picture_default.png"> </div> <div class="col-md-10 col-sm-9 col-xs-8"> <table class="table table-striped"> <thead> <tr> <th colspan="2"> Profile </th> </tr> </thead> <tbody> <tr> <td class="text-bold"> Short Name (Gender) </td> <td> name"/&gt;&lt;script&gt;alert('hi!');&lt;/script&gt; ( <i> <span class="text-muted"> Not Specified </span> </i> ) </td> </tr> <tr> <td class="text-bold"> Personal Email </td> <td> weird&'@gmail.tmt </td> </tr> <tr> <td class="text-bold"> Institution </td> <td> school'/&gt;&lt;script&gt;alert('hi!');&lt;/script&gt; </td> </tr> <tr> <td class="text-bold"> Nationality </td> <td> American </td> </tr> </tbody> </table> </div> </div> </div> </div> <div class="well well-plain"> <div class="form form-horizontal" id="studentInfomationTable"> <div class="form-group"> <label class="col-sm-1 control-label"> Student Name: </label> <div class="col-sm-11" id="studentname"> <p class="form-control-static"> Stud1&lt;/option&gt;&lt;/td&gt;&lt;/div&gt;'" </p> </div> </div> <div class="form-group"> <label class="col-sm-1 control-label"> Section Name: </label> <div class="col-sm-11" id="sectionname"> <p class="form-control-static"> Section'&lt;/td&gt; </p> </div> </div> <div class="form-group"> <label class="col-sm-1 control-label"> Team Name: </label> <div class="col-sm-11" id="teamname"> <p class="form-control-static"> Team tags&"&lt;/option&gt;&lt;/td&gt; </p> </div> </div> <div class="form-group"> <label class="col-sm-1 control-label"> Official Email Address: </label> <div class="col-sm-11" id="studentemail"> <p class="form-control-static"> CCSDetailsUiT.stud@sanitization.tmt </p> </div> </div> <div class="form-group"> <label class="col-sm-1 control-label"> Comments: </label> <div class="col-sm-11" id="comments"> <p class="form-control-static"> &lt;/p&gt;&lt;/div&gt;'"&lt;script&gt; alert('hi!'); &lt;/script&gt; </p> </div> </div> </div> </div> <div aria-hidden="true" aria-labelledby="myModalLabel" class="modal fade" id="studentProfileMoreInfo" role="dialog"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <button aria-hidden="true" class="close" data-dismiss="modal" type="button"> × </button> <h4 class="modal-title"> Stud1&lt;/option&gt;&lt;/td&gt;&lt;/div&gt;'"'s Profile - More Info </h4> </div> <div class="modal-body"> <br> <p class="text-preserve-space height-fixed-md"> I am just a student :P&lt;script&gt; alert('hi!'); &lt;/script&gt; </p> </div> <div class="modal-footer"> <button class="btn btn-primary" data-dismiss="modal" type="button"> Close </button> </div> </div> </div> </div> <div class="row"> <div class="col-xs-12"> <div class="panel panel-default"> <div class="panel-body"> <span class="text-muted pull-right glyphicon glyphicon-resize-full cursor-pointer" data-target="#studentProfileMoreInfo" data-toggle="modal"> </span> <h5> More Info </h5> <p class="text-preserve-space height-fixed-md"> I am just a student :P&lt;script&gt; alert('hi!'); &lt;/script&gt; </p> </div> </div> </div> </div> </div>
LimeTheCoder/teammates
src/test/resources/pages/instructorCourseStudentDetailsRegisteredWithAttemptedScriptInjection.html
HTML
gpl-2.0
4,994
module RSpec module Mocks module AnyInstance # @private # The `AnyInstance::Recorder` is responsible for redefining the klass's # instance method in order to add any stubs/expectations the first time # the method is called. It's not capable of updating a stub on an instance # that's already been previously stubbed (either directly, or via # `any_instance`). # # This proxy sits in front of the recorder and delegates both to it # and to the `RSpec::Mocks::Proxy` for each already mocked or stubbed # instance of the class, in order to propogates changes to the instances. # # Note that unlike `RSpec::Mocks::Proxy`, this proxy class is stateless # and is not persisted in `RSpec::Mocks.space`. # # Proxying for the message expectation fluent interface (typically chained # off of the return value of one of these methods) is provided by the # `FluentInterfaceProxy` class below. class Proxy def initialize(recorder, target_proxies) @recorder = recorder @target_proxies = target_proxies end def klass @recorder.klass end def stub(method_name_or_method_map, &block) if Hash === method_name_or_method_map method_name_or_method_map.each do |method_name, return_value| stub(method_name).and_return(return_value) end else perform_proxying(__method__, [method_name_or_method_map], block) do |proxy| proxy.add_stub(method_name_or_method_map, &block) end end end def unstub(method_name) perform_proxying(__method__, [method_name], nil) do |proxy| proxy.remove_stub_if_present(method_name) end end def stub_chain(*chain, &block) perform_proxying(__method__, chain, block) do |proxy| Mocks::StubChain.stub_chain_on(proxy.object, *chain, &block) end end def expect_chain(*chain, &block) perform_proxying(__method__, chain, block) do |proxy| Mocks::ExpectChain.expect_chain_on(proxy.object, *chain, &block) end end def should_receive(method_name, &block) perform_proxying(__method__, [method_name], block) do |proxy| # Yeah, this is a bit odd...but if we used `add_message_expectation` # then it would act like `expect_every_instance_of(klass).to receive`. # The any_instance recorder takes care of validating that an instance # received the message. proxy.add_stub(method_name, &block) end end def should_not_receive(method_name, &block) perform_proxying(__method__, [method_name], block) do |proxy| proxy.add_message_expectation(method_name, &block).never end end private def perform_proxying(method_name, args, block, &target_proxy_block) recorder_value = @recorder.__send__(method_name, *args, &block) proxy_values = @target_proxies.map(&target_proxy_block) FluentInterfaceProxy.new([recorder_value] + proxy_values) end end # @private # Delegates messages to each of the given targets in order to # provide the fluent interface that is available off of message # expectations when dealing with `any_instance`. # # `targets` will typically contain 1 of the `AnyInstance::Recorder` # return values and N `MessageExpectation` instances (one per instance # of the `any_instance` klass). class FluentInterfaceProxy def initialize(targets) @targets = targets end if RUBY_VERSION.to_f > 1.8 def respond_to_missing?(method_name, include_private = false) super || @targets.first.respond_to?(method_name, include_private) end else def respond_to?(method_name, include_private = false) super || @targets.first.respond_to?(method_name, include_private) end end def method_missing(*args, &block) return_values = @targets.map { |t| t.__send__(*args, &block) } FluentInterfaceProxy.new(return_values) end end end end end
sildani/skypal
skypal-server/vendor/ruby/1.9.1/gems/rspec-mocks-3.0.4/lib/rspec/mocks/any_instance/proxy.rb
Ruby
gpl-2.0
4,379
/* Copyright_License { XCSoar Glide Computer - http://www.xcsoar.org/ Copyright (C) 2000-2016 The XCSoar Project A detailed list of copyright holders can be found in the file "AUTHORS". This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. } */ #include "Asset.hpp" #if defined(USE_CONSOLE) && !defined(KOBO) bool HasPointer() { return true; } #endif #ifdef USE_LIBINPUT bool HasTouchScreen() { return IsAndroid() || IsKobo() || IsIOS(); } bool HasKeyboard() { return !IsEmbedded(); } #endif
RBE-Avionik/xcsoar
test/src/FakeAsset.cpp
C++
gpl-2.0
1,160
/* Matsushita 10300 specific support for 32-bit ELF Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sysdep.h" #include "bfd.h" #include "libbfd.h" #include "elf-bfd.h" #include "elf/mn10300.h" #include "libiberty.h" /* The mn10300 linker needs to keep track of the number of relocs that it decides to copy in check_relocs for each symbol. This is so that it can discard PC relative relocs if it doesn't need them when linking with -Bsymbolic. We store the information in a field extending the regular ELF linker hash table. */ struct elf32_mn10300_link_hash_entry { /* The basic elf link hash table entry. */ struct elf_link_hash_entry root; /* For function symbols, the number of times this function is called directly (ie by name). */ unsigned int direct_calls; /* For function symbols, the size of this function's stack (if <= 255 bytes). We stuff this into "call" instructions to this target when it's valid and profitable to do so. This does not include stack allocated by movm! */ unsigned char stack_size; /* For function symbols, arguments (if any) for movm instruction in the prologue. We stuff this value into "call" instructions to the target when it's valid and profitable to do so. */ unsigned char movm_args; /* For function symbols, the amount of stack space that would be allocated by the movm instruction. This is redundant with movm_args, but we add it to the hash table to avoid computing it over and over. */ unsigned char movm_stack_size; /* When set, convert all "call" instructions to this target into "calls" instructions. */ #define MN10300_CONVERT_CALL_TO_CALLS 0x1 /* Used to mark functions which have had redundant parts of their prologue deleted. */ #define MN10300_DELETED_PROLOGUE_BYTES 0x2 unsigned char flags; /* Calculated value. */ bfd_vma value; #define GOT_UNKNOWN 0 #define GOT_NORMAL 1 #define GOT_TLS_GD 2 #define GOT_TLS_LD 3 #define GOT_TLS_IE 4 /* Used to distinguish GOT entries for TLS types from normal GOT entries. */ unsigned char tls_type; }; /* We derive a hash table from the main elf linker hash table so we can store state variables and a secondary hash table without resorting to global variables. */ struct elf32_mn10300_link_hash_table { /* The main hash table. */ struct elf_link_hash_table root; /* A hash table for static functions. We could derive a new hash table instead of using the full elf32_mn10300_link_hash_table if we wanted to save some memory. */ struct elf32_mn10300_link_hash_table *static_hash_table; /* Random linker state flags. */ #define MN10300_HASH_ENTRIES_INITIALIZED 0x1 char flags; struct { bfd_signed_vma refcount; bfd_vma offset; char got_allocated; char rel_emitted; } tls_ldm_got; }; #define elf_mn10300_hash_entry(ent) ((struct elf32_mn10300_link_hash_entry *)(ent)) struct elf_mn10300_obj_tdata { struct elf_obj_tdata root; /* tls_type for each local got entry. */ char * local_got_tls_type; }; #define elf_mn10300_tdata(abfd) \ ((struct elf_mn10300_obj_tdata *) (abfd)->tdata.any) #define elf_mn10300_local_got_tls_type(abfd) \ (elf_mn10300_tdata (abfd)->local_got_tls_type) #ifndef streq #define streq(a, b) (strcmp ((a),(b)) == 0) #endif /* For MN10300 linker hash table. */ /* Get the MN10300 ELF linker hash table from a link_info structure. */ #define elf32_mn10300_hash_table(p) \ (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ == MN10300_ELF_DATA ? ((struct elf32_mn10300_link_hash_table *) ((p)->hash)) : NULL) #define elf32_mn10300_link_hash_traverse(table, func, info) \ (elf_link_hash_traverse \ (&(table)->root, \ (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ (info))) static reloc_howto_type elf_mn10300_howto_table[] = { /* Dummy relocation. Does nothing. */ HOWTO (R_MN10300_NONE, 0, 3, 0, FALSE, 0, complain_overflow_dont, bfd_elf_generic_reloc, "R_MN10300_NONE", FALSE, 0, 0, FALSE), /* Standard 32 bit reloc. */ HOWTO (R_MN10300_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_MN10300_32", FALSE, 0xffffffff, 0xffffffff, FALSE), /* Standard 16 bit reloc. */ HOWTO (R_MN10300_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_MN10300_16", FALSE, 0xffff, 0xffff, FALSE), /* Standard 8 bit reloc. */ HOWTO (R_MN10300_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_MN10300_8", FALSE, 0xff, 0xff, FALSE), /* Standard 32bit pc-relative reloc. */ HOWTO (R_MN10300_PCREL32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_MN10300_PCREL32", FALSE, 0xffffffff, 0xffffffff, TRUE), /* Standard 16bit pc-relative reloc. */ HOWTO (R_MN10300_PCREL16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_MN10300_PCREL16", FALSE, 0xffff, 0xffff, TRUE), /* Standard 8 pc-relative reloc. */ HOWTO (R_MN10300_PCREL8, 0, 0, 8, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_MN10300_PCREL8", FALSE, 0xff, 0xff, TRUE), /* GNU extension to record C++ vtable hierarchy. */ HOWTO (R_MN10300_GNU_VTINHERIT, /* type */ 0, /* rightshift */ 0, /* size (0 = byte, 1 = short, 2 = long) */ 0, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ NULL, /* special_function */ "R_MN10300_GNU_VTINHERIT", /* name */ FALSE, /* partial_inplace */ 0, /* src_mask */ 0, /* dst_mask */ FALSE), /* pcrel_offset */ /* GNU extension to record C++ vtable member usage */ HOWTO (R_MN10300_GNU_VTENTRY, /* type */ 0, /* rightshift */ 0, /* size (0 = byte, 1 = short, 2 = long) */ 0, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ NULL, /* special_function */ "R_MN10300_GNU_VTENTRY", /* name */ FALSE, /* partial_inplace */ 0, /* src_mask */ 0, /* dst_mask */ FALSE), /* pcrel_offset */ /* Standard 24 bit reloc. */ HOWTO (R_MN10300_24, 0, 2, 24, FALSE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_MN10300_24", FALSE, 0xffffff, 0xffffff, FALSE), HOWTO (R_MN10300_GOTPC32, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ TRUE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_GOTPC32", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ TRUE), /* pcrel_offset */ HOWTO (R_MN10300_GOTPC16, /* type */ 0, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 16, /* bitsize */ TRUE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_GOTPC16", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ TRUE), /* pcrel_offset */ HOWTO (R_MN10300_GOTOFF32, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_GOTOFF32", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_GOTOFF24, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 24, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_GOTOFF24", /* name */ FALSE, /* partial_inplace */ 0xffffff, /* src_mask */ 0xffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_GOTOFF16, /* type */ 0, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 16, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_GOTOFF16", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_PLT32, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ TRUE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_PLT32", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ TRUE), /* pcrel_offset */ HOWTO (R_MN10300_PLT16, /* type */ 0, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 16, /* bitsize */ TRUE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_PLT16", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ TRUE), /* pcrel_offset */ HOWTO (R_MN10300_GOT32, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_GOT32", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_GOT24, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 24, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_GOT24", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_GOT16, /* type */ 0, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 16, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_GOT16", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_COPY, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_COPY", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_GLOB_DAT, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_GLOB_DAT", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_JMP_SLOT, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_JMP_SLOT", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_RELATIVE, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_RELATIVE", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_TLS_GD, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_TLS_GD", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_TLS_LD, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_TLS_LD", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_TLS_LDO, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_TLS_LDO", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_TLS_GOTIE, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_TLS_GOTIE", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_TLS_IE, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_TLS_IE", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_TLS_LE, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_TLS_LE", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_TLS_DTPMOD, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_TLS_DTPMOD", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_TLS_DTPOFF, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_TLS_DTPOFF", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_TLS_TPOFF, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* */ "R_MN10300_TLS_TPOFF", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_SYM_DIFF, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont,/* complain_on_overflow */ NULL, /* special handler. */ "R_MN10300_SYM_DIFF", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_MN10300_ALIGN, /* type */ 0, /* rightshift */ 0, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont,/* complain_on_overflow */ NULL, /* special handler. */ "R_MN10300_ALIGN", /* name */ FALSE, /* partial_inplace */ 0, /* src_mask */ 0, /* dst_mask */ FALSE) /* pcrel_offset */ }; struct mn10300_reloc_map { bfd_reloc_code_real_type bfd_reloc_val; unsigned char elf_reloc_val; }; static const struct mn10300_reloc_map mn10300_reloc_map[] = { { BFD_RELOC_NONE, R_MN10300_NONE, }, { BFD_RELOC_32, R_MN10300_32, }, { BFD_RELOC_16, R_MN10300_16, }, { BFD_RELOC_8, R_MN10300_8, }, { BFD_RELOC_32_PCREL, R_MN10300_PCREL32, }, { BFD_RELOC_16_PCREL, R_MN10300_PCREL16, }, { BFD_RELOC_8_PCREL, R_MN10300_PCREL8, }, { BFD_RELOC_24, R_MN10300_24, }, { BFD_RELOC_VTABLE_INHERIT, R_MN10300_GNU_VTINHERIT }, { BFD_RELOC_VTABLE_ENTRY, R_MN10300_GNU_VTENTRY }, { BFD_RELOC_32_GOT_PCREL, R_MN10300_GOTPC32 }, { BFD_RELOC_16_GOT_PCREL, R_MN10300_GOTPC16 }, { BFD_RELOC_32_GOTOFF, R_MN10300_GOTOFF32 }, { BFD_RELOC_MN10300_GOTOFF24, R_MN10300_GOTOFF24 }, { BFD_RELOC_16_GOTOFF, R_MN10300_GOTOFF16 }, { BFD_RELOC_32_PLT_PCREL, R_MN10300_PLT32 }, { BFD_RELOC_16_PLT_PCREL, R_MN10300_PLT16 }, { BFD_RELOC_MN10300_GOT32, R_MN10300_GOT32 }, { BFD_RELOC_MN10300_GOT24, R_MN10300_GOT24 }, { BFD_RELOC_MN10300_GOT16, R_MN10300_GOT16 }, { BFD_RELOC_MN10300_COPY, R_MN10300_COPY }, { BFD_RELOC_MN10300_GLOB_DAT, R_MN10300_GLOB_DAT }, { BFD_RELOC_MN10300_JMP_SLOT, R_MN10300_JMP_SLOT }, { BFD_RELOC_MN10300_RELATIVE, R_MN10300_RELATIVE }, { BFD_RELOC_MN10300_TLS_GD, R_MN10300_TLS_GD }, { BFD_RELOC_MN10300_TLS_LD, R_MN10300_TLS_LD }, { BFD_RELOC_MN10300_TLS_LDO, R_MN10300_TLS_LDO }, { BFD_RELOC_MN10300_TLS_GOTIE, R_MN10300_TLS_GOTIE }, { BFD_RELOC_MN10300_TLS_IE, R_MN10300_TLS_IE }, { BFD_RELOC_MN10300_TLS_LE, R_MN10300_TLS_LE }, { BFD_RELOC_MN10300_TLS_DTPMOD, R_MN10300_TLS_DTPMOD }, { BFD_RELOC_MN10300_TLS_DTPOFF, R_MN10300_TLS_DTPOFF }, { BFD_RELOC_MN10300_TLS_TPOFF, R_MN10300_TLS_TPOFF }, { BFD_RELOC_MN10300_SYM_DIFF, R_MN10300_SYM_DIFF }, { BFD_RELOC_MN10300_ALIGN, R_MN10300_ALIGN } }; /* Create the GOT section. */ static bfd_boolean _bfd_mn10300_elf_create_got_section (bfd * abfd, struct bfd_link_info * info) { flagword flags; flagword pltflags; asection * s; struct elf_link_hash_entry * h; const struct elf_backend_data * bed = get_elf_backend_data (abfd); struct elf_link_hash_table *htab; int ptralign; /* This function may be called more than once. */ htab = elf_hash_table (info); if (htab->sgot != NULL) return TRUE; switch (bed->s->arch_size) { case 32: ptralign = 2; break; case 64: ptralign = 3; break; default: bfd_set_error (bfd_error_bad_value); return FALSE; } flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); pltflags = flags; pltflags |= SEC_CODE; if (bed->plt_not_loaded) pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS); if (bed->plt_readonly) pltflags |= SEC_READONLY; s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags); htab->splt = s; if (s == NULL || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) return FALSE; /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. */ if (bed->want_plt_sym) { h = _bfd_elf_define_linkage_sym (abfd, info, s, "_PROCEDURE_LINKAGE_TABLE_"); htab->hplt = h; if (h == NULL) return FALSE; } s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); htab->sgot = s; if (s == NULL || ! bfd_set_section_alignment (abfd, s, ptralign)) return FALSE; if (bed->want_got_plt) { s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags); htab->sgotplt = s; if (s == NULL || ! bfd_set_section_alignment (abfd, s, ptralign)) return FALSE; } /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got (or .got.plt) section. We don't do this in the linker script because we don't want to define the symbol if we are not creating a global offset table. */ h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_"); htab->hgot = h; if (h == NULL) return FALSE; /* The first bit of the global offset table is the header. */ s->size += bed->got_header_size; return TRUE; } static reloc_howto_type * bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code) { unsigned int i; for (i = ARRAY_SIZE (mn10300_reloc_map); i--;) if (mn10300_reloc_map[i].bfd_reloc_val == code) return &elf_mn10300_howto_table[mn10300_reloc_map[i].elf_reloc_val]; return NULL; } static reloc_howto_type * bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) { unsigned int i; for (i = ARRAY_SIZE (elf_mn10300_howto_table); i--;) if (elf_mn10300_howto_table[i].name != NULL && strcasecmp (elf_mn10300_howto_table[i].name, r_name) == 0) return elf_mn10300_howto_table + i; return NULL; } /* Set the howto pointer for an MN10300 ELF reloc. */ static void mn10300_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type; r_type = ELF32_R_TYPE (dst->r_info); if (r_type >= R_MN10300_MAX) { (*_bfd_error_handler) (_("%B: unrecognised MN10300 reloc number: %d"), abfd, r_type); bfd_set_error (bfd_error_bad_value); r_type = R_MN10300_NONE; } cache_ptr->howto = elf_mn10300_howto_table + r_type; } static int elf_mn10300_tls_transition (struct bfd_link_info * info, int r_type, struct elf_link_hash_entry * h, asection * sec, bfd_boolean counting) { bfd_boolean is_local; if (r_type == R_MN10300_TLS_GD && h != NULL && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_IE) return R_MN10300_TLS_GOTIE; if (bfd_link_pic (info)) return r_type; if (! (sec->flags & SEC_CODE)) return r_type; if (! counting && h != NULL && ! elf_hash_table (info)->dynamic_sections_created) is_local = TRUE; else is_local = SYMBOL_CALLS_LOCAL (info, h); /* For the main program, these are the transitions we do. */ switch (r_type) { case R_MN10300_TLS_GD: return is_local ? R_MN10300_TLS_LE : R_MN10300_TLS_GOTIE; case R_MN10300_TLS_LD: return R_MN10300_NONE; case R_MN10300_TLS_LDO: return R_MN10300_TLS_LE; case R_MN10300_TLS_IE: case R_MN10300_TLS_GOTIE: return is_local ? R_MN10300_TLS_LE : r_type; } return r_type; } /* Return the relocation value for @tpoff relocation if STT_TLS virtual address is ADDRESS. */ static bfd_vma dtpoff (struct bfd_link_info * info, bfd_vma address) { struct elf_link_hash_table *htab = elf_hash_table (info); /* If tls_sec is NULL, we should have signalled an error already. */ if (htab->tls_sec == NULL) return 0; return address - htab->tls_sec->vma; } /* Return the relocation value for @tpoff relocation if STT_TLS virtual address is ADDRESS. */ static bfd_vma tpoff (struct bfd_link_info * info, bfd_vma address) { struct elf_link_hash_table *htab = elf_hash_table (info); /* If tls_sec is NULL, we should have signalled an error already. */ if (htab->tls_sec == NULL) return 0; return address - (htab->tls_size + htab->tls_sec->vma); } /* Returns nonzero if there's a R_MN10300_PLT32 reloc that we now need to skip, after this one. The actual value is the offset between this reloc and the PLT reloc. */ static int mn10300_do_tls_transition (bfd * input_bfd, unsigned int r_type, unsigned int tls_r_type, bfd_byte * contents, bfd_vma offset) { bfd_byte *op = contents + offset; int gotreg = 0; #define TLS_PAIR(r1,r2) ((r1) * R_MN10300_MAX + (r2)) /* This is common to all GD/LD transitions, so break it out. */ if (r_type == R_MN10300_TLS_GD || r_type == R_MN10300_TLS_LD) { op -= 2; /* mov imm,d0. */ BFD_ASSERT (bfd_get_8 (input_bfd, op) == 0xFC); BFD_ASSERT (bfd_get_8 (input_bfd, op + 1) == 0xCC); /* add aN,d0. */ BFD_ASSERT (bfd_get_8 (input_bfd, op + 6) == 0xF1); gotreg = (bfd_get_8 (input_bfd, op + 7) & 0x0c) >> 2; /* Call. */ BFD_ASSERT (bfd_get_8 (input_bfd, op + 8) == 0xDD); } switch (TLS_PAIR (r_type, tls_r_type)) { case TLS_PAIR (R_MN10300_TLS_GD, R_MN10300_TLS_GOTIE): { /* Keep track of which register we put GOTptr in. */ /* mov (_x@indntpoff,a2),a0. */ memcpy (op, "\xFC\x20\x00\x00\x00\x00", 6); op[1] |= gotreg; /* add e2,a0. */ memcpy (op+6, "\xF9\x78\x28", 3); /* or 0x00000000, d0 - six byte nop. */ memcpy (op+9, "\xFC\xE4\x00\x00\x00\x00", 6); } return 7; case TLS_PAIR (R_MN10300_TLS_GD, R_MN10300_TLS_LE): { /* Register is *always* a0. */ /* mov _x@tpoff,a0. */ memcpy (op, "\xFC\xDC\x00\x00\x00\x00", 6); /* add e2,a0. */ memcpy (op+6, "\xF9\x78\x28", 3); /* or 0x00000000, d0 - six byte nop. */ memcpy (op+9, "\xFC\xE4\x00\x00\x00\x00", 6); } return 7; case TLS_PAIR (R_MN10300_TLS_LD, R_MN10300_NONE): { /* Register is *always* a0. */ /* mov e2,a0. */ memcpy (op, "\xF5\x88", 2); /* or 0x00000000, d0 - six byte nop. */ memcpy (op+2, "\xFC\xE4\x00\x00\x00\x00", 6); /* or 0x00000000, e2 - seven byte nop. */ memcpy (op+8, "\xFE\x19\x22\x00\x00\x00\x00", 7); } return 7; case TLS_PAIR (R_MN10300_TLS_LDO, R_MN10300_TLS_LE): /* No changes needed, just the reloc change. */ return 0; /* These are a little tricky, because we have to detect which opcode is being used (they're different sizes, with the reloc at different offsets within the opcode) and convert each accordingly, copying the operands as needed. The conversions we do are as follows (IE,GOTIE,LE): 1111 1100 1010 01Dn [-- abs32 --] MOV (x@indntpoff),Dn 1111 1100 0000 DnAm [-- abs32 --] MOV (x@gotntpoff,Am),Dn 1111 1100 1100 11Dn [-- abs32 --] MOV x@tpoff,Dn 1111 1100 1010 00An [-- abs32 --] MOV (x@indntpoff),An 1111 1100 0010 AnAm [-- abs32 --] MOV (x@gotntpoff,Am),An 1111 1100 1101 11An [-- abs32 --] MOV x@tpoff,An 1111 1110 0000 1110 Rnnn Xxxx [-- abs32 --] MOV (x@indntpoff),Rn 1111 1110 0000 1010 Rnnn Rmmm [-- abs32 --] MOV (x@indntpoff,Rm),Rn 1111 1110 0000 1000 Rnnn Xxxx [-- abs32 --] MOV x@tpoff,Rn Since the GOT pointer is always $a2, we assume the last normally won't happen, but let's be paranoid and plan for the day that GCC optimizes it somewhow. */ case TLS_PAIR (R_MN10300_TLS_IE, R_MN10300_TLS_LE): if (op[-2] == 0xFC) { op -= 2; if ((op[1] & 0xFC) == 0xA4) /* Dn */ { op[1] &= 0x03; /* Leaves Dn. */ op[1] |= 0xCC; } else /* An */ { op[1] &= 0x03; /* Leaves An. */ op[1] |= 0xDC; } } else if (op[-3] == 0xFE) op[-2] = 0x08; else abort (); break; case TLS_PAIR (R_MN10300_TLS_GOTIE, R_MN10300_TLS_LE): if (op[-2] == 0xFC) { op -= 2; if ((op[1] & 0xF0) == 0x00) /* Dn */ { op[1] &= 0x0C; /* Leaves Dn. */ op[1] >>= 2; op[1] |= 0xCC; } else /* An */ { op[1] &= 0x0C; /* Leaves An. */ op[1] >>= 2; op[1] |= 0xDC; } } else if (op[-3] == 0xFE) op[-2] = 0x08; else abort (); break; default: (*_bfd_error_handler) (_("%s: Unsupported transition from %s to %s"), bfd_get_filename (input_bfd), elf_mn10300_howto_table[r_type].name, elf_mn10300_howto_table[tls_r_type].name); break; } #undef TLS_PAIR return 0; } /* Look through the relocs for a section during the first phase. Since we don't do .gots or .plts, we just need to consider the virtual table relocs for gc. */ static bfd_boolean mn10300_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, const Elf_Internal_Rela *relocs) { struct elf32_mn10300_link_hash_table * htab = elf32_mn10300_hash_table (info); bfd_boolean sym_diff_reloc_seen; Elf_Internal_Shdr *symtab_hdr; Elf_Internal_Sym * isymbuf = NULL; struct elf_link_hash_entry **sym_hashes; const Elf_Internal_Rela *rel; const Elf_Internal_Rela *rel_end; bfd * dynobj; bfd_vma * local_got_offsets; asection * sgot; asection * srelgot; asection * sreloc; bfd_boolean result = FALSE; sgot = NULL; srelgot = NULL; sreloc = NULL; if (bfd_link_relocatable (info)) return TRUE; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; sym_hashes = elf_sym_hashes (abfd); dynobj = elf_hash_table (info)->dynobj; local_got_offsets = elf_local_got_offsets (abfd); rel_end = relocs + sec->reloc_count; sym_diff_reloc_seen = FALSE; for (rel = relocs; rel < rel_end; rel++) { struct elf_link_hash_entry *h; unsigned long r_symndx; unsigned int r_type; int tls_type = GOT_NORMAL; r_symndx = ELF32_R_SYM (rel->r_info); if (r_symndx < symtab_hdr->sh_info) h = NULL; else { h = sym_hashes[r_symndx - symtab_hdr->sh_info]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; /* PR15323, ref flags aren't set for references in the same object. */ h->root.non_ir_ref = 1; } r_type = ELF32_R_TYPE (rel->r_info); r_type = elf_mn10300_tls_transition (info, r_type, h, sec, TRUE); /* Some relocs require a global offset table. */ if (dynobj == NULL) { switch (r_type) { case R_MN10300_GOT32: case R_MN10300_GOT24: case R_MN10300_GOT16: case R_MN10300_GOTOFF32: case R_MN10300_GOTOFF24: case R_MN10300_GOTOFF16: case R_MN10300_GOTPC32: case R_MN10300_GOTPC16: case R_MN10300_TLS_GD: case R_MN10300_TLS_LD: case R_MN10300_TLS_GOTIE: case R_MN10300_TLS_IE: elf_hash_table (info)->dynobj = dynobj = abfd; if (! _bfd_mn10300_elf_create_got_section (dynobj, info)) goto fail; break; default: break; } } switch (r_type) { /* This relocation describes the C++ object vtable hierarchy. Reconstruct it for later use during GC. */ case R_MN10300_GNU_VTINHERIT: if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) goto fail; break; /* This relocation describes which C++ vtable entries are actually used. Record for later use during GC. */ case R_MN10300_GNU_VTENTRY: BFD_ASSERT (h != NULL); if (h != NULL && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) goto fail; break; case R_MN10300_TLS_LD: htab->tls_ldm_got.refcount ++; tls_type = GOT_TLS_LD; if (htab->tls_ldm_got.got_allocated) break; goto create_got; case R_MN10300_TLS_IE: case R_MN10300_TLS_GOTIE: if (bfd_link_pic (info)) info->flags |= DF_STATIC_TLS; /* Fall through */ case R_MN10300_TLS_GD: case R_MN10300_GOT32: case R_MN10300_GOT24: case R_MN10300_GOT16: create_got: /* This symbol requires a global offset table entry. */ switch (r_type) { case R_MN10300_TLS_IE: case R_MN10300_TLS_GOTIE: tls_type = GOT_TLS_IE; break; case R_MN10300_TLS_GD: tls_type = GOT_TLS_GD; break; default: tls_type = GOT_NORMAL; break; } if (sgot == NULL) { sgot = htab->root.sgot; BFD_ASSERT (sgot != NULL); } if (srelgot == NULL && (h != NULL || bfd_link_pic (info))) { srelgot = bfd_get_linker_section (dynobj, ".rela.got"); if (srelgot == NULL) { flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED | SEC_READONLY); srelgot = bfd_make_section_anyway_with_flags (dynobj, ".rela.got", flags); if (srelgot == NULL || ! bfd_set_section_alignment (dynobj, srelgot, 2)) goto fail; } } if (r_type == R_MN10300_TLS_LD) { htab->tls_ldm_got.offset = sgot->size; htab->tls_ldm_got.got_allocated ++; } else if (h != NULL) { if (elf_mn10300_hash_entry (h)->tls_type != tls_type && elf_mn10300_hash_entry (h)->tls_type != GOT_UNKNOWN) { if (tls_type == GOT_TLS_IE && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_GD) /* No change - this is ok. */; else if (tls_type == GOT_TLS_GD && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_IE) /* Transition GD->IE. */ tls_type = GOT_TLS_IE; else (*_bfd_error_handler) (_("%B: %s' accessed both as normal and thread local symbol"), abfd, h ? h->root.root.string : "<local>"); } elf_mn10300_hash_entry (h)->tls_type = tls_type; if (h->got.offset != (bfd_vma) -1) /* We have already allocated space in the .got. */ break; h->got.offset = sgot->size; if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL /* Make sure this symbol is output as a dynamic symbol. */ && h->dynindx == -1) { if (! bfd_elf_link_record_dynamic_symbol (info, h)) goto fail; } srelgot->size += sizeof (Elf32_External_Rela); if (r_type == R_MN10300_TLS_GD) srelgot->size += sizeof (Elf32_External_Rela); } else { /* This is a global offset table entry for a local symbol. */ if (local_got_offsets == NULL) { size_t size; unsigned int i; size = symtab_hdr->sh_info * (sizeof (bfd_vma) + sizeof (char)); local_got_offsets = bfd_alloc (abfd, size); if (local_got_offsets == NULL) goto fail; elf_local_got_offsets (abfd) = local_got_offsets; elf_mn10300_local_got_tls_type (abfd) = (char *) (local_got_offsets + symtab_hdr->sh_info); for (i = 0; i < symtab_hdr->sh_info; i++) local_got_offsets[i] = (bfd_vma) -1; } if (local_got_offsets[r_symndx] != (bfd_vma) -1) /* We have already allocated space in the .got. */ break; local_got_offsets[r_symndx] = sgot->size; if (bfd_link_pic (info)) { /* If we are generating a shared object, we need to output a R_MN10300_RELATIVE reloc so that the dynamic linker can adjust this GOT entry. */ srelgot->size += sizeof (Elf32_External_Rela); if (r_type == R_MN10300_TLS_GD) /* And a R_MN10300_TLS_DTPOFF reloc as well. */ srelgot->size += sizeof (Elf32_External_Rela); } elf_mn10300_local_got_tls_type (abfd) [r_symndx] = tls_type; } sgot->size += 4; if (r_type == R_MN10300_TLS_GD || r_type == R_MN10300_TLS_LD) sgot->size += 4; goto need_shared_relocs; case R_MN10300_PLT32: case R_MN10300_PLT16: /* This symbol requires a procedure linkage table entry. We actually build the entry in adjust_dynamic_symbol, because this might be a case of linking PIC code which is never referenced by a dynamic object, in which case we don't need to generate a procedure linkage table entry after all. */ /* If this is a local symbol, we resolve it directly without creating a procedure linkage table entry. */ if (h == NULL) continue; if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN) break; h->needs_plt = 1; break; case R_MN10300_24: case R_MN10300_16: case R_MN10300_8: case R_MN10300_PCREL32: case R_MN10300_PCREL16: case R_MN10300_PCREL8: if (h != NULL) h->non_got_ref = 1; break; case R_MN10300_SYM_DIFF: sym_diff_reloc_seen = TRUE; break; case R_MN10300_32: if (h != NULL) h->non_got_ref = 1; need_shared_relocs: /* If we are creating a shared library, then we need to copy the reloc into the shared library. */ if (bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0 /* Do not generate a dynamic reloc for a reloc associated with a SYM_DIFF operation. */ && ! sym_diff_reloc_seen) { asection * sym_section = NULL; /* Find the section containing the symbol involved in the relocation. */ if (h == NULL) { Elf_Internal_Sym * isym; if (isymbuf == NULL) isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL); if (isymbuf) { isym = isymbuf + r_symndx; /* All we care about is whether this local symbol is absolute. */ if (isym->st_shndx == SHN_ABS) sym_section = bfd_abs_section_ptr; } } else { if (h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak) sym_section = h->root.u.def.section; } /* If the symbol is absolute then the relocation can be resolved during linking and there is no need for a dynamic reloc. */ if (sym_section != bfd_abs_section_ptr) { /* When creating a shared object, we must copy these reloc types into the output file. We create a reloc section in dynobj and make room for this reloc. */ if (sreloc == NULL) { sreloc = _bfd_elf_make_dynamic_reloc_section (sec, dynobj, 2, abfd, /*rela?*/ TRUE); if (sreloc == NULL) goto fail; } sreloc->size += sizeof (Elf32_External_Rela); } } break; } if (ELF32_R_TYPE (rel->r_info) != R_MN10300_SYM_DIFF) sym_diff_reloc_seen = FALSE; } result = TRUE; fail: if (isymbuf != NULL) free (isymbuf); return result; } /* Return the section that should be marked against GC for a given relocation. */ static asection * mn10300_elf_gc_mark_hook (asection *sec, struct bfd_link_info *info, Elf_Internal_Rela *rel, struct elf_link_hash_entry *h, Elf_Internal_Sym *sym) { if (h != NULL) switch (ELF32_R_TYPE (rel->r_info)) { case R_MN10300_GNU_VTINHERIT: case R_MN10300_GNU_VTENTRY: return NULL; } return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); } /* Perform a relocation as part of a final link. */ static bfd_reloc_status_type mn10300_elf_final_link_relocate (reloc_howto_type *howto, bfd *input_bfd, bfd *output_bfd ATTRIBUTE_UNUSED, asection *input_section, bfd_byte *contents, bfd_vma offset, bfd_vma value, bfd_vma addend, struct elf_link_hash_entry * h, unsigned long symndx, struct bfd_link_info *info, asection *sym_sec ATTRIBUTE_UNUSED, int is_local ATTRIBUTE_UNUSED) { struct elf32_mn10300_link_hash_table * htab = elf32_mn10300_hash_table (info); static asection * sym_diff_section; static bfd_vma sym_diff_value; bfd_boolean is_sym_diff_reloc; unsigned long r_type = howto->type; bfd_byte * hit_data = contents + offset; bfd * dynobj; asection * sgot; asection * splt; asection * sreloc; dynobj = elf_hash_table (info)->dynobj; sgot = NULL; splt = NULL; sreloc = NULL; switch (r_type) { case R_MN10300_24: case R_MN10300_16: case R_MN10300_8: case R_MN10300_PCREL8: case R_MN10300_PCREL16: case R_MN10300_PCREL32: case R_MN10300_GOTOFF32: case R_MN10300_GOTOFF24: case R_MN10300_GOTOFF16: if (bfd_link_pic (info) && (input_section->flags & SEC_ALLOC) != 0 && h != NULL && ! SYMBOL_REFERENCES_LOCAL (info, h)) return bfd_reloc_dangerous; case R_MN10300_GOT32: /* Issue 2052223: Taking the address of a protected function in a shared library is illegal. Issue an error message here. */ if (bfd_link_pic (info) && (input_section->flags & SEC_ALLOC) != 0 && h != NULL && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED && (h->type == STT_FUNC || h->type == STT_GNU_IFUNC) && ! SYMBOL_REFERENCES_LOCAL (info, h)) return bfd_reloc_dangerous; } is_sym_diff_reloc = FALSE; if (sym_diff_section != NULL) { BFD_ASSERT (sym_diff_section == input_section); switch (r_type) { case R_MN10300_32: case R_MN10300_24: case R_MN10300_16: case R_MN10300_8: value -= sym_diff_value; /* If we are computing a 32-bit value for the location lists and the result is 0 then we add one to the value. A zero value can result because of linker relaxation deleteing prologue instructions and using a value of 1 (for the begin and end offsets in the location list entry) results in a nul entry which does not prevent the following entries from being parsed. */ if (r_type == R_MN10300_32 && value == 0 && strcmp (input_section->name, ".debug_loc") == 0) value = 1; sym_diff_section = NULL; is_sym_diff_reloc = TRUE; break; default: sym_diff_section = NULL; break; } } switch (r_type) { case R_MN10300_SYM_DIFF: BFD_ASSERT (addend == 0); /* Cache the input section and value. The offset is unreliable, since relaxation may have reduced the following reloc's offset. */ sym_diff_section = input_section; sym_diff_value = value; return bfd_reloc_ok; case R_MN10300_ALIGN: case R_MN10300_NONE: return bfd_reloc_ok; case R_MN10300_32: if (bfd_link_pic (info) /* Do not generate relocs when an R_MN10300_32 has been used with an R_MN10300_SYM_DIFF to compute a difference of two symbols. */ && is_sym_diff_reloc == FALSE /* Also, do not generate a reloc when the symbol associated with the R_MN10300_32 reloc is absolute - there is no need for a run time computation in this case. */ && sym_sec != bfd_abs_section_ptr /* If the section is not going to be allocated at load time then there is no need to generate relocs for it. */ && (input_section->flags & SEC_ALLOC) != 0) { Elf_Internal_Rela outrel; bfd_boolean skip, relocate; /* When generating a shared object, these relocations are copied into the output file to be resolved at run time. */ if (sreloc == NULL) { sreloc = _bfd_elf_get_dynamic_reloc_section (input_bfd, input_section, /*rela?*/ TRUE); if (sreloc == NULL) return FALSE; } skip = FALSE; outrel.r_offset = _bfd_elf_section_offset (input_bfd, info, input_section, offset); if (outrel.r_offset == (bfd_vma) -1) skip = TRUE; outrel.r_offset += (input_section->output_section->vma + input_section->output_offset); if (skip) { memset (&outrel, 0, sizeof outrel); relocate = FALSE; } else { /* h->dynindx may be -1 if this symbol was marked to become local. */ if (h == NULL || SYMBOL_REFERENCES_LOCAL (info, h)) { relocate = TRUE; outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE); outrel.r_addend = value + addend; } else { BFD_ASSERT (h->dynindx != -1); relocate = FALSE; outrel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_32); outrel.r_addend = value + addend; } } bfd_elf32_swap_reloca_out (output_bfd, &outrel, (bfd_byte *) (((Elf32_External_Rela *) sreloc->contents) + sreloc->reloc_count)); ++sreloc->reloc_count; /* If this reloc is against an external symbol, we do not want to fiddle with the addend. Otherwise, we need to include the symbol value so that it becomes an addend for the dynamic reloc. */ if (! relocate) return bfd_reloc_ok; } value += addend; bfd_put_32 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_24: value += addend; if ((long) value > 0x7fffff || (long) value < -0x800000) return bfd_reloc_overflow; bfd_put_8 (input_bfd, value & 0xff, hit_data); bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1); bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2); return bfd_reloc_ok; case R_MN10300_16: value += addend; if ((long) value > 0x7fff || (long) value < -0x8000) return bfd_reloc_overflow; bfd_put_16 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_8: value += addend; if ((long) value > 0x7f || (long) value < -0x80) return bfd_reloc_overflow; bfd_put_8 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_PCREL8: value -= (input_section->output_section->vma + input_section->output_offset); value -= offset; value += addend; if ((long) value > 0x7f || (long) value < -0x80) return bfd_reloc_overflow; bfd_put_8 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_PCREL16: value -= (input_section->output_section->vma + input_section->output_offset); value -= offset; value += addend; if ((long) value > 0x7fff || (long) value < -0x8000) return bfd_reloc_overflow; bfd_put_16 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_PCREL32: value -= (input_section->output_section->vma + input_section->output_offset); value -= offset; value += addend; bfd_put_32 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_GNU_VTINHERIT: case R_MN10300_GNU_VTENTRY: return bfd_reloc_ok; case R_MN10300_GOTPC32: if (dynobj == NULL) return bfd_reloc_dangerous; /* Use global offset table as symbol value. */ value = htab->root.sgot->output_section->vma; value -= (input_section->output_section->vma + input_section->output_offset); value -= offset; value += addend; bfd_put_32 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_GOTPC16: if (dynobj == NULL) return bfd_reloc_dangerous; /* Use global offset table as symbol value. */ value = htab->root.sgot->output_section->vma; value -= (input_section->output_section->vma + input_section->output_offset); value -= offset; value += addend; if ((long) value > 0x7fff || (long) value < -0x8000) return bfd_reloc_overflow; bfd_put_16 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_GOTOFF32: if (dynobj == NULL) return bfd_reloc_dangerous; value -= htab->root.sgot->output_section->vma; value += addend; bfd_put_32 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_GOTOFF24: if (dynobj == NULL) return bfd_reloc_dangerous; value -= htab->root.sgot->output_section->vma; value += addend; if ((long) value > 0x7fffff || (long) value < -0x800000) return bfd_reloc_overflow; bfd_put_8 (input_bfd, value, hit_data); bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1); bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2); return bfd_reloc_ok; case R_MN10300_GOTOFF16: if (dynobj == NULL) return bfd_reloc_dangerous; value -= htab->root.sgot->output_section->vma; value += addend; if ((long) value > 0x7fff || (long) value < -0x8000) return bfd_reloc_overflow; bfd_put_16 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_PLT32: if (h != NULL && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN && h->plt.offset != (bfd_vma) -1) { if (dynobj == NULL) return bfd_reloc_dangerous; splt = htab->root.splt; value = (splt->output_section->vma + splt->output_offset + h->plt.offset) - value; } value -= (input_section->output_section->vma + input_section->output_offset); value -= offset; value += addend; bfd_put_32 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_PLT16: if (h != NULL && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN && h->plt.offset != (bfd_vma) -1) { if (dynobj == NULL) return bfd_reloc_dangerous; splt = htab->root.splt; value = (splt->output_section->vma + splt->output_offset + h->plt.offset) - value; } value -= (input_section->output_section->vma + input_section->output_offset); value -= offset; value += addend; if ((long) value > 0x7fff || (long) value < -0x8000) return bfd_reloc_overflow; bfd_put_16 (input_bfd, value, hit_data); return bfd_reloc_ok; case R_MN10300_TLS_LDO: value = dtpoff (info, value); bfd_put_32 (input_bfd, value + addend, hit_data); return bfd_reloc_ok; case R_MN10300_TLS_LE: value = tpoff (info, value); bfd_put_32 (input_bfd, value + addend, hit_data); return bfd_reloc_ok; case R_MN10300_TLS_LD: if (dynobj == NULL) return bfd_reloc_dangerous; sgot = htab->root.sgot; BFD_ASSERT (sgot != NULL); value = htab->tls_ldm_got.offset + sgot->output_offset; bfd_put_32 (input_bfd, value, hit_data); if (!htab->tls_ldm_got.rel_emitted) { asection * srelgot = bfd_get_linker_section (dynobj, ".rela.got"); Elf_Internal_Rela rel; BFD_ASSERT (srelgot != NULL); htab->tls_ldm_got.rel_emitted ++; rel.r_offset = (sgot->output_section->vma + sgot->output_offset + htab->tls_ldm_got.offset); bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + htab->tls_ldm_got.offset); bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + htab->tls_ldm_got.offset+4); rel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPMOD); rel.r_addend = 0; bfd_elf32_swap_reloca_out (output_bfd, & rel, (bfd_byte *) ((Elf32_External_Rela *) srelgot->contents + srelgot->reloc_count)); ++ srelgot->reloc_count; } return bfd_reloc_ok; case R_MN10300_TLS_GOTIE: value = tpoff (info, value); /* Fall Through. */ case R_MN10300_TLS_GD: case R_MN10300_TLS_IE: case R_MN10300_GOT32: case R_MN10300_GOT24: case R_MN10300_GOT16: if (dynobj == NULL) return bfd_reloc_dangerous; sgot = htab->root.sgot; if (r_type == R_MN10300_TLS_GD) value = dtpoff (info, value); if (h != NULL) { bfd_vma off; off = h->got.offset; /* Offsets in the GOT are allocated in check_relocs which is not called for shared libraries... */ if (off == (bfd_vma) -1) off = 0; if (sgot->contents != NULL && (! elf_hash_table (info)->dynamic_sections_created || SYMBOL_REFERENCES_LOCAL (info, h))) /* This is actually a static link, or it is a -Bsymbolic link and the symbol is defined locally, or the symbol was forced to be local because of a version file. We must initialize this entry in the global offset table. When doing a dynamic link, we create a .rela.got relocation entry to initialize the value. This is done in the finish_dynamic_symbol routine. */ bfd_put_32 (output_bfd, value, sgot->contents + off); value = sgot->output_offset + off; } else { bfd_vma off; off = elf_local_got_offsets (input_bfd)[symndx]; if (off & 1) bfd_put_32 (output_bfd, value, sgot->contents + (off & ~ 1)); else { bfd_put_32 (output_bfd, value, sgot->contents + off); if (bfd_link_pic (info)) { asection * srelgot; Elf_Internal_Rela outrel; srelgot = bfd_get_linker_section (dynobj, ".rela.got"); BFD_ASSERT (srelgot != NULL); outrel.r_offset = (sgot->output_section->vma + sgot->output_offset + off); switch (r_type) { case R_MN10300_TLS_GD: outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPOFF); outrel.r_offset = (sgot->output_section->vma + sgot->output_offset + off + 4); bfd_elf32_swap_reloca_out (output_bfd, & outrel, (bfd_byte *) (((Elf32_External_Rela *) srelgot->contents) + srelgot->reloc_count)); ++ srelgot->reloc_count; outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPMOD); break; case R_MN10300_TLS_GOTIE: case R_MN10300_TLS_IE: outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_TPOFF); break; default: outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE); break; } outrel.r_addend = value; bfd_elf32_swap_reloca_out (output_bfd, &outrel, (bfd_byte *) (((Elf32_External_Rela *) srelgot->contents) + srelgot->reloc_count)); ++ srelgot->reloc_count; elf_local_got_offsets (input_bfd)[symndx] |= 1; } value = sgot->output_offset + (off & ~(bfd_vma) 1); } } value += addend; if (r_type == R_MN10300_TLS_IE) { value += sgot->output_section->vma; bfd_put_32 (input_bfd, value, hit_data); return bfd_reloc_ok; } else if (r_type == R_MN10300_TLS_GOTIE || r_type == R_MN10300_TLS_GD || r_type == R_MN10300_TLS_LD) { bfd_put_32 (input_bfd, value, hit_data); return bfd_reloc_ok; } else if (r_type == R_MN10300_GOT32) { bfd_put_32 (input_bfd, value, hit_data); return bfd_reloc_ok; } else if (r_type == R_MN10300_GOT24) { if ((long) value > 0x7fffff || (long) value < -0x800000) return bfd_reloc_overflow; bfd_put_8 (input_bfd, value & 0xff, hit_data); bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1); bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2); return bfd_reloc_ok; } else if (r_type == R_MN10300_GOT16) { if ((long) value > 0x7fff || (long) value < -0x8000) return bfd_reloc_overflow; bfd_put_16 (input_bfd, value, hit_data); return bfd_reloc_ok; } /* Fall through. */ default: return bfd_reloc_notsupported; } } /* Relocate an MN10300 ELF section. */ static bfd_boolean mn10300_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, bfd *input_bfd, asection *input_section, bfd_byte *contents, Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms, asection **local_sections) { Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; Elf_Internal_Rela *rel, *relend; Elf_Internal_Rela * trel; symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; sym_hashes = elf_sym_hashes (input_bfd); rel = relocs; relend = relocs + input_section->reloc_count; for (; rel < relend; rel++) { int r_type; reloc_howto_type *howto; unsigned long r_symndx; Elf_Internal_Sym *sym; asection *sec; struct elf32_mn10300_link_hash_entry *h; bfd_vma relocation; bfd_reloc_status_type r; int tls_r_type; bfd_boolean unresolved_reloc = FALSE; bfd_boolean warned, ignored; struct elf_link_hash_entry * hh; relocation = 0; r_symndx = ELF32_R_SYM (rel->r_info); r_type = ELF32_R_TYPE (rel->r_info); howto = elf_mn10300_howto_table + r_type; /* Just skip the vtable gc relocs. */ if (r_type == R_MN10300_GNU_VTINHERIT || r_type == R_MN10300_GNU_VTENTRY) continue; h = NULL; sym = NULL; sec = NULL; if (r_symndx < symtab_hdr->sh_info) hh = NULL; else { RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, r_symndx, symtab_hdr, sym_hashes, hh, sec, relocation, unresolved_reloc, warned, ignored); } h = elf_mn10300_hash_entry (hh); tls_r_type = elf_mn10300_tls_transition (info, r_type, hh, input_section, 0); if (tls_r_type != r_type) { bfd_boolean had_plt; had_plt = mn10300_do_tls_transition (input_bfd, r_type, tls_r_type, contents, rel->r_offset); r_type = tls_r_type; howto = elf_mn10300_howto_table + r_type; if (had_plt) for (trel = rel+1; trel < relend; trel++) if ((ELF32_R_TYPE (trel->r_info) == R_MN10300_PLT32 || ELF32_R_TYPE (trel->r_info) == R_MN10300_PCREL32) && rel->r_offset + had_plt == trel->r_offset) trel->r_info = ELF32_R_INFO (0, R_MN10300_NONE); } if (r_symndx < symtab_hdr->sh_info) { sym = local_syms + r_symndx; sec = local_sections[r_symndx]; relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); } else { if ((h->root.root.type == bfd_link_hash_defined || h->root.root.type == bfd_link_hash_defweak) && ( r_type == R_MN10300_GOTPC32 || r_type == R_MN10300_GOTPC16 || (( r_type == R_MN10300_PLT32 || r_type == R_MN10300_PLT16) && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN && h->root.plt.offset != (bfd_vma) -1) || (( r_type == R_MN10300_GOT32 || r_type == R_MN10300_GOT24 || r_type == R_MN10300_TLS_GD || r_type == R_MN10300_TLS_LD || r_type == R_MN10300_TLS_GOTIE || r_type == R_MN10300_TLS_IE || r_type == R_MN10300_GOT16) && elf_hash_table (info)->dynamic_sections_created && !SYMBOL_REFERENCES_LOCAL (info, hh)) || (r_type == R_MN10300_32 /* _32 relocs in executables force _COPY relocs, such that the address of the symbol ends up being local. */ && !bfd_link_executable (info) && !SYMBOL_REFERENCES_LOCAL (info, hh) && ((input_section->flags & SEC_ALLOC) != 0 /* DWARF will emit R_MN10300_32 relocations in its sections against symbols defined externally in shared libraries. We can't do anything with them here. */ || ((input_section->flags & SEC_DEBUGGING) != 0 && h->root.def_dynamic))))) /* In these cases, we don't need the relocation value. We check specially because in some obscure cases sec->output_section will be NULL. */ relocation = 0; else if (!bfd_link_relocatable (info) && unresolved_reloc && _bfd_elf_section_offset (output_bfd, info, input_section, rel->r_offset) != (bfd_vma) -1) (*_bfd_error_handler) (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), input_bfd, input_section, (long) rel->r_offset, howto->name, h->root.root.root.string); } if (sec != NULL && discarded_section (sec)) RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, rel, 1, relend, howto, 0, contents); if (bfd_link_relocatable (info)) continue; r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd, input_section, contents, rel->r_offset, relocation, rel->r_addend, (struct elf_link_hash_entry *) h, r_symndx, info, sec, h == NULL); if (r != bfd_reloc_ok) { const char *name; const char *msg = NULL; if (h != NULL) name = h->root.root.root.string; else { name = (bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link, sym->st_name)); if (name == NULL || *name == '\0') name = bfd_section_name (input_bfd, sec); } switch (r) { case bfd_reloc_overflow: if (! ((*info->callbacks->reloc_overflow) (info, (h ? &h->root.root : NULL), name, howto->name, (bfd_vma) 0, input_bfd, input_section, rel->r_offset))) return FALSE; break; case bfd_reloc_undefined: if (! ((*info->callbacks->undefined_symbol) (info, name, input_bfd, input_section, rel->r_offset, TRUE))) return FALSE; break; case bfd_reloc_outofrange: msg = _("internal error: out of range error"); goto common_error; case bfd_reloc_notsupported: msg = _("internal error: unsupported relocation error"); goto common_error; case bfd_reloc_dangerous: if (r_type == R_MN10300_PCREL32) msg = _("error: inappropriate relocation type for shared" " library (did you forget -fpic?)"); else if (r_type == R_MN10300_GOT32) msg = _("%B: taking the address of protected function" " '%s' cannot be done when making a shared library"); else msg = _("internal error: suspicious relocation type used" " in shared library"); goto common_error; default: msg = _("internal error: unknown error"); /* Fall through. */ common_error: _bfd_error_handler (msg, input_bfd, name); bfd_set_error (bfd_error_bad_value); return FALSE; } } } return TRUE; } /* Finish initializing one hash table entry. */ static bfd_boolean elf32_mn10300_finish_hash_table_entry (struct bfd_hash_entry *gen_entry, void * in_args) { struct elf32_mn10300_link_hash_entry *entry; struct bfd_link_info *link_info = (struct bfd_link_info *) in_args; unsigned int byte_count = 0; entry = (struct elf32_mn10300_link_hash_entry *) gen_entry; /* If we already know we want to convert "call" to "calls" for calls to this symbol, then return now. */ if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS) return TRUE; /* If there are no named calls to this symbol, or there's nothing we can move from the function itself into the "call" instruction, then note that all "call" instructions should be converted into "calls" instructions and return. If a symbol is available for dynamic symbol resolution (overridable or overriding), avoid custom calling conventions. */ if (entry->direct_calls == 0 || (entry->stack_size == 0 && entry->movm_args == 0) || (elf_hash_table (link_info)->dynamic_sections_created && ELF_ST_VISIBILITY (entry->root.other) != STV_INTERNAL && ELF_ST_VISIBILITY (entry->root.other) != STV_HIDDEN)) { /* Make a note that we should convert "call" instructions to "calls" instructions for calls to this symbol. */ entry->flags |= MN10300_CONVERT_CALL_TO_CALLS; return TRUE; } /* We may be able to move some instructions from the function itself into the "call" instruction. Count how many bytes we might be able to eliminate in the function itself. */ /* A movm instruction is two bytes. */ if (entry->movm_args) byte_count += 2; /* Count the insn to allocate stack space too. */ if (entry->stack_size > 0) { if (entry->stack_size <= 128) byte_count += 3; else byte_count += 4; } /* If using "call" will result in larger code, then turn all the associated "call" instructions into "calls" instructions. */ if (byte_count < entry->direct_calls) entry->flags |= MN10300_CONVERT_CALL_TO_CALLS; /* This routine never fails. */ return TRUE; } /* Used to count hash table entries. */ static bfd_boolean elf32_mn10300_count_hash_table_entries (struct bfd_hash_entry *gen_entry ATTRIBUTE_UNUSED, void * in_args) { int *count = (int *) in_args; (*count) ++; return TRUE; } /* Used to enumerate hash table entries into a linear array. */ static bfd_boolean elf32_mn10300_list_hash_table_entries (struct bfd_hash_entry *gen_entry, void * in_args) { struct bfd_hash_entry ***ptr = (struct bfd_hash_entry ***) in_args; **ptr = gen_entry; (*ptr) ++; return TRUE; } /* Used to sort the array created by the above. */ static int sort_by_value (const void *va, const void *vb) { struct elf32_mn10300_link_hash_entry *a = *(struct elf32_mn10300_link_hash_entry **) va; struct elf32_mn10300_link_hash_entry *b = *(struct elf32_mn10300_link_hash_entry **) vb; return a->value - b->value; } /* Compute the stack size and movm arguments for the function referred to by HASH at address ADDR in section with contents CONTENTS, store the information in the hash table. */ static void compute_function_info (bfd *abfd, struct elf32_mn10300_link_hash_entry *hash, bfd_vma addr, unsigned char *contents) { unsigned char byte1, byte2; /* We only care about a very small subset of the possible prologue sequences here. Basically we look for: movm [d2,d3,a2,a3],sp (optional) add <size>,sp (optional, and only for sizes which fit in an unsigned 8 bit number) If we find anything else, we quit. */ /* Look for movm [regs],sp. */ byte1 = bfd_get_8 (abfd, contents + addr); byte2 = bfd_get_8 (abfd, contents + addr + 1); if (byte1 == 0xcf) { hash->movm_args = byte2; addr += 2; byte1 = bfd_get_8 (abfd, contents + addr); byte2 = bfd_get_8 (abfd, contents + addr + 1); } /* Now figure out how much stack space will be allocated by the movm instruction. We need this kept separate from the function's normal stack space. */ if (hash->movm_args) { /* Space for d2. */ if (hash->movm_args & 0x80) hash->movm_stack_size += 4; /* Space for d3. */ if (hash->movm_args & 0x40) hash->movm_stack_size += 4; /* Space for a2. */ if (hash->movm_args & 0x20) hash->movm_stack_size += 4; /* Space for a3. */ if (hash->movm_args & 0x10) hash->movm_stack_size += 4; /* "other" space. d0, d1, a0, a1, mdr, lir, lar, 4 byte pad. */ if (hash->movm_args & 0x08) hash->movm_stack_size += 8 * 4; if (bfd_get_mach (abfd) == bfd_mach_am33 || bfd_get_mach (abfd) == bfd_mach_am33_2) { /* "exother" space. e0, e1, mdrq, mcrh, mcrl, mcvf */ if (hash->movm_args & 0x1) hash->movm_stack_size += 6 * 4; /* exreg1 space. e4, e5, e6, e7 */ if (hash->movm_args & 0x2) hash->movm_stack_size += 4 * 4; /* exreg0 space. e2, e3 */ if (hash->movm_args & 0x4) hash->movm_stack_size += 2 * 4; } } /* Now look for the two stack adjustment variants. */ if (byte1 == 0xf8 && byte2 == 0xfe) { int temp = bfd_get_8 (abfd, contents + addr + 2); temp = ((temp & 0xff) ^ (~0x7f)) + 0x80; hash->stack_size = -temp; } else if (byte1 == 0xfa && byte2 == 0xfe) { int temp = bfd_get_16 (abfd, contents + addr + 2); temp = ((temp & 0xffff) ^ (~0x7fff)) + 0x8000; temp = -temp; if (temp < 255) hash->stack_size = temp; } /* If the total stack to be allocated by the call instruction is more than 255 bytes, then we can't remove the stack adjustment by using "call" (we might still be able to remove the "movm" instruction. */ if (hash->stack_size + hash->movm_stack_size > 255) hash->stack_size = 0; } /* Delete some bytes from a section while relaxing. */ static bfd_boolean mn10300_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr, int count) { Elf_Internal_Shdr *symtab_hdr; unsigned int sec_shndx; bfd_byte *contents; Elf_Internal_Rela *irel, *irelend; Elf_Internal_Rela *irelalign; bfd_vma toaddr; Elf_Internal_Sym *isym, *isymend; struct elf_link_hash_entry **sym_hashes; struct elf_link_hash_entry **end_hashes; unsigned int symcount; sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec); contents = elf_section_data (sec)->this_hdr.contents; irelalign = NULL; toaddr = sec->size; irel = elf_section_data (sec)->relocs; irelend = irel + sec->reloc_count; if (sec->reloc_count > 0) { /* If there is an align reloc at the end of the section ignore it. GAS creates these relocs for reasons of its own, and they just serve to keep the section artifically inflated. */ if (ELF32_R_TYPE ((irelend - 1)->r_info) == (int) R_MN10300_ALIGN) --irelend; /* The deletion must stop at the next ALIGN reloc for an aligment power larger than, or not a multiple of, the number of bytes we are deleting. */ for (; irel < irelend; irel++) { int alignment = 1 << irel->r_addend; if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN && irel->r_offset > addr && irel->r_offset < toaddr && (count < alignment || alignment % count != 0)) { irelalign = irel; toaddr = irel->r_offset; break; } } } /* Actually delete the bytes. */ memmove (contents + addr, contents + addr + count, (size_t) (toaddr - addr - count)); /* Adjust the section's size if we are shrinking it, or else pad the bytes between the end of the shrunken region and the start of the next region with NOP codes. */ if (irelalign == NULL) { sec->size -= count; /* Include symbols at the end of the section, but not at the end of a sub-region of the section. */ toaddr ++; } else { int i; #define NOP_OPCODE 0xcb for (i = 0; i < count; i ++) bfd_put_8 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i); } /* Adjust all the relocs. */ for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++) { /* Get the new reloc address. */ if ((irel->r_offset > addr && irel->r_offset < toaddr) || (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN && irel->r_offset == toaddr)) irel->r_offset -= count; } /* Adjust the local symbols in the section, reducing their value by the number of bytes deleted. Note - symbols within the deleted region are moved to the address of the start of the region, which actually means that they will address the byte beyond the end of the region once the deletion has been completed. */ symtab_hdr = &elf_tdata (abfd)->symtab_hdr; isym = (Elf_Internal_Sym *) symtab_hdr->contents; for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++) { if (isym->st_shndx == sec_shndx && isym->st_value > addr && isym->st_value < toaddr) { if (isym->st_value < addr + count) isym->st_value = addr; else isym->st_value -= count; } /* Adjust the function symbol's size as well. */ else if (isym->st_shndx == sec_shndx && ELF_ST_TYPE (isym->st_info) == STT_FUNC && isym->st_value + isym->st_size > addr && isym->st_value + isym->st_size < toaddr) isym->st_size -= count; } /* Now adjust the global symbols defined in this section. */ symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) - symtab_hdr->sh_info); sym_hashes = elf_sym_hashes (abfd); end_hashes = sym_hashes + symcount; for (; sym_hashes < end_hashes; sym_hashes++) { struct elf_link_hash_entry *sym_hash = *sym_hashes; if ((sym_hash->root.type == bfd_link_hash_defined || sym_hash->root.type == bfd_link_hash_defweak) && sym_hash->root.u.def.section == sec && sym_hash->root.u.def.value > addr && sym_hash->root.u.def.value < toaddr) { if (sym_hash->root.u.def.value < addr + count) sym_hash->root.u.def.value = addr; else sym_hash->root.u.def.value -= count; } /* Adjust the function symbol's size as well. */ else if (sym_hash->root.type == bfd_link_hash_defined && sym_hash->root.u.def.section == sec && sym_hash->type == STT_FUNC && sym_hash->root.u.def.value + sym_hash->size > addr && sym_hash->root.u.def.value + sym_hash->size < toaddr) sym_hash->size -= count; } /* See if we can move the ALIGN reloc forward. We have adjusted r_offset for it already. */ if (irelalign != NULL) { bfd_vma alignto, alignaddr; if ((int) irelalign->r_addend > 0) { /* This is the old address. */ alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend); /* This is where the align points to now. */ alignaddr = BFD_ALIGN (irelalign->r_offset, 1 << irelalign->r_addend); if (alignaddr < alignto) /* Tail recursion. */ return mn10300_elf_relax_delete_bytes (abfd, sec, alignaddr, (int) (alignto - alignaddr)); } } return TRUE; } /* Return TRUE if a symbol exists at the given address, else return FALSE. */ static bfd_boolean mn10300_elf_symbol_address_p (bfd *abfd, asection *sec, Elf_Internal_Sym *isym, bfd_vma addr) { Elf_Internal_Shdr *symtab_hdr; unsigned int sec_shndx; Elf_Internal_Sym *isymend; struct elf_link_hash_entry **sym_hashes; struct elf_link_hash_entry **end_hashes; unsigned int symcount; sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec); /* Examine all the symbols. */ symtab_hdr = &elf_tdata (abfd)->symtab_hdr; for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++) if (isym->st_shndx == sec_shndx && isym->st_value == addr) return TRUE; symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) - symtab_hdr->sh_info); sym_hashes = elf_sym_hashes (abfd); end_hashes = sym_hashes + symcount; for (; sym_hashes < end_hashes; sym_hashes++) { struct elf_link_hash_entry *sym_hash = *sym_hashes; if ((sym_hash->root.type == bfd_link_hash_defined || sym_hash->root.type == bfd_link_hash_defweak) && sym_hash->root.u.def.section == sec && sym_hash->root.u.def.value == addr) return TRUE; } return FALSE; } /* This function handles relaxing for the mn10300. There are quite a few relaxing opportunities available on the mn10300: * calls:32 -> calls:16 2 bytes * call:32 -> call:16 2 bytes * call:32 -> calls:32 1 byte * call:16 -> calls:16 1 byte * These are done anytime using "calls" would result in smaller code, or when necessary to preserve the meaning of the program. * call:32 varies * call:16 * In some circumstances we can move instructions from a function prologue into a "call" instruction. This is only done if the resulting code is no larger than the original code. * jmp:32 -> jmp:16 2 bytes * jmp:16 -> bra:8 1 byte * If the previous instruction is a conditional branch around the jump/bra, we may be able to reverse its condition and change its target to the jump's target. The jump/bra can then be deleted. 2 bytes * mov abs32 -> mov abs16 1 or 2 bytes * Most instructions which accept imm32 can relax to imm16 1 or 2 bytes - Most instructions which accept imm16 can relax to imm8 1 or 2 bytes * Most instructions which accept d32 can relax to d16 1 or 2 bytes - Most instructions which accept d16 can relax to d8 1 or 2 bytes We don't handle imm16->imm8 or d16->d8 as they're very rare and somewhat more difficult to support. */ static bfd_boolean mn10300_elf_relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info, bfd_boolean *again) { Elf_Internal_Shdr *symtab_hdr; Elf_Internal_Rela *internal_relocs = NULL; Elf_Internal_Rela *irel, *irelend; bfd_byte *contents = NULL; Elf_Internal_Sym *isymbuf = NULL; struct elf32_mn10300_link_hash_table *hash_table; asection *section = sec; bfd_vma align_gap_adjustment; if (bfd_link_relocatable (link_info)) (*link_info->callbacks->einfo) (_("%P%F: --relax and -r may not be used together\n")); /* Assume nothing changes. */ *again = FALSE; /* We need a pointer to the mn10300 specific hash table. */ hash_table = elf32_mn10300_hash_table (link_info); if (hash_table == NULL) return FALSE; /* Initialize fields in each hash table entry the first time through. */ if ((hash_table->flags & MN10300_HASH_ENTRIES_INITIALIZED) == 0) { bfd *input_bfd; /* Iterate over all the input bfds. */ for (input_bfd = link_info->input_bfds; input_bfd != NULL; input_bfd = input_bfd->link.next) { /* We're going to need all the symbols for each bfd. */ symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; if (symtab_hdr->sh_info != 0) { isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; if (isymbuf == NULL) isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL); if (isymbuf == NULL) goto error_return; } /* Iterate over each section in this bfd. */ for (section = input_bfd->sections; section != NULL; section = section->next) { struct elf32_mn10300_link_hash_entry *hash; asection *sym_sec = NULL; const char *sym_name; char *new_name; /* If there's nothing to do in this section, skip it. */ if (! ((section->flags & SEC_RELOC) != 0 && section->reloc_count != 0)) continue; if ((section->flags & SEC_ALLOC) == 0) continue; /* Get cached copy of section contents if it exists. */ if (elf_section_data (section)->this_hdr.contents != NULL) contents = elf_section_data (section)->this_hdr.contents; else if (section->size != 0) { /* Go get them off disk. */ if (!bfd_malloc_and_get_section (input_bfd, section, &contents)) goto error_return; } else contents = NULL; /* If there aren't any relocs, then there's nothing to do. */ if ((section->flags & SEC_RELOC) != 0 && section->reloc_count != 0) { /* Get a copy of the native relocations. */ internal_relocs = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, link_info->keep_memory); if (internal_relocs == NULL) goto error_return; /* Now examine each relocation. */ irel = internal_relocs; irelend = irel + section->reloc_count; for (; irel < irelend; irel++) { long r_type; unsigned long r_index; unsigned char code; r_type = ELF32_R_TYPE (irel->r_info); r_index = ELF32_R_SYM (irel->r_info); if (r_type < 0 || r_type >= (int) R_MN10300_MAX) goto error_return; /* We need the name and hash table entry of the target symbol! */ hash = NULL; sym_sec = NULL; if (r_index < symtab_hdr->sh_info) { /* A local symbol. */ Elf_Internal_Sym *isym; struct elf_link_hash_table *elftab; bfd_size_type amt; isym = isymbuf + r_index; if (isym->st_shndx == SHN_UNDEF) sym_sec = bfd_und_section_ptr; else if (isym->st_shndx == SHN_ABS) sym_sec = bfd_abs_section_ptr; else if (isym->st_shndx == SHN_COMMON) sym_sec = bfd_com_section_ptr; else sym_sec = bfd_section_from_elf_index (input_bfd, isym->st_shndx); sym_name = bfd_elf_string_from_elf_section (input_bfd, (symtab_hdr ->sh_link), isym->st_name); /* If it isn't a function, then we don't care about it. */ if (ELF_ST_TYPE (isym->st_info) != STT_FUNC) continue; /* Tack on an ID so we can uniquely identify this local symbol in the global hash table. */ amt = strlen (sym_name) + 10; new_name = bfd_malloc (amt); if (new_name == NULL) goto error_return; sprintf (new_name, "%s_%08x", sym_name, sym_sec->id); sym_name = new_name; elftab = &hash_table->static_hash_table->root; hash = ((struct elf32_mn10300_link_hash_entry *) elf_link_hash_lookup (elftab, sym_name, TRUE, TRUE, FALSE)); free (new_name); } else { r_index -= symtab_hdr->sh_info; hash = (struct elf32_mn10300_link_hash_entry *) elf_sym_hashes (input_bfd)[r_index]; } sym_name = hash->root.root.root.string; if ((section->flags & SEC_CODE) != 0) { /* If this is not a "call" instruction, then we should convert "call" instructions to "calls" instructions. */ code = bfd_get_8 (input_bfd, contents + irel->r_offset - 1); if (code != 0xdd && code != 0xcd) hash->flags |= MN10300_CONVERT_CALL_TO_CALLS; } /* If this is a jump/call, then bump the direct_calls counter. Else force "call" to "calls" conversions. */ if (r_type == R_MN10300_PCREL32 || r_type == R_MN10300_PLT32 || r_type == R_MN10300_PLT16 || r_type == R_MN10300_PCREL16) hash->direct_calls++; else hash->flags |= MN10300_CONVERT_CALL_TO_CALLS; } } /* Now look at the actual contents to get the stack size, and a list of what registers were saved in the prologue (ie movm_args). */ if ((section->flags & SEC_CODE) != 0) { Elf_Internal_Sym *isym, *isymend; unsigned int sec_shndx; struct elf_link_hash_entry **hashes; struct elf_link_hash_entry **end_hashes; unsigned int symcount; sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd, section); symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) - symtab_hdr->sh_info); hashes = elf_sym_hashes (input_bfd); end_hashes = hashes + symcount; /* Look at each function defined in this section and update info for that function. */ isymend = isymbuf + symtab_hdr->sh_info; for (isym = isymbuf; isym < isymend; isym++) { if (isym->st_shndx == sec_shndx && ELF_ST_TYPE (isym->st_info) == STT_FUNC) { struct elf_link_hash_table *elftab; bfd_size_type amt; struct elf_link_hash_entry **lhashes = hashes; /* Skip a local symbol if it aliases a global one. */ for (; lhashes < end_hashes; lhashes++) { hash = (struct elf32_mn10300_link_hash_entry *) *lhashes; if ((hash->root.root.type == bfd_link_hash_defined || hash->root.root.type == bfd_link_hash_defweak) && hash->root.root.u.def.section == section && hash->root.type == STT_FUNC && hash->root.root.u.def.value == isym->st_value) break; } if (lhashes != end_hashes) continue; if (isym->st_shndx == SHN_UNDEF) sym_sec = bfd_und_section_ptr; else if (isym->st_shndx == SHN_ABS) sym_sec = bfd_abs_section_ptr; else if (isym->st_shndx == SHN_COMMON) sym_sec = bfd_com_section_ptr; else sym_sec = bfd_section_from_elf_index (input_bfd, isym->st_shndx); sym_name = (bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link, isym->st_name)); /* Tack on an ID so we can uniquely identify this local symbol in the global hash table. */ amt = strlen (sym_name) + 10; new_name = bfd_malloc (amt); if (new_name == NULL) goto error_return; sprintf (new_name, "%s_%08x", sym_name, sym_sec->id); sym_name = new_name; elftab = &hash_table->static_hash_table->root; hash = ((struct elf32_mn10300_link_hash_entry *) elf_link_hash_lookup (elftab, sym_name, TRUE, TRUE, FALSE)); free (new_name); compute_function_info (input_bfd, hash, isym->st_value, contents); hash->value = isym->st_value; } } for (; hashes < end_hashes; hashes++) { hash = (struct elf32_mn10300_link_hash_entry *) *hashes; if ((hash->root.root.type == bfd_link_hash_defined || hash->root.root.type == bfd_link_hash_defweak) && hash->root.root.u.def.section == section && hash->root.type == STT_FUNC) compute_function_info (input_bfd, hash, (hash)->root.root.u.def.value, contents); } } /* Cache or free any memory we allocated for the relocs. */ if (internal_relocs != NULL && elf_section_data (section)->relocs != internal_relocs) free (internal_relocs); internal_relocs = NULL; /* Cache or free any memory we allocated for the contents. */ if (contents != NULL && elf_section_data (section)->this_hdr.contents != contents) { if (! link_info->keep_memory) free (contents); else { /* Cache the section contents for elf_link_input_bfd. */ elf_section_data (section)->this_hdr.contents = contents; } } contents = NULL; } /* Cache or free any memory we allocated for the symbols. */ if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) { if (! link_info->keep_memory) free (isymbuf); else { /* Cache the symbols for elf_link_input_bfd. */ symtab_hdr->contents = (unsigned char *) isymbuf; } } isymbuf = NULL; } /* Now iterate on each symbol in the hash table and perform the final initialization steps on each. */ elf32_mn10300_link_hash_traverse (hash_table, elf32_mn10300_finish_hash_table_entry, link_info); elf32_mn10300_link_hash_traverse (hash_table->static_hash_table, elf32_mn10300_finish_hash_table_entry, link_info); { /* This section of code collects all our local symbols, sorts them by value, and looks for multiple symbols referring to the same address. For those symbols, the flags are merged. At this point, the only flag that can be set is MN10300_CONVERT_CALL_TO_CALLS, so we simply OR the flags together. */ int static_count = 0, i; struct elf32_mn10300_link_hash_entry **entries; struct elf32_mn10300_link_hash_entry **ptr; elf32_mn10300_link_hash_traverse (hash_table->static_hash_table, elf32_mn10300_count_hash_table_entries, &static_count); entries = bfd_malloc (static_count * sizeof (* ptr)); ptr = entries; elf32_mn10300_link_hash_traverse (hash_table->static_hash_table, elf32_mn10300_list_hash_table_entries, & ptr); qsort (entries, static_count, sizeof (entries[0]), sort_by_value); for (i = 0; i < static_count - 1; i++) if (entries[i]->value && entries[i]->value == entries[i+1]->value) { int v = entries[i]->flags; int j; for (j = i + 1; j < static_count && entries[j]->value == entries[i]->value; j++) v |= entries[j]->flags; for (j = i; j < static_count && entries[j]->value == entries[i]->value; j++) entries[j]->flags = v; i = j - 1; } } /* All entries in the hash table are fully initialized. */ hash_table->flags |= MN10300_HASH_ENTRIES_INITIALIZED; /* Now that everything has been initialized, go through each code section and delete any prologue insns which will be redundant because their operations will be performed by a "call" instruction. */ for (input_bfd = link_info->input_bfds; input_bfd != NULL; input_bfd = input_bfd->link.next) { /* We're going to need all the local symbols for each bfd. */ symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; if (symtab_hdr->sh_info != 0) { isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; if (isymbuf == NULL) isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL); if (isymbuf == NULL) goto error_return; } /* Walk over each section in this bfd. */ for (section = input_bfd->sections; section != NULL; section = section->next) { unsigned int sec_shndx; Elf_Internal_Sym *isym, *isymend; struct elf_link_hash_entry **hashes; struct elf_link_hash_entry **end_hashes; unsigned int symcount; /* Skip non-code sections and empty sections. */ if ((section->flags & SEC_CODE) == 0 || section->size == 0) continue; if (section->reloc_count != 0) { /* Get a copy of the native relocations. */ internal_relocs = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, link_info->keep_memory); if (internal_relocs == NULL) goto error_return; } /* Get cached copy of section contents if it exists. */ if (elf_section_data (section)->this_hdr.contents != NULL) contents = elf_section_data (section)->this_hdr.contents; else { /* Go get them off disk. */ if (!bfd_malloc_and_get_section (input_bfd, section, &contents)) goto error_return; } sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd, section); /* Now look for any function in this section which needs insns deleted from its prologue. */ isymend = isymbuf + symtab_hdr->sh_info; for (isym = isymbuf; isym < isymend; isym++) { struct elf32_mn10300_link_hash_entry *sym_hash; asection *sym_sec = NULL; const char *sym_name; char *new_name; struct elf_link_hash_table *elftab; bfd_size_type amt; if (isym->st_shndx != sec_shndx) continue; if (isym->st_shndx == SHN_UNDEF) sym_sec = bfd_und_section_ptr; else if (isym->st_shndx == SHN_ABS) sym_sec = bfd_abs_section_ptr; else if (isym->st_shndx == SHN_COMMON) sym_sec = bfd_com_section_ptr; else sym_sec = bfd_section_from_elf_index (input_bfd, isym->st_shndx); sym_name = bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link, isym->st_name); /* Tack on an ID so we can uniquely identify this local symbol in the global hash table. */ amt = strlen (sym_name) + 10; new_name = bfd_malloc (amt); if (new_name == NULL) goto error_return; sprintf (new_name, "%s_%08x", sym_name, sym_sec->id); sym_name = new_name; elftab = & hash_table->static_hash_table->root; sym_hash = (struct elf32_mn10300_link_hash_entry *) elf_link_hash_lookup (elftab, sym_name, FALSE, FALSE, FALSE); free (new_name); if (sym_hash == NULL) continue; if (! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS) && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES)) { int bytes = 0; /* Note that we've changed things. */ elf_section_data (section)->relocs = internal_relocs; elf_section_data (section)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Count how many bytes we're going to delete. */ if (sym_hash->movm_args) bytes += 2; if (sym_hash->stack_size > 0) { if (sym_hash->stack_size <= 128) bytes += 3; else bytes += 4; } /* Note that we've deleted prologue bytes for this function. */ sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES; /* Actually delete the bytes. */ if (!mn10300_elf_relax_delete_bytes (input_bfd, section, isym->st_value, bytes)) goto error_return; /* Something changed. Not strictly necessary, but may lead to more relaxing opportunities. */ *again = TRUE; } } /* Look for any global functions in this section which need insns deleted from their prologues. */ symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) - symtab_hdr->sh_info); hashes = elf_sym_hashes (input_bfd); end_hashes = hashes + symcount; for (; hashes < end_hashes; hashes++) { struct elf32_mn10300_link_hash_entry *sym_hash; sym_hash = (struct elf32_mn10300_link_hash_entry *) *hashes; if ((sym_hash->root.root.type == bfd_link_hash_defined || sym_hash->root.root.type == bfd_link_hash_defweak) && sym_hash->root.root.u.def.section == section && ! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS) && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES)) { int bytes = 0; bfd_vma symval; struct elf_link_hash_entry **hh; /* Note that we've changed things. */ elf_section_data (section)->relocs = internal_relocs; elf_section_data (section)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Count how many bytes we're going to delete. */ if (sym_hash->movm_args) bytes += 2; if (sym_hash->stack_size > 0) { if (sym_hash->stack_size <= 128) bytes += 3; else bytes += 4; } /* Note that we've deleted prologue bytes for this function. */ sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES; /* Actually delete the bytes. */ symval = sym_hash->root.root.u.def.value; if (!mn10300_elf_relax_delete_bytes (input_bfd, section, symval, bytes)) goto error_return; /* There may be other C++ functions symbols with the same address. If so then mark these as having had their prologue bytes deleted as well. */ for (hh = elf_sym_hashes (input_bfd); hh < end_hashes; hh++) { struct elf32_mn10300_link_hash_entry *h; h = (struct elf32_mn10300_link_hash_entry *) * hh; if (h != sym_hash && (h->root.root.type == bfd_link_hash_defined || h->root.root.type == bfd_link_hash_defweak) && h->root.root.u.def.section == section && ! (h->flags & MN10300_CONVERT_CALL_TO_CALLS) && h->root.root.u.def.value == symval && h->root.type == STT_FUNC) h->flags |= MN10300_DELETED_PROLOGUE_BYTES; } /* Something changed. Not strictly necessary, but may lead to more relaxing opportunities. */ *again = TRUE; } } /* Cache or free any memory we allocated for the relocs. */ if (internal_relocs != NULL && elf_section_data (section)->relocs != internal_relocs) free (internal_relocs); internal_relocs = NULL; /* Cache or free any memory we allocated for the contents. */ if (contents != NULL && elf_section_data (section)->this_hdr.contents != contents) { if (! link_info->keep_memory) free (contents); else /* Cache the section contents for elf_link_input_bfd. */ elf_section_data (section)->this_hdr.contents = contents; } contents = NULL; } /* Cache or free any memory we allocated for the symbols. */ if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) { if (! link_info->keep_memory) free (isymbuf); else /* Cache the symbols for elf_link_input_bfd. */ symtab_hdr->contents = (unsigned char *) isymbuf; } isymbuf = NULL; } } /* (Re)initialize for the basic instruction shortening/relaxing pass. */ contents = NULL; internal_relocs = NULL; isymbuf = NULL; /* For error_return. */ section = sec; /* We don't have to do anything for a relocatable link, if this section does not have relocs, or if this is not a code section. */ if (bfd_link_relocatable (link_info) || (sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0 || (sec->flags & SEC_CODE) == 0) return TRUE; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; /* Get a copy of the native relocations. */ internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory); if (internal_relocs == NULL) goto error_return; /* Scan for worst case alignment gap changes. Note that this logic is not ideal; what we should do is run this scan for every opcode/address range and adjust accordingly, but that's expensive. Worst case is that for an alignment of N bytes, we move by 2*N-N-1 bytes, assuming we have aligns of 1, 2, 4, 8, etc all before it. Plus, this still doesn't cover cross-section jumps with section alignment. */ irelend = internal_relocs + sec->reloc_count; align_gap_adjustment = 0; for (irel = internal_relocs; irel < irelend; irel++) { if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN) { bfd_vma adj = 1 << irel->r_addend; bfd_vma aend = irel->r_offset; aend = BFD_ALIGN (aend, 1 << irel->r_addend); adj = 2 * adj - adj - 1; /* Record the biggest adjustmnet. Skip any alignment at the end of our section. */ if (align_gap_adjustment < adj && aend < sec->output_section->vma + sec->output_offset + sec->size) align_gap_adjustment = adj; } } /* Walk through them looking for relaxing opportunities. */ irelend = internal_relocs + sec->reloc_count; for (irel = internal_relocs; irel < irelend; irel++) { bfd_vma symval; bfd_signed_vma jump_offset; asection *sym_sec = NULL; struct elf32_mn10300_link_hash_entry *h = NULL; /* If this isn't something that can be relaxed, then ignore this reloc. */ if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_NONE || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_8 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_MAX) continue; /* Get the section contents if we haven't done so already. */ if (contents == NULL) { /* Get cached copy if it exists. */ if (elf_section_data (sec)->this_hdr.contents != NULL) contents = elf_section_data (sec)->this_hdr.contents; else { /* Go get them off disk. */ if (!bfd_malloc_and_get_section (abfd, sec, &contents)) goto error_return; } } /* Read this BFD's symbols if we haven't done so already. */ if (isymbuf == NULL && symtab_hdr->sh_info != 0) { isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; if (isymbuf == NULL) isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL); if (isymbuf == NULL) goto error_return; } /* Get the value of the symbol referred to by the reloc. */ if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) { Elf_Internal_Sym *isym; const char *sym_name; char *new_name; /* A local symbol. */ isym = isymbuf + ELF32_R_SYM (irel->r_info); if (isym->st_shndx == SHN_UNDEF) sym_sec = bfd_und_section_ptr; else if (isym->st_shndx == SHN_ABS) sym_sec = bfd_abs_section_ptr; else if (isym->st_shndx == SHN_COMMON) sym_sec = bfd_com_section_ptr; else sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx); sym_name = bfd_elf_string_from_elf_section (abfd, symtab_hdr->sh_link, isym->st_name); if ((sym_sec->flags & SEC_MERGE) && sym_sec->sec_info_type == SEC_INFO_TYPE_MERGE) { symval = isym->st_value; /* GAS may reduce relocations against symbols in SEC_MERGE sections to a relocation against the section symbol when the original addend was zero. When the reloc is against a section symbol we should include the addend in the offset passed to _bfd_merged_section_offset, since the location of interest is the original symbol. On the other hand, an access to "sym+addend" where "sym" is not a section symbol should not include the addend; Such an access is presumed to be an offset from "sym"; The location of interest is just "sym". */ if (ELF_ST_TYPE (isym->st_info) == STT_SECTION) symval += irel->r_addend; symval = _bfd_merged_section_offset (abfd, & sym_sec, elf_section_data (sym_sec)->sec_info, symval); if (ELF_ST_TYPE (isym->st_info) != STT_SECTION) symval += irel->r_addend; symval += sym_sec->output_section->vma + sym_sec->output_offset - irel->r_addend; } else symval = (isym->st_value + sym_sec->output_section->vma + sym_sec->output_offset); /* Tack on an ID so we can uniquely identify this local symbol in the global hash table. */ new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10); if (new_name == NULL) goto error_return; sprintf (new_name, "%s_%08x", sym_name, sym_sec->id); sym_name = new_name; h = (struct elf32_mn10300_link_hash_entry *) elf_link_hash_lookup (&hash_table->static_hash_table->root, sym_name, FALSE, FALSE, FALSE); free (new_name); } else { unsigned long indx; /* An external symbol. */ indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; h = (struct elf32_mn10300_link_hash_entry *) (elf_sym_hashes (abfd)[indx]); BFD_ASSERT (h != NULL); if (h->root.root.type != bfd_link_hash_defined && h->root.root.type != bfd_link_hash_defweak) /* This appears to be a reference to an undefined symbol. Just ignore it--it will be caught by the regular reloc processing. */ continue; /* Check for a reference to a discarded symbol and ignore it. */ if (h->root.root.u.def.section->output_section == NULL) continue; sym_sec = h->root.root.u.def.section->output_section; symval = (h->root.root.u.def.value + h->root.root.u.def.section->output_section->vma + h->root.root.u.def.section->output_offset); } /* For simplicity of coding, we are going to modify the section contents, the section relocs, and the BFD symbol table. We must tell the rest of the code not to free up this information. It would be possible to instead create a table of changes which have to be made, as is done in coff-mips.c; that would be more work, but would require less memory when the linker is run. */ /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative branch/call, also deal with "call" -> "calls" conversions and insertion of prologue data into "call" instructions. */ if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL32 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32) { bfd_vma value = symval; if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32 && h != NULL && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN && h->root.plt.offset != (bfd_vma) -1) { asection * splt; splt = hash_table->root.splt; value = ((splt->output_section->vma + splt->output_offset + h->root.plt.offset) - (sec->output_section->vma + sec->output_offset + irel->r_offset)); } /* If we've got a "call" instruction that needs to be turned into a "calls" instruction, do so now. It saves a byte. */ if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS)) { unsigned char code; /* Get the opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 1); /* Make sure we're working with a "call" instruction! */ if (code == 0xdd) { /* Note that we've changed the relocs, section contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Fix the opcode. */ bfd_put_8 (abfd, 0xfc, contents + irel->r_offset - 1); bfd_put_8 (abfd, 0xff, contents + irel->r_offset); /* Fix irel->r_offset and irel->r_addend. */ irel->r_offset += 1; irel->r_addend += 1; /* Delete one byte of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 3, 1)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; } } else if (h) { /* We've got a "call" instruction which needs some data from target function filled in. */ unsigned char code; /* Get the opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 1); /* Insert data from the target function into the "call" instruction if needed. */ if (code == 0xdd) { bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 4); bfd_put_8 (abfd, h->stack_size + h->movm_stack_size, contents + irel->r_offset + 5); } } /* Deal with pc-relative gunk. */ value -= (sec->output_section->vma + sec->output_offset); value -= irel->r_offset; value += irel->r_addend; /* See if the value will fit in 16 bits, note the high value is 0x7fff + 2 as the target will be two bytes closer if we are able to relax, if it's in the same section. */ if (sec->output_section == sym_sec->output_section) jump_offset = 0x8001; else jump_offset = 0x7fff; /* Account for jumps across alignment boundaries using align_gap_adjustment. */ if ((bfd_signed_vma) value < jump_offset - (bfd_signed_vma) align_gap_adjustment && ((bfd_signed_vma) value > -0x8000 + (bfd_signed_vma) align_gap_adjustment)) { unsigned char code; /* Get the opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 1); if (code != 0xdc && code != 0xdd && code != 0xff) continue; /* Note that we've changed the relocs, section contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Fix the opcode. */ if (code == 0xdc) bfd_put_8 (abfd, 0xcc, contents + irel->r_offset - 1); else if (code == 0xdd) bfd_put_8 (abfd, 0xcd, contents + irel->r_offset - 1); else if (code == 0xff) bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32) ? R_MN10300_PLT16 : R_MN10300_PCREL16); /* Delete two bytes of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 1, 2)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; } } /* Try to turn a 16bit pc-relative branch into a 8bit pc-relative branch. */ if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL16) { bfd_vma value = symval; /* If we've got a "call" instruction that needs to be turned into a "calls" instruction, do so now. It saves a byte. */ if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS)) { unsigned char code; /* Get the opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 1); /* Make sure we're working with a "call" instruction! */ if (code == 0xcd) { /* Note that we've changed the relocs, section contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Fix the opcode. */ bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 1); bfd_put_8 (abfd, 0xff, contents + irel->r_offset); /* Fix irel->r_offset and irel->r_addend. */ irel->r_offset += 1; irel->r_addend += 1; /* Delete one byte of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 1, 1)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; } } else if (h) { unsigned char code; /* Get the opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 1); /* Insert data from the target function into the "call" instruction if needed. */ if (code == 0xcd) { bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 2); bfd_put_8 (abfd, h->stack_size + h->movm_stack_size, contents + irel->r_offset + 3); } } /* Deal with pc-relative gunk. */ value -= (sec->output_section->vma + sec->output_offset); value -= irel->r_offset; value += irel->r_addend; /* See if the value will fit in 8 bits, note the high value is 0x7f + 1 as the target will be one bytes closer if we are able to relax. */ if ((long) value < 0x80 && (long) value > -0x80) { unsigned char code; /* Get the opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 1); if (code != 0xcc) continue; /* Note that we've changed the relocs, section contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Fix the opcode. */ bfd_put_8 (abfd, 0xca, contents + irel->r_offset - 1); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_MN10300_PCREL8); /* Delete one byte of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 1, 1)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; } } /* Try to eliminate an unconditional 8 bit pc-relative branch which immediately follows a conditional 8 bit pc-relative branch around the unconditional branch. original: new: bCC lab1 bCC' lab2 bra lab2 lab1: lab1: This happens when the bCC can't reach lab2 at assembly time, but due to other relaxations it can reach at link time. */ if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL8) { Elf_Internal_Rela *nrel; bfd_vma value = symval; unsigned char code; /* Deal with pc-relative gunk. */ value -= (sec->output_section->vma + sec->output_offset); value -= irel->r_offset; value += irel->r_addend; /* Do nothing if this reloc is the last byte in the section. */ if (irel->r_offset == sec->size) continue; /* See if the next instruction is an unconditional pc-relative branch, more often than not this test will fail, so we test it first to speed things up. */ code = bfd_get_8 (abfd, contents + irel->r_offset + 1); if (code != 0xca) continue; /* Also make sure the next relocation applies to the next instruction and that it's a pc-relative 8 bit branch. */ nrel = irel + 1; if (nrel == irelend || irel->r_offset + 2 != nrel->r_offset || ELF32_R_TYPE (nrel->r_info) != (int) R_MN10300_PCREL8) continue; /* Make sure our destination immediately follows the unconditional branch. */ if (symval != (sec->output_section->vma + sec->output_offset + irel->r_offset + 3)) continue; /* Now make sure we are a conditional branch. This may not be necessary, but why take the chance. Note these checks assume that R_MN10300_PCREL8 relocs only occur on bCC and bCCx insns. If they occured elsewhere, we'd need to know the start of this insn for this check to be accurate. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 1); if (code != 0xc0 && code != 0xc1 && code != 0xc2 && code != 0xc3 && code != 0xc4 && code != 0xc5 && code != 0xc6 && code != 0xc7 && code != 0xc8 && code != 0xc9 && code != 0xe8 && code != 0xe9 && code != 0xea && code != 0xeb) continue; /* We also have to be sure there is no symbol/label at the unconditional branch. */ if (mn10300_elf_symbol_address_p (abfd, sec, isymbuf, irel->r_offset + 1)) continue; /* Note that we've changed the relocs, section contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Reverse the condition of the first branch. */ switch (code) { case 0xc8: code = 0xc9; break; case 0xc9: code = 0xc8; break; case 0xc0: code = 0xc2; break; case 0xc2: code = 0xc0; break; case 0xc3: code = 0xc1; break; case 0xc1: code = 0xc3; break; case 0xc4: code = 0xc6; break; case 0xc6: code = 0xc4; break; case 0xc7: code = 0xc5; break; case 0xc5: code = 0xc7; break; case 0xe8: code = 0xe9; break; case 0x9d: code = 0xe8; break; case 0xea: code = 0xeb; break; case 0xeb: code = 0xea; break; } bfd_put_8 (abfd, code, contents + irel->r_offset - 1); /* Set the reloc type and symbol for the first branch from the second branch. */ irel->r_info = nrel->r_info; /* Make the reloc for the second branch a null reloc. */ nrel->r_info = ELF32_R_INFO (ELF32_R_SYM (nrel->r_info), R_MN10300_NONE); /* Delete two bytes of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 1, 2)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; } /* Try to turn a 24 immediate, displacement or absolute address into a 8 immediate, displacement or absolute address. */ if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_24) { bfd_vma value = symval; value += irel->r_addend; /* See if the value will fit in 8 bits. */ if ((long) value < 0x7f && (long) value > -0x80) { unsigned char code; /* AM33 insns which have 24 operands are 6 bytes long and will have 0xfd as the first byte. */ /* Get the first opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 3); if (code == 0xfd) { /* Get the second opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 2); /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit equivalent instructions exists. */ if (code != 0x6b && code != 0x7b && code != 0x8b && code != 0x9b && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08 || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b || (code & 0x0f) == 0x0e)) { /* Not safe if the high bit is on as relaxing may move the value out of high mem and thus not fit in a signed 8bit value. This is currently over conservative. */ if ((value & 0x80) == 0) { /* Note that we've changed the relocation contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Fix the opcode. */ bfd_put_8 (abfd, 0xfb, contents + irel->r_offset - 3); bfd_put_8 (abfd, code, contents + irel->r_offset - 2); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_MN10300_8); /* Delete two bytes of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 1, 2)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; break; } } } } } /* Try to turn a 32bit immediate, displacement or absolute address into a 16bit immediate, displacement or absolute address. */ if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_32 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32) { bfd_vma value = symval; if (ELF32_R_TYPE (irel->r_info) != (int) R_MN10300_32) { asection * sgot; sgot = hash_table->root.sgot; if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32) { value = sgot->output_offset; if (h) value += h->root.got.offset; else value += (elf_local_got_offsets (abfd)[ELF32_R_SYM (irel->r_info)]); } else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32) value -= sgot->output_section->vma; else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32) value = (sgot->output_section->vma - (sec->output_section->vma + sec->output_offset + irel->r_offset)); else abort (); } value += irel->r_addend; /* See if the value will fit in 24 bits. We allow any 16bit match here. We prune those we can't handle below. */ if ((long) value < 0x7fffff && (long) value > -0x800000) { unsigned char code; /* AM33 insns which have 32bit operands are 7 bytes long and will have 0xfe as the first byte. */ /* Get the first opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 3); if (code == 0xfe) { /* Get the second opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 2); /* All the am33 32 -> 24 relaxing possibilities. */ /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit equivalent instructions exists. */ if (code != 0x6b && code != 0x7b && code != 0x8b && code != 0x9b && (ELF32_R_TYPE (irel->r_info) != (int) R_MN10300_GOTPC32) && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08 || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b || (code & 0x0f) == 0x0e)) { /* Not safe if the high bit is on as relaxing may move the value out of high mem and thus not fit in a signed 16bit value. This is currently over conservative. */ if ((value & 0x8000) == 0) { /* Note that we've changed the relocation contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Fix the opcode. */ bfd_put_8 (abfd, 0xfd, contents + irel->r_offset - 3); bfd_put_8 (abfd, code, contents + irel->r_offset - 2); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32) ? R_MN10300_GOTOFF24 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32) ? R_MN10300_GOT24 : R_MN10300_24); /* Delete one byte of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 3, 1)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; break; } } } } /* See if the value will fit in 16 bits. We allow any 16bit match here. We prune those we can't handle below. */ if ((long) value < 0x7fff && (long) value > -0x8000) { unsigned char code; /* Most insns which have 32bit operands are 6 bytes long; exceptions are pcrel insns and bit insns. We handle pcrel insns above. We don't bother trying to handle the bit insns here. The first byte of the remaining insns will be 0xfc. */ /* Get the first opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 2); if (code != 0xfc) continue; /* Get the second opcode. */ code = bfd_get_8 (abfd, contents + irel->r_offset - 1); if ((code & 0xf0) < 0x80) switch (code & 0xf0) { /* mov (d32,am),dn -> mov (d32,am),dn mov dm,(d32,am) -> mov dn,(d32,am) mov (d32,am),an -> mov (d32,am),an mov dm,(d32,am) -> mov dn,(d32,am) movbu (d32,am),dn -> movbu (d32,am),dn movbu dm,(d32,am) -> movbu dn,(d32,am) movhu (d32,am),dn -> movhu (d32,am),dn movhu dm,(d32,am) -> movhu dn,(d32,am) */ case 0x00: case 0x10: case 0x20: case 0x30: case 0x40: case 0x50: case 0x60: case 0x70: /* Not safe if the high bit is on as relaxing may move the value out of high mem and thus not fit in a signed 16bit value. */ if (code == 0xcc && (value & 0x8000)) continue; /* Note that we've changed the relocation contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Fix the opcode. */ bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2); bfd_put_8 (abfd, code, contents + irel->r_offset - 1); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32) ? R_MN10300_GOTOFF16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32) ? R_MN10300_GOT16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32) ? R_MN10300_GOTPC16 : R_MN10300_16); /* Delete two bytes of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 2, 2)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; break; } else if ((code & 0xf0) == 0x80 || (code & 0xf0) == 0x90) switch (code & 0xf3) { /* mov dn,(abs32) -> mov dn,(abs16) movbu dn,(abs32) -> movbu dn,(abs16) movhu dn,(abs32) -> movhu dn,(abs16) */ case 0x81: case 0x82: case 0x83: /* Note that we've changed the relocation contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; if ((code & 0xf3) == 0x81) code = 0x01 + (code & 0x0c); else if ((code & 0xf3) == 0x82) code = 0x02 + (code & 0x0c); else if ((code & 0xf3) == 0x83) code = 0x03 + (code & 0x0c); else abort (); /* Fix the opcode. */ bfd_put_8 (abfd, code, contents + irel->r_offset - 2); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32) ? R_MN10300_GOTOFF16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32) ? R_MN10300_GOT16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32) ? R_MN10300_GOTPC16 : R_MN10300_16); /* The opcode got shorter too, so we have to fix the addend and offset too! */ irel->r_offset -= 1; /* Delete three bytes of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 1, 3)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; break; /* mov am,(abs32) -> mov am,(abs16) mov am,(d32,sp) -> mov am,(d16,sp) mov dm,(d32,sp) -> mov dm,(d32,sp) movbu dm,(d32,sp) -> movbu dm,(d32,sp) movhu dm,(d32,sp) -> movhu dm,(d32,sp) */ case 0x80: case 0x90: case 0x91: case 0x92: case 0x93: /* sp-based offsets are zero-extended. */ if (code >= 0x90 && code <= 0x93 && (long) value < 0) continue; /* Note that we've changed the relocation contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Fix the opcode. */ bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2); bfd_put_8 (abfd, code, contents + irel->r_offset - 1); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32) ? R_MN10300_GOTOFF16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32) ? R_MN10300_GOT16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32) ? R_MN10300_GOTPC16 : R_MN10300_16); /* Delete two bytes of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 2, 2)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; break; } else if ((code & 0xf0) < 0xf0) switch (code & 0xfc) { /* mov imm32,dn -> mov imm16,dn mov imm32,an -> mov imm16,an mov (abs32),dn -> mov (abs16),dn movbu (abs32),dn -> movbu (abs16),dn movhu (abs32),dn -> movhu (abs16),dn */ case 0xcc: case 0xdc: case 0xa4: case 0xa8: case 0xac: /* Not safe if the high bit is on as relaxing may move the value out of high mem and thus not fit in a signed 16bit value. */ if (code == 0xcc && (value & 0x8000)) continue; /* "mov imm16, an" zero-extends the immediate. */ if ((code & 0xfc) == 0xdc && (long) value < 0) continue; /* Note that we've changed the relocation contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; if ((code & 0xfc) == 0xcc) code = 0x2c + (code & 0x03); else if ((code & 0xfc) == 0xdc) code = 0x24 + (code & 0x03); else if ((code & 0xfc) == 0xa4) code = 0x30 + (code & 0x03); else if ((code & 0xfc) == 0xa8) code = 0x34 + (code & 0x03); else if ((code & 0xfc) == 0xac) code = 0x38 + (code & 0x03); else abort (); /* Fix the opcode. */ bfd_put_8 (abfd, code, contents + irel->r_offset - 2); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32) ? R_MN10300_GOTOFF16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32) ? R_MN10300_GOT16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32) ? R_MN10300_GOTPC16 : R_MN10300_16); /* The opcode got shorter too, so we have to fix the addend and offset too! */ irel->r_offset -= 1; /* Delete three bytes of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 1, 3)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; break; /* mov (abs32),an -> mov (abs16),an mov (d32,sp),an -> mov (d16,sp),an mov (d32,sp),dn -> mov (d16,sp),dn movbu (d32,sp),dn -> movbu (d16,sp),dn movhu (d32,sp),dn -> movhu (d16,sp),dn add imm32,dn -> add imm16,dn cmp imm32,dn -> cmp imm16,dn add imm32,an -> add imm16,an cmp imm32,an -> cmp imm16,an and imm32,dn -> and imm16,dn or imm32,dn -> or imm16,dn xor imm32,dn -> xor imm16,dn btst imm32,dn -> btst imm16,dn */ case 0xa0: case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xc0: case 0xc8: case 0xd0: case 0xd8: case 0xe0: case 0xe1: case 0xe2: case 0xe3: /* cmp imm16, an zero-extends the immediate. */ if (code == 0xdc && (long) value < 0) continue; /* So do sp-based offsets. */ if (code >= 0xb0 && code <= 0xb3 && (long) value < 0) continue; /* Note that we've changed the relocation contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Fix the opcode. */ bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2); bfd_put_8 (abfd, code, contents + irel->r_offset - 1); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32) ? R_MN10300_GOTOFF16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32) ? R_MN10300_GOT16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32) ? R_MN10300_GOTPC16 : R_MN10300_16); /* Delete two bytes of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 2, 2)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; break; } else if (code == 0xfe) { /* add imm32,sp -> add imm16,sp */ /* Note that we've changed the relocation contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Fix the opcode. */ bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2); bfd_put_8 (abfd, 0xfe, contents + irel->r_offset - 1); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32) ? R_MN10300_GOT16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32) ? R_MN10300_GOTOFF16 : (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32) ? R_MN10300_GOTPC16 : R_MN10300_16); /* Delete two bytes of data. */ if (!mn10300_elf_relax_delete_bytes (abfd, sec, irel->r_offset + 2, 2)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; break; } } } } if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) { if (! link_info->keep_memory) free (isymbuf); else { /* Cache the symbols for elf_link_input_bfd. */ symtab_hdr->contents = (unsigned char *) isymbuf; } } if (contents != NULL && elf_section_data (sec)->this_hdr.contents != contents) { if (! link_info->keep_memory) free (contents); else { /* Cache the section contents for elf_link_input_bfd. */ elf_section_data (sec)->this_hdr.contents = contents; } } if (internal_relocs != NULL && elf_section_data (sec)->relocs != internal_relocs) free (internal_relocs); return TRUE; error_return: if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); if (contents != NULL && elf_section_data (section)->this_hdr.contents != contents) free (contents); if (internal_relocs != NULL && elf_section_data (section)->relocs != internal_relocs) free (internal_relocs); return FALSE; } /* This is a version of bfd_generic_get_relocated_section_contents which uses mn10300_elf_relocate_section. */ static bfd_byte * mn10300_elf_get_relocated_section_contents (bfd *output_bfd, struct bfd_link_info *link_info, struct bfd_link_order *link_order, bfd_byte *data, bfd_boolean relocatable, asymbol **symbols) { Elf_Internal_Shdr *symtab_hdr; asection *input_section = link_order->u.indirect.section; bfd *input_bfd = input_section->owner; asection **sections = NULL; Elf_Internal_Rela *internal_relocs = NULL; Elf_Internal_Sym *isymbuf = NULL; /* We only need to handle the case of relaxing, or of having a particular set of section contents, specially. */ if (relocatable || elf_section_data (input_section)->this_hdr.contents == NULL) return bfd_generic_get_relocated_section_contents (output_bfd, link_info, link_order, data, relocatable, symbols); symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; memcpy (data, elf_section_data (input_section)->this_hdr.contents, (size_t) input_section->size); if ((input_section->flags & SEC_RELOC) != 0 && input_section->reloc_count > 0) { asection **secpp; Elf_Internal_Sym *isym, *isymend; bfd_size_type amt; internal_relocs = _bfd_elf_link_read_relocs (input_bfd, input_section, NULL, NULL, FALSE); if (internal_relocs == NULL) goto error_return; if (symtab_hdr->sh_info != 0) { isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; if (isymbuf == NULL) isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL); if (isymbuf == NULL) goto error_return; } amt = symtab_hdr->sh_info; amt *= sizeof (asection *); sections = bfd_malloc (amt); if (sections == NULL && amt != 0) goto error_return; isymend = isymbuf + symtab_hdr->sh_info; for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp) { asection *isec; if (isym->st_shndx == SHN_UNDEF) isec = bfd_und_section_ptr; else if (isym->st_shndx == SHN_ABS) isec = bfd_abs_section_ptr; else if (isym->st_shndx == SHN_COMMON) isec = bfd_com_section_ptr; else isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx); *secpp = isec; } if (! mn10300_elf_relocate_section (output_bfd, link_info, input_bfd, input_section, data, internal_relocs, isymbuf, sections)) goto error_return; if (sections != NULL) free (sections); if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); if (internal_relocs != elf_section_data (input_section)->relocs) free (internal_relocs); } return data; error_return: if (sections != NULL) free (sections); if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); if (internal_relocs != NULL && internal_relocs != elf_section_data (input_section)->relocs) free (internal_relocs); return NULL; } /* Assorted hash table functions. */ /* Initialize an entry in the link hash table. */ /* Create an entry in an MN10300 ELF linker hash table. */ static struct bfd_hash_entry * elf32_mn10300_link_hash_newfunc (struct bfd_hash_entry *entry, struct bfd_hash_table *table, const char *string) { struct elf32_mn10300_link_hash_entry *ret = (struct elf32_mn10300_link_hash_entry *) entry; /* Allocate the structure if it has not already been allocated by a subclass. */ if (ret == NULL) ret = (struct elf32_mn10300_link_hash_entry *) bfd_hash_allocate (table, sizeof (* ret)); if (ret == NULL) return (struct bfd_hash_entry *) ret; /* Call the allocation method of the superclass. */ ret = (struct elf32_mn10300_link_hash_entry *) _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, table, string); if (ret != NULL) { ret->direct_calls = 0; ret->stack_size = 0; ret->movm_args = 0; ret->movm_stack_size = 0; ret->flags = 0; ret->value = 0; ret->tls_type = GOT_UNKNOWN; } return (struct bfd_hash_entry *) ret; } static void _bfd_mn10300_copy_indirect_symbol (struct bfd_link_info * info, struct elf_link_hash_entry * dir, struct elf_link_hash_entry * ind) { struct elf32_mn10300_link_hash_entry * edir; struct elf32_mn10300_link_hash_entry * eind; edir = elf_mn10300_hash_entry (dir); eind = elf_mn10300_hash_entry (ind); if (ind->root.type == bfd_link_hash_indirect && dir->got.refcount <= 0) { edir->tls_type = eind->tls_type; eind->tls_type = GOT_UNKNOWN; } edir->direct_calls = eind->direct_calls; edir->stack_size = eind->stack_size; edir->movm_args = eind->movm_args; edir->movm_stack_size = eind->movm_stack_size; edir->flags = eind->flags; _bfd_elf_link_hash_copy_indirect (info, dir, ind); } /* Destroy an mn10300 ELF linker hash table. */ static void elf32_mn10300_link_hash_table_free (bfd *obfd) { struct elf32_mn10300_link_hash_table *ret = (struct elf32_mn10300_link_hash_table *) obfd->link.hash; obfd->link.hash = &ret->static_hash_table->root.root; _bfd_elf_link_hash_table_free (obfd); obfd->is_linker_output = TRUE; obfd->link.hash = &ret->root.root; _bfd_elf_link_hash_table_free (obfd); } /* Create an mn10300 ELF linker hash table. */ static struct bfd_link_hash_table * elf32_mn10300_link_hash_table_create (bfd *abfd) { struct elf32_mn10300_link_hash_table *ret; bfd_size_type amt = sizeof (* ret); ret = bfd_zmalloc (amt); if (ret == NULL) return NULL; amt = sizeof (struct elf_link_hash_table); ret->static_hash_table = bfd_zmalloc (amt); if (ret->static_hash_table == NULL) { free (ret); return NULL; } if (!_bfd_elf_link_hash_table_init (&ret->static_hash_table->root, abfd, elf32_mn10300_link_hash_newfunc, sizeof (struct elf32_mn10300_link_hash_entry), MN10300_ELF_DATA)) { free (ret->static_hash_table); free (ret); return NULL; } abfd->is_linker_output = FALSE; abfd->link.hash = NULL; if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, elf32_mn10300_link_hash_newfunc, sizeof (struct elf32_mn10300_link_hash_entry), MN10300_ELF_DATA)) { abfd->is_linker_output = TRUE; abfd->link.hash = &ret->static_hash_table->root.root; _bfd_elf_link_hash_table_free (abfd); free (ret); return NULL; } ret->root.root.hash_table_free = elf32_mn10300_link_hash_table_free; ret->tls_ldm_got.offset = -1; return & ret->root.root; } static unsigned long elf_mn10300_mach (flagword flags) { switch (flags & EF_MN10300_MACH) { case E_MN10300_MACH_MN10300: default: return bfd_mach_mn10300; case E_MN10300_MACH_AM33: return bfd_mach_am33; case E_MN10300_MACH_AM33_2: return bfd_mach_am33_2; } } /* The final processing done just before writing out a MN10300 ELF object file. This gets the MN10300 architecture right based on the machine number. */ static void _bfd_mn10300_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) { unsigned long val; switch (bfd_get_mach (abfd)) { default: case bfd_mach_mn10300: val = E_MN10300_MACH_MN10300; break; case bfd_mach_am33: val = E_MN10300_MACH_AM33; break; case bfd_mach_am33_2: val = E_MN10300_MACH_AM33_2; break; } elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH); elf_elfheader (abfd)->e_flags |= val; } static bfd_boolean _bfd_mn10300_elf_object_p (bfd *abfd) { bfd_default_set_arch_mach (abfd, bfd_arch_mn10300, elf_mn10300_mach (elf_elfheader (abfd)->e_flags)); return TRUE; } /* Merge backend specific data from an object file to the output object file when linking. */ static bfd_boolean _bfd_mn10300_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) { if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour || bfd_get_flavour (obfd) != bfd_target_elf_flavour) return TRUE; if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) && bfd_get_mach (obfd) < bfd_get_mach (ibfd)) { if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd))) return FALSE; } return TRUE; } #define PLT0_ENTRY_SIZE 15 #define PLT_ENTRY_SIZE 20 #define PIC_PLT_ENTRY_SIZE 24 static const bfd_byte elf_mn10300_plt0_entry[PLT0_ENTRY_SIZE] = { 0xfc, 0xa0, 0, 0, 0, 0, /* mov (.got+8),a0 */ 0xfe, 0xe, 0x10, 0, 0, 0, 0, /* mov (.got+4),r1 */ 0xf0, 0xf4, /* jmp (a0) */ }; static const bfd_byte elf_mn10300_plt_entry[PLT_ENTRY_SIZE] = { 0xfc, 0xa0, 0, 0, 0, 0, /* mov (nameN@GOT + .got),a0 */ 0xf0, 0xf4, /* jmp (a0) */ 0xfe, 8, 0, 0, 0, 0, 0, /* mov reloc-table-address,r0 */ 0xdc, 0, 0, 0, 0, /* jmp .plt0 */ }; static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] = { 0xfc, 0x22, 0, 0, 0, 0, /* mov (nameN@GOT,a2),a0 */ 0xf0, 0xf4, /* jmp (a0) */ 0xfe, 8, 0, 0, 0, 0, 0, /* mov reloc-table-address,r0 */ 0xf8, 0x22, 8, /* mov (8,a2),a0 */ 0xfb, 0xa, 0x1a, 4, /* mov (4,a2),r1 */ 0xf0, 0xf4, /* jmp (a0) */ }; /* Return size of the first PLT entry. */ #define elf_mn10300_sizeof_plt0(info) \ (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE) /* Return size of a PLT entry. */ #define elf_mn10300_sizeof_plt(info) \ (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE) /* Return offset of the PLT0 address in an absolute PLT entry. */ #define elf_mn10300_plt_plt0_offset(info) 16 /* Return offset of the linker in PLT0 entry. */ #define elf_mn10300_plt0_linker_offset(info) 2 /* Return offset of the GOT id in PLT0 entry. */ #define elf_mn10300_plt0_gotid_offset(info) 9 /* Return offset of the temporary in PLT entry. */ #define elf_mn10300_plt_temp_offset(info) 8 /* Return offset of the symbol in PLT entry. */ #define elf_mn10300_plt_symbol_offset(info) 2 /* Return offset of the relocation in PLT entry. */ #define elf_mn10300_plt_reloc_offset(info) 11 /* The name of the dynamic interpreter. This is put in the .interp section. */ #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" /* Create dynamic sections when linking against a dynamic object. */ static bfd_boolean _bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) { flagword flags; asection * s; const struct elf_backend_data * bed = get_elf_backend_data (abfd); struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info); int ptralign = 0; switch (bed->s->arch_size) { case 32: ptralign = 2; break; case 64: ptralign = 3; break; default: bfd_set_error (bfd_error_bad_value); return FALSE; } /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and .rel[a].bss sections. */ flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); s = bfd_make_section_anyway_with_flags (abfd, (bed->default_use_rela_p ? ".rela.plt" : ".rel.plt"), flags | SEC_READONLY); htab->root.srelplt = s; if (s == NULL || ! bfd_set_section_alignment (abfd, s, ptralign)) return FALSE; if (! _bfd_mn10300_elf_create_got_section (abfd, info)) return FALSE; if (bed->want_dynbss) { /* The .dynbss section is a place to put symbols which are defined by dynamic objects, are referenced by regular objects, and are not functions. We must allocate space for them in the process image and use a R_*_COPY reloc to tell the dynamic linker to initialize them at run time. The linker script puts the .dynbss section into the .bss section of the final image. */ s = bfd_make_section_anyway_with_flags (abfd, ".dynbss", SEC_ALLOC | SEC_LINKER_CREATED); if (s == NULL) return FALSE; /* The .rel[a].bss section holds copy relocs. This section is not normally needed. We need to create it here, though, so that the linker will map it to an output section. We can't just create it only if we need it, because we will not know whether we need it until we have seen all the input files, and the first time the main linker code calls BFD after examining all the input files (size_dynamic_sections) the input sections have already been mapped to the output sections. If the section turns out not to be needed, we can discard it later. We will never need this section when generating a shared object, since they do not use copy relocs. */ if (! bfd_link_pic (info)) { s = bfd_make_section_anyway_with_flags (abfd, (bed->default_use_rela_p ? ".rela.bss" : ".rel.bss"), flags | SEC_READONLY); if (s == NULL || ! bfd_set_section_alignment (abfd, s, ptralign)) return FALSE; } } return TRUE; } /* Adjust a symbol defined by a dynamic object and referenced by a regular object. The current definition is in some section of the dynamic object, but we're not including those sections. We have to change the definition to something the rest of the link can understand. */ static bfd_boolean _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info, struct elf_link_hash_entry * h) { struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info); bfd * dynobj; asection * s; dynobj = htab->root.dynobj; /* Make sure we know what is going on here. */ BFD_ASSERT (dynobj != NULL && (h->needs_plt || h->u.weakdef != NULL || (h->def_dynamic && h->ref_regular && !h->def_regular))); /* If this is a function, put it in the procedure linkage table. We will fill in the contents of the procedure linkage table later, when we know the address of the .got section. */ if (h->type == STT_FUNC || h->needs_plt) { if (! bfd_link_pic (info) && !h->def_dynamic && !h->ref_dynamic) { /* This case can occur if we saw a PLT reloc in an input file, but the symbol was never referred to by a dynamic object. In such a case, we don't actually need to build a procedure linkage table, and we can just do a REL32 reloc instead. */ BFD_ASSERT (h->needs_plt); return TRUE; } /* Make sure this symbol is output as a dynamic symbol. */ if (h->dynindx == -1) { if (! bfd_elf_link_record_dynamic_symbol (info, h)) return FALSE; } s = htab->root.splt; BFD_ASSERT (s != NULL); /* If this is the first .plt entry, make room for the special first entry. */ if (s->size == 0) s->size += elf_mn10300_sizeof_plt0 (info); /* If this symbol is not defined in a regular file, and we are not generating a shared library, then set the symbol to this location in the .plt. This is required to make function pointers compare as equal between the normal executable and the shared library. */ if (! bfd_link_pic (info) && !h->def_regular) { h->root.u.def.section = s; h->root.u.def.value = s->size; } h->plt.offset = s->size; /* Make room for this entry. */ s->size += elf_mn10300_sizeof_plt (info); /* We also need to make an entry in the .got.plt section, which will be placed in the .got section by the linker script. */ s = htab->root.sgotplt; BFD_ASSERT (s != NULL); s->size += 4; /* We also need to make an entry in the .rela.plt section. */ s = bfd_get_linker_section (dynobj, ".rela.plt"); BFD_ASSERT (s != NULL); s->size += sizeof (Elf32_External_Rela); return TRUE; } /* If this is a weak symbol, and there is a real definition, the processor independent code will have arranged for us to see the real definition first, and we can just use the same value. */ if (h->u.weakdef != NULL) { BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined || h->u.weakdef->root.type == bfd_link_hash_defweak); h->root.u.def.section = h->u.weakdef->root.u.def.section; h->root.u.def.value = h->u.weakdef->root.u.def.value; return TRUE; } /* This is a reference to a symbol defined by a dynamic object which is not a function. */ /* If we are creating a shared library, we must presume that the only references to the symbol are via the global offset table. For such cases we need not do anything here; the relocations will be handled correctly by relocate_section. */ if (bfd_link_pic (info)) return TRUE; /* If there are no references to this symbol that do not use the GOT, we don't need to generate a copy reloc. */ if (!h->non_got_ref) return TRUE; /* We must allocate the symbol in our .dynbss section, which will become part of the .bss section of the executable. There will be an entry for this symbol in the .dynsym section. The dynamic object will contain position independent code, so all references from the dynamic object to this symbol will go through the global offset table. The dynamic linker will use the .dynsym entry to determine the address it must put in the global offset table, so both the dynamic object and the regular object will refer to the same memory location for the variable. */ s = bfd_get_linker_section (dynobj, ".dynbss"); BFD_ASSERT (s != NULL); /* We must generate a R_MN10300_COPY reloc to tell the dynamic linker to copy the initial value out of the dynamic object and into the runtime process image. We need to remember the offset into the .rela.bss section we are going to use. */ if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) { asection * srel; srel = bfd_get_linker_section (dynobj, ".rela.bss"); BFD_ASSERT (srel != NULL); srel->size += sizeof (Elf32_External_Rela); h->needs_copy = 1; } return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Set the sizes of the dynamic sections. */ static bfd_boolean _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info) { struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info); bfd * dynobj; asection * s; bfd_boolean plt; bfd_boolean relocs; bfd_boolean reltext; dynobj = htab->root.dynobj; BFD_ASSERT (dynobj != NULL); if (elf_hash_table (info)->dynamic_sections_created) { /* Set the contents of the .interp section to the interpreter. */ if (bfd_link_executable (info)) { s = bfd_get_linker_section (dynobj, ".interp"); BFD_ASSERT (s != NULL); s->size = sizeof ELF_DYNAMIC_INTERPRETER; s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; } } else { /* We may have created entries in the .rela.got section. However, if we are not creating the dynamic sections, we will not actually use these entries. Reset the size of .rela.got, which will cause it to get stripped from the output file below. */ s = htab->root.sgot; if (s != NULL) s->size = 0; } if (htab->tls_ldm_got.refcount > 0) { s = bfd_get_linker_section (dynobj, ".rela.got"); BFD_ASSERT (s != NULL); s->size += sizeof (Elf32_External_Rela); } /* The check_relocs and adjust_dynamic_symbol entry points have determined the sizes of the various dynamic sections. Allocate memory for them. */ plt = FALSE; relocs = FALSE; reltext = FALSE; for (s = dynobj->sections; s != NULL; s = s->next) { const char * name; if ((s->flags & SEC_LINKER_CREATED) == 0) continue; /* It's OK to base decisions on the section name, because none of the dynobj section names depend upon the input files. */ name = bfd_get_section_name (dynobj, s); if (streq (name, ".plt")) { /* Remember whether there is a PLT. */ plt = s->size != 0; } else if (CONST_STRNEQ (name, ".rela")) { if (s->size != 0) { asection * target; /* Remember whether there are any reloc sections other than .rela.plt. */ if (! streq (name, ".rela.plt")) { const char * outname; relocs = TRUE; /* If this relocation section applies to a read only section, then we probably need a DT_TEXTREL entry. The entries in the .rela.plt section really apply to the .got section, which we created ourselves and so know is not readonly. */ outname = bfd_get_section_name (output_bfd, s->output_section); target = bfd_get_section_by_name (output_bfd, outname + 5); if (target != NULL && (target->flags & SEC_READONLY) != 0 && (target->flags & SEC_ALLOC) != 0) reltext = TRUE; } /* We use the reloc_count field as a counter if we need to copy relocs into the output file. */ s->reloc_count = 0; } } else if (! CONST_STRNEQ (name, ".got") && ! streq (name, ".dynbss")) /* It's not one of our sections, so don't allocate space. */ continue; if (s->size == 0) { /* If we don't need this section, strip it from the output file. This is mostly to handle .rela.bss and .rela.plt. We must create both sections in create_dynamic_sections, because they must be created before the linker maps input sections to output sections. The linker does that before adjust_dynamic_symbol is called, and it is that function which decides whether anything needs to go into these sections. */ s->flags |= SEC_EXCLUDE; continue; } if ((s->flags & SEC_HAS_CONTENTS) == 0) continue; /* Allocate memory for the section contents. We use bfd_zalloc here in case unused entries are not reclaimed before the section's contents are written out. This should not happen, but this way if it does, we get a R_MN10300_NONE reloc instead of garbage. */ s->contents = bfd_zalloc (dynobj, s->size); if (s->contents == NULL) return FALSE; } if (elf_hash_table (info)->dynamic_sections_created) { /* Add some entries to the .dynamic section. We fill in the values later, in _bfd_mn10300_elf_finish_dynamic_sections, but we must add the entries now so that we get the correct size for the .dynamic section. The DT_DEBUG entry is filled in by the dynamic linker and used by the debugger. */ if (! bfd_link_pic (info)) { if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0)) return FALSE; } if (plt) { if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0) || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0) || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA) || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0)) return FALSE; } if (relocs) { if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0) || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0) || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT, sizeof (Elf32_External_Rela))) return FALSE; } if (reltext) { if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0)) return FALSE; } } return TRUE; } /* Finish up dynamic symbol handling. We set the contents of various dynamic sections here. */ static bfd_boolean _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info, struct elf_link_hash_entry * h, Elf_Internal_Sym * sym) { struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info); bfd * dynobj; dynobj = htab->root.dynobj; if (h->plt.offset != (bfd_vma) -1) { asection * splt; asection * sgot; asection * srel; bfd_vma plt_index; bfd_vma got_offset; Elf_Internal_Rela rel; /* This symbol has an entry in the procedure linkage table. Set it up. */ BFD_ASSERT (h->dynindx != -1); splt = htab->root.splt; sgot = htab->root.sgotplt; srel = bfd_get_linker_section (dynobj, ".rela.plt"); BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL); /* Get the index in the procedure linkage table which corresponds to this symbol. This is the index of this symbol in all the symbols for which we are making plt entries. The first entry in the procedure linkage table is reserved. */ plt_index = ((h->plt.offset - elf_mn10300_sizeof_plt0 (info)) / elf_mn10300_sizeof_plt (info)); /* Get the offset into the .got table of the entry that corresponds to this function. Each .got entry is 4 bytes. The first three are reserved. */ got_offset = (plt_index + 3) * 4; /* Fill in the entry in the procedure linkage table. */ if (! bfd_link_pic (info)) { memcpy (splt->contents + h->plt.offset, elf_mn10300_plt_entry, elf_mn10300_sizeof_plt (info)); bfd_put_32 (output_bfd, (sgot->output_section->vma + sgot->output_offset + got_offset), (splt->contents + h->plt.offset + elf_mn10300_plt_symbol_offset (info))); bfd_put_32 (output_bfd, (1 - h->plt.offset - elf_mn10300_plt_plt0_offset (info)), (splt->contents + h->plt.offset + elf_mn10300_plt_plt0_offset (info))); } else { memcpy (splt->contents + h->plt.offset, elf_mn10300_pic_plt_entry, elf_mn10300_sizeof_plt (info)); bfd_put_32 (output_bfd, got_offset, (splt->contents + h->plt.offset + elf_mn10300_plt_symbol_offset (info))); } bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), (splt->contents + h->plt.offset + elf_mn10300_plt_reloc_offset (info))); /* Fill in the entry in the global offset table. */ bfd_put_32 (output_bfd, (splt->output_section->vma + splt->output_offset + h->plt.offset + elf_mn10300_plt_temp_offset (info)), sgot->contents + got_offset); /* Fill in the entry in the .rela.plt section. */ rel.r_offset = (sgot->output_section->vma + sgot->output_offset + got_offset); rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_JMP_SLOT); rel.r_addend = 0; bfd_elf32_swap_reloca_out (output_bfd, &rel, (bfd_byte *) ((Elf32_External_Rela *) srel->contents + plt_index)); if (!h->def_regular) /* Mark the symbol as undefined, rather than as defined in the .plt section. Leave the value alone. */ sym->st_shndx = SHN_UNDEF; } if (h->got.offset != (bfd_vma) -1) { asection * sgot; asection * srel; Elf_Internal_Rela rel; /* This symbol has an entry in the global offset table. Set it up. */ sgot = htab->root.sgot; srel = bfd_get_linker_section (dynobj, ".rela.got"); BFD_ASSERT (sgot != NULL && srel != NULL); rel.r_offset = (sgot->output_section->vma + sgot->output_offset + (h->got.offset & ~1)); switch (elf_mn10300_hash_entry (h)->tls_type) { case GOT_TLS_GD: bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset + 4); rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_DTPMOD); rel.r_addend = 0; bfd_elf32_swap_reloca_out (output_bfd, & rel, (bfd_byte *) ((Elf32_External_Rela *) srel->contents + srel->reloc_count)); ++ srel->reloc_count; rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_DTPOFF); rel.r_offset += 4; rel.r_addend = 0; break; case GOT_TLS_IE: /* We originally stored the addend in the GOT, but at this point, we want to move it to the reloc instead as that's where the dynamic linker wants it. */ rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + h->got.offset); bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); if (h->dynindx == -1) rel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_TPOFF); else rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_TPOFF); break; default: /* If this is a -Bsymbolic link, and the symbol is defined locally, we just want to emit a RELATIVE reloc. Likewise if the symbol was forced to be local because of a version file. The entry in the global offset table will already have been initialized in the relocate_section function. */ if (bfd_link_pic (info) && (info->symbolic || h->dynindx == -1) && h->def_regular) { rel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE); rel.r_addend = (h->root.u.def.value + h->root.u.def.section->output_section->vma + h->root.u.def.section->output_offset); } else { bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_GLOB_DAT); rel.r_addend = 0; } } if (ELF32_R_TYPE (rel.r_info) != R_MN10300_NONE) { bfd_elf32_swap_reloca_out (output_bfd, &rel, (bfd_byte *) ((Elf32_External_Rela *) srel->contents + srel->reloc_count)); ++ srel->reloc_count; } } if (h->needs_copy) { asection * s; Elf_Internal_Rela rel; /* This symbol needs a copy reloc. Set it up. */ BFD_ASSERT (h->dynindx != -1 && (h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak)); s = bfd_get_linker_section (dynobj, ".rela.bss"); BFD_ASSERT (s != NULL); rel.r_offset = (h->root.u.def.value + h->root.u.def.section->output_section->vma + h->root.u.def.section->output_offset); rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_COPY); rel.r_addend = 0; bfd_elf32_swap_reloca_out (output_bfd, & rel, (bfd_byte *) ((Elf32_External_Rela *) s->contents + s->reloc_count)); ++ s->reloc_count; } /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ if (h == elf_hash_table (info)->hdynamic || h == elf_hash_table (info)->hgot) sym->st_shndx = SHN_ABS; return TRUE; } /* Finish up the dynamic sections. */ static bfd_boolean _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info) { bfd * dynobj; asection * sgot; asection * sdyn; struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info); dynobj = htab->root.dynobj; sgot = htab->root.sgotplt; BFD_ASSERT (sgot != NULL); sdyn = bfd_get_linker_section (dynobj, ".dynamic"); if (elf_hash_table (info)->dynamic_sections_created) { asection * splt; Elf32_External_Dyn * dyncon; Elf32_External_Dyn * dynconend; BFD_ASSERT (sdyn != NULL); dyncon = (Elf32_External_Dyn *) sdyn->contents; dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); for (; dyncon < dynconend; dyncon++) { Elf_Internal_Dyn dyn; const char * name; asection * s; bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); switch (dyn.d_tag) { default: break; case DT_PLTGOT: name = ".got"; goto get_vma; case DT_JMPREL: name = ".rela.plt"; get_vma: s = bfd_get_section_by_name (output_bfd, name); BFD_ASSERT (s != NULL); dyn.d_un.d_ptr = s->vma; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; case DT_PLTRELSZ: s = bfd_get_section_by_name (output_bfd, ".rela.plt"); BFD_ASSERT (s != NULL); dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; case DT_RELASZ: /* My reading of the SVR4 ABI indicates that the procedure linkage table relocs (DT_JMPREL) should be included in the overall relocs (DT_RELA). This is what Solaris does. However, UnixWare can not handle that case. Therefore, we override the DT_RELASZ entry here to make it not include the JMPREL relocs. Since the linker script arranges for .rela.plt to follow all other relocation sections, we don't have to worry about changing the DT_RELA entry. */ s = bfd_get_section_by_name (output_bfd, ".rela.plt"); if (s != NULL) dyn.d_un.d_val -= s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; } } /* Fill in the first entry in the procedure linkage table. */ splt = htab->root.splt; if (splt && splt->size > 0) { if (bfd_link_pic (info)) { memcpy (splt->contents, elf_mn10300_pic_plt_entry, elf_mn10300_sizeof_plt (info)); } else { memcpy (splt->contents, elf_mn10300_plt0_entry, PLT0_ENTRY_SIZE); bfd_put_32 (output_bfd, sgot->output_section->vma + sgot->output_offset + 4, splt->contents + elf_mn10300_plt0_gotid_offset (info)); bfd_put_32 (output_bfd, sgot->output_section->vma + sgot->output_offset + 8, splt->contents + elf_mn10300_plt0_linker_offset (info)); } /* UnixWare sets the entsize of .plt to 4, although that doesn't really seem like the right value. */ elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; /* UnixWare sets the entsize of .plt to 4, but this is incorrect as it means that the size of the PLT0 section (15 bytes) is not a multiple of the sh_entsize. Some ELF tools flag this as an error. We could pad PLT0 to 16 bytes, but that would introduce compatibilty issues with previous toolchains, so instead we just set the entry size to 1. */ elf_section_data (splt->output_section)->this_hdr.sh_entsize = 1; } } /* Fill in the first three entries in the global offset table. */ if (sgot->size > 0) { if (sdyn == NULL) bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); else bfd_put_32 (output_bfd, sdyn->output_section->vma + sdyn->output_offset, sgot->contents); bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); } elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; return TRUE; } /* Classify relocation types, such that combreloc can sort them properly. */ static enum elf_reloc_type_class _bfd_mn10300_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, const asection *rel_sec ATTRIBUTE_UNUSED, const Elf_Internal_Rela *rela) { switch ((int) ELF32_R_TYPE (rela->r_info)) { case R_MN10300_RELATIVE: return reloc_class_relative; case R_MN10300_JMP_SLOT: return reloc_class_plt; case R_MN10300_COPY: return reloc_class_copy; default: return reloc_class_normal; } } /* Allocate space for an MN10300 extension to the bfd elf data structure. */ static bfd_boolean mn10300_elf_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct elf_mn10300_obj_tdata), MN10300_ELF_DATA); } #define bfd_elf32_mkobject mn10300_elf_mkobject #ifndef ELF_ARCH #define TARGET_LITTLE_SYM mn10300_elf32_vec #define TARGET_LITTLE_NAME "elf32-mn10300" #define ELF_ARCH bfd_arch_mn10300 #define ELF_TARGET_ID MN10300_ELF_DATA #define ELF_MACHINE_CODE EM_MN10300 #define ELF_MACHINE_ALT1 EM_CYGNUS_MN10300 #define ELF_MAXPAGESIZE 0x1000 #endif #define elf_info_to_howto mn10300_info_to_howto #define elf_info_to_howto_rel 0 #define elf_backend_can_gc_sections 1 #define elf_backend_rela_normal 1 #define elf_backend_check_relocs mn10300_elf_check_relocs #define elf_backend_gc_mark_hook mn10300_elf_gc_mark_hook #define elf_backend_relocate_section mn10300_elf_relocate_section #define bfd_elf32_bfd_relax_section mn10300_elf_relax_section #define bfd_elf32_bfd_get_relocated_section_contents \ mn10300_elf_get_relocated_section_contents #define bfd_elf32_bfd_link_hash_table_create \ elf32_mn10300_link_hash_table_create #ifndef elf_symbol_leading_char #define elf_symbol_leading_char '_' #endif /* So we can set bits in e_flags. */ #define elf_backend_final_write_processing \ _bfd_mn10300_elf_final_write_processing #define elf_backend_object_p _bfd_mn10300_elf_object_p #define bfd_elf32_bfd_merge_private_bfd_data \ _bfd_mn10300_elf_merge_private_bfd_data #define elf_backend_can_gc_sections 1 #define elf_backend_create_dynamic_sections \ _bfd_mn10300_elf_create_dynamic_sections #define elf_backend_adjust_dynamic_symbol \ _bfd_mn10300_elf_adjust_dynamic_symbol #define elf_backend_size_dynamic_sections \ _bfd_mn10300_elf_size_dynamic_sections #define elf_backend_omit_section_dynsym \ ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true) #define elf_backend_finish_dynamic_symbol \ _bfd_mn10300_elf_finish_dynamic_symbol #define elf_backend_finish_dynamic_sections \ _bfd_mn10300_elf_finish_dynamic_sections #define elf_backend_copy_indirect_symbol \ _bfd_mn10300_copy_indirect_symbol #define elf_backend_reloc_type_class \ _bfd_mn10300_elf_reloc_type_class #define elf_backend_want_got_plt 1 #define elf_backend_plt_readonly 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 #include "elf32-target.h"
rmbq/hjl-binutils
bfd/elf-m10300.c
C
gpl-2.0
170,151
///////////////////////////////////////////////////////////////////////////// // Name: src/msw/scrolbar.cpp // Purpose: wxScrollBar // Author: Julian Smart // Modified by: // Created: 04/01/98 // RCS-ID: $Id: scrolbar.cpp 39476 2006-05-30 13:43:18Z ABX $ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #if wxUSE_SCROLLBAR #include "wx/scrolbar.h" #ifndef WX_PRECOMP #include "wx/utils.h" #include "wx/settings.h" #endif #include "wx/msw/private.h" #if wxUSE_EXTENDED_RTTI WX_DEFINE_FLAGS( wxScrollBarStyle ) wxBEGIN_FLAGS( wxScrollBarStyle ) // new style border flags, we put them first to // use them for streaming out wxFLAGS_MEMBER(wxBORDER_SIMPLE) wxFLAGS_MEMBER(wxBORDER_SUNKEN) wxFLAGS_MEMBER(wxBORDER_DOUBLE) wxFLAGS_MEMBER(wxBORDER_RAISED) wxFLAGS_MEMBER(wxBORDER_STATIC) wxFLAGS_MEMBER(wxBORDER_NONE) // old style border flags wxFLAGS_MEMBER(wxSIMPLE_BORDER) wxFLAGS_MEMBER(wxSUNKEN_BORDER) wxFLAGS_MEMBER(wxDOUBLE_BORDER) wxFLAGS_MEMBER(wxRAISED_BORDER) wxFLAGS_MEMBER(wxSTATIC_BORDER) wxFLAGS_MEMBER(wxBORDER) // standard window styles wxFLAGS_MEMBER(wxTAB_TRAVERSAL) wxFLAGS_MEMBER(wxCLIP_CHILDREN) wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) wxFLAGS_MEMBER(wxWANTS_CHARS) wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) wxFLAGS_MEMBER(wxVSCROLL) wxFLAGS_MEMBER(wxHSCROLL) wxFLAGS_MEMBER(wxSB_HORIZONTAL) wxFLAGS_MEMBER(wxSB_VERTICAL) wxEND_FLAGS( wxScrollBarStyle ) IMPLEMENT_DYNAMIC_CLASS_XTI(wxScrollBar, wxControl,"wx/scrolbar.h") wxBEGIN_PROPERTIES_TABLE(wxScrollBar) wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_CHANGED , wxScrollEvent ) wxPROPERTY( ThumbPosition , int , SetThumbPosition, GetThumbPosition, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) wxPROPERTY( Range , int , SetRange, GetRange, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) wxPROPERTY( ThumbSize , int , SetThumbSize, GetThumbSize, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) wxPROPERTY( PageSize , int , SetPageSize, GetPageSize, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) wxPROPERTY_FLAGS( WindowStyle , wxScrollBarStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style wxEND_PROPERTIES_TABLE() wxBEGIN_HANDLERS_TABLE(wxScrollBar) wxEND_HANDLERS_TABLE() wxCONSTRUCTOR_5( wxScrollBar , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) #else IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) #endif // Scrollbar bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { if ( !CreateControl(parent, id, pos, size, style, validator, name) ) return false; if (!MSWCreateControl(wxT("ScrollBar"), wxEmptyString, pos, size)) return false; SetScrollbar(0, 1, 2, 1, false); return true; } wxScrollBar::~wxScrollBar(void) { } bool wxScrollBar::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, WXWORD pos, WXHWND WXUNUSED(control)) { // current and max positions int position, maxPos, trackPos = pos; wxUnusedVar(trackPos); // when we're dragging the scrollbar we can't use pos parameter because it // is limited to 16 bits // JACS: now always using GetScrollInfo, since there's no reason // not to // if ( wParam == SB_THUMBPOSITION || wParam == SB_THUMBTRACK ) { SCROLLINFO scrollInfo; wxZeroMemory(scrollInfo); scrollInfo.cbSize = sizeof(SCROLLINFO); // also get the range if we call GetScrollInfo() anyhow -- this is less // expensive than call it once here and then call GetScrollRange() // below scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_TRACKPOS; if ( !::GetScrollInfo(GetHwnd(), SB_CTL, &scrollInfo) ) { wxLogLastError(_T("GetScrollInfo")); } trackPos = scrollInfo.nTrackPos; position = scrollInfo.nPos; maxPos = scrollInfo.nMax; } #if 0 else { position = ::GetScrollPos((HWND) control, SB_CTL); int minPos; ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos); } #endif // A page size greater than one has the effect of reducing the effective // range, therefore the range has already been boosted artificially - so // reduce it again. if ( m_pageSize > 1 ) maxPos -= (m_pageSize - 1); wxEventType scrollEvent = wxEVT_NULL; int nScrollInc; switch ( wParam ) { case SB_TOP: nScrollInc = maxPos - position; scrollEvent = wxEVT_SCROLL_TOP; break; case SB_BOTTOM: nScrollInc = -position; scrollEvent = wxEVT_SCROLL_BOTTOM; break; case SB_LINEUP: nScrollInc = -1; scrollEvent = wxEVT_SCROLL_LINEUP; break; case SB_LINEDOWN: nScrollInc = 1; scrollEvent = wxEVT_SCROLL_LINEDOWN; break; case SB_PAGEUP: nScrollInc = -GetPageSize(); scrollEvent = wxEVT_SCROLL_PAGEUP; break; case SB_PAGEDOWN: nScrollInc = GetPageSize(); scrollEvent = wxEVT_SCROLL_PAGEDOWN; break; case SB_THUMBPOSITION: nScrollInc = trackPos - position; scrollEvent = wxEVT_SCROLL_THUMBRELEASE; break; case SB_THUMBTRACK: nScrollInc = trackPos - position; scrollEvent = wxEVT_SCROLL_THUMBTRACK; break; case SB_ENDSCROLL: nScrollInc = 0; scrollEvent = wxEVT_SCROLL_CHANGED; break; default: nScrollInc = 0; } if ( nScrollInc ) { position += nScrollInc; if ( position < 0 ) position = 0; if ( position > maxPos ) position = maxPos; SetThumbPosition(position); } else if ( scrollEvent != wxEVT_SCROLL_THUMBRELEASE && scrollEvent != wxEVT_SCROLL_CHANGED ) { // don't process the event if there is no displacement, // unless this is a thumb release or end scroll event. return false; } wxScrollEvent event(scrollEvent, m_windowId); event.SetOrientation(IsVertical() ? wxVERTICAL : wxHORIZONTAL); event.SetPosition(position); event.SetEventObject( this ); return GetEventHandler()->ProcessEvent(event); } void wxScrollBar::SetThumbPosition(int viewStart) { SCROLLINFO info; info.cbSize = sizeof(SCROLLINFO); info.nPage = 0; info.nMin = 0; info.nPos = viewStart; info.fMask = SIF_POS ; ::SetScrollInfo((HWND) GetHWND(), SB_CTL, &info, TRUE); } int wxScrollBar::GetThumbPosition(void) const { SCROLLINFO scrollInfo; wxZeroMemory(scrollInfo); scrollInfo.cbSize = sizeof(SCROLLINFO); scrollInfo.fMask = SIF_POS; if ( !::GetScrollInfo(GetHwnd(), SB_CTL, &scrollInfo) ) { wxLogLastError(_T("GetScrollInfo")); } return scrollInfo.nPos; // return ::GetScrollPos((HWND)m_hWnd, SB_CTL); } void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, bool refresh) { m_viewSize = pageSize; m_pageSize = thumbSize; m_objectSize = range; // The range (number of scroll steps) is the // object length minus the page size. int range1 = wxMax((m_objectSize - m_pageSize), 0) ; // Try to adjust the range to cope with page size > 1 // (see comment for SetPageLength) if ( m_pageSize > 1 ) { range1 += (m_pageSize - 1); } SCROLLINFO info; info.cbSize = sizeof(SCROLLINFO); info.nPage = m_pageSize; info.nMin = 0; info.nMax = range1; info.nPos = position; info.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; ::SetScrollInfo((HWND) GetHWND(), SB_CTL, &info, refresh); } void wxScrollBar::Command(wxCommandEvent& event) { SetThumbPosition(event.GetInt()); ProcessCommand(event); } wxSize wxScrollBar::DoGetBestSize() const { int w = 100; int h = 100; if ( IsVertical() ) { w = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); } else { h = wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); } wxSize best(w, h); CacheBestSize(best); return best; } WXDWORD wxScrollBar::MSWGetStyle(long style, WXDWORD *exstyle) const { // we never have an external border WXDWORD msStyle = wxControl::MSWGetStyle ( (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle ); // SBS_HORZ is 0 anyhow, but do mention it explicitly for clarity msStyle |= style & wxSB_HORIZONTAL ? SBS_HORZ : SBS_VERT; return msStyle; } WXHBRUSH wxScrollBar::MSWControlColor(WXHDC pDC, WXHWND hWnd) { // unless we have an explicitly set bg colour, use default (gradient under // XP) brush instead of GetBackgroundColour() one as the base class would // // note that fg colour isn't used for a scrollbar return UseBgCol() ? wxControl::MSWControlColor(pDC, hWnd) : NULL; } #endif // wxUSE_SCROLLBAR
Lord-Kamina/pcsx2
3rdparty/wxWidgets/src/msw/scrolbar.cpp
C++
gpl-2.0
9,691
require 'models/authorization/authorization_base' module Katello class EnvironmentAuthorizationAdminTest < AuthorizationTestBase def setup super User.current = User.find(users('admin').id) @env = @dev @org = @acme_corporation end def test_readable refute_empty KTEnvironment.readable end def test_promotable? assert @env.promotable_or_removable? end def test_promotable refute_empty KTEnvironment.promotable end def test_any_promotable? assert KTEnvironment.any_promotable? end end class EnvironmentAuthorizationNoPermsTest < AuthorizationTestBase def setup super User.current = User.find(users('restricted').id) @env = @dev @org = @acme_corporation end def test_readable assert_empty KTEnvironment.readable end def test_promotable? refute @env.promotable_or_removable? end def test_promotable assert_empty KTEnvironment.promotable end def test_any_promotable? refute KTEnvironment.any_promotable? end end class EnvironmentAuthorizationWithPermsTest < AuthorizationTestBase def setup super User.current = User.find(users('restricted').id) end def test_readables environment = katello_environments(:staging_path1) setup_current_user_with_permissions(:name => "view_lifecycle_environments", :search => "name=\"#{environment.name}\"") assert_equal([environment.id], KTEnvironment.readable.pluck(:id)) assert environment.readable? refute environment.prior.readable? end def test_promotables environment = katello_environments(:staging_path1) setup_current_user_with_permissions(:name => "promote_or_remove_content_views_to_environments", :search => "name=\"#{environment.name}\"") assert_equal([environment.id], KTEnvironment.promotable.pluck(:id)) assert environment.promotable_or_removable? refute environment.prior.promotable_or_removable? end end end
akofink/katello
test/models/authorization/lifecycle_environment_authorization_test.rb
Ruby
gpl-2.0
2,132
/* JCE Editor - 2.4.6 | 19 January 2015 | http://www.joomlacontenteditor.net | Copyright (C) 2006 - 2014 Ryan Demmer. All rights reserved | GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html */ var SearchReplaceDialog={settings:{},init:function(ed){var self=this,m=tinyMCEPopup.getWindowArg("mode");$.Plugin.init();$('button#next').button({icons:{primary:'ui-icon-arrowthick-1-e'}}).click(function(e){self.searchNext('none');e.preventDefault();});$('button#replaceBtn').button({icons:{primary:'ui-icon-transferthick-e-w'}}).click(function(e){self.searchNext('current');e.preventDefault();});$('button#replaceAllBtn').button({icons:{primary:'ui-icon-transferthick-e-w'}}).click(function(e){self.searchNext('all');e.preventDefault();});var index=$('a[href="#'+m+'_tab"]').parent().index();$('#tabs').on('tabsactivate',function(e,ui){var id=$(ui.newPanel).attr('id');self.switchMode(id.substring(0,id.indexOf('_')));}).tabs('option','active',index);this.switchMode(m);$('#'+m+'_panel_searchstring').val(tinyMCEPopup.getWindowArg("search_string"));$('#'+m+'_panel_searchstring').focus();},switchMode:function(m){var lm=this.lastMode;if(lm!=m){if(lm){$('#'+m+'_panel_searchstring').val($('#'+lm+'_panel_searchstring').val());$('#'+m+'_panel_backwardsu').prop('checked',$('#'+lm+'_panel_backwardsu').is(':checked'));$('#'+m+'_panel_backwardsd').prop('checked',$('#'+lm+'_panel_backwardsd').is(':checked'));$('#'+m+'_panel_casesensitivebox').prop('checked',$('#'+lm+'_panel_casesensitivebox').is(':checked'));} $("#replaceBtn, #replaceAllBtn").css('display',function(){if(m=='replace'){return'inline';} return'none';});this.lastMode=m;}},searchNext:function(a){var ed=tinyMCEPopup.editor,se=ed.selection,r=se.getRng(),m=this.lastMode,s,b,fl=0,w=ed.getWin(),wm=ed.windowManager,fo=0,ca,rs;if(tinymce.isIE11&&!window.find){return;} s=$('#'+m+'_panel_searchstring').val();b=$('#'+m+'_panel_backwardsu').is(':checked');ca=$('#'+m+'_panel_casesensitivebox').is(':checked');rs=$('#replace_panel_replacestring').val();if(tinymce.isIE){r=ed.getDoc().selection.createRange();} if(s=='') return;function fix(){r=se.getRng().cloneRange();ed.getDoc().execCommand('SelectAll',false,null);se.setRng(r);} function replace(){ed.selection.setContent(rs);} if(ca) fl=fl|4;switch(a){case'all':ed.execCommand('SelectAll');ed.selection.collapse(true);if(tinymce.isIE){ed.focus();r=ed.getDoc().selection.createRange();while(r.findText(s,b?-1:1,fl)){r.scrollIntoView();r.select();replace();fo=1;if(b){r.moveEnd("character",-(rs.length));}} tinyMCEPopup.storeSelection();}else{while(w.find(s,ca,b,false,false,false,false)){replace();fo=1;}} if(fo) tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.allreplaced','All occurrences of the search string were replaced.'));else tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.notfound','The search has been completed. The search string could not be found.'));return;case'current':if(!ed.selection.isCollapsed()) replace();break;} se.collapse(b);r=se.getRng();if(!s) return;if(tinymce.isIE){ed.focus();r=ed.getDoc().selection.createRange();if(r.findText(s,b?-1:1,fl)){r.scrollIntoView();r.select();}else tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.notfound','The search has been completed. The search string could not be found.'));tinyMCEPopup.storeSelection();}else{if(!w.find(s,ca,b,false,false,false,false)) tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.notfound','The search has been completed. The search string could not be found.'));else fix();}}};tinyMCEPopup.onInit.add(SearchReplaceDialog.init,SearchReplaceDialog);
jorgejarh/comite_olimpico
components/com_jce/editor/tiny_mce/plugins/searchreplace/js/searchreplace.js
JavaScript
gpl-2.0
3,564
/* * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. * * Previously licensed under the ISC license by Qualcomm Atheros, Inc. * * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ /* * Copyright (c) 2012, The Linux Foundation. All rights reserved. * * Previously licensed under the ISC license by Qualcomm Atheros, Inc. * * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ /**======================================================================== \file wlan_hdd_hostapd.c \brief WLAN Host Device Driver implementation Copyright 2008 (c) Qualcomm, Incorporated. All Rights Reserved. Qualcomm Confidential and Proprietary. ========================================================================*/ /**========================================================================= EDIT HISTORY FOR FILE This section contains comments describing changes made to the module. Notice that changes are listed in reverse chronological order. $Header:$ $DateTime: $ $Author: $ when who what, where, why -------- --- -------------------------------------------------------- 04/5/09 Shailender Created module. 06/03/10 js - Added support to hostapd driven deauth/disassoc/mic failure ==========================================================================*/ /*-------------------------------------------------------------------------- Include Files ------------------------------------------------------------------------*/ #include <linux/version.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/wireless.h> #include <linux/semaphore.h> #include <vos_api.h> #include <vos_sched.h> #include <linux/etherdevice.h> #include <wlan_hdd_includes.h> #include <qc_sap_ioctl.h> #include <wlan_hdd_hostapd.h> #include <sapApi.h> #include <sapInternal.h> #include <wlan_qct_tl.h> #include <wlan_hdd_softap_tx_rx.h> #include <wlan_hdd_main.h> #include <linux/netdevice.h> #include <linux/mmc/sdio_func.h> #include "wlan_nlink_common.h" #include "wlan_btc_svc.h" #include <bap_hdd_main.h> #include "wlan_hdd_p2p.h" #define IS_UP(_dev) \ (((_dev)->flags & (IFF_RUNNING|IFF_UP)) == (IFF_RUNNING|IFF_UP)) #define IS_UP_AUTO(_ic) \ (IS_UP((_ic)->ic_dev) && (_ic)->ic_roaming == IEEE80211_ROAMING_AUTO) #define WE_WLAN_VERSION 1 #define STATS_CONTEXT_MAGIC 0x53544154 #define WE_GET_STA_INFO_SIZE 30 /* WEXT limition: MAX allowed buf len for any * * IW_PRIV_TYPE_CHAR is 2Kbytes * */ #define WE_SAP_MAX_STA_INFO 0x7FF struct statsContext { struct completion completion; hdd_adapter_t *pAdapter; unsigned int magic; }; #define SAP_24GHZ_CH_COUNT (14) /*--------------------------------------------------------------------------- * Function definitions *-------------------------------------------------------------------------*/ /**--------------------------------------------------------------------------- \brief hdd_hostapd_open() - HDD Open function for hostapd interface This is called in response to ifconfig up \param - dev Pointer to net_device structure \return - 0 for success non-zero for failure --------------------------------------------------------------------------*/ int hdd_hostapd_open (struct net_device *dev) { ENTER(); //Turn ON carrier state netif_carrier_on(dev); //Enable all Tx queues netif_tx_start_all_queues(dev); EXIT(); return 0; } /**--------------------------------------------------------------------------- \brief hdd_hostapd_stop() - HDD stop function for hostapd interface This is called in response to ifconfig down \param - dev Pointer to net_device structure \return - 0 for success non-zero for failure --------------------------------------------------------------------------*/ int hdd_hostapd_stop (struct net_device *dev) { ENTER(); //Stop all tx queues netif_tx_disable(dev); //Turn OFF carrier state netif_carrier_off(dev); EXIT(); return 0; } /**--------------------------------------------------------------------------- \brief hdd_hostapd_uninit() - HDD uninit function This is called during the netdev unregister to uninitialize all data associated with the device \param - dev Pointer to net_device structure \return - void --------------------------------------------------------------------------*/ static void hdd_hostapd_uninit (struct net_device *dev) { hdd_adapter_t *pHostapdAdapter = netdev_priv(dev); ENTER(); if (pHostapdAdapter && pHostapdAdapter->pHddCtx) { hdd_deinit_adapter(pHostapdAdapter->pHddCtx, pHostapdAdapter); /* after uninit our adapter structure will no longer be valid */ pHostapdAdapter->dev = NULL; } EXIT(); } /**============================================================================ @brief hdd_hostapd_hard_start_xmit() - Function registered with the Linux OS for transmitting packets. There are 2 versions of this function. One that uses locked queue and other that uses lockless queues. Both have been retained to do some performance testing @param skb : [in] pointer to OS packet (sk_buff) @param dev : [in] pointer to Libra network device @return : NET_XMIT_DROP if packets are dropped : NET_XMIT_SUCCESS if packet is enqueued succesfully ===========================================================================*/ int hdd_hostapd_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) { return 0; } int hdd_hostapd_change_mtu(struct net_device *dev, int new_mtu) { return 0; } int hdd_hostapd_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); hdd_priv_data_t priv_data; tANI_U8 *command = NULL; int ret = 0; if (NULL == pAdapter) { VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s: HDD adapter context is Null", __func__); ret = -ENODEV; goto exit; } if ((!ifr) || (!ifr->ifr_data)) { ret = -EINVAL; goto exit; } if (copy_from_user(&priv_data, ifr->ifr_data, sizeof(hdd_priv_data_t))) { ret = -EFAULT; goto exit; } command = kmalloc(priv_data.total_len, GFP_KERNEL); if (!command) { VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s: failed to allocate memory\n", __func__); ret = -ENOMEM; goto exit; } if (copy_from_user(command, priv_data.buf, priv_data.total_len)) { ret = -EFAULT; goto exit; } if ((SIOCDEVPRIVATE + 1) == cmd) { VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "***HOSTAPD*** : Received %s cmd from Wi-Fi GUI***", command); if(strncmp(command, "P2P_SET_NOA", 11) == 0 ) { hdd_setP2pNoa(dev, command); } else if( strncmp(command, "P2P_SET_PS", 10) == 0 ) { hdd_setP2pOpps(dev, command); } /* command should be a string having format SET_SAP_CHANNEL_LIST <num of channels> <the channels seperated by spaces> */ if(strncmp(command, "SET_SAP_CHANNEL_LIST", 20) == 0) { VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, " Received Command to Set Preferred Channels for SAP in %s", __func__); ret = sapSetPreferredChannel(command); } } exit: if (command) { kfree(command); } return ret; } /**--------------------------------------------------------------------------- \brief hdd_hostapd_set_mac_address() - This function sets the user specified mac address using the command ifconfig wlanX hw ether <mac adress>. \param - dev - Pointer to the net device. - addr - Pointer to the sockaddr. \return - 0 for success, non zero for failure --------------------------------------------------------------------------*/ static int hdd_hostapd_set_mac_address(struct net_device *dev, void *addr) { struct sockaddr *psta_mac_addr = addr; ENTER(); memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN); EXIT(); return 0; } void hdd_hostapd_inactivity_timer_cb(v_PVOID_t usrDataForCallback) { struct net_device *dev = (struct net_device *)usrDataForCallback; v_BYTE_t we_custom_event[64]; union iwreq_data wrqu; #ifdef DISABLE_CONCURRENCY_AUTOSAVE VOS_STATUS vos_status; hdd_adapter_t *pHostapdAdapter; hdd_ap_ctx_t *pHddApCtx; #endif /*DISABLE_CONCURRENCY_AUTOSAVE */ /* event_name space-delimiter driver_module_name */ /* Format of the event is "AUTO-SHUT.indication" " " "module_name" */ char * autoShutEvent = "AUTO-SHUT.indication" " " KBUILD_MODNAME; int event_len = strlen(autoShutEvent) + 1; /* For the NULL at the end */ ENTER(); #ifdef DISABLE_CONCURRENCY_AUTOSAVE if (vos_concurrent_sessions_running()) { /* This timer routine is going to be called only when AP persona is up. If there are concurrent sessions running we do not want to shut down the Bss.Instead we run the timer again so that if Autosave is enabled next time and other session was down only then we bring down AP */ pHostapdAdapter = netdev_priv(dev); pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter); vos_status = vos_timer_start( &pHddApCtx->hdd_ap_inactivity_timer, (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->nAPAutoShutOff * 1000); if (!VOS_IS_STATUS_SUCCESS(vos_status)) { hddLog(LOGE, FL("Failed to init AP inactivity timer")); } EXIT(); return; } #endif /*DISABLE_CONCURRENCY_AUTOSAVE */ memset(&we_custom_event, '\0', sizeof(we_custom_event)); memcpy(&we_custom_event, autoShutEvent, event_len); memset(&wrqu, 0, sizeof(wrqu)); wrqu.data.length = event_len; hddLog(LOG1, FL("Shutting down AP interface due to inactivity")); wireless_send_event(dev, IWEVCUSTOM, &wrqu, (char *)we_custom_event); EXIT(); } VOS_STATUS hdd_change_mcc_go_beacon_interval(hdd_adapter_t *pHostapdAdapter) { v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext; ptSapContext pSapCtx = NULL; eHalStatus halStatus = eHAL_STATUS_FAILURE; v_PVOID_t hHal = NULL; VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "%s: UPDATE Beacon Params", __func__); if(VOS_STA_SAP_MODE == vos_get_conparam ( )){ pSapCtx = VOS_GET_SAP_CB(pVosContext); if ( NULL == pSapCtx ) { VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "%s: Invalid SAP pointer from pvosGCtx", __func__); return VOS_STATUS_E_FAULT; } hHal = VOS_GET_HAL_CB(pSapCtx->pvosGCtx); if ( NULL == hHal ){ VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "%s: Invalid HAL pointer from pvosGCtx", __func__); return VOS_STATUS_E_FAULT; } halStatus = sme_ChangeMCCBeaconInterval(hHal, pSapCtx->sessionId); if(halStatus == eHAL_STATUS_FAILURE ){ VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "%s: Failed to update Beacon Params", __func__); return VOS_STATUS_E_FAILURE; } } return VOS_STATUS_SUCCESS; } void hdd_clear_all_sta(hdd_adapter_t *pHostapdAdapter, v_PVOID_t usrDataForCallback) { v_U8_t staId = 0; struct net_device *dev; dev = (struct net_device *)usrDataForCallback; hddLog(LOGE, FL("Clearing all the STA entry....\n")); for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++) { if ( pHostapdAdapter->aStaInfo[staId].isUsed && ( staId != (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uBCStaId)) { //Disconnect all the stations hdd_softap_sta_disassoc(pHostapdAdapter, &pHostapdAdapter->aStaInfo[staId].macAddrSTA.bytes[0]); } } } static int hdd_stop_p2p_link(hdd_adapter_t *pHostapdAdapter,v_PVOID_t usrDataForCallback) { struct net_device *dev; VOS_STATUS status = VOS_STATUS_SUCCESS; dev = (struct net_device *)usrDataForCallback; ENTER(); if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags)) { if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss((WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext) ) ) { VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, FL("Deleting P2P link!!!!!!")); } clear_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags); } EXIT(); return (status == VOS_STATUS_SUCCESS) ? 0 : -EBUSY; } VOS_STATUS hdd_hostapd_SAPEventCB( tpSap_Event pSapEvent, v_PVOID_t usrDataForCallback) { hdd_adapter_t *pHostapdAdapter; hdd_ap_ctx_t *pHddApCtx; hdd_hostapd_state_t *pHostapdState; struct net_device *dev; eSapHddEvent sapEvent; union iwreq_data wrqu; v_BYTE_t *we_custom_event_generic = NULL; int we_event = 0; int i = 0; v_U8_t staId; VOS_STATUS vos_status; v_BOOL_t bWPSState; v_BOOL_t bApActive = FALSE; v_BOOL_t bAuthRequired = TRUE; tpSap_AssocMacAddr pAssocStasArray = NULL; char unknownSTAEvent[IW_CUSTOM_MAX+1]; char maxAssocExceededEvent[IW_CUSTOM_MAX+1]; v_BYTE_t we_custom_start_event[64]; char *startBssEvent; hdd_context_t *pHddCtx; hdd_scaninfo_t *pScanInfo = NULL; struct iw_michaelmicfailure msg; dev = (struct net_device *)usrDataForCallback; pHostapdAdapter = netdev_priv(dev); pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter); pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter); sapEvent = pSapEvent->sapHddEventCode; memset(&wrqu, '\0', sizeof(wrqu)); pHddCtx = (hdd_context_t*)(pHostapdAdapter->pHddCtx); switch(sapEvent) { case eSAP_START_BSS_EVENT : hddLog(LOG1, FL("BSS configured status = %s, channel = %lu, bc sta Id = %d\n"), pSapEvent->sapevt.sapStartBssCompleteEvent.status ? "eSAP_STATUS_FAILURE" : "eSAP_STATUS_SUCCESS", pSapEvent->sapevt.sapStartBssCompleteEvent.operatingChannel, pSapEvent->sapevt.sapStartBssCompleteEvent.staId); pHostapdState->vosStatus = pSapEvent->sapevt.sapStartBssCompleteEvent.status; vos_status = vos_event_set(&pHostapdState->vosEvent); if (!VOS_IS_STATUS_SUCCESS(vos_status) || pHostapdState->vosStatus) { VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, ("ERROR: startbss event failed!!\n")); goto stopbss; } else { pHddApCtx->uBCStaId = pSapEvent->sapevt.sapStartBssCompleteEvent.staId; //@@@ need wep logic here to set privacy bit hdd_softap_Register_BC_STA(pHostapdAdapter, pHddApCtx->uPrivacy); } if (0 != (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->nAPAutoShutOff) { // AP Inactivity timer init and start vos_status = vos_timer_init( &pHddApCtx->hdd_ap_inactivity_timer, VOS_TIMER_TYPE_SW, hdd_hostapd_inactivity_timer_cb, (v_PVOID_t)dev ); if (!VOS_IS_STATUS_SUCCESS(vos_status)) hddLog(LOGE, FL("Failed to init AP inactivity timer\n")); vos_status = vos_timer_start( &pHddApCtx->hdd_ap_inactivity_timer, (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->nAPAutoShutOff * 1000); if (!VOS_IS_STATUS_SUCCESS(vos_status)) hddLog(LOGE, FL("Failed to init AP inactivity timer\n")); } pHddApCtx->operatingChannel = pSapEvent->sapevt.sapStartBssCompleteEvent.operatingChannel; pHostapdState->bssState = BSS_START; // Send current operating channel of SoftAP to BTC-ES send_btc_nlink_msg(WLAN_BTC_SOFTAP_BSS_START, 0); //Check if there is any group key pending to set. if( pHddApCtx->groupKey.keyLength ) { if( VOS_STATUS_SUCCESS != WLANSAP_SetKeySta( (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext, &pHddApCtx->groupKey ) ) { VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s: WLANSAP_SetKeySta failed", __func__); } pHddApCtx->groupKey.keyLength = 0; } else if ( pHddApCtx->wepKey[0].keyLength ) { int i=0; for ( i = 0; i < CSR_MAX_NUM_KEY; i++ ) { if( VOS_STATUS_SUCCESS != WLANSAP_SetKeySta( (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext, &pHddApCtx->wepKey[i] ) ) { VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s: WLANSAP_SetKeySta failed idx %d", __func__, i); } pHddApCtx->wepKey[i].keyLength = 0; } } //Fill the params for sending IWEVCUSTOM Event with SOFTAP.enabled startBssEvent = "SOFTAP.enabled"; memset(&we_custom_start_event, '\0', sizeof(we_custom_start_event)); memcpy(&we_custom_start_event, startBssEvent, strlen(startBssEvent)); memset(&wrqu, 0, sizeof(wrqu)); wrqu.data.length = strlen(startBssEvent); we_event = IWEVCUSTOM; we_custom_event_generic = we_custom_start_event; hdd_dump_concurrency_info(pHddCtx); break; //Event will be sent after Switch-Case stmt case eSAP_STOP_BSS_EVENT: hddLog(LOG1, FL("BSS stop status = %s\n"),pSapEvent->sapevt.sapStopBssCompleteEvent.status ? "eSAP_STATUS_FAILURE" : "eSAP_STATUS_SUCCESS"); //Free up Channel List incase if it is set sapCleanupChannelList(); pHddApCtx->operatingChannel = 0; //Invalidate the channel info. goto stopbss; case eSAP_STA_SET_KEY_EVENT: //TODO: forward the message to hostapd once implementtation is done for now just print hddLog(LOG1, FL("SET Key: configured status = %s\n"),pSapEvent->sapevt.sapStationSetKeyCompleteEvent.status ? "eSAP_STATUS_FAILURE" : "eSAP_STATUS_SUCCESS"); return VOS_STATUS_SUCCESS; case eSAP_STA_DEL_KEY_EVENT: //TODO: forward the message to hostapd once implementtation is done for now just print hddLog(LOG1, FL("Event received %s\n"),"eSAP_STA_DEL_KEY_EVENT"); return VOS_STATUS_SUCCESS; case eSAP_STA_MIC_FAILURE_EVENT: { memset(&msg, '\0', sizeof(msg)); msg.src_addr.sa_family = ARPHRD_ETHER; memcpy(msg.src_addr.sa_data, &pSapEvent->sapevt.sapStationMICFailureEvent.staMac, sizeof(v_MACADDR_t)); hddLog(LOG1, "MIC MAC "MAC_ADDRESS_STR"\n", MAC_ADDR_ARRAY(msg.src_addr.sa_data)); if(pSapEvent->sapevt.sapStationMICFailureEvent.multicast == eSAP_TRUE) msg.flags = IW_MICFAILURE_GROUP; else msg.flags = IW_MICFAILURE_PAIRWISE; memset(&wrqu, 0, sizeof(wrqu)); wrqu.data.length = sizeof(msg); we_event = IWEVMICHAELMICFAILURE; we_custom_event_generic = (v_BYTE_t *)&msg; } /* inform mic failure to nl80211 */ cfg80211_michael_mic_failure(dev, pSapEvent->sapevt. sapStationMICFailureEvent.staMac.bytes, ((pSapEvent->sapevt.sapStationMICFailureEvent.multicast == eSAP_TRUE) ? NL80211_KEYTYPE_GROUP : NL80211_KEYTYPE_PAIRWISE), pSapEvent->sapevt.sapStationMICFailureEvent.keyId, pSapEvent->sapevt.sapStationMICFailureEvent.TSC, GFP_KERNEL); break; case eSAP_STA_ASSOC_EVENT: case eSAP_STA_REASSOC_EVENT: wrqu.addr.sa_family = ARPHRD_ETHER; memcpy(wrqu.addr.sa_data, &pSapEvent->sapevt.sapStationAssocReassocCompleteEvent.staMac, sizeof(v_MACADDR_t)); hddLog(LOG1, " associated "MAC_ADDRESS_STR"\n", MAC_ADDR_ARRAY(wrqu.addr.sa_data)); we_event = IWEVREGISTERED; WLANSAP_Get_WPS_State((WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext, &bWPSState); if ( (eCSR_ENCRYPT_TYPE_NONE == pHddApCtx->ucEncryptType) || ( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == pHddApCtx->ucEncryptType ) || ( eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == pHddApCtx->ucEncryptType ) ) { bAuthRequired = FALSE; } if (bAuthRequired || bWPSState == eANI_BOOLEAN_TRUE ) { hdd_softap_RegisterSTA( pHostapdAdapter, TRUE, pHddApCtx->uPrivacy, pSapEvent->sapevt.sapStationAssocReassocCompleteEvent.staId, 0, 0, (v_MACADDR_t *)wrqu.addr.sa_data, pSapEvent->sapevt.sapStationAssocReassocCompleteEvent.wmmEnabled); } else { hdd_softap_RegisterSTA( pHostapdAdapter, FALSE, pHddApCtx->uPrivacy, pSapEvent->sapevt.sapStationAssocReassocCompleteEvent.staId, 0, 0, (v_MACADDR_t *)wrqu.addr.sa_data, pSapEvent->sapevt.sapStationAssocReassocCompleteEvent.wmmEnabled); } // Stop AP inactivity timer if (pHddApCtx->hdd_ap_inactivity_timer.state == VOS_TIMER_STATE_RUNNING) { vos_status = vos_timer_stop(&pHddApCtx->hdd_ap_inactivity_timer); if (!VOS_IS_STATUS_SUCCESS(vos_status)) hddLog(LOGE, FL("Failed to start AP inactivity timer\n")); } #ifdef WLAN_OPEN_SOURCE if (wake_lock_active(&pHddCtx->sap_wake_lock)) { wake_unlock(&pHddCtx->sap_wake_lock); } wake_lock_timeout(&pHddCtx->sap_wake_lock, msecs_to_jiffies(HDD_SAP_WAKE_LOCK_DURATION)); #endif #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) { struct station_info staInfo; v_U16_t iesLen = pSapEvent->sapevt.sapStationAssocReassocCompleteEvent.iesLen; memset(&staInfo, 0, sizeof(staInfo)); if (iesLen <= MAX_ASSOC_IND_IE_LEN ) { staInfo.assoc_req_ies = (const u8 *)&pSapEvent->sapevt.sapStationAssocReassocCompleteEvent.ies[0]; staInfo.assoc_req_ies_len = iesLen; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,31)) staInfo.filled |= STATION_INFO_ASSOC_REQ_IES; #endif cfg80211_new_sta(dev, (const u8 *)&pSapEvent->sapevt.sapStationAssocReassocCompleteEvent.staMac.bytes[0], &staInfo, GFP_KERNEL); } else { hddLog(LOGE, FL(" Assoc Ie length is too long \n")); } } #endif pScanInfo = &pHddCtx->scan_info; // Lets do abort scan to ensure smooth authentication for client if ((pScanInfo != NULL) && pScanInfo->mScanPending) { hdd_abort_mac_scan(pHddCtx); } break; case eSAP_STA_DISASSOC_EVENT: memcpy(wrqu.addr.sa_data, &pSapEvent->sapevt.sapStationDisassocCompleteEvent.staMac, sizeof(v_MACADDR_t)); hddLog(LOG1, " disassociated "MAC_ADDRESS_STR"\n", MAC_ADDR_ARRAY(wrqu.addr.sa_data)); if (pSapEvent->sapevt.sapStationDisassocCompleteEvent.reason == eSAP_USR_INITATED_DISASSOC) hddLog(LOG1," User initiated disassociation"); else hddLog(LOG1," MAC initiated disassociation"); we_event = IWEVEXPIRED; vos_status = hdd_softap_GetStaId(pHostapdAdapter, &pSapEvent->sapevt.sapStationDisassocCompleteEvent.staMac, &staId); if (!VOS_IS_STATUS_SUCCESS(vos_status)) { VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, FL("ERROR: HDD Failed to find sta id!!")); return VOS_STATUS_E_FAILURE; } hdd_softap_DeregisterSTA(pHostapdAdapter, staId); if (0 != (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->nAPAutoShutOff) { spin_lock_bh( &pHostapdAdapter->staInfo_lock ); // Start AP inactivity timer if no stations associated with it for (i = 0; i < WLAN_MAX_STA_COUNT; i++) { if (pHostapdAdapter->aStaInfo[i].isUsed && i != (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uBCStaId) { bApActive = TRUE; break; } } spin_unlock_bh( &pHostapdAdapter->staInfo_lock ); if (bApActive == FALSE) { if (pHddApCtx->hdd_ap_inactivity_timer.state == VOS_TIMER_STATE_STOPPED) { vos_status = vos_timer_start(&pHddApCtx->hdd_ap_inactivity_timer, (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->nAPAutoShutOff * 1000); if (!VOS_IS_STATUS_SUCCESS(vos_status)) hddLog(LOGE, FL("Failed to init AP inactivity timer\n")); } else VOS_ASSERT(vos_timer_getCurrentState(&pHddApCtx->hdd_ap_inactivity_timer) == VOS_TIMER_STATE_STOPPED); } } #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) cfg80211_del_sta(dev, (const u8 *)&pSapEvent->sapevt.sapStationDisassocCompleteEvent.staMac.bytes[0], GFP_KERNEL); #endif //Update the beacon Interval if it is P2P GO hdd_change_mcc_go_beacon_interval(pHostapdAdapter); break; case eSAP_WPS_PBC_PROBE_REQ_EVENT: { static const char * message ="MLMEWPSPBCPROBEREQ.indication"; union iwreq_data wreq; down(&pHddApCtx->semWpsPBCOverlapInd); pHddApCtx->WPSPBCProbeReq.probeReqIELen = pSapEvent->sapevt.sapPBCProbeReqEvent.WPSPBCProbeReq.probeReqIELen; vos_mem_copy(pHddApCtx->WPSPBCProbeReq.probeReqIE, pSapEvent->sapevt.sapPBCProbeReqEvent.WPSPBCProbeReq.probeReqIE, pHddApCtx->WPSPBCProbeReq.probeReqIELen); vos_mem_copy(pHddApCtx->WPSPBCProbeReq.peerMacAddr, pSapEvent->sapevt.sapPBCProbeReqEvent.WPSPBCProbeReq.peerMacAddr, sizeof(v_MACADDR_t)); hddLog(LOG1, "WPS PBC probe req "MAC_ADDRESS_STR"\n", MAC_ADDR_ARRAY(pHddApCtx->WPSPBCProbeReq.peerMacAddr)); memset(&wreq, 0, sizeof(wreq)); wreq.data.length = strlen(message); // This is length of message wireless_send_event(dev, IWEVCUSTOM, &wreq, (char *)message); return VOS_STATUS_SUCCESS; } case eSAP_ASSOC_STA_CALLBACK_EVENT: pAssocStasArray = pSapEvent->sapevt.sapAssocStaListEvent.pAssocStas; if (pSapEvent->sapevt.sapAssocStaListEvent.noOfAssocSta != 0) { // List of associated stations for (i = 0; i < pSapEvent->sapevt.sapAssocStaListEvent.noOfAssocSta; i++) { hddLog(LOG1,"Associated Sta Num %d:assocId=%d, staId=%d, staMac="MAC_ADDRESS_STR, i+1, pAssocStasArray->assocId, pAssocStasArray->staId, MAC_ADDR_ARRAY(pAssocStasArray->staMac.bytes)); pAssocStasArray++; } } vos_mem_free(pSapEvent->sapevt.sapAssocStaListEvent.pAssocStas);// Release caller allocated memory here return VOS_STATUS_SUCCESS; case eSAP_INDICATE_MGMT_FRAME: hdd_indicateMgmtFrame( pHostapdAdapter, pSapEvent->sapevt.sapManagementFrameInfo.nFrameLength, pSapEvent->sapevt.sapManagementFrameInfo.pbFrames, pSapEvent->sapevt.sapManagementFrameInfo.frameType, pSapEvent->sapevt.sapManagementFrameInfo.rxChan, 0); return VOS_STATUS_SUCCESS; case eSAP_REMAIN_CHAN_READY: hdd_remainChanReadyHandler( pHostapdAdapter ); return VOS_STATUS_SUCCESS; case eSAP_SEND_ACTION_CNF: hdd_sendActionCnf( pHostapdAdapter, ( eSAP_STATUS_SUCCESS == pSapEvent->sapevt.sapActionCnf.actionSendSuccess ) ? TRUE : FALSE ); return VOS_STATUS_SUCCESS; case eSAP_UNKNOWN_STA_JOIN: snprintf(unknownSTAEvent, IW_CUSTOM_MAX, "JOIN_UNKNOWN_STA-%02x:%02x:%02x:%02x:%02x:%02x", pSapEvent->sapevt.sapUnknownSTAJoin.macaddr.bytes[0], pSapEvent->sapevt.sapUnknownSTAJoin.macaddr.bytes[1], pSapEvent->sapevt.sapUnknownSTAJoin.macaddr.bytes[2], pSapEvent->sapevt.sapUnknownSTAJoin.macaddr.bytes[3], pSapEvent->sapevt.sapUnknownSTAJoin.macaddr.bytes[4], pSapEvent->sapevt.sapUnknownSTAJoin.macaddr.bytes[5]); we_event = IWEVCUSTOM; /* Discovered a new node (AP mode). */ wrqu.data.pointer = unknownSTAEvent; wrqu.data.length = strlen(unknownSTAEvent); we_custom_event_generic = (v_BYTE_t *)unknownSTAEvent; hddLog(LOG1,"%s\n", unknownSTAEvent); break; case eSAP_MAX_ASSOC_EXCEEDED: snprintf(maxAssocExceededEvent, IW_CUSTOM_MAX, "Peer %02x:%02x:%02x:%02x:%02x:%02x denied" " assoc due to Maximum Mobile Hotspot connections reached. Please disconnect" " one or more devices to enable the new device connection", pSapEvent->sapevt.sapMaxAssocExceeded.macaddr.bytes[0], pSapEvent->sapevt.sapMaxAssocExceeded.macaddr.bytes[1], pSapEvent->sapevt.sapMaxAssocExceeded.macaddr.bytes[2], pSapEvent->sapevt.sapMaxAssocExceeded.macaddr.bytes[3], pSapEvent->sapevt.sapMaxAssocExceeded.macaddr.bytes[4], pSapEvent->sapevt.sapMaxAssocExceeded.macaddr.bytes[5]); we_event = IWEVCUSTOM; /* Discovered a new node (AP mode). */ wrqu.data.pointer = maxAssocExceededEvent; wrqu.data.length = strlen(maxAssocExceededEvent); we_custom_event_generic = (v_BYTE_t *)maxAssocExceededEvent; hddLog(LOG1,"%s\n", maxAssocExceededEvent); break; case eSAP_STA_ASSOC_IND: return VOS_STATUS_SUCCESS; case eSAP_DISCONNECT_ALL_P2P_CLIENT: hddLog(LOG1, FL(" Disconnecting all the P2P Clients....\n")); hdd_clear_all_sta(pHostapdAdapter, usrDataForCallback); return VOS_STATUS_SUCCESS; case eSAP_MAC_TRIG_STOP_BSS_EVENT : hdd_stop_p2p_link(pHostapdAdapter, usrDataForCallback); return VOS_STATUS_SUCCESS; default: hddLog(LOG1,"SAP message is not handled\n"); goto stopbss; return VOS_STATUS_SUCCESS; } wireless_send_event(dev, we_event, &wrqu, (char *)we_custom_event_generic); return VOS_STATUS_SUCCESS; stopbss : { v_BYTE_t we_custom_event[64]; char *stopBssEvent = "STOP-BSS.response";//17 int event_len = strlen(stopBssEvent); hddLog(LOG1, FL("BSS stop status = %s"), pSapEvent->sapevt.sapStopBssCompleteEvent.status ? "eSAP_STATUS_FAILURE" : "eSAP_STATUS_SUCCESS"); /* Change the BSS state now since, as we are shutting things down, * we don't want interfaces to become re-enabled */ pHostapdState->bssState = BSS_STOP; if (0 != (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->nAPAutoShutOff) { if (VOS_TIMER_STATE_RUNNING == pHddApCtx->hdd_ap_inactivity_timer.state) { vos_status = vos_timer_stop(&pHddApCtx->hdd_ap_inactivity_timer); if (!VOS_IS_STATUS_SUCCESS(vos_status)) hddLog(LOGE, FL("Failed to stop AP inactivity timer")); } vos_status = vos_timer_destroy(&pHddApCtx->hdd_ap_inactivity_timer); if (!VOS_IS_STATUS_SUCCESS(vos_status)) hddLog(LOGE, FL("Failed to Destroy AP inactivity timer")); } /* Stop the pkts from n/w stack as we are going to free all of * the TX WMM queues for all STAID's */ hdd_hostapd_stop(dev); /* reclaim all resources allocated to the BSS */ hdd_softap_stop_bss(pHostapdAdapter); /* once the event is set, structure dev/pHostapdAdapter should * not be touched since they are now subject to being deleted * by another thread */ if (eSAP_STOP_BSS_EVENT == sapEvent) vos_event_set(&pHostapdState->vosEvent); /* notify userspace that the BSS has stopped */ memset(&we_custom_event, '\0', sizeof(we_custom_event)); memcpy(&we_custom_event, stopBssEvent, event_len); memset(&wrqu, 0, sizeof(wrqu)); wrqu.data.length = event_len; we_event = IWEVCUSTOM; we_custom_event_generic = we_custom_event; wireless_send_event(dev, we_event, &wrqu, (char *)we_custom_event_generic); hdd_dump_concurrency_info(pHddCtx); } return VOS_STATUS_SUCCESS; } int hdd_softap_unpackIE( tHalHandle halHandle, eCsrEncryptionType *pEncryptType, eCsrEncryptionType *mcEncryptType, eCsrAuthType *pAuthType, u_int16_t gen_ie_len, u_int8_t *gen_ie ) { tDot11fIERSN dot11RSNIE; tDot11fIEWPA dot11WPAIE; tANI_U8 *pRsnIe; tANI_U16 RSNIeLen; if (NULL == halHandle) { hddLog(LOGE, FL("Error haHandle returned NULL\n")); return -EINVAL; } // Validity checks if ((gen_ie_len < VOS_MIN(DOT11F_IE_RSN_MIN_LEN, DOT11F_IE_WPA_MIN_LEN)) || (gen_ie_len > VOS_MAX(DOT11F_IE_RSN_MAX_LEN, DOT11F_IE_WPA_MAX_LEN)) ) return -EINVAL; // Type check if ( gen_ie[0] == DOT11F_EID_RSN) { // Validity checks if ((gen_ie_len < DOT11F_IE_RSN_MIN_LEN ) || (gen_ie_len > DOT11F_IE_RSN_MAX_LEN) ) { return VOS_STATUS_E_FAILURE; } // Skip past the EID byte and length byte pRsnIe = gen_ie + 2; RSNIeLen = gen_ie_len - 2; // Unpack the RSN IE memset(&dot11RSNIE, 0, sizeof(tDot11fIERSN)); dot11fUnpackIeRSN((tpAniSirGlobal) halHandle, pRsnIe, RSNIeLen, &dot11RSNIE); // Copy out the encryption and authentication types hddLog(LOG1, FL("%s: pairwise cipher suite count: %d\n"), __func__, dot11RSNIE.pwise_cipher_suite_count ); hddLog(LOG1, FL("%s: authentication suite count: %d\n"), __func__, dot11RSNIE.akm_suite_count); /*Here we have followed the apple base code, but probably I suspect we can do something different*/ //dot11RSNIE.akm_suite_count // Just translate the FIRST one *pAuthType = hdd_TranslateRSNToCsrAuthType(dot11RSNIE.akm_suites[0]); //dot11RSNIE.pwise_cipher_suite_count *pEncryptType = hdd_TranslateRSNToCsrEncryptionType(dot11RSNIE.pwise_cipher_suites[0]); //dot11RSNIE.gp_cipher_suite_count *mcEncryptType = hdd_TranslateRSNToCsrEncryptionType(dot11RSNIE.gp_cipher_suite); // Set the PMKSA ID Cache for this interface // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache } else if (gen_ie[0] == DOT11F_EID_WPA) { // Validity checks if ((gen_ie_len < DOT11F_IE_WPA_MIN_LEN ) || (gen_ie_len > DOT11F_IE_WPA_MAX_LEN)) { return VOS_STATUS_E_FAILURE; } // Skip past the EID byte and length byte - and four byte WiFi OUI pRsnIe = gen_ie + 2 + 4; RSNIeLen = gen_ie_len - (2 + 4); // Unpack the WPA IE memset(&dot11WPAIE, 0, sizeof(tDot11fIEWPA)); dot11fUnpackIeWPA((tpAniSirGlobal) halHandle, pRsnIe, RSNIeLen, &dot11WPAIE); // Copy out the encryption and authentication types hddLog(LOG1, FL("%s: WPA unicast cipher suite count: %d\n"), __func__, dot11WPAIE.unicast_cipher_count ); hddLog(LOG1, FL("%s: WPA authentication suite count: %d\n"), __func__, dot11WPAIE.auth_suite_count); //dot11WPAIE.auth_suite_count // Just translate the FIRST one *pAuthType = hdd_TranslateWPAToCsrAuthType(dot11WPAIE.auth_suites[0]); //dot11WPAIE.unicast_cipher_count *pEncryptType = hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.unicast_ciphers[0]); //dot11WPAIE.unicast_cipher_count *mcEncryptType = hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher); } else { hddLog(LOGW, FL("%s: gen_ie[0]: %d\n"), __func__, gen_ie[0]); return VOS_STATUS_E_FAILURE; } return VOS_STATUS_SUCCESS; } int static iw_softap_setparam(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter); int *value = (int *)extra; int sub_cmd = value[0]; int set_value = value[1]; eHalStatus status; int ret = 0; /* success */ v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext; switch(sub_cmd) { case QCSAP_PARAM_CLR_ACL: if ( VOS_STATUS_SUCCESS != WLANSAP_ClearACL( pVosContext )) { ret = -EIO; } break; case QCSAP_PARAM_ACL_MODE: if ((eSAP_ALLOW_ALL < (eSapMacAddrACL)set_value) || (eSAP_ACCEPT_UNLESS_DENIED > (eSapMacAddrACL)set_value)) { hddLog(LOGE, FL("Invalid ACL Mode value %d"), set_value); ret = -EINVAL; } else { WLANSAP_SetMode(pVosContext, set_value); } break; case QCSAP_PARAM_MAX_ASSOC: if (WNI_CFG_ASSOC_STA_LIMIT_STAMIN > set_value) { hddLog(LOGE, FL("Invalid setMaxAssoc value %d"), set_value); ret = -EINVAL; } else { if (WNI_CFG_ASSOC_STA_LIMIT_STAMAX < set_value) { hddLog(LOGW, FL("setMaxAssoc value %d higher than max allowed %d." "Setting it to max allowed and continuing"), set_value, WNI_CFG_ASSOC_STA_LIMIT_STAMAX); set_value = WNI_CFG_ASSOC_STA_LIMIT_STAMAX; } status = ccmCfgSetInt(hHal, WNI_CFG_ASSOC_STA_LIMIT, set_value, NULL, eANI_BOOLEAN_FALSE); if ( status != eHAL_STATUS_SUCCESS ) { hddLog(LOGE, FL("setMaxAssoc failure, status %d"), status); ret = -EIO; } } break; case QCSAP_PARAM_HIDE_SSID: { eHalStatus status = eHAL_STATUS_SUCCESS; status = sme_HideSSID(hHal, pHostapdAdapter->sessionId, set_value); if(eHAL_STATUS_SUCCESS != status) { hddLog(VOS_TRACE_LEVEL_ERROR, "%s: QCSAP_PARAM_HIDE_SSID failed", __func__); return status; } break; } default: hddLog(LOGE, FL("Invalid setparam command %d value %d"), sub_cmd, set_value); ret = -EINVAL; break; } return ret; } int static iw_softap_getparam(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter); int *value = (int *)extra; int sub_cmd = value[0]; eHalStatus status; int ret = 0; /* success */ v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext; switch (sub_cmd) { case QCSAP_PARAM_MAX_ASSOC: status = ccmCfgGetInt(hHal, WNI_CFG_ASSOC_STA_LIMIT, (tANI_U32 *)value); if (eHAL_STATUS_SUCCESS != status) { ret = -EIO; } break; case QCSAP_PARAM_CLR_ACL: if ( VOS_STATUS_SUCCESS != WLANSAP_ClearACL( pVosContext )) { ret = -EIO; } *value = 0; break; case QCSAP_PARAM_MODULE_DOWN_IND: { VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: sending WLAN_MODULE_DOWN_IND", __func__); send_btc_nlink_msg(WLAN_MODULE_DOWN_IND, 0); #ifdef WLAN_BTAMP_FEATURE VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: Take down AMP PAL", __func__); BSL_Deinit(vos_get_global_context(VOS_MODULE_ID_HDD, NULL)); #endif *value = 0; break; } case QCSAP_PARAM_GET_WLAN_DBG: { vos_trace_display(); *value = 0; break; } case QCSAP_PARAM_AUTO_CHANNEL: { *value = (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apAutoChannelSelection; break; } default: hddLog(LOGE, FL("Invalid getparam command %d"), sub_cmd); ret = -EINVAL; break; } return ret; } /* Usage: BLACK_LIST = 0 WHITE_LIST = 1 ADD MAC = 0 REMOVE MAC = 1 mac addr will be accepted as a 6 octet mac address with each octet inputted in hex for e.g. 00:0a:f5:11:22:33 will be represented as 0x00 0x0a 0xf5 0x11 0x22 0x33 while using this ioctl Syntax: iwpriv softap.0 modify_acl <6 octet mac addr> <list type> <cmd type> Examples: eg 1. to add a mac addr 00:0a:f5:89:89:90 to the black list iwpriv softap.0 modify_acl 0x00 0x0a 0xf5 0x89 0x89 0x90 0 0 eg 2. to delete a mac addr 00:0a:f5:89:89:90 from white list iwpriv softap.0 modify_acl 0x00 0x0a 0xf5 0x89 0x89 0x90 1 1 */ int iw_softap_modify_acl(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext; v_BYTE_t *value = (v_BYTE_t*)extra; v_U8_t pPeerStaMac[VOS_MAC_ADDR_SIZE]; int listType, cmd, i; int ret = 0; /* success */ ENTER(); for (i=0; i<VOS_MAC_ADDR_SIZE; i++) { pPeerStaMac[i] = *(value+i); } listType = (int)(*(value+i)); i++; cmd = (int)(*(value+i)); hddLog(LOG1, "%s: SAP Modify ACL arg0 %02x:%02x:%02x:%02x:%02x:%02x arg1 %d arg2 %d\n", __func__, pPeerStaMac[0], pPeerStaMac[1], pPeerStaMac[2], pPeerStaMac[3], pPeerStaMac[4], pPeerStaMac[5], listType, cmd); if (WLANSAP_ModifyACL(pVosContext, pPeerStaMac,(eSapACLType)listType,(eSapACLCmdType)cmd) != VOS_STATUS_SUCCESS) { hddLog(LOGE, FL("Modify ACL failed\n")); ret = -EIO; } EXIT(); return ret; } int static iw_softap_getchannel(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); int *value = (int *)extra; *value = (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->operatingChannel; return 0; } int static iw_softap_set_max_tx_power(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter); int *value = (int *)extra; int set_value; tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; if (NULL == value) return -ENOMEM; set_value = value[0]; if (eHAL_STATUS_SUCCESS != sme_SetMaxTxPower(hHal, bssid, selfMac, set_value)) { hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed", __func__); return -EIO; } return 0; } int static iw_display_data_path_snapshot(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { /* Function intitiating dumping states of * HDD(WMM Tx Queues) * TL State (with Per Client infor) * DXE Snapshot (Called at the end of TL Snapshot) */ hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); hddLog(LOGE, "%s: called for SAP",__func__); hdd_wmm_tx_snapshot(pHostapdAdapter); WLANTL_TLDebugMessage(VOS_TRUE); return 0; } int static iw_softap_set_tx_power(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext; tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter); int *value = (int *)extra; int set_value; ptSapContext pSapCtx = NULL; if (NULL == value) return -ENOMEM; pSapCtx = VOS_GET_SAP_CB(pVosContext); if (NULL == pSapCtx) { VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "%s: Invalid SAP pointer from pvosGCtx", __func__); return VOS_STATUS_E_FAULT; } set_value = value[0]; if (eHAL_STATUS_SUCCESS != sme_SetTxPower(hHal, pSapCtx->sessionId, set_value)) { hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting tx power failed", __func__); return -EIO; } return 0; } /**--------------------------------------------------------------------------- \brief iw_softap_set_trafficmonitor() - This function dynamically enable/disable traffic monitor functonality the command iwpriv wlanX setTrafficMon <value>. \param - dev - Pointer to the net device. - addr - Pointer to the sockaddr. \return - 0 for success, non zero for failure --------------------------------------------------------------------------*/ static int iw_softap_set_trafficmonitor(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); int *isSetTrafficMon = (int *)wrqu->data.pointer; hdd_context_t *pHddCtx; int status; if (NULL == pAdapter) { VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "%s: HDD adapter is Null", __func__); return -ENODEV; } pHddCtx = WLAN_HDD_GET_CTX(pAdapter); status = wlan_hdd_validate_context(pHddCtx); if (0 != status) { VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s: HDD context is not valid", __func__); return status; } hddLog(VOS_TRACE_LEVEL_INFO, "%s : ", __func__); if (NULL == isSetTrafficMon) { VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "%s: Invalid SAP pointer from extra", __func__); return -ENOMEM; } if (TRUE == *isSetTrafficMon) { pHddCtx->cfg_ini->enableTrafficMonitor= TRUE; if (VOS_STATUS_SUCCESS != hdd_start_trafficMonitor(pAdapter)) { VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_ERROR, "%s: failed to Start Traffic Monitor timer ", __func__ ); return -EIO; } } else if (FALSE == *isSetTrafficMon) { pHddCtx->cfg_ini->enableTrafficMonitor= FALSE; if (VOS_STATUS_SUCCESS != hdd_stop_trafficMonitor(pAdapter)) { VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_ERROR, "%s: failed to Stop Traffic Monitor timer ", __func__ ); return -EIO; } } return 0; } #define IS_BROADCAST_MAC(x) (((x[0] & x[1] & x[2] & x[3] & x[4] & x[5]) == 0xff) ? 1 : 0) int static iw_softap_getassoc_stamacaddr(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); unsigned char *pmaclist; hdd_station_info_t *pStaInfo = pHostapdAdapter->aStaInfo; int cnt = 0, len; pmaclist = wrqu->data.pointer + sizeof(unsigned long int); len = wrqu->data.length; spin_lock_bh( &pHostapdAdapter->staInfo_lock ); while((cnt < WLAN_MAX_STA_COUNT) && (len > (sizeof(v_MACADDR_t)+1))) { if (TRUE == pStaInfo[cnt].isUsed) { if(!IS_BROADCAST_MAC(pStaInfo[cnt].macAddrSTA.bytes)) { memcpy((void *)pmaclist, (void *)&(pStaInfo[cnt].macAddrSTA), sizeof(v_MACADDR_t)); pmaclist += sizeof(v_MACADDR_t); len -= sizeof(v_MACADDR_t); } } cnt++; } spin_unlock_bh( &pHostapdAdapter->staInfo_lock ); *pmaclist = '\0'; wrqu->data.length -= len; *(unsigned long int *)(wrqu->data.pointer) = wrqu->data.length; return 0; } /* Usage: mac addr will be accepted as a 6 octet mac address with each octet inputted in hex for e.g. 00:0a:f5:11:22:33 will be represented as 0x00 0x0a 0xf5 0x11 0x22 0x33 while using this ioctl Syntax: iwpriv softap.0 disassoc_sta <6 octet mac address> e.g. disassociate sta with mac addr 00:0a:f5:11:22:33 from softap iwpriv softap.0 disassoc_sta 0x00 0x0a 0xf5 0x11 0x22 0x33 */ int static iw_softap_disassoc_sta(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); v_U8_t *peerMacAddr; ENTER(); /* iwpriv tool or framework calls this ioctl with * data passed in extra (less than 16 octets); */ peerMacAddr = (v_U8_t *)(extra); hddLog(LOG1, "data %02x:%02x:%02x:%02x:%02x:%02x", peerMacAddr[0], peerMacAddr[1], peerMacAddr[2], peerMacAddr[3], peerMacAddr[4], peerMacAddr[5]); hdd_softap_sta_disassoc(pHostapdAdapter, peerMacAddr); EXIT(); return 0; } int static iw_softap_ap_stats(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); WLANTL_TRANSFER_STA_TYPE statBuffer; char *pstatbuf; int len = wrqu->data.length; pstatbuf = wrqu->data.pointer; WLANSAP_GetStatistics((WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext, &statBuffer, (v_BOOL_t)wrqu->data.flags); len = snprintf(pstatbuf, len, "RUF=%d RMF=%d RBF=%d " "RUB=%d RMB=%d RBB=%d " "TUF=%d TMF=%d TBF=%d " "TUB=%d TMB=%d TBB=%d", (int)statBuffer.rxUCFcnt, (int)statBuffer.rxMCFcnt, (int)statBuffer.rxBCFcnt, (int)statBuffer.rxUCBcnt, (int)statBuffer.rxMCBcnt, (int)statBuffer.rxBCBcnt, (int)statBuffer.txUCFcnt, (int)statBuffer.txMCFcnt, (int)statBuffer.txBCFcnt, (int)statBuffer.txUCBcnt, (int)statBuffer.txMCBcnt, (int)statBuffer.txBCBcnt ); wrqu->data.length -= len; return 0; } int static iw_softap_commit(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { VOS_STATUS vos_status = VOS_STATUS_SUCCESS; hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); hdd_hostapd_state_t *pHostapdState; v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext; tpWLAN_SAPEventCB pSapEventCallback; tsap_Config_t *pConfig; s_CommitConfig_t *pCommitConfig; struct qc_mac_acl_entry *acl_entry = NULL; v_SINT_t i = 0, num_mac = 0; v_U32_t status = 0; eCsrAuthType RSNAuthType; eCsrEncryptionType RSNEncryptType; eCsrEncryptionType mcRSNEncryptType; pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter); pCommitConfig = (s_CommitConfig_t *)extra; pConfig = kmalloc(sizeof(tsap_Config_t), GFP_KERNEL); if(NULL == pConfig) { hddLog(LOG1, "VOS unable to allocate memory\n"); return -ENOMEM; } pConfig->beacon_int = pCommitConfig->beacon_int; pConfig->channel = pCommitConfig->channel; /*Protection parameter to enable or disable*/ pConfig->protEnabled = (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled; pConfig->dtim_period = pCommitConfig->dtim_period; switch(pCommitConfig->hw_mode ) { case eQC_DOT11_MODE_11A: pConfig->SapHw_mode = eSAP_DOT11_MODE_11a; break; case eQC_DOT11_MODE_11B: pConfig->SapHw_mode = eSAP_DOT11_MODE_11b; break; case eQC_DOT11_MODE_11G: pConfig->SapHw_mode = eSAP_DOT11_MODE_11g; break; case eQC_DOT11_MODE_11N: pConfig->SapHw_mode = eSAP_DOT11_MODE_11n; break; case eQC_DOT11_MODE_11G_ONLY: pConfig->SapHw_mode = eSAP_DOT11_MODE_11g_ONLY; break; case eQC_DOT11_MODE_11N_ONLY: pConfig->SapHw_mode = eSAP_DOT11_MODE_11n_ONLY; break; default: pConfig->SapHw_mode = eSAP_DOT11_MODE_11n; break; } pConfig->ieee80211d = pCommitConfig->qcsap80211d; vos_mem_copy(pConfig->countryCode, pCommitConfig->countryCode, 3); if(pCommitConfig->authType == eQC_AUTH_TYPE_SHARED_KEY) pConfig->authType = eSAP_SHARED_KEY; else if(pCommitConfig->authType == eQC_AUTH_TYPE_OPEN_SYSTEM) pConfig->authType = eSAP_OPEN_SYSTEM; else pConfig->authType = eSAP_AUTO_SWITCH; pConfig->privacy = pCommitConfig->privacy; (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pCommitConfig->privacy; pConfig->wps_state = pCommitConfig->wps_state; pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up pConfig->RSNWPAReqIELength = pCommitConfig->RSNWPAReqIELength; if(pConfig->RSNWPAReqIELength){ pConfig->pRSNWPAReqIE = &pCommitConfig->RSNWPAReqIE[0]; if ((pConfig->pRSNWPAReqIE[0] == DOT11F_EID_RSN) || (pConfig->pRSNWPAReqIE[0] == DOT11F_EID_WPA)){ // The actual processing may eventually be more extensive than this. // Right now, just consume any PMKIDs that are sent in by the app. status = hdd_softap_unpackIE( vos_get_context( VOS_MODULE_ID_PE, pVosContext), &RSNEncryptType, &mcRSNEncryptType, &RSNAuthType, pConfig->pRSNWPAReqIE[1]+2, pConfig->pRSNWPAReqIE ); if( VOS_STATUS_SUCCESS == status ) { // Now copy over all the security attributes you have parsed out //TODO: Need to handle mixed mode pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE pConfig->mcRSNEncryptType = mcRSNEncryptType; hddLog( LOG1, FL("CSR AuthType = %d, EncryptionType = %d mcEncryptionType = %d\n"), RSNAuthType, RSNEncryptType, mcRSNEncryptType); } } } else { /* If no RSNIE, set encrypt type to NONE*/ pConfig->RSNEncryptType = eCSR_ENCRYPT_TYPE_NONE; pConfig->mcRSNEncryptType = eCSR_ENCRYPT_TYPE_NONE; hddLog( LOG1, FL("EncryptionType = %d mcEncryptionType = %d\n"), pConfig->RSNEncryptType, pConfig->mcRSNEncryptType); } if (pConfig->RSNWPAReqIELength > QCSAP_MAX_OPT_IE) { hddLog(LOGE, FL("RSNWPAReqIELength: %d too large"), pConfig->RSNWPAReqIELength); kfree(pConfig); return -EIO; } pConfig->SSIDinfo.ssidHidden = pCommitConfig->SSIDinfo.ssidHidden; pConfig->SSIDinfo.ssid.length = pCommitConfig->SSIDinfo.ssid.length; vos_mem_copy(pConfig->SSIDinfo.ssid.ssId, pCommitConfig->SSIDinfo.ssid.ssId, pConfig->SSIDinfo.ssid.length); vos_mem_copy(pConfig->self_macaddr.bytes, pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t)); pConfig->SapMacaddr_acl = pCommitConfig->qc_macaddr_acl; // ht_capab is not what the name conveys,this is used for protection bitmap pConfig->ht_capab = (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection; if (pCommitConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS) num_mac = pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS; else num_mac = pConfig->num_accept_mac = pCommitConfig->num_accept_mac; acl_entry = pCommitConfig->accept_mac; for (i = 0; i < num_mac; i++) { vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(v_MACADDR_t)); acl_entry++; } if (pCommitConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS) num_mac = pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS; else num_mac = pConfig->num_deny_mac = pCommitConfig->num_deny_mac; acl_entry = pCommitConfig->deny_mac; for (i = 0; i < num_mac; i++) { vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(v_MACADDR_t)); acl_entry++; } //Uapsd Enabled Bit pConfig->UapsdEnable = (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled; //Enable OBSS protection pConfig->obssProtEnabled = (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled; (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->apDisableIntraBssFwd = (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apDisableIntraBssFwd; hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR"\n"), MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes)); hddLog(LOGW,FL("ssid =%s\n"), pConfig->SSIDinfo.ssid.ssId); hddLog(LOGW,FL("beaconint=%d, channel=%d\n"), (int)pConfig->beacon_int, (int)pConfig->channel); hddLog(LOGW,FL("hw_mode=%x\n"), pConfig->SapHw_mode); hddLog(LOGW,FL("privacy=%d, authType=%d\n"), pConfig->privacy, pConfig->authType); hddLog(LOGW,FL("RSN/WPALen=%d, \n"),(int)pConfig->RSNWPAReqIELength); hddLog(LOGW,FL("Uapsd = %d\n"),pConfig->UapsdEnable); hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d\n"),pConfig->protEnabled, pConfig->obssProtEnabled); hddLog(LOGW,FL("DisableIntraBssFwd = %d\n"),(WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->apDisableIntraBssFwd); pSapEventCallback = hdd_hostapd_SAPEventCB; pConfig->persona = pHostapdAdapter->device_mode; if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,(v_PVOID_t)dev) != VOS_STATUS_SUCCESS) { hddLog(LOGE,FL("SAP Start Bss fail\n")); } kfree(pConfig); hddLog(LOG1, FL("Waiting for Scan to complete(auto mode) and BSS to start")); vos_status = vos_wait_single_event(&pHostapdState->vosEvent, 10000); if (!VOS_IS_STATUS_SUCCESS(vos_status)) { VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, ("ERROR: HDD vos wait for single_event failed!!\n")); VOS_ASSERT(0); } pHostapdState->bCommit = TRUE; if(pHostapdState->vosStatus) { return -EIO; } else { set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags); WLANSAP_Update_WpsIe ( pVosContext ); return 0; } } static int iw_softap_setmlme(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { struct sQcSapreq_mlme *pmlme; hdd_adapter_t *pHostapdAdapter = (hdd_adapter_t*)(netdev_priv(dev)); v_MACADDR_t destAddress; pmlme = (struct sQcSapreq_mlme *)(wrqu->name); /* NOTE: this address is not valid incase of TKIP failure, since not filled */ vos_mem_copy(&destAddress.bytes, pmlme->im_macaddr, sizeof(v_MACADDR_t)); switch(pmlme->im_op) { case QCSAP_MLME_AUTHORIZE: hdd_softap_change_STA_state( pHostapdAdapter, &destAddress, WLANTL_STA_AUTHENTICATED); break; case QCSAP_MLME_ASSOC: //TODO:inform to TL after associating (not needed as we do in sapCallback) break; case QCSAP_MLME_UNAUTHORIZE: //TODO: send the disassoc to station //hdd_softap_change_STA_state( pHostapdAdapter, pmlme->im_macaddr, WLANTL_STA_AUTHENTICATED); break; case QCSAP_MLME_DISASSOC: hdd_softap_sta_disassoc(pHostapdAdapter,pmlme->im_macaddr); break; case QCSAP_MLME_DEAUTH: hdd_softap_sta_deauth(pHostapdAdapter,pmlme->im_macaddr); break; case QCSAP_MLME_MICFAILURE: hdd_softap_tkip_mic_fail_counter_measure(pHostapdAdapter,pmlme->im_reason); break; default: break; } return 0; } static int iw_softap_set_channel_range(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter); hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter); int *value = (int *)extra; int startChannel = value[0]; int endChannel = value[1]; int band = value[2]; VOS_STATUS status; int ret = 0; /* success */ status = WLANSAP_SetChannelRange(hHal,startChannel,endChannel,band); if(status != VOS_STATUS_SUCCESS) { hddLog( LOGE, FL("iw_softap_set_channel_range: startChannel = %d, endChannel = %d band = %d\n"), startChannel,endChannel, band); ret = -EINVAL; } pHddCtx->is_dynamic_channel_range_set = 1; return ret; } int iw_softap_get_channel_list(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { v_U32_t num_channels = 0; v_U8_t i = 0; v_U8_t bandStartChannel = RF_CHAN_1; v_U8_t bandEndChannel = RF_CHAN_165; v_U32_t temp_num_channels = 0; hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter); v_REGDOMAIN_t domainIdCurrentSoftap; tpChannelListInfo channel_list = (tpChannelListInfo) extra; eCsrBand curBand = eCSR_BAND_ALL; if (eHAL_STATUS_SUCCESS != sme_GetFreqBand(hHal, &curBand)) { hddLog(LOGE,FL("not able get the current frequency band\n")); return -EIO; } wrqu->data.length = sizeof(tChannelListInfo); ENTER(); if (eCSR_BAND_24 == curBand) { bandStartChannel = RF_CHAN_1; bandEndChannel = RF_CHAN_14; } else if (eCSR_BAND_5G == curBand) { bandStartChannel = RF_CHAN_36; bandEndChannel = RF_CHAN_165; } hddLog(LOG1, FL("\n curBand = %d, bandStartChannel = %hu, " "bandEndChannel = %hu "), curBand, bandStartChannel, bandEndChannel ); for( i = bandStartChannel; i <= bandEndChannel; i++ ) { if( NV_CHANNEL_ENABLE == regChannels[i].enabled ) { channel_list->channels[num_channels] = rfChannels[i].channelNum; num_channels++; } } /* remove indoor channels if the domain is FCC, channels 36 - 48 */ temp_num_channels = num_channels; if(eHAL_STATUS_SUCCESS != sme_getSoftApDomain(hHal,(v_REGDOMAIN_t *) &domainIdCurrentSoftap)) { hddLog(LOG1,FL("Failed to get Domain ID, %d \n"),domainIdCurrentSoftap); return -EIO; } if(REGDOMAIN_FCC == domainIdCurrentSoftap) { for(i = 0; i < temp_num_channels; i++) { if((channel_list->channels[i] > 35) && (channel_list->channels[i] < 49)) { vos_mem_move(&channel_list->channels[i], &channel_list->channels[i+1], temp_num_channels - (i-1)); num_channels--; temp_num_channels--; i--; } } } hddLog(LOG1,FL(" number of channels %d\n"), num_channels); if (num_channels > IW_MAX_FREQUENCIES) { num_channels = IW_MAX_FREQUENCIES; } channel_list->num_channels = num_channels; EXIT(); return 0; } static int iw_get_genie(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext; eHalStatus status; v_U32_t length = DOT11F_IE_RSN_MAX_LEN; v_U8_t genIeBytes[DOT11F_IE_RSN_MAX_LEN]; ENTER(); hddLog(LOG1,FL("getGEN_IE ioctl\n")); // Actually retrieve the RSN IE from CSR. (We previously sent it down in the CSR Roam Profile.) status = WLANSap_getstationIE_information(pVosContext, &length, genIeBytes); wrqu->data.length = VOS_MIN((u_int16_t) length, DOT11F_IE_RSN_MAX_LEN); vos_mem_copy( wrqu->data.pointer, (v_VOID_t*)genIeBytes, wrqu->data.length); hddLog(LOG1,FL(" RSN IE of %d bytes returned\n"), wrqu->data.length ); EXIT(); return 0; } static int iw_get_WPSPBCProbeReqIEs(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); sQcSapreq_WPSPBCProbeReqIES_t *pWPSPBCProbeReqIEs; hdd_ap_ctx_t *pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter); ENTER(); hddLog(LOG1,FL("get_WPSPBCProbeReqIEs ioctl\n")); pWPSPBCProbeReqIEs = (sQcSapreq_WPSPBCProbeReqIES_t *)(wrqu->data.pointer); pWPSPBCProbeReqIEs->probeReqIELen = pHddApCtx->WPSPBCProbeReq.probeReqIELen; vos_mem_copy(pWPSPBCProbeReqIEs->probeReqIE, pHddApCtx->WPSPBCProbeReq.probeReqIE, pWPSPBCProbeReqIEs->probeReqIELen); vos_mem_copy(pWPSPBCProbeReqIEs->macaddr, pHddApCtx->WPSPBCProbeReq.peerMacAddr, sizeof(v_MACADDR_t)); wrqu->data.length = 12 + pWPSPBCProbeReqIEs->probeReqIELen; hddLog(LOG1, FL("Macaddress : "MAC_ADDRESS_STR"\n"), MAC_ADDR_ARRAY(pWPSPBCProbeReqIEs->macaddr)); up(&pHddApCtx->semWpsPBCOverlapInd); EXIT(); return 0; } /**--------------------------------------------------------------------------- \brief iw_set_auth_hostap() - This function sets the auth type received from the wpa_supplicant. \param - dev - Pointer to the net device. - info - Pointer to the iw_request_info. - wrqu - Pointer to the iwreq_data. - extra - Pointer to the data. \return - 0 for success, non zero for failure --------------------------------------------------------------------------*/ int iw_set_auth_hostap(struct net_device *dev,struct iw_request_info *info, union iwreq_data *wrqu,char *extra) { hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter); ENTER(); switch(wrqu->param.flags & IW_AUTH_INDEX) { case IW_AUTH_TKIP_COUNTERMEASURES: { if(wrqu->param.value) { hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "Counter Measure started %d", wrqu->param.value); pWextState->mTKIPCounterMeasures = TKIP_COUNTER_MEASURE_STARTED; } else { hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "Counter Measure stopped=%d", wrqu->param.value); pWextState->mTKIPCounterMeasures = TKIP_COUNTER_MEASURE_STOPED; } hdd_softap_tkip_mic_fail_counter_measure(pAdapter, wrqu->param.value); } break; default: hddLog(LOGW, "%s called with unsupported auth type %d", __func__, wrqu->param.flags & IW_AUTH_INDEX); break; } EXIT(); return 0; } static int iw_set_ap_encodeext(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext; hdd_ap_ctx_t *pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter); int retval = 0; VOS_STATUS vstatus; struct iw_encode_ext *ext = (struct iw_encode_ext*)extra; v_U8_t groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; int key_index; struct iw_point *encoding = &wrqu->encoding; tCsrRoamSetKey setKey; // tCsrRoamRemoveKey RemoveKey; int i; ENTER(); key_index = encoding->flags & IW_ENCODE_INDEX; if(key_index > 0) { /*Convert from 1-based to 0-based keying*/ key_index--; } if(!ext->key_len) { #if 0 /*Set the encrytion type to NONE*/ #if 0 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE; #endif RemoveKey.keyId = key_index; if(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { /*Key direction for group is RX only*/ vos_mem_copy(RemoveKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN); } else { vos_mem_copy(RemoveKey.peerMac,ext->addr.sa_data,WNI_CFG_BSSID_LEN); } switch(ext->alg) { case IW_ENCODE_ALG_NONE: RemoveKey.encType = eCSR_ENCRYPT_TYPE_NONE; break; case IW_ENCODE_ALG_WEP: RemoveKey.encType = (ext->key_len== 5) ? eCSR_ENCRYPT_TYPE_WEP40:eCSR_ENCRYPT_TYPE_WEP104; break; case IW_ENCODE_ALG_TKIP: RemoveKey.encType = eCSR_ENCRYPT_TYPE_TKIP; break; case IW_ENCODE_ALG_CCMP: RemoveKey.encType = eCSR_ENCRYPT_TYPE_AES; break; default: RemoveKey.encType = eCSR_ENCRYPT_TYPE_NONE; break; } VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: Remove key cipher_alg:%d key_len%d *pEncryptionType :%d \n", __func__,(int)ext->alg,(int)ext->key_len,RemoveKey.encType); VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: Peer Mac = "MAC_ADDRESS_STR"\n", __func__, MAC_ADDR_ARRAY(RemoveKey.peerMac)); ); vstatus = WLANSAP_DelKeySta( pVosContext, &RemoveKey); if ( vstatus != VOS_STATUS_SUCCESS ) { VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "[%4d] WLANSAP_DeleteKeysSta returned ERROR status= %d", __LINE__, vstatus ); retval = -EINVAL; } #endif return retval; } vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey)); setKey.keyId = key_index; setKey.keyLength = ext->key_len; if(ext->key_len <= CSR_MAX_KEY_LEN) { vos_mem_copy(&setKey.Key[0],ext->key,ext->key_len); } if(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { /*Key direction for group is RX only*/ setKey.keyDirection = eSIR_RX_ONLY; vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN); } else { setKey.keyDirection = eSIR_TX_RX; vos_mem_copy(setKey.peerMac,ext->addr.sa_data,WNI_CFG_BSSID_LEN); } if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { setKey.keyDirection = eSIR_TX_DEFAULT; vos_mem_copy(setKey.peerMac,ext->addr.sa_data,WNI_CFG_BSSID_LEN); } /*For supplicant pae role is zero*/ setKey.paeRole = 0; switch(ext->alg) { case IW_ENCODE_ALG_NONE: setKey.encType = eCSR_ENCRYPT_TYPE_NONE; break; case IW_ENCODE_ALG_WEP: setKey.encType = (ext->key_len== 5) ? eCSR_ENCRYPT_TYPE_WEP40:eCSR_ENCRYPT_TYPE_WEP104; pHddApCtx->uPrivacy = 1; hddLog(LOG1, "(%s) uPrivacy=%d", __func__, pHddApCtx->uPrivacy); break; case IW_ENCODE_ALG_TKIP: { v_U8_t *pKey = &setKey.Key[0]; setKey.encType = eCSR_ENCRYPT_TYPE_TKIP; vos_mem_zero(pKey, CSR_MAX_KEY_LEN); /*Supplicant sends the 32bytes key in this order |--------------|----------|----------| | Tk1 |TX-MIC | RX Mic | |--------------|----------|----------| <---16bytes---><--8bytes--><--8bytes--> */ /*Sme expects the 32 bytes key to be in the below order |--------------|----------|----------| | Tk1 |RX-MIC | TX Mic | |--------------|----------|----------| <---16bytes---><--8bytes--><--8bytes--> */ /* Copy the Temporal Key 1 (TK1) */ vos_mem_copy(pKey,ext->key,16); /*Copy the rx mic first*/ vos_mem_copy(&pKey[16],&ext->key[24],8); /*Copy the tx mic */ vos_mem_copy(&pKey[24],&ext->key[16],8); } break; case IW_ENCODE_ALG_CCMP: setKey.encType = eCSR_ENCRYPT_TYPE_AES; break; default: setKey.encType = eCSR_ENCRYPT_TYPE_NONE; break; } VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, ("%s:EncryptionType:%d key_len:%d, KeyId:%d"), __func__, setKey.encType, setKey.keyLength, setKey.keyId); for(i=0; i< ext->key_len; i++) VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, ("%02x"), setKey.Key[i]); VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, ("\n")); vstatus = WLANSAP_SetKeySta( pVosContext, &setKey); if ( vstatus != VOS_STATUS_SUCCESS ) { VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "[%4d] WLANSAP_SetKeySta returned ERROR status= %d", __LINE__, vstatus ); retval = -EINVAL; } return retval; } static int iw_set_ap_mlme(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { #if 0 hdd_adapter_t *pAdapter = (netdev_priv(dev)); struct iw_mlme *mlme = (struct iw_mlme *)extra; ENTER(); //reason_code is unused. By default it is set to eCSR_DISCONNECT_REASON_UNSPECIFIED switch (mlme->cmd) { case IW_MLME_DISASSOC: case IW_MLME_DEAUTH: hddLog(LOG1, "Station disassociate"); if( pAdapter->conn_info.connState == eConnectionState_Associated ) { eCsrRoamDisconnectReason reason = eCSR_DISCONNECT_REASON_UNSPECIFIED; if( mlme->reason_code == HDD_REASON_MICHAEL_MIC_FAILURE ) reason = eCSR_DISCONNECT_REASON_MIC_ERROR; status = sme_RoamDisconnect( pAdapter->hHal,pAdapter->sessionId, reason); //clear all the reason codes if (status != 0) { hddLog(LOGE,"%s %d Command Disassociate/Deauthenticate : csrRoamDisconnect failure returned %d \n", __func__, (int)mlme->cmd, (int)status ); } netif_stop_queue(dev); netif_carrier_off(dev); } else { hddLog(LOGE,"%s %d Command Disassociate/Deauthenticate called but station is not in associated state \n", __func__, (int)mlme->cmd ); } default: hddLog(LOGE,"%s %d Command should be Disassociate/Deauthenticate \n", __func__, (int)mlme->cmd ); return -EINVAL; }//end of switch EXIT(); #endif return 0; // return status; } static int iw_get_ap_rts_threshold(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); v_U32_t status = 0; status = hdd_wlan_get_rts_threshold(pHostapdAdapter, wrqu); return status; } static int iw_get_ap_frag_threshold(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); v_U32_t status = 0; status = hdd_wlan_get_frag_threshold(pHostapdAdapter, wrqu); return status; } static int iw_get_ap_freq(struct net_device *dev, struct iw_request_info *info, struct iw_freq *fwrq, char *extra) { v_U32_t status = FALSE, channel = 0, freq = 0; hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); tHalHandle hHal; hdd_hostapd_state_t *pHostapdState; hdd_ap_ctx_t *pHddApCtx = WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter); ENTER(); if ((WLAN_HDD_GET_CTX(pHostapdAdapter))->isLogpInProgress) { VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s:LOGP in Progress. Ignore!!!",__func__); return status; } pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter); hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter); if(pHostapdState->bssState == BSS_STOP ) { if (ccmCfgGetInt(hHal, WNI_CFG_CURRENT_CHANNEL, &channel) != eHAL_STATUS_SUCCESS) { return -EIO; } else { status = hdd_wlan_get_freq(channel, &freq); if( TRUE == status) { /* Set Exponent parameter as 6 (MHZ) in struct iw_freq * iwlist & iwconfig command shows frequency into proper * format (2.412 GHz instead of 246.2 MHz)*/ fwrq->m = freq; fwrq->e = MHZ; } } } else { channel = pHddApCtx->operatingChannel; status = hdd_wlan_get_freq(channel, &freq); if( TRUE == status) { /* Set Exponent parameter as 6 (MHZ) in struct iw_freq * iwlist & iwconfig command shows frequency into proper * format (2.412 GHz instead of 246.2 MHz)*/ fwrq->m = freq; fwrq->e = MHZ; } } return 0; } static int iw_get_mode(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { int status = 0; wrqu->mode = IW_MODE_MASTER; return status; } static int iw_softap_setwpsie(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext; hdd_hostapd_state_t *pHostapdState; eHalStatus halStatus= eHAL_STATUS_SUCCESS; u_int8_t *wps_genie = wrqu->data.pointer; u_int8_t *pos; tpSap_WPSIE pSap_WPSIe; u_int8_t WPSIeType; u_int16_t length; ENTER(); if(!wrqu->data.length) return 0; pSap_WPSIe = vos_mem_malloc(sizeof(tSap_WPSIE)); if (NULL == pSap_WPSIe) { hddLog(LOGE, "VOS unable to allocate memory\n"); return -ENOMEM; } vos_mem_zero(pSap_WPSIe, sizeof(tSap_WPSIE)); hddLog(LOG1,"%s WPS IE type[0x%X] IE[0x%X], LEN[%d]\n", __func__, wps_genie[0], wps_genie[1], wps_genie[2]); WPSIeType = wps_genie[0]; if ( wps_genie[0] == eQC_WPS_BEACON_IE) { pSap_WPSIe->sapWPSIECode = eSAP_WPS_BEACON_IE; wps_genie = wps_genie + 1; switch ( wps_genie[0] ) { case DOT11F_EID_WPA: if (wps_genie[1] < 2 + 4) { vos_mem_free(pSap_WPSIe); return -EINVAL; } else if (memcmp(&wps_genie[2], "\x00\x50\xf2\x04", 4) == 0) { hddLog (LOG1, "%s Set WPS BEACON IE(len %d)",__func__, wps_genie[1]+2); pos = &wps_genie[6]; while (((size_t)pos - (size_t)&wps_genie[6]) < (wps_genie[1] - 4) ) { switch((u_int16_t)(*pos<<8) | *(pos+1)) { case HDD_WPS_ELEM_VERSION: pos += 4; pSap_WPSIe->sapwpsie.sapWPSBeaconIE.Version = *pos; hddLog(LOG1, "WPS version %d\n", pSap_WPSIe->sapwpsie.sapWPSBeaconIE.Version); pSap_WPSIe->sapwpsie.sapWPSBeaconIE.FieldPresent |= WPS_BEACON_VER_PRESENT; pos += 1; break; case HDD_WPS_ELEM_WPS_STATE: pos +=4; pSap_WPSIe->sapwpsie.sapWPSBeaconIE.wpsState = *pos; hddLog(LOG1, "WPS State %d\n", pSap_WPSIe->sapwpsie.sapWPSBeaconIE.wpsState); pSap_WPSIe->sapwpsie.sapWPSBeaconIE.FieldPresent |= WPS_BEACON_STATE_PRESENT; pos += 1; break; case HDD_WPS_ELEM_APSETUPLOCK: pos += 4; pSap_WPSIe->sapwpsie.sapWPSBeaconIE.APSetupLocked = *pos; hddLog(LOG1, "AP setup lock %d\n", pSap_WPSIe->sapwpsie.sapWPSBeaconIE.APSetupLocked); pSap_WPSIe->sapwpsie.sapWPSBeaconIE.FieldPresent |= WPS_BEACON_APSETUPLOCK_PRESENT; pos += 1; break; case HDD_WPS_ELEM_SELECTEDREGISTRA: pos += 4; pSap_WPSIe->sapwpsie.sapWPSBeaconIE.SelectedRegistra = *pos; hddLog(LOG1, "Selected Registra %d\n", pSap_WPSIe->sapwpsie.sapWPSBeaconIE.SelectedRegistra); pSap_WPSIe->sapwpsie.sapWPSBeaconIE.FieldPresent |= WPS_BEACON_SELECTEDREGISTRA_PRESENT; pos += 1; break; case HDD_WPS_ELEM_DEVICE_PASSWORD_ID: pos += 4; pSap_WPSIe->sapwpsie.sapWPSBeaconIE.DevicePasswordID = (*pos<<8) | *(pos+1); hddLog(LOG1, "Password ID: %x\n", pSap_WPSIe->sapwpsie.sapWPSBeaconIE.DevicePasswordID); pSap_WPSIe->sapwpsie.sapWPSBeaconIE.FieldPresent |= WPS_BEACON_DEVICEPASSWORDID_PRESENT; pos += 2; break; case HDD_WPS_ELEM_REGISTRA_CONF_METHODS: pos += 4; pSap_WPSIe->sapwpsie.sapWPSBeaconIE.SelectedRegistraCfgMethod = (*pos<<8) | *(pos+1); hddLog(LOG1, "Select Registra Config Methods: %x\n", pSap_WPSIe->sapwpsie.sapWPSBeaconIE.SelectedRegistraCfgMethod); pSap_WPSIe->sapwpsie.sapWPSBeaconIE.FieldPresent |= WPS_BEACON_SELECTEDREGISTRACFGMETHOD_PRESENT; pos += 2; break; case HDD_WPS_ELEM_UUID_E: pos += 2; length = *pos<<8 | *(pos+1); pos += 2; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSBeaconIE.UUID_E, pos, length); pSap_WPSIe->sapwpsie.sapWPSBeaconIE.FieldPresent |= WPS_BEACON_UUIDE_PRESENT; pos += length; break; case HDD_WPS_ELEM_RF_BANDS: pos += 4; pSap_WPSIe->sapwpsie.sapWPSBeaconIE.RFBand = *pos; hddLog(LOG1, "RF band: %d\n", pSap_WPSIe->sapwpsie.sapWPSBeaconIE.RFBand); pSap_WPSIe->sapwpsie.sapWPSBeaconIE.FieldPresent |= WPS_BEACON_RF_BANDS_PRESENT; pos += 1; break; default: hddLog (LOGW, "UNKNOWN TLV in WPS IE(%x)\n", (*pos<<8 | *(pos+1))); vos_mem_free(pSap_WPSIe); return -EINVAL; } } } else { hddLog (LOGE, "%s WPS IE Mismatch %X", __func__, wps_genie[0]); } break; default: hddLog (LOGE, "%s Set UNKNOWN IE %X",__func__, wps_genie[0]); vos_mem_free(pSap_WPSIe); return 0; } } else if( wps_genie[0] == eQC_WPS_PROBE_RSP_IE) { pSap_WPSIe->sapWPSIECode = eSAP_WPS_PROBE_RSP_IE; wps_genie = wps_genie + 1; switch ( wps_genie[0] ) { case DOT11F_EID_WPA: if (wps_genie[1] < 2 + 4) { vos_mem_free(pSap_WPSIe); return -EINVAL; } else if (memcmp(&wps_genie[2], "\x00\x50\xf2\x04", 4) == 0) { hddLog (LOG1, "%s Set WPS PROBE RSP IE(len %d)",__func__, wps_genie[1]+2); pos = &wps_genie[6]; while (((size_t)pos - (size_t)&wps_genie[6]) < (wps_genie[1] - 4) ) { switch((u_int16_t)(*pos<<8) | *(pos+1)) { case HDD_WPS_ELEM_VERSION: pos += 4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.Version = *pos; hddLog(LOG1, "WPS version %d\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.Version); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_VER_PRESENT; pos += 1; break; case HDD_WPS_ELEM_WPS_STATE: pos +=4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.wpsState = *pos; hddLog(LOG1, "WPS State %d\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.wpsState); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_STATE_PRESENT; pos += 1; break; case HDD_WPS_ELEM_APSETUPLOCK: pos += 4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.APSetupLocked = *pos; hddLog(LOG1, "AP setup lock %d\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.APSetupLocked); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_APSETUPLOCK_PRESENT; pos += 1; break; case HDD_WPS_ELEM_SELECTEDREGISTRA: pos += 4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.SelectedRegistra = *pos; hddLog(LOG1, "Selected Registra %d\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.SelectedRegistra); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_SELECTEDREGISTRA_PRESENT; pos += 1; break; case HDD_WPS_ELEM_DEVICE_PASSWORD_ID: pos += 4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.DevicePasswordID = (*pos<<8) | *(pos+1); hddLog(LOG1, "Password ID: %d\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.DevicePasswordID); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_DEVICEPASSWORDID_PRESENT; pos += 2; break; case HDD_WPS_ELEM_REGISTRA_CONF_METHODS: pos += 4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.SelectedRegistraCfgMethod = (*pos<<8) | *(pos+1); hddLog(LOG1, "Select Registra Config Methods: %x\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.SelectedRegistraCfgMethod); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_SELECTEDREGISTRACFGMETHOD_PRESENT; pos += 2; break; case HDD_WPS_ELEM_RSP_TYPE: pos += 4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ResponseType = *pos; hddLog(LOG1, "Config Methods: %d\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ResponseType); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_RESPONSETYPE_PRESENT; pos += 1; break; case HDD_WPS_ELEM_UUID_E: pos += 2; length = *pos<<8 | *(pos+1); pos += 2; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.UUID_E, pos, length); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_UUIDE_PRESENT; pos += length; break; case HDD_WPS_ELEM_MANUFACTURER: pos += 2; length = *pos<<8 | *(pos+1); pos += 2; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.Manufacture.num_name = length; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.Manufacture.name, pos, length); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_MANUFACTURE_PRESENT; pos += length; break; case HDD_WPS_ELEM_MODEL_NAME: pos += 2; length = *pos<<8 | *(pos+1); pos += 2; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ModelName.num_text = length; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ModelName.text, pos, length); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_MODELNAME_PRESENT; pos += length; break; case HDD_WPS_ELEM_MODEL_NUM: pos += 2; length = *pos<<8 | *(pos+1); pos += 2; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ModelNumber.num_text = length; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ModelNumber.text, pos, length); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_MODELNUMBER_PRESENT; pos += length; break; case HDD_WPS_ELEM_SERIAL_NUM: pos += 2; length = *pos<<8 | *(pos+1); pos += 2; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.SerialNumber.num_text = length; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.SerialNumber.text, pos, length); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_SERIALNUMBER_PRESENT; pos += length; break; case HDD_WPS_ELEM_PRIMARY_DEVICE_TYPE: pos += 4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.PrimaryDeviceCategory = (*pos<<8 | *(pos+1)); hddLog(LOG1, "primary dev category: %d\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.PrimaryDeviceCategory); pos += 2; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.PrimaryDeviceOUI, pos, HDD_WPS_DEVICE_OUI_LEN); hddLog(LOG1, "primary dev oui: %02x, %02x, %02x, %02x\n", pos[0], pos[1], pos[2], pos[3]); pos += 4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.DeviceSubCategory = (*pos<<8 | *(pos+1)); hddLog(LOG1, "primary dev sub category: %d\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.DeviceSubCategory); pos += 2; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_PRIMARYDEVICETYPE_PRESENT; break; case HDD_WPS_ELEM_DEVICE_NAME: pos += 2; length = *pos<<8 | *(pos+1); pos += 2; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.DeviceName.num_text = length; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.DeviceName.text, pos, length); pos += length; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_DEVICENAME_PRESENT; break; case HDD_WPS_ELEM_CONFIG_METHODS: pos += 4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ConfigMethod = (*pos<<8) | *(pos+1); hddLog(LOG1, "Config Methods: %d\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.SelectedRegistraCfgMethod); pos += 2; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_CONFIGMETHODS_PRESENT; break; case HDD_WPS_ELEM_RF_BANDS: pos += 4; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.RFBand = *pos; hddLog(LOG1, "RF band: %d\n", pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.RFBand); pos += 1; pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_RF_BANDS_PRESENT; break; } // switch } } else { hddLog (LOGE, "%s WPS IE Mismatch %X",__func__, wps_genie[0]); } } // switch } halStatus = WLANSAP_Set_WpsIe(pVosContext, pSap_WPSIe); pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter); if( pHostapdState->bCommit && WPSIeType == eQC_WPS_PROBE_RSP_IE) { //hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); //v_CONTEXT_t pVosContext = pHostapdAdapter->pvosContext; WLANSAP_Update_WpsIe ( pVosContext ); } vos_mem_free(pSap_WPSIe); EXIT(); return halStatus; } static int iw_softap_stopbss(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); VOS_STATUS status = VOS_STATUS_SUCCESS; ENTER(); if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags)) { if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss((WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext) ) ) { hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter); status = vos_wait_single_event(&pHostapdState->vosEvent, 10000); if (!VOS_IS_STATUS_SUCCESS(status)) { VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, ("ERROR: HDD vos wait for single_event failed!!\n")); VOS_ASSERT(0); } } clear_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags); } EXIT(); return (status == VOS_STATUS_SUCCESS) ? 0 : -EBUSY; } static int iw_softap_version(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); ENTER(); hdd_wlan_get_version(pHostapdAdapter, wrqu, extra); EXIT(); return 0; } VOS_STATUS hdd_softap_get_sta_info(hdd_adapter_t *pAdapter, v_U8_t *pBuf, int buf_len) { v_U8_t i; int len = 0; const char sta_info_header[] = "staId staAddress\n"; len = snprintf(pBuf, buf_len, sta_info_header); pBuf += len; buf_len -= len; for (i = 0; i < WLAN_MAX_STA_COUNT; i++) { if(pAdapter->aStaInfo[i].isUsed) { len = snprintf(pBuf, buf_len, "%*d .%02x:%02x:%02x:%02x:%02x:%02x\n", strlen("staId"), pAdapter->aStaInfo[i].ucSTAId, pAdapter->aStaInfo[i].macAddrSTA.bytes[0], pAdapter->aStaInfo[i].macAddrSTA.bytes[1], pAdapter->aStaInfo[i].macAddrSTA.bytes[2], pAdapter->aStaInfo[i].macAddrSTA.bytes[3], pAdapter->aStaInfo[i].macAddrSTA.bytes[4], pAdapter->aStaInfo[i].macAddrSTA.bytes[5]); pBuf += len; buf_len -= len; } if(WE_GET_STA_INFO_SIZE > buf_len) { break; } } return VOS_STATUS_SUCCESS; } static int iw_softap_get_sta_info(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); VOS_STATUS status; ENTER(); status = hdd_softap_get_sta_info(pHostapdAdapter, extra, WE_SAP_MAX_STA_INFO); if ( !VOS_IS_STATUS_SUCCESS( status ) ) { hddLog(VOS_TRACE_LEVEL_ERROR, "%s Failed!!!\n",__func__); return -EINVAL; } wrqu->data.length = strlen(extra); EXIT(); return 0; } static int iw_set_ap_genie(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext; eHalStatus halStatus= eHAL_STATUS_SUCCESS; u_int8_t *genie = wrqu->data.pointer; ENTER(); if(!wrqu->data.length) { EXIT(); return 0; } switch (genie[0]) { case DOT11F_EID_WPA: case DOT11F_EID_RSN: if((WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy == 0) { hdd_softap_Deregister_BC_STA(pHostapdAdapter); hdd_softap_Register_BC_STA(pHostapdAdapter, 1); } (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = 1; halStatus = WLANSAP_Set_WPARSNIes(pVosContext, wrqu->data.pointer, wrqu->data.length); break; default: hddLog (LOGE, "%s Set UNKNOWN IE %X",__func__, genie[0]); halStatus = 0; } EXIT(); return halStatus; } static VOS_STATUS wlan_hdd_get_classAstats_for_station(hdd_adapter_t *pAdapter, u8 staid) { eHalStatus hstatus; long lrc; struct statsContext context; if (NULL == pAdapter) { hddLog(VOS_TRACE_LEVEL_ERROR,"%s: Padapter is NULL", __func__); return VOS_STATUS_E_FAULT; } init_completion(&context.completion); context.pAdapter = pAdapter; context.magic = STATS_CONTEXT_MAGIC; hstatus = sme_GetStatistics( WLAN_HDD_GET_HAL_CTX(pAdapter), eCSR_HDD, SME_GLOBAL_CLASSA_STATS, hdd_GetClassA_statisticsCB, 0, // not periodic FALSE, //non-cached results staid, &context); if (eHAL_STATUS_SUCCESS != hstatus) { hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unable to retrieve statistics for link speed", __func__); } else { lrc = wait_for_completion_interruptible_timeout(&context.completion, msecs_to_jiffies(WLAN_WAIT_TIME_STATS)); context.magic = 0; if (lrc <= 0) { hddLog(VOS_TRACE_LEVEL_ERROR, "%s: SME %s while retrieving link speed", __func__, (0 == lrc) ? "timeout" : "interrupt"); msleep(50); } } return VOS_STATUS_SUCCESS; } int iw_get_softap_linkspeed(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { hdd_adapter_t *pHostapdAdapter = (netdev_priv(dev)); hdd_context_t *pHddCtx; char *pLinkSpeed = (char*)extra; v_U32_t link_speed; unsigned short staId; int len = sizeof(v_U32_t)+1; v_BYTE_t macAddress[VOS_MAC_ADDR_SIZE]; VOS_STATUS status; int rc, valid; pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter); valid = wlan_hdd_validate_context(pHddCtx); if (0 != valid) { hddLog(VOS_TRACE_LEVEL_ERROR, FL("HDD context not valid")); return valid; } hddLog(VOS_TRACE_LEVEL_INFO, "%s wrqu->data.length= %d\n", __func__, wrqu->data.length); status = hdd_string_to_hex ((char *)wrqu->data.pointer, wrqu->data.length, macAddress ); if (!VOS_IS_STATUS_SUCCESS(status )) { hddLog(VOS_TRACE_LEVEL_ERROR, FL("String to Hex conversion Failed")); } /* If no mac address is passed and/or its length is less than 17, * link speed for first connected client will be returned. */ if (!VOS_IS_STATUS_SUCCESS(status ) || wrqu->data.length < 17) { status = hdd_softap_GetConnectedStaId(pHostapdAdapter, (void *)(&staId)); } else { status = hdd_softap_GetStaId(pHostapdAdapter, (v_MACADDR_t *)macAddress, (void *)(&staId)); } if (!VOS_IS_STATUS_SUCCESS(status)) { hddLog(VOS_TRACE_LEVEL_ERROR, FL("ERROR: HDD Failed to find sta id!!")); link_speed = 0; } else { status = wlan_hdd_get_classAstats_for_station(pHostapdAdapter , staId); if (!VOS_IS_STATUS_SUCCESS(status )) { hddLog(VOS_TRACE_LEVEL_ERROR, FL("Unable to retrieve SME statistics")); return -EINVAL; } WLANTL_GetSTALinkCapacity(pHddCtx->pvosContext, staId, &link_speed); link_speed = link_speed / 10; if (0 == link_speed) { /* The linkspeed returned by HAL is in units of 500kbps. * converting it to mbps. * This is required to support legacy firmware which does * not return link capacity. */ link_speed =(int)pHostapdAdapter->hdd_stats.ClassA_stat.tx_rate/2; } } wrqu->data.length = len; rc = snprintf(pLinkSpeed, len, "%lu", link_speed); if ((rc < 0) || (rc >= len)) { // encoding or length error? hddLog(VOS_TRACE_LEVEL_ERROR,FL( "Unable to encode link speed")); return -EIO; } return 0; } static const iw_handler hostapd_handler[] = { (iw_handler) NULL, /* SIOCSIWCOMMIT */ (iw_handler) NULL, /* SIOCGIWNAME */ (iw_handler) NULL, /* SIOCSIWNWID */ (iw_handler) NULL, /* SIOCGIWNWID */ (iw_handler) NULL, /* SIOCSIWFREQ */ (iw_handler) iw_get_ap_freq, /* SIOCGIWFREQ */ (iw_handler) NULL, /* SIOCSIWMODE */ (iw_handler) iw_get_mode, /* SIOCGIWMODE */ (iw_handler) NULL, /* SIOCSIWSENS */ (iw_handler) NULL, /* SIOCGIWSENS */ (iw_handler) NULL, /* SIOCSIWRANGE */ (iw_handler) NULL, /* SIOCGIWRANGE */ (iw_handler) NULL, /* SIOCSIWPRIV */ (iw_handler) NULL, /* SIOCGIWPRIV */ (iw_handler) NULL, /* SIOCSIWSTATS */ (iw_handler) NULL, /* SIOCGIWSTATS */ (iw_handler) NULL, /* SIOCSIWSPY */ (iw_handler) NULL, /* SIOCGIWSPY */ (iw_handler) NULL, /* SIOCSIWTHRSPY */ (iw_handler) NULL, /* SIOCGIWTHRSPY */ (iw_handler) NULL, /* SIOCSIWAP */ (iw_handler) NULL, /* SIOCGIWAP */ (iw_handler) iw_set_ap_mlme, /* SIOCSIWMLME */ (iw_handler) NULL, /* SIOCGIWAPLIST */ (iw_handler) NULL, /* SIOCSIWSCAN */ (iw_handler) NULL, /* SIOCGIWSCAN */ (iw_handler) NULL, /* SIOCSIWESSID */ (iw_handler) NULL, /* SIOCGIWESSID */ (iw_handler) NULL, /* SIOCSIWNICKN */ (iw_handler) NULL, /* SIOCGIWNICKN */ (iw_handler) NULL, /* -- hole -- */ (iw_handler) NULL, /* -- hole -- */ (iw_handler) NULL, /* SIOCSIWRATE */ (iw_handler) NULL, /* SIOCGIWRATE */ (iw_handler) NULL, /* SIOCSIWRTS */ (iw_handler) iw_get_ap_rts_threshold, /* SIOCGIWRTS */ (iw_handler) NULL, /* SIOCSIWFRAG */ (iw_handler) iw_get_ap_frag_threshold, /* SIOCGIWFRAG */ (iw_handler) NULL, /* SIOCSIWTXPOW */ (iw_handler) NULL, /* SIOCGIWTXPOW */ (iw_handler) NULL, /* SIOCSIWRETRY */ (iw_handler) NULL, /* SIOCGIWRETRY */ (iw_handler) NULL, /* SIOCSIWENCODE */ (iw_handler) NULL, /* SIOCGIWENCODE */ (iw_handler) NULL, /* SIOCSIWPOWER */ (iw_handler) NULL, /* SIOCGIWPOWER */ (iw_handler) NULL, /* -- hole -- */ (iw_handler) NULL, /* -- hole -- */ (iw_handler) iw_set_ap_genie, /* SIOCSIWGENIE */ (iw_handler) NULL, /* SIOCGIWGENIE */ (iw_handler) iw_set_auth_hostap, /* SIOCSIWAUTH */ (iw_handler) NULL, /* SIOCGIWAUTH */ (iw_handler) iw_set_ap_encodeext, /* SIOCSIWENCODEEXT */ (iw_handler) NULL, /* SIOCGIWENCODEEXT */ (iw_handler) NULL, /* SIOCSIWPMKSA */ }; #define IW_PRIV_TYPE_OPTIE (IW_PRIV_TYPE_BYTE | QCSAP_MAX_OPT_IE) #define IW_PRIV_TYPE_MLME \ (IW_PRIV_TYPE_BYTE | sizeof(struct ieee80211req_mlme)) static const struct iw_priv_args hostapd_private_args[] = { { QCSAP_IOCTL_SETPARAM, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "setparam" }, { QCSAP_IOCTL_SETPARAM, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" }, { QCSAP_PARAM_MAX_ASSOC, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setMaxAssoc" }, { QCSAP_PARAM_HIDE_SSID, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hideSSID" }, { QCSAP_IOCTL_GETPARAM, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getparam" }, { QCSAP_IOCTL_GETPARAM, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" }, { QCSAP_PARAM_MAX_ASSOC, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getMaxAssoc" }, { QCSAP_PARAM_GET_WLAN_DBG, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwlandbg" }, { QCSAP_PARAM_AUTO_CHANNEL, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getAutoChannel" }, { QCSAP_PARAM_MODULE_DOWN_IND, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "moduleDownInd" }, { QCSAP_PARAM_CLR_ACL, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "setClearAcl" }, { QCSAP_PARAM_ACL_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setAclMode" }, { QCSAP_IOCTL_COMMIT, IW_PRIV_TYPE_BYTE | sizeof(struct s_CommitConfig) | IW_PRIV_SIZE_FIXED, 0, "commit" }, { QCSAP_IOCTL_SETMLME, IW_PRIV_TYPE_BYTE | sizeof(struct sQcSapreq_mlme)| IW_PRIV_SIZE_FIXED, 0, "setmlme" }, { QCSAP_IOCTL_GET_STAWPAIE, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "get_staWPAIE" }, { QCSAP_IOCTL_SETWPAIE, IW_PRIV_TYPE_BYTE | QCSAP_MAX_WSC_IE | IW_PRIV_SIZE_FIXED, 0, "setwpaie" }, { QCSAP_IOCTL_STOPBSS, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED, 0, "stopbss" }, { QCSAP_IOCTL_VERSION, 0, IW_PRIV_TYPE_CHAR | QCSAP_MAX_WSC_IE, "version" }, { QCSAP_IOCTL_GET_STA_INFO, 0, IW_PRIV_TYPE_CHAR | WE_SAP_MAX_STA_INFO, "get_sta_info" }, { QCSAP_IOCTL_GET_WPS_PBC_PROBE_REQ_IES, IW_PRIV_TYPE_BYTE | sizeof(sQcSapreq_WPSPBCProbeReqIES_t) | IW_PRIV_SIZE_FIXED | 1, 0, "getProbeReqIEs" }, { QCSAP_IOCTL_GET_CHANNEL, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getchannel" }, { QCSAP_IOCTL_ASSOC_STA_MACADDR, 0, IW_PRIV_TYPE_BYTE | /*((WLAN_MAX_STA_COUNT*6)+100)*/1 , "get_assoc_stamac" }, { QCSAP_IOCTL_DISASSOC_STA, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 6 , 0, "disassoc_sta" }, { QCSAP_IOCTL_AP_STATS, IW_PRIV_TYPE_BYTE | QCSAP_MAX_WSC_IE, 0, "ap_stats" }, { QCSAP_IOCTL_PRIV_GET_SOFTAP_LINK_SPEED, IW_PRIV_TYPE_CHAR | 18, IW_PRIV_TYPE_CHAR | 5, "getLinkSpeed" }, { QCSAP_IOCTL_PRIV_SET_THREE_INT_GET_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "" }, /* handlers for sub-ioctl */ { WE_SET_WLAN_DBG, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "setwlandbg" }, /* handlers for main ioctl */ { QCSAP_IOCTL_PRIV_SET_VAR_INT_GET_NONE, IW_PRIV_TYPE_INT | MAX_VAR_ARGS, 0, "" }, /* handlers for sub-ioctl */ { WE_LOG_DUMP_CMD, IW_PRIV_TYPE_INT | MAX_VAR_ARGS, 0, "dump" }, { WE_P2P_NOA_CMD, IW_PRIV_TYPE_INT | MAX_VAR_ARGS, 0, "SetP2pPs" }, /* handlers for sub ioctl */ { WE_MCC_CONFIG_CREDENTIAL, IW_PRIV_TYPE_INT | MAX_VAR_ARGS, 0, "setMccCrdnl" }, /* handlers for sub ioctl */ { WE_MCC_CONFIG_PARAMS, IW_PRIV_TYPE_INT | MAX_VAR_ARGS, 0, "setMccConfig" }, /* handlers for main ioctl */ { QCSAP_IOCTL_MODIFY_ACL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 8, 0, "modify_acl" }, /* handlers for main ioctl */ { QCSAP_IOCTL_GET_CHANNEL_LIST, 0, IW_PRIV_TYPE_BYTE | sizeof(tChannelListInfo), "getChannelList" }, /* handlers for main ioctl */ { QCSAP_IOCTL_SET_TX_POWER, IW_PRIV_TYPE_INT| IW_PRIV_SIZE_FIXED | 1, 0, "setTxPower" }, /* handlers for main ioctl */ { QCSAP_IOCTL_SET_MAX_TX_POWER, IW_PRIV_TYPE_INT| IW_PRIV_SIZE_FIXED | 1, 0, "setTxMaxPower" }, { QCSAP_IOCTL_DATAPATH_SNAP_SHOT, IW_PRIV_TYPE_NONE | IW_PRIV_TYPE_NONE, 0, "dataSnapshot" }, /* handlers for main ioctl */ { QCSAP_IOCTL_SET_TRAFFIC_MONITOR, IW_PRIV_TYPE_INT| IW_PRIV_SIZE_FIXED | 1, 0, "setTrafficMon" }, }; static const iw_handler hostapd_private[] = { [QCSAP_IOCTL_SETPARAM - SIOCIWFIRSTPRIV] = iw_softap_setparam, //set priv ioctl [QCSAP_IOCTL_GETPARAM - SIOCIWFIRSTPRIV] = iw_softap_getparam, //get priv ioctl [QCSAP_IOCTL_COMMIT - SIOCIWFIRSTPRIV] = iw_softap_commit, //get priv ioctl [QCSAP_IOCTL_SETMLME - SIOCIWFIRSTPRIV] = iw_softap_setmlme, [QCSAP_IOCTL_GET_STAWPAIE - SIOCIWFIRSTPRIV] = iw_get_genie, //get station genIE [QCSAP_IOCTL_SETWPAIE - SIOCIWFIRSTPRIV] = iw_softap_setwpsie, [QCSAP_IOCTL_STOPBSS - SIOCIWFIRSTPRIV] = iw_softap_stopbss, // stop bss [QCSAP_IOCTL_VERSION - SIOCIWFIRSTPRIV] = iw_softap_version, // get driver version [QCSAP_IOCTL_GET_WPS_PBC_PROBE_REQ_IES - SIOCIWFIRSTPRIV] = iw_get_WPSPBCProbeReqIEs, [QCSAP_IOCTL_GET_CHANNEL - SIOCIWFIRSTPRIV] = iw_softap_getchannel, [QCSAP_IOCTL_ASSOC_STA_MACADDR - SIOCIWFIRSTPRIV] = iw_softap_getassoc_stamacaddr, [QCSAP_IOCTL_DISASSOC_STA - SIOCIWFIRSTPRIV] = iw_softap_disassoc_sta, [QCSAP_IOCTL_AP_STATS - SIOCIWFIRSTPRIV] = iw_softap_ap_stats, [QCSAP_IOCTL_PRIV_SET_THREE_INT_GET_NONE - SIOCIWFIRSTPRIV] = iw_set_three_ints_getnone, [QCSAP_IOCTL_PRIV_SET_VAR_INT_GET_NONE - SIOCIWFIRSTPRIV] = iw_set_var_ints_getnone, [QCSAP_IOCTL_SET_CHANNEL_RANGE - SIOCIWFIRSTPRIV] = iw_softap_set_channel_range, [QCSAP_IOCTL_MODIFY_ACL - SIOCIWFIRSTPRIV] = iw_softap_modify_acl, [QCSAP_IOCTL_GET_CHANNEL_LIST - SIOCIWFIRSTPRIV] = iw_softap_get_channel_list, [QCSAP_IOCTL_GET_STA_INFO - SIOCIWFIRSTPRIV] = iw_softap_get_sta_info, [QCSAP_IOCTL_PRIV_GET_SOFTAP_LINK_SPEED - SIOCIWFIRSTPRIV] = iw_get_softap_linkspeed, [QCSAP_IOCTL_SET_TX_POWER - SIOCIWFIRSTPRIV] = iw_softap_set_tx_power, [QCSAP_IOCTL_SET_MAX_TX_POWER - SIOCIWFIRSTPRIV] = iw_softap_set_max_tx_power, [QCSAP_IOCTL_DATAPATH_SNAP_SHOT - SIOCIWFIRSTPRIV] = iw_display_data_path_snapshot, [QCSAP_IOCTL_SET_TRAFFIC_MONITOR - SIOCIWFIRSTPRIV] = iw_softap_set_trafficmonitor, }; const struct iw_handler_def hostapd_handler_def = { .num_standard = sizeof(hostapd_handler) / sizeof(hostapd_handler[0]), .num_private = sizeof(hostapd_private) / sizeof(hostapd_private[0]), .num_private_args = sizeof(hostapd_private_args) / sizeof(hostapd_private_args[0]), .standard = (iw_handler *)hostapd_handler, .private = (iw_handler *)hostapd_private, .private_args = hostapd_private_args, .get_wireless_stats = NULL, }; #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29) struct net_device_ops net_ops_struct = { .ndo_open = hdd_hostapd_open, .ndo_stop = hdd_hostapd_stop, .ndo_uninit = hdd_hostapd_uninit, .ndo_start_xmit = hdd_softap_hard_start_xmit, .ndo_tx_timeout = hdd_softap_tx_timeout, .ndo_get_stats = hdd_softap_stats, .ndo_set_mac_address = hdd_hostapd_set_mac_address, .ndo_do_ioctl = hdd_hostapd_ioctl, .ndo_change_mtu = hdd_hostapd_change_mtu, .ndo_select_queue = hdd_hostapd_select_queue, }; #endif int hdd_set_hostapd(hdd_adapter_t *pAdapter) { return VOS_STATUS_SUCCESS; } void hdd_set_ap_ops( struct net_device *pWlanHostapdDev ) { #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29) pWlanHostapdDev->netdev_ops = &net_ops_struct; #else pWlanHostapdDev->open = hdd_hostapd_open; pWlanHostapdDev->stop = hdd_hostapd_stop; pWlanHostapdDev->uninit = hdd_hostapd_uninit; pWlanHostapdDev->hard_start_xmit = hdd_softap_hard_start_xmit; pWlanHostapdDev->tx_timeout = hdd_softap_tx_timeout; pWlanHostapdDev->get_stats = hdd_softap_stats; pWlanHostapdDev->set_mac_address = hdd_hostapd_set_mac_address; pWlanHostapdDev->do_ioctl = hdd_hostapd_ioctl; #endif } VOS_STATUS hdd_init_ap_mode( hdd_adapter_t *pAdapter ) { hdd_hostapd_state_t * phostapdBuf; struct net_device *dev = pAdapter->dev; VOS_STATUS status; ENTER(); // Allocate the Wireless Extensions state structure phostapdBuf = WLAN_HDD_GET_HOSTAP_STATE_PTR( pAdapter ); // Zero the memory. This zeros the profile structure. memset(phostapdBuf, 0,sizeof(hdd_hostapd_state_t)); // Set up the pointer to the Wireless Extensions state structure // NOP status = hdd_set_hostapd(pAdapter); if(!VOS_IS_STATUS_SUCCESS(status)) { VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, ("ERROR: hdd_set_hostapd failed!!\n")); return status; } status = vos_event_init(&phostapdBuf->vosEvent); if (!VOS_IS_STATUS_SUCCESS(status)) { VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, ("ERROR: Hostapd HDD vos event init failed!!\n")); return status; } init_completion(&pAdapter->session_close_comp_var); init_completion(&pAdapter->session_open_comp_var); sema_init(&(WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->semWpsPBCOverlapInd, 1); // Register as a wireless device dev->wireless_handlers = (struct iw_handler_def *)& hostapd_handler_def; //Initialize the data path module status = hdd_softap_init_tx_rx(pAdapter); if ( !VOS_IS_STATUS_SUCCESS( status )) { hddLog(VOS_TRACE_LEVEL_FATAL, "%s: hdd_softap_init_tx_rx failed", __func__); } status = hdd_wmm_adapter_init( pAdapter ); if (!VOS_IS_STATUS_SUCCESS(status)) { hddLog(VOS_TRACE_LEVEL_ERROR, "hdd_wmm_adapter_init() failed with status code %08d [x%08lx]", status, status ); goto error_wmm_init; } set_bit(WMM_INIT_DONE, &pAdapter->event_flags); wlan_hdd_set_monitor_tx_adapter( WLAN_HDD_GET_CTX(pAdapter), pAdapter ); return status; error_wmm_init: hdd_softap_deinit_tx_rx( pAdapter ); EXIT(); return status; } hdd_adapter_t* hdd_wlan_create_ap_dev( hdd_context_t *pHddCtx, tSirMacAddr macAddr, tANI_U8 *iface_name ) { struct net_device *pWlanHostapdDev = NULL; hdd_adapter_t *pHostapdAdapter = NULL; v_CONTEXT_t pVosContext= NULL; pWlanHostapdDev = alloc_netdev_mq(sizeof(hdd_adapter_t), iface_name, ether_setup, NUM_TX_QUEUES); if (pWlanHostapdDev != NULL) { pHostapdAdapter = netdev_priv(pWlanHostapdDev); //Init the net_device structure ether_setup(pWlanHostapdDev); //Initialize the adapter context to zeros. vos_mem_zero(pHostapdAdapter, sizeof( hdd_adapter_t )); pHostapdAdapter->dev = pWlanHostapdDev; pHostapdAdapter->pHddCtx = pHddCtx; pHostapdAdapter->magic = WLAN_HDD_ADAPTER_MAGIC; //Get the Global VOSS context. pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL); //Save the adapter context in global context for future. ((VosContextType*)(pVosContext))->pHDDSoftAPContext = (v_VOID_t*)pHostapdAdapter; //Init the net_device structure strlcpy(pWlanHostapdDev->name, (const char *)iface_name, IFNAMSIZ); hdd_set_ap_ops( pHostapdAdapter->dev ); pWlanHostapdDev->tx_queue_len = NET_DEV_TX_QUEUE_LEN; pWlanHostapdDev->watchdog_timeo = HDD_TX_TIMEOUT; pWlanHostapdDev->mtu = HDD_DEFAULT_MTU; vos_mem_copy(pWlanHostapdDev->dev_addr, (void *)macAddr,sizeof(tSirMacAddr)); vos_mem_copy(pHostapdAdapter->macAddressCurrent.bytes, (void *)macAddr, sizeof(tSirMacAddr)); pWlanHostapdDev->destructor = free_netdev; pWlanHostapdDev->ieee80211_ptr = &pHostapdAdapter->wdev ; pHostapdAdapter->wdev.wiphy = pHddCtx->wiphy; pHostapdAdapter->wdev.netdev = pWlanHostapdDev; init_completion(&pHostapdAdapter->tx_action_cnf_event); init_completion(&pHostapdAdapter->cancel_rem_on_chan_var); init_completion(&pHostapdAdapter->rem_on_chan_ready_event); #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) init_completion(&pHostapdAdapter->offchannel_tx_event); #endif SET_NETDEV_DEV(pWlanHostapdDev, pHddCtx->parent_dev); } return pHostapdAdapter; } VOS_STATUS hdd_register_hostapd( hdd_adapter_t *pAdapter, tANI_U8 rtnl_lock_held ) { struct net_device *dev = pAdapter->dev; VOS_STATUS status = VOS_STATUS_SUCCESS; ENTER(); if( rtnl_lock_held ) { if (strnchr(dev->name, strlen(dev->name), '%')) { if( dev_alloc_name(dev, dev->name) < 0 ) { hddLog(VOS_TRACE_LEVEL_FATAL, "%s:Failed:dev_alloc_name", __func__); return VOS_STATUS_E_FAILURE; } } if (register_netdevice(dev)) { hddLog(VOS_TRACE_LEVEL_FATAL, "%s:Failed:register_netdevice", __func__); return VOS_STATUS_E_FAILURE; } } else { if (register_netdev(dev)) { hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Failed:register_netdev", __func__); return VOS_STATUS_E_FAILURE; } } set_bit(NET_DEVICE_REGISTERED, &pAdapter->event_flags); EXIT(); return status; } VOS_STATUS hdd_unregister_hostapd(hdd_adapter_t *pAdapter) { ENTER(); hdd_softap_deinit_tx_rx(pAdapter); /* if we are being called during driver unload, then the dev has already been invalidated. if we are being called at other times, then we can detatch the wireless device handlers */ if (pAdapter->dev) { pAdapter->dev->wireless_handlers = NULL; } EXIT(); return 0; }
TeamEOS/kernel_oppo_msm8960
drivers/staging/prima/CORE/HDD/src/wlan_hdd_hostapd.c
C
gpl-2.0
124,150
/* Copyright_License { XCSoar Glide Computer - http://www.xcsoar.org/ Copyright (C) 2000-2016 The XCSoar Project A detailed list of copyright holders can be found in the file "AUTHORS". This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. } */ #include "Printing.hpp" #include "harness_waypoints.hpp" #include "Engine/Waypoint/Waypoints.hpp" #include "OS/FileUtil.hpp" #include "test_debug.hpp" #include <fstream> #include <iostream> #include <algorithm> /** * Initialises waypoints with random and non-random waypoints * for testing * * @param waypoints waypoints class to add waypoints to */ bool SetupWaypoints(Waypoints &waypoints, const unsigned n) { Waypoint wp = waypoints.Create(GeoPoint(Angle::Zero(), Angle::Zero())); wp.type = Waypoint::Type::AIRFIELD; wp.elevation = 0.25; waypoints.Append(std::move(wp)); wp = waypoints.Create(GeoPoint(Angle::Zero(), Angle::Degrees(1))); wp.type = Waypoint::Type::AIRFIELD; wp.elevation = 0.25; waypoints.Append(std::move(wp)); wp = waypoints.Create(GeoPoint(Angle::Degrees(1), Angle::Degrees(1))); wp.name = _T("Hello"); wp.type = Waypoint::Type::AIRFIELD; wp.elevation = 0.5; waypoints.Append(std::move(wp)); wp = waypoints.Create(GeoPoint(Angle::Degrees(0.8), Angle::Degrees(0.5))); wp.name = _T("Unk"); wp.type = Waypoint::Type::AIRFIELD; wp.elevation = 0.25; waypoints.Append(std::move(wp)); wp = waypoints.Create(GeoPoint(Angle::Degrees(1), Angle::Zero())); wp.type = Waypoint::Type::AIRFIELD; wp.elevation = 0.25; waypoints.Append(std::move(wp)); wp = waypoints.Create(GeoPoint(Angle::Zero(), Angle::Degrees(0.23))); wp.type = Waypoint::Type::AIRFIELD; wp.elevation = 0.25; waypoints.Append(std::move(wp)); for (unsigned i=0; i<(unsigned)std::max((int)n-6,0); i++) { int x = rand()%1200-100; int y = rand()%1200-100; double z = rand()% std::max(terrain_height,1); wp = waypoints.Create(GeoPoint(Angle::Degrees(x / 1000.0), Angle::Degrees(y / 1000.0))); wp.type = Waypoint::Type::NORMAL; wp.elevation = z; waypoints.Append(std::move(wp)); } waypoints.Optimise(); if (verbose) { Directory::Create(Path(_T("output/results"))); std::ofstream fin("output/results/res-wp-in.txt"); for (unsigned i=1; i<=waypoints.size(); i++) { const auto wpt = waypoints.LookupId(i); if (wpt) fin << *wpt; } } return true; }
glukolog/xcsoar
test/src/harness_waypoints.cpp
C++
gpl-2.0
3,299
/* * Signal Handling for ARC * * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * vineetg: Jan 2010 (Restarting of timer related syscalls) * * vineetg: Nov 2009 (Everything needed for TIF_RESTORE_SIGMASK) * -do_signal() supports TIF_RESTORE_SIGMASK * -do_signal() no loner needs oldset, required by OLD sys_sigsuspend * -sys_rt_sigsuspend() now comes from generic code, so discard arch implemen * -sys_sigsuspend() no longer needs to fudge ptregs, hence that arg removed * -sys_sigsuspend() no longer loops for do_signal(), sets TIF_xxx and leaves * the job to do_signal() * * vineetg: July 2009 * -Modified Code to support the uClibc provided userland sigreturn stub * to avoid kernel synthesing it on user stack at runtime, costing TLB * probes and Cache line flushes. * * vineetg: July 2009 * -In stash_usr_regs( ) and restore_usr_regs( ), save/restore of user regs * in done in block copy rather than one word at a time. * This saves around 2K of code and improves LMBench lat_sig <catch> * * rajeshwarr: Feb 2009 * - Support for Realtime Signals * * vineetg: Aug 11th 2008: Bug #94183 * -ViXS were still seeing crashes when using insmod to load drivers. * It turned out that the code to change Execute permssions for TLB entries * of user was not guarded for interrupts (mod_tlb_permission) * This was cauing TLB entries to be overwritten on unrelated indexes * * Vineetg: July 15th 2008: Bug #94183 * -Exception happens in Delay slot of a JMP, and before user space resumes, * Signal is delivered (Ctrl + C) = >SIGINT. * setup_frame( ) sets up PC,SP,BLINK to enable user space signal handler * to run, but doesn't clear the Delay slot bit from status32. As a result, * on resuming user mode, signal handler branches off to BTA of orig JMP * -FIX: clear the DE bit from status32 in setup_frame( ) * * Rahul Trivedi, Kanika Nema: Codito Technologies 2004 */ #include <linux/signal.h> #include <linux/ptrace.h> #include <linux/personality.h> #include <linux/uaccess.h> #include <linux/syscalls.h> #include <linux/tracehook.h> #include <asm/ucontext.h> struct rt_sigframe { struct siginfo info; struct ucontext uc; #define MAGIC_SIGALTSTK 0x07302004 unsigned int sigret_magic; }; static int stash_usr_regs(struct rt_sigframe __user *sf, struct pt_regs *regs, sigset_t *set) { int err; err = __copy_to_user(&(sf->uc.uc_mcontext.regs), regs, sizeof(sf->uc.uc_mcontext.regs.scratch)); err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(sigset_t)); return err; } static int restore_usr_regs(struct pt_regs *regs, struct rt_sigframe __user *sf) { sigset_t set; int err; err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set)); if (!err) set_current_blocked(&set); err |= __copy_from_user(regs, &(sf->uc.uc_mcontext.regs), sizeof(sf->uc.uc_mcontext.regs.scratch)); return err; } static inline int is_do_ss_needed(unsigned int magic) { if (MAGIC_SIGALTSTK == magic) return 1; else return 0; } SYSCALL_DEFINE0(rt_sigreturn) { struct rt_sigframe __user *sf; unsigned int magic; struct pt_regs *regs = current_pt_regs(); /* Always make any pending restarted system calls return -EINTR */ current_thread_info()->restart_block.fn = do_no_restart_syscall; /* Since we stacked the signal on a word boundary, * then 'sp' should be word aligned here. If it's * not, then the user is trying to mess with us. */ if (regs->sp & 3) goto badframe; sf = (struct rt_sigframe __force __user *)(regs->sp); if (!access_ok(VERIFY_READ, sf, sizeof(*sf))) goto badframe; if (__get_user(magic, &sf->sigret_magic)) goto badframe; if (unlikely(is_do_ss_needed(magic))) if (restore_altstack(&sf->uc.uc_stack)) goto badframe; if (restore_usr_regs(regs, sf)) goto badframe; /* Don't restart from sigreturn */ syscall_wont_restart(regs); return regs->r0; badframe: force_sig(SIGSEGV, current); return 0; } /* * Determine which stack to use.. */ static inline void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs, unsigned long framesize) { unsigned long sp = sigsp(regs->sp, ksig); void __user *frame; /* No matter what happens, 'sp' must be word * aligned otherwise nasty things could happen */ /* ATPCS B01 mandates 8-byte alignment */ frame = (void __user *)((sp - framesize) & ~7); /* Check that we can actually write to the signal frame */ if (!access_ok(VERIFY_WRITE, frame, framesize)) frame = NULL; return frame; } /* * translate the signal */ static inline int map_sig(int sig) { struct thread_info *thread = current_thread_info(); if (thread->exec_domain && thread->exec_domain->signal_invmap && sig < 32) sig = thread->exec_domain->signal_invmap[sig]; return sig; } static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs) { struct rt_sigframe __user *sf; unsigned int magic = 0; int err = 0; sf = get_sigframe(ksig, regs, sizeof(struct rt_sigframe)); if (!sf) return 1; /* * w/o SA_SIGINFO, struct ucontext is partially populated (only * uc_mcontext/uc_sigmask) for kernel's normal user state preservation * during signal handler execution. This works for SA_SIGINFO as well * although the semantics are now overloaded (the same reg state can be * inspected by userland: but are they allowed to fiddle with it ? */ err |= stash_usr_regs(sf, regs, set); /* * SA_SIGINFO requires 3 args to signal handler: * #1: sig-no (common to any handler) * #2: struct siginfo * #3: struct ucontext (completely populated) */ if (unlikely(ksig->ka.sa.sa_flags & SA_SIGINFO)) { err |= copy_siginfo_to_user(&sf->info, &ksig->info); err |= __put_user(0, &sf->uc.uc_flags); err |= __put_user(NULL, &sf->uc.uc_link); err |= __save_altstack(&sf->uc.uc_stack, regs->sp); /* setup args 2 and 3 for user mode handler */ regs->r1 = (unsigned long)&sf->info; regs->r2 = (unsigned long)&sf->uc; /* * small optim to avoid unconditonally calling do_sigaltstack * in sigreturn path, now that we only have rt_sigreturn */ magic = MAGIC_SIGALTSTK; } err |= __put_user(magic, &sf->sigret_magic); if (err) return err; /* #1 arg to the user Signal handler */ regs->r0 = map_sig(ksig->sig); /* setup PC of user space signal handler */ regs->ret = (unsigned long)ksig->ka.sa.sa_handler; /* * handler returns using sigreturn stub provided already by userpsace */ BUG_ON(!(ksig->ka.sa.sa_flags & SA_RESTORER)); regs->blink = (unsigned long)ksig->ka.sa.sa_restorer; /* User Stack for signal handler will be above the frame just carved */ regs->sp = (unsigned long)sf; /* * Bug 94183, Clear the DE bit, so that when signal handler * starts to run, it doesn't use BTA */ regs->status32 &= ~STATUS_DE_MASK; regs->status32 |= STATUS_L_MASK; return err; } static void arc_restart_syscall(struct k_sigaction *ka, struct pt_regs *regs) { switch (regs->r0) { case -ERESTART_RESTARTBLOCK: case -ERESTARTNOHAND: /* * ERESTARTNOHAND means that the syscall should * only be restarted if there was no handler for * the signal, and since we only get here if there * is a handler, we don't restart */ regs->r0 = -EINTR; /* ERESTART_xxx is internal */ break; case -ERESTARTSYS: /* * ERESTARTSYS means to restart the syscall if * there is no handler or the handler was * registered with SA_RESTART */ if (!(ka->sa.sa_flags & SA_RESTART)) { regs->r0 = -EINTR; break; } /* fallthrough */ case -ERESTARTNOINTR: /* * ERESTARTNOINTR means that the syscall should * be called again after the signal handler returns. * Setup reg state just as it was before doing the trap * r0 has been clobbered with sys call ret code thus it * needs to be reloaded with orig first arg to syscall * in orig_r0. Rest of relevant reg-file: * r8 (syscall num) and (r1 - r7) will be reset to * their orig user space value when we ret from kernel */ regs->r0 = regs->orig_r0; regs->ret -= 4; break; } } /* * OK, we're invoking a handler */ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs) { sigset_t *oldset = sigmask_to_save(); int ret; /* Set up the stack frame */ ret = setup_rt_frame(ksig, oldset, regs); signal_setup_done(ret, ksig, 0); } void do_signal(struct pt_regs *regs) { struct ksignal ksig; int restart_scall; restart_scall = in_syscall(regs) && syscall_restartable(regs); if (get_signal(&ksig)) { if (restart_scall) { arc_restart_syscall(&ksig.ka, regs); syscall_wont_restart(regs); /* No more restarts */ } handle_signal(&ksig, regs); return; } if (restart_scall) { /* No handler for syscall: restart it */ if (regs->r0 == -ERESTARTNOHAND || regs->r0 == -ERESTARTSYS || regs->r0 == -ERESTARTNOINTR) { regs->r0 = regs->orig_r0; regs->ret -= 4; } else if (regs->r0 == -ERESTART_RESTARTBLOCK) { regs->r8 = __NR_restart_syscall; regs->ret -= 4; } syscall_wont_restart(regs); /* No more restarts */ } /* If there's no signal to deliver, restore the saved sigmask back */ restore_saved_sigmask(); } void do_notify_resume(struct pt_regs *regs) { /* * ASM glue gaurantees that this is only called when returning to * user mode */ if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME)) tracehook_notify_resume(regs); }
abanerj/linux-mac
arch/arc/kernel/signal.c
C
gpl-2.0
9,602
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <linux/clk.h> #include <linux/delay.h> #include <linux/gpio.h> #include <linux/of_gpio.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/mfd/pm8xxx/pm8921.h> #include <linux/qpnp/clkdiv.h> #include <linux/io.h> #include <sound/core.h> #include <sound/soc.h> #include <sound/soc-dapm.h> #include <sound/pcm.h> #include <sound/jack.h> #include <asm/mach-types.h> #include <mach/socinfo.h> #include <qdsp6v2/msm-pcm-routing-v2.h> #include <sound/q6afe-v2.h> #include <linux/module.h> #include <mach/gpiomux.h> #include "../codecs/msm8x10-wcd.h" #define DRV_NAME "msm8x10-asoc-wcd" #define BTSCO_RATE_8KHZ 8000 #define BTSCO_RATE_16KHZ 16000 /* It takes about 13ms for Class-D PAs to ramp-up */ #define EXT_CLASS_D_EN_DELAY 13000 #define EXT_CLASS_D_DIS_DELAY 3000 #define EXT_CLASS_D_DELAY_DELTA 2000 #define CDC_EXT_CLK_RATE 9600000 #define WCD9XXX_MBHC_DEF_BUTTONS 8 #define WCD9XXX_MBHC_DEF_RLOADS 5 static int msm_btsco_rate = BTSCO_RATE_8KHZ; static int msm_btsco_ch = 1; static int msm_proxy_rx_ch = 2; static struct platform_device *spdev; static int ext_spk_amp_gpio = -1; /* pointers for digital codec register mappings */ static void __iomem *pcbcr; static void __iomem *prcgr; static int msm_sec_mi2s_rx_ch = 1; static int msm_pri_mi2s_tx_ch = 1; static int msm_sec_mi2s_rx_bit_format = SNDRV_PCM_FORMAT_S16_LE; static inline int param_is_mask(int p) { return ((p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) && (p <= SNDRV_PCM_HW_PARAM_LAST_MASK)); } static inline struct snd_mask *param_to_mask(struct snd_pcm_hw_params *p, int n) { return &(p->masks[n - SNDRV_PCM_HW_PARAM_FIRST_MASK]); } static void param_set_mask(struct snd_pcm_hw_params *p, int n, unsigned bit) { if (bit >= SNDRV_MASK_MAX) return; if (param_is_mask(n)) { struct snd_mask *m = param_to_mask(p, n); m->bits[0] = 0; m->bits[1] = 0; m->bits[bit >> 5] |= (1 << (bit & 31)); } } static void *def_msm8x10_wcd_mbhc_cal(void); static int msm8x10_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable, bool dapm); static struct wcd9xxx_mbhc_config mbhc_cfg = { .read_fw_bin = false, .calibration = NULL, .micbias = MBHC_MICBIAS1, .mclk_cb_fn = msm8x10_enable_codec_ext_clk, .mclk_rate = CDC_EXT_CLK_RATE, .gpio = 0, .gpio_irq = 0, .gpio_level_insert = 0, .detect_extn_cable = false, .insert_detect = true, .swap_gnd_mic = NULL, .use_int_rbias = false, .micbias_enable_flags = 1 << MBHC_MICBIAS_ENABLE_THRESHOLD_HEADSET | 1 << MBHC_MICBIAS_ENABLE_REGULAR_HEADSET, .cs_enable_flags = (1 << MBHC_CS_ENABLE_POLLING | 1 << MBHC_CS_ENABLE_INSERTION | 1 << MBHC_CS_ENABLE_REMOVAL), .do_recalibration = false, .use_vddio_meas = false, .hw_jack_type = FOUR_POLE_JACK, }; /* * There is limitation for the clock root selection from * either MI2S or DIG_CODEC. * If DIG_CODEC root can only provide 9.6MHz clock * to codec while MI2S only can provide * 12.288MHz. */ enum { DIG_CDC_CLK_SEL_DIG_CODEC, DIG_CDC_CLK_SEL_PRI_MI2S, DIG_CDC_CLK_SEL_SEC_MI2S, }; static struct afe_clk_cfg mi2s_rx_clk = { AFE_API_VERSION_I2S_CONFIG, Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ, Q6AFE_LPASS_OSR_CLK_12_P288_MHZ, Q6AFE_LPASS_CLK_SRC_INTERNAL, Q6AFE_LPASS_CLK_ROOT_DEFAULT, Q6AFE_LPASS_MODE_BOTH_VALID, 0, }; static struct afe_clk_cfg mi2s_tx_clk = { AFE_API_VERSION_I2S_CONFIG, Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ, Q6AFE_LPASS_OSR_CLK_12_P288_MHZ, Q6AFE_LPASS_CLK_SRC_INTERNAL, Q6AFE_LPASS_CLK_ROOT_DEFAULT, Q6AFE_LPASS_MODE_BOTH_VALID, 0, }; static struct afe_digital_clk_cfg digital_cdc_clk = { AFE_API_VERSION_I2S_CONFIG, 9600000, 5, /* Digital Codec root */ 0, }; static atomic_t mclk_rsc_ref; static struct mutex cdc_mclk_mutex; static int msm8x10_mclk_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event); static int msm_ext_spkramp_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event); static void msm8x10_enable_ext_spk_power_amp(u32 on); static const struct snd_soc_dapm_widget msm8x10_dapm_widgets[] = { SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0, msm8x10_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), SND_SOC_DAPM_SPK("Lineout amp", msm_ext_spkramp_event), SND_SOC_DAPM_MIC("Handset Mic", NULL), SND_SOC_DAPM_MIC("Headset Mic", NULL), SND_SOC_DAPM_MIC("Secondary Mic", NULL), SND_SOC_DAPM_MIC("Digital Mic1", NULL), SND_SOC_DAPM_MIC("Digital Mic2", NULL), }; static int msm8x10_ext_spk_power_amp_init(void) { int ret = 0; ext_spk_amp_gpio = of_get_named_gpio(spdev->dev.of_node, "qcom,ext-spk-amp-gpio", 0); if (ext_spk_amp_gpio >= 0) { ret = gpio_request(ext_spk_amp_gpio, "ext_spk_amp_gpio"); if (ret) { pr_err("%s: gpio_request failed for ext_spk_amp_gpio.\n", __func__); return -EINVAL; } gpio_direction_output(ext_spk_amp_gpio, 0); } return 0; } static int msm_ext_spkramp_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { pr_debug("%s()\n", __func__); if (ext_spk_amp_gpio >= 0) { if (SND_SOC_DAPM_EVENT_ON(event)) msm8x10_enable_ext_spk_power_amp(1); else msm8x10_enable_ext_spk_power_amp(0); } return 0; } static void msm8x10_enable_ext_spk_power_amp(u32 on) { if (on) { gpio_direction_output(ext_spk_amp_gpio, on); /*time takes enable the external power amplifier*/ usleep_range(EXT_CLASS_D_EN_DELAY, EXT_CLASS_D_EN_DELAY + EXT_CLASS_D_DELAY_DELTA); } else { gpio_direction_output(ext_spk_amp_gpio, on); /*time takes disable the external power amplifier*/ usleep_range(EXT_CLASS_D_DIS_DELAY, EXT_CLASS_D_DIS_DELAY + EXT_CLASS_D_DELAY_DELTA); } pr_debug("%s: %s external speaker PAs.\n", __func__, on ? "Enable" : "Disable"); } static int msm_config_mclk(u16 port_id, struct afe_digital_clk_cfg *cfg) { /* set the drive strength on the clock */ msm_tlmm_misc_reg_write(TLMM_CDC_HDRV_CTL, 0x00); msm_tlmm_misc_reg_write(TLMM_CDC_HDRV_PULL_CTL, 0x0006db6d); iowrite32(0x1, pcbcr); /* Set the update bit to make the settings go through */ iowrite32(0x1, prcgr); return 0; } static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); pr_debug("%s()\n", __func__); rate->min = rate->max = 48000; return 0; } static int msm_be_fm_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); pr_debug("%s()\n", __func__); rate->min = rate->max = 48000; channels->min = channels->max = 2; return 0; } static int msm_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); pr_debug("%s(): channel:%d\n", __func__, msm_pri_mi2s_tx_ch); param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, msm_sec_mi2s_rx_bit_format); rate->min = rate->max = 48000; channels->min = channels->max = msm_sec_mi2s_rx_ch; return 0; } static int msm_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); pr_debug("%s(), channel:%d\n", __func__, msm_pri_mi2s_tx_ch); param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, msm_sec_mi2s_rx_bit_format); rate->min = rate->max = 48000; channels->min = channels->max = msm_pri_mi2s_tx_ch; return 0; } static const char *const btsco_rate_text[] = {"BTSCO_RATE_8KHZ", "BTSCO_RATE_16KHZ"}; static const struct soc_enum msm_btsco_enum[] = { SOC_ENUM_SINGLE_EXT(2, btsco_rate_text), }; static const char *const sec_mi2s_rx_ch_text[] = {"One", "Two"}; static const char *const pri_mi2s_tx_ch_text[] = {"One", "Two"}; static int msm_btsco_rate_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { pr_debug("%s: msm_btsco_rate = %d", __func__, msm_btsco_rate); ucontrol->value.integer.value[0] = msm_btsco_rate; return 0; } static int msm_btsco_rate_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { switch (ucontrol->value.integer.value[0]) { case 0: msm_btsco_rate = BTSCO_RATE_8KHZ; break; case 1: msm_btsco_rate = BTSCO_RATE_16KHZ; break; default: msm_btsco_rate = BTSCO_RATE_8KHZ; break; } pr_debug("%s: msm_btsco_rate = %d\n", __func__, msm_btsco_rate); return 0; } static int msm_sec_mi2s_rx_ch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { pr_debug("%s: msm_sec_mi2s_rx_ch = %d\n", __func__, msm_sec_mi2s_rx_ch); ucontrol->value.integer.value[0] = msm_sec_mi2s_rx_ch - 1; return 0; } static int msm_sec_mi2s_rx_ch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { msm_sec_mi2s_rx_ch = ucontrol->value.integer.value[0] + 1; pr_debug("%s: msm_sec_mi2s_rx_ch = %d\n", __func__, msm_sec_mi2s_rx_ch); return 1; } static int msm_pri_mi2s_tx_ch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { pr_debug("%s: msm_pri_mi2s_tx_ch = %d\n", __func__, msm_pri_mi2s_tx_ch); ucontrol->value.integer.value[0] = msm_pri_mi2s_tx_ch - 1; return 0; } static int msm_pri_mi2s_tx_ch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { msm_pri_mi2s_tx_ch = ucontrol->value.integer.value[0] + 1; pr_debug("%s: msm_pri_mi2s_tx_ch = %d\n", __func__, msm_pri_mi2s_tx_ch); return 1; } static int msm_btsco_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); rate->min = rate->max = msm_btsco_rate; channels->min = channels->max = msm_btsco_ch; return 0; } static int msm_mi2s_snd_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { pr_debug("%s(): substream = %s stream = %d\n", __func__, substream->name, substream->stream); return 0; } static int mi2s_clk_ctl(struct snd_pcm_substream *substream, bool enable) { int ret = 0; if (enable) { digital_cdc_clk.clk_val = 9600000; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { mi2s_rx_clk.clk_val2 = Q6AFE_LPASS_OSR_CLK_12_P288_MHZ; mi2s_rx_clk.clk_val1 = Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ; ret = afe_set_lpass_clock(AFE_PORT_ID_SECONDARY_MI2S_RX, &mi2s_rx_clk); } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { mi2s_tx_clk.clk_val2 = Q6AFE_LPASS_OSR_CLK_12_P288_MHZ; mi2s_tx_clk.clk_val1 = Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ; ret = afe_set_lpass_clock(AFE_PORT_ID_PRIMARY_MI2S_RX, &mi2s_tx_clk); } else pr_err("%s:Not valid substream.\n", __func__); if (ret < 0) pr_err("%s:afe_set_lpass_clock failed\n", __func__); } else { digital_cdc_clk.clk_val = 0; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { mi2s_rx_clk.clk_val2 = Q6AFE_LPASS_OSR_CLK_DISABLE; mi2s_rx_clk.clk_val1 = Q6AFE_LPASS_IBIT_CLK_DISABLE; ret = afe_set_lpass_clock(AFE_PORT_ID_SECONDARY_MI2S_RX, &mi2s_rx_clk); } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { mi2s_tx_clk.clk_val2 = Q6AFE_LPASS_OSR_CLK_DISABLE; mi2s_tx_clk.clk_val1 = Q6AFE_LPASS_IBIT_CLK_DISABLE; ret = afe_set_lpass_clock(AFE_PORT_ID_PRIMARY_MI2S_RX, &mi2s_tx_clk); } else pr_err("%s:Not valid substream.\n", __func__); if (ret < 0) pr_err("%s:afe_set_lpass_clock failed\n", __func__); } return ret; } static int msm8x10_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable, bool dapm) { int ret = 0; mutex_lock(&cdc_mclk_mutex); pr_debug("%s: enable = %d codec name %s enable %d mclk ref counter %d\n", __func__, enable, codec->name, enable, atomic_read(&mclk_rsc_ref)); if (enable) { if (atomic_inc_return(&mclk_rsc_ref) == 1) { digital_cdc_clk.clk_val = 9600000; msm_config_mclk(AFE_PORT_ID_SECONDARY_MI2S_RX, &digital_cdc_clk); msm8x10_wcd_mclk_enable(codec, 1, dapm); } } else { if (atomic_dec_return(&mclk_rsc_ref) == 0) { digital_cdc_clk.clk_val = 0; msm8x10_wcd_mclk_enable(codec, 0, dapm); msm_config_mclk(AFE_PORT_ID_SECONDARY_MI2S_RX, &digital_cdc_clk); } } mutex_unlock(&cdc_mclk_mutex); return ret; } static int msm8x10_mclk_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { pr_debug("%s: event = %d\n", __func__, event); switch (event) { case SND_SOC_DAPM_PRE_PMU: return msm8x10_enable_codec_ext_clk(w->codec, 1, true); case SND_SOC_DAPM_POST_PMD: return msm8x10_enable_codec_ext_clk(w->codec, 0, true); default: return -EINVAL; } } static void msm_mi2s_snd_shutdown(struct snd_pcm_substream *substream) { int ret; pr_debug("%s(): substream = %s stream = %d\n", __func__, substream->name, substream->stream); ret = mi2s_clk_ctl(substream, false); if (ret < 0) pr_err("%s:clock disable failed\n", __func__); } static int msm_mi2s_snd_startup(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; int ret = 0; pr_debug("%s(): substream = %s stream = %d\n", __func__, substream->name, substream->stream); ret = mi2s_clk_ctl(substream, true); ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBS_CFS); if (ret < 0) pr_err("set fmt cpu dai failed\n"); return ret; } static const struct soc_enum msm_snd_enum[] = { SOC_ENUM_SINGLE_EXT(2, sec_mi2s_rx_ch_text), SOC_ENUM_SINGLE_EXT(2, pri_mi2s_tx_ch_text), }; static const struct snd_kcontrol_new msm_snd_controls[] = { SOC_ENUM_EXT("Internal BTSCO SampleRate", msm_btsco_enum[0], msm_btsco_rate_get, msm_btsco_rate_put), SOC_ENUM_EXT("MI2S_RX Channels", msm_snd_enum[0], msm_sec_mi2s_rx_ch_get, msm_sec_mi2s_rx_ch_put), SOC_ENUM_EXT("MI2S_TX Channels", msm_snd_enum[1], msm_pri_mi2s_tx_ch_get, msm_pri_mi2s_tx_ch_put), }; static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd) { struct snd_soc_codec *codec = rtd->codec; struct snd_soc_dapm_context *dapm = &codec->dapm; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; int ret = 0; pr_debug("%s(),dev_name%s\n", __func__, dev_name(cpu_dai->dev)); msm8x10_ext_spk_power_amp_init(); mbhc_cfg.calibration = def_msm8x10_wcd_mbhc_cal(); if (mbhc_cfg.calibration) { ret = msm8x10_wcd_hs_detect(codec, &mbhc_cfg); if (ret) { pr_err("%s: msm8x10_wcd_hs_detect failed\n", __func__); goto exit; } } else { ret = -ENOMEM; goto exit; } snd_soc_dapm_new_controls(dapm, msm8x10_dapm_widgets, ARRAY_SIZE(msm8x10_dapm_widgets)); snd_soc_dapm_enable_pin(dapm, "Lineout amp"); snd_soc_dapm_sync(dapm); ret = snd_soc_add_codec_controls(codec, msm_snd_controls, ARRAY_SIZE(msm_snd_controls)); if (ret < 0) return ret; exit: if (gpio_is_valid(ext_spk_amp_gpio)) gpio_free(ext_spk_amp_gpio); return ret; } static void *def_msm8x10_wcd_mbhc_cal(void) { void *msm8x10_wcd_cal; struct wcd9xxx_mbhc_btn_detect_cfg *btn_cfg; u16 *btn_low, *btn_high; u8 *n_ready, *n_cic, *gain; msm8x10_wcd_cal = kzalloc(WCD9XXX_MBHC_CAL_SIZE( WCD9XXX_MBHC_DEF_BUTTONS, WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL); if (!msm8x10_wcd_cal) { pr_err("%s: out of memory\n", __func__); return NULL; } #define S(X, Y) ((WCD9XXX_MBHC_CAL_GENERAL_PTR(msm8x10_wcd_cal)->X) = (Y)) S(t_ldoh, 100); S(t_bg_fast_settle, 100); S(t_shutdown_plug_rem, 255); S(mbhc_nsa, 2); S(mbhc_navg, 128); #undef S #define S(X, Y) ((WCD9XXX_MBHC_CAL_PLUG_DET_PTR(msm8x10_wcd_cal)->X) = (Y)) S(mic_current, MSM8X10_WCD_PID_MIC_5_UA); S(hph_current, MSM8X10_WCD_PID_MIC_5_UA); S(t_mic_pid, 100); S(t_ins_complete, 250); S(t_ins_retry, 200); #undef S #define S(X, Y) ((WCD9XXX_MBHC_CAL_PLUG_TYPE_PTR(msm8x10_wcd_cal)->X) = (Y)) S(v_no_mic, 30); S(v_hs_max, 2550); #undef S #define S(X, Y) ((WCD9XXX_MBHC_CAL_BTN_DET_PTR(msm8x10_wcd_cal)->X) = (Y)) S(c[0], 62); S(c[1], 124); S(nc, 1); S(n_meas, 5); S(mbhc_nsc, 10); S(n_btn_meas, 1); S(n_btn_con, 2); S(num_btn, WCD9XXX_MBHC_DEF_BUTTONS); S(v_btn_press_delta_sta, 100); S(v_btn_press_delta_cic, 50); #undef S btn_cfg = WCD9XXX_MBHC_CAL_BTN_DET_PTR(msm8x10_wcd_cal); btn_low = wcd9xxx_mbhc_cal_btn_det_mp(btn_cfg, MBHC_BTN_DET_V_BTN_LOW); btn_high = wcd9xxx_mbhc_cal_btn_det_mp(btn_cfg, MBHC_BTN_DET_V_BTN_HIGH); btn_low[0] = -50; btn_high[0] = 20; btn_low[1] = 21; btn_high[1] = 61; btn_low[2] = 62; btn_high[2] = 104; btn_low[3] = 105; btn_high[3] = 148; btn_low[4] = 149; btn_high[4] = 189; btn_low[5] = 190; btn_high[5] = 228; btn_low[6] = 229; btn_high[6] = 264; btn_low[7] = 265; btn_high[7] = 500; n_ready = wcd9xxx_mbhc_cal_btn_det_mp(btn_cfg, MBHC_BTN_DET_N_READY); n_ready[0] = 80; n_ready[1] = 68; n_cic = wcd9xxx_mbhc_cal_btn_det_mp(btn_cfg, MBHC_BTN_DET_N_CIC); n_cic[0] = 60; n_cic[1] = 47; gain = wcd9xxx_mbhc_cal_btn_det_mp(btn_cfg, MBHC_BTN_DET_GAIN); gain[0] = 11; gain[1] = 14; return msm8x10_wcd_cal; } static int msm_proxy_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); pr_debug("%s: msm_proxy_rx_ch =%d\n", __func__, msm_proxy_rx_ch); if (channels->max < 2) channels->min = channels->max = 2; channels->min = channels->max = msm_proxy_rx_ch; rate->min = rate->max = 48000; return 0; } static int msm_proxy_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); rate->min = rate->max = 48000; return 0; } static struct snd_soc_ops msm8x10_mi2s_be_ops = { .startup = msm_mi2s_snd_startup, .hw_params = msm_mi2s_snd_hw_params, .shutdown = msm_mi2s_snd_shutdown, }; /* Digital audio interface glue - connects codec <---> CPU */ static struct snd_soc_dai_link msm8x10_dai[] = { /* FrontEnd DAI Links */ {/* hw:x,0 */ .name = "MSM8X10 Media1", .stream_name = "MultiMedia1", .cpu_dai_name = "MultiMedia1", .platform_name = "msm-pcm-dsp.0", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .be_id = MSM_FRONTEND_DAI_MULTIMEDIA1 }, {/* hw:x,1 */ .name = "MSM8X10 Media2", .stream_name = "MultiMedia2", .cpu_dai_name = "MultiMedia2", .platform_name = "msm-pcm-dsp.0", .dynamic = 1, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .be_id = MSM_FRONTEND_DAI_MULTIMEDIA2, }, {/* hw:x,2 */ .name = "Circuit-Switch Voice", .stream_name = "CS-Voice", .cpu_dai_name = "CS-VOICE", .platform_name = "msm-pcm-voice", .dynamic = 1, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .be_id = MSM_FRONTEND_DAI_CS_VOICE, }, {/* hw:x,3 */ .name = "MSM VoIP", .stream_name = "VoIP", .cpu_dai_name = "VoIP", .platform_name = "msm-voip-dsp", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .be_id = MSM_FRONTEND_DAI_VOIP, }, {/* hw:x,4 */ .name = "MSM8X10 LPA", .stream_name = "LPA", .cpu_dai_name = "MultiMedia3", .platform_name = "msm-pcm-lpa", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .be_id = MSM_FRONTEND_DAI_MULTIMEDIA3, }, /* Hostless PCM purpose */ {/* hw:x,5 */ .name = "Secondary MI2S RX Hostless", .stream_name = "Secondary MI2S_RX Hostless Playback", .cpu_dai_name = "SEC_MI2S_RX_HOSTLESS", .platform_name = "msm-pcm-hostless", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, .ignore_suspend = 1, .ignore_pmdown_time = 1, /* This dainlink has MI2S support */ .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", }, {/* hw:x,6 */ .name = "INT_FM Hostless", .stream_name = "INT_FM Hostless", .cpu_dai_name = "INT_FM_HOSTLESS", .platform_name = "msm-pcm-hostless", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", }, {/* hw:x,7 */ .name = "MSM AFE-PCM RX", .stream_name = "AFE-PROXY RX", .cpu_dai_name = "msm-dai-q6-dev.241", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-rx", .platform_name = "msm-pcm-afe", .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, }, {/* hw:x,8 */ .name = "MSM AFE-PCM TX", .stream_name = "AFE-PROXY TX", .cpu_dai_name = "msm-dai-q6-dev.240", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-tx", .platform_name = "msm-pcm-afe", .ignore_suspend = 1, }, {/* hw:x,9 */ .name = "MSM8X10 Compr", .stream_name = "COMPR", .cpu_dai_name = "MultiMedia4", .platform_name = "msm-compress-dsp", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", .ignore_suspend = 1, .ignore_pmdown_time = 1, /* this dainlink has playback support */ .be_id = MSM_FRONTEND_DAI_MULTIMEDIA4, }, {/* hw:x,10 */ .name = "AUXPCM Hostless", .stream_name = "AUXPCM Hostless", .cpu_dai_name = "AUXPCM_HOSTLESS", .platform_name = "msm-pcm-hostless", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", }, {/* hw:x,11 */ .name = "Primary MI2S TX Hostless", .stream_name = "Primary MI2S_TX Hostless Capture", .cpu_dai_name = "PRI_MI2S_TX_HOSTLESS", .platform_name = "msm-pcm-hostless", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, .ignore_suspend = 1, .ignore_pmdown_time = 1, /* This dainlink has MI2S support */ .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", }, {/* hw:x,12 */ .name = "MSM8x10 LowLatency", .stream_name = "MultiMedia5", .cpu_dai_name = "MultiMedia5", .platform_name = "msm-pcm-dsp.1", .dynamic = 1, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .be_id = MSM_FRONTEND_DAI_MULTIMEDIA5, }, {/* hw:x,13 */ .name = "Voice2", .stream_name = "Voice2", .cpu_dai_name = "Voice2", .platform_name = "msm-pcm-voice", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", }, {/* hw:x,14 */ .name = "QCHAT", .stream_name = "QCHAT", .cpu_dai_name = "QCHAT", .platform_name = "msm-pcm-voice", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", .be_id = MSM_FRONTEND_DAI_QCHAT, }, {/* hw:x,15 */ .name = "MSM8X10 Media9", .stream_name = "MultiMedia9", .cpu_dai_name = "MultiMedia9", .platform_name = "msm-pcm-dsp.0", .dynamic = 1, .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, .codec_dai_name = "snd-soc-dummy-dai", .codec_name = "snd-soc-dummy", .ignore_suspend = 1, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .be_id = MSM_FRONTEND_DAI_MULTIMEDIA9 }, /* Backend I2S DAI Links */ { .name = LPASS_BE_SEC_MI2S_RX, .stream_name = "Secondary MI2S Playback", .cpu_dai_name = "msm-dai-q6-mi2s.1", .platform_name = "msm-pcm-routing", .codec_name = MSM8X10_CODEC_NAME, .codec_dai_name = "msm8x10_wcd_i2s_rx1", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_SECONDARY_MI2S_RX, .init = &msm_audrx_init, .be_hw_params_fixup = msm_rx_be_hw_params_fixup, .ops = &msm8x10_mi2s_be_ops, .ignore_suspend = 1, }, { .name = LPASS_BE_PRI_MI2S_TX, .stream_name = "Primary MI2S Capture", .cpu_dai_name = "msm-dai-q6-mi2s.0", .platform_name = "msm-pcm-routing", .codec_name = MSM8X10_CODEC_NAME, .codec_dai_name = "msm8x10_wcd_i2s_tx1", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_PRI_MI2S_TX, .be_hw_params_fixup = msm_tx_be_hw_params_fixup, .ops = &msm8x10_mi2s_be_ops, .ignore_suspend = 1, }, { .name = LPASS_BE_INT_BT_SCO_RX, .stream_name = "Internal BT-SCO Playback", .cpu_dai_name = "msm-dai-q6-dev.12288", .platform_name = "msm-pcm-routing", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-rx", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_INT_BT_SCO_RX, .be_hw_params_fixup = msm_btsco_be_hw_params_fixup, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .ignore_suspend = 1, }, { .name = LPASS_BE_INT_BT_SCO_TX, .stream_name = "Internal BT-SCO Capture", .cpu_dai_name = "msm-dai-q6-dev.12289", .platform_name = "msm-pcm-routing", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-tx", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_INT_BT_SCO_TX, .be_hw_params_fixup = msm_btsco_be_hw_params_fixup, .ignore_suspend = 1, }, { .name = LPASS_BE_INT_FM_RX, .stream_name = "Internal FM Playback", .cpu_dai_name = "msm-dai-q6-dev.12292", .platform_name = "msm-pcm-routing", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-rx", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_INT_FM_RX, .be_hw_params_fixup = msm_be_fm_hw_params_fixup, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .ignore_suspend = 1, }, { .name = LPASS_BE_INT_FM_TX, .stream_name = "Internal FM Capture", .cpu_dai_name = "msm-dai-q6-dev.12293", .platform_name = "msm-pcm-routing", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-tx", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_INT_FM_TX, .be_hw_params_fixup = msm_be_hw_params_fixup, .ignore_suspend = 1, }, { .name = LPASS_BE_AFE_PCM_RX, .stream_name = "AFE Playback", .cpu_dai_name = "msm-dai-q6-dev.224", .platform_name = "msm-pcm-routing", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-rx", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_AFE_PCM_RX, .be_hw_params_fixup = msm_proxy_rx_be_hw_params_fixup, /* this dainlink has playback support */ .ignore_pmdown_time = 1, .ignore_suspend = 1, }, { .name = LPASS_BE_AFE_PCM_TX, .stream_name = "AFE Capture", .cpu_dai_name = "msm-dai-q6-dev.225", .platform_name = "msm-pcm-routing", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-tx", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_AFE_PCM_TX, .be_hw_params_fixup = msm_proxy_tx_be_hw_params_fixup, .ignore_suspend = 1, }, /* Incall Record Uplink BACK END DAI Link */ { .name = LPASS_BE_INCALL_RECORD_TX, .stream_name = "Voice Uplink Capture", .cpu_dai_name = "msm-dai-q6-dev.32772", .platform_name = "msm-pcm-routing", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-tx", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_INCALL_RECORD_TX, .be_hw_params_fixup = msm_be_hw_params_fixup, .ignore_suspend = 1, }, /* Incall Record Downlink BACK END DAI Link */ { .name = LPASS_BE_INCALL_RECORD_RX, .stream_name = "Voice Downlink Capture", .cpu_dai_name = "msm-dai-q6-dev.32771", .platform_name = "msm-pcm-routing", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-tx", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_INCALL_RECORD_RX, .be_hw_params_fixup = msm_be_hw_params_fixup, .ignore_suspend = 1, }, /* Incall Music BACK END DAI Link */ { .name = LPASS_BE_VOICE_PLAYBACK_TX, .stream_name = "Voice Farend Playback", .cpu_dai_name = "msm-dai-q6-dev.32773", .platform_name = "msm-pcm-routing", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-rx", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_VOICE_PLAYBACK_TX, .be_hw_params_fixup = msm_be_hw_params_fixup, .ignore_suspend = 1, }, /* Incall Music 2 BACK END DAI Link */ { .name = LPASS_BE_VOICE2_PLAYBACK_TX, .stream_name = "Voice2 Farend Playback", .cpu_dai_name = "msm-dai-q6-dev.32770", .platform_name = "msm-pcm-routing", .codec_name = "msm-stub-codec.1", .codec_dai_name = "msm-stub-rx", .no_pcm = 1, .be_id = MSM_BACKEND_DAI_VOICE2_PLAYBACK_TX, .be_hw_params_fixup = msm_be_hw_params_fixup, .ignore_suspend = 1, }, }; struct snd_soc_card snd_soc_card_msm8x10 = { .name = "msm8x10-snd-card", .dai_link = msm8x10_dai, .num_links = ARRAY_SIZE(msm8x10_dai), }; static __devinit int msm8x10_asoc_machine_probe(struct platform_device *pdev) { struct snd_soc_card *card = &snd_soc_card_msm8x10; const char *mbhc_audio_jack_type = NULL; size_t n = strlen("4-pole-jack"); int ret; dev_dbg(&pdev->dev, "%s\n", __func__); if (!pdev->dev.of_node) { dev_err(&pdev->dev, "No platform supplied from device tree\n"); return -EINVAL; } card->dev = &pdev->dev; platform_set_drvdata(pdev, card); ret = snd_soc_of_parse_card_name(card, "qcom,model"); if (ret) goto err; ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing"); if (ret) goto err; mutex_init(&cdc_mclk_mutex); pcbcr = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_CBCR, 4); if (!pcbcr) { ret = -ENOMEM; goto err1; } prcgr = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_CMD_RCGR, 4); if (!prcgr) { ret = -ENOMEM; goto err1; } atomic_set(&mclk_rsc_ref, 0); mbhc_cfg.gpio_level_insert = of_property_read_bool(pdev->dev.of_node, "qcom,headset-jack-type-NC"); mbhc_cfg.use_int_rbias = of_property_read_bool(pdev->dev.of_node, "qcom,mbhc-bias-internal"); ret = of_property_read_string(pdev->dev.of_node, "qcom,mbhc-audio-jack-type", &mbhc_audio_jack_type); if (ret) { dev_dbg(&pdev->dev, "Looking up %s property in node %s failed", "qcom,mbhc-audio-jack-type", pdev->dev.of_node->full_name); mbhc_cfg.hw_jack_type = FOUR_POLE_JACK; mbhc_cfg.enable_anc_mic_detect = false; dev_dbg(&pdev->dev, "Jack type properties set to default"); } else { if (!strncmp(mbhc_audio_jack_type, "4-pole-jack", n)) { mbhc_cfg.hw_jack_type = FOUR_POLE_JACK; mbhc_cfg.enable_anc_mic_detect = false; dev_dbg(&pdev->dev, "This hardware has 4 pole jack"); } else if (!strncmp(mbhc_audio_jack_type, "5-pole-jack", n)) { mbhc_cfg.hw_jack_type = FIVE_POLE_JACK; mbhc_cfg.enable_anc_mic_detect = true; dev_dbg(&pdev->dev, "This hardware has 5 pole jack"); } else if (!strncmp(mbhc_audio_jack_type, "6-pole-jack", n)) { mbhc_cfg.hw_jack_type = SIX_POLE_JACK; mbhc_cfg.enable_anc_mic_detect = true; dev_dbg(&pdev->dev, "This hardware has 6 pole jack"); } else { mbhc_cfg.hw_jack_type = FOUR_POLE_JACK; mbhc_cfg.enable_anc_mic_detect = false; dev_dbg(&pdev->dev, "Unknown value, hence setting to default"); } } spdev = pdev; ret = snd_soc_register_card(card); if (ret == -EPROBE_DEFER) goto err1; else if (ret) { dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); goto err1; } return 0; err1: mutex_destroy(&cdc_mclk_mutex); if (pcbcr) iounmap(pcbcr); if (prcgr) iounmap(prcgr); err: return ret; } static int __devexit msm8x10_asoc_machine_remove(struct platform_device *pdev) { struct snd_soc_card *card = platform_get_drvdata(pdev); if (gpio_is_valid(ext_spk_amp_gpio)) gpio_free(ext_spk_amp_gpio); snd_soc_unregister_card(card); mutex_destroy(&cdc_mclk_mutex); iounmap(pcbcr); iounmap(prcgr); return 0; } static const struct of_device_id msm8x10_asoc_machine_of_match[] = { { .compatible = "qcom,msm8x10-audio-codec", }, {}, }; static struct platform_driver msm8x10_asoc_machine_driver = { .driver = { .name = DRV_NAME, .owner = THIS_MODULE, .pm = &snd_soc_pm_ops, .of_match_table = msm8x10_asoc_machine_of_match, }, .probe = msm8x10_asoc_machine_probe, .remove = __devexit_p(msm8x10_asoc_machine_remove), }; module_platform_driver(msm8x10_asoc_machine_driver); MODULE_DESCRIPTION("ALSA SoC msm"); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("platform:" DRV_NAME); MODULE_DEVICE_TABLE(of, msm8x10_asoc_machine_of_match);
AICP/kernel_lge_msm8974
sound/soc/msm/msm8x10.c
C
gpl-2.0
34,644
/* * Device operations for the pnfs nfs4 file layout driver. * * Copyright (c) 2002 * The Regents of the University of Michigan * All Rights Reserved * * Dean Hildebrand <dhildebz@umich.edu> * Garth Goodson <Garth.Goodson@netapp.com> * * Permission is granted to use, copy, create derivative works, and * redistribute this software and such derivative works for any purpose, * so long as the name of the University of Michigan is not used in * any advertising or publicity pertaining to the use or distribution * of this software without specific, written prior authorization. If * the above copyright notice or any other identification of the * University of Michigan is included in any copy of any portion of * this software, then the disclaimer below must also be included. * * This software is provided as is, without representation or warranty * of any kind either express or implied, including without limitation * the implied warranties of merchantability, fitness for a particular * purpose, or noninfringement. The Regents of the University of * Michigan shall not be liable for any damages, including special, * indirect, incidental, or consequential damages, with respect to any * claim arising out of or in connection with the use of the software, * even if it has been or is hereafter advised of the possibility of * such damages. */ #include <linux/nfs_fs.h> #include <linux/vmalloc.h> #include <linux/module.h> #include <linux/sunrpc/addr.h> #include "internal.h" #include "nfs4session.h" #include "nfs4filelayout.h" #define NFSDBG_FACILITY NFSDBG_PNFS_LD static unsigned int dataserver_timeo = NFS4_DEF_DS_TIMEO; static unsigned int dataserver_retrans = NFS4_DEF_DS_RETRANS; /* * Data server cache * * Data servers can be mapped to different device ids. * nfs4_pnfs_ds reference counting * - set to 1 on allocation * - incremented when a device id maps a data server already in the cache. * - decremented when deviceid is removed from the cache. */ static DEFINE_SPINLOCK(nfs4_ds_cache_lock); static LIST_HEAD(nfs4_data_server_cache); /* Debug routines */ void print_ds(struct nfs4_pnfs_ds *ds) { if (ds == NULL) { printk("%s NULL device\n", __func__); return; } printk(" ds %s\n" " ref count %d\n" " client %p\n" " cl_exchange_flags %x\n", ds->ds_remotestr, atomic_read(&ds->ds_count), ds->ds_clp, ds->ds_clp ? ds->ds_clp->cl_exchange_flags : 0); } static bool same_sockaddr(struct sockaddr *addr1, struct sockaddr *addr2) { struct sockaddr_in *a, *b; struct sockaddr_in6 *a6, *b6; if (addr1->sa_family != addr2->sa_family) return false; switch (addr1->sa_family) { case AF_INET: a = (struct sockaddr_in *)addr1; b = (struct sockaddr_in *)addr2; if (a->sin_addr.s_addr == b->sin_addr.s_addr && a->sin_port == b->sin_port) return true; break; case AF_INET6: a6 = (struct sockaddr_in6 *)addr1; b6 = (struct sockaddr_in6 *)addr2; /* LINKLOCAL addresses must have matching scope_id */ if (ipv6_addr_scope(&a6->sin6_addr) == IPV6_ADDR_SCOPE_LINKLOCAL && a6->sin6_scope_id != b6->sin6_scope_id) return false; if (ipv6_addr_equal(&a6->sin6_addr, &b6->sin6_addr) && a6->sin6_port == b6->sin6_port) return true; break; default: dprintk("%s: unhandled address family: %u\n", __func__, addr1->sa_family); return false; } return false; } static bool _same_data_server_addrs_locked(const struct list_head *dsaddrs1, const struct list_head *dsaddrs2) { struct nfs4_pnfs_ds_addr *da1, *da2; /* step through both lists, comparing as we go */ for (da1 = list_first_entry(dsaddrs1, typeof(*da1), da_node), da2 = list_first_entry(dsaddrs2, typeof(*da2), da_node); da1 != NULL && da2 != NULL; da1 = list_entry(da1->da_node.next, typeof(*da1), da_node), da2 = list_entry(da2->da_node.next, typeof(*da2), da_node)) { if (!same_sockaddr((struct sockaddr *)&da1->da_addr, (struct sockaddr *)&da2->da_addr)) return false; } if (da1 == NULL && da2 == NULL) return true; return false; } /* * Lookup DS by addresses. nfs4_ds_cache_lock is held */ static struct nfs4_pnfs_ds * _data_server_lookup_locked(const struct list_head *dsaddrs) { struct nfs4_pnfs_ds *ds; list_for_each_entry(ds, &nfs4_data_server_cache, ds_node) if (_same_data_server_addrs_locked(&ds->ds_addrs, dsaddrs)) return ds; return NULL; } /* * Create an rpc connection to the nfs4_pnfs_ds data server * Currently only supports IPv4 and IPv6 addresses */ static int nfs4_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds) { struct nfs_client *clp = ERR_PTR(-EIO); struct nfs4_pnfs_ds_addr *da; int status = 0; dprintk("--> %s DS %s au_flavor %d\n", __func__, ds->ds_remotestr, mds_srv->nfs_client->cl_rpcclient->cl_auth->au_flavor); list_for_each_entry(da, &ds->ds_addrs, da_node) { dprintk("%s: DS %s: trying address %s\n", __func__, ds->ds_remotestr, da->da_remotestr); clp = nfs4_set_ds_client(mds_srv->nfs_client, (struct sockaddr *)&da->da_addr, da->da_addrlen, IPPROTO_TCP, dataserver_timeo, dataserver_retrans); if (!IS_ERR(clp)) break; } if (IS_ERR(clp)) { status = PTR_ERR(clp); goto out; } status = nfs4_init_ds_session(clp, mds_srv->nfs_client->cl_lease_time); if (status) goto out_put; ds->ds_clp = clp; dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr); out: return status; out_put: nfs_put_client(clp); goto out; } static void destroy_ds(struct nfs4_pnfs_ds *ds) { struct nfs4_pnfs_ds_addr *da; dprintk("--> %s\n", __func__); ifdebug(FACILITY) print_ds(ds); if (ds->ds_clp) nfs_put_client(ds->ds_clp); while (!list_empty(&ds->ds_addrs)) { da = list_first_entry(&ds->ds_addrs, struct nfs4_pnfs_ds_addr, da_node); list_del_init(&da->da_node); kfree(da->da_remotestr); kfree(da); } kfree(ds->ds_remotestr); kfree(ds); } void nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) { struct nfs4_pnfs_ds *ds; int i; nfs4_print_deviceid(&dsaddr->id_node.deviceid); for (i = 0; i < dsaddr->ds_num; i++) { ds = dsaddr->ds_list[i]; if (ds != NULL) { if (atomic_dec_and_lock(&ds->ds_count, &nfs4_ds_cache_lock)) { list_del_init(&ds->ds_node); spin_unlock(&nfs4_ds_cache_lock); destroy_ds(ds); } } } kfree(dsaddr->stripe_indices); kfree(dsaddr); } /* * Create a string with a human readable address and port to avoid * complicated setup around many dprinks. */ static char * nfs4_pnfs_remotestr(struct list_head *dsaddrs, gfp_t gfp_flags) { struct nfs4_pnfs_ds_addr *da; char *remotestr; size_t len; char *p; len = 3; /* '{', '}' and eol */ list_for_each_entry(da, dsaddrs, da_node) { len += strlen(da->da_remotestr) + 1; /* string plus comma */ } remotestr = kzalloc(len, gfp_flags); if (!remotestr) return NULL; p = remotestr; *(p++) = '{'; len--; list_for_each_entry(da, dsaddrs, da_node) { size_t ll = strlen(da->da_remotestr); if (ll > len) goto out_err; memcpy(p, da->da_remotestr, ll); p += ll; len -= ll; if (len < 1) goto out_err; (*p++) = ','; len--; } if (len < 2) goto out_err; *(p++) = '}'; *p = '\0'; return remotestr; out_err: kfree(remotestr); return NULL; } static struct nfs4_pnfs_ds * nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags) { struct nfs4_pnfs_ds *tmp_ds, *ds = NULL; char *remotestr; if (list_empty(dsaddrs)) { dprintk("%s: no addresses defined\n", __func__); goto out; } ds = kzalloc(sizeof(*ds), gfp_flags); if (!ds) goto out; /* this is only used for debugging, so it's ok if its NULL */ remotestr = nfs4_pnfs_remotestr(dsaddrs, gfp_flags); spin_lock(&nfs4_ds_cache_lock); tmp_ds = _data_server_lookup_locked(dsaddrs); if (tmp_ds == NULL) { INIT_LIST_HEAD(&ds->ds_addrs); list_splice_init(dsaddrs, &ds->ds_addrs); ds->ds_remotestr = remotestr; atomic_set(&ds->ds_count, 1); INIT_LIST_HEAD(&ds->ds_node); ds->ds_clp = NULL; list_add(&ds->ds_node, &nfs4_data_server_cache); dprintk("%s add new data server %s\n", __func__, ds->ds_remotestr); } else { kfree(remotestr); kfree(ds); atomic_inc(&tmp_ds->ds_count); dprintk("%s data server %s found, inc'ed ds_count to %d\n", __func__, tmp_ds->ds_remotestr, atomic_read(&tmp_ds->ds_count)); ds = tmp_ds; } spin_unlock(&nfs4_ds_cache_lock); out: return ds; } /* * Currently only supports ipv4, ipv6 and one multi-path address. */ static struct nfs4_pnfs_ds_addr * decode_ds_addr(struct net *net, struct xdr_stream *streamp, gfp_t gfp_flags) { struct nfs4_pnfs_ds_addr *da = NULL; char *buf, *portstr; __be16 port; int nlen, rlen; int tmp[2]; __be32 *p; char *netid, *match_netid; size_t len, match_netid_len; char *startsep = ""; char *endsep = ""; /* r_netid */ p = xdr_inline_decode(streamp, 4); if (unlikely(!p)) goto out_err; nlen = be32_to_cpup(p++); p = xdr_inline_decode(streamp, nlen); if (unlikely(!p)) goto out_err; netid = kmalloc(nlen+1, gfp_flags); if (unlikely(!netid)) goto out_err; netid[nlen] = '\0'; memcpy(netid, p, nlen); /* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */ p = xdr_inline_decode(streamp, 4); if (unlikely(!p)) goto out_free_netid; rlen = be32_to_cpup(p); p = xdr_inline_decode(streamp, rlen); if (unlikely(!p)) goto out_free_netid; /* port is ".ABC.DEF", 8 chars max */ if (rlen > INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN + 8) { dprintk("%s: Invalid address, length %d\n", __func__, rlen); goto out_free_netid; } buf = kmalloc(rlen + 1, gfp_flags); if (!buf) { dprintk("%s: Not enough memory\n", __func__); goto out_free_netid; } buf[rlen] = '\0'; memcpy(buf, p, rlen); /* replace port '.' with '-' */ portstr = strrchr(buf, '.'); if (!portstr) { dprintk("%s: Failed finding expected dot in port\n", __func__); goto out_free_buf; } *portstr = '-'; /* find '.' between address and port */ portstr = strrchr(buf, '.'); if (!portstr) { dprintk("%s: Failed finding expected dot between address and " "port\n", __func__); goto out_free_buf; } *portstr = '\0'; da = kzalloc(sizeof(*da), gfp_flags); if (unlikely(!da)) goto out_free_buf; INIT_LIST_HEAD(&da->da_node); if (!rpc_pton(net, buf, portstr-buf, (struct sockaddr *)&da->da_addr, sizeof(da->da_addr))) { dprintk("%s: error parsing address %s\n", __func__, buf); goto out_free_da; } portstr++; sscanf(portstr, "%d-%d", &tmp[0], &tmp[1]); port = htons((tmp[0] << 8) | (tmp[1])); switch (da->da_addr.ss_family) { case AF_INET: ((struct sockaddr_in *)&da->da_addr)->sin_port = port; da->da_addrlen = sizeof(struct sockaddr_in); match_netid = "tcp"; match_netid_len = 3; break; case AF_INET6: ((struct sockaddr_in6 *)&da->da_addr)->sin6_port = port; da->da_addrlen = sizeof(struct sockaddr_in6); match_netid = "tcp6"; match_netid_len = 4; startsep = "["; endsep = "]"; break; default: dprintk("%s: unsupported address family: %u\n", __func__, da->da_addr.ss_family); goto out_free_da; } if (nlen != match_netid_len || strncmp(netid, match_netid, nlen)) { dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n", __func__, netid, match_netid); goto out_free_da; } /* save human readable address */ len = strlen(startsep) + strlen(buf) + strlen(endsep) + 7; da->da_remotestr = kzalloc(len, gfp_flags); /* NULL is ok, only used for dprintk */ if (da->da_remotestr) snprintf(da->da_remotestr, len, "%s%s%s:%u", startsep, buf, endsep, ntohs(port)); dprintk("%s: Parsed DS addr %s\n", __func__, da->da_remotestr); kfree(buf); kfree(netid); return da; out_free_da: kfree(da); out_free_buf: dprintk("%s: Error parsing DS addr: %s\n", __func__, buf); kfree(buf); out_free_netid: kfree(netid); out_err: return NULL; } /* Decode opaque device data and return the result */ static struct nfs4_file_layout_dsaddr* decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags) { int i; u32 cnt, num; u8 *indexp; __be32 *p; u8 *stripe_indices; u8 max_stripe_index; struct nfs4_file_layout_dsaddr *dsaddr = NULL; struct xdr_stream stream; struct xdr_buf buf; struct page *scratch; struct list_head dsaddrs; struct nfs4_pnfs_ds_addr *da; /* set up xdr stream */ scratch = alloc_page(gfp_flags); if (!scratch) goto out_err; xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen); xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); /* Get the stripe count (number of stripe index) */ p = xdr_inline_decode(&stream, 4); if (unlikely(!p)) goto out_err_free_scratch; cnt = be32_to_cpup(p); dprintk("%s stripe count %d\n", __func__, cnt); if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) { printk(KERN_WARNING "NFS: %s: stripe count %d greater than " "supported maximum %d\n", __func__, cnt, NFS4_PNFS_MAX_STRIPE_CNT); goto out_err_free_scratch; } /* read stripe indices */ stripe_indices = kcalloc(cnt, sizeof(u8), gfp_flags); if (!stripe_indices) goto out_err_free_scratch; p = xdr_inline_decode(&stream, cnt << 2); if (unlikely(!p)) goto out_err_free_stripe_indices; indexp = &stripe_indices[0]; max_stripe_index = 0; for (i = 0; i < cnt; i++) { *indexp = be32_to_cpup(p++); max_stripe_index = max(max_stripe_index, *indexp); indexp++; } /* Check the multipath list count */ p = xdr_inline_decode(&stream, 4); if (unlikely(!p)) goto out_err_free_stripe_indices; num = be32_to_cpup(p); dprintk("%s ds_num %u\n", __func__, num); if (num > NFS4_PNFS_MAX_MULTI_CNT) { printk(KERN_WARNING "NFS: %s: multipath count %d greater than " "supported maximum %d\n", __func__, num, NFS4_PNFS_MAX_MULTI_CNT); goto out_err_free_stripe_indices; } /* validate stripe indices are all < num */ if (max_stripe_index >= num) { printk(KERN_WARNING "NFS: %s: stripe index %u >= num ds %u\n", __func__, max_stripe_index, num); goto out_err_free_stripe_indices; } dsaddr = kzalloc(sizeof(*dsaddr) + (sizeof(struct nfs4_pnfs_ds *) * (num - 1)), gfp_flags); if (!dsaddr) goto out_err_free_stripe_indices; dsaddr->stripe_count = cnt; dsaddr->stripe_indices = stripe_indices; stripe_indices = NULL; dsaddr->ds_num = num; nfs4_init_deviceid_node(&dsaddr->id_node, NFS_SERVER(ino)->pnfs_curr_ld, NFS_SERVER(ino)->nfs_client, &pdev->dev_id); INIT_LIST_HEAD(&dsaddrs); for (i = 0; i < dsaddr->ds_num; i++) { int j; u32 mp_count; p = xdr_inline_decode(&stream, 4); if (unlikely(!p)) goto out_err_free_deviceid; mp_count = be32_to_cpup(p); /* multipath count */ for (j = 0; j < mp_count; j++) { da = decode_ds_addr(NFS_SERVER(ino)->nfs_client->cl_net, &stream, gfp_flags); if (da) list_add_tail(&da->da_node, &dsaddrs); } if (list_empty(&dsaddrs)) { dprintk("%s: no suitable DS addresses found\n", __func__); goto out_err_free_deviceid; } dsaddr->ds_list[i] = nfs4_pnfs_ds_add(&dsaddrs, gfp_flags); if (!dsaddr->ds_list[i]) goto out_err_drain_dsaddrs; /* If DS was already in cache, free ds addrs */ while (!list_empty(&dsaddrs)) { da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr, da_node); list_del_init(&da->da_node); kfree(da->da_remotestr); kfree(da); } } __free_page(scratch); return dsaddr; out_err_drain_dsaddrs: while (!list_empty(&dsaddrs)) { da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr, da_node); list_del_init(&da->da_node); kfree(da->da_remotestr); kfree(da); } out_err_free_deviceid: nfs4_fl_free_deviceid(dsaddr); /* stripe_indicies was part of dsaddr */ goto out_err_free_scratch; out_err_free_stripe_indices: kfree(stripe_indices); out_err_free_scratch: __free_page(scratch); out_err: dprintk("%s ERROR: returning NULL\n", __func__); return NULL; } /* * Decode the opaque device specified in 'dev' and add it to the cache of * available devices. */ static struct nfs4_file_layout_dsaddr * decode_and_add_device(struct inode *inode, struct pnfs_device *dev, gfp_t gfp_flags) { struct nfs4_deviceid_node *d; struct nfs4_file_layout_dsaddr *n, *new; new = decode_device(inode, dev, gfp_flags); if (!new) { printk(KERN_WARNING "NFS: %s: Could not decode or add device\n", __func__); return NULL; } d = nfs4_insert_deviceid_node(&new->id_node); n = container_of(d, struct nfs4_file_layout_dsaddr, id_node); if (n != new) { nfs4_fl_free_deviceid(new); return n; } return new; } /* * Retrieve the information for dev_id, add it to the list * of available devices, and return it. */ struct nfs4_file_layout_dsaddr * filelayout_get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_flags) { struct pnfs_device *pdev = NULL; u32 max_resp_sz; int max_pages; struct page **pages = NULL; struct nfs4_file_layout_dsaddr *dsaddr = NULL; int rc, i; struct nfs_server *server = NFS_SERVER(inode); /* * Use the session max response size as the basis for setting * GETDEVICEINFO's maxcount */ max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; max_pages = nfs_page_array_len(0, max_resp_sz); dprintk("%s inode %p max_resp_sz %u max_pages %d\n", __func__, inode, max_resp_sz, max_pages); pdev = kzalloc(sizeof(struct pnfs_device), gfp_flags); if (pdev == NULL) return NULL; pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags); if (pages == NULL) { kfree(pdev); return NULL; } for (i = 0; i < max_pages; i++) { pages[i] = alloc_page(gfp_flags); if (!pages[i]) goto out_free; } memcpy(&pdev->dev_id, dev_id, sizeof(*dev_id)); pdev->layout_type = LAYOUT_NFSV4_1_FILES; pdev->pages = pages; pdev->pgbase = 0; pdev->pglen = max_resp_sz; pdev->mincount = 0; rc = nfs4_proc_getdeviceinfo(server, pdev); dprintk("%s getdevice info returns %d\n", __func__, rc); if (rc) goto out_free; /* * Found new device, need to decode it and then add it to the * list of known devices for this mountpoint. */ dsaddr = decode_and_add_device(inode, pdev, gfp_flags); out_free: for (i = 0; i < max_pages; i++) __free_page(pages[i]); kfree(pages); kfree(pdev); dprintk("<-- %s dsaddr %p\n", __func__, dsaddr); return dsaddr; } void nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) { nfs4_put_deviceid_node(&dsaddr->id_node); } /* * Want res = (offset - layout->pattern_offset)/ layout->stripe_unit * Then: ((res + fsi) % dsaddr->stripe_count) */ u32 nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset) { struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); u64 tmp; tmp = offset - flseg->pattern_offset; do_div(tmp, flseg->stripe_unit); tmp += flseg->first_stripe_index; return do_div(tmp, flseg->dsaddr->stripe_count); } u32 nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j) { return FILELAYOUT_LSEG(lseg)->dsaddr->stripe_indices[j]; } struct nfs_fh * nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j) { struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); u32 i; if (flseg->stripe_type == STRIPE_SPARSE) { if (flseg->num_fh == 1) i = 0; else if (flseg->num_fh == 0) /* Use the MDS OPEN fh set in nfs_read_rpcsetup */ return NULL; else i = nfs4_fl_calc_ds_index(lseg, j); } else i = j; return flseg->fh_array[i]; } static void nfs4_wait_ds_connect(struct nfs4_pnfs_ds *ds) { might_sleep(); wait_on_bit(&ds->ds_state, NFS4DS_CONNECTING, nfs_wait_bit_killable, TASK_KILLABLE); } static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds *ds) { smp_mb__before_clear_bit(); clear_bit(NFS4DS_CONNECTING, &ds->ds_state); smp_mb__after_clear_bit(); wake_up_bit(&ds->ds_state, NFS4DS_CONNECTING); } struct nfs4_pnfs_ds * nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx) { struct nfs4_file_layout_dsaddr *dsaddr = FILELAYOUT_LSEG(lseg)->dsaddr; struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx]; struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg); struct nfs4_pnfs_ds *ret = ds; if (ds == NULL) { printk(KERN_ERR "NFS: %s: No data server for offset index %d\n", __func__, ds_idx); filelayout_mark_devid_invalid(devid); goto out; } if (ds->ds_clp) goto out_test_devid; if (test_and_set_bit(NFS4DS_CONNECTING, &ds->ds_state) == 0) { struct nfs_server *s = NFS_SERVER(lseg->pls_layout->plh_inode); int err; err = nfs4_ds_connect(s, ds); if (err) nfs4_mark_deviceid_unavailable(devid); nfs4_clear_ds_conn_bit(ds); } else { /* Either ds is connected, or ds is NULL */ nfs4_wait_ds_connect(ds); } out_test_devid: if (filelayout_test_devid_unavailable(devid)) ret = NULL; out: return ret; } module_param(dataserver_retrans, uint, 0644); MODULE_PARM_DESC(dataserver_retrans, "The number of times the NFSv4.1 client " "retries a request before it attempts further " " recovery action."); module_param(dataserver_timeo, uint, 0644); MODULE_PARM_DESC(dataserver_timeo, "The time (in tenths of a second) the " "NFSv4.1 client waits for a response from a " " data server before it retries an NFS request.");
Druboo666/android_kernel_asus_moorefield
fs/nfs/nfs4filelayoutdev.c
C
gpl-2.0
21,184
/* * controlfb.c -- frame buffer device for the PowerMac 'control' display * * Created 12 July 1998 by Dan Jacobowitz <dan@debian.org> * Copyright (C) 1998 Dan Jacobowitz * Copyright (C) 2001 Takashi Oe * * Mmap code by Michel Lanners <mlan@cpu.lu> * * Frame buffer structure from: * drivers/video/chipsfb.c -- frame buffer device for * Chips & Technologies 65550 chip. * * Copyright (C) 1998 Paul Mackerras * * This file is derived from the Powermac "chips" driver: * Copyright (C) 1997 Fabio Riccardi. * And from the frame buffer device for Open Firmware-initialized devices: * Copyright (C) 1997 Geert Uytterhoeven. * * Hardware information from: * control.c: Console support for PowerMac "control" display adaptor. * Copyright (C) 1996 Paul Mackerras * * Updated to 2.5 framebuffer API by Ben Herrenschmidt * <benh@kernel.crashing.org>, Paul Mackerras <paulus@samba.org>, * and James Simmons <jsimmons@infradead.org>. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive for * more details. */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/fb.h> #include <linux/init.h> #include <linux/pci.h> #include <linux/nvram.h> #include <linux/adb.h> #include <linux/cuda.h> #include <asm/io.h> #include <asm/prom.h> #include <asm/pgtable.h> #include <asm/btext.h> #include "macmodes.h" #include "controlfb.h" struct fb_par_control { int vmode, cmode; int xres, yres; int vxres, vyres; int xoffset, yoffset; int pitch; struct control_regvals regvals; unsigned long sync; unsigned char ctrl; }; #define DIRTY(z) ((x)->z != (y)->z) #define DIRTY_CMAP(z) (memcmp(&((x)->z), &((y)->z), sizeof((y)->z))) static inline int PAR_EQUAL(struct fb_par_control *x, struct fb_par_control *y) { int i, results; results = 1; for (i = 0; i < 3; i++) results &= !DIRTY(regvals.clock_params[i]); if (!results) return 0; for (i = 0; i < 16; i++) results &= !DIRTY(regvals.regs[i]); if (!results) return 0; return (!DIRTY(cmode) && !DIRTY(xres) && !DIRTY(yres) && !DIRTY(vxres) && !DIRTY(vyres)); } static inline int VAR_MATCH(struct fb_var_screeninfo *x, struct fb_var_screeninfo *y) { return (!DIRTY(bits_per_pixel) && !DIRTY(xres) && !DIRTY(yres) && !DIRTY(xres_virtual) && !DIRTY(yres_virtual) && !DIRTY_CMAP(red) && !DIRTY_CMAP(green) && !DIRTY_CMAP(blue)); } struct fb_info_control { struct fb_info info; struct fb_par_control par; u32 pseudo_palette[16]; struct cmap_regs __iomem *cmap_regs; unsigned long cmap_regs_phys; struct control_regs __iomem *control_regs; unsigned long control_regs_phys; unsigned long control_regs_size; __u8 __iomem *frame_buffer; unsigned long frame_buffer_phys; unsigned long fb_orig_base; unsigned long fb_orig_size; int control_use_bank2; unsigned long total_vram; unsigned char vram_attr; }; /* control register access macro */ #define CNTRL_REG(INFO,REG) (&(((INFO)->control_regs->REG).r)) /******************** Prototypes for exported functions ********************/ /* * struct fb_ops */ static int controlfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info); static int controlfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, u_int transp, struct fb_info *info); static int controlfb_blank(int blank_mode, struct fb_info *info); static int controlfb_mmap(struct fb_info *info, struct vm_area_struct *vma); static int controlfb_set_par (struct fb_info *info); static int controlfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info); /******************** Prototypes for internal functions **********************/ static void set_control_clock(unsigned char *params); static int init_control(struct fb_info_control *p); static void control_set_hardware(struct fb_info_control *p, struct fb_par_control *par); static int control_of_init(struct device_node *dp); static void find_vram_size(struct fb_info_control *p); static int read_control_sense(struct fb_info_control *p); static int calc_clock_params(unsigned long clk, unsigned char *param); static int control_var_to_par(struct fb_var_screeninfo *var, struct fb_par_control *par, const struct fb_info *fb_info); static inline void control_par_to_var(struct fb_par_control *par, struct fb_var_screeninfo *var); static void control_init_info(struct fb_info *info, struct fb_info_control *p); static void control_cleanup(void); /************************** Internal variables *******************************/ static struct fb_info_control *control_fb; static int default_vmode __initdata = VMODE_NVRAM; static int default_cmode __initdata = CMODE_NVRAM; static struct fb_ops controlfb_ops = { .owner = THIS_MODULE, .fb_check_var = controlfb_check_var, .fb_set_par = controlfb_set_par, .fb_setcolreg = controlfb_setcolreg, .fb_pan_display = controlfb_pan_display, .fb_blank = controlfb_blank, .fb_mmap = controlfb_mmap, .fb_fillrect = cfb_fillrect, .fb_copyarea = cfb_copyarea, .fb_imageblit = cfb_imageblit, }; /******************** The functions for controlfb_ops ********************/ #ifdef MODULE MODULE_LICENSE("GPL"); int init_module(void) { struct device_node *dp; int ret = -ENXIO; dp = of_find_node_by_name(NULL, "control"); if (dp != 0 && !control_of_init(dp)) ret = 0; of_node_put(dp); return ret; } void cleanup_module(void) { control_cleanup(); } #endif /* * Checks a var structure */ static int controlfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info) { struct fb_par_control par; int err; err = control_var_to_par(var, &par, info); if (err) return err; control_par_to_var(&par, var); return 0; } /* * Applies current var to display */ static int controlfb_set_par (struct fb_info *info) { struct fb_info_control *p = container_of(info, struct fb_info_control, info); struct fb_par_control par; int err; if((err = control_var_to_par(&info->var, &par, info))) { printk (KERN_ERR "controlfb_set_par: error calling" " control_var_to_par: %d.\n", err); return err; } control_set_hardware(p, &par); info->fix.visual = (p->par.cmode == CMODE_8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR; info->fix.line_length = p->par.pitch; info->fix.xpanstep = 32 >> p->par.cmode; info->fix.ypanstep = 1; return 0; } /* * Set screen start address according to var offset values */ static inline void set_screen_start(int xoffset, int yoffset, struct fb_info_control *p) { struct fb_par_control *par = &p->par; par->xoffset = xoffset; par->yoffset = yoffset; out_le32(CNTRL_REG(p,start_addr), par->yoffset * par->pitch + (par->xoffset << par->cmode)); } static int controlfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) { unsigned int xoffset, hstep; struct fb_info_control *p = container_of(info, struct fb_info_control, info); struct fb_par_control *par = &p->par; /* * make sure start addr will be 32-byte aligned */ hstep = 0x1f >> par->cmode; xoffset = (var->xoffset + hstep) & ~hstep; if (xoffset+par->xres > par->vxres || var->yoffset+par->yres > par->vyres) return -EINVAL; set_screen_start(xoffset, var->yoffset, p); return 0; } /* * Private mmap since we want to have a different caching on the framebuffer * for controlfb. * Note there's no locking in here; it's done in fb_mmap() in fbmem.c. */ static int controlfb_mmap(struct fb_info *info, struct vm_area_struct *vma) { unsigned long mmio_pgoff; unsigned long start; u32 len; start = info->fix.smem_start; len = info->fix.smem_len; mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT; if (vma->vm_pgoff >= mmio_pgoff) { if (info->var.accel_flags) return -EINVAL; vma->vm_pgoff -= mmio_pgoff; start = info->fix.mmio_start; len = info->fix.mmio_len; vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); } else { /* framebuffer */ vma->vm_page_prot = pgprot_cached_wthru(vma->vm_page_prot); } return vm_iomap_memory(vma, start, len); } static int controlfb_blank(int blank_mode, struct fb_info *info) { struct fb_info_control *p = container_of(info, struct fb_info_control, info); unsigned ctrl; ctrl = le32_to_cpup(CNTRL_REG(p,ctrl)); if (blank_mode > 0) switch (blank_mode) { case FB_BLANK_VSYNC_SUSPEND: ctrl &= ~3; break; case FB_BLANK_HSYNC_SUSPEND: ctrl &= ~0x30; break; case FB_BLANK_POWERDOWN: ctrl &= ~0x33; /* fall through */ case FB_BLANK_NORMAL: ctrl |= 0x400; break; default: break; } else { ctrl &= ~0x400; ctrl |= 0x33; } out_le32(CNTRL_REG(p,ctrl), ctrl); return 0; } static int controlfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, u_int transp, struct fb_info *info) { struct fb_info_control *p = container_of(info, struct fb_info_control, info); __u8 r, g, b; if (regno > 255) return 1; r = red >> 8; g = green >> 8; b = blue >> 8; out_8(&p->cmap_regs->addr, regno); /* tell clut what addr to fill */ out_8(&p->cmap_regs->lut, r); /* send one color channel at */ out_8(&p->cmap_regs->lut, g); /* a time... */ out_8(&p->cmap_regs->lut, b); if (regno < 16) { int i; switch (p->par.cmode) { case CMODE_16: p->pseudo_palette[regno] = (regno << 10) | (regno << 5) | regno; break; case CMODE_32: i = (regno << 8) | regno; p->pseudo_palette[regno] = (i << 16) | i; break; } } return 0; } /******************** End of controlfb_ops implementation ******************/ static void set_control_clock(unsigned char *params) { #ifdef CONFIG_ADB_CUDA struct adb_request req; int i; for (i = 0; i < 3; ++i) { cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x50, i + 1, params[i]); while (!req.complete) cuda_poll(); } #endif } /* * finish off the driver initialization and register */ static int __init init_control(struct fb_info_control *p) { int full, sense, vmode, cmode, vyres; struct fb_var_screeninfo var; int rc; printk(KERN_INFO "controlfb: "); full = p->total_vram == 0x400000; /* Try to pick a video mode out of NVRAM if we have one. */ #ifdef CONFIG_NVRAM if (default_cmode == CMODE_NVRAM) { cmode = nvram_read_byte(NV_CMODE); if(cmode < CMODE_8 || cmode > CMODE_32) cmode = CMODE_8; } else #endif cmode=default_cmode; #ifdef CONFIG_NVRAM if (default_vmode == VMODE_NVRAM) { vmode = nvram_read_byte(NV_VMODE); if (vmode < 1 || vmode > VMODE_MAX || control_mac_modes[vmode - 1].m[full] < cmode) { sense = read_control_sense(p); printk("Monitor sense value = 0x%x, ", sense); vmode = mac_map_monitor_sense(sense); if (control_mac_modes[vmode - 1].m[full] < cmode) vmode = VMODE_640_480_60; } } else #endif { vmode=default_vmode; if (control_mac_modes[vmode - 1].m[full] < cmode) { if (cmode > CMODE_8) cmode--; else vmode = VMODE_640_480_60; } } /* Initialize info structure */ control_init_info(&p->info, p); /* Setup default var */ if (mac_vmode_to_var(vmode, cmode, &var) < 0) { /* This shouldn't happen! */ printk("mac_vmode_to_var(%d, %d,) failed\n", vmode, cmode); try_again: vmode = VMODE_640_480_60; cmode = CMODE_8; if (mac_vmode_to_var(vmode, cmode, &var) < 0) { printk(KERN_ERR "controlfb: mac_vmode_to_var() failed\n"); return -ENXIO; } printk(KERN_INFO "controlfb: "); } printk("using video mode %d and color mode %d.\n", vmode, cmode); vyres = (p->total_vram - CTRLFB_OFF) / (var.xres << cmode); if (vyres > var.yres) var.yres_virtual = vyres; /* Apply default var */ var.activate = FB_ACTIVATE_NOW; rc = fb_set_var(&p->info, &var); if (rc && (vmode != VMODE_640_480_60 || cmode != CMODE_8)) goto try_again; /* Register with fbdev layer */ if (register_framebuffer(&p->info) < 0) return -ENXIO; fb_info(&p->info, "control display adapter\n"); return 0; } #define RADACAL_WRITE(a,d) \ out_8(&p->cmap_regs->addr, (a)); \ out_8(&p->cmap_regs->dat, (d)) /* Now how about actually saying, Make it so! */ /* Some things in here probably don't need to be done each time. */ static void control_set_hardware(struct fb_info_control *p, struct fb_par_control *par) { struct control_regvals *r; volatile struct preg __iomem *rp; int i, cmode; if (PAR_EQUAL(&p->par, par)) { /* * check if only xoffset or yoffset differs. * this prevents flickers in typical VT switch case. */ if (p->par.xoffset != par->xoffset || p->par.yoffset != par->yoffset) set_screen_start(par->xoffset, par->yoffset, p); return; } p->par = *par; cmode = p->par.cmode; r = &par->regvals; /* Turn off display */ out_le32(CNTRL_REG(p,ctrl), 0x400 | par->ctrl); set_control_clock(r->clock_params); RADACAL_WRITE(0x20, r->radacal_ctrl); RADACAL_WRITE(0x21, p->control_use_bank2 ? 0 : 1); RADACAL_WRITE(0x10, 0); RADACAL_WRITE(0x11, 0); rp = &p->control_regs->vswin; for (i = 0; i < 16; ++i, ++rp) out_le32(&rp->r, r->regs[i]); out_le32(CNTRL_REG(p,pitch), par->pitch); out_le32(CNTRL_REG(p,mode), r->mode); out_le32(CNTRL_REG(p,vram_attr), p->vram_attr); out_le32(CNTRL_REG(p,start_addr), par->yoffset * par->pitch + (par->xoffset << cmode)); out_le32(CNTRL_REG(p,rfrcnt), 0x1e5); out_le32(CNTRL_REG(p,intr_ena), 0); /* Turn on display */ out_le32(CNTRL_REG(p,ctrl), par->ctrl); #ifdef CONFIG_BOOTX_TEXT btext_update_display(p->frame_buffer_phys + CTRLFB_OFF, p->par.xres, p->par.yres, (cmode == CMODE_32? 32: cmode == CMODE_16? 16: 8), p->par.pitch); #endif /* CONFIG_BOOTX_TEXT */ } /* * Parse user specified options (`video=controlfb:') */ static void __init control_setup(char *options) { char *this_opt; if (!options || !*options) return; while ((this_opt = strsep(&options, ",")) != NULL) { if (!strncmp(this_opt, "vmode:", 6)) { int vmode = simple_strtoul(this_opt+6, NULL, 0); if (vmode > 0 && vmode <= VMODE_MAX && control_mac_modes[vmode - 1].m[1] >= 0) default_vmode = vmode; } else if (!strncmp(this_opt, "cmode:", 6)) { int depth = simple_strtoul(this_opt+6, NULL, 0); switch (depth) { case CMODE_8: case CMODE_16: case CMODE_32: default_cmode = depth; break; case 8: default_cmode = CMODE_8; break; case 15: case 16: default_cmode = CMODE_16; break; case 24: case 32: default_cmode = CMODE_32; break; } } } } static int __init control_init(void) { struct device_node *dp; char *option = NULL; int ret = -ENXIO; if (fb_get_options("controlfb", &option)) return -ENODEV; control_setup(option); dp = of_find_node_by_name(NULL, "control"); if (dp != 0 && !control_of_init(dp)) ret = 0; of_node_put(dp); return ret; } module_init(control_init); /* Work out which banks of VRAM we have installed. */ /* danj: I guess the card just ignores writes to nonexistant VRAM... */ static void __init find_vram_size(struct fb_info_control *p) { int bank1, bank2; /* * Set VRAM in 2MB (bank 1) mode * VRAM Bank 2 will be accessible through offset 0x600000 if present * and VRAM Bank 1 will not respond at that offset even if present */ out_le32(CNTRL_REG(p,vram_attr), 0x31); out_8(&p->frame_buffer[0x600000], 0xb3); out_8(&p->frame_buffer[0x600001], 0x71); asm volatile("eieio; dcbf 0,%0" : : "r" (&p->frame_buffer[0x600000]) : "memory" ); mb(); asm volatile("eieio; dcbi 0,%0" : : "r" (&p->frame_buffer[0x600000]) : "memory" ); mb(); bank2 = (in_8(&p->frame_buffer[0x600000]) == 0xb3) && (in_8(&p->frame_buffer[0x600001]) == 0x71); /* * Set VRAM in 2MB (bank 2) mode * VRAM Bank 1 will be accessible through offset 0x000000 if present * and VRAM Bank 2 will not respond at that offset even if present */ out_le32(CNTRL_REG(p,vram_attr), 0x39); out_8(&p->frame_buffer[0], 0x5a); out_8(&p->frame_buffer[1], 0xc7); asm volatile("eieio; dcbf 0,%0" : : "r" (&p->frame_buffer[0]) : "memory" ); mb(); asm volatile("eieio; dcbi 0,%0" : : "r" (&p->frame_buffer[0]) : "memory" ); mb(); bank1 = (in_8(&p->frame_buffer[0]) == 0x5a) && (in_8(&p->frame_buffer[1]) == 0xc7); if (bank2) { if (!bank1) { /* * vram bank 2 only */ p->control_use_bank2 = 1; p->vram_attr = 0x39; p->frame_buffer += 0x600000; p->frame_buffer_phys += 0x600000; } else { /* * 4 MB vram */ p->vram_attr = 0x51; } } else { /* * vram bank 1 only */ p->vram_attr = 0x31; } p->total_vram = (bank1 + bank2) * 0x200000; printk(KERN_INFO "controlfb: VRAM Total = %dMB " "(%dMB @ bank 1, %dMB @ bank 2)\n", (bank1 + bank2) << 1, bank1 << 1, bank2 << 1); } /* * find "control" and initialize */ static int __init control_of_init(struct device_node *dp) { struct fb_info_control *p; struct resource fb_res, reg_res; if (control_fb) { printk(KERN_ERR "controlfb: only one control is supported\n"); return -ENXIO; } if (of_pci_address_to_resource(dp, 2, &fb_res) || of_pci_address_to_resource(dp, 1, &reg_res)) { printk(KERN_ERR "can't get 2 addresses for control\n"); return -ENXIO; } p = kzalloc(sizeof(*p), GFP_KERNEL); if (p == 0) return -ENXIO; control_fb = p; /* save it for cleanups */ /* Map in frame buffer and registers */ p->fb_orig_base = fb_res.start; p->fb_orig_size = resource_size(&fb_res); /* use the big-endian aperture (??) */ p->frame_buffer_phys = fb_res.start + 0x800000; p->control_regs_phys = reg_res.start; p->control_regs_size = resource_size(&reg_res); if (!p->fb_orig_base || !request_mem_region(p->fb_orig_base,p->fb_orig_size,"controlfb")) { p->fb_orig_base = 0; goto error_out; } /* map at most 8MB for the frame buffer */ p->frame_buffer = __ioremap(p->frame_buffer_phys, 0x800000, _PAGE_WRITETHRU); if (!p->control_regs_phys || !request_mem_region(p->control_regs_phys, p->control_regs_size, "controlfb regs")) { p->control_regs_phys = 0; goto error_out; } p->control_regs = ioremap(p->control_regs_phys, p->control_regs_size); p->cmap_regs_phys = 0xf301b000; /* XXX not in prom? */ if (!request_mem_region(p->cmap_regs_phys, 0x1000, "controlfb cmap")) { p->cmap_regs_phys = 0; goto error_out; } p->cmap_regs = ioremap(p->cmap_regs_phys, 0x1000); if (!p->cmap_regs || !p->control_regs || !p->frame_buffer) goto error_out; find_vram_size(p); if (!p->total_vram) goto error_out; if (init_control(p) < 0) goto error_out; return 0; error_out: control_cleanup(); return -ENXIO; } /* * Get the monitor sense value. * Note that this can be called before calibrate_delay, * so we can't use udelay. */ static int read_control_sense(struct fb_info_control *p) { int sense; out_le32(CNTRL_REG(p,mon_sense), 7); /* drive all lines high */ __delay(200); out_le32(CNTRL_REG(p,mon_sense), 077); /* turn off drivers */ __delay(2000); sense = (in_le32(CNTRL_REG(p,mon_sense)) & 0x1c0) << 2; /* drive each sense line low in turn and collect the other 2 */ out_le32(CNTRL_REG(p,mon_sense), 033); /* drive A low */ __delay(2000); sense |= (in_le32(CNTRL_REG(p,mon_sense)) & 0xc0) >> 2; out_le32(CNTRL_REG(p,mon_sense), 055); /* drive B low */ __delay(2000); sense |= ((in_le32(CNTRL_REG(p,mon_sense)) & 0x100) >> 5) | ((in_le32(CNTRL_REG(p,mon_sense)) & 0x40) >> 4); out_le32(CNTRL_REG(p,mon_sense), 066); /* drive C low */ __delay(2000); sense |= (in_le32(CNTRL_REG(p,mon_sense)) & 0x180) >> 7; out_le32(CNTRL_REG(p,mon_sense), 077); /* turn off drivers */ return sense; } /********************** Various translation functions **********************/ #define CONTROL_PIXCLOCK_BASE 256016 #define CONTROL_PIXCLOCK_MIN 5000 /* ~ 200 MHz dot clock */ /* * calculate the clock paramaters to be sent to CUDA according to given * pixclock in pico second. */ static int calc_clock_params(unsigned long clk, unsigned char *param) { unsigned long p0, p1, p2, k, l, m, n, min; if (clk > (CONTROL_PIXCLOCK_BASE << 3)) return 1; p2 = ((clk << 4) < CONTROL_PIXCLOCK_BASE)? 3: 2; l = clk << p2; p0 = 0; p1 = 0; for (k = 1, min = l; k < 32; k++) { unsigned long rem; m = CONTROL_PIXCLOCK_BASE * k; n = m / l; rem = m % l; if (n && (n < 128) && rem < min) { p0 = k; p1 = n; min = rem; } } if (!p0 || !p1) return 1; param[0] = p0; param[1] = p1; param[2] = p2; return 0; } /* * This routine takes a user-supplied var, and picks the best vmode/cmode * from it. */ static int control_var_to_par(struct fb_var_screeninfo *var, struct fb_par_control *par, const struct fb_info *fb_info) { int cmode, piped_diff, hstep; unsigned hperiod, hssync, hsblank, hesync, heblank, piped, heq, hlfln, hserr, vperiod, vssync, vesync, veblank, vsblank, vswin, vewin; unsigned long pixclock; struct fb_info_control *p = container_of(fb_info, struct fb_info_control, info); struct control_regvals *r = &par->regvals; switch (var->bits_per_pixel) { case 8: par->cmode = CMODE_8; if (p->total_vram > 0x200000) { r->mode = 3; r->radacal_ctrl = 0x20; piped_diff = 13; } else { r->mode = 2; r->radacal_ctrl = 0x10; piped_diff = 9; } break; case 15: case 16: par->cmode = CMODE_16; if (p->total_vram > 0x200000) { r->mode = 2; r->radacal_ctrl = 0x24; piped_diff = 5; } else { r->mode = 1; r->radacal_ctrl = 0x14; piped_diff = 3; } break; case 32: par->cmode = CMODE_32; if (p->total_vram > 0x200000) { r->mode = 1; r->radacal_ctrl = 0x28; } else { r->mode = 0; r->radacal_ctrl = 0x18; } piped_diff = 1; break; default: return -EINVAL; } /* * adjust xres and vxres so that the corresponding memory widths are * 32-byte aligned */ hstep = 31 >> par->cmode; par->xres = (var->xres + hstep) & ~hstep; par->vxres = (var->xres_virtual + hstep) & ~hstep; par->xoffset = (var->xoffset + hstep) & ~hstep; if (par->vxres < par->xres) par->vxres = par->xres; par->pitch = par->vxres << par->cmode; par->yres = var->yres; par->vyres = var->yres_virtual; par->yoffset = var->yoffset; if (par->vyres < par->yres) par->vyres = par->yres; par->sync = var->sync; if (par->pitch * par->vyres + CTRLFB_OFF > p->total_vram) return -EINVAL; if (par->xoffset + par->xres > par->vxres) par->xoffset = par->vxres - par->xres; if (par->yoffset + par->yres > par->vyres) par->yoffset = par->vyres - par->yres; pixclock = (var->pixclock < CONTROL_PIXCLOCK_MIN)? CONTROL_PIXCLOCK_MIN: var->pixclock; if (calc_clock_params(pixclock, r->clock_params)) return -EINVAL; hperiod = ((var->left_margin + par->xres + var->right_margin + var->hsync_len) >> 1) - 2; hssync = hperiod + 1; hsblank = hssync - (var->right_margin >> 1); hesync = (var->hsync_len >> 1) - 1; heblank = (var->left_margin >> 1) + hesync; piped = heblank - piped_diff; heq = var->hsync_len >> 2; hlfln = (hperiod+2) >> 1; hserr = hssync-hesync; vperiod = (var->vsync_len + var->lower_margin + par->yres + var->upper_margin) << 1; vssync = vperiod - 2; vesync = (var->vsync_len << 1) - vperiod + vssync; veblank = (var->upper_margin << 1) + vesync; vsblank = vssync - (var->lower_margin << 1); vswin = (vsblank+vssync) >> 1; vewin = (vesync+veblank) >> 1; r->regs[0] = vswin; r->regs[1] = vsblank; r->regs[2] = veblank; r->regs[3] = vewin; r->regs[4] = vesync; r->regs[5] = vssync; r->regs[6] = vperiod; r->regs[7] = piped; r->regs[8] = hperiod; r->regs[9] = hsblank; r->regs[10] = heblank; r->regs[11] = hesync; r->regs[12] = hssync; r->regs[13] = heq; r->regs[14] = hlfln; r->regs[15] = hserr; if (par->xres >= 1280 && par->cmode >= CMODE_16) par->ctrl = 0x7f; else par->ctrl = 0x3b; if (mac_var_to_vmode(var, &par->vmode, &cmode)) par->vmode = 0; return 0; } /* * Convert hardware data in par to an fb_var_screeninfo */ static void control_par_to_var(struct fb_par_control *par, struct fb_var_screeninfo *var) { struct control_regints *rv; rv = (struct control_regints *) par->regvals.regs; memset(var, 0, sizeof(*var)); var->xres = par->xres; var->yres = par->yres; var->xres_virtual = par->vxres; var->yres_virtual = par->vyres; var->xoffset = par->xoffset; var->yoffset = par->yoffset; switch(par->cmode) { default: case CMODE_8: var->bits_per_pixel = 8; var->red.length = 8; var->green.length = 8; var->blue.length = 8; break; case CMODE_16: /* RGB 555 */ var->bits_per_pixel = 16; var->red.offset = 10; var->red.length = 5; var->green.offset = 5; var->green.length = 5; var->blue.length = 5; break; case CMODE_32: /* RGB 888 */ var->bits_per_pixel = 32; var->red.offset = 16; var->red.length = 8; var->green.offset = 8; var->green.length = 8; var->blue.length = 8; var->transp.offset = 24; var->transp.length = 8; break; } var->height = -1; var->width = -1; var->vmode = FB_VMODE_NONINTERLACED; var->left_margin = (rv->heblank - rv->hesync) << 1; var->right_margin = (rv->hssync - rv->hsblank) << 1; var->hsync_len = (rv->hperiod + 2 - rv->hssync + rv->hesync) << 1; var->upper_margin = (rv->veblank - rv->vesync) >> 1; var->lower_margin = (rv->vssync - rv->vsblank) >> 1; var->vsync_len = (rv->vperiod - rv->vssync + rv->vesync) >> 1; var->sync = par->sync; /* * 10^12 * clock_params[0] / (3906400 * clock_params[1] * * 2^clock_params[2]) * (10^12 * clock_params[0] / (3906400 * clock_params[1])) * >> clock_params[2] */ /* (255990.17 * clock_params[0] / clock_params[1]) >> clock_params[2] */ var->pixclock = CONTROL_PIXCLOCK_BASE * par->regvals.clock_params[0]; var->pixclock /= par->regvals.clock_params[1]; var->pixclock >>= par->regvals.clock_params[2]; } /* * Set misc info vars for this driver */ static void __init control_init_info(struct fb_info *info, struct fb_info_control *p) { /* Fill fb_info */ info->par = &p->par; info->fbops = &controlfb_ops; info->pseudo_palette = p->pseudo_palette; info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; info->screen_base = p->frame_buffer + CTRLFB_OFF; fb_alloc_cmap(&info->cmap, 256, 0); /* Fill fix common fields */ strcpy(info->fix.id, "control"); info->fix.mmio_start = p->control_regs_phys; info->fix.mmio_len = sizeof(struct control_regs); info->fix.type = FB_TYPE_PACKED_PIXELS; info->fix.smem_start = p->frame_buffer_phys + CTRLFB_OFF; info->fix.smem_len = p->total_vram - CTRLFB_OFF; info->fix.ywrapstep = 0; info->fix.type_aux = 0; info->fix.accel = FB_ACCEL_NONE; } static void control_cleanup(void) { struct fb_info_control *p = control_fb; if (!p) return; if (p->cmap_regs) iounmap(p->cmap_regs); if (p->control_regs) iounmap(p->control_regs); if (p->frame_buffer) { if (p->control_use_bank2) p->frame_buffer -= 0x600000; iounmap(p->frame_buffer); } if (p->cmap_regs_phys) release_mem_region(p->cmap_regs_phys, 0x1000); if (p->control_regs_phys) release_mem_region(p->control_regs_phys, p->control_regs_size); if (p->fb_orig_base) release_mem_region(p->fb_orig_base, p->fb_orig_size); kfree(p); }
rosterloh/linux
drivers/video/fbdev/controlfb.c
C
gpl-2.0
27,394
/*****************************************************************************/ /* * baycom_ser_hdx.c -- baycom ser12 halfduplex radio modem driver. * * Copyright (C) 1996-2000 Thomas Sailer (sailer@ife.ee.ethz.ch) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Please note that the GPL allows you to use the driver, NOT the radio. * In order to use the radio, you need a license from the communications * authority of your country. * * * Supported modems * * ser12: This is a very simple 1200 baud AFSK modem. The modem consists only * of a modulator/demodulator chip, usually a TI TCM3105. The computer * is responsible for regenerating the receiver bit clock, as well as * for handling the HDLC protocol. The modem connects to a serial port, * hence the name. Since the serial port is not used as an async serial * port, the kernel driver for serial ports cannot be used, and this * driver only supports standard serial hardware (8250, 16450, 16550A) * * * Command line options (insmod command line) * * mode ser12 hardware DCD * ser12* software DCD * ser12@ hardware/software DCD, i.e. no explicit DCD signal but hardware * mutes audio input to the modem * ser12+ hardware DCD, inverted signal at DCD pin * iobase base address of the port; common values are 0x3f8, 0x2f8, 0x3e8, 0x2e8 * irq interrupt line of the port; common values are 4,3 * * * History: * 0.1 26.06.1996 Adapted from baycom.c and made network driver interface * 18.10.1996 Changed to new user space access routines (copy_{to,from}_user) * 0.3 26.04.1997 init code/data tagged * 0.4 08.07.1997 alternative ser12 decoding algorithm (uses delta CTS ints) * 0.5 11.11.1997 ser12/par96 split into separate files * 0.6 14.04.1998 cleanups * 0.7 03.08.1999 adapt to Linus' new __setup/__initcall * 0.8 10.08.1999 use module_init/module_exit * 0.9 12.02.2000 adapted to softnet driver interface * 0.10 03.07.2000 fix interface name handling */ /*****************************************************************************/ #include <linux/capability.h> #include <linux/module.h> #include <linux/ioport.h> #include <linux/string.h> #include <linux/init.h> #include <asm/uaccess.h> #include <asm/io.h> #include <linux/hdlcdrv.h> #include <linux/baycom.h> #include <linux/jiffies.h> /* --------------------------------------------------------------------- */ #define BAYCOM_DEBUG /* --------------------------------------------------------------------- */ static const char bc_drvname[] = "baycom_ser_hdx"; static const char bc_drvinfo[] = KERN_INFO "baycom_ser_hdx: (C) 1996-2000 Thomas Sailer, HB9JNX/AE4WA\n" "baycom_ser_hdx: version 0.10 compiled " __TIME__ " " __DATE__ "\n"; /* --------------------------------------------------------------------- */ #define NR_PORTS 4 static struct net_device *baycom_device[NR_PORTS]; /* --------------------------------------------------------------------- */ #define RBR(iobase) (iobase+0) #define THR(iobase) (iobase+0) #define IER(iobase) (iobase+1) #define IIR(iobase) (iobase+2) #define FCR(iobase) (iobase+2) #define LCR(iobase) (iobase+3) #define MCR(iobase) (iobase+4) #define LSR(iobase) (iobase+5) #define MSR(iobase) (iobase+6) #define SCR(iobase) (iobase+7) #define DLL(iobase) (iobase+0) #define DLM(iobase) (iobase+1) #define SER12_EXTENT 8 /* ---------------------------------------------------------------------- */ /* * Information that need to be kept for each board. */ struct baycom_state { struct hdlcdrv_state hdrv; int opt_dcd; struct modem_state { short arb_divider; unsigned char flags; unsigned int shreg; struct modem_state_ser12 { unsigned char tx_bit; int dcd_sum0, dcd_sum1, dcd_sum2; unsigned char last_sample; unsigned char last_rxbit; unsigned int dcd_shreg; unsigned int dcd_time; unsigned int bit_pll; unsigned char interm_sample; } ser12; } modem; #ifdef BAYCOM_DEBUG struct debug_vals { unsigned long last_jiffies; unsigned cur_intcnt; unsigned last_intcnt; int cur_pllcorr; int last_pllcorr; } debug_vals; #endif /* BAYCOM_DEBUG */ }; /* --------------------------------------------------------------------- */ static inline void baycom_int_freq(struct baycom_state *bc) { #ifdef BAYCOM_DEBUG unsigned long cur_jiffies = jiffies; /* * measure the interrupt frequency */ bc->debug_vals.cur_intcnt++; if (time_after_eq(cur_jiffies, bc->debug_vals.last_jiffies + HZ)) { bc->debug_vals.last_jiffies = cur_jiffies; bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; bc->debug_vals.cur_intcnt = 0; bc->debug_vals.last_pllcorr = bc->debug_vals.cur_pllcorr; bc->debug_vals.cur_pllcorr = 0; } #endif /* BAYCOM_DEBUG */ } /* --------------------------------------------------------------------- */ /* * ===================== SER12 specific routines ========================= */ static inline void ser12_set_divisor(struct net_device *dev, unsigned char divisor) { outb(0x81, LCR(dev->base_addr)); /* DLAB = 1 */ outb(divisor, DLL(dev->base_addr)); outb(0, DLM(dev->base_addr)); outb(0x01, LCR(dev->base_addr)); /* word length = 6 */ /* * make sure the next interrupt is generated; * 0 must be used to power the modem; the modem draws its * power from the TxD line */ outb(0x00, THR(dev->base_addr)); /* * it is important not to set the divider while transmitting; * this reportedly makes some UARTs generating interrupts * in the hundredthousands per second region * Reported by: Ignacio.Arenaza@studi.epfl.ch (Ignacio Arenaza Nuno) */ } /* --------------------------------------------------------------------- */ /* * must call the TX arbitrator every 10ms */ #define SER12_ARB_DIVIDER(bc) (bc->opt_dcd ? 24 : 36) #define SER12_DCD_INTERVAL(bc) (bc->opt_dcd ? 12 : 240) static inline void ser12_tx(struct net_device *dev, struct baycom_state *bc) { /* one interrupt per channel bit */ ser12_set_divisor(dev, 12); /* * first output the last bit (!) then call HDLC transmitter, * since this may take quite long */ outb(0x0e | (!!bc->modem.ser12.tx_bit), MCR(dev->base_addr)); if (bc->modem.shreg <= 1) bc->modem.shreg = 0x10000 | hdlcdrv_getbits(&bc->hdrv); bc->modem.ser12.tx_bit = !(bc->modem.ser12.tx_bit ^ (bc->modem.shreg & 1)); bc->modem.shreg >>= 1; } /* --------------------------------------------------------------------- */ static inline void ser12_rx(struct net_device *dev, struct baycom_state *bc) { unsigned char cur_s; /* * do demodulator */ cur_s = inb(MSR(dev->base_addr)) & 0x10; /* the CTS line */ hdlcdrv_channelbit(&bc->hdrv, cur_s); bc->modem.ser12.dcd_shreg = (bc->modem.ser12.dcd_shreg << 1) | (cur_s != bc->modem.ser12.last_sample); bc->modem.ser12.last_sample = cur_s; if(bc->modem.ser12.dcd_shreg & 1) { if (!bc->opt_dcd) { unsigned int dcdspos, dcdsneg; dcdspos = dcdsneg = 0; dcdspos += ((bc->modem.ser12.dcd_shreg >> 1) & 1); if (!(bc->modem.ser12.dcd_shreg & 0x7ffffffe)) dcdspos += 2; dcdsneg += ((bc->modem.ser12.dcd_shreg >> 2) & 1); dcdsneg += ((bc->modem.ser12.dcd_shreg >> 3) & 1); dcdsneg += ((bc->modem.ser12.dcd_shreg >> 4) & 1); bc->modem.ser12.dcd_sum0 += 16*dcdspos - dcdsneg; } else bc->modem.ser12.dcd_sum0--; } if(!bc->modem.ser12.dcd_time) { hdlcdrv_setdcd(&bc->hdrv, (bc->modem.ser12.dcd_sum0 + bc->modem.ser12.dcd_sum1 + bc->modem.ser12.dcd_sum2) < 0); bc->modem.ser12.dcd_sum2 = bc->modem.ser12.dcd_sum1; bc->modem.ser12.dcd_sum1 = bc->modem.ser12.dcd_sum0; /* offset to ensure DCD off on silent input */ bc->modem.ser12.dcd_sum0 = 2; bc->modem.ser12.dcd_time = SER12_DCD_INTERVAL(bc); } bc->modem.ser12.dcd_time--; if (!bc->opt_dcd) { /* * PLL code for the improved software DCD algorithm */ if (bc->modem.ser12.interm_sample) { /* * intermediate sample; set timing correction to normal */ ser12_set_divisor(dev, 4); } else { /* * do PLL correction and call HDLC receiver */ switch (bc->modem.ser12.dcd_shreg & 7) { case 1: /* transition too late */ ser12_set_divisor(dev, 5); #ifdef BAYCOM_DEBUG bc->debug_vals.cur_pllcorr++; #endif /* BAYCOM_DEBUG */ break; case 4: /* transition too early */ ser12_set_divisor(dev, 3); #ifdef BAYCOM_DEBUG bc->debug_vals.cur_pllcorr--; #endif /* BAYCOM_DEBUG */ break; default: ser12_set_divisor(dev, 4); break; } bc->modem.shreg >>= 1; if (bc->modem.ser12.last_sample == bc->modem.ser12.last_rxbit) bc->modem.shreg |= 0x10000; bc->modem.ser12.last_rxbit = bc->modem.ser12.last_sample; } if (++bc->modem.ser12.interm_sample >= 3) bc->modem.ser12.interm_sample = 0; /* * DCD stuff */ if (bc->modem.ser12.dcd_shreg & 1) { unsigned int dcdspos, dcdsneg; dcdspos = dcdsneg = 0; dcdspos += ((bc->modem.ser12.dcd_shreg >> 1) & 1); dcdspos += (!(bc->modem.ser12.dcd_shreg & 0x7ffffffe)) << 1; dcdsneg += ((bc->modem.ser12.dcd_shreg >> 2) & 1); dcdsneg += ((bc->modem.ser12.dcd_shreg >> 3) & 1); dcdsneg += ((bc->modem.ser12.dcd_shreg >> 4) & 1); bc->modem.ser12.dcd_sum0 += 16*dcdspos - dcdsneg; } } else { /* * PLL algorithm for the hardware squelch DCD algorithm */ if (bc->modem.ser12.interm_sample) { /* * intermediate sample; set timing correction to normal */ ser12_set_divisor(dev, 6); } else { /* * do PLL correction and call HDLC receiver */ switch (bc->modem.ser12.dcd_shreg & 3) { case 1: /* transition too late */ ser12_set_divisor(dev, 7); #ifdef BAYCOM_DEBUG bc->debug_vals.cur_pllcorr++; #endif /* BAYCOM_DEBUG */ break; case 2: /* transition too early */ ser12_set_divisor(dev, 5); #ifdef BAYCOM_DEBUG bc->debug_vals.cur_pllcorr--; #endif /* BAYCOM_DEBUG */ break; default: ser12_set_divisor(dev, 6); break; } bc->modem.shreg >>= 1; if (bc->modem.ser12.last_sample == bc->modem.ser12.last_rxbit) bc->modem.shreg |= 0x10000; bc->modem.ser12.last_rxbit = bc->modem.ser12.last_sample; } bc->modem.ser12.interm_sample = !bc->modem.ser12.interm_sample; /* * DCD stuff */ bc->modem.ser12.dcd_sum0 -= (bc->modem.ser12.dcd_shreg & 1); } outb(0x0d, MCR(dev->base_addr)); /* transmitter off */ if (bc->modem.shreg & 1) { hdlcdrv_putbits(&bc->hdrv, bc->modem.shreg >> 1); bc->modem.shreg = 0x10000; } if(!bc->modem.ser12.dcd_time) { if (bc->opt_dcd & 1) hdlcdrv_setdcd(&bc->hdrv, !((inb(MSR(dev->base_addr)) ^ bc->opt_dcd) & 0x80)); else hdlcdrv_setdcd(&bc->hdrv, (bc->modem.ser12.dcd_sum0 + bc->modem.ser12.dcd_sum1 + bc->modem.ser12.dcd_sum2) < 0); bc->modem.ser12.dcd_sum2 = bc->modem.ser12.dcd_sum1; bc->modem.ser12.dcd_sum1 = bc->modem.ser12.dcd_sum0; /* offset to ensure DCD off on silent input */ bc->modem.ser12.dcd_sum0 = 2; bc->modem.ser12.dcd_time = SER12_DCD_INTERVAL(bc); } bc->modem.ser12.dcd_time--; } /* --------------------------------------------------------------------- */ static irqreturn_t ser12_interrupt(int irq, void *dev_id) { struct net_device *dev = (struct net_device *)dev_id; struct baycom_state *bc = netdev_priv(dev); unsigned char iir; if (!dev || !bc || bc->hdrv.magic != HDLCDRV_MAGIC) return IRQ_NONE; /* fast way out */ if ((iir = inb(IIR(dev->base_addr))) & 1) return IRQ_NONE; baycom_int_freq(bc); do { switch (iir & 6) { case 6: inb(LSR(dev->base_addr)); break; case 4: inb(RBR(dev->base_addr)); break; case 2: /* * check if transmitter active */ if (hdlcdrv_ptt(&bc->hdrv)) ser12_tx(dev, bc); else { ser12_rx(dev, bc); bc->modem.arb_divider--; } outb(0x00, THR(dev->base_addr)); break; default: inb(MSR(dev->base_addr)); break; } iir = inb(IIR(dev->base_addr)); } while (!(iir & 1)); if (bc->modem.arb_divider <= 0) { bc->modem.arb_divider = SER12_ARB_DIVIDER(bc); local_irq_enable(); hdlcdrv_arbitrate(dev, &bc->hdrv); } local_irq_enable(); hdlcdrv_transmitter(dev, &bc->hdrv); hdlcdrv_receiver(dev, &bc->hdrv); local_irq_disable(); return IRQ_HANDLED; } /* --------------------------------------------------------------------- */ enum uart { c_uart_unknown, c_uart_8250, c_uart_16450, c_uart_16550, c_uart_16550A}; static const char *uart_str[] = { "unknown", "8250", "16450", "16550", "16550A" }; static enum uart ser12_check_uart(unsigned int iobase) { unsigned char b1,b2,b3; enum uart u; enum uart uart_tab[] = { c_uart_16450, c_uart_unknown, c_uart_16550, c_uart_16550A }; b1 = inb(MCR(iobase)); outb(b1 | 0x10, MCR(iobase)); /* loopback mode */ b2 = inb(MSR(iobase)); outb(0x1a, MCR(iobase)); b3 = inb(MSR(iobase)) & 0xf0; outb(b1, MCR(iobase)); /* restore old values */ outb(b2, MSR(iobase)); if (b3 != 0x90) return c_uart_unknown; inb(RBR(iobase)); inb(RBR(iobase)); outb(0x01, FCR(iobase)); /* enable FIFOs */ u = uart_tab[(inb(IIR(iobase)) >> 6) & 3]; if (u == c_uart_16450) { outb(0x5a, SCR(iobase)); b1 = inb(SCR(iobase)); outb(0xa5, SCR(iobase)); b2 = inb(SCR(iobase)); if ((b1 != 0x5a) || (b2 != 0xa5)) u = c_uart_8250; } return u; } /* --------------------------------------------------------------------- */ static int ser12_open(struct net_device *dev) { struct baycom_state *bc = netdev_priv(dev); enum uart u; if (!dev || !bc) return -ENXIO; if (!dev->base_addr || dev->base_addr > 0x1000-SER12_EXTENT || dev->irq < 2 || dev->irq > 15) return -ENXIO; if (!request_region(dev->base_addr, SER12_EXTENT, "baycom_ser12")) return -EACCES; memset(&bc->modem, 0, sizeof(bc->modem)); bc->hdrv.par.bitrate = 1200; if ((u = ser12_check_uart(dev->base_addr)) == c_uart_unknown) { release_region(dev->base_addr, SER12_EXTENT); return -EIO; } outb(0, FCR(dev->base_addr)); /* disable FIFOs */ outb(0x0d, MCR(dev->base_addr)); outb(0, IER(dev->base_addr)); if (request_irq(dev->irq, ser12_interrupt, IRQF_DISABLED | IRQF_SHARED, "baycom_ser12", dev)) { release_region(dev->base_addr, SER12_EXTENT); return -EBUSY; } /* * enable transmitter empty interrupt */ outb(2, IER(dev->base_addr)); /* * set the SIO to 6 Bits/character and 19200 or 28800 baud, so that * we get exactly (hopefully) 2 or 3 interrupts per radio symbol, * depending on the usage of the software DCD routine */ ser12_set_divisor(dev, bc->opt_dcd ? 6 : 4); printk(KERN_INFO "%s: ser12 at iobase 0x%lx irq %u uart %s\n", bc_drvname, dev->base_addr, dev->irq, uart_str[u]); return 0; } /* --------------------------------------------------------------------- */ static int ser12_close(struct net_device *dev) { struct baycom_state *bc = netdev_priv(dev); if (!dev || !bc) return -EINVAL; /* * disable interrupts */ outb(0, IER(dev->base_addr)); outb(1, MCR(dev->base_addr)); free_irq(dev->irq, dev); release_region(dev->base_addr, SER12_EXTENT); printk(KERN_INFO "%s: close ser12 at iobase 0x%lx irq %u\n", bc_drvname, dev->base_addr, dev->irq); return 0; } /* --------------------------------------------------------------------- */ /* * ===================== hdlcdrv driver interface ========================= */ /* --------------------------------------------------------------------- */ static int baycom_ioctl(struct net_device *dev, struct ifreq *ifr, struct hdlcdrv_ioctl *hi, int cmd); /* --------------------------------------------------------------------- */ static struct hdlcdrv_ops ser12_ops = { .drvname = bc_drvname, .drvinfo = bc_drvinfo, .open = ser12_open, .close = ser12_close, .ioctl = baycom_ioctl, }; /* --------------------------------------------------------------------- */ static int baycom_setmode(struct baycom_state *bc, const char *modestr) { if (strchr(modestr, '*')) bc->opt_dcd = 0; else if (strchr(modestr, '+')) bc->opt_dcd = -1; else if (strchr(modestr, '@')) bc->opt_dcd = -2; else bc->opt_dcd = 1; return 0; } /* --------------------------------------------------------------------- */ static int baycom_ioctl(struct net_device *dev, struct ifreq *ifr, struct hdlcdrv_ioctl *hi, int cmd) { struct baycom_state *bc; struct baycom_ioctl bi; if (!dev) return -EINVAL; bc = netdev_priv(dev); BUG_ON(bc->hdrv.magic != HDLCDRV_MAGIC); if (cmd != SIOCDEVPRIVATE) return -ENOIOCTLCMD; switch (hi->cmd) { default: break; case HDLCDRVCTL_GETMODE: strcpy(hi->data.modename, "ser12"); if (bc->opt_dcd <= 0) strcat(hi->data.modename, (!bc->opt_dcd) ? "*" : (bc->opt_dcd == -2) ? "@" : "+"); if (copy_to_user(ifr->ifr_data, hi, sizeof(struct hdlcdrv_ioctl))) return -EFAULT; return 0; case HDLCDRVCTL_SETMODE: if (netif_running(dev) || !capable(CAP_NET_ADMIN)) return -EACCES; hi->data.modename[sizeof(hi->data.modename)-1] = '\0'; return baycom_setmode(bc, hi->data.modename); case HDLCDRVCTL_MODELIST: strcpy(hi->data.modename, "ser12"); if (copy_to_user(ifr->ifr_data, hi, sizeof(struct hdlcdrv_ioctl))) return -EFAULT; return 0; case HDLCDRVCTL_MODEMPARMASK: return HDLCDRV_PARMASK_IOBASE | HDLCDRV_PARMASK_IRQ; } if (copy_from_user(&bi, ifr->ifr_data, sizeof(bi))) return -EFAULT; switch (bi.cmd) { default: return -ENOIOCTLCMD; #ifdef BAYCOM_DEBUG case BAYCOMCTL_GETDEBUG: bi.data.dbg.debug1 = bc->hdrv.ptt_keyed; bi.data.dbg.debug2 = bc->debug_vals.last_intcnt; bi.data.dbg.debug3 = bc->debug_vals.last_pllcorr; break; #endif /* BAYCOM_DEBUG */ } if (copy_to_user(ifr->ifr_data, &bi, sizeof(bi))) return -EFAULT; return 0; } /* --------------------------------------------------------------------- */ /* * command line settable parameters */ static char *mode[NR_PORTS] = { "ser12*", }; static int iobase[NR_PORTS] = { 0x3f8, }; static int irq[NR_PORTS] = { 4, }; module_param_array(mode, charp, NULL, 0); MODULE_PARM_DESC(mode, "baycom operating mode; * for software DCD"); module_param_array(iobase, int, NULL, 0); MODULE_PARM_DESC(iobase, "baycom io base address"); module_param_array(irq, int, NULL, 0); MODULE_PARM_DESC(irq, "baycom irq number"); MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu"); MODULE_DESCRIPTION("Baycom ser12 half duplex amateur radio modem driver"); MODULE_LICENSE("GPL"); /* --------------------------------------------------------------------- */ static int __init init_baycomserhdx(void) { int i, found = 0; char set_hw = 1; printk(bc_drvinfo); /* * register net devices */ for (i = 0; i < NR_PORTS; i++) { struct net_device *dev; struct baycom_state *bc; char ifname[IFNAMSIZ]; sprintf(ifname, "bcsh%d", i); if (!mode[i]) set_hw = 0; if (!set_hw) iobase[i] = irq[i] = 0; dev = hdlcdrv_register(&ser12_ops, sizeof(struct baycom_state), ifname, iobase[i], irq[i], 0); if (IS_ERR(dev)) break; bc = netdev_priv(dev); if (set_hw && baycom_setmode(bc, mode[i])) set_hw = 0; found++; baycom_device[i] = dev; } if (!found) return -ENXIO; return 0; } static void __exit cleanup_baycomserhdx(void) { int i; for(i = 0; i < NR_PORTS; i++) { struct net_device *dev = baycom_device[i]; if (dev) hdlcdrv_unregister(dev); } } module_init(init_baycomserhdx); module_exit(cleanup_baycomserhdx); /* --------------------------------------------------------------------- */ #ifndef MODULE /* * format: baycom_ser_hdx=io,irq,mode * mode: ser12 hardware DCD * ser12* software DCD * ser12@ hardware/software DCD, i.e. no explicit DCD signal but hardware * mutes audio input to the modem * ser12+ hardware DCD, inverted signal at DCD pin */ static int __init baycom_ser_hdx_setup(char *str) { static unsigned nr_dev; int ints[3]; if (nr_dev >= NR_PORTS) return 0; str = get_options(str, 3, ints); if (ints[0] < 2) return 0; mode[nr_dev] = str; iobase[nr_dev] = ints[1]; irq[nr_dev] = ints[2]; nr_dev++; return 1; } __setup("baycom_ser_hdx=", baycom_ser_hdx_setup); #endif /* MODULE */ /* --------------------------------------------------------------------- */
johnweber/bbxm-kernel
drivers/net/hamradio/baycom_ser_hdx.c
C
gpl-2.0
21,025
/* * Sequencer Serial Port (SSP) driver for Texas Instruments' SoCs * * Copyright (C) 2010 Texas Instruments Inc * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/errno.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/init.h> #include <linux/wait.h> #include <linux/clk.h> #include <linux/interrupt.h> #include <linux/device.h> #include <linux/spinlock.h> #include <linux/platform_device.h> #include <linux/delay.h> #include <linux/io.h> #include <linux/mfd/core.h> #include <linux/mfd/ti_ssp.h> /* Register Offsets */ #define REG_REV 0x00 #define REG_IOSEL_1 0x04 #define REG_IOSEL_2 0x08 #define REG_PREDIV 0x0c #define REG_INTR_ST 0x10 #define REG_INTR_EN 0x14 #define REG_TEST_CTRL 0x18 /* Per port registers */ #define PORT_CFG_2 0x00 #define PORT_ADDR 0x04 #define PORT_DATA 0x08 #define PORT_CFG_1 0x0c #define PORT_STATE 0x10 #define SSP_PORT_CONFIG_MASK (SSP_EARLY_DIN | SSP_DELAY_DOUT) #define SSP_PORT_CLKRATE_MASK 0x0f #define SSP_SEQRAM_WR_EN BIT(4) #define SSP_SEQRAM_RD_EN BIT(5) #define SSP_START BIT(15) #define SSP_BUSY BIT(10) #define SSP_PORT_ASL BIT(7) #define SSP_PORT_CFO1 BIT(6) #define SSP_PORT_SEQRAM_SIZE 32 static const int ssp_port_base[] = {0x040, 0x080}; static const int ssp_port_seqram[] = {0x100, 0x180}; struct ti_ssp { struct resource *res; struct device *dev; void __iomem *regs; spinlock_t lock; struct clk *clk; int irq; wait_queue_head_t wqh; /* * Some of the iosel2 register bits always read-back as 0, we need to * remember these values so that we don't clobber previously set * values. */ u32 iosel2; }; static inline struct ti_ssp *dev_to_ssp(struct device *dev) { return dev_get_drvdata(dev->parent); } static inline int dev_to_port(struct device *dev) { return to_platform_device(dev)->id; } /* Register Access Helpers, rmw() functions need to run locked */ static inline u32 ssp_read(struct ti_ssp *ssp, int reg) { return __raw_readl(ssp->regs + reg); } static inline void ssp_write(struct ti_ssp *ssp, int reg, u32 val) { __raw_writel(val, ssp->regs + reg); } static inline void ssp_rmw(struct ti_ssp *ssp, int reg, u32 mask, u32 bits) { ssp_write(ssp, reg, (ssp_read(ssp, reg) & ~mask) | bits); } static inline u32 ssp_port_read(struct ti_ssp *ssp, int port, int reg) { return ssp_read(ssp, ssp_port_base[port] + reg); } static inline void ssp_port_write(struct ti_ssp *ssp, int port, int reg, u32 val) { ssp_write(ssp, ssp_port_base[port] + reg, val); } static inline void ssp_port_rmw(struct ti_ssp *ssp, int port, int reg, u32 mask, u32 bits) { ssp_rmw(ssp, ssp_port_base[port] + reg, mask, bits); } static inline void ssp_port_clr_bits(struct ti_ssp *ssp, int port, int reg, u32 bits) { ssp_port_rmw(ssp, port, reg, bits, 0); } static inline void ssp_port_set_bits(struct ti_ssp *ssp, int port, int reg, u32 bits) { ssp_port_rmw(ssp, port, reg, 0, bits); } /* Called to setup port clock mode, caller must hold ssp->lock */ static int __set_mode(struct ti_ssp *ssp, int port, int mode) { mode &= SSP_PORT_CONFIG_MASK; ssp_port_rmw(ssp, port, PORT_CFG_1, SSP_PORT_CONFIG_MASK, mode); return 0; } int ti_ssp_set_mode(struct device *dev, int mode) { struct ti_ssp *ssp = dev_to_ssp(dev); int port = dev_to_port(dev); int ret; spin_lock(&ssp->lock); ret = __set_mode(ssp, port, mode); spin_unlock(&ssp->lock); return ret; } EXPORT_SYMBOL(ti_ssp_set_mode); /* Called to setup iosel2, caller must hold ssp->lock */ static void __set_iosel2(struct ti_ssp *ssp, u32 mask, u32 val) { ssp->iosel2 = (ssp->iosel2 & ~mask) | val; ssp_write(ssp, REG_IOSEL_2, ssp->iosel2); } /* Called to setup port iosel, caller must hold ssp->lock */ static void __set_iosel(struct ti_ssp *ssp, int port, u32 iosel) { unsigned val, shift = port ? 16 : 0; /* IOSEL1 gets the least significant 16 bits */ val = ssp_read(ssp, REG_IOSEL_1); val &= 0xffff << (port ? 0 : 16); val |= (iosel & 0xffff) << (port ? 16 : 0); ssp_write(ssp, REG_IOSEL_1, val); /* IOSEL2 gets the most significant 16 bits */ val = (iosel >> 16) & 0x7; __set_iosel2(ssp, 0x7 << shift, val << shift); } int ti_ssp_set_iosel(struct device *dev, u32 iosel) { struct ti_ssp *ssp = dev_to_ssp(dev); int port = dev_to_port(dev); spin_lock(&ssp->lock); __set_iosel(ssp, port, iosel); spin_unlock(&ssp->lock); return 0; } EXPORT_SYMBOL(ti_ssp_set_iosel); int ti_ssp_load(struct device *dev, int offs, u32* prog, int len) { struct ti_ssp *ssp = dev_to_ssp(dev); int port = dev_to_port(dev); int i; if (len > SSP_PORT_SEQRAM_SIZE) return -ENOSPC; spin_lock(&ssp->lock); /* Enable SeqRAM access */ ssp_port_set_bits(ssp, port, PORT_CFG_2, SSP_SEQRAM_WR_EN); /* Copy code */ for (i = 0; i < len; i++) { __raw_writel(prog[i], ssp->regs + offs + 4*i + ssp_port_seqram[port]); } /* Disable SeqRAM access */ ssp_port_clr_bits(ssp, port, PORT_CFG_2, SSP_SEQRAM_WR_EN); spin_unlock(&ssp->lock); return 0; } EXPORT_SYMBOL(ti_ssp_load); int ti_ssp_raw_read(struct device *dev) { struct ti_ssp *ssp = dev_to_ssp(dev); int port = dev_to_port(dev); int shift = port ? 27 : 11; return (ssp_read(ssp, REG_IOSEL_2) >> shift) & 0xf; } EXPORT_SYMBOL(ti_ssp_raw_read); int ti_ssp_raw_write(struct device *dev, u32 val) { struct ti_ssp *ssp = dev_to_ssp(dev); int port = dev_to_port(dev), shift; spin_lock(&ssp->lock); shift = port ? 22 : 6; val &= 0xf; __set_iosel2(ssp, 0xf << shift, val << shift); spin_unlock(&ssp->lock); return 0; } EXPORT_SYMBOL(ti_ssp_raw_write); static inline int __xfer_done(struct ti_ssp *ssp, int port) { return !(ssp_port_read(ssp, port, PORT_CFG_1) & SSP_BUSY); } int ti_ssp_run(struct device *dev, u32 pc, u32 input, u32 *output) { struct ti_ssp *ssp = dev_to_ssp(dev); int port = dev_to_port(dev); int ret; if (pc & ~(0x3f)) return -EINVAL; /* Grab ssp->lock to serialize rmw on ssp registers */ spin_lock(&ssp->lock); ssp_port_write(ssp, port, PORT_ADDR, input >> 16); ssp_port_write(ssp, port, PORT_DATA, input & 0xffff); ssp_port_rmw(ssp, port, PORT_CFG_1, 0x3f, pc); /* grab wait queue head lock to avoid race with the isr */ spin_lock_irq(&ssp->wqh.lock); /* kick off sequence execution in hardware */ ssp_port_set_bits(ssp, port, PORT_CFG_1, SSP_START); /* drop ssp lock; no register writes beyond this */ spin_unlock(&ssp->lock); ret = wait_event_interruptible_locked_irq(ssp->wqh, __xfer_done(ssp, port)); spin_unlock_irq(&ssp->wqh.lock); if (ret < 0) return ret; if (output) { *output = (ssp_port_read(ssp, port, PORT_ADDR) << 16) | (ssp_port_read(ssp, port, PORT_DATA) & 0xffff); } ret = ssp_port_read(ssp, port, PORT_STATE) & 0x3f; /* stop address */ return ret; } EXPORT_SYMBOL(ti_ssp_run); static irqreturn_t ti_ssp_interrupt(int irq, void *dev_data) { struct ti_ssp *ssp = dev_data; spin_lock(&ssp->wqh.lock); ssp_write(ssp, REG_INTR_ST, 0x3); wake_up_locked(&ssp->wqh); spin_unlock(&ssp->wqh.lock); return IRQ_HANDLED; } static int ti_ssp_probe(struct platform_device *pdev) { static struct ti_ssp *ssp; const struct ti_ssp_data *pdata = pdev->dev.platform_data; int error = 0, prediv = 0xff, id; unsigned long sysclk; struct device *dev = &pdev->dev; struct mfd_cell cells[2]; ssp = kzalloc(sizeof(*ssp), GFP_KERNEL); if (!ssp) { dev_err(dev, "cannot allocate device info\n"); return -ENOMEM; } ssp->dev = dev; dev_set_drvdata(dev, ssp); ssp->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!ssp->res) { error = -ENODEV; dev_err(dev, "cannot determine register area\n"); goto error_res; } if (!request_mem_region(ssp->res->start, resource_size(ssp->res), pdev->name)) { error = -ENOMEM; dev_err(dev, "cannot claim register memory\n"); goto error_res; } ssp->regs = ioremap(ssp->res->start, resource_size(ssp->res)); if (!ssp->regs) { error = -ENOMEM; dev_err(dev, "cannot map register memory\n"); goto error_map; } ssp->clk = clk_get(dev, NULL); if (IS_ERR(ssp->clk)) { error = PTR_ERR(ssp->clk); dev_err(dev, "cannot claim device clock\n"); goto error_clk; } ssp->irq = platform_get_irq(pdev, 0); if (ssp->irq < 0) { error = -ENODEV; dev_err(dev, "unknown irq\n"); goto error_irq; } error = request_threaded_irq(ssp->irq, NULL, ti_ssp_interrupt, 0, dev_name(dev), ssp); if (error < 0) { dev_err(dev, "cannot acquire irq\n"); goto error_irq; } spin_lock_init(&ssp->lock); init_waitqueue_head(&ssp->wqh); /* Power on and initialize SSP */ error = clk_enable(ssp->clk); if (error) { dev_err(dev, "cannot enable device clock\n"); goto error_enable; } /* Reset registers to a sensible known state */ ssp_write(ssp, REG_IOSEL_1, 0); ssp_write(ssp, REG_IOSEL_2, 0); ssp_write(ssp, REG_INTR_EN, 0x3); ssp_write(ssp, REG_INTR_ST, 0x3); ssp_write(ssp, REG_TEST_CTRL, 0); ssp_port_write(ssp, 0, PORT_CFG_1, SSP_PORT_ASL); ssp_port_write(ssp, 1, PORT_CFG_1, SSP_PORT_ASL); ssp_port_write(ssp, 0, PORT_CFG_2, SSP_PORT_CFO1); ssp_port_write(ssp, 1, PORT_CFG_2, SSP_PORT_CFO1); sysclk = clk_get_rate(ssp->clk); if (pdata && pdata->out_clock) prediv = (sysclk / pdata->out_clock) - 1; prediv = clamp(prediv, 0, 0xff); ssp_rmw(ssp, REG_PREDIV, 0xff, prediv); memset(cells, 0, sizeof(cells)); for (id = 0; id < 2; id++) { const struct ti_ssp_dev_data *data = &pdata->dev_data[id]; cells[id].id = id; cells[id].name = data->dev_name; cells[id].platform_data = data->pdata; cells[id].data_size = data->pdata_size; } error = mfd_add_devices(dev, 0, cells, 2, NULL, 0, NULL); if (error < 0) { dev_err(dev, "cannot add mfd cells\n"); goto error_enable; } return 0; error_enable: free_irq(ssp->irq, ssp); error_irq: clk_put(ssp->clk); error_clk: iounmap(ssp->regs); error_map: release_mem_region(ssp->res->start, resource_size(ssp->res)); error_res: kfree(ssp); return error; } static int ti_ssp_remove(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct ti_ssp *ssp = dev_get_drvdata(dev); mfd_remove_devices(dev); clk_disable(ssp->clk); free_irq(ssp->irq, ssp); clk_put(ssp->clk); iounmap(ssp->regs); release_mem_region(ssp->res->start, resource_size(ssp->res)); kfree(ssp); dev_set_drvdata(dev, NULL); return 0; } static struct platform_driver ti_ssp_driver = { .probe = ti_ssp_probe, .remove = ti_ssp_remove, .driver = { .name = "ti-ssp", .owner = THIS_MODULE, } }; module_platform_driver(ti_ssp_driver); MODULE_DESCRIPTION("Sequencer Serial Port (SSP) Driver"); MODULE_AUTHOR("Cyril Chemparathy"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:ti-ssp");
ArtVandelae/steamos_kernel
drivers/mfd/ti-ssp.c
C
gpl-2.0
11,364
/* * Support for 'media5200-platform' compatible boards. * * Copyright (C) 2008 Secret Lab Technologies Ltd. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * Description: * This code implements support for the Freescape Media5200 platform * (built around the MPC5200 SoC). * * Notable characteristic of the Media5200 is the presence of an FPGA * that has all external IRQ lines routed through it. This file implements * a cascaded interrupt controller driver which attaches itself to the * Virtual IRQ subsystem after the primary mpc5200 interrupt controller * is initialized. * */ #undef DEBUG #include <linux/irq.h> #include <linux/interrupt.h> #include <linux/io.h> #include <asm/time.h> #include <asm/prom.h> #include <asm/machdep.h> #include <asm/mpc52xx.h> static struct of_device_id mpc5200_gpio_ids[] __initdata = { { .compatible = "fsl,mpc5200-gpio", }, { .compatible = "mpc5200-gpio", }, {} }; /* FPGA register set */ #define MEDIA5200_IRQ_ENABLE (0x40c) #define MEDIA5200_IRQ_STATUS (0x410) #define MEDIA5200_NUM_IRQS (6) #define MEDIA5200_IRQ_SHIFT (32 - MEDIA5200_NUM_IRQS) struct media5200_irq { void __iomem *regs; spinlock_t lock; struct irq_host *irqhost; }; struct media5200_irq media5200_irq; static void media5200_irq_unmask(struct irq_data *d) { unsigned long flags; u32 val; spin_lock_irqsave(&media5200_irq.lock, flags); val = in_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE); val |= 1 << (MEDIA5200_IRQ_SHIFT + irqd_to_hwirq(d)); out_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE, val); spin_unlock_irqrestore(&media5200_irq.lock, flags); } static void media5200_irq_mask(struct irq_data *d) { unsigned long flags; u32 val; spin_lock_irqsave(&media5200_irq.lock, flags); val = in_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE); val &= ~(1 << (MEDIA5200_IRQ_SHIFT + irqd_to_hwirq(d))); out_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE, val); spin_unlock_irqrestore(&media5200_irq.lock, flags); } static struct irq_chip media5200_irq_chip = { .name = "Media5200 FPGA", .irq_unmask = media5200_irq_unmask, .irq_mask = media5200_irq_mask, .irq_mask_ack = media5200_irq_mask, }; void media5200_irq_cascade(unsigned int virq, struct irq_desc *desc) { struct irq_chip *chip = irq_desc_get_chip(desc); int sub_virq, val; u32 status, enable; /* Mask off the cascaded IRQ */ raw_spin_lock(&desc->lock); chip->irq_mask(&desc->irq_data); raw_spin_unlock(&desc->lock); /* Ask the FPGA for IRQ status. If 'val' is 0, then no irqs * are pending. 'ffs()' is 1 based */ status = in_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE); enable = in_be32(media5200_irq.regs + MEDIA5200_IRQ_STATUS); val = ffs((status & enable) >> MEDIA5200_IRQ_SHIFT); if (val) { sub_virq = irq_linear_revmap(media5200_irq.irqhost, val - 1); /* pr_debug("%s: virq=%i s=%.8x e=%.8x hwirq=%i subvirq=%i\n", * __func__, virq, status, enable, val - 1, sub_virq); */ generic_handle_irq(sub_virq); } /* Processing done; can reenable the cascade now */ raw_spin_lock(&desc->lock); chip->irq_ack(&desc->irq_data); if (!irqd_irq_disabled(&desc->irq_data)) chip->irq_unmask(&desc->irq_data); raw_spin_unlock(&desc->lock); } static int media5200_irq_map(struct irq_host *h, unsigned int virq, irq_hw_number_t hw) { pr_debug("%s: h=%p, virq=%i, hwirq=%i\n", __func__, h, virq, (int)hw); irq_set_chip_data(virq, &media5200_irq); irq_set_chip_and_handler(virq, &media5200_irq_chip, handle_level_irq); irq_set_status_flags(virq, IRQ_LEVEL); return 0; } static int media5200_irq_xlate(struct irq_host *h, struct device_node *ct, const u32 *intspec, unsigned int intsize, irq_hw_number_t *out_hwirq, unsigned int *out_flags) { if (intsize != 2) return -1; pr_debug("%s: bank=%i, number=%i\n", __func__, intspec[0], intspec[1]); *out_hwirq = intspec[1]; *out_flags = IRQ_TYPE_NONE; return 0; } static struct irq_host_ops media5200_irq_ops = { .map = media5200_irq_map, .xlate = media5200_irq_xlate, }; /* * Setup Media5200 IRQ mapping */ static void __init media5200_init_irq(void) { struct device_node *fpga_np; int cascade_virq; /* First setup the regular MPC5200 interrupt controller */ mpc52xx_init_irq(); /* Now find the FPGA IRQ */ fpga_np = of_find_compatible_node(NULL, NULL, "fsl,media5200-fpga"); if (!fpga_np) goto out; pr_debug("%s: found fpga node: %s\n", __func__, fpga_np->full_name); media5200_irq.regs = of_iomap(fpga_np, 0); if (!media5200_irq.regs) goto out; pr_debug("%s: mapped to %p\n", __func__, media5200_irq.regs); cascade_virq = irq_of_parse_and_map(fpga_np, 0); if (!cascade_virq) goto out; pr_debug("%s: cascaded on virq=%i\n", __func__, cascade_virq); /* Disable all FPGA IRQs */ out_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE, 0); spin_lock_init(&media5200_irq.lock); media5200_irq.irqhost = irq_alloc_host(fpga_np, IRQ_HOST_MAP_LINEAR, MEDIA5200_NUM_IRQS, &media5200_irq_ops, -1); if (!media5200_irq.irqhost) goto out; pr_debug("%s: allocated irqhost\n", __func__); media5200_irq.irqhost->host_data = &media5200_irq; irq_set_handler_data(cascade_virq, &media5200_irq); irq_set_chained_handler(cascade_virq, media5200_irq_cascade); return; out: pr_err("Could not find Media5200 FPGA; PCI interrupts will not work\n"); } /* * Setup the architecture */ static void __init media5200_setup_arch(void) { struct device_node *np; struct mpc52xx_gpio __iomem *gpio; u32 port_config; if (ppc_md.progress) ppc_md.progress("media5200_setup_arch()", 0); /* Map important registers from the internal memory map */ mpc52xx_map_common_devices(); /* Some mpc5200 & mpc5200b related configuration */ mpc5200_setup_xlb_arbiter(); mpc52xx_setup_pci(); np = of_find_matching_node(NULL, mpc5200_gpio_ids); gpio = of_iomap(np, 0); of_node_put(np); if (!gpio) { printk(KERN_ERR "%s() failed. expect abnormal behavior\n", __func__); return; } /* Set port config */ port_config = in_be32(&gpio->port_config); port_config &= ~0x03000000; /* ATA CS is on csb_4/5 */ port_config |= 0x01000000; out_be32(&gpio->port_config, port_config); /* Unmap zone */ iounmap(gpio); } /* list of the supported boards */ static const char *board[] __initdata = { "fsl,media5200", NULL }; /* * Called very early, MMU is off, device-tree isn't unflattened */ static int __init media5200_probe(void) { return of_flat_dt_match(of_get_flat_dt_root(), board); } define_machine(media5200_platform) { .name = "media5200-platform", .probe = media5200_probe, .setup_arch = media5200_setup_arch, .init = mpc52xx_declare_of_platform_devices, .init_IRQ = media5200_init_irq, .get_irq = mpc52xx_get_irq, .restart = mpc52xx_restart, .calibrate_decr = generic_calibrate_decr, };
mericon/Xperia-S-msm8660
arch/powerpc/platforms/52xx/media5200.c
C
gpl-2.0
7,027
/* * arch/powerpc/platforms/embedded6xx/hlwd-pic.c * * Nintendo Wii "Hollywood" interrupt controller support. * Copyright (C) 2009 The GameCube Linux Team * Copyright (C) 2009 Albert Herranz * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * */ #define DRV_MODULE_NAME "hlwd-pic" #define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt #include <linux/kernel.h> #include <linux/init.h> #include <linux/irq.h> #include <linux/of.h> #include <asm/io.h> #include "hlwd-pic.h" #define HLWD_NR_IRQS 32 /* * Each interrupt has a corresponding bit in both * the Interrupt Cause (ICR) and Interrupt Mask (IMR) registers. * * Enabling/disabling an interrupt line involves asserting/clearing * the corresponding bit in IMR. ACK'ing a request simply involves * asserting the corresponding bit in ICR. */ #define HW_BROADWAY_ICR 0x00 #define HW_BROADWAY_IMR 0x04 /* * IRQ chip hooks. * */ static void hlwd_pic_mask_and_ack(struct irq_data *d) { int irq = irqd_to_hwirq(d); void __iomem *io_base = irq_data_get_irq_chip_data(d); u32 mask = 1 << irq; clrbits32(io_base + HW_BROADWAY_IMR, mask); out_be32(io_base + HW_BROADWAY_ICR, mask); } static void hlwd_pic_ack(struct irq_data *d) { int irq = irqd_to_hwirq(d); void __iomem *io_base = irq_data_get_irq_chip_data(d); out_be32(io_base + HW_BROADWAY_ICR, 1 << irq); } static void hlwd_pic_mask(struct irq_data *d) { int irq = irqd_to_hwirq(d); void __iomem *io_base = irq_data_get_irq_chip_data(d); clrbits32(io_base + HW_BROADWAY_IMR, 1 << irq); } static void hlwd_pic_unmask(struct irq_data *d) { int irq = irqd_to_hwirq(d); void __iomem *io_base = irq_data_get_irq_chip_data(d); setbits32(io_base + HW_BROADWAY_IMR, 1 << irq); } static struct irq_chip hlwd_pic = { .name = "hlwd-pic", .irq_ack = hlwd_pic_ack, .irq_mask_ack = hlwd_pic_mask_and_ack, .irq_mask = hlwd_pic_mask, .irq_unmask = hlwd_pic_unmask, }; /* * IRQ host hooks. * */ static struct irq_host *hlwd_irq_host; static int hlwd_pic_map(struct irq_host *h, unsigned int virq, irq_hw_number_t hwirq) { irq_set_chip_data(virq, h->host_data); irq_set_status_flags(virq, IRQ_LEVEL); irq_set_chip_and_handler(virq, &hlwd_pic, handle_level_irq); return 0; } static struct irq_host_ops hlwd_irq_host_ops = { .map = hlwd_pic_map, }; static unsigned int __hlwd_pic_get_irq(struct irq_host *h) { void __iomem *io_base = h->host_data; int irq; u32 irq_status; irq_status = in_be32(io_base + HW_BROADWAY_ICR) & in_be32(io_base + HW_BROADWAY_IMR); if (irq_status == 0) return NO_IRQ; /* no more IRQs pending */ irq = __ffs(irq_status); return irq_linear_revmap(h, irq); } static void hlwd_pic_irq_cascade(unsigned int cascade_virq, struct irq_desc *desc) { struct irq_chip *chip = irq_desc_get_chip(desc); struct irq_host *irq_host = irq_get_handler_data(cascade_virq); unsigned int virq; raw_spin_lock(&desc->lock); chip->irq_mask(&desc->irq_data); /* IRQ_LEVEL */ raw_spin_unlock(&desc->lock); virq = __hlwd_pic_get_irq(irq_host); if (virq != NO_IRQ) generic_handle_irq(virq); else pr_err("spurious interrupt!\n"); raw_spin_lock(&desc->lock); chip->irq_ack(&desc->irq_data); /* IRQ_LEVEL */ if (!irqd_irq_disabled(&desc->irq_data) && chip->irq_unmask) chip->irq_unmask(&desc->irq_data); raw_spin_unlock(&desc->lock); } /* * Platform hooks. * */ static void __hlwd_quiesce(void __iomem *io_base) { /* mask and ack all IRQs */ out_be32(io_base + HW_BROADWAY_IMR, 0); out_be32(io_base + HW_BROADWAY_ICR, 0xffffffff); } struct irq_host *hlwd_pic_init(struct device_node *np) { struct irq_host *irq_host; struct resource res; void __iomem *io_base; int retval; retval = of_address_to_resource(np, 0, &res); if (retval) { pr_err("no io memory range found\n"); return NULL; } io_base = ioremap(res.start, resource_size(&res)); if (!io_base) { pr_err("ioremap failed\n"); return NULL; } pr_info("controller at 0x%08x mapped to 0x%p\n", res.start, io_base); __hlwd_quiesce(io_base); irq_host = irq_alloc_host(np, IRQ_HOST_MAP_LINEAR, HLWD_NR_IRQS, &hlwd_irq_host_ops, -1); if (!irq_host) { pr_err("failed to allocate irq_host\n"); return NULL; } irq_host->host_data = io_base; return irq_host; } unsigned int hlwd_pic_get_irq(void) { return __hlwd_pic_get_irq(hlwd_irq_host); } /* * Probe function. * */ void hlwd_pic_probe(void) { struct irq_host *host; struct device_node *np; const u32 *interrupts; int cascade_virq; for_each_compatible_node(np, NULL, "nintendo,hollywood-pic") { interrupts = of_get_property(np, "interrupts", NULL); if (interrupts) { host = hlwd_pic_init(np); BUG_ON(!host); cascade_virq = irq_of_parse_and_map(np, 0); irq_set_handler_data(cascade_virq, host); irq_set_chained_handler(cascade_virq, hlwd_pic_irq_cascade); hlwd_irq_host = host; break; } } } /** * hlwd_quiesce() - quiesce hollywood irq controller * * Mask and ack all interrupt sources. * */ void hlwd_quiesce(void) { void __iomem *io_base = hlwd_irq_host->host_data; __hlwd_quiesce(io_base); }
rogersb11/android_kernel_samsung_smdk4412
arch/powerpc/platforms/embedded6xx/hlwd-pic.c
C
gpl-2.0
5,290
/* * * tdfxfb.c * * Author: Hannu Mallat <hmallat@cc.hut.fi> * * Copyright © 1999 Hannu Mallat * All rights reserved * * Created : Thu Sep 23 18:17:43 1999, hmallat * Last modified: Tue Nov 2 21:19:47 1999, hmallat * * I2C part copied from the i2c-voodoo3.c driver by: * Frodo Looijaard <frodol@dds.nl>, * Philip Edelbrock <phil@netroedge.com>, * Ralph Metzler <rjkm@thp.uni-koeln.de>, and * Mark D. Studebaker <mdsxyz123@yahoo.com> * * Lots of the information here comes from the Daryll Strauss' Banshee * patches to the XF86 server, and the rest comes from the 3dfx * Banshee specification. I'm very much indebted to Daryll for his * work on the X server. * * Voodoo3 support was contributed Harold Oga. Lots of additions * (proper acceleration, 24 bpp, hardware cursor) and bug fixes by Attila * Kesmarki. Thanks guys! * * Voodoo1 and Voodoo2 support aren't relevant to this driver as they * behave very differently from the Voodoo3/4/5. For anyone wanting to * use frame buffer on the Voodoo1/2, see the sstfb driver (which is * located at http://www.sourceforge.net/projects/sstfb). * * While I _am_ grateful to 3Dfx for releasing the specs for Banshee, * I do wish the next version is a bit more complete. Without the XF86 * patches I couldn't have gotten even this far... for instance, the * extensions to the VGA register set go completely unmentioned in the * spec! Also, lots of references are made to the 'SST core', but no * spec is publicly available, AFAIK. * * The structure of this driver comes pretty much from the Permedia * driver by Ilario Nardinocchi, which in turn is based on skeletonfb. * * TODO: * - multihead support (basically need to support an array of fb_infos) * - support other architectures (PPC, Alpha); does the fact that the VGA * core can be accessed only thru I/O (not memory mapped) complicate * things? * * Version history: * * 0.1.4 (released 2002-05-28) ported over to new fbdev api by James Simmons * * 0.1.3 (released 1999-11-02) added Attila's panning support, code * reorg, hwcursor address page size alignment * (for mmapping both frame buffer and regs), * and my changes to get rid of hardcoded * VGA i/o register locations (uses PCI * configuration info now) * 0.1.2 (released 1999-10-19) added Attila Kesmarki's bug fixes and * improvements * 0.1.1 (released 1999-10-07) added Voodoo3 support by Harold Oga. * 0.1.0 (released 1999-10-06) initial version * */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/slab.h> #include <linux/fb.h> #include <linux/init.h> #include <linux/pci.h> #include <asm/io.h> #include <video/tdfx.h> #define DPRINTK(a, b...) pr_debug("fb: %s: " a, __func__ , ## b) #ifdef CONFIG_MTRR #include <asm/mtrr.h> #else /* duplicate asm/mtrr.h defines to work on archs without mtrr */ #define MTRR_TYPE_WRCOMB 1 static inline int mtrr_add(unsigned long base, unsigned long size, unsigned int type, char increment) { return -ENODEV; } static inline int mtrr_del(int reg, unsigned long base, unsigned long size) { return -ENODEV; } #endif #define BANSHEE_MAX_PIXCLOCK 270000 #define VOODOO3_MAX_PIXCLOCK 300000 #define VOODOO5_MAX_PIXCLOCK 350000 static struct fb_fix_screeninfo tdfx_fix __devinitdata = { .type = FB_TYPE_PACKED_PIXELS, .visual = FB_VISUAL_PSEUDOCOLOR, .ypanstep = 1, .ywrapstep = 1, .accel = FB_ACCEL_3DFX_BANSHEE }; static struct fb_var_screeninfo tdfx_var __devinitdata = { /* "640x480, 8 bpp @ 60 Hz */ .xres = 640, .yres = 480, .xres_virtual = 640, .yres_virtual = 1024, .bits_per_pixel = 8, .red = {0, 8, 0}, .blue = {0, 8, 0}, .green = {0, 8, 0}, .activate = FB_ACTIVATE_NOW, .height = -1, .width = -1, .accel_flags = FB_ACCELF_TEXT, .pixclock = 39722, .left_margin = 40, .right_margin = 24, .upper_margin = 32, .lower_margin = 11, .hsync_len = 96, .vsync_len = 2, .vmode = FB_VMODE_NONINTERLACED }; /* * PCI driver prototypes */ static int __devinit tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id); static void __devexit tdfxfb_remove(struct pci_dev *pdev); static struct pci_device_id tdfxfb_id_table[] = { { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_BANSHEE, PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, 0xff0000, 0 }, { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO3, PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, 0xff0000, 0 }, { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO5, PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, 0xff0000, 0 }, { 0, } }; static struct pci_driver tdfxfb_driver = { .name = "tdfxfb", .id_table = tdfxfb_id_table, .probe = tdfxfb_probe, .remove = __devexit_p(tdfxfb_remove), }; MODULE_DEVICE_TABLE(pci, tdfxfb_id_table); /* * Driver data */ static int nopan; static int nowrap = 1; /* not implemented (yet) */ static int hwcursor = 1; static char *mode_option __devinitdata; /* mtrr option */ static int nomtrr __devinitdata; /* ------------------------------------------------------------------------- * Hardware-specific funcions * ------------------------------------------------------------------------- */ static inline u8 vga_inb(struct tdfx_par *par, u32 reg) { return inb(par->iobase + reg - 0x300); } static inline void vga_outb(struct tdfx_par *par, u32 reg, u8 val) { outb(val, par->iobase + reg - 0x300); } static inline void gra_outb(struct tdfx_par *par, u32 idx, u8 val) { vga_outb(par, GRA_I, idx); wmb(); vga_outb(par, GRA_D, val); wmb(); } static inline void seq_outb(struct tdfx_par *par, u32 idx, u8 val) { vga_outb(par, SEQ_I, idx); wmb(); vga_outb(par, SEQ_D, val); wmb(); } static inline u8 seq_inb(struct tdfx_par *par, u32 idx) { vga_outb(par, SEQ_I, idx); mb(); return vga_inb(par, SEQ_D); } static inline void crt_outb(struct tdfx_par *par, u32 idx, u8 val) { vga_outb(par, CRT_I, idx); wmb(); vga_outb(par, CRT_D, val); wmb(); } static inline u8 crt_inb(struct tdfx_par *par, u32 idx) { vga_outb(par, CRT_I, idx); mb(); return vga_inb(par, CRT_D); } static inline void att_outb(struct tdfx_par *par, u32 idx, u8 val) { unsigned char tmp; tmp = vga_inb(par, IS1_R); vga_outb(par, ATT_IW, idx); vga_outb(par, ATT_IW, val); } static inline void vga_disable_video(struct tdfx_par *par) { unsigned char s; s = seq_inb(par, 0x01) | 0x20; seq_outb(par, 0x00, 0x01); seq_outb(par, 0x01, s); seq_outb(par, 0x00, 0x03); } static inline void vga_enable_video(struct tdfx_par *par) { unsigned char s; s = seq_inb(par, 0x01) & 0xdf; seq_outb(par, 0x00, 0x01); seq_outb(par, 0x01, s); seq_outb(par, 0x00, 0x03); } static inline void vga_enable_palette(struct tdfx_par *par) { vga_inb(par, IS1_R); mb(); vga_outb(par, ATT_IW, 0x20); } static inline u32 tdfx_inl(struct tdfx_par *par, unsigned int reg) { return readl(par->regbase_virt + reg); } static inline void tdfx_outl(struct tdfx_par *par, unsigned int reg, u32 val) { writel(val, par->regbase_virt + reg); } static inline void banshee_make_room(struct tdfx_par *par, int size) { /* Note: The Voodoo3's onboard FIFO has 32 slots. This loop * won't quit if you ask for more. */ while ((tdfx_inl(par, STATUS) & 0x1f) < size - 1) cpu_relax(); } static int banshee_wait_idle(struct fb_info *info) { struct tdfx_par *par = info->par; int i = 0; banshee_make_room(par, 1); tdfx_outl(par, COMMAND_3D, COMMAND_3D_NOP); do { if ((tdfx_inl(par, STATUS) & STATUS_BUSY) == 0) i++; } while (i < 3); return 0; } /* * Set the color of a palette entry in 8bpp mode */ static inline void do_setpalentry(struct tdfx_par *par, unsigned regno, u32 c) { banshee_make_room(par, 2); tdfx_outl(par, DACADDR, regno); /* read after write makes it working */ tdfx_inl(par, DACADDR); tdfx_outl(par, DACDATA, c); } static u32 do_calc_pll(int freq, int *freq_out) { int m, n, k, best_m, best_n, best_k, best_error; int fref = 14318; best_error = freq; best_n = best_m = best_k = 0; for (k = 3; k >= 0; k--) { for (m = 63; m >= 0; m--) { /* * Estimate value of n that produces target frequency * with current m and k */ int n_estimated = ((freq * (m + 2) << k) / fref) - 2; /* Search neighborhood of estimated n */ for (n = max(0, n_estimated); n <= min(255, n_estimated + 1); n++) { /* * Calculate PLL freqency with current m, k and * estimated n */ int f = (fref * (n + 2) / (m + 2)) >> k; int error = abs(f - freq); /* * If this is the closest we've come to the * target frequency then remember n, m and k */ if (error < best_error) { best_error = error; best_n = n; best_m = m; best_k = k; } } } } n = best_n; m = best_m; k = best_k; *freq_out = (fref * (n + 2) / (m + 2)) >> k; return (n << 8) | (m << 2) | k; } static void do_write_regs(struct fb_info *info, struct banshee_reg *reg) { struct tdfx_par *par = info->par; int i; banshee_wait_idle(info); tdfx_outl(par, MISCINIT1, tdfx_inl(par, MISCINIT1) | 0x01); crt_outb(par, 0x11, crt_inb(par, 0x11) & 0x7f); /* CRT unprotect */ banshee_make_room(par, 3); tdfx_outl(par, VGAINIT1, reg->vgainit1 & 0x001FFFFF); tdfx_outl(par, VIDPROCCFG, reg->vidcfg & ~0x00000001); #if 0 tdfx_outl(par, PLLCTRL1, reg->mempll); tdfx_outl(par, PLLCTRL2, reg->gfxpll); #endif tdfx_outl(par, PLLCTRL0, reg->vidpll); vga_outb(par, MISC_W, reg->misc[0x00] | 0x01); for (i = 0; i < 5; i++) seq_outb(par, i, reg->seq[i]); for (i = 0; i < 25; i++) crt_outb(par, i, reg->crt[i]); for (i = 0; i < 9; i++) gra_outb(par, i, reg->gra[i]); for (i = 0; i < 21; i++) att_outb(par, i, reg->att[i]); crt_outb(par, 0x1a, reg->ext[0]); crt_outb(par, 0x1b, reg->ext[1]); vga_enable_palette(par); vga_enable_video(par); banshee_make_room(par, 9); tdfx_outl(par, VGAINIT0, reg->vgainit0); tdfx_outl(par, DACMODE, reg->dacmode); tdfx_outl(par, VIDDESKSTRIDE, reg->stride); tdfx_outl(par, HWCURPATADDR, reg->curspataddr); tdfx_outl(par, VIDSCREENSIZE, reg->screensize); tdfx_outl(par, VIDDESKSTART, reg->startaddr); tdfx_outl(par, VIDPROCCFG, reg->vidcfg); tdfx_outl(par, VGAINIT1, reg->vgainit1); tdfx_outl(par, MISCINIT0, reg->miscinit0); banshee_make_room(par, 8); tdfx_outl(par, SRCBASE, reg->startaddr); tdfx_outl(par, DSTBASE, reg->startaddr); tdfx_outl(par, COMMANDEXTRA_2D, 0); tdfx_outl(par, CLIP0MIN, 0); tdfx_outl(par, CLIP0MAX, 0x0fff0fff); tdfx_outl(par, CLIP1MIN, 0); tdfx_outl(par, CLIP1MAX, 0x0fff0fff); tdfx_outl(par, SRCXY, 0); banshee_wait_idle(info); } static unsigned long do_lfb_size(struct tdfx_par *par, unsigned short dev_id) { u32 draminit0 = tdfx_inl(par, DRAMINIT0); u32 draminit1 = tdfx_inl(par, DRAMINIT1); u32 miscinit1; int num_chips = (draminit0 & DRAMINIT0_SGRAM_NUM) ? 8 : 4; int chip_size; /* in MB */ int has_sgram = draminit1 & DRAMINIT1_MEM_SDRAM; if (dev_id < PCI_DEVICE_ID_3DFX_VOODOO5) { /* Banshee/Voodoo3 */ chip_size = 2; if (has_sgram && !(draminit0 & DRAMINIT0_SGRAM_TYPE)) chip_size = 1; } else { /* Voodoo4/5 */ has_sgram = 0; chip_size = draminit0 & DRAMINIT0_SGRAM_TYPE_MASK; chip_size = 1 << (chip_size >> DRAMINIT0_SGRAM_TYPE_SHIFT); } /* disable block writes for SDRAM */ miscinit1 = tdfx_inl(par, MISCINIT1); miscinit1 |= has_sgram ? 0 : MISCINIT1_2DBLOCK_DIS; miscinit1 |= MISCINIT1_CLUT_INV; banshee_make_room(par, 1); tdfx_outl(par, MISCINIT1, miscinit1); return num_chips * chip_size * 1024l * 1024; } /* ------------------------------------------------------------------------- */ static int tdfxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) { struct tdfx_par *par = info->par; u32 lpitch; if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 && var->bits_per_pixel != 24 && var->bits_per_pixel != 32) { DPRINTK("depth not supported: %u\n", var->bits_per_pixel); return -EINVAL; } if (var->xres != var->xres_virtual) var->xres_virtual = var->xres; if (var->yres > var->yres_virtual) var->yres_virtual = var->yres; if (var->xoffset) { DPRINTK("xoffset not supported\n"); return -EINVAL; } var->yoffset = 0; /* * Banshee doesn't support interlace, but Voodoo4/5 and probably * Voodoo3 do. * no direct information about device id now? * use max_pixclock for this... */ if (((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) && (par->max_pixclock < VOODOO3_MAX_PIXCLOCK)) { DPRINTK("interlace not supported\n"); return -EINVAL; } if (info->monspecs.hfmax && info->monspecs.vfmax && info->monspecs.dclkmax && fb_validate_mode(var, info) < 0) { DPRINTK("mode outside monitor's specs\n"); return -EINVAL; } var->xres = (var->xres + 15) & ~15; /* could sometimes be 8 */ lpitch = var->xres * ((var->bits_per_pixel + 7) >> 3); if (var->xres < 320 || var->xres > 2048) { DPRINTK("width not supported: %u\n", var->xres); return -EINVAL; } if (var->yres < 200 || var->yres > 2048) { DPRINTK("height not supported: %u\n", var->yres); return -EINVAL; } if (lpitch * var->yres_virtual > info->fix.smem_len) { var->yres_virtual = info->fix.smem_len / lpitch; if (var->yres_virtual < var->yres) { DPRINTK("no memory for screen (%ux%ux%u)\n", var->xres, var->yres_virtual, var->bits_per_pixel); return -EINVAL; } } if (PICOS2KHZ(var->pixclock) > par->max_pixclock) { DPRINTK("pixclock too high (%ldKHz)\n", PICOS2KHZ(var->pixclock)); return -EINVAL; } var->transp.offset = 0; var->transp.length = 0; switch (var->bits_per_pixel) { case 8: var->red.length = 8; var->red.offset = 0; var->green = var->red; var->blue = var->red; break; case 16: var->red.offset = 11; var->red.length = 5; var->green.offset = 5; var->green.length = 6; var->blue.offset = 0; var->blue.length = 5; break; case 32: var->transp.offset = 24; var->transp.length = 8; case 24: var->red.offset = 16; var->green.offset = 8; var->blue.offset = 0; var->red.length = var->green.length = var->blue.length = 8; break; } var->width = -1; var->height = -1; var->accel_flags = FB_ACCELF_TEXT; DPRINTK("Checking graphics mode at %dx%d depth %d\n", var->xres, var->yres, var->bits_per_pixel); return 0; } static int tdfxfb_set_par(struct fb_info *info) { struct tdfx_par *par = info->par; u32 hdispend = info->var.xres; u32 hsyncsta = hdispend + info->var.right_margin; u32 hsyncend = hsyncsta + info->var.hsync_len; u32 htotal = hsyncend + info->var.left_margin; u32 hd, hs, he, ht, hbs, hbe; u32 vd, vs, ve, vt, vbs, vbe; struct banshee_reg reg; int fout, freq; u32 wd; u32 cpp = (info->var.bits_per_pixel + 7) >> 3; memset(&reg, 0, sizeof(reg)); reg.vidcfg = VIDCFG_VIDPROC_ENABLE | VIDCFG_DESK_ENABLE | VIDCFG_CURS_X11 | ((cpp - 1) << VIDCFG_PIXFMT_SHIFT) | (cpp != 1 ? VIDCFG_CLUT_BYPASS : 0); /* PLL settings */ freq = PICOS2KHZ(info->var.pixclock); reg.vidcfg &= ~VIDCFG_2X; if (freq > par->max_pixclock / 2) { freq = freq > par->max_pixclock ? par->max_pixclock : freq; reg.dacmode |= DACMODE_2X; reg.vidcfg |= VIDCFG_2X; hdispend >>= 1; hsyncsta >>= 1; hsyncend >>= 1; htotal >>= 1; } wd = (hdispend >> 3) - 1; hd = wd; hs = (hsyncsta >> 3) - 1; he = (hsyncend >> 3) - 1; ht = (htotal >> 3) - 1; hbs = hd; hbe = ht; if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) { vd = (info->var.yres << 1) - 1; vs = vd + (info->var.lower_margin << 1); ve = vs + (info->var.vsync_len << 1); vt = ve + (info->var.upper_margin << 1) - 1; reg.screensize = info->var.xres | (info->var.yres << 13); reg.vidcfg |= VIDCFG_HALF_MODE; reg.crt[0x09] = 0x80; } else { vd = info->var.yres - 1; vs = vd + info->var.lower_margin; ve = vs + info->var.vsync_len; vt = ve + info->var.upper_margin - 1; reg.screensize = info->var.xres | (info->var.yres << 12); reg.vidcfg &= ~VIDCFG_HALF_MODE; } vbs = vd; vbe = vt; /* this is all pretty standard VGA register stuffing */ reg.misc[0x00] = 0x0f | (info->var.xres < 400 ? 0xa0 : info->var.xres < 480 ? 0x60 : info->var.xres < 768 ? 0xe0 : 0x20); reg.gra[0x05] = 0x40; reg.gra[0x06] = 0x05; reg.gra[0x07] = 0x0f; reg.gra[0x08] = 0xff; reg.att[0x00] = 0x00; reg.att[0x01] = 0x01; reg.att[0x02] = 0x02; reg.att[0x03] = 0x03; reg.att[0x04] = 0x04; reg.att[0x05] = 0x05; reg.att[0x06] = 0x06; reg.att[0x07] = 0x07; reg.att[0x08] = 0x08; reg.att[0x09] = 0x09; reg.att[0x0a] = 0x0a; reg.att[0x0b] = 0x0b; reg.att[0x0c] = 0x0c; reg.att[0x0d] = 0x0d; reg.att[0x0e] = 0x0e; reg.att[0x0f] = 0x0f; reg.att[0x10] = 0x41; reg.att[0x12] = 0x0f; reg.seq[0x00] = 0x03; reg.seq[0x01] = 0x01; /* fixme: clkdiv2? */ reg.seq[0x02] = 0x0f; reg.seq[0x03] = 0x00; reg.seq[0x04] = 0x0e; reg.crt[0x00] = ht - 4; reg.crt[0x01] = hd; reg.crt[0x02] = hbs; reg.crt[0x03] = 0x80 | (hbe & 0x1f); reg.crt[0x04] = hs; reg.crt[0x05] = ((hbe & 0x20) << 2) | (he & 0x1f); reg.crt[0x06] = vt; reg.crt[0x07] = ((vs & 0x200) >> 2) | ((vd & 0x200) >> 3) | ((vt & 0x200) >> 4) | 0x10 | ((vbs & 0x100) >> 5) | ((vs & 0x100) >> 6) | ((vd & 0x100) >> 7) | ((vt & 0x100) >> 8); reg.crt[0x09] |= 0x40 | ((vbs & 0x200) >> 4); reg.crt[0x10] = vs; reg.crt[0x11] = (ve & 0x0f) | 0x20; reg.crt[0x12] = vd; reg.crt[0x13] = wd; reg.crt[0x15] = vbs; reg.crt[0x16] = vbe + 1; reg.crt[0x17] = 0xc3; reg.crt[0x18] = 0xff; /* Banshee's nonvga stuff */ reg.ext[0x00] = (((ht & 0x100) >> 8) | ((hd & 0x100) >> 6) | ((hbs & 0x100) >> 4) | ((hbe & 0x40) >> 1) | ((hs & 0x100) >> 2) | ((he & 0x20) << 2)); reg.ext[0x01] = (((vt & 0x400) >> 10) | ((vd & 0x400) >> 8) | ((vbs & 0x400) >> 6) | ((vbe & 0x400) >> 4)); reg.vgainit0 = VGAINIT0_8BIT_DAC | VGAINIT0_EXT_ENABLE | VGAINIT0_WAKEUP_3C3 | VGAINIT0_ALT_READBACK | VGAINIT0_EXTSHIFTOUT; reg.vgainit1 = tdfx_inl(par, VGAINIT1) & 0x1fffff; if (hwcursor) reg.curspataddr = info->fix.smem_len; reg.cursloc = 0; reg.cursc0 = 0; reg.cursc1 = 0xffffff; reg.stride = info->var.xres * cpp; reg.startaddr = info->var.yoffset * reg.stride + info->var.xoffset * cpp; reg.vidpll = do_calc_pll(freq, &fout); #if 0 reg.mempll = do_calc_pll(..., &fout); reg.gfxpll = do_calc_pll(..., &fout); #endif if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) reg.vidcfg |= VIDCFG_INTERLACE; reg.miscinit0 = tdfx_inl(par, MISCINIT0); #if defined(__BIG_ENDIAN) switch (info->var.bits_per_pixel) { case 8: case 24: reg.miscinit0 &= ~(1 << 30); reg.miscinit0 &= ~(1 << 31); break; case 16: reg.miscinit0 |= (1 << 30); reg.miscinit0 |= (1 << 31); break; case 32: reg.miscinit0 |= (1 << 30); reg.miscinit0 &= ~(1 << 31); break; } #endif do_write_regs(info, &reg); /* Now change fb_fix_screeninfo according to changes in par */ info->fix.line_length = reg.stride; info->fix.visual = (info->var.bits_per_pixel == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; DPRINTK("Graphics mode is now set at %dx%d depth %d\n", info->var.xres, info->var.yres, info->var.bits_per_pixel); return 0; } /* A handy macro shamelessly pinched from matroxfb */ #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF - (val)) >> 16) static int tdfxfb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info) { struct tdfx_par *par = info->par; u32 rgbcol; if (regno >= info->cmap.len || regno > 255) return 1; /* grayscale works only partially under directcolor */ if (info->var.grayscale) { /* grayscale = 0.30*R + 0.59*G + 0.11*B */ blue = (red * 77 + green * 151 + blue * 28) >> 8; green = blue; red = blue; } switch (info->fix.visual) { case FB_VISUAL_PSEUDOCOLOR: rgbcol = (((u32)red & 0xff00) << 8) | (((u32)green & 0xff00) << 0) | (((u32)blue & 0xff00) >> 8); do_setpalentry(par, regno, rgbcol); break; /* Truecolor has no hardware color palettes. */ case FB_VISUAL_TRUECOLOR: if (regno < 16) { rgbcol = (CNVT_TOHW(red, info->var.red.length) << info->var.red.offset) | (CNVT_TOHW(green, info->var.green.length) << info->var.green.offset) | (CNVT_TOHW(blue, info->var.blue.length) << info->var.blue.offset) | (CNVT_TOHW(transp, info->var.transp.length) << info->var.transp.offset); par->palette[regno] = rgbcol; } break; default: DPRINTK("bad depth %u\n", info->var.bits_per_pixel); break; } return 0; } /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */ static int tdfxfb_blank(int blank, struct fb_info *info) { struct tdfx_par *par = info->par; int vgablank = 1; u32 dacmode = tdfx_inl(par, DACMODE); dacmode &= ~(BIT(1) | BIT(3)); switch (blank) { case FB_BLANK_UNBLANK: /* Screen: On; HSync: On, VSync: On */ vgablank = 0; break; case FB_BLANK_NORMAL: /* Screen: Off; HSync: On, VSync: On */ break; case FB_BLANK_VSYNC_SUSPEND: /* Screen: Off; HSync: On, VSync: Off */ dacmode |= BIT(3); break; case FB_BLANK_HSYNC_SUSPEND: /* Screen: Off; HSync: Off, VSync: On */ dacmode |= BIT(1); break; case FB_BLANK_POWERDOWN: /* Screen: Off; HSync: Off, VSync: Off */ dacmode |= BIT(1) | BIT(3); break; } banshee_make_room(par, 1); tdfx_outl(par, DACMODE, dacmode); if (vgablank) vga_disable_video(par); else vga_enable_video(par); return 0; } /* * Set the starting position of the visible screen to var->yoffset */ static int tdfxfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) { struct tdfx_par *par = info->par; u32 addr = var->yoffset * info->fix.line_length; if (nopan || var->xoffset) return -EINVAL; banshee_make_room(par, 1); tdfx_outl(par, VIDDESKSTART, addr); return 0; } #ifdef CONFIG_FB_3DFX_ACCEL /* * FillRect 2D command (solidfill or invert (via ROP_XOR)) */ static void tdfxfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) { struct tdfx_par *par = info->par; u32 bpp = info->var.bits_per_pixel; u32 stride = info->fix.line_length; u32 fmt = stride | ((bpp + ((bpp == 8) ? 0 : 8)) << 13); int tdfx_rop; u32 dx = rect->dx; u32 dy = rect->dy; u32 dstbase = 0; if (rect->rop == ROP_COPY) tdfx_rop = TDFX_ROP_COPY; else tdfx_rop = TDFX_ROP_XOR; /* assume always rect->height < 4096 */ if (dy + rect->height > 4095) { dstbase = stride * dy; dy = 0; } /* assume always rect->width < 4096 */ if (dx + rect->width > 4095) { dstbase += dx * bpp >> 3; dx = 0; } banshee_make_room(par, 6); tdfx_outl(par, DSTFORMAT, fmt); if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) { tdfx_outl(par, COLORFORE, rect->color); } else { /* FB_VISUAL_TRUECOLOR */ tdfx_outl(par, COLORFORE, par->palette[rect->color]); } tdfx_outl(par, COMMAND_2D, COMMAND_2D_FILLRECT | (tdfx_rop << 24)); tdfx_outl(par, DSTBASE, dstbase); tdfx_outl(par, DSTSIZE, rect->width | (rect->height << 16)); tdfx_outl(par, LAUNCH_2D, dx | (dy << 16)); } /* * Screen-to-Screen BitBlt 2D command (for the bmove fb op.) */ static void tdfxfb_copyarea(struct fb_info *info, const struct fb_copyarea *area) { struct tdfx_par *par = info->par; u32 sx = area->sx, sy = area->sy, dx = area->dx, dy = area->dy; u32 bpp = info->var.bits_per_pixel; u32 stride = info->fix.line_length; u32 blitcmd = COMMAND_2D_S2S_BITBLT | (TDFX_ROP_COPY << 24); u32 fmt = stride | ((bpp + ((bpp == 8) ? 0 : 8)) << 13); u32 dstbase = 0; u32 srcbase = 0; /* assume always area->height < 4096 */ if (sy + area->height > 4095) { srcbase = stride * sy; sy = 0; } /* assume always area->width < 4096 */ if (sx + area->width > 4095) { srcbase += sx * bpp >> 3; sx = 0; } /* assume always area->height < 4096 */ if (dy + area->height > 4095) { dstbase = stride * dy; dy = 0; } /* assume always area->width < 4096 */ if (dx + area->width > 4095) { dstbase += dx * bpp >> 3; dx = 0; } if (area->sx <= area->dx) { /* -X */ blitcmd |= BIT(14); sx += area->width - 1; dx += area->width - 1; } if (area->sy <= area->dy) { /* -Y */ blitcmd |= BIT(15); sy += area->height - 1; dy += area->height - 1; } banshee_make_room(par, 8); tdfx_outl(par, SRCFORMAT, fmt); tdfx_outl(par, DSTFORMAT, fmt); tdfx_outl(par, COMMAND_2D, blitcmd); tdfx_outl(par, DSTSIZE, area->width | (area->height << 16)); tdfx_outl(par, DSTXY, dx | (dy << 16)); tdfx_outl(par, SRCBASE, srcbase); tdfx_outl(par, DSTBASE, dstbase); tdfx_outl(par, LAUNCH_2D, sx | (sy << 16)); } static void tdfxfb_imageblit(struct fb_info *info, const struct fb_image *image) { struct tdfx_par *par = info->par; int size = image->height * ((image->width * image->depth + 7) >> 3); int fifo_free; int i, stride = info->fix.line_length; u32 bpp = info->var.bits_per_pixel; u32 dstfmt = stride | ((bpp + ((bpp == 8) ? 0 : 8)) << 13); u8 *chardata = (u8 *) image->data; u32 srcfmt; u32 dx = image->dx; u32 dy = image->dy; u32 dstbase = 0; if (image->depth != 1) { #ifdef BROKEN_CODE banshee_make_room(par, 6 + ((size + 3) >> 2)); srcfmt = stride | ((bpp + ((bpp == 8) ? 0 : 8)) << 13) | 0x400000; #else cfb_imageblit(info, image); #endif return; } banshee_make_room(par, 9); switch (info->fix.visual) { case FB_VISUAL_PSEUDOCOLOR: tdfx_outl(par, COLORFORE, image->fg_color); tdfx_outl(par, COLORBACK, image->bg_color); break; case FB_VISUAL_TRUECOLOR: default: tdfx_outl(par, COLORFORE, par->palette[image->fg_color]); tdfx_outl(par, COLORBACK, par->palette[image->bg_color]); } #ifdef __BIG_ENDIAN srcfmt = 0x400000 | BIT(20); #else srcfmt = 0x400000; #endif /* assume always image->height < 4096 */ if (dy + image->height > 4095) { dstbase = stride * dy; dy = 0; } /* assume always image->width < 4096 */ if (dx + image->width > 4095) { dstbase += dx * bpp >> 3; dx = 0; } tdfx_outl(par, DSTBASE, dstbase); tdfx_outl(par, SRCXY, 0); tdfx_outl(par, DSTXY, dx | (dy << 16)); tdfx_outl(par, COMMAND_2D, COMMAND_2D_H2S_BITBLT | (TDFX_ROP_COPY << 24)); tdfx_outl(par, SRCFORMAT, srcfmt); tdfx_outl(par, DSTFORMAT, dstfmt); tdfx_outl(par, DSTSIZE, image->width | (image->height << 16)); /* A count of how many free FIFO entries we've requested. * When this goes negative, we need to request more. */ fifo_free = 0; /* Send four bytes at a time of data */ for (i = (size >> 2); i > 0; i--) { if (--fifo_free < 0) { fifo_free = 31; banshee_make_room(par, fifo_free); } tdfx_outl(par, LAUNCH_2D, *(u32 *)chardata); chardata += 4; } /* Send the leftovers now */ banshee_make_room(par, 3); switch (size % 4) { case 0: break; case 1: tdfx_outl(par, LAUNCH_2D, *chardata); break; case 2: tdfx_outl(par, LAUNCH_2D, *(u16 *)chardata); break; case 3: tdfx_outl(par, LAUNCH_2D, *(u16 *)chardata | (chardata[3] << 24)); break; } } #endif /* CONFIG_FB_3DFX_ACCEL */ static int tdfxfb_cursor(struct fb_info *info, struct fb_cursor *cursor) { struct tdfx_par *par = info->par; u32 vidcfg; if (!hwcursor) return -EINVAL; /* just to force soft_cursor() call */ /* Too large of a cursor or wrong bpp :-( */ if (cursor->image.width > 64 || cursor->image.height > 64 || cursor->image.depth > 1) return -EINVAL; vidcfg = tdfx_inl(par, VIDPROCCFG); if (cursor->enable) tdfx_outl(par, VIDPROCCFG, vidcfg | VIDCFG_HWCURSOR_ENABLE); else tdfx_outl(par, VIDPROCCFG, vidcfg & ~VIDCFG_HWCURSOR_ENABLE); /* * If the cursor is not be changed this means either we want the * current cursor state (if enable is set) or we want to query what * we can do with the cursor (if enable is not set) */ if (!cursor->set) return 0; /* fix cursor color - XFree86 forgets to restore it properly */ if (cursor->set & FB_CUR_SETCMAP) { struct fb_cmap cmap = info->cmap; u32 bg_idx = cursor->image.bg_color; u32 fg_idx = cursor->image.fg_color; unsigned long bg_color, fg_color; fg_color = (((u32)cmap.red[fg_idx] & 0xff00) << 8) | (((u32)cmap.green[fg_idx] & 0xff00) << 0) | (((u32)cmap.blue[fg_idx] & 0xff00) >> 8); bg_color = (((u32)cmap.red[bg_idx] & 0xff00) << 8) | (((u32)cmap.green[bg_idx] & 0xff00) << 0) | (((u32)cmap.blue[bg_idx] & 0xff00) >> 8); banshee_make_room(par, 2); tdfx_outl(par, HWCURC0, bg_color); tdfx_outl(par, HWCURC1, fg_color); } if (cursor->set & FB_CUR_SETPOS) { int x = cursor->image.dx; int y = cursor->image.dy - info->var.yoffset; x += 63; y += 63; banshee_make_room(par, 1); tdfx_outl(par, HWCURLOC, (y << 16) + x); } if (cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE)) { /* * Voodoo 3 and above cards use 2 monochrome cursor patterns. * The reason is so the card can fetch 8 words at a time * and are stored on chip for use for the next 8 scanlines. * This reduces the number of times for access to draw the * cursor for each screen refresh. * Each pattern is a bitmap of 64 bit wide and 64 bit high * (total of 8192 bits or 1024 bytes). The two patterns are * stored in such a way that pattern 0 always resides in the * lower half (least significant 64 bits) of a 128 bit word * and pattern 1 the upper half. If you examine the data of * the cursor image the graphics card uses then from the * beginning you see line one of pattern 0, line one of * pattern 1, line two of pattern 0, line two of pattern 1, * etc etc. The linear stride for the cursor is always 16 bytes * (128 bits) which is the maximum cursor width times two for * the two monochrome patterns. */ u8 __iomem *cursorbase = info->screen_base + info->fix.smem_len; u8 *bitmap = (u8 *)cursor->image.data; u8 *mask = (u8 *)cursor->mask; int i; fb_memset(cursorbase, 0, 1024); for (i = 0; i < cursor->image.height; i++) { int h = 0; int j = (cursor->image.width + 7) >> 3; for (; j > 0; j--) { u8 data = *mask ^ *bitmap; if (cursor->rop == ROP_COPY) data = *mask & *bitmap; /* Pattern 0. Copy the cursor mask to it */ fb_writeb(*mask, cursorbase + h); mask++; /* Pattern 1. Copy the cursor bitmap to it */ fb_writeb(data, cursorbase + h + 8); bitmap++; h++; } cursorbase += 16; } } return 0; } static struct fb_ops tdfxfb_ops = { .owner = THIS_MODULE, .fb_check_var = tdfxfb_check_var, .fb_set_par = tdfxfb_set_par, .fb_setcolreg = tdfxfb_setcolreg, .fb_blank = tdfxfb_blank, .fb_pan_display = tdfxfb_pan_display, .fb_sync = banshee_wait_idle, .fb_cursor = tdfxfb_cursor, #ifdef CONFIG_FB_3DFX_ACCEL .fb_fillrect = tdfxfb_fillrect, .fb_copyarea = tdfxfb_copyarea, .fb_imageblit = tdfxfb_imageblit, #else .fb_fillrect = cfb_fillrect, .fb_copyarea = cfb_copyarea, .fb_imageblit = cfb_imageblit, #endif }; #ifdef CONFIG_FB_3DFX_I2C /* The voo GPIO registers don't have individual masks for each bit so we always have to read before writing. */ static void tdfxfb_i2c_setscl(void *data, int val) { struct tdfxfb_i2c_chan *chan = data; struct tdfx_par *par = chan->par; unsigned int r; r = tdfx_inl(par, VIDSERPARPORT); if (val) r |= I2C_SCL_OUT; else r &= ~I2C_SCL_OUT; tdfx_outl(par, VIDSERPARPORT, r); tdfx_inl(par, VIDSERPARPORT); /* flush posted write */ } static void tdfxfb_i2c_setsda(void *data, int val) { struct tdfxfb_i2c_chan *chan = data; struct tdfx_par *par = chan->par; unsigned int r; r = tdfx_inl(par, VIDSERPARPORT); if (val) r |= I2C_SDA_OUT; else r &= ~I2C_SDA_OUT; tdfx_outl(par, VIDSERPARPORT, r); tdfx_inl(par, VIDSERPARPORT); /* flush posted write */ } /* The GPIO pins are open drain, so the pins always remain outputs. We rely on the i2c-algo-bit routines to set the pins high before reading the input from other chips. */ static int tdfxfb_i2c_getscl(void *data) { struct tdfxfb_i2c_chan *chan = data; struct tdfx_par *par = chan->par; return (0 != (tdfx_inl(par, VIDSERPARPORT) & I2C_SCL_IN)); } static int tdfxfb_i2c_getsda(void *data) { struct tdfxfb_i2c_chan *chan = data; struct tdfx_par *par = chan->par; return (0 != (tdfx_inl(par, VIDSERPARPORT) & I2C_SDA_IN)); } static void tdfxfb_ddc_setscl(void *data, int val) { struct tdfxfb_i2c_chan *chan = data; struct tdfx_par *par = chan->par; unsigned int r; r = tdfx_inl(par, VIDSERPARPORT); if (val) r |= DDC_SCL_OUT; else r &= ~DDC_SCL_OUT; tdfx_outl(par, VIDSERPARPORT, r); tdfx_inl(par, VIDSERPARPORT); /* flush posted write */ } static void tdfxfb_ddc_setsda(void *data, int val) { struct tdfxfb_i2c_chan *chan = data; struct tdfx_par *par = chan->par; unsigned int r; r = tdfx_inl(par, VIDSERPARPORT); if (val) r |= DDC_SDA_OUT; else r &= ~DDC_SDA_OUT; tdfx_outl(par, VIDSERPARPORT, r); tdfx_inl(par, VIDSERPARPORT); /* flush posted write */ } static int tdfxfb_ddc_getscl(void *data) { struct tdfxfb_i2c_chan *chan = data; struct tdfx_par *par = chan->par; return (0 != (tdfx_inl(par, VIDSERPARPORT) & DDC_SCL_IN)); } static int tdfxfb_ddc_getsda(void *data) { struct tdfxfb_i2c_chan *chan = data; struct tdfx_par *par = chan->par; return (0 != (tdfx_inl(par, VIDSERPARPORT) & DDC_SDA_IN)); } static int __devinit tdfxfb_setup_ddc_bus(struct tdfxfb_i2c_chan *chan, const char *name, struct device *dev) { int rc; strlcpy(chan->adapter.name, name, sizeof(chan->adapter.name)); chan->adapter.owner = THIS_MODULE; chan->adapter.class = I2C_CLASS_DDC; chan->adapter.algo_data = &chan->algo; chan->adapter.dev.parent = dev; chan->algo.setsda = tdfxfb_ddc_setsda; chan->algo.setscl = tdfxfb_ddc_setscl; chan->algo.getsda = tdfxfb_ddc_getsda; chan->algo.getscl = tdfxfb_ddc_getscl; chan->algo.udelay = 10; chan->algo.timeout = msecs_to_jiffies(500); chan->algo.data = chan; i2c_set_adapdata(&chan->adapter, chan); rc = i2c_bit_add_bus(&chan->adapter); if (rc == 0) DPRINTK("I2C bus %s registered.\n", name); else chan->par = NULL; return rc; } static int __devinit tdfxfb_setup_i2c_bus(struct tdfxfb_i2c_chan *chan, const char *name, struct device *dev) { int rc; strlcpy(chan->adapter.name, name, sizeof(chan->adapter.name)); chan->adapter.owner = THIS_MODULE; chan->adapter.algo_data = &chan->algo; chan->adapter.dev.parent = dev; chan->algo.setsda = tdfxfb_i2c_setsda; chan->algo.setscl = tdfxfb_i2c_setscl; chan->algo.getsda = tdfxfb_i2c_getsda; chan->algo.getscl = tdfxfb_i2c_getscl; chan->algo.udelay = 10; chan->algo.timeout = msecs_to_jiffies(500); chan->algo.data = chan; i2c_set_adapdata(&chan->adapter, chan); rc = i2c_bit_add_bus(&chan->adapter); if (rc == 0) DPRINTK("I2C bus %s registered.\n", name); else chan->par = NULL; return rc; } static void __devinit tdfxfb_create_i2c_busses(struct fb_info *info) { struct tdfx_par *par = info->par; tdfx_outl(par, VIDINFORMAT, 0x8160); tdfx_outl(par, VIDSERPARPORT, 0xcffc0020); par->chan[0].par = par; par->chan[1].par = par; tdfxfb_setup_ddc_bus(&par->chan[0], "Voodoo3-DDC", info->dev); tdfxfb_setup_i2c_bus(&par->chan[1], "Voodoo3-I2C", info->dev); } static void tdfxfb_delete_i2c_busses(struct tdfx_par *par) { if (par->chan[0].par) i2c_del_adapter(&par->chan[0].adapter); par->chan[0].par = NULL; if (par->chan[1].par) i2c_del_adapter(&par->chan[1].adapter); par->chan[1].par = NULL; } static int tdfxfb_probe_i2c_connector(struct tdfx_par *par, struct fb_monspecs *specs) { u8 *edid = NULL; DPRINTK("Probe DDC Bus\n"); if (par->chan[0].par) edid = fb_ddc_read(&par->chan[0].adapter); if (edid) { fb_edid_to_monspecs(edid, specs); kfree(edid); return 0; } return 1; } #endif /* CONFIG_FB_3DFX_I2C */ /** * tdfxfb_probe - Device Initializiation * * @pdev: PCI Device to initialize * @id: PCI Device ID * * Initializes and allocates resources for PCI device @pdev. * */ static int __devinit tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id) { struct tdfx_par *default_par; struct fb_info *info; int err, lpitch; struct fb_monspecs *specs; bool found; err = pci_enable_device(pdev); if (err) { printk(KERN_ERR "tdfxfb: Can't enable pdev: %d\n", err); return err; } info = framebuffer_alloc(sizeof(struct tdfx_par), &pdev->dev); if (!info) return -ENOMEM; default_par = info->par; info->fix = tdfx_fix; /* Configure the default fb_fix_screeninfo first */ switch (pdev->device) { case PCI_DEVICE_ID_3DFX_BANSHEE: strcpy(info->fix.id, "3Dfx Banshee"); default_par->max_pixclock = BANSHEE_MAX_PIXCLOCK; break; case PCI_DEVICE_ID_3DFX_VOODOO3: strcpy(info->fix.id, "3Dfx Voodoo3"); default_par->max_pixclock = VOODOO3_MAX_PIXCLOCK; break; case PCI_DEVICE_ID_3DFX_VOODOO5: strcpy(info->fix.id, "3Dfx Voodoo5"); default_par->max_pixclock = VOODOO5_MAX_PIXCLOCK; break; } info->fix.mmio_start = pci_resource_start(pdev, 0); info->fix.mmio_len = pci_resource_len(pdev, 0); if (!request_mem_region(info->fix.mmio_start, info->fix.mmio_len, "tdfx regbase")) { printk(KERN_ERR "tdfxfb: Can't reserve regbase\n"); goto out_err; } default_par->regbase_virt = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len); if (!default_par->regbase_virt) { printk(KERN_ERR "fb: Can't remap %s register area.\n", info->fix.id); goto out_err_regbase; } info->fix.smem_start = pci_resource_start(pdev, 1); info->fix.smem_len = do_lfb_size(default_par, pdev->device); if (!info->fix.smem_len) { printk(KERN_ERR "fb: Can't count %s memory.\n", info->fix.id); goto out_err_regbase; } if (!request_mem_region(info->fix.smem_start, pci_resource_len(pdev, 1), "tdfx smem")) { printk(KERN_ERR "tdfxfb: Can't reserve smem\n"); goto out_err_regbase; } info->screen_base = ioremap_nocache(info->fix.smem_start, info->fix.smem_len); if (!info->screen_base) { printk(KERN_ERR "fb: Can't remap %s framebuffer.\n", info->fix.id); goto out_err_screenbase; } default_par->iobase = pci_resource_start(pdev, 2); if (!request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2), "tdfx iobase")) { printk(KERN_ERR "tdfxfb: Can't reserve iobase\n"); goto out_err_screenbase; } printk(KERN_INFO "fb: %s memory = %dK\n", info->fix.id, info->fix.smem_len >> 10); default_par->mtrr_handle = -1; if (!nomtrr) default_par->mtrr_handle = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1); info->fix.ypanstep = nopan ? 0 : 1; info->fix.ywrapstep = nowrap ? 0 : 1; info->fbops = &tdfxfb_ops; info->pseudo_palette = default_par->palette; info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; #ifdef CONFIG_FB_3DFX_ACCEL info->flags |= FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_IMAGEBLIT | FBINFO_READS_FAST; #endif /* reserve 8192 bits for cursor */ /* the 2.4 driver says PAGE_MASK boundary is not enough for Voodoo4 */ if (hwcursor) info->fix.smem_len = (info->fix.smem_len - 1024) & (PAGE_MASK << 1); specs = &info->monspecs; found = false; info->var.bits_per_pixel = 8; #ifdef CONFIG_FB_3DFX_I2C tdfxfb_create_i2c_busses(info); err = tdfxfb_probe_i2c_connector(default_par, specs); if (!err) { if (specs->modedb == NULL) DPRINTK("Unable to get Mode Database\n"); else { const struct fb_videomode *m; fb_videomode_to_modelist(specs->modedb, specs->modedb_len, &info->modelist); m = fb_find_best_display(specs, &info->modelist); if (m) { fb_videomode_to_var(&info->var, m); /* fill all other info->var's fields */ if (tdfxfb_check_var(&info->var, info) < 0) info->var = tdfx_var; else found = true; } } } #endif if (!mode_option && !found) mode_option = "640x480@60"; if (mode_option) { err = fb_find_mode(&info->var, info, mode_option, specs->modedb, specs->modedb_len, NULL, info->var.bits_per_pixel); if (!err || err == 4) info->var = tdfx_var; } if (found) { fb_destroy_modedb(specs->modedb); specs->modedb = NULL; } /* maximize virtual vertical length */ lpitch = info->var.xres_virtual * ((info->var.bits_per_pixel + 7) >> 3); info->var.yres_virtual = info->fix.smem_len / lpitch; if (info->var.yres_virtual < info->var.yres) goto out_err_iobase; if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { printk(KERN_ERR "tdfxfb: Can't allocate color map\n"); goto out_err_iobase; } if (register_framebuffer(info) < 0) { printk(KERN_ERR "tdfxfb: can't register framebuffer\n"); fb_dealloc_cmap(&info->cmap); goto out_err_iobase; } /* * Our driver data */ pci_set_drvdata(pdev, info); return 0; out_err_iobase: #ifdef CONFIG_FB_3DFX_I2C tdfxfb_delete_i2c_busses(default_par); #endif if (default_par->mtrr_handle >= 0) mtrr_del(default_par->mtrr_handle, info->fix.smem_start, info->fix.smem_len); release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2)); out_err_screenbase: if (info->screen_base) iounmap(info->screen_base); release_mem_region(info->fix.smem_start, pci_resource_len(pdev, 1)); out_err_regbase: /* * Cleanup after anything that was remapped/allocated. */ if (default_par->regbase_virt) iounmap(default_par->regbase_virt); release_mem_region(info->fix.mmio_start, info->fix.mmio_len); out_err: framebuffer_release(info); return -ENXIO; } #ifndef MODULE static void __init tdfxfb_setup(char *options) { char *this_opt; if (!options || !*options) return; while ((this_opt = strsep(&options, ",")) != NULL) { if (!*this_opt) continue; if (!strcmp(this_opt, "nopan")) { nopan = 1; } else if (!strcmp(this_opt, "nowrap")) { nowrap = 1; } else if (!strncmp(this_opt, "hwcursor=", 9)) { hwcursor = simple_strtoul(this_opt + 9, NULL, 0); #ifdef CONFIG_MTRR } else if (!strncmp(this_opt, "nomtrr", 6)) { nomtrr = 1; #endif } else { mode_option = this_opt; } } } #endif /** * tdfxfb_remove - Device removal * * @pdev: PCI Device to cleanup * * Releases all resources allocated during the course of the driver's * lifetime for the PCI device @pdev. * */ static void __devexit tdfxfb_remove(struct pci_dev *pdev) { struct fb_info *info = pci_get_drvdata(pdev); struct tdfx_par *par = info->par; unregister_framebuffer(info); #ifdef CONFIG_FB_3DFX_I2C tdfxfb_delete_i2c_busses(par); #endif if (par->mtrr_handle >= 0) mtrr_del(par->mtrr_handle, info->fix.smem_start, info->fix.smem_len); iounmap(par->regbase_virt); iounmap(info->screen_base); /* Clean up after reserved regions */ release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2)); release_mem_region(pci_resource_start(pdev, 1), pci_resource_len(pdev, 1)); release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); pci_set_drvdata(pdev, NULL); fb_dealloc_cmap(&info->cmap); framebuffer_release(info); } static int __init tdfxfb_init(void) { #ifndef MODULE char *option = NULL; if (fb_get_options("tdfxfb", &option)) return -ENODEV; tdfxfb_setup(option); #endif return pci_register_driver(&tdfxfb_driver); } static void __exit tdfxfb_exit(void) { pci_unregister_driver(&tdfxfb_driver); } MODULE_AUTHOR("Hannu Mallat <hmallat@cc.hut.fi>"); MODULE_DESCRIPTION("3Dfx framebuffer device driver"); MODULE_LICENSE("GPL"); module_param(hwcursor, int, 0644); MODULE_PARM_DESC(hwcursor, "Enable hardware cursor " "(1=enable, 0=disable, default=1)"); module_param(mode_option, charp, 0); MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'"); #ifdef CONFIG_MTRR module_param(nomtrr, bool, 0); MODULE_PARM_DESC(nomtrr, "Disable MTRR support (default: enabled)"); #endif module_init(tdfxfb_init); module_exit(tdfxfb_exit);
andyvand/android_kernel_samsung_crespo
drivers/video/tdfxfb.c
C
gpl-2.0
43,815
/* * File: af_phonet.c * * Phonet protocols family * * Copyright (C) 2008 Nokia Corporation. * * Contact: Remi Denis-Courmont <remi.denis-courmont@nokia.com> * Original author: Sakari Ailus <sakari.ailus@nokia.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <asm/unaligned.h> #include <net/sock.h> #include <linux/if_phonet.h> #include <linux/phonet.h> #include <net/phonet/phonet.h> #include <net/phonet/pn_dev.h> /* Transport protocol registration */ static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly; static struct phonet_protocol *phonet_proto_get(unsigned int protocol) { struct phonet_protocol *pp; if (protocol >= PHONET_NPROTO) return NULL; rcu_read_lock(); pp = rcu_dereference(proto_tab[protocol]); if (pp && !try_module_get(pp->prot->owner)) pp = NULL; rcu_read_unlock(); return pp; } static inline void phonet_proto_put(struct phonet_protocol *pp) { module_put(pp->prot->owner); } /* protocol family functions */ static int pn_socket_create(struct net *net, struct socket *sock, int protocol, int kern) { struct sock *sk; struct pn_sock *pn; struct phonet_protocol *pnp; int err; if (!capable(CAP_SYS_ADMIN)) return -EPERM; if (protocol == 0) { /* Default protocol selection */ switch (sock->type) { case SOCK_DGRAM: protocol = PN_PROTO_PHONET; break; case SOCK_SEQPACKET: protocol = PN_PROTO_PIPE; break; default: return -EPROTONOSUPPORT; } } pnp = phonet_proto_get(protocol); if (pnp == NULL && request_module("net-pf-%d-proto-%d", PF_PHONET, protocol) == 0) pnp = phonet_proto_get(protocol); if (pnp == NULL) return -EPROTONOSUPPORT; if (sock->type != pnp->sock_type) { err = -EPROTONOSUPPORT; goto out; } sk = sk_alloc(net, PF_PHONET, GFP_KERNEL, pnp->prot); if (sk == NULL) { err = -ENOMEM; goto out; } sock_init_data(sock, sk); sock->state = SS_UNCONNECTED; sock->ops = pnp->ops; sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv; sk->sk_protocol = protocol; pn = pn_sk(sk); pn->sobject = 0; pn->dobject = 0; pn->resource = 0; sk->sk_prot->init(sk); err = 0; out: phonet_proto_put(pnp); return err; } static const struct net_proto_family phonet_proto_family = { .family = PF_PHONET, .create = pn_socket_create, .owner = THIS_MODULE, }; /* Phonet device header operations */ static int pn_header_create(struct sk_buff *skb, struct net_device *dev, unsigned short type, const void *daddr, const void *saddr, unsigned len) { u8 *media = skb_push(skb, 1); if (type != ETH_P_PHONET) return -1; if (!saddr) saddr = dev->dev_addr; *media = *(const u8 *)saddr; return 1; } static int pn_header_parse(const struct sk_buff *skb, unsigned char *haddr) { const u8 *media = skb_mac_header(skb); *haddr = *media; return 1; } struct header_ops phonet_header_ops = { .create = pn_header_create, .parse = pn_header_parse, }; EXPORT_SYMBOL(phonet_header_ops); /* * Prepends an ISI header and sends a datagram. */ static int pn_send(struct sk_buff *skb, struct net_device *dev, u16 dst, u16 src, u8 res, u8 irq) { struct phonethdr *ph; int err; if (skb->len + 2 > 0xffff /* Phonet length field limit */ || skb->len + sizeof(struct phonethdr) > dev->mtu) { err = -EMSGSIZE; goto drop; } /* Broadcast sending is not implemented */ if (pn_addr(dst) == PNADDR_BROADCAST) { err = -EOPNOTSUPP; goto drop; } skb_reset_transport_header(skb); WARN_ON(skb_headroom(skb) & 1); /* HW assumes word alignment */ skb_push(skb, sizeof(struct phonethdr)); skb_reset_network_header(skb); ph = pn_hdr(skb); ph->pn_rdev = pn_dev(dst); ph->pn_sdev = pn_dev(src); ph->pn_res = res; ph->pn_length = __cpu_to_be16(skb->len + 2 - sizeof(*ph)); ph->pn_robj = pn_obj(dst); ph->pn_sobj = pn_obj(src); skb->protocol = htons(ETH_P_PHONET); skb->priority = 0; skb->dev = dev; if (skb->pkt_type == PACKET_LOOPBACK) { skb_reset_mac_header(skb); skb_orphan(skb); err = (irq ? netif_rx(skb) : netif_rx_ni(skb)) ? -ENOBUFS : 0; } else { err = dev_hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL, skb->len); if (err < 0) { err = -EHOSTUNREACH; goto drop; } err = dev_queue_xmit(skb); if (unlikely(err > 0)) err = net_xmit_errno(err); } return err; drop: kfree_skb(skb); return err; } static int pn_raw_send(const void *data, int len, struct net_device *dev, u16 dst, u16 src, u8 res) { struct sk_buff *skb = alloc_skb(MAX_PHONET_HEADER + len, GFP_ATOMIC); if (skb == NULL) return -ENOMEM; if (phonet_address_lookup(dev_net(dev), pn_addr(dst)) == 0) skb->pkt_type = PACKET_LOOPBACK; skb_reserve(skb, MAX_PHONET_HEADER); __skb_put(skb, len); skb_copy_to_linear_data(skb, data, len); return pn_send(skb, dev, dst, src, res, 1); } /* * Create a Phonet header for the skb and send it out. Returns * non-zero error code if failed. The skb is freed then. */ int pn_skb_send(struct sock *sk, struct sk_buff *skb, const struct sockaddr_pn *target) { struct net *net = sock_net(sk); struct net_device *dev; struct pn_sock *pn = pn_sk(sk); int err; u16 src, dst; u8 daddr, saddr, res; src = pn->sobject; if (target != NULL) { dst = pn_sockaddr_get_object(target); res = pn_sockaddr_get_resource(target); } else { dst = pn->dobject; res = pn->resource; } daddr = pn_addr(dst); err = -EHOSTUNREACH; if (sk->sk_bound_dev_if) dev = dev_get_by_index(net, sk->sk_bound_dev_if); else if (phonet_address_lookup(net, daddr) == 0) { dev = phonet_device_get(net); skb->pkt_type = PACKET_LOOPBACK; } else if (dst == 0) { /* Resource routing (small race until phonet_rcv()) */ struct sock *sk = pn_find_sock_by_res(net, res); if (sk) { sock_put(sk); dev = phonet_device_get(net); skb->pkt_type = PACKET_LOOPBACK; } else dev = phonet_route_output(net, daddr); } else dev = phonet_route_output(net, daddr); if (!dev || !(dev->flags & IFF_UP)) goto drop; saddr = phonet_address_get(dev, daddr); if (saddr == PN_NO_ADDR) goto drop; if (!pn_addr(src)) src = pn_object(saddr, pn_obj(src)); err = pn_send(skb, dev, dst, src, res, 0); dev_put(dev); return err; drop: kfree_skb(skb); if (dev) dev_put(dev); return err; } EXPORT_SYMBOL(pn_skb_send); /* Do not send an error message in response to an error message */ static inline int can_respond(struct sk_buff *skb) { const struct phonethdr *ph; const struct phonetmsg *pm; u8 submsg_id; if (!pskb_may_pull(skb, 3)) return 0; ph = pn_hdr(skb); if (ph->pn_res == PN_PREFIX && !pskb_may_pull(skb, 5)) return 0; if (ph->pn_res == PN_COMMGR) /* indications */ return 0; ph = pn_hdr(skb); /* re-acquires the pointer */ pm = pn_msg(skb); if (pm->pn_msg_id != PN_COMMON_MESSAGE) return 1; submsg_id = (ph->pn_res == PN_PREFIX) ? pm->pn_e_submsg_id : pm->pn_submsg_id; if (submsg_id != PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP && pm->pn_e_submsg_id != PN_COMM_SERVICE_NOT_IDENTIFIED_RESP) return 1; return 0; } static int send_obj_unreachable(struct sk_buff *rskb) { const struct phonethdr *oph = pn_hdr(rskb); const struct phonetmsg *opm = pn_msg(rskb); struct phonetmsg resp; memset(&resp, 0, sizeof(resp)); resp.pn_trans_id = opm->pn_trans_id; resp.pn_msg_id = PN_COMMON_MESSAGE; if (oph->pn_res == PN_PREFIX) { resp.pn_e_res_id = opm->pn_e_res_id; resp.pn_e_submsg_id = PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP; resp.pn_e_orig_msg_id = opm->pn_msg_id; resp.pn_e_status = 0; } else { resp.pn_submsg_id = PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP; resp.pn_orig_msg_id = opm->pn_msg_id; resp.pn_status = 0; } return pn_raw_send(&resp, sizeof(resp), rskb->dev, pn_object(oph->pn_sdev, oph->pn_sobj), pn_object(oph->pn_rdev, oph->pn_robj), oph->pn_res); } static int send_reset_indications(struct sk_buff *rskb) { struct phonethdr *oph = pn_hdr(rskb); static const u8 data[4] = { 0x00 /* trans ID */, 0x10 /* subscribe msg */, 0x00 /* subscription count */, 0x00 /* dummy */ }; return pn_raw_send(data, sizeof(data), rskb->dev, pn_object(oph->pn_sdev, 0x00), pn_object(oph->pn_rdev, oph->pn_robj), PN_COMMGR); } /* packet type functions */ /* * Stuff received packets to associated sockets. * On error, returns non-zero and releases the skb. */ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pkttype, struct net_device *orig_dev) { struct net *net = dev_net(dev); struct phonethdr *ph; struct sockaddr_pn sa; u16 len; /* check we have at least a full Phonet header */ if (!pskb_pull(skb, sizeof(struct phonethdr))) goto out; /* check that the advertised length is correct */ ph = pn_hdr(skb); len = get_unaligned_be16(&ph->pn_length); if (len < 2) goto out; len -= 2; if ((len > skb->len) || pskb_trim(skb, len)) goto out; skb_reset_transport_header(skb); pn_skb_get_dst_sockaddr(skb, &sa); /* check if this is broadcasted */ if (pn_sockaddr_get_addr(&sa) == PNADDR_BROADCAST) { pn_deliver_sock_broadcast(net, skb); goto out; } /* resource routing */ if (pn_sockaddr_get_object(&sa) == 0) { struct sock *sk = pn_find_sock_by_res(net, sa.spn_resource); if (sk) return sk_receive_skb(sk, skb, 0); } /* check if we are the destination */ if (phonet_address_lookup(net, pn_sockaddr_get_addr(&sa)) == 0) { /* Phonet packet input */ struct sock *sk = pn_find_sock_by_sa(net, &sa); if (sk) return sk_receive_skb(sk, skb, 0); if (can_respond(skb)) { send_obj_unreachable(skb); send_reset_indications(skb); } } else if (unlikely(skb->pkt_type == PACKET_LOOPBACK)) goto out; /* Race between address deletion and loopback */ else { /* Phonet packet routing */ struct net_device *out_dev; out_dev = phonet_route_output(net, pn_sockaddr_get_addr(&sa)); if (!out_dev) { LIMIT_NETDEBUG(KERN_WARNING"No Phonet route to %02X\n", pn_sockaddr_get_addr(&sa)); goto out; } __skb_push(skb, sizeof(struct phonethdr)); skb->dev = out_dev; if (out_dev == dev) { LIMIT_NETDEBUG(KERN_ERR"Phonet loop to %02X on %s\n", pn_sockaddr_get_addr(&sa), dev->name); goto out_dev; } /* Some drivers (e.g. TUN) do not allocate HW header space */ if (skb_cow_head(skb, out_dev->hard_header_len)) goto out_dev; if (dev_hard_header(skb, out_dev, ETH_P_PHONET, NULL, NULL, skb->len) < 0) goto out_dev; dev_queue_xmit(skb); dev_put(out_dev); return NET_RX_SUCCESS; out_dev: dev_put(out_dev); } out: kfree_skb(skb); return NET_RX_DROP; } static struct packet_type phonet_packet_type __read_mostly = { .type = cpu_to_be16(ETH_P_PHONET), .func = phonet_rcv, }; static DEFINE_MUTEX(proto_tab_lock); int __init_or_module phonet_proto_register(unsigned int protocol, struct phonet_protocol *pp) { int err = 0; if (protocol >= PHONET_NPROTO) return -EINVAL; err = proto_register(pp->prot, 1); if (err) return err; mutex_lock(&proto_tab_lock); if (proto_tab[protocol]) err = -EBUSY; else rcu_assign_pointer(proto_tab[protocol], pp); mutex_unlock(&proto_tab_lock); return err; } EXPORT_SYMBOL(phonet_proto_register); void phonet_proto_unregister(unsigned int protocol, struct phonet_protocol *pp) { mutex_lock(&proto_tab_lock); BUG_ON(proto_tab[protocol] != pp); RCU_INIT_POINTER(proto_tab[protocol], NULL); mutex_unlock(&proto_tab_lock); synchronize_rcu(); proto_unregister(pp->prot); } EXPORT_SYMBOL(phonet_proto_unregister); /* Module registration */ static int __init phonet_init(void) { int err; err = phonet_device_init(); if (err) return err; pn_sock_init(); err = sock_register(&phonet_proto_family); if (err) { printk(KERN_ALERT "phonet protocol family initialization failed\n"); goto err_sock; } dev_add_pack(&phonet_packet_type); phonet_sysctl_init(); err = isi_register(); if (err) goto err; return 0; err: phonet_sysctl_exit(); sock_unregister(PF_PHONET); dev_remove_pack(&phonet_packet_type); err_sock: phonet_device_exit(); return err; } static void __exit phonet_exit(void) { isi_unregister(); phonet_sysctl_exit(); sock_unregister(PF_PHONET); dev_remove_pack(&phonet_packet_type); phonet_device_exit(); } module_init(phonet_init); module_exit(phonet_exit); MODULE_DESCRIPTION("Phonet protocol stack for Linux"); MODULE_LICENSE("GPL"); MODULE_ALIAS_NETPROTO(PF_PHONET);
arcardinal/kernel_lge_g3
net/phonet/af_phonet.c
C
gpl-2.0
13,013
/*====================================================================== fmvj18x_cs.c 2.8 2002/03/23 A fmvj18x (and its compatibles) PCMCIA client driver Contributed by Shingo Fujimoto, shingo@flab.fujitsu.co.jp TDK LAK-CD021 and CONTEC C-NET(PC)C support added by Nobuhiro Katayama, kata-n@po.iijnet.or.jp The PCMCIA client code is based on code written by David Hinds. Network code is based on the "FMV-18x driver" by Yutaka TAMIYA but is actually largely Donald Becker's AT1700 driver, which carries the following attribution: Written 1993-94 by Donald Becker. Copyright 1993 United States Government as represented by the Director, National Security Agency. This software may be used and distributed according to the terms of the GNU General Public License, incorporated herein by reference. The author may be reached as becker@scyld.com, or C/O Scyld Computing Corporation 410 Severn Ave., Suite 210 Annapolis MD 21403 ======================================================================*/ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define DRV_NAME "fmvj18x_cs" #define DRV_VERSION "2.9" #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/ptrace.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/timer.h> #include <linux/interrupt.h> #include <linux/in.h> #include <linux/delay.h> #include <linux/ethtool.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/skbuff.h> #include <linux/if_arp.h> #include <linux/ioport.h> #include <linux/crc32.h> #include <pcmcia/cistpl.h> #include <pcmcia/ciscode.h> #include <pcmcia/ds.h> #include <asm/uaccess.h> #include <asm/io.h> /*====================================================================*/ /* Module parameters */ MODULE_DESCRIPTION("fmvj18x and compatible PCMCIA ethernet driver"); MODULE_LICENSE("GPL"); #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0) /* SRAM configuration */ /* 0:4KB*2 TX buffer else:8KB*2 TX buffer */ INT_MODULE_PARM(sram_config, 0); /*====================================================================*/ /* PCMCIA event handlers */ static int fmvj18x_config(struct pcmcia_device *link); static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id); static int fmvj18x_setup_mfc(struct pcmcia_device *link); static void fmvj18x_release(struct pcmcia_device *link); static void fmvj18x_detach(struct pcmcia_device *p_dev); /* LAN controller(MBH86960A) specific routines */ static int fjn_config(struct net_device *dev, struct ifmap *map); static int fjn_open(struct net_device *dev); static int fjn_close(struct net_device *dev); static netdev_tx_t fjn_start_xmit(struct sk_buff *skb, struct net_device *dev); static irqreturn_t fjn_interrupt(int irq, void *dev_id); static void fjn_rx(struct net_device *dev); static void fjn_reset(struct net_device *dev); static void set_rx_mode(struct net_device *dev); static void fjn_tx_timeout(struct net_device *dev); static const struct ethtool_ops netdev_ethtool_ops; /* card type */ typedef enum { MBH10302, MBH10304, TDK, CONTEC, LA501, UNGERMANN, XXX10304, NEC, KME } cardtype_t; /* driver specific data structure */ typedef struct local_info_t { struct pcmcia_device *p_dev; long open_time; uint tx_started:1; uint tx_queue; u_short tx_queue_len; cardtype_t cardtype; u_short sent; u_char __iomem *base; } local_info_t; #define MC_FILTERBREAK 64 /*====================================================================*/ /* ioport offset from the base address */ #define TX_STATUS 0 /* transmit status register */ #define RX_STATUS 1 /* receive status register */ #define TX_INTR 2 /* transmit interrupt mask register */ #define RX_INTR 3 /* receive interrupt mask register */ #define TX_MODE 4 /* transmit mode register */ #define RX_MODE 5 /* receive mode register */ #define CONFIG_0 6 /* configuration register 0 */ #define CONFIG_1 7 /* configuration register 1 */ #define NODE_ID 8 /* node ID register (bank 0) */ #define MAR_ADR 8 /* multicast address registers (bank 1) */ #define DATAPORT 8 /* buffer mem port registers (bank 2) */ #define TX_START 10 /* transmit start register */ #define COL_CTRL 11 /* 16 collision control register */ #define BMPR12 12 /* reserved */ #define BMPR13 13 /* reserved */ #define RX_SKIP 14 /* skip received packet register */ #define LAN_CTRL 16 /* LAN card control register */ #define MAC_ID 0x1a /* hardware address */ #define UNGERMANN_MAC_ID 0x18 /* UNGERMANN-BASS hardware address */ /* control bits */ #define ENA_TMT_OK 0x80 #define ENA_TMT_REC 0x20 #define ENA_COL 0x04 #define ENA_16_COL 0x02 #define ENA_TBUS_ERR 0x01 #define ENA_PKT_RDY 0x80 #define ENA_BUS_ERR 0x40 #define ENA_LEN_ERR 0x08 #define ENA_ALG_ERR 0x04 #define ENA_CRC_ERR 0x02 #define ENA_OVR_FLO 0x01 /* flags */ #define F_TMT_RDY 0x80 /* can accept new packet */ #define F_NET_BSY 0x40 /* carrier is detected */ #define F_TMT_OK 0x20 /* send packet successfully */ #define F_SRT_PKT 0x10 /* short packet error */ #define F_COL_ERR 0x04 /* collision error */ #define F_16_COL 0x02 /* 16 collision error */ #define F_TBUS_ERR 0x01 /* bus read error */ #define F_PKT_RDY 0x80 /* packet(s) in buffer */ #define F_BUS_ERR 0x40 /* bus read error */ #define F_LEN_ERR 0x08 /* short packet */ #define F_ALG_ERR 0x04 /* frame error */ #define F_CRC_ERR 0x02 /* CRC error */ #define F_OVR_FLO 0x01 /* overflow error */ #define F_BUF_EMP 0x40 /* receive buffer is empty */ #define F_SKP_PKT 0x05 /* drop packet in buffer */ /* default bitmaps */ #define D_TX_INTR ( ENA_TMT_OK ) #define D_RX_INTR ( ENA_PKT_RDY | ENA_LEN_ERR \ | ENA_ALG_ERR | ENA_CRC_ERR | ENA_OVR_FLO ) #define TX_STAT_M ( F_TMT_RDY ) #define RX_STAT_M ( F_PKT_RDY | F_LEN_ERR \ | F_ALG_ERR | F_CRC_ERR | F_OVR_FLO ) /* commands */ #define D_TX_MODE 0x06 /* no tests, detect carrier */ #define ID_MATCHED 0x02 /* (RX_MODE) */ #define RECV_ALL 0x03 /* (RX_MODE) */ #define CONFIG0_DFL 0x5a /* 16bit bus, 4K x 2 Tx queues */ #define CONFIG0_DFL_1 0x5e /* 16bit bus, 8K x 2 Tx queues */ #define CONFIG0_RST 0xda /* Data Link Controller off (CONFIG_0) */ #define CONFIG0_RST_1 0xde /* Data Link Controller off (CONFIG_0) */ #define BANK_0 0xa0 /* bank 0 (CONFIG_1) */ #define BANK_1 0xa4 /* bank 1 (CONFIG_1) */ #define BANK_2 0xa8 /* bank 2 (CONFIG_1) */ #define CHIP_OFF 0x80 /* contrl chip power off (CONFIG_1) */ #define DO_TX 0x80 /* do transmit packet */ #define SEND_PKT 0x81 /* send a packet */ #define AUTO_MODE 0x07 /* Auto skip packet on 16 col detected */ #define MANU_MODE 0x03 /* Stop and skip packet on 16 col */ #define TDK_AUTO_MODE 0x47 /* Auto skip packet on 16 col detected */ #define TDK_MANU_MODE 0x43 /* Stop and skip packet on 16 col */ #define INTR_OFF 0x0d /* LAN controller ignores interrupts */ #define INTR_ON 0x1d /* LAN controller will catch interrupts */ #define TX_TIMEOUT ((400*HZ)/1000) #define BANK_0U 0x20 /* bank 0 (CONFIG_1) */ #define BANK_1U 0x24 /* bank 1 (CONFIG_1) */ #define BANK_2U 0x28 /* bank 2 (CONFIG_1) */ static const struct net_device_ops fjn_netdev_ops = { .ndo_open = fjn_open, .ndo_stop = fjn_close, .ndo_start_xmit = fjn_start_xmit, .ndo_tx_timeout = fjn_tx_timeout, .ndo_set_config = fjn_config, .ndo_set_rx_mode = set_rx_mode, .ndo_change_mtu = eth_change_mtu, .ndo_set_mac_address = eth_mac_addr, .ndo_validate_addr = eth_validate_addr, }; static int fmvj18x_probe(struct pcmcia_device *link) { local_info_t *lp; struct net_device *dev; dev_dbg(&link->dev, "fmvj18x_attach()\n"); /* Make up a FMVJ18x specific data structure */ dev = alloc_etherdev(sizeof(local_info_t)); if (!dev) return -ENOMEM; lp = netdev_priv(dev); link->priv = dev; lp->p_dev = link; lp->base = NULL; /* The io structure describes IO port mapping */ link->resource[0]->end = 32; link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; /* General socket configuration */ link->config_flags |= CONF_ENABLE_IRQ; dev->netdev_ops = &fjn_netdev_ops; dev->watchdog_timeo = TX_TIMEOUT; SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); return fmvj18x_config(link); } /* fmvj18x_attach */ /*====================================================================*/ static void fmvj18x_detach(struct pcmcia_device *link) { struct net_device *dev = link->priv; dev_dbg(&link->dev, "fmvj18x_detach\n"); unregister_netdev(dev); fmvj18x_release(link); free_netdev(dev); } /* fmvj18x_detach */ /*====================================================================*/ static int mfc_try_io_port(struct pcmcia_device *link) { int i, ret; static const unsigned int serial_base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; for (i = 0; i < 5; i++) { link->resource[1]->start = serial_base[i]; link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; if (link->resource[1]->start == 0) { link->resource[1]->end = 0; pr_notice("out of resource for serial\n"); } ret = pcmcia_request_io(link); if (ret == 0) return ret; } return ret; } static int ungermann_try_io_port(struct pcmcia_device *link) { int ret; unsigned int ioaddr; /* Ungermann-Bass Access/CARD accepts 0x300,0x320,0x340,0x360 0x380,0x3c0 only for ioport. */ for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) { link->resource[0]->start = ioaddr; ret = pcmcia_request_io(link); if (ret == 0) { /* calculate ConfigIndex value */ link->config_index = ((link->resource[0]->start & 0x0f0) >> 3) | 0x22; return ret; } } return ret; /* RequestIO failed */ } static int fmvj18x_ioprobe(struct pcmcia_device *p_dev, void *priv_data) { return 0; /* strange, but that's what the code did already before... */ } static int fmvj18x_config(struct pcmcia_device *link) { struct net_device *dev = link->priv; local_info_t *lp = netdev_priv(dev); int i, ret; unsigned int ioaddr; cardtype_t cardtype; char *card_name = "unknown"; u8 *buf; size_t len; u_char buggybuf[32]; dev_dbg(&link->dev, "fmvj18x_config\n"); link->io_lines = 5; len = pcmcia_get_tuple(link, CISTPL_FUNCE, &buf); kfree(buf); if (len) { /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */ ret = pcmcia_loop_config(link, fmvj18x_ioprobe, NULL); if (ret != 0) goto failed; switch (link->manf_id) { case MANFID_TDK: cardtype = TDK; if (link->card_id == PRODID_TDK_GN3410 || link->card_id == PRODID_TDK_NP9610 || link->card_id == PRODID_TDK_MN3200) { /* MultiFunction Card */ link->config_base = 0x800; link->config_index = 0x47; link->resource[1]->end = 8; } break; case MANFID_NEC: cardtype = NEC; /* MultiFunction Card */ link->config_base = 0x800; link->config_index = 0x47; link->resource[1]->end = 8; break; case MANFID_KME: cardtype = KME; /* MultiFunction Card */ link->config_base = 0x800; link->config_index = 0x47; link->resource[1]->end = 8; break; case MANFID_CONTEC: cardtype = CONTEC; break; case MANFID_FUJITSU: if (link->config_base == 0x0fe0) cardtype = MBH10302; else if (link->card_id == PRODID_FUJITSU_MBH10302) /* RATOC REX-5588/9822/4886's PRODID are 0004(=MBH10302), but these are MBH10304 based card. */ cardtype = MBH10304; else if (link->card_id == PRODID_FUJITSU_MBH10304) cardtype = MBH10304; else cardtype = LA501; break; default: cardtype = MBH10304; } } else { /* old type card */ switch (link->manf_id) { case MANFID_FUJITSU: if (link->card_id == PRODID_FUJITSU_MBH10304) { cardtype = XXX10304; /* MBH10304 with buggy CIS */ link->config_index = 0x20; } else { cardtype = MBH10302; /* NextCom NC5310, etc. */ link->config_index = 1; } break; case MANFID_UNGERMANN: cardtype = UNGERMANN; break; default: cardtype = MBH10302; link->config_index = 1; } } if (link->resource[1]->end != 0) { ret = mfc_try_io_port(link); if (ret != 0) goto failed; } else if (cardtype == UNGERMANN) { ret = ungermann_try_io_port(link); if (ret != 0) goto failed; } else { ret = pcmcia_request_io(link); if (ret) goto failed; } ret = pcmcia_request_irq(link, fjn_interrupt); if (ret) goto failed; ret = pcmcia_enable_device(link); if (ret) goto failed; dev->irq = link->irq; dev->base_addr = link->resource[0]->start; if (resource_size(link->resource[1]) != 0) { ret = fmvj18x_setup_mfc(link); if (ret != 0) goto failed; } ioaddr = dev->base_addr; /* Reset controller */ if (sram_config == 0) outb(CONFIG0_RST, ioaddr + CONFIG_0); else outb(CONFIG0_RST_1, ioaddr + CONFIG_0); /* Power On chip and select bank 0 */ if (cardtype == MBH10302) outb(BANK_0, ioaddr + CONFIG_1); else outb(BANK_0U, ioaddr + CONFIG_1); /* Set hardware address */ switch (cardtype) { case MBH10304: case TDK: case LA501: case CONTEC: case NEC: case KME: if (cardtype == MBH10304) { card_name = "FMV-J182"; len = pcmcia_get_tuple(link, CISTPL_FUNCE, &buf); if (len < 11) { kfree(buf); goto failed; } /* Read MACID from CIS */ for (i = 5; i < 11; i++) dev->dev_addr[i] = buf[i]; kfree(buf); } else { if (pcmcia_get_mac_from_cis(link, dev)) goto failed; if( cardtype == TDK ) { card_name = "TDK LAK-CD021"; } else if( cardtype == LA501 ) { card_name = "LA501"; } else if( cardtype == NEC ) { card_name = "PK-UG-J001"; } else if( cardtype == KME ) { card_name = "Panasonic"; } else { card_name = "C-NET(PC)C"; } } break; case UNGERMANN: /* Read MACID from register */ for (i = 0; i < 6; i++) dev->dev_addr[i] = inb(ioaddr + UNGERMANN_MAC_ID + i); card_name = "Access/CARD"; break; case XXX10304: /* Read MACID from Buggy CIS */ if (fmvj18x_get_hwinfo(link, buggybuf) == -1) { pr_notice("unable to read hardware net address\n"); goto failed; } for (i = 0 ; i < 6; i++) { dev->dev_addr[i] = buggybuf[i]; } card_name = "FMV-J182"; break; case MBH10302: default: /* Read MACID from register */ for (i = 0; i < 6; i++) dev->dev_addr[i] = inb(ioaddr + MAC_ID + i); card_name = "FMV-J181"; break; } lp->cardtype = cardtype; SET_NETDEV_DEV(dev, &link->dev); if (register_netdev(dev) != 0) { pr_notice("register_netdev() failed\n"); goto failed; } /* print current configuration */ netdev_info(dev, "%s, sram %s, port %#3lx, irq %d, hw_addr %pM\n", card_name, sram_config == 0 ? "4K TX*2" : "8K TX*2", dev->base_addr, dev->irq, dev->dev_addr); return 0; failed: fmvj18x_release(link); return -ENODEV; } /* fmvj18x_config */ /*====================================================================*/ static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id) { u_char __iomem *base; int i, j; /* Allocate a small memory window */ link->resource[2]->flags |= WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; link->resource[2]->start = 0; link->resource[2]->end = 0; i = pcmcia_request_window(link, link->resource[2], 0); if (i != 0) return -1; base = ioremap(link->resource[2]->start, resource_size(link->resource[2])); pcmcia_map_mem_page(link, link->resource[2], 0); /* * MBH10304 CISTPL_FUNCE_LAN_NODE_ID format * 22 0d xx xx xx 04 06 yy yy yy yy yy yy ff * 'xx' is garbage. * 'yy' is MAC address. */ for (i = 0; i < 0x200; i++) { if (readb(base+i*2) == 0x22) { if (readb(base+(i-1)*2) == 0xff && readb(base+(i+5)*2) == 0x04 && readb(base+(i+6)*2) == 0x06 && readb(base+(i+13)*2) == 0xff) break; } } if (i != 0x200) { for (j = 0 ; j < 6; j++,i++) { node_id[j] = readb(base+(i+7)*2); } } iounmap(base); j = pcmcia_release_window(link, link->resource[2]); return (i != 0x200) ? 0 : -1; } /* fmvj18x_get_hwinfo */ /*====================================================================*/ static int fmvj18x_setup_mfc(struct pcmcia_device *link) { int i; struct net_device *dev = link->priv; unsigned int ioaddr; local_info_t *lp = netdev_priv(dev); /* Allocate a small memory window */ link->resource[3]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; link->resource[3]->start = link->resource[3]->end = 0; i = pcmcia_request_window(link, link->resource[3], 0); if (i != 0) return -1; lp->base = ioremap(link->resource[3]->start, resource_size(link->resource[3])); if (lp->base == NULL) { netdev_notice(dev, "ioremap failed\n"); return -1; } i = pcmcia_map_mem_page(link, link->resource[3], 0); if (i != 0) { iounmap(lp->base); lp->base = NULL; return -1; } ioaddr = dev->base_addr; writeb(0x47, lp->base+0x800); /* Config Option Register of LAN */ writeb(0x0, lp->base+0x802); /* Config and Status Register */ writeb(ioaddr & 0xff, lp->base+0x80a); /* I/O Base(Low) of LAN */ writeb((ioaddr >> 8) & 0xff, lp->base+0x80c); /* I/O Base(High) of LAN */ writeb(0x45, lp->base+0x820); /* Config Option Register of Modem */ writeb(0x8, lp->base+0x822); /* Config and Status Register */ return 0; } /*====================================================================*/ static void fmvj18x_release(struct pcmcia_device *link) { struct net_device *dev = link->priv; local_info_t *lp = netdev_priv(dev); u_char __iomem *tmp; dev_dbg(&link->dev, "fmvj18x_release\n"); if (lp->base != NULL) { tmp = lp->base; lp->base = NULL; /* set NULL before iounmap */ iounmap(tmp); } pcmcia_disable_device(link); } static int fmvj18x_suspend(struct pcmcia_device *link) { struct net_device *dev = link->priv; if (link->open) netif_device_detach(dev); return 0; } static int fmvj18x_resume(struct pcmcia_device *link) { struct net_device *dev = link->priv; if (link->open) { fjn_reset(dev); netif_device_attach(dev); } return 0; } /*====================================================================*/ static const struct pcmcia_device_id fmvj18x_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x0004, 0x0004), PCMCIA_DEVICE_PROD_ID12("EAGLE Technology", "NE200 ETHERNET LAN MBH10302 04", 0x528c88c4, 0x74f91e59), PCMCIA_DEVICE_PROD_ID12("Eiger Labs,Inc", "EPX-10BT PC Card Ethernet 10BT", 0x53af556e, 0x877f9922), PCMCIA_DEVICE_PROD_ID12("Eiger labs,Inc.", "EPX-10BT PC Card Ethernet 10BT", 0xf47e6c66, 0x877f9922), PCMCIA_DEVICE_PROD_ID12("FUJITSU", "LAN Card(FMV-J182)", 0x6ee5a3d8, 0x5baf31db), PCMCIA_DEVICE_PROD_ID12("FUJITSU", "MBH10308", 0x6ee5a3d8, 0x3f04875e), PCMCIA_DEVICE_PROD_ID12("FUJITSU TOWA", "LA501", 0xb8451188, 0x12939ba2), PCMCIA_DEVICE_PROD_ID12("HITACHI", "HT-4840-11", 0xf4f43949, 0x773910f4), PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310B Ver1.0 ", 0x8cef4d3a, 0x075fc7b6), PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310 Ver1.0 ", 0x8cef4d3a, 0xbccf43e6), PCMCIA_DEVICE_PROD_ID12("RATOC System Inc.", "10BASE_T CARD R280", 0x85c10e17, 0xd9413666), PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CD02x", 0x1eae9475, 0x8fa0ee70), PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CF010", 0x1eae9475, 0x7683bc9a), PCMCIA_DEVICE_PROD_ID1("CONTEC Co.,Ltd.", 0x58d8fee2), PCMCIA_DEVICE_PROD_ID1("PCMCIA LAN MBH10304 ES", 0x2599f454), PCMCIA_DEVICE_PROD_ID1("PCMCIA MBH10302", 0x8f4005da), PCMCIA_DEVICE_PROD_ID1("UBKK,V2.0", 0x90888080), PCMCIA_PFC_DEVICE_PROD_ID12(0, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed), PCMCIA_PFC_DEVICE_PROD_ID12(0, "NEC", "PK-UG-J001" ,0x18df0ba0 ,0x831b1064), PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0d0a), PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0e0a), PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0e01), PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0a05), PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0b05), PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x1101), PCMCIA_DEVICE_NULL, }; MODULE_DEVICE_TABLE(pcmcia, fmvj18x_ids); static struct pcmcia_driver fmvj18x_cs_driver = { .owner = THIS_MODULE, .name = "fmvj18x_cs", .probe = fmvj18x_probe, .remove = fmvj18x_detach, .id_table = fmvj18x_ids, .suspend = fmvj18x_suspend, .resume = fmvj18x_resume, }; static int __init init_fmvj18x_cs(void) { return pcmcia_register_driver(&fmvj18x_cs_driver); } static void __exit exit_fmvj18x_cs(void) { pcmcia_unregister_driver(&fmvj18x_cs_driver); } module_init(init_fmvj18x_cs); module_exit(exit_fmvj18x_cs); /*====================================================================*/ static irqreturn_t fjn_interrupt(int dummy, void *dev_id) { struct net_device *dev = dev_id; local_info_t *lp = netdev_priv(dev); unsigned int ioaddr; unsigned short tx_stat, rx_stat; ioaddr = dev->base_addr; /* avoid multiple interrupts */ outw(0x0000, ioaddr + TX_INTR); /* wait for a while */ udelay(1); /* get status */ tx_stat = inb(ioaddr + TX_STATUS); rx_stat = inb(ioaddr + RX_STATUS); /* clear status */ outb(tx_stat, ioaddr + TX_STATUS); outb(rx_stat, ioaddr + RX_STATUS); pr_debug("%s: interrupt, rx_status %02x.\n", dev->name, rx_stat); pr_debug(" tx_status %02x.\n", tx_stat); if (rx_stat || (inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) { /* there is packet(s) in rx buffer */ fjn_rx(dev); } if (tx_stat & F_TMT_RDY) { dev->stats.tx_packets += lp->sent ; lp->sent = 0 ; if (lp->tx_queue) { outb(DO_TX | lp->tx_queue, ioaddr + TX_START); lp->sent = lp->tx_queue ; lp->tx_queue = 0; lp->tx_queue_len = 0; dev->trans_start = jiffies; } else { lp->tx_started = 0; } netif_wake_queue(dev); } pr_debug("%s: exiting interrupt,\n", dev->name); pr_debug(" tx_status %02x, rx_status %02x.\n", tx_stat, rx_stat); outb(D_TX_INTR, ioaddr + TX_INTR); outb(D_RX_INTR, ioaddr + RX_INTR); if (lp->base != NULL) { /* Ack interrupt for multifunction card */ writeb(0x01, lp->base+0x802); writeb(0x09, lp->base+0x822); } return IRQ_HANDLED; } /* fjn_interrupt */ /*====================================================================*/ static void fjn_tx_timeout(struct net_device *dev) { struct local_info_t *lp = netdev_priv(dev); unsigned int ioaddr = dev->base_addr; netdev_notice(dev, "transmit timed out with status %04x, %s?\n", htons(inw(ioaddr + TX_STATUS)), inb(ioaddr + TX_STATUS) & F_TMT_RDY ? "IRQ conflict" : "network cable problem"); netdev_notice(dev, "timeout registers: %04x %04x %04x " "%04x %04x %04x %04x %04x.\n", htons(inw(ioaddr + 0)), htons(inw(ioaddr + 2)), htons(inw(ioaddr + 4)), htons(inw(ioaddr + 6)), htons(inw(ioaddr + 8)), htons(inw(ioaddr + 10)), htons(inw(ioaddr + 12)), htons(inw(ioaddr + 14))); dev->stats.tx_errors++; /* ToDo: We should try to restart the adaptor... */ local_irq_disable(); fjn_reset(dev); lp->tx_started = 0; lp->tx_queue = 0; lp->tx_queue_len = 0; lp->sent = 0; lp->open_time = jiffies; local_irq_enable(); netif_wake_queue(dev); } static netdev_tx_t fjn_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct local_info_t *lp = netdev_priv(dev); unsigned int ioaddr = dev->base_addr; short length = skb->len; if (length < ETH_ZLEN) { if (skb_padto(skb, ETH_ZLEN)) return NETDEV_TX_OK; length = ETH_ZLEN; } netif_stop_queue(dev); { unsigned char *buf = skb->data; if (length > ETH_FRAME_LEN) { netdev_notice(dev, "Attempting to send a large packet (%d bytes)\n", length); return NETDEV_TX_BUSY; } netdev_dbg(dev, "Transmitting a packet of length %lu\n", (unsigned long)skb->len); dev->stats.tx_bytes += skb->len; /* Disable both interrupts. */ outw(0x0000, ioaddr + TX_INTR); /* wait for a while */ udelay(1); outw(length, ioaddr + DATAPORT); outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1); lp->tx_queue++; lp->tx_queue_len += ((length+3) & ~1); if (lp->tx_started == 0) { /* If the Tx is idle, always trigger a transmit. */ outb(DO_TX | lp->tx_queue, ioaddr + TX_START); lp->sent = lp->tx_queue ; lp->tx_queue = 0; lp->tx_queue_len = 0; lp->tx_started = 1; netif_start_queue(dev); } else { if( sram_config == 0 ) { if (lp->tx_queue_len < (4096 - (ETH_FRAME_LEN +2)) ) /* Yes, there is room for one more packet. */ netif_start_queue(dev); } else { if (lp->tx_queue_len < (8192 - (ETH_FRAME_LEN +2)) && lp->tx_queue < 127 ) /* Yes, there is room for one more packet. */ netif_start_queue(dev); } } /* Re-enable interrupts */ outb(D_TX_INTR, ioaddr + TX_INTR); outb(D_RX_INTR, ioaddr + RX_INTR); } dev_kfree_skb (skb); return NETDEV_TX_OK; } /* fjn_start_xmit */ /*====================================================================*/ static void fjn_reset(struct net_device *dev) { struct local_info_t *lp = netdev_priv(dev); unsigned int ioaddr = dev->base_addr; int i; netdev_dbg(dev, "fjn_reset() called\n"); /* Reset controller */ if( sram_config == 0 ) outb(CONFIG0_RST, ioaddr + CONFIG_0); else outb(CONFIG0_RST_1, ioaddr + CONFIG_0); /* Power On chip and select bank 0 */ if (lp->cardtype == MBH10302) outb(BANK_0, ioaddr + CONFIG_1); else outb(BANK_0U, ioaddr + CONFIG_1); /* Set Tx modes */ outb(D_TX_MODE, ioaddr + TX_MODE); /* set Rx modes */ outb(ID_MATCHED, ioaddr + RX_MODE); /* Set hardware address */ for (i = 0; i < 6; i++) outb(dev->dev_addr[i], ioaddr + NODE_ID + i); /* (re)initialize the multicast table */ set_rx_mode(dev); /* Switch to bank 2 (runtime mode) */ if (lp->cardtype == MBH10302) outb(BANK_2, ioaddr + CONFIG_1); else outb(BANK_2U, ioaddr + CONFIG_1); /* set 16col ctrl bits */ if( lp->cardtype == TDK || lp->cardtype == CONTEC) outb(TDK_AUTO_MODE, ioaddr + COL_CTRL); else outb(AUTO_MODE, ioaddr + COL_CTRL); /* clear Reserved Regs */ outb(0x00, ioaddr + BMPR12); outb(0x00, ioaddr + BMPR13); /* reset Skip packet reg. */ outb(0x01, ioaddr + RX_SKIP); /* Enable Tx and Rx */ if( sram_config == 0 ) outb(CONFIG0_DFL, ioaddr + CONFIG_0); else outb(CONFIG0_DFL_1, ioaddr + CONFIG_0); /* Init receive pointer ? */ inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT); /* Clear all status */ outb(0xff, ioaddr + TX_STATUS); outb(0xff, ioaddr + RX_STATUS); if (lp->cardtype == MBH10302) outb(INTR_OFF, ioaddr + LAN_CTRL); /* Turn on Rx interrupts */ outb(D_TX_INTR, ioaddr + TX_INTR); outb(D_RX_INTR, ioaddr + RX_INTR); /* Turn on interrupts from LAN card controller */ if (lp->cardtype == MBH10302) outb(INTR_ON, ioaddr + LAN_CTRL); } /* fjn_reset */ /*====================================================================*/ static void fjn_rx(struct net_device *dev) { unsigned int ioaddr = dev->base_addr; int boguscount = 10; /* 5 -> 10: by agy 19940922 */ pr_debug("%s: in rx_packet(), rx_status %02x.\n", dev->name, inb(ioaddr + RX_STATUS)); while ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) { u_short status = inw(ioaddr + DATAPORT); netdev_dbg(dev, "Rxing packet mode %02x status %04x.\n", inb(ioaddr + RX_MODE), status); #ifndef final_version if (status == 0) { outb(F_SKP_PKT, ioaddr + RX_SKIP); break; } #endif if ((status & 0xF0) != 0x20) { /* There was an error. */ dev->stats.rx_errors++; if (status & F_LEN_ERR) dev->stats.rx_length_errors++; if (status & F_ALG_ERR) dev->stats.rx_frame_errors++; if (status & F_CRC_ERR) dev->stats.rx_crc_errors++; if (status & F_OVR_FLO) dev->stats.rx_over_errors++; } else { u_short pkt_len = inw(ioaddr + DATAPORT); /* Malloc up new buffer. */ struct sk_buff *skb; if (pkt_len > 1550) { netdev_notice(dev, "The FMV-18x claimed a very large packet, size %d\n", pkt_len); outb(F_SKP_PKT, ioaddr + RX_SKIP); dev->stats.rx_errors++; break; } skb = netdev_alloc_skb(dev, pkt_len + 2); if (skb == NULL) { netdev_notice(dev, "Memory squeeze, dropping packet (len %d)\n", pkt_len); outb(F_SKP_PKT, ioaddr + RX_SKIP); dev->stats.rx_dropped++; break; } skb_reserve(skb, 2); insw(ioaddr + DATAPORT, skb_put(skb, pkt_len), (pkt_len + 1) >> 1); skb->protocol = eth_type_trans(skb, dev); { int i; pr_debug("%s: Rxed packet of length %d: ", dev->name, pkt_len); for (i = 0; i < 14; i++) pr_debug(" %02x", skb->data[i]); pr_debug(".\n"); } netif_rx(skb); dev->stats.rx_packets++; dev->stats.rx_bytes += pkt_len; } if (--boguscount <= 0) break; } /* If any worth-while packets have been received, dev_rint() has done a netif_wake_queue() for us and will work on them when we get to the bottom-half routine. */ /* if (lp->cardtype != TDK) { int i; for (i = 0; i < 20; i++) { if ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == F_BUF_EMP) break; (void)inw(ioaddr + DATAPORT); /+ dummy status read +/ outb(F_SKP_PKT, ioaddr + RX_SKIP); } if (i > 0) pr_debug("%s: Exint Rx packet with mode %02x after " "%d ticks.\n", dev->name, inb(ioaddr + RX_MODE), i); } */ } /* fjn_rx */ /*====================================================================*/ static void netdev_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) { strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); strlcpy(info->version, DRV_VERSION, sizeof(info->version)); snprintf(info->bus_info, sizeof(info->bus_info), "PCMCIA 0x%lx", dev->base_addr); } static const struct ethtool_ops netdev_ethtool_ops = { .get_drvinfo = netdev_get_drvinfo, }; static int fjn_config(struct net_device *dev, struct ifmap *map){ return 0; } static int fjn_open(struct net_device *dev) { struct local_info_t *lp = netdev_priv(dev); struct pcmcia_device *link = lp->p_dev; pr_debug("fjn_open('%s').\n", dev->name); if (!pcmcia_dev_present(link)) return -ENODEV; link->open++; fjn_reset(dev); lp->tx_started = 0; lp->tx_queue = 0; lp->tx_queue_len = 0; lp->open_time = jiffies; netif_start_queue(dev); return 0; } /* fjn_open */ /*====================================================================*/ static int fjn_close(struct net_device *dev) { struct local_info_t *lp = netdev_priv(dev); struct pcmcia_device *link = lp->p_dev; unsigned int ioaddr = dev->base_addr; pr_debug("fjn_close('%s').\n", dev->name); lp->open_time = 0; netif_stop_queue(dev); /* Set configuration register 0 to disable Tx and Rx. */ if( sram_config == 0 ) outb(CONFIG0_RST ,ioaddr + CONFIG_0); else outb(CONFIG0_RST_1 ,ioaddr + CONFIG_0); /* Update the statistics -- ToDo. */ /* Power-down the chip. Green, green, green! */ outb(CHIP_OFF ,ioaddr + CONFIG_1); /* Set the ethernet adaptor disable IRQ */ if (lp->cardtype == MBH10302) outb(INTR_OFF, ioaddr + LAN_CTRL); link->open--; return 0; } /* fjn_close */ /*====================================================================*/ /* Set the multicast/promiscuous mode for this adaptor. */ static void set_rx_mode(struct net_device *dev) { unsigned int ioaddr = dev->base_addr; u_char mc_filter[8]; /* Multicast hash filter */ u_long flags; int i; int saved_bank; int saved_config_0 = inb(ioaddr + CONFIG_0); local_irq_save(flags); /* Disable Tx and Rx */ if (sram_config == 0) outb(CONFIG0_RST, ioaddr + CONFIG_0); else outb(CONFIG0_RST_1, ioaddr + CONFIG_0); if (dev->flags & IFF_PROMISC) { memset(mc_filter, 0xff, sizeof(mc_filter)); outb(3, ioaddr + RX_MODE); /* Enable promiscuous mode */ } else if (netdev_mc_count(dev) > MC_FILTERBREAK || (dev->flags & IFF_ALLMULTI)) { /* Too many to filter perfectly -- accept all multicasts. */ memset(mc_filter, 0xff, sizeof(mc_filter)); outb(2, ioaddr + RX_MODE); /* Use normal mode. */ } else if (netdev_mc_empty(dev)) { memset(mc_filter, 0x00, sizeof(mc_filter)); outb(1, ioaddr + RX_MODE); /* Ignore almost all multicasts. */ } else { struct netdev_hw_addr *ha; memset(mc_filter, 0, sizeof(mc_filter)); netdev_for_each_mc_addr(ha, dev) { unsigned int bit = ether_crc_le(ETH_ALEN, ha->addr) >> 26; mc_filter[bit >> 3] |= (1 << (bit & 7)); } outb(2, ioaddr + RX_MODE); /* Use normal mode. */ } /* Switch to bank 1 and set the multicast table. */ saved_bank = inb(ioaddr + CONFIG_1); outb(0xe4, ioaddr + CONFIG_1); for (i = 0; i < 8; i++) outb(mc_filter[i], ioaddr + MAR_ADR + i); outb(saved_bank, ioaddr + CONFIG_1); outb(saved_config_0, ioaddr + CONFIG_0); local_irq_restore(flags); }
BobZmotion/android_kernel_sony_msm8974
drivers/net/ethernet/fujitsu/fmvj18x_cs.c
C
gpl-2.0
34,182
/* * linux/arch/m68k/kernel/ints.c -- Linux/m68k general interrupt handling code * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details. */ #include <linux/module.h> #include <linux/types.h> #include <linux/sched.h> #include <linux/interrupt.h> #include <linux/kernel_stat.h> #include <linux/errno.h> #include <linux/init.h> #include <asm/setup.h> #include <asm/irq.h> #include <asm/traps.h> #include <asm/page.h> #include <asm/machdep.h> #include <asm/cacheflush.h> #include <asm/irq_regs.h> #ifdef CONFIG_Q40 #include <asm/q40ints.h> #endif extern u32 auto_irqhandler_fixup[]; extern u16 user_irqvec_fixup[]; static int m68k_first_user_vec; static struct irq_chip auto_irq_chip = { .name = "auto", .irq_startup = m68k_irq_startup, .irq_shutdown = m68k_irq_shutdown, }; static struct irq_chip user_irq_chip = { .name = "user", .irq_startup = m68k_irq_startup, .irq_shutdown = m68k_irq_shutdown, }; /* * void init_IRQ(void) * * Parameters: None * * Returns: Nothing * * This function should be called during kernel startup to initialize * the IRQ handling routines. */ void __init init_IRQ(void) { int i; /* assembly irq entry code relies on this... */ if (HARDIRQ_MASK != 0x00ff0000) { extern void hardirq_mask_is_broken(void); hardirq_mask_is_broken(); } for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++) irq_set_chip_and_handler(i, &auto_irq_chip, handle_simple_irq); mach_init_IRQ(); } /** * m68k_setup_auto_interrupt * @handler: called from auto vector interrupts * * setup the handler to be called from auto vector interrupts instead of the * standard do_IRQ(), it will be called with irq numbers in the range * from IRQ_AUTO_1 - IRQ_AUTO_7. */ void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *)) { if (handler) *auto_irqhandler_fixup = (u32)handler; flush_icache(); } /** * m68k_setup_user_interrupt * @vec: first user vector interrupt to handle * @cnt: number of active user vector interrupts * * setup user vector interrupts, this includes activating the specified range * of interrupts, only then these interrupts can be requested (note: this is * different from auto vector interrupts). */ void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt) { int i; BUG_ON(IRQ_USER + cnt > NR_IRQS); m68k_first_user_vec = vec; for (i = 0; i < cnt; i++) irq_set_chip(IRQ_USER + i, &user_irq_chip); *user_irqvec_fixup = vec - IRQ_USER; flush_icache(); } /** * m68k_setup_irq_controller * @chip: irq chip which controls specified irq * @handle: flow handler which handles specified irq * @irq: first irq to be managed by the controller * @cnt: number of irqs to be managed by the controller * * Change the controller for the specified range of irq, which will be used to * manage these irq. auto/user irq already have a default controller, which can * be changed as well, but the controller probably should use m68k_irq_startup/ * m68k_irq_shutdown. */ void m68k_setup_irq_controller(struct irq_chip *chip, irq_flow_handler_t handle, unsigned int irq, unsigned int cnt) { int i; for (i = 0; i < cnt; i++) { irq_set_chip(irq + i, chip); if (handle) irq_set_handler(irq + i, handle); } } unsigned int m68k_irq_startup_irq(unsigned int irq) { if (irq <= IRQ_AUTO_7) vectors[VEC_SPUR + irq] = auto_inthandler; else vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler; return 0; } unsigned int m68k_irq_startup(struct irq_data *data) { return m68k_irq_startup_irq(data->irq); } void m68k_irq_shutdown(struct irq_data *data) { unsigned int irq = data->irq; if (irq <= IRQ_AUTO_7) vectors[VEC_SPUR + irq] = bad_inthandler; else vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler; } unsigned int irq_canonicalize(unsigned int irq) { #ifdef CONFIG_Q40 if (MACH_IS_Q40 && irq == 11) irq = 10; #endif return irq; } EXPORT_SYMBOL(irq_canonicalize); asmlinkage void handle_badint(struct pt_regs *regs) { atomic_inc(&irq_err_count); pr_warn("unexpected interrupt from %u\n", regs->vector); }
shoey63/kernel-copyleft
arch/m68k/kernel/ints.c
C
gpl-2.0
4,209
/* * arch/powerpc/math-emu/math_efp.c * * Copyright (C) 2006-2008, 2010 Freescale Semiconductor, Inc. * * Author: Ebony Zhu, <ebony.zhu@freescale.com> * Yu Liu, <yu.liu@freescale.com> * * Derived from arch/alpha/math-emu/math.c * arch/powerpc/math-emu/math.c * * Description: * This file is the exception handler to make E500 SPE instructions * fully comply with IEEE-754 floating point standard. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/types.h> #include <asm/uaccess.h> #include <asm/reg.h> #define FP_EX_BOOKE_E500_SPE #include <asm/sfp-machine.h> #include <math-emu/soft-fp.h> #include <math-emu/single.h> #include <math-emu/double.h> #define EFAPU 0x4 #define VCT 0x4 #define SPFP 0x6 #define DPFP 0x7 #define EFSADD 0x2c0 #define EFSSUB 0x2c1 #define EFSABS 0x2c4 #define EFSNABS 0x2c5 #define EFSNEG 0x2c6 #define EFSMUL 0x2c8 #define EFSDIV 0x2c9 #define EFSCMPGT 0x2cc #define EFSCMPLT 0x2cd #define EFSCMPEQ 0x2ce #define EFSCFD 0x2cf #define EFSCFSI 0x2d1 #define EFSCTUI 0x2d4 #define EFSCTSI 0x2d5 #define EFSCTUF 0x2d6 #define EFSCTSF 0x2d7 #define EFSCTUIZ 0x2d8 #define EFSCTSIZ 0x2da #define EVFSADD 0x280 #define EVFSSUB 0x281 #define EVFSABS 0x284 #define EVFSNABS 0x285 #define EVFSNEG 0x286 #define EVFSMUL 0x288 #define EVFSDIV 0x289 #define EVFSCMPGT 0x28c #define EVFSCMPLT 0x28d #define EVFSCMPEQ 0x28e #define EVFSCTUI 0x294 #define EVFSCTSI 0x295 #define EVFSCTUF 0x296 #define EVFSCTSF 0x297 #define EVFSCTUIZ 0x298 #define EVFSCTSIZ 0x29a #define EFDADD 0x2e0 #define EFDSUB 0x2e1 #define EFDABS 0x2e4 #define EFDNABS 0x2e5 #define EFDNEG 0x2e6 #define EFDMUL 0x2e8 #define EFDDIV 0x2e9 #define EFDCTUIDZ 0x2ea #define EFDCTSIDZ 0x2eb #define EFDCMPGT 0x2ec #define EFDCMPLT 0x2ed #define EFDCMPEQ 0x2ee #define EFDCFS 0x2ef #define EFDCTUI 0x2f4 #define EFDCTSI 0x2f5 #define EFDCTUF 0x2f6 #define EFDCTSF 0x2f7 #define EFDCTUIZ 0x2f8 #define EFDCTSIZ 0x2fa #define AB 2 #define XA 3 #define XB 4 #define XCR 5 #define NOTYPE 0 #define SIGN_BIT_S (1UL << 31) #define SIGN_BIT_D (1ULL << 63) #define FP_EX_MASK (FP_EX_INEXACT | FP_EX_INVALID | FP_EX_DIVZERO | \ FP_EX_UNDERFLOW | FP_EX_OVERFLOW) static int have_e500_cpu_a005_erratum; union dw_union { u64 dp[1]; u32 wp[2]; }; static unsigned long insn_type(unsigned long speinsn) { unsigned long ret = NOTYPE; switch (speinsn & 0x7ff) { case EFSABS: ret = XA; break; case EFSADD: ret = AB; break; case EFSCFD: ret = XB; break; case EFSCMPEQ: ret = XCR; break; case EFSCMPGT: ret = XCR; break; case EFSCMPLT: ret = XCR; break; case EFSCTSF: ret = XB; break; case EFSCTSI: ret = XB; break; case EFSCTSIZ: ret = XB; break; case EFSCTUF: ret = XB; break; case EFSCTUI: ret = XB; break; case EFSCTUIZ: ret = XB; break; case EFSDIV: ret = AB; break; case EFSMUL: ret = AB; break; case EFSNABS: ret = XA; break; case EFSNEG: ret = XA; break; case EFSSUB: ret = AB; break; case EFSCFSI: ret = XB; break; case EVFSABS: ret = XA; break; case EVFSADD: ret = AB; break; case EVFSCMPEQ: ret = XCR; break; case EVFSCMPGT: ret = XCR; break; case EVFSCMPLT: ret = XCR; break; case EVFSCTSF: ret = XB; break; case EVFSCTSI: ret = XB; break; case EVFSCTSIZ: ret = XB; break; case EVFSCTUF: ret = XB; break; case EVFSCTUI: ret = XB; break; case EVFSCTUIZ: ret = XB; break; case EVFSDIV: ret = AB; break; case EVFSMUL: ret = AB; break; case EVFSNABS: ret = XA; break; case EVFSNEG: ret = XA; break; case EVFSSUB: ret = AB; break; case EFDABS: ret = XA; break; case EFDADD: ret = AB; break; case EFDCFS: ret = XB; break; case EFDCMPEQ: ret = XCR; break; case EFDCMPGT: ret = XCR; break; case EFDCMPLT: ret = XCR; break; case EFDCTSF: ret = XB; break; case EFDCTSI: ret = XB; break; case EFDCTSIDZ: ret = XB; break; case EFDCTSIZ: ret = XB; break; case EFDCTUF: ret = XB; break; case EFDCTUI: ret = XB; break; case EFDCTUIDZ: ret = XB; break; case EFDCTUIZ: ret = XB; break; case EFDDIV: ret = AB; break; case EFDMUL: ret = AB; break; case EFDNABS: ret = XA; break; case EFDNEG: ret = XA; break; case EFDSUB: ret = AB; break; } return ret; } int do_spe_mathemu(struct pt_regs *regs) { FP_DECL_EX; int IR, cmp; unsigned long type, func, fc, fa, fb, src, speinsn; union dw_union vc, va, vb; if (get_user(speinsn, (unsigned int __user *) regs->nip)) return -EFAULT; if ((speinsn >> 26) != EFAPU) return -EINVAL; /* not an spe instruction */ type = insn_type(speinsn); if (type == NOTYPE) goto illegal; func = speinsn & 0x7ff; fc = (speinsn >> 21) & 0x1f; fa = (speinsn >> 16) & 0x1f; fb = (speinsn >> 11) & 0x1f; src = (speinsn >> 5) & 0x7; vc.wp[0] = current->thread.evr[fc]; vc.wp[1] = regs->gpr[fc]; va.wp[0] = current->thread.evr[fa]; va.wp[1] = regs->gpr[fa]; vb.wp[0] = current->thread.evr[fb]; vb.wp[1] = regs->gpr[fb]; __FPU_FPSCR = mfspr(SPRN_SPEFSCR); pr_debug("speinsn:%08lx spefscr:%08lx\n", speinsn, __FPU_FPSCR); pr_debug("vc: %08x %08x\n", vc.wp[0], vc.wp[1]); pr_debug("va: %08x %08x\n", va.wp[0], va.wp[1]); pr_debug("vb: %08x %08x\n", vb.wp[0], vb.wp[1]); switch (src) { case SPFP: { FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR); switch (type) { case AB: case XCR: FP_UNPACK_SP(SA, va.wp + 1); case XB: FP_UNPACK_SP(SB, vb.wp + 1); break; case XA: FP_UNPACK_SP(SA, va.wp + 1); break; } pr_debug("SA: %ld %08lx %ld (%ld)\n", SA_s, SA_f, SA_e, SA_c); pr_debug("SB: %ld %08lx %ld (%ld)\n", SB_s, SB_f, SB_e, SB_c); switch (func) { case EFSABS: vc.wp[1] = va.wp[1] & ~SIGN_BIT_S; goto update_regs; case EFSNABS: vc.wp[1] = va.wp[1] | SIGN_BIT_S; goto update_regs; case EFSNEG: vc.wp[1] = va.wp[1] ^ SIGN_BIT_S; goto update_regs; case EFSADD: FP_ADD_S(SR, SA, SB); goto pack_s; case EFSSUB: FP_SUB_S(SR, SA, SB); goto pack_s; case EFSMUL: FP_MUL_S(SR, SA, SB); goto pack_s; case EFSDIV: FP_DIV_S(SR, SA, SB); goto pack_s; case EFSCMPEQ: cmp = 0; goto cmp_s; case EFSCMPGT: cmp = 1; goto cmp_s; case EFSCMPLT: cmp = -1; goto cmp_s; case EFSCTSF: case EFSCTUF: if (!((vb.wp[1] >> 23) == 0xff && ((vb.wp[1] & 0x7fffff) > 0))) { /* NaN */ if (((vb.wp[1] >> 23) & 0xff) == 0) { /* denorm */ vc.wp[1] = 0x0; } else if ((vb.wp[1] >> 31) == 0) { /* positive normal */ vc.wp[1] = (func == EFSCTSF) ? 0x7fffffff : 0xffffffff; } else { /* negative normal */ vc.wp[1] = (func == EFSCTSF) ? 0x80000000 : 0x0; } } else { /* rB is NaN */ vc.wp[1] = 0x0; } goto update_regs; case EFSCFD: { FP_DECL_D(DB); FP_CLEAR_EXCEPTIONS; FP_UNPACK_DP(DB, vb.dp); pr_debug("DB: %ld %08lx %08lx %ld (%ld)\n", DB_s, DB_f1, DB_f0, DB_e, DB_c); FP_CONV(S, D, 1, 2, SR, DB); goto pack_s; } case EFSCTSI: case EFSCTSIZ: case EFSCTUI: case EFSCTUIZ: if (func & 0x4) { _FP_ROUND(1, SB); } else { _FP_ROUND_ZERO(1, SB); } FP_TO_INT_S(vc.wp[1], SB, 32, (((func & 0x3) != 0) || SB_s)); goto update_regs; default: goto illegal; } break; pack_s: pr_debug("SR: %ld %08lx %ld (%ld)\n", SR_s, SR_f, SR_e, SR_c); FP_PACK_SP(vc.wp + 1, SR); goto update_regs; cmp_s: FP_CMP_S(IR, SA, SB, 3); if (IR == 3 && (FP_ISSIGNAN_S(SA) || FP_ISSIGNAN_S(SB))) FP_SET_EXCEPTION(FP_EX_INVALID); if (IR == cmp) { IR = 0x4; } else { IR = 0; } goto update_ccr; } case DPFP: { FP_DECL_D(DA); FP_DECL_D(DB); FP_DECL_D(DR); switch (type) { case AB: case XCR: FP_UNPACK_DP(DA, va.dp); case XB: FP_UNPACK_DP(DB, vb.dp); break; case XA: FP_UNPACK_DP(DA, va.dp); break; } pr_debug("DA: %ld %08lx %08lx %ld (%ld)\n", DA_s, DA_f1, DA_f0, DA_e, DA_c); pr_debug("DB: %ld %08lx %08lx %ld (%ld)\n", DB_s, DB_f1, DB_f0, DB_e, DB_c); switch (func) { case EFDABS: vc.dp[0] = va.dp[0] & ~SIGN_BIT_D; goto update_regs; case EFDNABS: vc.dp[0] = va.dp[0] | SIGN_BIT_D; goto update_regs; case EFDNEG: vc.dp[0] = va.dp[0] ^ SIGN_BIT_D; goto update_regs; case EFDADD: FP_ADD_D(DR, DA, DB); goto pack_d; case EFDSUB: FP_SUB_D(DR, DA, DB); goto pack_d; case EFDMUL: FP_MUL_D(DR, DA, DB); goto pack_d; case EFDDIV: FP_DIV_D(DR, DA, DB); goto pack_d; case EFDCMPEQ: cmp = 0; goto cmp_d; case EFDCMPGT: cmp = 1; goto cmp_d; case EFDCMPLT: cmp = -1; goto cmp_d; case EFDCTSF: case EFDCTUF: if (!((vb.wp[0] >> 20) == 0x7ff && ((vb.wp[0] & 0xfffff) > 0 || (vb.wp[1] > 0)))) { /* not a NaN */ if (((vb.wp[0] >> 20) & 0x7ff) == 0) { /* denorm */ vc.wp[1] = 0x0; } else if ((vb.wp[0] >> 31) == 0) { /* positive normal */ vc.wp[1] = (func == EFDCTSF) ? 0x7fffffff : 0xffffffff; } else { /* negative normal */ vc.wp[1] = (func == EFDCTSF) ? 0x80000000 : 0x0; } } else { /* NaN */ vc.wp[1] = 0x0; } goto update_regs; case EFDCFS: { FP_DECL_S(SB); FP_CLEAR_EXCEPTIONS; FP_UNPACK_SP(SB, vb.wp + 1); pr_debug("SB: %ld %08lx %ld (%ld)\n", SB_s, SB_f, SB_e, SB_c); FP_CONV(D, S, 2, 1, DR, SB); goto pack_d; } case EFDCTUIDZ: case EFDCTSIDZ: _FP_ROUND_ZERO(2, DB); FP_TO_INT_D(vc.dp[0], DB, 64, ((func & 0x1) == 0)); goto update_regs; case EFDCTUI: case EFDCTSI: case EFDCTUIZ: case EFDCTSIZ: if (func & 0x4) { _FP_ROUND(2, DB); } else { _FP_ROUND_ZERO(2, DB); } FP_TO_INT_D(vc.wp[1], DB, 32, (((func & 0x3) != 0) || DB_s)); goto update_regs; default: goto illegal; } break; pack_d: pr_debug("DR: %ld %08lx %08lx %ld (%ld)\n", DR_s, DR_f1, DR_f0, DR_e, DR_c); FP_PACK_DP(vc.dp, DR); goto update_regs; cmp_d: FP_CMP_D(IR, DA, DB, 3); if (IR == 3 && (FP_ISSIGNAN_D(DA) || FP_ISSIGNAN_D(DB))) FP_SET_EXCEPTION(FP_EX_INVALID); if (IR == cmp) { IR = 0x4; } else { IR = 0; } goto update_ccr; } case VCT: { FP_DECL_S(SA0); FP_DECL_S(SB0); FP_DECL_S(SR0); FP_DECL_S(SA1); FP_DECL_S(SB1); FP_DECL_S(SR1); int IR0, IR1; switch (type) { case AB: case XCR: FP_UNPACK_SP(SA0, va.wp); FP_UNPACK_SP(SA1, va.wp + 1); case XB: FP_UNPACK_SP(SB0, vb.wp); FP_UNPACK_SP(SB1, vb.wp + 1); break; case XA: FP_UNPACK_SP(SA0, va.wp); FP_UNPACK_SP(SA1, va.wp + 1); break; } pr_debug("SA0: %ld %08lx %ld (%ld)\n", SA0_s, SA0_f, SA0_e, SA0_c); pr_debug("SA1: %ld %08lx %ld (%ld)\n", SA1_s, SA1_f, SA1_e, SA1_c); pr_debug("SB0: %ld %08lx %ld (%ld)\n", SB0_s, SB0_f, SB0_e, SB0_c); pr_debug("SB1: %ld %08lx %ld (%ld)\n", SB1_s, SB1_f, SB1_e, SB1_c); switch (func) { case EVFSABS: vc.wp[0] = va.wp[0] & ~SIGN_BIT_S; vc.wp[1] = va.wp[1] & ~SIGN_BIT_S; goto update_regs; case EVFSNABS: vc.wp[0] = va.wp[0] | SIGN_BIT_S; vc.wp[1] = va.wp[1] | SIGN_BIT_S; goto update_regs; case EVFSNEG: vc.wp[0] = va.wp[0] ^ SIGN_BIT_S; vc.wp[1] = va.wp[1] ^ SIGN_BIT_S; goto update_regs; case EVFSADD: FP_ADD_S(SR0, SA0, SB0); FP_ADD_S(SR1, SA1, SB1); goto pack_vs; case EVFSSUB: FP_SUB_S(SR0, SA0, SB0); FP_SUB_S(SR1, SA1, SB1); goto pack_vs; case EVFSMUL: FP_MUL_S(SR0, SA0, SB0); FP_MUL_S(SR1, SA1, SB1); goto pack_vs; case EVFSDIV: FP_DIV_S(SR0, SA0, SB0); FP_DIV_S(SR1, SA1, SB1); goto pack_vs; case EVFSCMPEQ: cmp = 0; goto cmp_vs; case EVFSCMPGT: cmp = 1; goto cmp_vs; case EVFSCMPLT: cmp = -1; goto cmp_vs; case EVFSCTSF: __asm__ __volatile__ ("mtspr 512, %4\n" "efsctsf %0, %2\n" "efsctsf %1, %3\n" : "=r" (vc.wp[0]), "=r" (vc.wp[1]) : "r" (vb.wp[0]), "r" (vb.wp[1]), "r" (0)); goto update_regs; case EVFSCTUF: __asm__ __volatile__ ("mtspr 512, %4\n" "efsctuf %0, %2\n" "efsctuf %1, %3\n" : "=r" (vc.wp[0]), "=r" (vc.wp[1]) : "r" (vb.wp[0]), "r" (vb.wp[1]), "r" (0)); goto update_regs; case EVFSCTUI: case EVFSCTSI: case EVFSCTUIZ: case EVFSCTSIZ: if (func & 0x4) { _FP_ROUND(1, SB0); _FP_ROUND(1, SB1); } else { _FP_ROUND_ZERO(1, SB0); _FP_ROUND_ZERO(1, SB1); } FP_TO_INT_S(vc.wp[0], SB0, 32, (((func & 0x3) != 0) || SB0_s)); FP_TO_INT_S(vc.wp[1], SB1, 32, (((func & 0x3) != 0) || SB1_s)); goto update_regs; default: goto illegal; } break; pack_vs: pr_debug("SR0: %ld %08lx %ld (%ld)\n", SR0_s, SR0_f, SR0_e, SR0_c); pr_debug("SR1: %ld %08lx %ld (%ld)\n", SR1_s, SR1_f, SR1_e, SR1_c); FP_PACK_SP(vc.wp, SR0); FP_PACK_SP(vc.wp + 1, SR1); goto update_regs; cmp_vs: { int ch, cl; FP_CMP_S(IR0, SA0, SB0, 3); FP_CMP_S(IR1, SA1, SB1, 3); if (IR0 == 3 && (FP_ISSIGNAN_S(SA0) || FP_ISSIGNAN_S(SB0))) FP_SET_EXCEPTION(FP_EX_INVALID); if (IR1 == 3 && (FP_ISSIGNAN_S(SA1) || FP_ISSIGNAN_S(SB1))) FP_SET_EXCEPTION(FP_EX_INVALID); ch = (IR0 == cmp) ? 1 : 0; cl = (IR1 == cmp) ? 1 : 0; IR = (ch << 3) | (cl << 2) | ((ch | cl) << 1) | ((ch & cl) << 0); goto update_ccr; } } default: return -EINVAL; } update_ccr: regs->ccr &= ~(15 << ((7 - ((speinsn >> 23) & 0x7)) << 2)); regs->ccr |= (IR << ((7 - ((speinsn >> 23) & 0x7)) << 2)); update_regs: __FPU_FPSCR &= ~FP_EX_MASK; __FPU_FPSCR |= (FP_CUR_EXCEPTIONS & FP_EX_MASK); mtspr(SPRN_SPEFSCR, __FPU_FPSCR); current->thread.evr[fc] = vc.wp[0]; regs->gpr[fc] = vc.wp[1]; pr_debug("ccr = %08lx\n", regs->ccr); pr_debug("cur exceptions = %08x spefscr = %08lx\n", FP_CUR_EXCEPTIONS, __FPU_FPSCR); pr_debug("vc: %08x %08x\n", vc.wp[0], vc.wp[1]); pr_debug("va: %08x %08x\n", va.wp[0], va.wp[1]); pr_debug("vb: %08x %08x\n", vb.wp[0], vb.wp[1]); return 0; illegal: if (have_e500_cpu_a005_erratum) { /* according to e500 cpu a005 erratum, reissue efp inst */ regs->nip -= 4; pr_debug("re-issue efp inst: %08lx\n", speinsn); return 0; } printk(KERN_ERR "\nOoops! IEEE-754 compliance handler encountered un-supported instruction.\ninst code: %08lx\n", speinsn); return -ENOSYS; } int speround_handler(struct pt_regs *regs) { union dw_union fgpr; int s_lo, s_hi; unsigned long speinsn, type, fc; if (get_user(speinsn, (unsigned int __user *) regs->nip)) return -EFAULT; if ((speinsn >> 26) != 4) return -EINVAL; /* not an spe instruction */ type = insn_type(speinsn & 0x7ff); if (type == XCR) return -ENOSYS; __FPU_FPSCR = mfspr(SPRN_SPEFSCR); pr_debug("speinsn:%08lx spefscr:%08lx\n", speinsn, __FPU_FPSCR); /* No need to round if the result is exact */ if (!(__FPU_FPSCR & FP_EX_INEXACT)) return 0; fc = (speinsn >> 21) & 0x1f; s_lo = regs->gpr[fc] & SIGN_BIT_S; s_hi = current->thread.evr[fc] & SIGN_BIT_S; fgpr.wp[0] = current->thread.evr[fc]; fgpr.wp[1] = regs->gpr[fc]; pr_debug("round fgpr: %08x %08x\n", fgpr.wp[0], fgpr.wp[1]); switch ((speinsn >> 5) & 0x7) { /* Since SPE instructions on E500 core can handle round to nearest * and round toward zero with IEEE-754 complied, we just need * to handle round toward +Inf and round toward -Inf by software. */ case SPFP: if ((FP_ROUNDMODE) == FP_RND_PINF) { if (!s_lo) fgpr.wp[1]++; /* Z > 0, choose Z1 */ } else { /* round to -Inf */ if (s_lo) fgpr.wp[1]++; /* Z < 0, choose Z2 */ } break; case DPFP: if (FP_ROUNDMODE == FP_RND_PINF) { if (!s_hi) fgpr.dp[0]++; /* Z > 0, choose Z1 */ } else { /* round to -Inf */ if (s_hi) fgpr.dp[0]++; /* Z < 0, choose Z2 */ } break; case VCT: if (FP_ROUNDMODE == FP_RND_PINF) { if (!s_lo) fgpr.wp[1]++; /* Z_low > 0, choose Z1 */ if (!s_hi) fgpr.wp[0]++; /* Z_high word > 0, choose Z1 */ } else { /* round to -Inf */ if (s_lo) fgpr.wp[1]++; /* Z_low < 0, choose Z2 */ if (s_hi) fgpr.wp[0]++; /* Z_high < 0, choose Z2 */ } break; default: return -EINVAL; } current->thread.evr[fc] = fgpr.wp[0]; regs->gpr[fc] = fgpr.wp[1]; pr_debug(" to fgpr: %08x %08x\n", fgpr.wp[0], fgpr.wp[1]); return 0; } int __init spe_mathemu_init(void) { u32 pvr, maj, min; pvr = mfspr(SPRN_PVR); if ((PVR_VER(pvr) == PVR_VER_E500V1) || (PVR_VER(pvr) == PVR_VER_E500V2)) { maj = PVR_MAJ(pvr); min = PVR_MIN(pvr); /* * E500 revision below 1.1, 2.3, 3.1, 4.1, 5.1 * need cpu a005 errata workaround */ switch (maj) { case 1: if (min < 1) have_e500_cpu_a005_erratum = 1; break; case 2: if (min < 3) have_e500_cpu_a005_erratum = 1; break; case 3: case 4: case 5: if (min < 1) have_e500_cpu_a005_erratum = 1; break; default: break; } } return 0; } module_init(spe_mathemu_init);
dtsinc/DTS-Sound-Integration_CAF-Android-kernel
arch/powerpc/math-emu/math_efp.c
C
gpl-2.0
16,878
/* * arch/powerpc/math-emu/math_efp.c * * Copyright (C) 2006-2008, 2010 Freescale Semiconductor, Inc. * * Author: Ebony Zhu, <ebony.zhu@freescale.com> * Yu Liu, <yu.liu@freescale.com> * * Derived from arch/alpha/math-emu/math.c * arch/powerpc/math-emu/math.c * * Description: * This file is the exception handler to make E500 SPE instructions * fully comply with IEEE-754 floating point standard. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/types.h> #include <asm/uaccess.h> #include <asm/reg.h> #define FP_EX_BOOKE_E500_SPE #include <asm/sfp-machine.h> #include <math-emu/soft-fp.h> #include <math-emu/single.h> #include <math-emu/double.h> #define EFAPU 0x4 #define VCT 0x4 #define SPFP 0x6 #define DPFP 0x7 #define EFSADD 0x2c0 #define EFSSUB 0x2c1 #define EFSABS 0x2c4 #define EFSNABS 0x2c5 #define EFSNEG 0x2c6 #define EFSMUL 0x2c8 #define EFSDIV 0x2c9 #define EFSCMPGT 0x2cc #define EFSCMPLT 0x2cd #define EFSCMPEQ 0x2ce #define EFSCFD 0x2cf #define EFSCFSI 0x2d1 #define EFSCTUI 0x2d4 #define EFSCTSI 0x2d5 #define EFSCTUF 0x2d6 #define EFSCTSF 0x2d7 #define EFSCTUIZ 0x2d8 #define EFSCTSIZ 0x2da #define EVFSADD 0x280 #define EVFSSUB 0x281 #define EVFSABS 0x284 #define EVFSNABS 0x285 #define EVFSNEG 0x286 #define EVFSMUL 0x288 #define EVFSDIV 0x289 #define EVFSCMPGT 0x28c #define EVFSCMPLT 0x28d #define EVFSCMPEQ 0x28e #define EVFSCTUI 0x294 #define EVFSCTSI 0x295 #define EVFSCTUF 0x296 #define EVFSCTSF 0x297 #define EVFSCTUIZ 0x298 #define EVFSCTSIZ 0x29a #define EFDADD 0x2e0 #define EFDSUB 0x2e1 #define EFDABS 0x2e4 #define EFDNABS 0x2e5 #define EFDNEG 0x2e6 #define EFDMUL 0x2e8 #define EFDDIV 0x2e9 #define EFDCTUIDZ 0x2ea #define EFDCTSIDZ 0x2eb #define EFDCMPGT 0x2ec #define EFDCMPLT 0x2ed #define EFDCMPEQ 0x2ee #define EFDCFS 0x2ef #define EFDCTUI 0x2f4 #define EFDCTSI 0x2f5 #define EFDCTUF 0x2f6 #define EFDCTSF 0x2f7 #define EFDCTUIZ 0x2f8 #define EFDCTSIZ 0x2fa #define AB 2 #define XA 3 #define XB 4 #define XCR 5 #define NOTYPE 0 #define SIGN_BIT_S (1UL << 31) #define SIGN_BIT_D (1ULL << 63) #define FP_EX_MASK (FP_EX_INEXACT | FP_EX_INVALID | FP_EX_DIVZERO | \ FP_EX_UNDERFLOW | FP_EX_OVERFLOW) static int have_e500_cpu_a005_erratum; union dw_union { u64 dp[1]; u32 wp[2]; }; static unsigned long insn_type(unsigned long speinsn) { unsigned long ret = NOTYPE; switch (speinsn & 0x7ff) { case EFSABS: ret = XA; break; case EFSADD: ret = AB; break; case EFSCFD: ret = XB; break; case EFSCMPEQ: ret = XCR; break; case EFSCMPGT: ret = XCR; break; case EFSCMPLT: ret = XCR; break; case EFSCTSF: ret = XB; break; case EFSCTSI: ret = XB; break; case EFSCTSIZ: ret = XB; break; case EFSCTUF: ret = XB; break; case EFSCTUI: ret = XB; break; case EFSCTUIZ: ret = XB; break; case EFSDIV: ret = AB; break; case EFSMUL: ret = AB; break; case EFSNABS: ret = XA; break; case EFSNEG: ret = XA; break; case EFSSUB: ret = AB; break; case EFSCFSI: ret = XB; break; case EVFSABS: ret = XA; break; case EVFSADD: ret = AB; break; case EVFSCMPEQ: ret = XCR; break; case EVFSCMPGT: ret = XCR; break; case EVFSCMPLT: ret = XCR; break; case EVFSCTSF: ret = XB; break; case EVFSCTSI: ret = XB; break; case EVFSCTSIZ: ret = XB; break; case EVFSCTUF: ret = XB; break; case EVFSCTUI: ret = XB; break; case EVFSCTUIZ: ret = XB; break; case EVFSDIV: ret = AB; break; case EVFSMUL: ret = AB; break; case EVFSNABS: ret = XA; break; case EVFSNEG: ret = XA; break; case EVFSSUB: ret = AB; break; case EFDABS: ret = XA; break; case EFDADD: ret = AB; break; case EFDCFS: ret = XB; break; case EFDCMPEQ: ret = XCR; break; case EFDCMPGT: ret = XCR; break; case EFDCMPLT: ret = XCR; break; case EFDCTSF: ret = XB; break; case EFDCTSI: ret = XB; break; case EFDCTSIDZ: ret = XB; break; case EFDCTSIZ: ret = XB; break; case EFDCTUF: ret = XB; break; case EFDCTUI: ret = XB; break; case EFDCTUIDZ: ret = XB; break; case EFDCTUIZ: ret = XB; break; case EFDDIV: ret = AB; break; case EFDMUL: ret = AB; break; case EFDNABS: ret = XA; break; case EFDNEG: ret = XA; break; case EFDSUB: ret = AB; break; } return ret; } int do_spe_mathemu(struct pt_regs *regs) { FP_DECL_EX; int IR, cmp; unsigned long type, func, fc, fa, fb, src, speinsn; union dw_union vc, va, vb; if (get_user(speinsn, (unsigned int __user *) regs->nip)) return -EFAULT; if ((speinsn >> 26) != EFAPU) return -EINVAL; /* not an spe instruction */ type = insn_type(speinsn); if (type == NOTYPE) goto illegal; func = speinsn & 0x7ff; fc = (speinsn >> 21) & 0x1f; fa = (speinsn >> 16) & 0x1f; fb = (speinsn >> 11) & 0x1f; src = (speinsn >> 5) & 0x7; vc.wp[0] = current->thread.evr[fc]; vc.wp[1] = regs->gpr[fc]; va.wp[0] = current->thread.evr[fa]; va.wp[1] = regs->gpr[fa]; vb.wp[0] = current->thread.evr[fb]; vb.wp[1] = regs->gpr[fb]; __FPU_FPSCR = mfspr(SPRN_SPEFSCR); pr_debug("speinsn:%08lx spefscr:%08lx\n", speinsn, __FPU_FPSCR); pr_debug("vc: %08x %08x\n", vc.wp[0], vc.wp[1]); pr_debug("va: %08x %08x\n", va.wp[0], va.wp[1]); pr_debug("vb: %08x %08x\n", vb.wp[0], vb.wp[1]); switch (src) { case SPFP: { FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR); switch (type) { case AB: case XCR: FP_UNPACK_SP(SA, va.wp + 1); case XB: FP_UNPACK_SP(SB, vb.wp + 1); break; case XA: FP_UNPACK_SP(SA, va.wp + 1); break; } pr_debug("SA: %ld %08lx %ld (%ld)\n", SA_s, SA_f, SA_e, SA_c); pr_debug("SB: %ld %08lx %ld (%ld)\n", SB_s, SB_f, SB_e, SB_c); switch (func) { case EFSABS: vc.wp[1] = va.wp[1] & ~SIGN_BIT_S; goto update_regs; case EFSNABS: vc.wp[1] = va.wp[1] | SIGN_BIT_S; goto update_regs; case EFSNEG: vc.wp[1] = va.wp[1] ^ SIGN_BIT_S; goto update_regs; case EFSADD: FP_ADD_S(SR, SA, SB); goto pack_s; case EFSSUB: FP_SUB_S(SR, SA, SB); goto pack_s; case EFSMUL: FP_MUL_S(SR, SA, SB); goto pack_s; case EFSDIV: FP_DIV_S(SR, SA, SB); goto pack_s; case EFSCMPEQ: cmp = 0; goto cmp_s; case EFSCMPGT: cmp = 1; goto cmp_s; case EFSCMPLT: cmp = -1; goto cmp_s; case EFSCTSF: case EFSCTUF: if (!((vb.wp[1] >> 23) == 0xff && ((vb.wp[1] & 0x7fffff) > 0))) { /* NaN */ if (((vb.wp[1] >> 23) & 0xff) == 0) { /* denorm */ vc.wp[1] = 0x0; } else if ((vb.wp[1] >> 31) == 0) { /* positive normal */ vc.wp[1] = (func == EFSCTSF) ? 0x7fffffff : 0xffffffff; } else { /* negative normal */ vc.wp[1] = (func == EFSCTSF) ? 0x80000000 : 0x0; } } else { /* rB is NaN */ vc.wp[1] = 0x0; } goto update_regs; case EFSCFD: { FP_DECL_D(DB); FP_CLEAR_EXCEPTIONS; FP_UNPACK_DP(DB, vb.dp); pr_debug("DB: %ld %08lx %08lx %ld (%ld)\n", DB_s, DB_f1, DB_f0, DB_e, DB_c); FP_CONV(S, D, 1, 2, SR, DB); goto pack_s; } case EFSCTSI: case EFSCTSIZ: case EFSCTUI: case EFSCTUIZ: if (func & 0x4) { _FP_ROUND(1, SB); } else { _FP_ROUND_ZERO(1, SB); } FP_TO_INT_S(vc.wp[1], SB, 32, (((func & 0x3) != 0) || SB_s)); goto update_regs; default: goto illegal; } break; pack_s: pr_debug("SR: %ld %08lx %ld (%ld)\n", SR_s, SR_f, SR_e, SR_c); FP_PACK_SP(vc.wp + 1, SR); goto update_regs; cmp_s: FP_CMP_S(IR, SA, SB, 3); if (IR == 3 && (FP_ISSIGNAN_S(SA) || FP_ISSIGNAN_S(SB))) FP_SET_EXCEPTION(FP_EX_INVALID); if (IR == cmp) { IR = 0x4; } else { IR = 0; } goto update_ccr; } case DPFP: { FP_DECL_D(DA); FP_DECL_D(DB); FP_DECL_D(DR); switch (type) { case AB: case XCR: FP_UNPACK_DP(DA, va.dp); case XB: FP_UNPACK_DP(DB, vb.dp); break; case XA: FP_UNPACK_DP(DA, va.dp); break; } pr_debug("DA: %ld %08lx %08lx %ld (%ld)\n", DA_s, DA_f1, DA_f0, DA_e, DA_c); pr_debug("DB: %ld %08lx %08lx %ld (%ld)\n", DB_s, DB_f1, DB_f0, DB_e, DB_c); switch (func) { case EFDABS: vc.dp[0] = va.dp[0] & ~SIGN_BIT_D; goto update_regs; case EFDNABS: vc.dp[0] = va.dp[0] | SIGN_BIT_D; goto update_regs; case EFDNEG: vc.dp[0] = va.dp[0] ^ SIGN_BIT_D; goto update_regs; case EFDADD: FP_ADD_D(DR, DA, DB); goto pack_d; case EFDSUB: FP_SUB_D(DR, DA, DB); goto pack_d; case EFDMUL: FP_MUL_D(DR, DA, DB); goto pack_d; case EFDDIV: FP_DIV_D(DR, DA, DB); goto pack_d; case EFDCMPEQ: cmp = 0; goto cmp_d; case EFDCMPGT: cmp = 1; goto cmp_d; case EFDCMPLT: cmp = -1; goto cmp_d; case EFDCTSF: case EFDCTUF: if (!((vb.wp[0] >> 20) == 0x7ff && ((vb.wp[0] & 0xfffff) > 0 || (vb.wp[1] > 0)))) { /* not a NaN */ if (((vb.wp[0] >> 20) & 0x7ff) == 0) { /* denorm */ vc.wp[1] = 0x0; } else if ((vb.wp[0] >> 31) == 0) { /* positive normal */ vc.wp[1] = (func == EFDCTSF) ? 0x7fffffff : 0xffffffff; } else { /* negative normal */ vc.wp[1] = (func == EFDCTSF) ? 0x80000000 : 0x0; } } else { /* NaN */ vc.wp[1] = 0x0; } goto update_regs; case EFDCFS: { FP_DECL_S(SB); FP_CLEAR_EXCEPTIONS; FP_UNPACK_SP(SB, vb.wp + 1); pr_debug("SB: %ld %08lx %ld (%ld)\n", SB_s, SB_f, SB_e, SB_c); FP_CONV(D, S, 2, 1, DR, SB); goto pack_d; } case EFDCTUIDZ: case EFDCTSIDZ: _FP_ROUND_ZERO(2, DB); FP_TO_INT_D(vc.dp[0], DB, 64, ((func & 0x1) == 0)); goto update_regs; case EFDCTUI: case EFDCTSI: case EFDCTUIZ: case EFDCTSIZ: if (func & 0x4) { _FP_ROUND(2, DB); } else { _FP_ROUND_ZERO(2, DB); } FP_TO_INT_D(vc.wp[1], DB, 32, (((func & 0x3) != 0) || DB_s)); goto update_regs; default: goto illegal; } break; pack_d: pr_debug("DR: %ld %08lx %08lx %ld (%ld)\n", DR_s, DR_f1, DR_f0, DR_e, DR_c); FP_PACK_DP(vc.dp, DR); goto update_regs; cmp_d: FP_CMP_D(IR, DA, DB, 3); if (IR == 3 && (FP_ISSIGNAN_D(DA) || FP_ISSIGNAN_D(DB))) FP_SET_EXCEPTION(FP_EX_INVALID); if (IR == cmp) { IR = 0x4; } else { IR = 0; } goto update_ccr; } case VCT: { FP_DECL_S(SA0); FP_DECL_S(SB0); FP_DECL_S(SR0); FP_DECL_S(SA1); FP_DECL_S(SB1); FP_DECL_S(SR1); int IR0, IR1; switch (type) { case AB: case XCR: FP_UNPACK_SP(SA0, va.wp); FP_UNPACK_SP(SA1, va.wp + 1); case XB: FP_UNPACK_SP(SB0, vb.wp); FP_UNPACK_SP(SB1, vb.wp + 1); break; case XA: FP_UNPACK_SP(SA0, va.wp); FP_UNPACK_SP(SA1, va.wp + 1); break; } pr_debug("SA0: %ld %08lx %ld (%ld)\n", SA0_s, SA0_f, SA0_e, SA0_c); pr_debug("SA1: %ld %08lx %ld (%ld)\n", SA1_s, SA1_f, SA1_e, SA1_c); pr_debug("SB0: %ld %08lx %ld (%ld)\n", SB0_s, SB0_f, SB0_e, SB0_c); pr_debug("SB1: %ld %08lx %ld (%ld)\n", SB1_s, SB1_f, SB1_e, SB1_c); switch (func) { case EVFSABS: vc.wp[0] = va.wp[0] & ~SIGN_BIT_S; vc.wp[1] = va.wp[1] & ~SIGN_BIT_S; goto update_regs; case EVFSNABS: vc.wp[0] = va.wp[0] | SIGN_BIT_S; vc.wp[1] = va.wp[1] | SIGN_BIT_S; goto update_regs; case EVFSNEG: vc.wp[0] = va.wp[0] ^ SIGN_BIT_S; vc.wp[1] = va.wp[1] ^ SIGN_BIT_S; goto update_regs; case EVFSADD: FP_ADD_S(SR0, SA0, SB0); FP_ADD_S(SR1, SA1, SB1); goto pack_vs; case EVFSSUB: FP_SUB_S(SR0, SA0, SB0); FP_SUB_S(SR1, SA1, SB1); goto pack_vs; case EVFSMUL: FP_MUL_S(SR0, SA0, SB0); FP_MUL_S(SR1, SA1, SB1); goto pack_vs; case EVFSDIV: FP_DIV_S(SR0, SA0, SB0); FP_DIV_S(SR1, SA1, SB1); goto pack_vs; case EVFSCMPEQ: cmp = 0; goto cmp_vs; case EVFSCMPGT: cmp = 1; goto cmp_vs; case EVFSCMPLT: cmp = -1; goto cmp_vs; case EVFSCTSF: __asm__ __volatile__ ("mtspr 512, %4\n" "efsctsf %0, %2\n" "efsctsf %1, %3\n" : "=r" (vc.wp[0]), "=r" (vc.wp[1]) : "r" (vb.wp[0]), "r" (vb.wp[1]), "r" (0)); goto update_regs; case EVFSCTUF: __asm__ __volatile__ ("mtspr 512, %4\n" "efsctuf %0, %2\n" "efsctuf %1, %3\n" : "=r" (vc.wp[0]), "=r" (vc.wp[1]) : "r" (vb.wp[0]), "r" (vb.wp[1]), "r" (0)); goto update_regs; case EVFSCTUI: case EVFSCTSI: case EVFSCTUIZ: case EVFSCTSIZ: if (func & 0x4) { _FP_ROUND(1, SB0); _FP_ROUND(1, SB1); } else { _FP_ROUND_ZERO(1, SB0); _FP_ROUND_ZERO(1, SB1); } FP_TO_INT_S(vc.wp[0], SB0, 32, (((func & 0x3) != 0) || SB0_s)); FP_TO_INT_S(vc.wp[1], SB1, 32, (((func & 0x3) != 0) || SB1_s)); goto update_regs; default: goto illegal; } break; pack_vs: pr_debug("SR0: %ld %08lx %ld (%ld)\n", SR0_s, SR0_f, SR0_e, SR0_c); pr_debug("SR1: %ld %08lx %ld (%ld)\n", SR1_s, SR1_f, SR1_e, SR1_c); FP_PACK_SP(vc.wp, SR0); FP_PACK_SP(vc.wp + 1, SR1); goto update_regs; cmp_vs: { int ch, cl; FP_CMP_S(IR0, SA0, SB0, 3); FP_CMP_S(IR1, SA1, SB1, 3); if (IR0 == 3 && (FP_ISSIGNAN_S(SA0) || FP_ISSIGNAN_S(SB0))) FP_SET_EXCEPTION(FP_EX_INVALID); if (IR1 == 3 && (FP_ISSIGNAN_S(SA1) || FP_ISSIGNAN_S(SB1))) FP_SET_EXCEPTION(FP_EX_INVALID); ch = (IR0 == cmp) ? 1 : 0; cl = (IR1 == cmp) ? 1 : 0; IR = (ch << 3) | (cl << 2) | ((ch | cl) << 1) | ((ch & cl) << 0); goto update_ccr; } } default: return -EINVAL; } update_ccr: regs->ccr &= ~(15 << ((7 - ((speinsn >> 23) & 0x7)) << 2)); regs->ccr |= (IR << ((7 - ((speinsn >> 23) & 0x7)) << 2)); update_regs: __FPU_FPSCR &= ~FP_EX_MASK; __FPU_FPSCR |= (FP_CUR_EXCEPTIONS & FP_EX_MASK); mtspr(SPRN_SPEFSCR, __FPU_FPSCR); current->thread.evr[fc] = vc.wp[0]; regs->gpr[fc] = vc.wp[1]; pr_debug("ccr = %08lx\n", regs->ccr); pr_debug("cur exceptions = %08x spefscr = %08lx\n", FP_CUR_EXCEPTIONS, __FPU_FPSCR); pr_debug("vc: %08x %08x\n", vc.wp[0], vc.wp[1]); pr_debug("va: %08x %08x\n", va.wp[0], va.wp[1]); pr_debug("vb: %08x %08x\n", vb.wp[0], vb.wp[1]); return 0; illegal: if (have_e500_cpu_a005_erratum) { /* according to e500 cpu a005 erratum, reissue efp inst */ regs->nip -= 4; pr_debug("re-issue efp inst: %08lx\n", speinsn); return 0; } printk(KERN_ERR "\nOoops! IEEE-754 compliance handler encountered un-supported instruction.\ninst code: %08lx\n", speinsn); return -ENOSYS; } int speround_handler(struct pt_regs *regs) { union dw_union fgpr; int s_lo, s_hi; unsigned long speinsn, type, fc; if (get_user(speinsn, (unsigned int __user *) regs->nip)) return -EFAULT; if ((speinsn >> 26) != 4) return -EINVAL; /* not an spe instruction */ type = insn_type(speinsn & 0x7ff); if (type == XCR) return -ENOSYS; __FPU_FPSCR = mfspr(SPRN_SPEFSCR); pr_debug("speinsn:%08lx spefscr:%08lx\n", speinsn, __FPU_FPSCR); /* No need to round if the result is exact */ if (!(__FPU_FPSCR & FP_EX_INEXACT)) return 0; fc = (speinsn >> 21) & 0x1f; s_lo = regs->gpr[fc] & SIGN_BIT_S; s_hi = current->thread.evr[fc] & SIGN_BIT_S; fgpr.wp[0] = current->thread.evr[fc]; fgpr.wp[1] = regs->gpr[fc]; pr_debug("round fgpr: %08x %08x\n", fgpr.wp[0], fgpr.wp[1]); switch ((speinsn >> 5) & 0x7) { /* Since SPE instructions on E500 core can handle round to nearest * and round toward zero with IEEE-754 complied, we just need * to handle round toward +Inf and round toward -Inf by software. */ case SPFP: if ((FP_ROUNDMODE) == FP_RND_PINF) { if (!s_lo) fgpr.wp[1]++; /* Z > 0, choose Z1 */ } else { /* round to -Inf */ if (s_lo) fgpr.wp[1]++; /* Z < 0, choose Z2 */ } break; case DPFP: if (FP_ROUNDMODE == FP_RND_PINF) { if (!s_hi) fgpr.dp[0]++; /* Z > 0, choose Z1 */ } else { /* round to -Inf */ if (s_hi) fgpr.dp[0]++; /* Z < 0, choose Z2 */ } break; case VCT: if (FP_ROUNDMODE == FP_RND_PINF) { if (!s_lo) fgpr.wp[1]++; /* Z_low > 0, choose Z1 */ if (!s_hi) fgpr.wp[0]++; /* Z_high word > 0, choose Z1 */ } else { /* round to -Inf */ if (s_lo) fgpr.wp[1]++; /* Z_low < 0, choose Z2 */ if (s_hi) fgpr.wp[0]++; /* Z_high < 0, choose Z2 */ } break; default: return -EINVAL; } current->thread.evr[fc] = fgpr.wp[0]; regs->gpr[fc] = fgpr.wp[1]; pr_debug(" to fgpr: %08x %08x\n", fgpr.wp[0], fgpr.wp[1]); return 0; } int __init spe_mathemu_init(void) { u32 pvr, maj, min; pvr = mfspr(SPRN_PVR); if ((PVR_VER(pvr) == PVR_VER_E500V1) || (PVR_VER(pvr) == PVR_VER_E500V2)) { maj = PVR_MAJ(pvr); min = PVR_MIN(pvr); /* * E500 revision below 1.1, 2.3, 3.1, 4.1, 5.1 * need cpu a005 errata workaround */ switch (maj) { case 1: if (min < 1) have_e500_cpu_a005_erratum = 1; break; case 2: if (min < 3) have_e500_cpu_a005_erratum = 1; break; case 3: case 4: case 5: if (min < 1) have_e500_cpu_a005_erratum = 1; break; default: break; } } return 0; } module_init(spe_mathemu_init);
touchpro/android_kernel_lge_msm8226_old_bad
arch/powerpc/math-emu/math_efp.c
C
gpl-2.0
16,878
/* * Basic HP/COMPAQ MSA 1000 support. This is only needed if your HW cannot be * upgraded. * * Copyright (C) 2006 Red Hat, Inc. All rights reserved. * Copyright (C) 2006 Mike Christie * Copyright (C) 2008 Hannes Reinecke <hare@suse.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/slab.h> #include <linux/module.h> #include <scsi/scsi.h> #include <scsi/scsi_dbg.h> #include <scsi/scsi_eh.h> #include <scsi/scsi_dh.h> #define HP_SW_NAME "hp_sw" #define HP_SW_TIMEOUT (60 * HZ) #define HP_SW_RETRIES 3 #define HP_SW_PATH_UNINITIALIZED -1 #define HP_SW_PATH_ACTIVE 0 #define HP_SW_PATH_PASSIVE 1 struct hp_sw_dh_data { unsigned char sense[SCSI_SENSE_BUFFERSIZE]; int path_state; int retries; int retry_cnt; struct scsi_device *sdev; activate_complete callback_fn; void *callback_data; }; static int hp_sw_start_stop(struct hp_sw_dh_data *); static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev) { struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; BUG_ON(scsi_dh_data == NULL); return ((struct hp_sw_dh_data *) scsi_dh_data->buf); } /* * tur_done - Handle TEST UNIT READY return status * @sdev: sdev the command has been sent to * @errors: blk error code * * Returns SCSI_DH_DEV_OFFLINED if the sdev is on the passive path */ static int tur_done(struct scsi_device *sdev, unsigned char *sense) { struct scsi_sense_hdr sshdr; int ret; ret = scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, &sshdr); if (!ret) { sdev_printk(KERN_WARNING, sdev, "%s: sending tur failed, no sense available\n", HP_SW_NAME); ret = SCSI_DH_IO; goto done; } switch (sshdr.sense_key) { case UNIT_ATTENTION: ret = SCSI_DH_IMM_RETRY; break; case NOT_READY: if ((sshdr.asc == 0x04) && (sshdr.ascq == 2)) { /* * LUN not ready - Initialization command required * * This is the passive path */ ret = SCSI_DH_DEV_OFFLINED; break; } /* Fallthrough */ default: sdev_printk(KERN_WARNING, sdev, "%s: sending tur failed, sense %x/%x/%x\n", HP_SW_NAME, sshdr.sense_key, sshdr.asc, sshdr.ascq); break; } done: return ret; } /* * hp_sw_tur - Send TEST UNIT READY * @sdev: sdev command should be sent to * * Use the TEST UNIT READY command to determine * the path state. */ static int hp_sw_tur(struct scsi_device *sdev, struct hp_sw_dh_data *h) { struct request *req; int ret; retry: req = blk_get_request(sdev->request_queue, WRITE, GFP_NOIO); if (!req) return SCSI_DH_RES_TEMP_UNAVAIL; req->cmd_type = REQ_TYPE_BLOCK_PC; req->cmd_flags |= REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER; req->cmd_len = COMMAND_SIZE(TEST_UNIT_READY); req->cmd[0] = TEST_UNIT_READY; req->timeout = HP_SW_TIMEOUT; req->sense = h->sense; memset(req->sense, 0, SCSI_SENSE_BUFFERSIZE); req->sense_len = 0; ret = blk_execute_rq(req->q, NULL, req, 1); if (ret == -EIO) { if (req->sense_len > 0) { ret = tur_done(sdev, h->sense); } else { sdev_printk(KERN_WARNING, sdev, "%s: sending tur failed with %x\n", HP_SW_NAME, req->errors); ret = SCSI_DH_IO; } } else { h->path_state = HP_SW_PATH_ACTIVE; ret = SCSI_DH_OK; } if (ret == SCSI_DH_IMM_RETRY) { blk_put_request(req); goto retry; } if (ret == SCSI_DH_DEV_OFFLINED) { h->path_state = HP_SW_PATH_PASSIVE; ret = SCSI_DH_OK; } blk_put_request(req); return ret; } /* * start_done - Handle START STOP UNIT return status * @sdev: sdev the command has been sent to * @errors: blk error code */ static int start_done(struct scsi_device *sdev, unsigned char *sense) { struct scsi_sense_hdr sshdr; int rc; rc = scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, &sshdr); if (!rc) { sdev_printk(KERN_WARNING, sdev, "%s: sending start_stop_unit failed, " "no sense available\n", HP_SW_NAME); return SCSI_DH_IO; } switch (sshdr.sense_key) { case NOT_READY: if ((sshdr.asc == 0x04) && (sshdr.ascq == 3)) { /* * LUN not ready - manual intervention required * * Switch-over in progress, retry. */ rc = SCSI_DH_RETRY; break; } /* fall through */ default: sdev_printk(KERN_WARNING, sdev, "%s: sending start_stop_unit failed, sense %x/%x/%x\n", HP_SW_NAME, sshdr.sense_key, sshdr.asc, sshdr.ascq); rc = SCSI_DH_IO; } return rc; } static void start_stop_endio(struct request *req, int error) { struct hp_sw_dh_data *h = req->end_io_data; unsigned err = SCSI_DH_OK; if (error || host_byte(req->errors) != DID_OK || msg_byte(req->errors) != COMMAND_COMPLETE) { sdev_printk(KERN_WARNING, h->sdev, "%s: sending start_stop_unit failed with %x\n", HP_SW_NAME, req->errors); err = SCSI_DH_IO; goto done; } if (req->sense_len > 0) { err = start_done(h->sdev, h->sense); if (err == SCSI_DH_RETRY) { err = SCSI_DH_IO; if (--h->retry_cnt) { blk_put_request(req); err = hp_sw_start_stop(h); if (err == SCSI_DH_OK) return; } } } done: req->end_io_data = NULL; __blk_put_request(req->q, req); if (h->callback_fn) { h->callback_fn(h->callback_data, err); h->callback_fn = h->callback_data = NULL; } return; } /* * hp_sw_start_stop - Send START STOP UNIT command * @sdev: sdev command should be sent to * * Sending START STOP UNIT activates the SP. */ static int hp_sw_start_stop(struct hp_sw_dh_data *h) { struct request *req; req = blk_get_request(h->sdev->request_queue, WRITE, GFP_ATOMIC); if (!req) return SCSI_DH_RES_TEMP_UNAVAIL; req->cmd_type = REQ_TYPE_BLOCK_PC; req->cmd_flags |= REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER; req->cmd_len = COMMAND_SIZE(START_STOP); req->cmd[0] = START_STOP; req->cmd[4] = 1; /* Start spin cycle */ req->timeout = HP_SW_TIMEOUT; req->sense = h->sense; memset(req->sense, 0, SCSI_SENSE_BUFFERSIZE); req->sense_len = 0; req->end_io_data = h; blk_execute_rq_nowait(req->q, NULL, req, 1, start_stop_endio); return SCSI_DH_OK; } static int hp_sw_prep_fn(struct scsi_device *sdev, struct request *req) { struct hp_sw_dh_data *h = get_hp_sw_data(sdev); int ret = BLKPREP_OK; if (h->path_state != HP_SW_PATH_ACTIVE) { ret = BLKPREP_KILL; req->cmd_flags |= REQ_QUIET; } return ret; } /* * hp_sw_activate - Activate a path * @sdev: sdev on the path to be activated * * The HP Active/Passive firmware is pretty simple; * the passive path reports NOT READY with sense codes * 0x04/0x02; a START STOP UNIT command will then * activate the passive path (and deactivate the * previously active one). */ static int hp_sw_activate(struct scsi_device *sdev, activate_complete fn, void *data) { int ret = SCSI_DH_OK; struct hp_sw_dh_data *h = get_hp_sw_data(sdev); ret = hp_sw_tur(sdev, h); if (ret == SCSI_DH_OK && h->path_state == HP_SW_PATH_PASSIVE) { h->retry_cnt = h->retries; h->callback_fn = fn; h->callback_data = data; ret = hp_sw_start_stop(h); if (ret == SCSI_DH_OK) return 0; h->callback_fn = h->callback_data = NULL; } if (fn) fn(data, ret); return 0; } static const struct scsi_dh_devlist hp_sw_dh_data_list[] = { {"COMPAQ", "MSA1000 VOLUME"}, {"COMPAQ", "HSV110"}, {"HP", "HSV100"}, {"DEC", "HSG80"}, {NULL, NULL}, }; static bool hp_sw_match(struct scsi_device *sdev) { int i; if (scsi_device_tpgs(sdev)) return false; for (i = 0; hp_sw_dh_data_list[i].vendor; i++) { if (!strncmp(sdev->vendor, hp_sw_dh_data_list[i].vendor, strlen(hp_sw_dh_data_list[i].vendor)) && !strncmp(sdev->model, hp_sw_dh_data_list[i].model, strlen(hp_sw_dh_data_list[i].model))) { return true; } } return false; } static int hp_sw_bus_attach(struct scsi_device *sdev); static void hp_sw_bus_detach(struct scsi_device *sdev); static struct scsi_device_handler hp_sw_dh = { .name = HP_SW_NAME, .module = THIS_MODULE, .devlist = hp_sw_dh_data_list, .attach = hp_sw_bus_attach, .detach = hp_sw_bus_detach, .activate = hp_sw_activate, .prep_fn = hp_sw_prep_fn, .match = hp_sw_match, }; static int hp_sw_bus_attach(struct scsi_device *sdev) { struct scsi_dh_data *scsi_dh_data; struct hp_sw_dh_data *h; unsigned long flags; int ret; scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) + sizeof(*h) , GFP_KERNEL); if (!scsi_dh_data) { sdev_printk(KERN_ERR, sdev, "%s: Attach Failed\n", HP_SW_NAME); return 0; } scsi_dh_data->scsi_dh = &hp_sw_dh; h = (struct hp_sw_dh_data *) scsi_dh_data->buf; h->path_state = HP_SW_PATH_UNINITIALIZED; h->retries = HP_SW_RETRIES; h->sdev = sdev; ret = hp_sw_tur(sdev, h); if (ret != SCSI_DH_OK || h->path_state == HP_SW_PATH_UNINITIALIZED) goto failed; if (!try_module_get(THIS_MODULE)) goto failed; spin_lock_irqsave(sdev->request_queue->queue_lock, flags); sdev->scsi_dh_data = scsi_dh_data; spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n", HP_SW_NAME, h->path_state == HP_SW_PATH_ACTIVE? "active":"passive"); return 0; failed: kfree(scsi_dh_data); sdev_printk(KERN_ERR, sdev, "%s: not attached\n", HP_SW_NAME); return -EINVAL; } static void hp_sw_bus_detach( struct scsi_device *sdev ) { struct scsi_dh_data *scsi_dh_data; unsigned long flags; spin_lock_irqsave(sdev->request_queue->queue_lock, flags); scsi_dh_data = sdev->scsi_dh_data; sdev->scsi_dh_data = NULL; spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); module_put(THIS_MODULE); sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", HP_SW_NAME); kfree(scsi_dh_data); } static int __init hp_sw_init(void) { return scsi_register_device_handler(&hp_sw_dh); } static void __exit hp_sw_exit(void) { scsi_unregister_device_handler(&hp_sw_dh); } module_init(hp_sw_init); module_exit(hp_sw_exit); MODULE_DESCRIPTION("HP Active/Passive driver"); MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu"); MODULE_LICENSE("GPL");
173210/Monarudo_GPU_M7
drivers/scsi/device_handler/scsi_dh_hp_sw.c
C
gpl-2.0
10,601
/* * JFFS2 -- Journalling Flash File System, Version 2. * * Copyright © 2001-2007 Red Hat, Inc. * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org> * * Created by David Woodhouse <dwmw2@infradead.org> * * For licensing information, see the file 'LICENCE' in this directory. * */ #if !defined(__KERNEL__) && !defined(__ECOS) #error "The userspace support got too messy and was removed. Update your mkfs.jffs2" #endif #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/kernel.h> #include <linux/zlib.h> #include <linux/zutil.h> #include "nodelist.h" #include "compr.h" /* Plan: call deflate() with avail_in == *sourcelen, avail_out = *dstlen - 12 and flush == Z_FINISH. If it doesn't manage to finish, call it again with avail_in == 0 and avail_out set to the remaining 12 bytes for it to clean up. Q: Is 12 bytes sufficient? */ #define STREAM_END_SPACE 12 static DEFINE_MUTEX(deflate_mutex); static DEFINE_MUTEX(inflate_mutex); static z_stream inf_strm, def_strm; #ifdef __KERNEL__ /* Linux-only */ #include <linux/vmalloc.h> #include <linux/init.h> #include <linux/mutex.h> static int __init alloc_workspaces(void) { def_strm.workspace = vmalloc(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL)); if (!def_strm.workspace) return -ENOMEM; jffs2_dbg(1, "Allocated %d bytes for deflate workspace\n", zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL)); inf_strm.workspace = vmalloc(zlib_inflate_workspacesize()); if (!inf_strm.workspace) { vfree(def_strm.workspace); return -ENOMEM; } jffs2_dbg(1, "Allocated %d bytes for inflate workspace\n", zlib_inflate_workspacesize()); return 0; } static void free_workspaces(void) { vfree(def_strm.workspace); vfree(inf_strm.workspace); } #else #define alloc_workspaces() (0) #define free_workspaces() do { } while(0) #endif /* __KERNEL__ */ static int jffs2_zlib_compress(unsigned char *data_in, unsigned char *cpage_out, uint32_t *sourcelen, uint32_t *dstlen) { int ret; if (*dstlen <= STREAM_END_SPACE) return -1; mutex_lock(&deflate_mutex); if (Z_OK != zlib_deflateInit(&def_strm, 3)) { pr_warn("deflateInit failed\n"); mutex_unlock(&deflate_mutex); return -1; } def_strm.next_in = data_in; def_strm.total_in = 0; def_strm.next_out = cpage_out; def_strm.total_out = 0; while (def_strm.total_out < *dstlen - STREAM_END_SPACE && def_strm.total_in < *sourcelen) { def_strm.avail_out = *dstlen - (def_strm.total_out + STREAM_END_SPACE); def_strm.avail_in = min((unsigned)(*sourcelen-def_strm.total_in), def_strm.avail_out); jffs2_dbg(1, "calling deflate with avail_in %d, avail_out %d\n", def_strm.avail_in, def_strm.avail_out); ret = zlib_deflate(&def_strm, Z_PARTIAL_FLUSH); jffs2_dbg(1, "deflate returned with avail_in %d, avail_out %d, total_in %ld, total_out %ld\n", def_strm.avail_in, def_strm.avail_out, def_strm.total_in, def_strm.total_out); if (ret != Z_OK) { jffs2_dbg(1, "deflate in loop returned %d\n", ret); zlib_deflateEnd(&def_strm); mutex_unlock(&deflate_mutex); return -1; } } def_strm.avail_out += STREAM_END_SPACE; def_strm.avail_in = 0; ret = zlib_deflate(&def_strm, Z_FINISH); zlib_deflateEnd(&def_strm); if (ret != Z_STREAM_END) { jffs2_dbg(1, "final deflate returned %d\n", ret); ret = -1; goto out; } if (def_strm.total_out >= def_strm.total_in) { jffs2_dbg(1, "zlib compressed %ld bytes into %ld; failing\n", def_strm.total_in, def_strm.total_out); ret = -1; goto out; } jffs2_dbg(1, "zlib compressed %ld bytes into %ld\n", def_strm.total_in, def_strm.total_out); *dstlen = def_strm.total_out; *sourcelen = def_strm.total_in; ret = 0; out: mutex_unlock(&deflate_mutex); return ret; } static int jffs2_zlib_decompress(unsigned char *data_in, unsigned char *cpage_out, uint32_t srclen, uint32_t destlen) { int ret; int wbits = MAX_WBITS; mutex_lock(&inflate_mutex); inf_strm.next_in = data_in; inf_strm.avail_in = srclen; inf_strm.total_in = 0; inf_strm.next_out = cpage_out; inf_strm.avail_out = destlen; inf_strm.total_out = 0; /* If it's deflate, and it's got no preset dictionary, then we can tell zlib to skip the adler32 check. */ if (srclen > 2 && !(data_in[1] & PRESET_DICT) && ((data_in[0] & 0x0f) == Z_DEFLATED) && !(((data_in[0]<<8) + data_in[1]) % 31)) { jffs2_dbg(2, "inflate skipping adler32\n"); wbits = -((data_in[0] >> 4) + 8); inf_strm.next_in += 2; inf_strm.avail_in -= 2; } else { /* Let this remain D1 for now -- it should never happen */ jffs2_dbg(1, "inflate not skipping adler32\n"); } if (Z_OK != zlib_inflateInit2(&inf_strm, wbits)) { pr_warn("inflateInit failed\n"); mutex_unlock(&inflate_mutex); return 1; } while((ret = zlib_inflate(&inf_strm, Z_FINISH)) == Z_OK) ; if (ret != Z_STREAM_END) { pr_notice("inflate returned %d\n", ret); } zlib_inflateEnd(&inf_strm); mutex_unlock(&inflate_mutex); return 0; } static struct jffs2_compressor jffs2_zlib_comp = { .priority = JFFS2_ZLIB_PRIORITY, .name = "zlib", .compr = JFFS2_COMPR_ZLIB, .compress = &jffs2_zlib_compress, .decompress = &jffs2_zlib_decompress, #ifdef JFFS2_ZLIB_DISABLED .disabled = 1, #else .disabled = 0, #endif }; int __init jffs2_zlib_init(void) { int ret; ret = alloc_workspaces(); if (ret) return ret; ret = jffs2_register_compressor(&jffs2_zlib_comp); if (ret) free_workspaces(); return ret; } void jffs2_zlib_exit(void) { jffs2_unregister_compressor(&jffs2_zlib_comp); free_workspaces(); }
smartboyhw/ubuntu-saucy-rt
fs/jffs2/compr_zlib.c
C
gpl-2.0
5,619