Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 26 Mar 2009 18:05:17 +0000 (11:05 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 26 Mar 2009 18:05:17 +0000 (11:05 -0700)
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6: (430 commits)
  ALSA: hda - Add quirk for Acer Ferrari 5000
  ALSA: hda - Use cached calls to get widget caps and pin caps
  ALSA: hda - Don't create empty/single-item input source
  ALSA: hda - Fix the wrong pin-cap check in patch_realtek.c
  ALSA: hda - Cache pin-cap values
  ALSA: hda - Avoid output amp manipulation to digital mic pins
  ALSA: hda - Add function id to proc output
  ALSA: pcm - Safer boundary checks
  ALSA: hda - Detect digital-mic inputs on ALC663 / ALC272
  ALSA: sound/ali5451: typo: s/resouces/resources/
  ALSA: hda - Don't show the current connection for power widgets
  ALSA: Fix wrong pointer to dev_err() in arm/pxa2xx-ac97-lib.c
  ASoC: Declare Headset as Mic and Headphone widgets for SDP3430
  ASoC: OMAP: N810: Add more jack functions
  ASoC: OMAP: N810: Mark not connected input pins
  ASoC: Add FLL support for WM8400
  ALSA: hda - Don't reset stream at each prepare callback
  ALSA: hda - Don't reset BDL unnecessarily
  ALSA: pcm - Fix delta calculation at boundary overlap
  ALSA: pcm - Reset invalid position even without debug option
  ...

162 files changed:
Documentation/ABI/testing/ima_policy [new file with mode: 0644]
Documentation/cpu-freq/governors.txt
Documentation/cpu-freq/user-guide.txt
Documentation/kernel-parameters.txt
MAINTAINERS
arch/mips/include/asm/mipsregs.h
arch/mips/kernel/linux32.c
arch/mips/kernel/traps.c
arch/mips/mm/c-r4k.c
arch/mips/mm/dma-default.c
arch/powerpc/boot/dts/canyonlands.dts
arch/powerpc/boot/dts/kilauea.dts
arch/s390/crypto/sha.h
arch/s390/crypto/sha1_s390.c
arch/s390/crypto/sha256_s390.c
arch/s390/crypto/sha512_s390.c
arch/s390/crypto/sha_common.c
arch/x86/crypto/Makefile
arch/x86/crypto/aes-i586-asm_32.S
arch/x86/crypto/aes-x86_64-asm_64.S
arch/x86/crypto/aes_glue.c
arch/x86/crypto/aesni-intel_asm.S [new file with mode: 0644]
arch/x86/crypto/aesni-intel_glue.c [new file with mode: 0644]
arch/x86/include/asm/aes.h [new file with mode: 0644]
arch/x86/include/asm/cpufeature.h
arch/x86/include/asm/timer.h
arch/x86/kernel/cpu/cpufreq/Kconfig
arch/x86/kernel/cpu/cpufreq/Makefile
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c
arch/x86/kernel/cpu/cpufreq/e_powersaver.c
arch/x86/kernel/cpu/cpufreq/elanfreq.c
arch/x86/kernel/cpu/cpufreq/gx-suspmod.c
arch/x86/kernel/cpu/cpufreq/longhaul.c
arch/x86/kernel/cpu/cpufreq/longhaul.h
arch/x86/kernel/cpu/cpufreq/longrun.c
arch/x86/kernel/cpu/cpufreq/p4-clockmod.c
arch/x86/kernel/cpu/cpufreq/powernow-k6.c
arch/x86/kernel/cpu/cpufreq/powernow-k7.c
arch/x86/kernel/cpu/cpufreq/powernow-k8.c
arch/x86/kernel/cpu/cpufreq/powernow-k8.h
arch/x86/kernel/cpu/cpufreq/sc520_freq.c
arch/x86/kernel/cpu/cpufreq/speedstep-ich.c
arch/x86/kernel/cpu/cpufreq/speedstep-lib.c
arch/x86/kernel/cpu/cpufreq/speedstep-lib.h
arch/x86/kernel/cpu/cpufreq/speedstep-smi.c
arch/x86/kernel/tsc.c
crypto/Kconfig
crypto/Makefile
crypto/ablkcipher.c
crypto/aead.c
crypto/algboss.c
crypto/ansi_cprng.c
crypto/api.c
crypto/blkcipher.c
crypto/chainiv.c
crypto/cryptd.c
crypto/crypto_wq.c [new file with mode: 0644]
crypto/gf128mul.c
crypto/internal.h
crypto/pcompress.c [new file with mode: 0644]
crypto/sha256_generic.c
crypto/shash.c
crypto/tcrypt.c
crypto/testmgr.c
crypto/testmgr.h
crypto/zlib.c [new file with mode: 0644]
drivers/char/hw_random/Kconfig
drivers/char/hw_random/Makefile
drivers/char/hw_random/timeriomem-rng.c [new file with mode: 0644]
drivers/char/tpm/tpm.c
drivers/char/tpm/tpm.h
drivers/cpufreq/cpufreq.c
drivers/cpufreq/cpufreq_conservative.c
drivers/cpufreq/cpufreq_ondemand.c
drivers/cpufreq/cpufreq_stats.c
drivers/cpufreq/cpufreq_userspace.c
drivers/cpufreq/freq_table.c
drivers/crypto/Kconfig
drivers/crypto/Makefile
drivers/crypto/amcc/Makefile [new file with mode: 0644]
drivers/crypto/amcc/crypto4xx_alg.c [new file with mode: 0644]
drivers/crypto/amcc/crypto4xx_core.c [new file with mode: 0644]
drivers/crypto/amcc/crypto4xx_core.h [new file with mode: 0644]
drivers/crypto/amcc/crypto4xx_reg_def.h [new file with mode: 0644]
drivers/crypto/amcc/crypto4xx_sa.c [new file with mode: 0644]
drivers/crypto/amcc/crypto4xx_sa.h [new file with mode: 0644]
fs/compat.c
fs/exec.c
fs/file_table.c
fs/inode.c
fs/namei.c
fs/namespace.c
include/crypto/aes.h
include/crypto/compress.h [new file with mode: 0644]
include/crypto/cryptd.h [new file with mode: 0644]
include/crypto/crypto_wq.h [new file with mode: 0644]
include/crypto/hash.h
include/crypto/internal/compress.h [new file with mode: 0644]
include/linux/audit.h
include/linux/crypto.h
include/linux/fs.h
include/linux/ima.h [new file with mode: 0644]
include/linux/mount.h
include/linux/sched.h
include/linux/timeriomem-rng.h [new file with mode: 0644]
include/linux/tpm.h [new file with mode: 0644]
ipc/shm.c
kernel/user.c
lib/Kconfig
lib/Makefile
lib/nlattr.c [moved from net/netlink/attr.c with 99% similarity]
mm/mmap.c
mm/page-writeback.c
mm/shmem.c
net/Kconfig
net/netlink/Makefile
security/Kconfig
security/Makefile
security/inode.c
security/integrity/ima/Kconfig [new file with mode: 0644]
security/integrity/ima/Makefile [new file with mode: 0644]
security/integrity/ima/ima.h [new file with mode: 0644]
security/integrity/ima/ima_api.c [new file with mode: 0644]
security/integrity/ima/ima_audit.c [new file with mode: 0644]
security/integrity/ima/ima_crypto.c [new file with mode: 0644]
security/integrity/ima/ima_fs.c [new file with mode: 0644]
security/integrity/ima/ima_iint.c [new file with mode: 0644]
security/integrity/ima/ima_init.c [new file with mode: 0644]
security/integrity/ima/ima_main.c [new file with mode: 0644]
security/integrity/ima/ima_policy.c [new file with mode: 0644]
security/integrity/ima/ima_queue.c [new file with mode: 0644]
security/keys/internal.h
security/keys/key.c
security/keys/keyctl.c
security/keys/keyring.c
security/keys/permission.c
security/keys/proc.c
security/keys/process_keys.c
security/keys/request_key.c
security/selinux/avc.c
security/selinux/hooks.c
security/selinux/include/av_perm_to_string.h
security/selinux/include/av_permissions.h
security/selinux/include/objsec.h
security/selinux/include/security.h
security/selinux/nlmsgtab.c
security/selinux/selinuxfs.c
security/selinux/ss/services.c
security/smack/smack_access.c
security/smack/smack_lsm.c
security/smack/smackfs.c
security/tomoyo/Kconfig [new file with mode: 0644]
security/tomoyo/Makefile [new file with mode: 0644]
security/tomoyo/common.c [new file with mode: 0644]
security/tomoyo/common.h [new file with mode: 0644]
security/tomoyo/domain.c [new file with mode: 0644]
security/tomoyo/file.c [new file with mode: 0644]
security/tomoyo/realpath.c [new file with mode: 0644]
security/tomoyo/realpath.h [new file with mode: 0644]
security/tomoyo/tomoyo.c [new file with mode: 0644]
security/tomoyo/tomoyo.h [new file with mode: 0644]

diff --git a/Documentation/ABI/testing/ima_policy b/Documentation/ABI/testing/ima_policy
new file mode 100644 (file)
index 0000000..6434f0d
--- /dev/null
@@ -0,0 +1,61 @@
+What:          security/ima/policy
+Date:          May 2008
+Contact:       Mimi Zohar <zohar@us.ibm.com>
+Description:
+               The Trusted Computing Group(TCG) runtime Integrity
+               Measurement Architecture(IMA) maintains a list of hash
+               values of executables and other sensitive system files
+               loaded into the run-time of this system.  At runtime,
+               the policy can be constrained based on LSM specific data.
+               Policies are loaded into the securityfs file ima/policy
+               by opening the file, writing the rules one at a time and
+               then closing the file.  The new policy takes effect after
+               the file ima/policy is closed.
+
+               rule format: action [condition ...]
+
+               action: measure | dont_measure
+               condition:= base | lsm
+                       base:   [[func=] [mask=] [fsmagic=] [uid=]]
+                       lsm:    [[subj_user=] [subj_role=] [subj_type=]
+                                [obj_user=] [obj_role=] [obj_type=]]
+
+               base:   func:= [BPRM_CHECK][FILE_MMAP][INODE_PERMISSION]
+                       mask:= [MAY_READ] [MAY_WRITE] [MAY_APPEND] [MAY_EXEC]
+                       fsmagic:= hex value
+                       uid:= decimal value
+               lsm:    are LSM specific
+
+               default policy:
+                       # PROC_SUPER_MAGIC
+                       dont_measure fsmagic=0x9fa0
+                       # SYSFS_MAGIC
+                       dont_measure fsmagic=0x62656572
+                       # DEBUGFS_MAGIC
+                       dont_measure fsmagic=0x64626720
+                       # TMPFS_MAGIC
+                       dont_measure fsmagic=0x01021994
+                       # SECURITYFS_MAGIC
+                       dont_measure fsmagic=0x73636673
+
+                       measure func=BPRM_CHECK
+                       measure func=FILE_MMAP mask=MAY_EXEC
+                       measure func=INODE_PERM mask=MAY_READ uid=0
+
+               The default policy measures all executables in bprm_check,
+               all files mmapped executable in file_mmap, and all files
+               open for read by root in inode_permission.
+
+               Examples of LSM specific definitions:
+
+               SELinux:
+                       # SELINUX_MAGIC
+                       dont_measure fsmagic=0xF97CFF8C
+
+                       dont_measure obj_type=var_log_t
+                       dont_measure obj_type=auditd_log_t
+                       measure subj_user=system_u func=INODE_PERM mask=MAY_READ
+                       measure subj_role=system_r func=INODE_PERM mask=MAY_READ
+
+               Smack:
+                       measure subj_user=_ func=INODE_PERM mask=MAY_READ
index 5b0cfa67aff9c89ebc6d0f9dd4d467e8be8ae71f..ce73f3eb5ddb1a99a1b4571d6e058ac5c9823765 100644 (file)
@@ -117,10 +117,28 @@ accessible parameters:
 sampling_rate: measured in uS (10^-6 seconds), this is how often you
 want the kernel to look at the CPU usage and to make decisions on
 what to do about the frequency.  Typically this is set to values of
-around '10000' or more.
-
-show_sampling_rate_(min|max): the minimum and maximum sampling rates
-available that you may set 'sampling_rate' to.
+around '10000' or more. It's default value is (cmp. with users-guide.txt):
+transition_latency * 1000
+The lowest value you can set is:
+transition_latency * 100 or it may get restricted to a value where it
+makes not sense for the kernel anymore to poll that often which depends
+on your HZ config variable (HZ=1000: max=20000us, HZ=250: max=5000).
+Be aware that transition latency is in ns and sampling_rate is in us, so you
+get the same sysfs value by default.
+Sampling rate should always get adjusted considering the transition latency
+To set the sampling rate 750 times as high as the transition latency
+in the bash (as said, 1000 is default), do:
+echo `$(($(cat cpuinfo_transition_latency) * 750 / 1000)) \
+    >ondemand/sampling_rate
+
+show_sampling_rate_(min|max): THIS INTERFACE IS DEPRECATED, DON'T USE IT.
+You can use wider ranges now and the general
+cpuinfo_transition_latency variable (cmp. with user-guide.txt) can be
+used to obtain exactly the same info:
+show_sampling_rate_min = transtition_latency * 500    / 1000
+show_sampling_rate_max = transtition_latency * 500000 / 1000
+(divided by 1000 is to illustrate that sampling rate is in us and
+transition latency is exported ns).
 
 up_threshold: defines what the average CPU usage between the samplings
 of 'sampling_rate' needs to be for the kernel to make a decision on
index 917918f84fc75ac09061be1f1f242159823983cf..75f41193f3e1858b2370a2f4500caf49d2b90360 100644 (file)
@@ -152,6 +152,18 @@ cpuinfo_min_freq :         this file shows the minimum operating
                                frequency the processor can run at(in kHz) 
 cpuinfo_max_freq :             this file shows the maximum operating
                                frequency the processor can run at(in kHz) 
+cpuinfo_transition_latency     The time it takes on this CPU to
+                               switch between two frequencies in nano
+                               seconds. If unknown or known to be
+                               that high that the driver does not
+                               work with the ondemand governor, -1
+                               (CPUFREQ_ETERNAL) will be returned.
+                               Using this information can be useful
+                               to choose an appropriate polling
+                               frequency for a kernel governor or
+                               userspace daemon. Make sure to not
+                               switch the frequency too often
+                               resulting in performance loss.
 scaling_driver :               this file shows what cpufreq driver is
                                used to set the frequency on this CPU
 
index 54f21a5c262b02ef6cb4718f72b8357693197cf3..224263e7711f78d98fcc0becec0a92db2aac6f38 100644 (file)
@@ -44,6 +44,7 @@ parameter is applicable:
        FB      The frame buffer device is enabled.
        HW      Appropriate hardware is enabled.
        IA-64   IA-64 architecture is enabled.
+       IMA     Integrity measurement architecture is enabled.
        IOSCHED More than one I/O scheduler is enabled.
        IP_PNP  IP DHCP, BOOTP, or RARP is enabled.
        ISAPNP  ISA PnP code is enabled.
@@ -902,6 +903,15 @@ and is between 256 and 4096 characters. It is defined in the file
        ihash_entries=  [KNL]
                        Set number of hash buckets for inode cache.
 
+       ima_audit=      [IMA]
+                       Format: { "0" | "1" }
+                       0 -- integrity auditing messages. (Default)
+                       1 -- enable informational integrity auditing messages.
+
+       ima_hash=       [IMA]
+                       Formt: { "sha1" | "md5" }
+                       default: "sha1"
+
        in2000=         [HW,SCSI]
                        See header of drivers/scsi/in2000.c.
 
index 5d460c9d1c2c19ca871fabf53eb786572a64d5aa..1978fb205bf75b6b00df8f19f6b67ccf879ebeca 100644 (file)
@@ -1269,6 +1269,12 @@ L:       linux-crypto@vger.kernel.org
 T:     git kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6.git
 S:     Maintained
 
+CRYPTOGRAPHIC RANDOM NUMBER GENERATOR
+P:     Neil Horman
+M:     nhorman@tuxdriver.com
+L:     linux-crypto@vger.kernel.org
+S:     Maintained
+
 CS5535 Audio ALSA driver
 P:     Jaya Kumar
 M:     jayakumar.alsa@gmail.com
@@ -2216,6 +2222,11 @@ M:       stefanr@s5r6.in-berlin.de
 L:     linux1394-devel@lists.sourceforge.net
 S:     Maintained
 
+INTEGRITY MEASUREMENT ARCHITECTURE (IMA)
+P:     Mimi Zohar
+M:     zohar@us.ibm.com
+S:     Supported
+
 IMS TWINTURBO FRAMEBUFFER DRIVER
 L:     linux-fbdev-devel@lists.sourceforge.net (moderated for non-subscribers)
 S:     Orphan
@@ -3844,6 +3855,7 @@ M:        jmorris@namei.org
 L:     linux-kernel@vger.kernel.org
 L:     linux-security-module@vger.kernel.org (suggested Cc:)
 T:     git kernel.org:pub/scm/linux/kernel/git/jmorris/security-testing-2.6.git
+W:     http://security.wiki.kernel.org/
 S:     Supported
 
 SECURITY CONTACT
@@ -4285,6 +4297,19 @@ L:       tlan-devel@lists.sourceforge.net (subscribers-only)
 W:     http://sourceforge.net/projects/tlan/
 S:     Maintained
 
+TOMOYO SECURITY MODULE
+P:     Kentaro Takeda
+M:     takedakn@nttdata.co.jp
+P:     Tetsuo Handa
+M:     penguin-kernel@I-love.SAKURA.ne.jp
+L:     linux-kernel@vger.kernel.org (kernel issues)
+L:     tomoyo-users-en@lists.sourceforge.jp (subscribers-only, for developers and users in English)
+L:     tomoyo-dev@lists.sourceforge.jp (subscribers-only, for developers in Japanese)
+L:     tomoyo-users@lists.sourceforge.jp (subscribers-only, for users in Japanese)
+W:     http://tomoyo.sourceforge.jp/
+T:     quilt http://svn.sourceforge.jp/svnroot/tomoyo/trunk/2.2.x/tomoyo-lsm/patches/
+S:     Maintained
+
 TOSHIBA ACPI EXTRAS DRIVER
 P:     John Belmonte
 M:     toshiba_acpi@memebeam.org
index 0417516503f634484bea51436d9befa8059b4a83..526f327475cea59bf93f0db86505fdd2ef4f86c3 100644 (file)
@@ -1391,11 +1391,11 @@ static inline void tlb_write_random(void)
 static inline unsigned int                                     \
 set_c0_##name(unsigned int set)                                        \
 {                                                              \
-       unsigned int res;                                       \
+       unsigned int res, new;                                  \
                                                                \
        res = read_c0_##name();                                 \
-       res |= set;                                             \
-       write_c0_##name(res);                                   \
+       new = res | set;                                        \
+       write_c0_##name(new);                                   \
                                                                \
        return res;                                             \
 }                                                              \
@@ -1403,24 +1403,24 @@ set_c0_##name(unsigned int set)                                 \
 static inline unsigned int                                     \
 clear_c0_##name(unsigned int clear)                            \
 {                                                              \
-       unsigned int res;                                       \
+       unsigned int res, new;                                  \
                                                                \
        res = read_c0_##name();                                 \
-       res &= ~clear;                                          \
-       write_c0_##name(res);                                   \
+       new = res & ~clear;                                     \
+       write_c0_##name(new);                                   \
                                                                \
        return res;                                             \
 }                                                              \
                                                                \
 static inline unsigned int                                     \
-change_c0_##name(unsigned int change, unsigned int new)                \
+change_c0_##name(unsigned int change, unsigned int val)                \
 {                                                              \
-       unsigned int res;                                       \
+       unsigned int res, new;                                  \
                                                                \
        res = read_c0_##name();                                 \
-       res &= ~change;                                         \
-       res |= (new & change);                                  \
-       write_c0_##name(res);                                   \
+       new = res & ~change;                                    \
+       new |= (val & change);                                  \
+       write_c0_##name(new);                                   \
                                                                \
        return res;                                             \
 }
index 1a86f84fa9470f31030c53fdc9ad45c792d08425..49aac6e17df932a89658840302c7332a8c27f012 100644 (file)
@@ -32,7 +32,6 @@
 #include <linux/module.h>
 #include <linux/binfmts.h>
 #include <linux/security.h>
-#include <linux/syscalls.h>
 #include <linux/compat.h>
 #include <linux/vfs.h>
 #include <linux/ipc.h>
index b2d7041341b8f5afa3e313302c21b90e34e5ea3d..29fadaccecddef31d5da3ea33f819b1ad3941fe0 100644 (file)
@@ -1520,7 +1520,9 @@ void __cpuinit per_cpu_trap_init(void)
 #endif /* CONFIG_MIPS_MT_SMTC */
 
        if (cpu_has_veic || cpu_has_vint) {
+               unsigned long sr = set_c0_status(ST0_BEV);
                write_c0_ebase(ebase);
+               write_c0_status(sr);
                /* Setting vector spacing enables EI/VI mode  */
                change_c0_intctl(0x3e0, VECTORSPACING);
        }
@@ -1602,8 +1604,6 @@ void __cpuinit set_uncached_handler(unsigned long offset, void *addr,
 #ifdef CONFIG_64BIT
        unsigned long uncached_ebase = TO_UNCAC(ebase);
 #endif
-       if (cpu_has_mips_r2)
-               uncached_ebase += (read_c0_ebase() & 0x3ffff000);
 
        if (!addr)
                panic(panic_null_cerr);
@@ -1635,9 +1635,11 @@ void __init trap_init(void)
                return; /* Already done */
 #endif
 
-       if (cpu_has_veic || cpu_has_vint)
-               ebase = (unsigned long) alloc_bootmem_low_pages(0x200 + VECTORSPACING*64);
-       else {
+       if (cpu_has_veic || cpu_has_vint) {
+               unsigned long size = 0x200 + VECTORSPACING*64;
+               ebase = (unsigned long)
+                       __alloc_bootmem(size, 1 << fls(size), 0);
+       } else {
                ebase = CAC_BASE;
                if (cpu_has_mips_r2)
                        ebase += (read_c0_ebase() & 0x3ffff000);
index c43f4b26a69010b63154a734618060c0981b692e..871e828bc62ac2e7db45405f4347b598374301a5 100644 (file)
@@ -780,7 +780,7 @@ static void __cpuinit probe_pcache(void)
                c->dcache.ways = 2;
                c->dcache.waybit = 0;
 
-               c->options |= MIPS_CPU_CACHE_CDEX_P;
+               c->options |= MIPS_CPU_CACHE_CDEX_P | MIPS_CPU_PREFETCH;
                break;
 
        case CPU_TX49XX:
index 546e6977d4ffb0bd1910a57114803bdb1bffe858..bed56f1ac83709887aa1c4b60922d9fa6602d354 100644 (file)
@@ -225,7 +225,7 @@ void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
        if (!plat_device_is_coherent(dev) && direction != DMA_TO_DEVICE) {
                unsigned long addr;
 
-               addr = plat_dma_addr_to_phys(dma_address);
+               addr = dma_addr_to_virt(dma_address);
                dma_cache_wback_inv(addr, size);
        }
 
index 8b5ba8261a36ad54d80863881da214d3bc273d71..4447def69dc5175f78afb33a7546e901cb9d99b4 100644 (file)
                        dcr-reg = <0x010 0x002>;
                };
 
+               CRYPTO: crypto@180000 {
+                       compatible = "amcc,ppc460ex-crypto", "amcc,ppc4xx-crypto";
+                       reg = <4 0x00180000 0x80400>;
+                       interrupt-parent = <&UIC0>;
+                       interrupts = <0x1d 0x4>;
+               };
+
                MAL0: mcmal {
                        compatible = "ibm,mcmal-460ex", "ibm,mcmal2";
                        dcr-reg = <0x180 0x062>;
index 2804444812e5e75e0a0e19c7ea4c82ad92712700..5e6b08ff6f6701e158aa94241cabe3681024d520 100644 (file)
                                      0x6 0x4>; /* ECC SEC Error */ 
                };
 
+               CRYPTO: crypto@ef700000 {
+                       compatible = "amcc,ppc405ex-crypto", "amcc,ppc4xx-crypto";
+                       reg = <0xef700000 0x80400>;
+                       interrupt-parent = <&UIC0>;
+                       interrupts = <0x17 0x2>;
+               };
+
                MAL0: mcmal {
                        compatible = "ibm,mcmal-405ex", "ibm,mcmal2";
                        dcr-reg = <0x180 0x062>;
index 1ceafa571eab5e2c87276a7da7f8cd1ae66e4dd5..f4e9dc71675f7e5d572c2e6d97312b097e5d89a2 100644 (file)
@@ -29,7 +29,9 @@ struct s390_sha_ctx {
        int func;               /* KIMD function to use */
 };
 
-void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len);
-void s390_sha_final(struct crypto_tfm *tfm, u8 *out);
+struct shash_desc;
+
+int s390_sha_update(struct shash_desc *desc, const u8 *data, unsigned int len);
+int s390_sha_final(struct shash_desc *desc, u8 *out);
 
 #endif
index b3cb5a89b00d08a37030c80ca53940ef9bc3af16..e85ba348722a95007d26bb8ce73e4fe5913c944f 100644 (file)
  * any later version.
  *
  */
+#include <crypto/internal/hash.h>
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/crypto.h>
 #include <crypto/sha.h>
 
 #include "crypt_s390.h"
 #include "sha.h"
 
-static void sha1_init(struct crypto_tfm *tfm)
+static int sha1_init(struct shash_desc *desc)
 {
-       struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm);
+       struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
 
        sctx->state[0] = SHA1_H0;
        sctx->state[1] = SHA1_H1;
@@ -42,34 +42,36 @@ static void sha1_init(struct crypto_tfm *tfm)
        sctx->state[4] = SHA1_H4;
        sctx->count = 0;
        sctx->func = KIMD_SHA_1;
+
+       return 0;
 }
 
-static struct crypto_alg alg = {
-       .cra_name       =       "sha1",
-       .cra_driver_name=       "sha1-s390",
-       .cra_priority   =       CRYPT_S390_PRIORITY,
-       .cra_flags      =       CRYPTO_ALG_TYPE_DIGEST,
-       .cra_blocksize  =       SHA1_BLOCK_SIZE,
-       .cra_ctxsize    =       sizeof(struct s390_sha_ctx),
-       .cra_module     =       THIS_MODULE,
-       .cra_list       =       LIST_HEAD_INIT(alg.cra_list),
-       .cra_u          =       { .digest = {
-       .dia_digestsize =       SHA1_DIGEST_SIZE,
-       .dia_init       =       sha1_init,
-       .dia_update     =       s390_sha_update,
-       .dia_final      =       s390_sha_final } }
+static struct shash_alg alg = {
+       .digestsize     =       SHA1_DIGEST_SIZE,
+       .init           =       sha1_init,
+       .update         =       s390_sha_update,
+       .final          =       s390_sha_final,
+       .descsize       =       sizeof(struct s390_sha_ctx),
+       .base           =       {
+               .cra_name       =       "sha1",
+               .cra_driver_name=       "sha1-s390",
+               .cra_priority   =       CRYPT_S390_PRIORITY,
+               .cra_flags      =       CRYPTO_ALG_TYPE_SHASH,
+               .cra_blocksize  =       SHA1_BLOCK_SIZE,
+               .cra_module     =       THIS_MODULE,
+       }
 };
 
 static int __init sha1_s390_init(void)
 {
        if (!crypt_s390_func_available(KIMD_SHA_1))
                return -EOPNOTSUPP;
-       return crypto_register_alg(&alg);
+       return crypto_register_shash(&alg);
 }
 
 static void __exit sha1_s390_fini(void)
 {
-       crypto_unregister_alg(&alg);
+       crypto_unregister_shash(&alg);
 }
 
 module_init(sha1_s390_init);
index 19c03fb6ba7eee64d773ab0cdb5d0c1d556c05c0..f9fefc5696329fd4f64e272ff6dac0c4e5ec0f91 100644 (file)
  * any later version.
  *
  */
+#include <crypto/internal/hash.h>
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/crypto.h>
 #include <crypto/sha.h>
 
 #include "crypt_s390.h"
 #include "sha.h"
 
-static void sha256_init(struct crypto_tfm *tfm)
+static int sha256_init(struct shash_desc *desc)
 {
-       struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm);
+       struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
 
        sctx->state[0] = SHA256_H0;
        sctx->state[1] = SHA256_H1;
@@ -38,22 +38,24 @@ static void sha256_init(struct crypto_tfm *tfm)
        sctx->state[7] = SHA256_H7;
        sctx->count = 0;
        sctx->func = KIMD_SHA_256;
+
+       return 0;
 }
 
-static struct crypto_alg alg = {
-       .cra_name       =       "sha256",
-       .cra_driver_name =      "sha256-s390",
-       .cra_priority   =       CRYPT_S390_PRIORITY,
-       .cra_flags      =       CRYPTO_ALG_TYPE_DIGEST,
-       .cra_blocksize  =       SHA256_BLOCK_SIZE,
-       .cra_ctxsize    =       sizeof(struct s390_sha_ctx),
-       .cra_module     =       THIS_MODULE,
-       .cra_list       =       LIST_HEAD_INIT(alg.cra_list),
-       .cra_u          =       { .digest = {
-       .dia_digestsize =       SHA256_DIGEST_SIZE,
-       .dia_init       =       sha256_init,
-       .dia_update     =       s390_sha_update,
-       .dia_final      =       s390_sha_final } }
+static struct shash_alg alg = {
+       .digestsize     =       SHA256_DIGEST_SIZE,
+       .init           =       sha256_init,
+       .update         =       s390_sha_update,
+       .final          =       s390_sha_final,
+       .descsize       =       sizeof(struct s390_sha_ctx),
+       .base           =       {
+               .cra_name       =       "sha256",
+               .cra_driver_name=       "sha256-s390",
+               .cra_priority   =       CRYPT_S390_PRIORITY,
+               .cra_flags      =       CRYPTO_ALG_TYPE_SHASH,
+               .cra_blocksize  =       SHA256_BLOCK_SIZE,
+               .cra_module     =       THIS_MODULE,
+       }
 };
 
 static int sha256_s390_init(void)
@@ -61,12 +63,12 @@ static int sha256_s390_init(void)
        if (!crypt_s390_func_available(KIMD_SHA_256))
                return -EOPNOTSUPP;
 
-       return crypto_register_alg(&alg);
+       return crypto_register_shash(&alg);
 }
 
 static void __exit sha256_s390_fini(void)
 {
-       crypto_unregister_alg(&alg);
+       crypto_unregister_shash(&alg);
 }
 
 module_init(sha256_s390_init);
index 23c7861f6aeb4d132c2380aca491998be609174c..83192bfc80480bd1477433fd906b6450ab7c4d38 100644 (file)
  * any later version.
  *
  */
+#include <crypto/internal/hash.h>
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/crypto.h>
 
 #include "sha.h"
 #include "crypt_s390.h"
 
-static void sha512_init(struct crypto_tfm *tfm)
+static int sha512_init(struct shash_desc *desc)
 {
-       struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm);
+       struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
 
        *(__u64 *)&ctx->state[0] = 0x6a09e667f3bcc908ULL;
        *(__u64 *)&ctx->state[2] = 0xbb67ae8584caa73bULL;
@@ -33,29 +33,31 @@ static void sha512_init(struct crypto_tfm *tfm)
        *(__u64 *)&ctx->state[14] = 0x5be0cd19137e2179ULL;
        ctx->count = 0;
        ctx->func = KIMD_SHA_512;
+
+       return 0;
 }
 
-static struct crypto_alg sha512_alg = {
-       .cra_name       =       "sha512",
-       .cra_driver_name =      "sha512-s390",
-       .cra_priority   =       CRYPT_S390_PRIORITY,
-       .cra_flags      =       CRYPTO_ALG_TYPE_DIGEST,
-       .cra_blocksize  =       SHA512_BLOCK_SIZE,
-       .cra_ctxsize    =       sizeof(struct s390_sha_ctx),
-       .cra_module     =       THIS_MODULE,
-       .cra_list       =       LIST_HEAD_INIT(sha512_alg.cra_list),
-       .cra_u          =       { .digest = {
-       .dia_digestsize =       SHA512_DIGEST_SIZE,
-       .dia_init       =       sha512_init,
-       .dia_update     =       s390_sha_update,
-       .dia_final      =       s390_sha_final } }
+static struct shash_alg sha512_alg = {
+       .digestsize     =       SHA512_DIGEST_SIZE,
+       .init           =       sha512_init,
+       .update         =       s390_sha_update,
+       .final          =       s390_sha_final,
+       .descsize       =       sizeof(struct s390_sha_ctx),
+       .base           =       {
+               .cra_name       =       "sha512",
+               .cra_driver_name=       "sha512-s390",
+               .cra_priority   =       CRYPT_S390_PRIORITY,
+               .cra_flags      =       CRYPTO_ALG_TYPE_SHASH,
+               .cra_blocksize  =       SHA512_BLOCK_SIZE,
+               .cra_module     =       THIS_MODULE,
+       }
 };
 
 MODULE_ALIAS("sha512");
 
-static void sha384_init(struct crypto_tfm *tfm)
+static int sha384_init(struct shash_desc *desc)
 {
-       struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm);
+       struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
 
        *(__u64 *)&ctx->state[0] = 0xcbbb9d5dc1059ed8ULL;
        *(__u64 *)&ctx->state[2] = 0x629a292a367cd507ULL;
@@ -67,22 +69,25 @@ static void sha384_init(struct crypto_tfm *tfm)
        *(__u64 *)&ctx->state[14] = 0x47b5481dbefa4fa4ULL;
        ctx->count = 0;
        ctx->func = KIMD_SHA_512;
+
+       return 0;
 }
 
-static struct crypto_alg sha384_alg = {
-       .cra_name       =       "sha384",
-       .cra_driver_name =      "sha384-s390",
-       .cra_priority   =       CRYPT_S390_PRIORITY,
-       .cra_flags      =       CRYPTO_ALG_TYPE_DIGEST,
-       .cra_blocksize  =       SHA384_BLOCK_SIZE,
-       .cra_ctxsize    =       sizeof(struct s390_sha_ctx),
-       .cra_module     =       THIS_MODULE,
-       .cra_list       =       LIST_HEAD_INIT(sha384_alg.cra_list),
-       .cra_u          =       { .digest = {
-       .dia_digestsize =       SHA384_DIGEST_SIZE,
-       .dia_init       =       sha384_init,
-       .dia_update     =       s390_sha_update,
-       .dia_final      =       s390_sha_final } }
+static struct shash_alg sha384_alg = {
+       .digestsize     =       SHA384_DIGEST_SIZE,
+       .init           =       sha384_init,
+       .update         =       s390_sha_update,
+       .final          =       s390_sha_final,
+       .descsize       =       sizeof(struct s390_sha_ctx),
+       .base           =       {
+               .cra_name       =       "sha384",
+               .cra_driver_name=       "sha384-s390",
+               .cra_priority   =       CRYPT_S390_PRIORITY,
+               .cra_flags      =       CRYPTO_ALG_TYPE_SHASH,
+               .cra_blocksize  =       SHA384_BLOCK_SIZE,
+               .cra_ctxsize    =       sizeof(struct s390_sha_ctx),
+               .cra_module     =       THIS_MODULE,
+       }
 };
 
 MODULE_ALIAS("sha384");
@@ -93,18 +98,18 @@ static int __init init(void)
 
        if (!crypt_s390_func_available(KIMD_SHA_512))
                return -EOPNOTSUPP;
-       if ((ret = crypto_register_alg(&sha512_alg)) < 0)
+       if ((ret = crypto_register_shash(&sha512_alg)) < 0)
                goto out;
-       if ((ret = crypto_register_alg(&sha384_alg)) < 0)
-               crypto_unregister_alg(&sha512_alg);
+       if ((ret = crypto_register_shash(&sha384_alg)) < 0)
+               crypto_unregister_shash(&sha512_alg);
 out:
        return ret;
 }
 
 static void __exit fini(void)
 {
-       crypto_unregister_alg(&sha512_alg);
-       crypto_unregister_alg(&sha384_alg);
+       crypto_unregister_shash(&sha512_alg);
+       crypto_unregister_shash(&sha384_alg);
 }
 
 module_init(init);
index 9d6eb8c3d37e3fac5df1312fd00d05554adbac3c..7903ec47e6b9c4a48ab9ffd6b2f47db7ee601678 100644 (file)
  *
  */
 
-#include <linux/crypto.h>
+#include <crypto/internal/hash.h>
 #include "sha.h"
 #include "crypt_s390.h"
 
-void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
+int s390_sha_update(struct shash_desc *desc, const u8 *data, unsigned int len)
 {
-       struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm);
-       unsigned int bsize = crypto_tfm_alg_blocksize(tfm);
+       struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
+       unsigned int bsize = crypto_shash_blocksize(desc->tfm);
        unsigned int index;
        int ret;
 
@@ -51,13 +51,15 @@ void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
 store:
        if (len)
                memcpy(ctx->buf + index , data, len);
+
+       return 0;
 }
 EXPORT_SYMBOL_GPL(s390_sha_update);
 
-void s390_sha_final(struct crypto_tfm *tfm, u8 *out)
+int s390_sha_final(struct shash_desc *desc, u8 *out)
 {
-       struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm);
-       unsigned int bsize = crypto_tfm_alg_blocksize(tfm);
+       struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
+       unsigned int bsize = crypto_shash_blocksize(desc->tfm);
        u64 bits;
        unsigned int index, end, plen;
        int ret;
@@ -87,9 +89,11 @@ void s390_sha_final(struct crypto_tfm *tfm, u8 *out)
        BUG_ON(ret != end);
 
        /* copy digest to out */
-       memcpy(out, ctx->state, crypto_hash_digestsize(crypto_hash_cast(tfm)));
+       memcpy(out, ctx->state, crypto_shash_digestsize(desc->tfm));
        /* wipe context */
        memset(ctx, 0, sizeof *ctx);
+
+       return 0;
 }
 EXPORT_SYMBOL_GPL(s390_sha_final);
 
index 903de4aa509496205cf792980d1b6f57b3d87177..ebe7deedd5b42b27974b1b8884e1b68bdebb82cb 100644 (file)
@@ -9,6 +9,7 @@ obj-$(CONFIG_CRYPTO_SALSA20_586) += salsa20-i586.o
 obj-$(CONFIG_CRYPTO_AES_X86_64) += aes-x86_64.o
 obj-$(CONFIG_CRYPTO_TWOFISH_X86_64) += twofish-x86_64.o
 obj-$(CONFIG_CRYPTO_SALSA20_X86_64) += salsa20-x86_64.o
+obj-$(CONFIG_CRYPTO_AES_NI_INTEL) += aesni-intel.o
 
 obj-$(CONFIG_CRYPTO_CRC32C_INTEL) += crc32c-intel.o
 
@@ -19,3 +20,5 @@ salsa20-i586-y := salsa20-i586-asm_32.o salsa20_glue.o
 aes-x86_64-y := aes-x86_64-asm_64.o aes_glue.o
 twofish-x86_64-y := twofish-x86_64-asm_64.o twofish_glue.o
 salsa20-x86_64-y := salsa20-x86_64-asm_64.o salsa20_glue.o
+
+aesni-intel-y := aesni-intel_asm.o aesni-intel_glue.o
index e41b147f45093009d9dbda30c314d1d4d748d3a5..b949ec2f9af444e06377492d39b9db9960f3a626 100644 (file)
 #define tlen 1024   // length of each of 4 'xor' arrays (256 32-bit words)
 
 /* offsets to parameters with one register pushed onto stack */
-#define tfm 8
+#define ctx 8
 #define out_blk 12
 #define in_blk 16
 
-/* offsets in crypto_tfm structure */
-#define klen (crypto_tfm_ctx_offset + 0)
-#define ekey (crypto_tfm_ctx_offset + 4)
-#define dkey (crypto_tfm_ctx_offset + 244)
+/* offsets in crypto_aes_ctx structure */
+#define klen (480)
+#define ekey (0)
+#define dkey (240)
 
 // register mapping for encrypt and decrypt subroutines
 
        do_col (table, r5,r0,r1,r4, r2,r3);             /* idx=r5 */
 
 // AES (Rijndael) Encryption Subroutine
-/* void aes_enc_blk(struct crypto_tfm *tfm, u8 *out_blk, const u8 *in_blk) */
+/* void aes_enc_blk(struct crypto_aes_ctx *ctx, u8 *out_blk, const u8 *in_blk) */
 
 .global  aes_enc_blk
 
 
 aes_enc_blk:
        push    %ebp
-       mov     tfm(%esp),%ebp
+       mov     ctx(%esp),%ebp
 
 // CAUTION: the order and the values used in these assigns 
 // rely on the register mappings
@@ -292,7 +292,7 @@ aes_enc_blk:
        ret
 
 // AES (Rijndael) Decryption Subroutine
-/* void aes_dec_blk(struct crypto_tfm *tfm, u8 *out_blk, const u8 *in_blk) */
+/* void aes_dec_blk(struct crypto_aes_ctx *ctx, u8 *out_blk, const u8 *in_blk) */
 
 .global  aes_dec_blk
 
@@ -303,7 +303,7 @@ aes_enc_blk:
 
 aes_dec_blk:
        push    %ebp
-       mov     tfm(%esp),%ebp
+       mov     ctx(%esp),%ebp
 
 // CAUTION: the order and the values used in these assigns 
 // rely on the register mappings
index a120f526c3df9d9c547b996867f1b035b44b006b..5b577d5a059b03db65d587e1eb15495d0ba99fa1 100644 (file)
@@ -17,8 +17,6 @@
 
 #include <asm/asm-offsets.h>
 
-#define BASE crypto_tfm_ctx_offset
-
 #define R1     %rax
 #define R1E    %eax
 #define R1X    %ax
        .align  8;                      \
 FUNC:  movq    r1,r2;                  \
        movq    r3,r4;                  \
-       leaq    BASE+KEY+48+4(r8),r9;   \
+       leaq    KEY+48(r8),r9;          \
        movq    r10,r11;                \
        movl    (r7),r5 ## E;           \
        movl    4(r7),r1 ## E;          \
        movl    8(r7),r6 ## E;          \
        movl    12(r7),r7 ## E;         \
-       movl    BASE+0(r8),r10 ## E;    \
+       movl    480(r8),r10 ## E;       \
        xorl    -48(r9),r5 ## E;        \
        xorl    -44(r9),r1 ## E;        \
        xorl    -40(r9),r6 ## E;        \
index 71f457827116bee654f4f5c67edebfe8117697c9..49ae9fe32b22079dc22c8d0bf121410285010d3d 100644 (file)
@@ -5,17 +5,29 @@
 
 #include <crypto/aes.h>
 
-asmlinkage void aes_enc_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
-asmlinkage void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
+asmlinkage void aes_enc_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);
+asmlinkage void aes_dec_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);
+
+void crypto_aes_encrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
+{
+       aes_enc_blk(ctx, dst, src);
+}
+EXPORT_SYMBOL_GPL(crypto_aes_encrypt_x86);
+
+void crypto_aes_decrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
+{
+       aes_dec_blk(ctx, dst, src);
+}
+EXPORT_SYMBOL_GPL(crypto_aes_decrypt_x86);
 
 static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 {
-       aes_enc_blk(tfm, dst, src);
+       aes_enc_blk(crypto_tfm_ctx(tfm), dst, src);
 }
 
 static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 {
-       aes_dec_blk(tfm, dst, src);
+       aes_dec_blk(crypto_tfm_ctx(tfm), dst, src);
 }
 
 static struct crypto_alg aes_alg = {
diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
new file mode 100644 (file)
index 0000000..caba996
--- /dev/null
@@ -0,0 +1,896 @@
+/*
+ * Implement AES algorithm in Intel AES-NI instructions.
+ *
+ * The white paper of AES-NI instructions can be downloaded from:
+ *   http://softwarecommunity.intel.com/isn/downloads/intelavx/AES-Instructions-Set_WP.pdf
+ *
+ * Copyright (C) 2008, Intel Corp.
+ *    Author: Huang Ying <ying.huang@intel.com>
+ *            Vinodh Gopal <vinodh.gopal@intel.com>
+ *            Kahraman Akdemir
+ *
+ * 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/linkage.h>
+
+.text
+
+#define STATE1 %xmm0
+#define STATE2 %xmm4
+#define STATE3 %xmm5
+#define STATE4 %xmm6
+#define STATE  STATE1
+#define IN1    %xmm1
+#define IN2    %xmm7
+#define IN3    %xmm8
+#define IN4    %xmm9
+#define IN     IN1
+#define KEY    %xmm2
+#define IV     %xmm3
+
+#define KEYP   %rdi
+#define OUTP   %rsi
+#define INP    %rdx
+#define LEN    %rcx
+#define IVP    %r8
+#define KLEN   %r9d
+#define T1     %r10
+#define TKEYP  T1
+#define T2     %r11
+
+_key_expansion_128:
+_key_expansion_256a:
+       pshufd $0b11111111, %xmm1, %xmm1
+       shufps $0b00010000, %xmm0, %xmm4
+       pxor %xmm4, %xmm0
+       shufps $0b10001100, %xmm0, %xmm4
+       pxor %xmm4, %xmm0
+       pxor %xmm1, %xmm0
+       movaps %xmm0, (%rcx)
+       add $0x10, %rcx
+       ret
+
+_key_expansion_192a:
+       pshufd $0b01010101, %xmm1, %xmm1
+       shufps $0b00010000, %xmm0, %xmm4
+       pxor %xmm4, %xmm0
+       shufps $0b10001100, %xmm0, %xmm4
+       pxor %xmm4, %xmm0
+       pxor %xmm1, %xmm0
+
+       movaps %xmm2, %xmm5
+       movaps %xmm2, %xmm6
+       pslldq $4, %xmm5
+       pshufd $0b11111111, %xmm0, %xmm3
+       pxor %xmm3, %xmm2
+       pxor %xmm5, %xmm2
+
+       movaps %xmm0, %xmm1
+       shufps $0b01000100, %xmm0, %xmm6
+       movaps %xmm6, (%rcx)
+       shufps $0b01001110, %xmm2, %xmm1
+       movaps %xmm1, 16(%rcx)
+       add $0x20, %rcx
+       ret
+
+_key_expansion_192b:
+       pshufd $0b01010101, %xmm1, %xmm1
+       shufps $0b00010000, %xmm0, %xmm4
+       pxor %xmm4, %xmm0
+       shufps $0b10001100, %xmm0, %xmm4
+       pxor %xmm4, %xmm0
+       pxor %xmm1, %xmm0
+
+       movaps %xmm2, %xmm5
+       pslldq $4, %xmm5
+       pshufd $0b11111111, %xmm0, %xmm3
+       pxor %xmm3, %xmm2
+       pxor %xmm5, %xmm2
+
+       movaps %xmm0, (%rcx)
+       add $0x10, %rcx
+       ret
+
+_key_expansion_256b:
+       pshufd $0b10101010, %xmm1, %xmm1
+       shufps $0b00010000, %xmm2, %xmm4
+       pxor %xmm4, %xmm2
+       shufps $0b10001100, %xmm2, %xmm4
+       pxor %xmm4, %xmm2
+       pxor %xmm1, %xmm2
+       movaps %xmm2, (%rcx)
+       add $0x10, %rcx
+       ret
+
+/*
+ * int aesni_set_key(struct crypto_aes_ctx *ctx, const u8 *in_key,
+ *                   unsigned int key_len)
+ */
+ENTRY(aesni_set_key)
+       movups (%rsi), %xmm0            # user key (first 16 bytes)
+       movaps %xmm0, (%rdi)
+       lea 0x10(%rdi), %rcx            # key addr
+       movl %edx, 480(%rdi)
+       pxor %xmm4, %xmm4               # xmm4 is assumed 0 in _key_expansion_x
+       cmp $24, %dl
+       jb .Lenc_key128
+       je .Lenc_key192
+       movups 0x10(%rsi), %xmm2        # other user key
+       movaps %xmm2, (%rcx)
+       add $0x10, %rcx
+       # aeskeygenassist $0x1, %xmm2, %xmm1    # round 1
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x01
+       call _key_expansion_256a
+       # aeskeygenassist $0x1, %xmm0, %xmm1
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x01
+       call _key_expansion_256b
+       # aeskeygenassist $0x2, %xmm2, %xmm1    # round 2
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x02
+       call _key_expansion_256a
+       # aeskeygenassist $0x2, %xmm0, %xmm1
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x02
+       call _key_expansion_256b
+       # aeskeygenassist $0x4, %xmm2, %xmm1    # round 3
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x04
+       call _key_expansion_256a
+       # aeskeygenassist $0x4, %xmm0, %xmm1
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x04
+       call _key_expansion_256b
+       # aeskeygenassist $0x8, %xmm2, %xmm1    # round 4
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x08
+       call _key_expansion_256a
+       # aeskeygenassist $0x8, %xmm0, %xmm1
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x08
+       call _key_expansion_256b
+       # aeskeygenassist $0x10, %xmm2, %xmm1   # round 5
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x10
+       call _key_expansion_256a
+       # aeskeygenassist $0x10, %xmm0, %xmm1
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x10
+       call _key_expansion_256b
+       # aeskeygenassist $0x20, %xmm2, %xmm1   # round 6
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x20
+       call _key_expansion_256a
+       # aeskeygenassist $0x20, %xmm0, %xmm1
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x20
+       call _key_expansion_256b
+       # aeskeygenassist $0x40, %xmm2, %xmm1   # round 7
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x40
+       call _key_expansion_256a
+       jmp .Ldec_key
+.Lenc_key192:
+       movq 0x10(%rsi), %xmm2          # other user key
+       # aeskeygenassist $0x1, %xmm2, %xmm1    # round 1
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x01
+       call _key_expansion_192a
+       # aeskeygenassist $0x2, %xmm2, %xmm1    # round 2
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x02
+       call _key_expansion_192b
+       # aeskeygenassist $0x4, %xmm2, %xmm1    # round 3
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x04
+       call _key_expansion_192a
+       # aeskeygenassist $0x8, %xmm2, %xmm1    # round 4
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x08
+       call _key_expansion_192b
+       # aeskeygenassist $0x10, %xmm2, %xmm1   # round 5
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x10
+       call _key_expansion_192a
+       # aeskeygenassist $0x20, %xmm2, %xmm1   # round 6
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x20
+       call _key_expansion_192b
+       # aeskeygenassist $0x40, %xmm2, %xmm1   # round 7
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x40
+       call _key_expansion_192a
+       # aeskeygenassist $0x80, %xmm2, %xmm1   # round 8
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x80
+       call _key_expansion_192b
+       jmp .Ldec_key
+.Lenc_key128:
+       # aeskeygenassist $0x1, %xmm0, %xmm1    # round 1
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x01
+       call _key_expansion_128
+       # aeskeygenassist $0x2, %xmm0, %xmm1    # round 2
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x02
+       call _key_expansion_128
+       # aeskeygenassist $0x4, %xmm0, %xmm1    # round 3
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x04
+       call _key_expansion_128
+       # aeskeygenassist $0x8, %xmm0, %xmm1    # round 4
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x08
+       call _key_expansion_128
+       # aeskeygenassist $0x10, %xmm0, %xmm1   # round 5
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x10
+       call _key_expansion_128
+       # aeskeygenassist $0x20, %xmm0, %xmm1   # round 6
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x20
+       call _key_expansion_128
+       # aeskeygenassist $0x40, %xmm0, %xmm1   # round 7
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x40
+       call _key_expansion_128
+       # aeskeygenassist $0x80, %xmm0, %xmm1   # round 8
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x80
+       call _key_expansion_128
+       # aeskeygenassist $0x1b, %xmm0, %xmm1   # round 9
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x1b
+       call _key_expansion_128
+       # aeskeygenassist $0x36, %xmm0, %xmm1   # round 10
+       .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x36
+       call _key_expansion_128
+.Ldec_key:
+       sub $0x10, %rcx
+       movaps (%rdi), %xmm0
+       movaps (%rcx), %xmm1
+       movaps %xmm0, 240(%rcx)
+       movaps %xmm1, 240(%rdi)
+       add $0x10, %rdi
+       lea 240-16(%rcx), %rsi
+.align 4
+.Ldec_key_loop:
+       movaps (%rdi), %xmm0
+       # aesimc %xmm0, %xmm1
+       .byte 0x66, 0x0f, 0x38, 0xdb, 0xc8
+       movaps %xmm1, (%rsi)
+       add $0x10, %rdi
+       sub $0x10, %rsi
+       cmp %rcx, %rdi
+       jb .Ldec_key_loop
+       xor %rax, %rax
+       ret
+
+/*
+ * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
+ */
+ENTRY(aesni_enc)
+       movl 480(KEYP), KLEN            # key length
+       movups (INP), STATE             # input
+       call _aesni_enc1
+       movups STATE, (OUTP)            # output
+       ret
+
+/*
+ * _aesni_enc1:                internal ABI
+ * input:
+ *     KEYP:           key struct pointer
+ *     KLEN:           round count
+ *     STATE:          initial state (input)
+ * output:
+ *     STATE:          finial state (output)
+ * changed:
+ *     KEY
+ *     TKEYP (T1)
+ */
+_aesni_enc1:
+       movaps (KEYP), KEY              # key
+       mov KEYP, TKEYP
+       pxor KEY, STATE         # round 0
+       add $0x30, TKEYP
+       cmp $24, KLEN
+       jb .Lenc128
+       lea 0x20(TKEYP), TKEYP
+       je .Lenc192
+       add $0x20, TKEYP
+       movaps -0x60(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps -0x50(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+.align 4
+.Lenc192:
+       movaps -0x40(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps -0x30(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+.align 4
+.Lenc128:
+       movaps -0x20(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps -0x10(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps (TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps 0x10(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps 0x20(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps 0x30(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps 0x40(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps 0x50(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps 0x60(TKEYP), KEY
+       # aesenc KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       movaps 0x70(TKEYP), KEY
+       # aesenclast KEY, STATE # last round
+       .byte 0x66, 0x0f, 0x38, 0xdd, 0xc2
+       ret
+
+/*
+ * _aesni_enc4:        internal ABI
+ * input:
+ *     KEYP:           key struct pointer
+ *     KLEN:           round count
+ *     STATE1:         initial state (input)
+ *     STATE2
+ *     STATE3
+ *     STATE4
+ * output:
+ *     STATE1:         finial state (output)
+ *     STATE2
+ *     STATE3
+ *     STATE4
+ * changed:
+ *     KEY
+ *     TKEYP (T1)
+ */
+_aesni_enc4:
+       movaps (KEYP), KEY              # key
+       mov KEYP, TKEYP
+       pxor KEY, STATE1                # round 0
+       pxor KEY, STATE2
+       pxor KEY, STATE3
+       pxor KEY, STATE4
+       add $0x30, TKEYP
+       cmp $24, KLEN
+       jb .L4enc128
+       lea 0x20(TKEYP), TKEYP
+       je .L4enc192
+       add $0x20, TKEYP
+       movaps -0x60(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps -0x50(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+#.align 4
+.L4enc192:
+       movaps -0x40(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps -0x30(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+#.align 4
+.L4enc128:
+       movaps -0x20(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps -0x10(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps (TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps 0x10(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps 0x20(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps 0x30(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps 0x40(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps 0x50(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps 0x60(TKEYP), KEY
+       # aesenc KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
+       # aesenc KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
+       # aesenc KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
+       # aesenc KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
+       movaps 0x70(TKEYP), KEY
+       # aesenclast KEY, STATE1        # last round
+       .byte 0x66, 0x0f, 0x38, 0xdd, 0xc2
+       # aesenclast KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdd, 0xe2
+       # aesenclast KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdd, 0xea
+       # aesenclast KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdd, 0xf2
+       ret
+
+/*
+ * void aesni_dec (struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
+ */
+ENTRY(aesni_dec)
+       mov 480(KEYP), KLEN             # key length
+       add $240, KEYP
+       movups (INP), STATE             # input
+       call _aesni_dec1
+       movups STATE, (OUTP)            #output
+       ret
+
+/*
+ * _aesni_dec1:                internal ABI
+ * input:
+ *     KEYP:           key struct pointer
+ *     KLEN:           key length
+ *     STATE:          initial state (input)
+ * output:
+ *     STATE:          finial state (output)
+ * changed:
+ *     KEY
+ *     TKEYP (T1)
+ */
+_aesni_dec1:
+       movaps (KEYP), KEY              # key
+       mov KEYP, TKEYP
+       pxor KEY, STATE         # round 0
+       add $0x30, TKEYP
+       cmp $24, KLEN
+       jb .Ldec128
+       lea 0x20(TKEYP), TKEYP
+       je .Ldec192
+       add $0x20, TKEYP
+       movaps -0x60(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps -0x50(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+.align 4
+.Ldec192:
+       movaps -0x40(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps -0x30(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+.align 4
+.Ldec128:
+       movaps -0x20(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps -0x10(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps (TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps 0x10(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps 0x20(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps 0x30(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps 0x40(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps 0x50(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps 0x60(TKEYP), KEY
+       # aesdec KEY, STATE
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       movaps 0x70(TKEYP), KEY
+       # aesdeclast KEY, STATE         # last round
+       .byte 0x66, 0x0f, 0x38, 0xdf, 0xc2
+       ret
+
+/*
+ * _aesni_dec4:        internal ABI
+ * input:
+ *     KEYP:           key struct pointer
+ *     KLEN:           key length
+ *     STATE1:         initial state (input)
+ *     STATE2
+ *     STATE3
+ *     STATE4
+ * output:
+ *     STATE1:         finial state (output)
+ *     STATE2
+ *     STATE3
+ *     STATE4
+ * changed:
+ *     KEY
+ *     TKEYP (T1)
+ */
+_aesni_dec4:
+       movaps (KEYP), KEY              # key
+       mov KEYP, TKEYP
+       pxor KEY, STATE1                # round 0
+       pxor KEY, STATE2
+       pxor KEY, STATE3
+       pxor KEY, STATE4
+       add $0x30, TKEYP
+       cmp $24, KLEN
+       jb .L4dec128
+       lea 0x20(TKEYP), TKEYP
+       je .L4dec192
+       add $0x20, TKEYP
+       movaps -0x60(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps -0x50(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+.align 4
+.L4dec192:
+       movaps -0x40(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps -0x30(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+.align 4
+.L4dec128:
+       movaps -0x20(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps -0x10(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps (TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps 0x10(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps 0x20(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps 0x30(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps 0x40(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps 0x50(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps 0x60(TKEYP), KEY
+       # aesdec KEY, STATE1
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
+       # aesdec KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
+       # aesdec KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xea
+       # aesdec KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
+       movaps 0x70(TKEYP), KEY
+       # aesdeclast KEY, STATE1        # last round
+       .byte 0x66, 0x0f, 0x38, 0xdf, 0xc2
+       # aesdeclast KEY, STATE2
+       .byte 0x66, 0x0f, 0x38, 0xdf, 0xe2
+       # aesdeclast KEY, STATE3
+       .byte 0x66, 0x0f, 0x38, 0xdf, 0xea
+       # aesdeclast KEY, STATE4
+       .byte 0x66, 0x0f, 0x38, 0xdf, 0xf2
+       ret
+
+/*
+ * void aesni_ecb_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
+ *                   size_t len)
+ */
+ENTRY(aesni_ecb_enc)
+       test LEN, LEN           # check length
+       jz .Lecb_enc_ret
+       mov 480(KEYP), KLEN
+       cmp $16, LEN
+       jb .Lecb_enc_ret
+       cmp $64, LEN
+       jb .Lecb_enc_loop1
+.align 4
+.Lecb_enc_loop4:
+       movups (INP), STATE1
+       movups 0x10(INP), STATE2
+       movups 0x20(INP), STATE3
+       movups 0x30(INP), STATE4
+       call _aesni_enc4
+       movups STATE1, (OUTP)
+       movups STATE2, 0x10(OUTP)
+       movups STATE3, 0x20(OUTP)
+       movups STATE4, 0x30(OUTP)
+       sub $64, LEN
+       add $64, INP
+       add $64, OUTP
+       cmp $64, LEN
+       jge .Lecb_enc_loop4
+       cmp $16, LEN
+       jb .Lecb_enc_ret
+.align 4
+.Lecb_enc_loop1:
+       movups (INP), STATE1
+       call _aesni_enc1
+       movups STATE1, (OUTP)
+       sub $16, LEN
+       add $16, INP
+       add $16, OUTP
+       cmp $16, LEN
+       jge .Lecb_enc_loop1
+.Lecb_enc_ret:
+       ret
+
+/*
+ * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
+ *                   size_t len);
+ */
+ENTRY(aesni_ecb_dec)
+       test LEN, LEN
+       jz .Lecb_dec_ret
+       mov 480(KEYP), KLEN
+       add $240, KEYP
+       cmp $16, LEN
+       jb .Lecb_dec_ret
+       cmp $64, LEN
+       jb .Lecb_dec_loop1
+.align 4
+.Lecb_dec_loop4:
+       movups (INP), STATE1
+       movups 0x10(INP), STATE2
+       movups 0x20(INP), STATE3
+       movups 0x30(INP), STATE4
+       call _aesni_dec4
+       movups STATE1, (OUTP)
+       movups STATE2, 0x10(OUTP)
+       movups STATE3, 0x20(OUTP)
+       movups STATE4, 0x30(OUTP)
+       sub $64, LEN
+       add $64, INP
+       add $64, OUTP
+       cmp $64, LEN
+       jge .Lecb_dec_loop4
+       cmp $16, LEN
+       jb .Lecb_dec_ret
+.align 4
+.Lecb_dec_loop1:
+       movups (INP), STATE1
+       call _aesni_dec1
+       movups STATE1, (OUTP)
+       sub $16, LEN
+       add $16, INP
+       add $16, OUTP
+       cmp $16, LEN
+       jge .Lecb_dec_loop1
+.Lecb_dec_ret:
+       ret
+
+/*
+ * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
+ *                   size_t len, u8 *iv)
+ */
+ENTRY(aesni_cbc_enc)
+       cmp $16, LEN
+       jb .Lcbc_enc_ret
+       mov 480(KEYP), KLEN
+       movups (IVP), STATE     # load iv as initial state
+.align 4
+.Lcbc_enc_loop:
+       movups (INP), IN        # load input
+       pxor IN, STATE
+       call _aesni_enc1
+       movups STATE, (OUTP)    # store output
+       sub $16, LEN
+       add $16, INP
+       add $16, OUTP
+       cmp $16, LEN
+       jge .Lcbc_enc_loop
+       movups STATE, (IVP)
+.Lcbc_enc_ret:
+       ret
+
+/*
+ * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
+ *                   size_t len, u8 *iv)
+ */
+ENTRY(aesni_cbc_dec)
+       cmp $16, LEN
+       jb .Lcbc_dec_ret
+       mov 480(KEYP), KLEN
+       add $240, KEYP
+       movups (IVP), IV
+       cmp $64, LEN
+       jb .Lcbc_dec_loop1
+.align 4
+.Lcbc_dec_loop4:
+       movups (INP), IN1
+       movaps IN1, STATE1
+       movups 0x10(INP), IN2
+       movaps IN2, STATE2
+       movups 0x20(INP), IN3
+       movaps IN3, STATE3
+       movups 0x30(INP), IN4
+       movaps IN4, STATE4
+       call _aesni_dec4
+       pxor IV, STATE1
+       pxor IN1, STATE2
+       pxor IN2, STATE3
+       pxor IN3, STATE4
+       movaps IN4, IV
+       movups STATE1, (OUTP)
+       movups STATE2, 0x10(OUTP)
+       movups STATE3, 0x20(OUTP)
+       movups STATE4, 0x30(OUTP)
+       sub $64, LEN
+       add $64, INP
+       add $64, OUTP
+       cmp $64, LEN
+       jge .Lcbc_dec_loop4
+       cmp $16, LEN
+       jb .Lcbc_dec_ret
+.align 4
+.Lcbc_dec_loop1:
+       movups (INP), IN
+       movaps IN, STATE
+       call _aesni_dec1
+       pxor IV, STATE
+       movups STATE, (OUTP)
+       movaps IN, IV
+       sub $16, LEN
+       add $16, INP
+       add $16, OUTP
+       cmp $16, LEN
+       jge .Lcbc_dec_loop1
+       movups IV, (IVP)
+.Lcbc_dec_ret:
+       ret
diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
new file mode 100644 (file)
index 0000000..02af0af
--- /dev/null
@@ -0,0 +1,461 @@
+/*
+ * Support for Intel AES-NI instructions. This file contains glue
+ * code, the real AES implementation is in intel-aes_asm.S.
+ *
+ * Copyright (C) 2008, Intel Corp.
+ *    Author: Huang Ying <ying.huang@intel.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/hardirq.h>
+#include <linux/types.h>
+#include <linux/crypto.h>
+#include <linux/err.h>
+#include <crypto/algapi.h>
+#include <crypto/aes.h>
+#include <crypto/cryptd.h>
+#include <asm/i387.h>
+#include <asm/aes.h>
+
+struct async_aes_ctx {
+       struct cryptd_ablkcipher *cryptd_tfm;
+};
+
+#define AESNI_ALIGN    16
+#define AES_BLOCK_MASK (~(AES_BLOCK_SIZE-1))
+
+asmlinkage int aesni_set_key(struct crypto_aes_ctx *ctx, const u8 *in_key,
+                            unsigned int key_len);
+asmlinkage void aesni_enc(struct crypto_aes_ctx *ctx, u8 *out,
+                         const u8 *in);
+asmlinkage void aesni_dec(struct crypto_aes_ctx *ctx, u8 *out,
+                         const u8 *in);
+asmlinkage void aesni_ecb_enc(struct crypto_aes_ctx *ctx, u8 *out,
+                             const u8 *in, unsigned int len);
+asmlinkage void aesni_ecb_dec(struct crypto_aes_ctx *ctx, u8 *out,
+                             const u8 *in, unsigned int len);
+asmlinkage void aesni_cbc_enc(struct crypto_aes_ctx *ctx, u8 *out,
+                             const u8 *in, unsigned int len, u8 *iv);
+asmlinkage void aesni_cbc_dec(struct crypto_aes_ctx *ctx, u8 *out,
+                             const u8 *in, unsigned int len, u8 *iv);
+
+static inline int kernel_fpu_using(void)
+{
+       if (in_interrupt() && !(read_cr0() & X86_CR0_TS))
+               return 1;
+       return 0;
+}
+
+static inline struct crypto_aes_ctx *aes_ctx(void *raw_ctx)
+{
+       unsigned long addr = (unsigned long)raw_ctx;
+       unsigned long align = AESNI_ALIGN;
+
+       if (align <= crypto_tfm_ctx_alignment())
+               align = 1;
+       return (struct crypto_aes_ctx *)ALIGN(addr, align);
+}
+
+static int aes_set_key_common(struct crypto_tfm *tfm, void *raw_ctx,
+                             const u8 *in_key, unsigned int key_len)
+{
+       struct crypto_aes_ctx *ctx = aes_ctx(raw_ctx);
+       u32 *flags = &tfm->crt_flags;
+       int err;
+
+       if (key_len != AES_KEYSIZE_128 && key_len != AES_KEYSIZE_192 &&
+           key_len != AES_KEYSIZE_256) {
+               *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
+               return -EINVAL;
+       }
+
+       if (kernel_fpu_using())
+               err = crypto_aes_expand_key(ctx, in_key, key_len);
+       else {
+               kernel_fpu_begin();
+               err = aesni_set_key(ctx, in_key, key_len);
+               kernel_fpu_end();
+       }
+
+       return err;
+}
+
+static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
+                      unsigned int key_len)
+{
+       return aes_set_key_common(tfm, crypto_tfm_ctx(tfm), in_key, key_len);
+}
+
+static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+{
+       struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm));
+
+       if (kernel_fpu_using())
+               crypto_aes_encrypt_x86(ctx, dst, src);
+       else {
+               kernel_fpu_begin();
+               aesni_enc(ctx, dst, src);
+               kernel_fpu_end();
+       }
+}
+
+static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+{
+       struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm));
+
+       if (kernel_fpu_using())
+               crypto_aes_decrypt_x86(ctx, dst, src);
+       else {
+               kernel_fpu_begin();
+               aesni_dec(ctx, dst, src);
+               kernel_fpu_end();
+       }
+}
+
+static struct crypto_alg aesni_alg = {
+       .cra_name               = "aes",
+       .cra_driver_name        = "aes-aesni",
+       .cra_priority           = 300,
+       .cra_flags              = CRYPTO_ALG_TYPE_CIPHER,
+       .cra_blocksize          = AES_BLOCK_SIZE,
+       .cra_ctxsize            = sizeof(struct crypto_aes_ctx)+AESNI_ALIGN-1,
+       .cra_alignmask          = 0,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(aesni_alg.cra_list),
+       .cra_u  = {
+               .cipher = {
+                       .cia_min_keysize        = AES_MIN_KEY_SIZE,
+                       .cia_max_keysize        = AES_MAX_KEY_SIZE,
+                       .cia_setkey             = aes_set_key,
+                       .cia_encrypt            = aes_encrypt,
+                       .cia_decrypt            = aes_decrypt
+               }
+       }
+};
+
+static int ecb_encrypt(struct blkcipher_desc *desc,
+                      struct scatterlist *dst, struct scatterlist *src,
+                      unsigned int nbytes)
+{
+       struct crypto_aes_ctx *ctx = aes_ctx(crypto_blkcipher_ctx(desc->tfm));
+       struct blkcipher_walk walk;
+       int err;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       err = blkcipher_walk_virt(desc, &walk);
+
+       kernel_fpu_begin();
+       while ((nbytes = walk.nbytes)) {
+               aesni_ecb_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
+                             nbytes & AES_BLOCK_MASK);
+               nbytes &= AES_BLOCK_SIZE - 1;
+               err = blkcipher_walk_done(desc, &walk, nbytes);
+       }
+       kernel_fpu_end();
+
+       return err;
+}
+
+static int ecb_decrypt(struct blkcipher_desc *desc,
+                      struct scatterlist *dst, struct scatterlist *src,
+                      unsigned int nbytes)
+{
+       struct crypto_aes_ctx *ctx = aes_ctx(crypto_blkcipher_ctx(desc->tfm));
+       struct blkcipher_walk walk;
+       int err;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       err = blkcipher_walk_virt(desc, &walk);
+
+       kernel_fpu_begin();
+       while ((nbytes = walk.nbytes)) {
+               aesni_ecb_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
+                             nbytes & AES_BLOCK_MASK);
+               nbytes &= AES_BLOCK_SIZE - 1;
+               err = blkcipher_walk_done(desc, &walk, nbytes);
+       }
+       kernel_fpu_end();
+
+       return err;
+}
+
+static struct crypto_alg blk_ecb_alg = {
+       .cra_name               = "__ecb-aes-aesni",
+       .cra_driver_name        = "__driver-ecb-aes-aesni",
+       .cra_priority           = 0,
+       .cra_flags              = CRYPTO_ALG_TYPE_BLKCIPHER,
+       .cra_blocksize          = AES_BLOCK_SIZE,
+       .cra_ctxsize            = sizeof(struct crypto_aes_ctx)+AESNI_ALIGN-1,
+       .cra_alignmask          = 0,
+       .cra_type               = &crypto_blkcipher_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(blk_ecb_alg.cra_list),
+       .cra_u = {
+               .blkcipher = {
+                       .min_keysize    = AES_MIN_KEY_SIZE,
+                       .max_keysize    = AES_MAX_KEY_SIZE,
+                       .setkey         = aes_set_key,
+                       .encrypt        = ecb_encrypt,
+                       .decrypt        = ecb_decrypt,
+               },
+       },
+};
+
+static int cbc_encrypt(struct blkcipher_desc *desc,
+                      struct scatterlist *dst, struct scatterlist *src,
+                      unsigned int nbytes)
+{
+       struct crypto_aes_ctx *ctx = aes_ctx(crypto_blkcipher_ctx(desc->tfm));
+       struct blkcipher_walk walk;
+       int err;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       err = blkcipher_walk_virt(desc, &walk);
+
+       kernel_fpu_begin();
+       while ((nbytes = walk.nbytes)) {
+               aesni_cbc_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
+                             nbytes & AES_BLOCK_MASK, walk.iv);
+               nbytes &= AES_BLOCK_SIZE - 1;
+               err = blkcipher_walk_done(desc, &walk, nbytes);
+       }
+       kernel_fpu_end();
+
+       return err;
+}
+
+static int cbc_decrypt(struct blkcipher_desc *desc,
+                      struct scatterlist *dst, struct scatterlist *src,
+                      unsigned int nbytes)
+{
+       struct crypto_aes_ctx *ctx = aes_ctx(crypto_blkcipher_ctx(desc->tfm));
+       struct blkcipher_walk walk;
+       int err;
+
+       blkcipher_walk_init(&walk, dst, src, nbytes);
+       err = blkcipher_walk_virt(desc, &walk);
+
+       kernel_fpu_begin();
+       while ((nbytes = walk.nbytes)) {
+               aesni_cbc_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
+                             nbytes & AES_BLOCK_MASK, walk.iv);
+               nbytes &= AES_BLOCK_SIZE - 1;
+               err = blkcipher_walk_done(desc, &walk, nbytes);
+       }
+       kernel_fpu_end();
+
+       return err;
+}
+
+static struct crypto_alg blk_cbc_alg = {
+       .cra_name               = "__cbc-aes-aesni",
+       .cra_driver_name        = "__driver-cbc-aes-aesni",
+       .cra_priority           = 0,
+       .cra_flags              = CRYPTO_ALG_TYPE_BLKCIPHER,
+       .cra_blocksize          = AES_BLOCK_SIZE,
+       .cra_ctxsize            = sizeof(struct crypto_aes_ctx)+AESNI_ALIGN-1,
+       .cra_alignmask          = 0,
+       .cra_type               = &crypto_blkcipher_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(blk_cbc_alg.cra_list),
+       .cra_u = {
+               .blkcipher = {
+                       .min_keysize    = AES_MIN_KEY_SIZE,
+                       .max_keysize    = AES_MAX_KEY_SIZE,
+                       .setkey         = aes_set_key,
+                       .encrypt        = cbc_encrypt,
+                       .decrypt        = cbc_decrypt,
+               },
+       },
+};
+
+static int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key,
+                       unsigned int key_len)
+{
+       struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+
+       return crypto_ablkcipher_setkey(&ctx->cryptd_tfm->base, key, key_len);
+}
+
+static int ablk_encrypt(struct ablkcipher_request *req)
+{
+       struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+       struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+
+       if (kernel_fpu_using()) {
+               struct ablkcipher_request *cryptd_req =
+                       ablkcipher_request_ctx(req);
+               memcpy(cryptd_req, req, sizeof(*req));
+               ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
+               return crypto_ablkcipher_encrypt(cryptd_req);
+       } else {
+               struct blkcipher_desc desc;
+               desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
+               desc.info = req->info;
+               desc.flags = 0;
+               return crypto_blkcipher_crt(desc.tfm)->encrypt(
+                       &desc, req->dst, req->src, req->nbytes);
+       }
+}
+
+static int ablk_decrypt(struct ablkcipher_request *req)
+{
+       struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+       struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+
+       if (kernel_fpu_using()) {
+               struct ablkcipher_request *cryptd_req =
+                       ablkcipher_request_ctx(req);
+               memcpy(cryptd_req, req, sizeof(*req));
+               ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
+               return crypto_ablkcipher_decrypt(cryptd_req);
+       } else {
+               struct blkcipher_desc desc;
+               desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
+               desc.info = req->info;
+               desc.flags = 0;
+               return crypto_blkcipher_crt(desc.tfm)->decrypt(
+                       &desc, req->dst, req->src, req->nbytes);
+       }
+}
+
+static void ablk_exit(struct crypto_tfm *tfm)
+{
+       struct async_aes_ctx *ctx = crypto_tfm_ctx(tfm);
+
+       cryptd_free_ablkcipher(ctx->cryptd_tfm);
+}
+
+static void ablk_init_common(struct crypto_tfm *tfm,
+                            struct cryptd_ablkcipher *cryptd_tfm)
+{
+       struct async_aes_ctx *ctx = crypto_tfm_ctx(tfm);
+
+       ctx->cryptd_tfm = cryptd_tfm;
+       tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request) +
+               crypto_ablkcipher_reqsize(&cryptd_tfm->base);
+}
+
+static int ablk_ecb_init(struct crypto_tfm *tfm)
+{
+       struct cryptd_ablkcipher *cryptd_tfm;
+
+       cryptd_tfm = cryptd_alloc_ablkcipher("__driver-ecb-aes-aesni", 0, 0);
+       if (IS_ERR(cryptd_tfm))
+               return PTR_ERR(cryptd_tfm);
+       ablk_init_common(tfm, cryptd_tfm);
+       return 0;
+}
+
+static struct crypto_alg ablk_ecb_alg = {
+       .cra_name               = "ecb(aes)",
+       .cra_driver_name        = "ecb-aes-aesni",
+       .cra_priority           = 400,
+       .cra_flags              = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
+       .cra_blocksize          = AES_BLOCK_SIZE,
+       .cra_ctxsize            = sizeof(struct async_aes_ctx),
+       .cra_alignmask          = 0,
+       .cra_type               = &crypto_ablkcipher_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(ablk_ecb_alg.cra_list),
+       .cra_init               = ablk_ecb_init,
+       .cra_exit               = ablk_exit,
+       .cra_u = {
+               .ablkcipher = {
+                       .min_keysize    = AES_MIN_KEY_SIZE,
+                       .max_keysize    = AES_MAX_KEY_SIZE,
+                       .setkey         = ablk_set_key,
+                       .encrypt        = ablk_encrypt,
+                       .decrypt        = ablk_decrypt,
+               },
+       },
+};
+
+static int ablk_cbc_init(struct crypto_tfm *tfm)
+{
+       struct cryptd_ablkcipher *cryptd_tfm;
+
+       cryptd_tfm = cryptd_alloc_ablkcipher("__driver-cbc-aes-aesni", 0, 0);
+       if (IS_ERR(cryptd_tfm))
+               return PTR_ERR(cryptd_tfm);
+       ablk_init_common(tfm, cryptd_tfm);
+       return 0;
+}
+
+static struct crypto_alg ablk_cbc_alg = {
+       .cra_name               = "cbc(aes)",
+       .cra_driver_name        = "cbc-aes-aesni",
+       .cra_priority           = 400,
+       .cra_flags              = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
+       .cra_blocksize          = AES_BLOCK_SIZE,
+       .cra_ctxsize            = sizeof(struct async_aes_ctx),
+       .cra_alignmask          = 0,
+       .cra_type               = &crypto_ablkcipher_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(ablk_cbc_alg.cra_list),
+       .cra_init               = ablk_cbc_init,
+       .cra_exit               = ablk_exit,
+       .cra_u = {
+               .ablkcipher = {
+                       .min_keysize    = AES_MIN_KEY_SIZE,
+                       .max_keysize    = AES_MAX_KEY_SIZE,
+                       .ivsize         = AES_BLOCK_SIZE,
+                       .setkey         = ablk_set_key,
+                       .encrypt        = ablk_encrypt,
+                       .decrypt        = ablk_decrypt,
+               },
+       },
+};
+
+static int __init aesni_init(void)
+{
+       int err;
+
+       if (!cpu_has_aes) {
+               printk(KERN_ERR "Intel AES-NI instructions are not detected.\n");
+               return -ENODEV;
+       }
+       if ((err = crypto_register_alg(&aesni_alg)))
+               goto aes_err;
+       if ((err = crypto_register_alg(&blk_ecb_alg)))
+               goto blk_ecb_err;
+       if ((err = crypto_register_alg(&blk_cbc_alg)))
+               goto blk_cbc_err;
+       if ((err = crypto_register_alg(&ablk_ecb_alg)))
+               goto ablk_ecb_err;
+       if ((err = crypto_register_alg(&ablk_cbc_alg)))
+               goto ablk_cbc_err;
+
+       return err;
+
+ablk_cbc_err:
+       crypto_unregister_alg(&ablk_ecb_alg);
+ablk_ecb_err:
+       crypto_unregister_alg(&blk_cbc_alg);
+blk_cbc_err:
+       crypto_unregister_alg(&blk_ecb_alg);
+blk_ecb_err:
+       crypto_unregister_alg(&aesni_alg);
+aes_err:
+       return err;
+}
+
+static void __exit aesni_exit(void)
+{
+       crypto_unregister_alg(&ablk_cbc_alg);
+       crypto_unregister_alg(&ablk_ecb_alg);
+       crypto_unregister_alg(&blk_cbc_alg);
+       crypto_unregister_alg(&blk_ecb_alg);
+       crypto_unregister_alg(&aesni_alg);
+}
+
+module_init(aesni_init);
+module_exit(aesni_exit);
+
+MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm, Intel AES-NI instructions optimized");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("aes");
diff --git a/arch/x86/include/asm/aes.h b/arch/x86/include/asm/aes.h
new file mode 100644 (file)
index 0000000..80545a1
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef ASM_X86_AES_H
+#define ASM_X86_AES_H
+
+#include <linux/crypto.h>
+#include <crypto/aes.h>
+
+void crypto_aes_encrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst,
+                           const u8 *src);
+void crypto_aes_decrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst,
+                           const u8 *src);
+#endif
index 7301e60dc4a83c56e28b6e8867ab6a15419347bf..0beba0d1468db24bceaa1e81cdf8c652eb5180ee 100644 (file)
@@ -213,6 +213,7 @@ extern const char * const x86_power_flags[32];
 #define cpu_has_xmm            boot_cpu_has(X86_FEATURE_XMM)
 #define cpu_has_xmm2           boot_cpu_has(X86_FEATURE_XMM2)
 #define cpu_has_xmm3           boot_cpu_has(X86_FEATURE_XMM3)
+#define cpu_has_aes            boot_cpu_has(X86_FEATURE_AES)
 #define cpu_has_ht             boot_cpu_has(X86_FEATURE_HT)
 #define cpu_has_mp             boot_cpu_has(X86_FEATURE_MP)
 #define cpu_has_nx             boot_cpu_has(X86_FEATURE_NX)
index 2bb6a835c453c0ced2d9b7e78e998e7fde5d8c3e..4f5c247248567708f0b4b599c8b618b12ddb458d 100644 (file)
@@ -11,8 +11,8 @@ unsigned long native_calibrate_tsc(void);
 
 #ifdef CONFIG_X86_32
 extern int timer_ack;
+#endif
 extern int recalibrate_cpu_khz(void);
-#endif /* CONFIG_X86_32 */
 
 extern int no_timer_check;
 
index 65792c2cc4625f7c44337ddb043bbcd92090aee5..52c839875478571711df3d861ffc1a3d4c5eb413 100644 (file)
@@ -87,30 +87,15 @@ config X86_POWERNOW_K7_ACPI
 config X86_POWERNOW_K8
        tristate "AMD Opteron/Athlon64 PowerNow!"
        select CPU_FREQ_TABLE
+       depends on ACPI && ACPI_PROCESSOR
        help
-         This adds the CPUFreq driver for mobile AMD Opteron/Athlon64 processors.
+         This adds the CPUFreq driver for K8/K10 Opteron/Athlon64 processors.
 
          To compile this driver as a module, choose M here: the
          module will be called powernow-k8.
 
          For details, take a look at <file:Documentation/cpu-freq/>.
 
-         If in doubt, say N.
-
-config X86_POWERNOW_K8_ACPI
-       bool
-       prompt "ACPI Support" if X86_32
-       depends on ACPI && X86_POWERNOW_K8 && ACPI_PROCESSOR
-       depends on !(X86_POWERNOW_K8 = y && ACPI_PROCESSOR = m)
-       default y
-       help
-         This provides access to the K8s Processor Performance States via ACPI.
-         This driver is probably required for CPUFreq to work with multi-socket and
-         SMP systems.  It is not required on at least some single-socket yet
-         multi-core systems, even if SMP is enabled.
-
-         It is safe to say Y here.
-
 config X86_GX_SUSPMOD
        tristate "Cyrix MediaGX/NatSemi Geode Suspend Modulation"
        depends on X86_32 && PCI
index 560f7760dae5c3dd18fa4b85845531bca0d30db4..509296df294d9432ed6459f8c6b3cccbbb04e1ef 100644 (file)
@@ -1,6 +1,11 @@
+# Link order matters. K8 is preferred to ACPI because of firmware bugs in early
+# K8 systems. ACPI is preferred to all other hardware-specific drivers.
+# speedstep-* is preferred over p4-clockmod.
+
+obj-$(CONFIG_X86_POWERNOW_K8)          += powernow-k8.o
+obj-$(CONFIG_X86_ACPI_CPUFREQ)         += acpi-cpufreq.o
 obj-$(CONFIG_X86_POWERNOW_K6)          += powernow-k6.o
 obj-$(CONFIG_X86_POWERNOW_K7)          += powernow-k7.o
-obj-$(CONFIG_X86_POWERNOW_K8)          += powernow-k8.o
 obj-$(CONFIG_X86_LONGHAUL)             += longhaul.o
 obj-$(CONFIG_X86_E_POWERSAVER)         += e_powersaver.o
 obj-$(CONFIG_ELAN_CPUFREQ)             += elanfreq.o
@@ -10,7 +15,6 @@ obj-$(CONFIG_X86_GX_SUSPMOD)          += gx-suspmod.o
 obj-$(CONFIG_X86_SPEEDSTEP_ICH)                += speedstep-ich.o
 obj-$(CONFIG_X86_SPEEDSTEP_LIB)                += speedstep-lib.o
 obj-$(CONFIG_X86_SPEEDSTEP_SMI)                += speedstep-smi.o
-obj-$(CONFIG_X86_ACPI_CPUFREQ)         += acpi-cpufreq.o
 obj-$(CONFIG_X86_SPEEDSTEP_CENTRINO)   += speedstep-centrino.o
 obj-$(CONFIG_X86_P4_CLOCKMOD)          += p4-clockmod.o
 obj-$(CONFIG_X86_CPUFREQ_NFORCE2)      += cpufreq-nforce2.o
index 4b1c319d30c368592e990663fb1c8efd5abea963..3babe1f1e912eba061378087b5d4211022e4f772 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * acpi-cpufreq.c - ACPI Processor P-States Driver ($Revision: 1.4 $)
+ * acpi-cpufreq.c - ACPI Processor P-States Driver
  *
  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
 #include <linux/ftrace.h>
 
 #include <linux/acpi.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
+
 #include <acpi/processor.h>
 
-#include <asm/io.h>
 #include <asm/msr.h>
 #include <asm/processor.h>
 #include <asm/cpufeature.h>
-#include <asm/delay.h>
-#include <asm/uaccess.h>
 
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "acpi-cpufreq", msg)
+#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
+               "acpi-cpufreq", msg)
 
 MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski");
 MODULE_DESCRIPTION("ACPI Processor P-States Driver");
@@ -95,7 +97,7 @@ static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data)
 
        perf = data->acpi_data;
 
-       for (i=0; i<perf->state_count; i++) {
+       for (i = 0; i < perf->state_count; i++) {
                if (value == perf->states[i].status)
                        return data->freq_table[i].frequency;
        }
@@ -110,7 +112,7 @@ static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data)
        msr &= INTEL_MSR_RANGE;
        perf = data->acpi_data;
 
-       for (i=0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
+       for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
                if (msr == perf->states[data->freq_table[i].index].status)
                        return data->freq_table[i].frequency;
        }
@@ -138,15 +140,13 @@ struct io_addr {
        u8 bit_width;
 };
 
-typedef union {
-       struct msr_addr msr;
-       struct io_addr io;
-} drv_addr_union;
-
 struct drv_cmd {
        unsigned int type;
        const struct cpumask *mask;
-       drv_addr_union addr;
+       union {
+               struct msr_addr msr;
+               struct io_addr io;
+       } addr;
        u32 val;
 };
 
@@ -369,7 +369,7 @@ static unsigned int check_freqs(const struct cpumask *mask, unsigned int freq,
        unsigned int cur_freq;
        unsigned int i;
 
-       for (i=0; i<100; i++) {
+       for (i = 0; i < 100; i++) {
                cur_freq = extract_freq(get_cur_val(mask), data);
                if (cur_freq == freq)
                        return 1;
@@ -494,7 +494,7 @@ acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu)
                unsigned long freq;
                unsigned long freqn = perf->states[0].core_frequency * 1000;
 
-               for (i=0; i<(perf->state_count-1); i++) {
+               for (i = 0; i < (perf->state_count-1); i++) {
                        freq = freqn;
                        freqn = perf->states[i+1].core_frequency * 1000;
                        if ((2 * cpu_khz) > (freqn + freq)) {
@@ -673,7 +673,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 
        /* detect transition latency */
        policy->cpuinfo.transition_latency = 0;
-       for (i=0; i<perf->state_count; i++) {
+       for (i = 0; i < perf->state_count; i++) {
                if ((perf->states[i].transition_latency * 1000) >
                    policy->cpuinfo.transition_latency)
                        policy->cpuinfo.transition_latency =
@@ -682,8 +682,8 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 
        data->max_freq = perf->states[0].core_frequency * 1000;
        /* table init */
-       for (i=0; i<perf->state_count; i++) {
-               if (i>0 && perf->states[i].core_frequency >=
+       for (i = 0; i < perf->state_count; i++) {
+               if (i > 0 && perf->states[i].core_frequency >=
                    data->freq_table[valid_states-1].frequency / 1000)
                        continue;
 
index 965ea52767ac65f5059673a3448764103a0e8543..733093d6043698ecba3eca01249b3d301f6008b2 100644 (file)
@@ -32,7 +32,7 @@
  * nforce2_chipset:
  * FSB is changed using the chipset
  */
-static struct pci_dev *nforce2_chipset_dev;
+static struct pci_dev *nforce2_dev;
 
 /* fid:
  * multiplier * 10
@@ -56,7 +56,9 @@ MODULE_PARM_DESC(fid, "CPU multiplier to use (11.5 = 115)");
 MODULE_PARM_DESC(min_fsb,
                "Minimum FSB to use, if not defined: current FSB - 50");
 
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "cpufreq-nforce2", msg)
+#define PFX "cpufreq-nforce2: "
+#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
+               "cpufreq-nforce2", msg)
 
 /**
  * nforce2_calc_fsb - calculate FSB
@@ -118,11 +120,11 @@ static void nforce2_write_pll(int pll)
        int temp;
 
        /* Set the pll addr. to 0x00 */
-       pci_write_config_dword(nforce2_chipset_dev, NFORCE2_PLLADR, 0);
+       pci_write_config_dword(nforce2_dev, NFORCE2_PLLADR, 0);
 
        /* Now write the value in all 64 registers */
        for (temp = 0; temp <= 0x3f; temp++)
-               pci_write_config_dword(nforce2_chipset_dev, NFORCE2_PLLREG, pll);
+               pci_write_config_dword(nforce2_dev, NFORCE2_PLLREG, pll);
 
        return;
 }
@@ -139,8 +141,8 @@ static unsigned int nforce2_fsb_read(int bootfsb)
        u32 fsb, temp = 0;
 
        /* Get chipset boot FSB from subdevice 5 (FSB at boot-time) */
-       nforce2_sub5 = pci_get_subsys(PCI_VENDOR_ID_NVIDIA,
-                                               0x01EF, PCI_ANY_ID, PCI_ANY_ID, NULL);
+       nforce2_sub5 = pci_get_subsys(PCI_VENDOR_ID_NVIDIA, 0x01EF,
+                               PCI_ANY_ID, PCI_ANY_ID, NULL);
        if (!nforce2_sub5)
                return 0;
 
@@ -148,13 +150,13 @@ static unsigned int nforce2_fsb_read(int bootfsb)
        fsb /= 1000000;
 
        /* Check if PLL register is already set */
-       pci_read_config_byte(nforce2_chipset_dev, NFORCE2_PLLENABLE, (u8 *)&temp);
+       pci_read_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8 *)&temp);
 
        if (bootfsb || !temp)
                return fsb;
 
        /* Use PLL register FSB value */
-       pci_read_config_dword(nforce2_chipset_dev, NFORCE2_PLLREG, &temp);
+       pci_read_config_dword(nforce2_dev, NFORCE2_PLLREG, &temp);
        fsb = nforce2_calc_fsb(temp);
 
        return fsb;
@@ -174,18 +176,18 @@ static int nforce2_set_fsb(unsigned int fsb)
        int pll = 0;
 
        if ((fsb > max_fsb) || (fsb < NFORCE2_MIN_FSB)) {
-               printk(KERN_ERR "cpufreq: FSB %d is out of range!\n", fsb);
+               printk(KERN_ERR PFX "FSB %d is out of range!\n", fsb);
                return -EINVAL;
        }
 
        tfsb = nforce2_fsb_read(0);
        if (!tfsb) {
-               printk(KERN_ERR "cpufreq: Error while reading the FSB\n");
+               printk(KERN_ERR PFX "Error while reading the FSB\n");
                return -EINVAL;
        }
 
        /* First write? Then set actual value */
-       pci_read_config_byte(nforce2_chipset_dev, NFORCE2_PLLENABLE, (u8 *)&temp);
+       pci_read_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8 *)&temp);
        if (!temp) {
                pll = nforce2_calc_pll(tfsb);
 
@@ -197,7 +199,7 @@ static int nforce2_set_fsb(unsigned int fsb)
 
        /* Enable write access */
        temp = 0x01;
-       pci_write_config_byte(nforce2_chipset_dev, NFORCE2_PLLENABLE, (u8)temp);
+       pci_write_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8)temp);
 
        diff = tfsb - fsb;
 
@@ -222,7 +224,7 @@ static int nforce2_set_fsb(unsigned int fsb)
        }
 
        temp = 0x40;
-       pci_write_config_byte(nforce2_chipset_dev, NFORCE2_PLLADR, (u8)temp);
+       pci_write_config_byte(nforce2_dev, NFORCE2_PLLADR, (u8)temp);
 
        return 0;
 }
@@ -244,7 +246,8 @@ static unsigned int nforce2_get(unsigned int cpu)
  * nforce2_target - set a new CPUFreq policy
  * @policy: new policy
  * @target_freq: the target frequency
- * @relation: how that frequency relates to achieved frequency (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
+ * @relation: how that frequency relates to achieved frequency
+ *  (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
  *
  * Sets a new CPUFreq policy.
  */
@@ -276,7 +279,7 @@ static int nforce2_target(struct cpufreq_policy *policy,
        /* local_irq_save(flags); */
 
        if (nforce2_set_fsb(target_fsb) < 0)
-               printk(KERN_ERR "cpufreq: Changing FSB to %d failed\n",
+               printk(KERN_ERR PFX "Changing FSB to %d failed\n",
                        target_fsb);
        else
                dprintk("Changed FSB successfully to %d\n",
@@ -327,8 +330,8 @@ static int nforce2_cpu_init(struct cpufreq_policy *policy)
        /* FIX: Get FID from CPU */
        if (!fid) {
                if (!cpu_khz) {
-                       printk(KERN_WARNING
-                              "cpufreq: cpu_khz not set, can't calculate multiplier!\n");
+                       printk(KERN_WARNING PFX
+                       "cpu_khz not set, can't calculate multiplier!\n");
                        return -ENODEV;
                }
 
@@ -343,7 +346,7 @@ static int nforce2_cpu_init(struct cpufreq_policy *policy)
                }
        }
 
-       printk(KERN_INFO "cpufreq: FSB currently at %i MHz, FID %d.%d\n", fsb,
+       printk(KERN_INFO PFX "FSB currently at %i MHz, FID %d.%d\n", fsb,
               fid / 10, fid % 10);
 
        /* Set maximum FSB to FSB at boot time */
@@ -392,17 +395,18 @@ static struct cpufreq_driver nforce2_driver = {
  */
 static unsigned int nforce2_detect_chipset(void)
 {
-       nforce2_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_NVIDIA,
+       nforce2_dev = pci_get_subsys(PCI_VENDOR_ID_NVIDIA,
                                        PCI_DEVICE_ID_NVIDIA_NFORCE2,
                                        PCI_ANY_ID, PCI_ANY_ID, NULL);
 
-       if (nforce2_chipset_dev == NULL)
+       if (nforce2_dev == NULL)
                return -ENODEV;
 
-       printk(KERN_INFO "cpufreq: Detected nForce2 chipset revision %X\n",
-              nforce2_chipset_dev->revision);
-       printk(KERN_INFO
-              "cpufreq: FSB changing is maybe unstable and can lead to crashes and data loss.\n");
+       printk(KERN_INFO PFX "Detected nForce2 chipset revision %X\n",
+              nforce2_dev->revision);
+       printk(KERN_INFO PFX
+              "FSB changing is maybe unstable and can lead to "
+              "crashes and data loss.\n");
 
        return 0;
 }
@@ -420,7 +424,7 @@ static int __init nforce2_init(void)
 
        /* detect chipset */
        if (nforce2_detect_chipset()) {
-               printk(KERN_ERR "cpufreq: No nForce2 chipset.\n");
+               printk(KERN_INFO PFX "No nForce2 chipset.\n");
                return -ENODEV;
        }
 
index c2f930d8664091932c1a7b614d860f8f365b7f10..3f83ea12c47a5972c2a32e3f5750e6d79fa9f105 100644 (file)
 #include <linux/cpufreq.h>
 #include <linux/ioport.h>
 #include <linux/slab.h>
+#include <linux/timex.h>
+#include <linux/io.h>
+#include <linux/delay.h>
 
 #include <asm/msr.h>
 #include <asm/tsc.h>
-#include <asm/timex.h>
-#include <asm/io.h>
-#include <asm/delay.h>
 
 #define EPS_BRAND_C7M  0
 #define EPS_BRAND_C7   1
@@ -184,7 +184,7 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
                break;
        }
 
-       switch(brand) {
+       switch (brand) {
        case EPS_BRAND_C7M:
                printk(KERN_CONT "C7-M\n");
                break;
@@ -218,17 +218,20 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
        /* Print voltage and multiplier */
        rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
        current_voltage = lo & 0xff;
-       printk(KERN_INFO "eps: Current voltage = %dmV\n", current_voltage * 16 + 700);
+       printk(KERN_INFO "eps: Current voltage = %dmV\n",
+                       current_voltage * 16 + 700);
        current_multiplier = (lo >> 8) & 0xff;
        printk(KERN_INFO "eps: Current multiplier = %d\n", current_multiplier);
 
        /* Print limits */
        max_voltage = hi & 0xff;
-       printk(KERN_INFO "eps: Highest voltage = %dmV\n", max_voltage * 16 + 700);
+       printk(KERN_INFO "eps: Highest voltage = %dmV\n",
+                       max_voltage * 16 + 700);
        max_multiplier = (hi >> 8) & 0xff;
        printk(KERN_INFO "eps: Highest multiplier = %d\n", max_multiplier);
        min_voltage = (hi >> 16) & 0xff;
-       printk(KERN_INFO "eps: Lowest voltage = %dmV\n", min_voltage * 16 + 700);
+       printk(KERN_INFO "eps: Lowest voltage = %dmV\n",
+                       min_voltage * 16 + 700);
        min_multiplier = (hi >> 24) & 0xff;
        printk(KERN_INFO "eps: Lowest multiplier = %d\n", min_multiplier);
 
@@ -318,7 +321,7 @@ static int eps_cpu_exit(struct cpufreq_policy *policy)
        return 0;
 }
 
-static struct freq_attreps_attr[] = {
+static struct freq_attr *eps_attr[] = {
        &cpufreq_freq_attr_scaling_available_freqs,
        NULL,
 };
@@ -356,7 +359,7 @@ static void __exit eps_exit(void)
        cpufreq_unregister_driver(&eps_driver);
 }
 
-MODULE_AUTHOR("Rafa³ Bilski <rafalbilski@interia.pl>");
+MODULE_AUTHOR("Rafal Bilski <rafalbilski@interia.pl>");
 MODULE_DESCRIPTION("Enhanced PowerSaver driver for VIA C7 CPU's.");
 MODULE_LICENSE("GPL");
 
index fe613c93b3667d73e78ca6747f691232a9233702..006b278b0d5d973f794e3c0f17a0e9f925369f52 100644 (file)
@@ -184,7 +184,8 @@ static int elanfreq_target(struct cpufreq_policy *policy,
 {
        unsigned int newstate = 0;
 
-       if (cpufreq_frequency_table_target(policy, &elanfreq_table[0], target_freq, relation, &newstate))
+       if (cpufreq_frequency_table_target(policy, &elanfreq_table[0],
+                               target_freq, relation, &newstate))
                return -EINVAL;
 
        elanfreq_set_cpu_state(newstate);
@@ -301,7 +302,8 @@ static void __exit elanfreq_exit(void)
 module_param(max_freq, int, 0444);
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Robert Schwebel <r.schwebel@pengutronix.de>, Sven Geggus <sven@geggus.net>");
+MODULE_AUTHOR("Robert Schwebel <r.schwebel@pengutronix.de>, "
+               "Sven Geggus <sven@geggus.net>");
 MODULE_DESCRIPTION("cpufreq driver for AMD's Elan CPUs");
 
 module_init(elanfreq_init);
index 9d9eae82e60fae3baec7333269ddb6c46b7d1d27..ac27ec2264d50afd3601ae7a5a10caf93bb94858 100644 (file)
@@ -79,8 +79,9 @@
 #include <linux/smp.h>
 #include <linux/cpufreq.h>
 #include <linux/pci.h>
+#include <linux/errno.h>
+
 #include <asm/processor-cyrix.h>
-#include <asm/errno.h>
 
 /* PCI config registers, all at F0 */
 #define PCI_PMER1      0x80    /* power management enable register 1 */
@@ -122,8 +123,8 @@ static struct gxfreq_params *gx_params;
 static int stock_freq;
 
 /* PCI bus clock - defaults to 30.000 if cpu_khz is not available */
-static int pci_busclk = 0;
-module_param (pci_busclk, int, 0444);
+static int pci_busclk;
+module_param(pci_busclk, int, 0444);
 
 /* maximum duration for which the cpu may be suspended
  * (32us * MAX_DURATION). If no parameter is given, this defaults
@@ -132,7 +133,7 @@ module_param (pci_busclk, int, 0444);
  * is suspended -- processing power is just 0.39% of what it used to be,
  * though. 781.25 kHz(!) for a 200 MHz processor -- wow. */
 static int max_duration = 255;
-module_param (max_duration, int, 0444);
+module_param(max_duration, int, 0444);
 
 /* For the default policy, we want at least some processing power
  * - let's say 5%. (min = maxfreq / POLICY_MIN_DIV)
@@ -140,7 +141,8 @@ module_param (max_duration, int, 0444);
 #define POLICY_MIN_DIV 20
 
 
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "gx-suspmod", msg)
+#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
+               "gx-suspmod", msg)
 
 /**
  * we can detect a core multipiler from dir0_lsb
@@ -166,12 +168,20 @@ static int gx_freq_mult[16] = {
  *     Low Level chipset interface                             *
  ****************************************************************/
 static struct pci_device_id gx_chipset_tbl[] __initdata = {
-       { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_LEGACY, PCI_ANY_ID, PCI_ANY_ID },
-       { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520, PCI_ANY_ID, PCI_ANY_ID },
-       { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510, PCI_ANY_ID, PCI_ANY_ID },
+       { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_LEGACY,
+               PCI_ANY_ID, PCI_ANY_ID },
+       { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520,
+               PCI_ANY_ID, PCI_ANY_ID },
+       { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510,
+               PCI_ANY_ID, PCI_ANY_ID },
        { 0, },
 };
 
+static void gx_write_byte(int reg, int value)
+{
+       pci_write_config_byte(gx_params->cs55x0, reg, value);
+}
+
 /**
  * gx_detect_chipset:
  *
@@ -200,7 +210,8 @@ static __init struct pci_dev *gx_detect_chipset(void)
 /**
  * gx_get_cpuspeed:
  *
- * Finds out at which efficient frequency the Cyrix MediaGX/NatSemi Geode CPU runs.
+ * Finds out at which efficient frequency the Cyrix MediaGX/NatSemi
+ * Geode CPU runs.
  */
 static unsigned int gx_get_cpuspeed(unsigned int cpu)
 {
@@ -217,17 +228,18 @@ static unsigned int gx_get_cpuspeed(unsigned int cpu)
  *
  **/
 
-static unsigned int gx_validate_speed(unsigned int khz, u8 *on_duration, u8 *off_duration)
+static unsigned int gx_validate_speed(unsigned int khz, u8 *on_duration,
+               u8 *off_duration)
 {
        unsigned int i;
        u8 tmp_on, tmp_off;
        int old_tmp_freq = stock_freq;
        int tmp_freq;
 
-       *off_duration=1;
-       *on_duration=0;
+       *off_duration = 1;
+       *on_duration = 0;
 
-       for (i=max_duration; i>0; i--) {
+       for (i = max_duration; i > 0; i--) {
                tmp_off = ((khz * i) / stock_freq) & 0xff;
                tmp_on = i - tmp_off;
                tmp_freq = (stock_freq * tmp_off) / i;
@@ -259,26 +271,34 @@ static void gx_set_cpuspeed(unsigned int khz)
        freqs.cpu = 0;
        freqs.old = gx_get_cpuspeed(0);
 
-       new_khz = gx_validate_speed(khz, &gx_params->on_duration, &gx_params->off_duration);
+       new_khz = gx_validate_speed(khz, &gx_params->on_duration,
+                       &gx_params->off_duration);
 
        freqs.new = new_khz;
 
        cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
        local_irq_save(flags);
 
-       if (new_khz != stock_freq) {  /* if new khz == 100% of CPU speed, it is special case */
+
+
+       if (new_khz != stock_freq) {
+               /* if new khz == 100% of CPU speed, it is special case */
                switch (gx_params->cs55x0->device) {
                case PCI_DEVICE_ID_CYRIX_5530_LEGACY:
                        pmer1 = gx_params->pci_pmer1 | IRQ_SPDUP | VID_SPDUP;
                        /* FIXME: need to test other values -- Zwane,Miura */
-                       pci_write_config_byte(gx_params->cs55x0, PCI_IRQTC, 4); /* typical 2 to 4ms */
-                       pci_write_config_byte(gx_params->cs55x0, PCI_VIDTC, 100);/* typical 50 to 100ms */
-                       pci_write_config_byte(gx_params->cs55x0, PCI_PMER1, pmer1);
-
-                       if (gx_params->cs55x0->revision < 0x10) {   /* CS5530(rev 1.2, 1.3) */
-                               suscfg = gx_params->pci_suscfg | SUSMOD;
-                       } else {                           /* CS5530A,B.. */
-                               suscfg = gx_params->pci_suscfg | SUSMOD | PWRSVE;
+                       /* typical 2 to 4ms */
+                       gx_write_byte(PCI_IRQTC, 4);
+                       /* typical 50 to 100ms */
+                       gx_write_byte(PCI_VIDTC, 100);
+                       gx_write_byte(PCI_PMER1, pmer1);
+
+                       if (gx_params->cs55x0->revision < 0x10) {
+                               /* CS5530(rev 1.2, 1.3) */
+                               suscfg = gx_params->pci_suscfg|SUSMOD;
+                       } else {
+                               /* CS5530A,B.. */
+                               suscfg = gx_params->pci_suscfg|SUSMOD|PWRSVE;
                        }
                        break;
                case PCI_DEVICE_ID_CYRIX_5520:
@@ -294,13 +314,13 @@ static void gx_set_cpuspeed(unsigned int khz)
                suscfg = gx_params->pci_suscfg & ~(SUSMOD);
                gx_params->off_duration = 0;
                gx_params->on_duration = 0;
-               dprintk("suspend modulation disabled: cpu runs 100 percent speed.\n");
+               dprintk("suspend modulation disabled: cpu runs 100%% speed.\n");
        }
 
-       pci_write_config_byte(gx_params->cs55x0, PCI_MODOFF, gx_params->off_duration);
-       pci_write_config_byte(gx_params->cs55x0, PCI_MODON, gx_params->on_duration);
+       gx_write_byte(PCI_MODOFF, gx_params->off_duration);
+       gx_write_byte(PCI_MODON, gx_params->on_duration);
 
-       pci_write_config_byte(gx_params->cs55x0, PCI_SUSCFG, suscfg);
+       gx_write_byte(PCI_SUSCFG, suscfg);
        pci_read_config_byte(gx_params->cs55x0, PCI_SUSCFG, &suscfg);
 
        local_irq_restore(flags);
@@ -334,7 +354,8 @@ static int cpufreq_gx_verify(struct cpufreq_policy *policy)
                return -EINVAL;
 
        policy->cpu = 0;
-       cpufreq_verify_within_limits(policy, (stock_freq / max_duration), stock_freq);
+       cpufreq_verify_within_limits(policy, (stock_freq / max_duration),
+                       stock_freq);
 
        /* it needs to be assured that at least one supported frequency is
         * within policy->min and policy->max. If it is not, policy->max
@@ -354,7 +375,8 @@ static int cpufreq_gx_verify(struct cpufreq_policy *policy)
        policy->max = tmp_freq;
        if (policy->max < policy->min)
                policy->max = policy->min;
-       cpufreq_verify_within_limits(policy, (stock_freq / max_duration), stock_freq);
+       cpufreq_verify_within_limits(policy, (stock_freq / max_duration),
+                       stock_freq);
 
        return 0;
 }
@@ -398,18 +420,18 @@ static int cpufreq_gx_cpu_init(struct cpufreq_policy *policy)
                return -ENODEV;
 
        /* determine maximum frequency */
-       if (pci_busclk) {
+       if (pci_busclk)
                maxfreq = pci_busclk * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f];
-       } else if (cpu_khz) {
+       else if (cpu_khz)
                maxfreq = cpu_khz;
-       } else {
+       else
                maxfreq = 30000 * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f];
-       }
+
        stock_freq = maxfreq;
        curfreq = gx_get_cpuspeed(0);
 
        dprintk("cpu max frequency is %d.\n", maxfreq);
-       dprintk("cpu current frequency is %dkHz.\n",curfreq);
+       dprintk("cpu current frequency is %dkHz.\n", curfreq);
 
        /* setup basic struct for cpufreq API */
        policy->cpu = 0;
@@ -447,7 +469,8 @@ static int __init cpufreq_gx_init(void)
        struct pci_dev *gx_pci;
 
        /* Test if we have the right hardware */
-       if ((gx_pci = gx_detect_chipset()) == NULL)
+       gx_pci = gx_detect_chipset();
+       if (gx_pci == NULL)
                return -ENODEV;
 
        /* check whether module parameters are sane */
@@ -468,9 +491,11 @@ static int __init cpufreq_gx_init(void)
        pci_read_config_byte(params->cs55x0, PCI_PMER1, &(params->pci_pmer1));
        pci_read_config_byte(params->cs55x0, PCI_PMER2, &(params->pci_pmer2));
        pci_read_config_byte(params->cs55x0, PCI_MODON, &(params->on_duration));
-       pci_read_config_byte(params->cs55x0, PCI_MODOFF, &(params->off_duration));
+       pci_read_config_byte(params->cs55x0, PCI_MODOFF,
+                       &(params->off_duration));
 
-       if ((ret = cpufreq_register_driver(&gx_suspmod_driver))) {
+       ret = cpufreq_register_driver(&gx_suspmod_driver);
+       if (ret) {
                kfree(params);
                return ret;                   /* register error! */
        }
@@ -485,9 +510,9 @@ static void __exit cpufreq_gx_exit(void)
        kfree(gx_params);
 }
 
-MODULE_AUTHOR ("Hiroshi Miura <miura@da-cha.org>");
-MODULE_DESCRIPTION ("Cpufreq driver for Cyrix MediaGX and NatSemi Geode");
-MODULE_LICENSE ("GPL");
+MODULE_AUTHOR("Hiroshi Miura <miura@da-cha.org>");
+MODULE_DESCRIPTION("Cpufreq driver for Cyrix MediaGX and NatSemi Geode");
+MODULE_LICENSE("GPL");
 
 module_init(cpufreq_gx_init);
 module_exit(cpufreq_gx_exit);
index a4cff5d6e380fa8b027eaf3413f1911fbe821599..f1c51aea064df73fb28c3793da94c080703d4580 100644 (file)
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/delay.h>
+#include <linux/timex.h>
+#include <linux/io.h>
+#include <linux/acpi.h>
+#include <linux/kernel.h>
 
 #include <asm/msr.h>
-#include <asm/timex.h>
-#include <asm/io.h>
-#include <asm/acpi.h>
-#include <linux/acpi.h>
 #include <acpi/processor.h>
 
 #include "longhaul.h"
@@ -58,7 +58,7 @@
 #define USE_NORTHBRIDGE                (1 << 2)
 
 static int cpu_model;
-static unsigned int numscales=16;
+static unsigned int numscales = 16;
 static unsigned int fsb;
 
 static const struct mV_pos *vrm_mV_table;
@@ -67,8 +67,8 @@ static const unsigned char *mV_vrm_table;
 static unsigned int highest_speed, lowest_speed; /* kHz */
 static unsigned int minmult, maxmult;
 static int can_scale_voltage;
-static struct acpi_processor *pr = NULL;
-static struct acpi_processor_cx *cx = NULL;
+static struct acpi_processor *pr;
+static struct acpi_processor_cx *cx;
 static u32 acpi_regs_addr;
 static u8 longhaul_flags;
 static unsigned int longhaul_index;
@@ -78,12 +78,13 @@ static int scale_voltage;
 static int disable_acpi_c3;
 static int revid_errata;
 
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "longhaul", msg)
+#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
+               "longhaul", msg)
 
 
 /* Clock ratios multiplied by 10 */
-static int clock_ratio[32];
-static int eblcr_table[32];
+static int mults[32];
+static int eblcr[32];
 static int longhaul_version;
 static struct cpufreq_frequency_table *longhaul_table;
 
@@ -93,7 +94,7 @@ static char speedbuffer[8];
 static char *print_speed(int speed)
 {
        if (speed < 1000) {
-               snprintf(speedbuffer, sizeof(speedbuffer),"%dMHz", speed);
+               snprintf(speedbuffer, sizeof(speedbuffer), "%dMHz", speed);
                return speedbuffer;
        }
 
@@ -122,27 +123,28 @@ static unsigned int calc_speed(int mult)
 
 static int longhaul_get_cpu_mult(void)
 {
-       unsigned long invalue=0,lo, hi;
+       unsigned long invalue = 0, lo, hi;
 
-       rdmsr (MSR_IA32_EBL_CR_POWERON, lo, hi);
-       invalue = (lo & (1<<22|1<<23|1<<24|1<<25)) >>22;
-       if (longhaul_version==TYPE_LONGHAUL_V2 || longhaul_version==TYPE_POWERSAVER) {
+       rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi);
+       invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22;
+       if (longhaul_version == TYPE_LONGHAUL_V2 ||
+           longhaul_version == TYPE_POWERSAVER) {
                if (lo & (1<<27))
-                       invalue+=16;
+                       invalue += 16;
        }
-       return eblcr_table[invalue];
+       return eblcr[invalue];
 }
 
 /* For processor with BCR2 MSR */
 
-static void do_longhaul1(unsigned int clock_ratio_index)
+static void do_longhaul1(unsigned int mults_index)
 {
        union msr_bcr2 bcr2;
 
        rdmsrl(MSR_VIA_BCR2, bcr2.val);
        /* Enable software clock multiplier */
        bcr2.bits.ESOFTBF = 1;
-       bcr2.bits.CLOCKMUL = clock_ratio_index & 0xff;
+       bcr2.bits.CLOCKMUL = mults_index & 0xff;
 
        /* Sync to timer tick */
        safe_halt();
@@ -161,7 +163,7 @@ static void do_longhaul1(unsigned int clock_ratio_index)
 
 /* For processor with Longhaul MSR */
 
-static void do_powersaver(int cx_address, unsigned int clock_ratio_index,
+static void do_powersaver(int cx_address, unsigned int mults_index,
                          unsigned int dir)
 {
        union msr_longhaul longhaul;
@@ -173,11 +175,11 @@ static void do_powersaver(int cx_address, unsigned int clock_ratio_index,
                longhaul.bits.RevisionKey = longhaul.bits.RevisionID;
        else
                longhaul.bits.RevisionKey = 0;
-       longhaul.bits.SoftBusRatio = clock_ratio_index & 0xf;
-       longhaul.bits.SoftBusRatio4 = (clock_ratio_index & 0x10) >> 4;
+       longhaul.bits.SoftBusRatio = mults_index & 0xf;
+       longhaul.bits.SoftBusRatio4 = (mults_index & 0x10) >> 4;
        /* Setup new voltage */
        if (can_scale_voltage)
-               longhaul.bits.SoftVID = (clock_ratio_index >> 8) & 0x1f;
+               longhaul.bits.SoftVID = (mults_index >> 8) & 0x1f;
        /* Sync to timer tick */
        safe_halt();
        /* Raise voltage if necessary */
@@ -240,14 +242,14 @@ static void do_powersaver(int cx_address, unsigned int clock_ratio_index,
 
 /**
  * longhaul_set_cpu_frequency()
- * @clock_ratio_index : bitpattern of the new multiplier.
+ * @mults_index : bitpattern of the new multiplier.
  *
  * Sets a new clock ratio.
  */
 
 static void longhaul_setstate(unsigned int table_index)
 {
-       unsigned int clock_ratio_index;
+       unsigned int mults_index;
        int speed, mult;
        struct cpufreq_freqs freqs;
        unsigned long flags;
@@ -256,9 +258,9 @@ static void longhaul_setstate(unsigned int table_index)
        u32 bm_timeout = 1000;
        unsigned int dir = 0;
 
-       clock_ratio_index = longhaul_table[table_index].index;
+       mults_index = longhaul_table[table_index].index;
        /* Safety precautions */
-       mult = clock_ratio[clock_ratio_index & 0x1f];
+       mult = mults[mults_index & 0x1f];
        if (mult == -1)
                return;
        speed = calc_speed(mult);
@@ -274,7 +276,7 @@ static void longhaul_setstate(unsigned int table_index)
 
        cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
 
-       dprintk ("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n",
+       dprintk("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n",
                        fsb, mult/10, mult%10, print_speed(speed/1000));
 retry_loop:
        preempt_disable();
@@ -282,8 +284,8 @@ retry_loop:
 
        pic2_mask = inb(0xA1);
        pic1_mask = inb(0x21);  /* works on C3. save mask. */
-       outb(0xFF,0xA1);        /* Overkill */
-       outb(0xFE,0x21);        /* TMR0 only */
+       outb(0xFF, 0xA1);       /* Overkill */
+       outb(0xFE, 0x21);       /* TMR0 only */
 
        /* Wait while PCI bus is busy. */
        if (acpi_regs_addr && (longhaul_flags & USE_NORTHBRIDGE
@@ -312,7 +314,7 @@ retry_loop:
         * Software controlled multipliers only.
         */
        case TYPE_LONGHAUL_V1:
-               do_longhaul1(clock_ratio_index);
+               do_longhaul1(mults_index);
                break;
 
        /*
@@ -327,9 +329,9 @@ retry_loop:
                if (longhaul_flags & USE_ACPI_C3) {
                        /* Don't allow wakeup */
                        acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
-                       do_powersaver(cx->address, clock_ratio_index, dir);
+                       do_powersaver(cx->address, mults_index, dir);
                } else {
-                       do_powersaver(0, clock_ratio_index, dir);
+                       do_powersaver(0, mults_index, dir);
                }
                break;
        }
@@ -341,8 +343,8 @@ retry_loop:
                /* Enable bus master arbitration */
                acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
        }
-       outb(pic2_mask,0xA1);   /* restore mask */
-       outb(pic1_mask,0x21);
+       outb(pic2_mask, 0xA1);  /* restore mask */
+       outb(pic1_mask, 0x21);
 
        local_irq_restore(flags);
        preempt_enable();
@@ -392,7 +394,8 @@ retry_loop:
        cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
 
        if (!bm_timeout)
-               printk(KERN_INFO PFX "Warning: Timeout while waiting for idle PCI bus.\n");
+               printk(KERN_INFO PFX "Warning: Timeout while waiting for "
+                               "idle PCI bus.\n");
 }
 
 /*
@@ -458,31 +461,32 @@ static int __init longhaul_get_ranges(void)
                break;
        }
 
-       dprintk ("MinMult:%d.%dx MaxMult:%d.%dx\n",
+       dprintk("MinMult:%d.%dx MaxMult:%d.%dx\n",
                 minmult/10, minmult%10, maxmult/10, maxmult%10);
 
        highest_speed = calc_speed(maxmult);
        lowest_speed = calc_speed(minmult);
-       dprintk ("FSB:%dMHz  Lowest speed: %s   Highest speed:%s\n", fsb,
+       dprintk("FSB:%dMHz  Lowest speed: %s   Highest speed:%s\n", fsb,
                 print_speed(lowest_speed/1000),
                 print_speed(highest_speed/1000));
 
        if (lowest_speed == highest_speed) {
-               printk (KERN_INFO PFX "highestspeed == lowest, aborting.\n");
+               printk(KERN_INFO PFX "highestspeed == lowest, aborting.\n");
                return -EINVAL;
        }
        if (lowest_speed > highest_speed) {
-               printk (KERN_INFO PFX "nonsense! lowest (%d > %d) !\n",
+               printk(KERN_INFO PFX "nonsense! lowest (%d > %d) !\n",
                        lowest_speed, highest_speed);
                return -EINVAL;
        }
 
-       longhaul_table = kmalloc((numscales + 1) * sizeof(struct cpufreq_frequency_table), GFP_KERNEL);
-       if(!longhaul_table)
+       longhaul_table = kmalloc((numscales + 1) * sizeof(*longhaul_table),
+                       GFP_KERNEL);
+       if (!longhaul_table)
                return -ENOMEM;
 
        for (j = 0; j < numscales; j++) {
-               ratio = clock_ratio[j];
+               ratio = mults[j];
                if (ratio == -1)
                        continue;
                if (ratio > maxmult || ratio < minmult)
@@ -507,13 +511,10 @@ static int __init longhaul_get_ranges(void)
                        }
                }
                if (min_i != j) {
-                       unsigned int temp;
-                       temp = longhaul_table[j].frequency;
-                       longhaul_table[j].frequency = longhaul_table[min_i].frequency;
-                       longhaul_table[min_i].frequency = temp;
-                       temp = longhaul_table[j].index;
-                       longhaul_table[j].index = longhaul_table[min_i].index;
-                       longhaul_table[min_i].index = temp;
+                       swap(longhaul_table[j].frequency,
+                            longhaul_table[min_i].frequency);
+                       swap(longhaul_table[j].index,
+                            longhaul_table[min_i].index);
                }
        }
 
@@ -521,7 +522,7 @@ static int __init longhaul_get_ranges(void)
 
        /* Find index we are running on */
        for (j = 0; j < k; j++) {
-               if (clock_ratio[longhaul_table[j].index & 0x1f] == mult) {
+               if (mults[longhaul_table[j].index & 0x1f] == mult) {
                        longhaul_index = j;
                        break;
                }
@@ -559,20 +560,22 @@ static void __init longhaul_setup_voltagescaling(void)
        maxvid = vrm_mV_table[longhaul.bits.MaximumVID];
 
        if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) {
-               printk (KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. "
+               printk(KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. "
                                        "Voltage scaling disabled.\n",
-                                       minvid.mV/1000, minvid.mV%1000, maxvid.mV/1000, maxvid.mV%1000);
+                                       minvid.mV/1000, minvid.mV%1000,
+                                       maxvid.mV/1000, maxvid.mV%1000);
                return;
        }
 
        if (minvid.mV == maxvid.mV) {
-               printk (KERN_INFO PFX "Claims to support voltage scaling but min & max are "
-                               "both %d.%03d. Voltage scaling disabled\n",
+               printk(KERN_INFO PFX "Claims to support voltage scaling but "
+                               "min & max are both %d.%03d. "
+                               "Voltage scaling disabled\n",
                                maxvid.mV/1000, maxvid.mV%1000);
                return;
        }
 
-       /* How many voltage steps */
+       /* How many voltage steps*/
        numvscales = maxvid.pos - minvid.pos + 1;
        printk(KERN_INFO PFX
                "Max VID=%d.%03d  "
@@ -586,7 +589,7 @@ static void __init longhaul_setup_voltagescaling(void)
        j = longhaul.bits.MinMHzBR;
        if (longhaul.bits.MinMHzBR4)
                j += 16;
-       min_vid_speed = eblcr_table[j];
+       min_vid_speed = eblcr[j];
        if (min_vid_speed == -1)
                return;
        switch (longhaul.bits.MinMHzFSB) {
@@ -617,7 +620,8 @@ static void __init longhaul_setup_voltagescaling(void)
                        pos = minvid.pos;
                longhaul_table[j].index |= mV_vrm_table[pos] << 8;
                vid = vrm_mV_table[mV_vrm_table[pos]];
-               printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", speed, j, vid.mV);
+               printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n",
+                               speed, j, vid.mV);
                j++;
        }
 
@@ -640,7 +644,8 @@ static int longhaul_target(struct cpufreq_policy *policy,
        unsigned int dir = 0;
        u8 vid, current_vid;
 
-       if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq, relation, &table_index))
+       if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq,
+                               relation, &table_index))
                return -EINVAL;
 
        /* Don't set same frequency again */
@@ -656,7 +661,8 @@ static int longhaul_target(struct cpufreq_policy *policy,
                 * this in hardware, C3 is old and we need to do this
                 * in software. */
                i = longhaul_index;
-               current_vid = (longhaul_table[longhaul_index].index >> 8) & 0x1f;
+               current_vid = (longhaul_table[longhaul_index].index >> 8);
+               current_vid &= 0x1f;
                if (table_index > longhaul_index)
                        dir = 1;
                while (i != table_index) {
@@ -691,9 +697,9 @@ static acpi_status longhaul_walk_callback(acpi_handle obj_handle,
 {
        struct acpi_device *d;
 
-       if ( acpi_bus_get_device(obj_handle, &d) ) {
+       if (acpi_bus_get_device(obj_handle, &d))
                return 0;
-       }
+
        *return_value = acpi_driver_data(d);
        return 1;
 }
@@ -750,7 +756,7 @@ static int longhaul_setup_southbridge(void)
        /* Find VT8235 southbridge */
        dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL);
        if (dev == NULL)
-       /* Find VT8237 southbridge */
+               /* Find VT8237 southbridge */
                dev = pci_get_device(PCI_VENDOR_ID_VIA,
                                     PCI_DEVICE_ID_VIA_8237, NULL);
        if (dev != NULL) {
@@ -769,7 +775,8 @@ static int longhaul_setup_southbridge(void)
                if (pci_cmd & 1 << 7) {
                        pci_read_config_dword(dev, 0x88, &acpi_regs_addr);
                        acpi_regs_addr &= 0xff00;
-                       printk(KERN_INFO PFX "ACPI I/O at 0x%x\n", acpi_regs_addr);
+                       printk(KERN_INFO PFX "ACPI I/O at 0x%x\n",
+                                       acpi_regs_addr);
                }
 
                pci_dev_put(dev);
@@ -781,7 +788,7 @@ static int longhaul_setup_southbridge(void)
 static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
 {
        struct cpuinfo_x86 *c = &cpu_data(0);
-       char *cpuname=NULL;
+       char *cpuname = NULL;
        int ret;
        u32 lo, hi;
 
@@ -791,8 +798,8 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
                cpu_model = CPU_SAMUEL;
                cpuname = "C3 'Samuel' [C5A]";
                longhaul_version = TYPE_LONGHAUL_V1;
-               memcpy (clock_ratio, samuel1_clock_ratio, sizeof(samuel1_clock_ratio));
-               memcpy (eblcr_table, samuel1_eblcr, sizeof(samuel1_eblcr));
+               memcpy(mults, samuel1_mults, sizeof(samuel1_mults));
+               memcpy(eblcr, samuel1_eblcr, sizeof(samuel1_eblcr));
                break;
 
        case 7:
@@ -803,10 +810,8 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
                        cpuname = "C3 'Samuel 2' [C5B]";
                        /* Note, this is not a typo, early Samuel2's had
                         * Samuel1 ratios. */
-                       memcpy(clock_ratio, samuel1_clock_ratio,
-                               sizeof(samuel1_clock_ratio));
-                       memcpy(eblcr_table, samuel2_eblcr,
-                               sizeof(samuel2_eblcr));
+                       memcpy(mults, samuel1_mults, sizeof(samuel1_mults));
+                       memcpy(eblcr, samuel2_eblcr, sizeof(samuel2_eblcr));
                        break;
                case 1 ... 15:
                        longhaul_version = TYPE_LONGHAUL_V1;
@@ -817,10 +822,8 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
                                cpu_model = CPU_EZRA;
                                cpuname = "C3 'Ezra' [C5C]";
                        }
-                       memcpy(clock_ratio, ezra_clock_ratio,
-                               sizeof(ezra_clock_ratio));
-                       memcpy(eblcr_table, ezra_eblcr,
-                               sizeof(ezra_eblcr));
+                       memcpy(mults, ezra_mults, sizeof(ezra_mults));
+                       memcpy(eblcr, ezra_eblcr, sizeof(ezra_eblcr));
                        break;
                }
                break;
@@ -829,18 +832,16 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
                cpu_model = CPU_EZRA_T;
                cpuname = "C3 'Ezra-T' [C5M]";
                longhaul_version = TYPE_POWERSAVER;
-               numscales=32;
-               memcpy (clock_ratio, ezrat_clock_ratio, sizeof(ezrat_clock_ratio));
-               memcpy (eblcr_table, ezrat_eblcr, sizeof(ezrat_eblcr));
+               numscales = 32;
+               memcpy(mults, ezrat_mults, sizeof(ezrat_mults));
+               memcpy(eblcr, ezrat_eblcr, sizeof(ezrat_eblcr));
                break;
 
        case 9:
                longhaul_version = TYPE_POWERSAVER;
                numscales = 32;
-               memcpy(clock_ratio,
-                      nehemiah_clock_ratio,
-                      sizeof(nehemiah_clock_ratio));
-               memcpy(eblcr_table, nehemiah_eblcr, sizeof(nehemiah_eblcr));
+               memcpy(mults, nehemiah_mults, sizeof(nehemiah_mults));
+               memcpy(eblcr, nehemiah_eblcr, sizeof(nehemiah_eblcr));
                switch (c->x86_mask) {
                case 0 ... 1:
                        cpu_model = CPU_NEHEMIAH;
@@ -869,14 +870,14 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
                        longhaul_version = TYPE_LONGHAUL_V1;
        }
 
-       printk (KERN_INFO PFX "VIA %s CPU detected.  ", cpuname);
+       printk(KERN_INFO PFX "VIA %s CPU detected.  ", cpuname);
        switch (longhaul_version) {
        case TYPE_LONGHAUL_V1:
        case TYPE_LONGHAUL_V2:
-               printk ("Longhaul v%d supported.\n", longhaul_version);
+               printk(KERN_CONT "Longhaul v%d supported.\n", longhaul_version);
                break;
        case TYPE_POWERSAVER:
-               printk ("Powersaver supported.\n");
+               printk(KERN_CONT "Powersaver supported.\n");
                break;
        };
 
@@ -940,7 +941,7 @@ static int __devexit longhaul_cpu_exit(struct cpufreq_policy *policy)
        return 0;
 }
 
-static struct freq_attrlonghaul_attr[] = {
+static struct freq_attr *longhaul_attr[] = {
        &cpufreq_freq_attr_scaling_available_freqs,
        NULL,
 };
@@ -966,13 +967,15 @@ static int __init longhaul_init(void)
 
 #ifdef CONFIG_SMP
        if (num_online_cpus() > 1) {
-               printk(KERN_ERR PFX "More than 1 CPU detected, longhaul disabled.\n");
+               printk(KERN_ERR PFX "More than 1 CPU detected, "
+                               "longhaul disabled.\n");
                return -ENODEV;
        }
 #endif
 #ifdef CONFIG_X86_IO_APIC
        if (cpu_has_apic) {
-               printk(KERN_ERR PFX "APIC detected. Longhaul is currently broken in this configuration.\n");
+               printk(KERN_ERR PFX "APIC detected. Longhaul is currently "
+                               "broken in this configuration.\n");
                return -ENODEV;
        }
 #endif
@@ -993,8 +996,8 @@ static void __exit longhaul_exit(void)
 {
        int i;
 
-       for (i=0; i < numscales; i++) {
-               if (clock_ratio[i] == maxmult) {
+       for (i = 0; i < numscales; i++) {
+               if (mults[i] == maxmult) {
                        longhaul_setstate(i);
                        break;
                }
@@ -1007,11 +1010,11 @@ static void __exit longhaul_exit(void)
 /* Even if BIOS is exporting ACPI C3 state, and it is used
  * with success when CPU is idle, this state doesn't
  * trigger frequency transition in some cases. */
-module_param (disable_acpi_c3, int, 0644);
+module_param(disable_acpi_c3, int, 0644);
 MODULE_PARM_DESC(disable_acpi_c3, "Don't use ACPI C3 support");
 /* Change CPU voltage with frequency. Very usefull to save
  * power, but most VIA C3 processors aren't supporting it. */
-module_param (scale_voltage, int, 0644);
+module_param(scale_voltage, int, 0644);
 MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor");
 /* Force revision key to 0 for processors which doesn't
  * support voltage scaling, but are introducing itself as
@@ -1019,9 +1022,9 @@ MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor");
 module_param(revid_errata, int, 0644);
 MODULE_PARM_DESC(revid_errata, "Ignore CPU Revision ID");
 
-MODULE_AUTHOR ("Dave Jones <davej@redhat.com>");
-MODULE_DESCRIPTION ("Longhaul driver for VIA Cyrix processors.");
-MODULE_LICENSE ("GPL");
+MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
+MODULE_DESCRIPTION("Longhaul driver for VIA Cyrix processors.");
+MODULE_LICENSE("GPL");
 
 late_initcall(longhaul_init);
 module_exit(longhaul_exit);
index 4fcc320997dfd5b9462d21f9282ca2bdcb0c85f0..e2360a469f793b50ab0a5a2662cce15edf25c2aa 100644 (file)
@@ -49,14 +49,14 @@ union msr_longhaul {
 
 /*
  * Clock ratio tables. Div/Mod by 10 to get ratio.
- * The eblcr ones specify the ratio read from the CPU.
- * The clock_ratio ones specify what to write to the CPU.
+ * The eblcr values specify the ratio read from the CPU.
+ * The mults values specify what to write to the CPU.
  */
 
 /*
  * VIA C3 Samuel 1  & Samuel 2 (stepping 0)
  */
-static const int __initdata samuel1_clock_ratio[16] = {
+static const int __initdata samuel1_mults[16] = {
        -1, /* 0000 -> RESERVED */
        30, /* 0001 ->  3.0x */
        40, /* 0010 ->  4.0x */
@@ -119,7 +119,7 @@ static const int __initdata samuel2_eblcr[16] = {
 /*
  * VIA C3 Ezra
  */
-static const int __initdata ezra_clock_ratio[16] = {
+static const int __initdata ezra_mults[16] = {
        100, /* 0000 -> 10.0x */
        30,  /* 0001 ->  3.0x */
        40,  /* 0010 ->  4.0x */
@@ -160,7 +160,7 @@ static const int __initdata ezra_eblcr[16] = {
 /*
  * VIA C3 (Ezra-T) [C5M].
  */
-static const int __initdata ezrat_clock_ratio[32] = {
+static const int __initdata ezrat_mults[32] = {
        100, /* 0000 -> 10.0x */
        30,  /* 0001 ->  3.0x */
        40,  /* 0010 ->  4.0x */
@@ -235,7 +235,7 @@ static const int __initdata ezrat_eblcr[32] = {
 /*
  * VIA C3 Nehemiah */
 
-static const int __initdata  nehemiah_clock_ratio[32] = {
+static const int __initdata  nehemiah_mults[32] = {
        100, /* 0000 -> 10.0x */
        -1, /* 0001 -> 16.0x */
        40,  /* 0010 ->  4.0x */
index 777a7ff075ded63d0c460a4d3c5c2db64ae764e3..da5f70fcb766d1f4a257466e5710c7da62af6d5e 100644 (file)
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/cpufreq.h>
+#include <linux/timex.h>
 
 #include <asm/msr.h>
 #include <asm/processor.h>
-#include <asm/timex.h>
 
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "longrun", msg)
+#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
+               "longrun", msg)
 
 static struct cpufreq_driver   longrun_driver;
 
@@ -51,7 +52,7 @@ static void __init longrun_get_policy(struct cpufreq_policy *policy)
        msr_lo &= 0x0000007F;
        msr_hi &= 0x0000007F;
 
-       if ( longrun_high_freq <= longrun_low_freq ) {
+       if (longrun_high_freq <= longrun_low_freq) {
                /* Assume degenerate Longrun table */
                policy->min = policy->max = longrun_high_freq;
        } else {
@@ -79,7 +80,7 @@ static int longrun_set_policy(struct cpufreq_policy *policy)
        if (!policy)
                return -EINVAL;
 
-       if ( longrun_high_freq <= longrun_low_freq ) {
+       if (longrun_high_freq <= longrun_low_freq) {
                /* Assume degenerate Longrun table */
                pctg_lo = pctg_hi = 100;
        } else {
@@ -152,7 +153,7 @@ static unsigned int longrun_get(unsigned int cpu)
        cpuid(0x80860007, &eax, &ebx, &ecx, &edx);
        dprintk("cpuid eax is %u\n", eax);
 
-       return (eax * 1000);
+       return eax * 1000;
 }
 
 /**
@@ -196,7 +197,8 @@ static unsigned int __init longrun_determine_freqs(unsigned int *low_freq,
                rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi);
                *high_freq = msr_lo * 1000; /* to kHz */
 
-               dprintk("longrun table interface told %u - %u kHz\n", *low_freq, *high_freq);
+               dprintk("longrun table interface told %u - %u kHz\n",
+                               *low_freq, *high_freq);
 
                if (*low_freq > *high_freq)
                        *low_freq = *high_freq;
@@ -219,7 +221,7 @@ static unsigned int __init longrun_determine_freqs(unsigned int *low_freq,
        cpuid(0x80860007, &eax, &ebx, &ecx, &edx);
        /* try decreasing in 10% steps, some processors react only
         * on some barrier values */
-       for (try_hi = 80; try_hi > 0 && ecx > 90; try_hi -=10) {
+       for (try_hi = 80; try_hi > 0 && ecx > 90; try_hi -= 10) {
                /* set to 0 to try_hi perf_pctg */
                msr_lo &= 0xFFFFFF80;
                msr_hi &= 0xFFFFFF80;
@@ -236,7 +238,7 @@ static unsigned int __init longrun_determine_freqs(unsigned int *low_freq,
 
        /* performance_pctg = (current_freq - low_freq)/(high_freq - low_freq)
         * eqals
-        * low_freq * ( 1 - perf_pctg) = (cur_freq - high_freq * perf_pctg)
+        * low_freq * (1 - perf_pctg) = (cur_freq - high_freq * perf_pctg)
         *
         * high_freq * perf_pctg is stored tempoarily into "ebx".
         */
@@ -317,9 +319,10 @@ static void __exit longrun_exit(void)
 }
 
 
-MODULE_AUTHOR ("Dominik Brodowski <linux@brodo.de>");
-MODULE_DESCRIPTION ("LongRun driver for Transmeta Crusoe and Efficeon processors.");
-MODULE_LICENSE ("GPL");
+MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
+MODULE_DESCRIPTION("LongRun driver for Transmeta Crusoe and "
+               "Efficeon processors.");
+MODULE_LICENSE("GPL");
 
 module_init(longrun_init);
 module_exit(longrun_exit);
index 3178c3acd97ebb4aa515d19da8a7f75b1178b08a..41ed94915f974ce0310510d9864b54d8e96f37df 100644 (file)
 #include <linux/cpufreq.h>
 #include <linux/slab.h>
 #include <linux/cpumask.h>
+#include <linux/timex.h>
 
 #include <asm/processor.h>
 #include <asm/msr.h>
-#include <asm/timex.h>
+#include <asm/timer.h>
 
 #include "speedstep-lib.h"
 
 #define PFX    "p4-clockmod: "
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "p4-clockmod", msg)
+#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
+               "p4-clockmod", msg)
 
 /*
  * Duty Cycle (3bits), note DC_DISABLE is not specified in
@@ -58,7 +60,8 @@ static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate)
 {
        u32 l, h;
 
-       if (!cpu_online(cpu) || (newstate > DC_DISABLE) || (newstate == DC_RESV))
+       if (!cpu_online(cpu) ||
+           (newstate > DC_DISABLE) || (newstate == DC_RESV))
                return -EINVAL;
 
        rdmsr_on_cpu(cpu, MSR_IA32_THERM_STATUS, &l, &h);
@@ -66,7 +69,8 @@ static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate)
        if (l & 0x01)
                dprintk("CPU#%d currently thermal throttled\n", cpu);
 
-       if (has_N44_O17_errata[cpu] && (newstate == DC_25PT || newstate == DC_DFLT))
+       if (has_N44_O17_errata[cpu] &&
+           (newstate == DC_25PT || newstate == DC_DFLT))
                newstate = DC_38PT;
 
        rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h);
@@ -112,7 +116,8 @@ static int cpufreq_p4_target(struct cpufreq_policy *policy,
        struct cpufreq_freqs freqs;
        int i;
 
-       if (cpufreq_frequency_table_target(policy, &p4clockmod_table[0], target_freq, relation, &newstate))
+       if (cpufreq_frequency_table_target(policy, &p4clockmod_table[0],
+                               target_freq, relation, &newstate))
                return -EINVAL;
 
        freqs.old = cpufreq_p4_get(policy->cpu);
@@ -127,7 +132,8 @@ static int cpufreq_p4_target(struct cpufreq_policy *policy,
                cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
        }
 
-       /* run on each logical CPU, see section 13.15.3 of IA32 Intel Architecture Software
+       /* run on each logical CPU,
+        * see section 13.15.3 of IA32 Intel Architecture Software
         * Developer's Manual, Volume 3
         */
        for_each_cpu(i, policy->cpus)
@@ -153,28 +159,30 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
 {
        if (c->x86 == 0x06) {
                if (cpu_has(c, X86_FEATURE_EST))
-                       printk(KERN_WARNING PFX "Warning: EST-capable CPU detected. "
-                              "The acpi-cpufreq module offers voltage scaling"
-                              " in addition of frequency scaling. You should use "
-                              "that instead of p4-clockmod, if possible.\n");
+                       printk(KERN_WARNING PFX "Warning: EST-capable CPU "
+                              "detected. The acpi-cpufreq module offers "
+                              "voltage scaling in addition of frequency "
+                              "scaling. You should use that instead of "
+                              "p4-clockmod, if possible.\n");
                switch (c->x86_model) {
                case 0x0E: /* Core */
                case 0x0F: /* Core Duo */
                case 0x16: /* Celeron Core */
                        p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
-                       return speedstep_get_processor_frequency(SPEEDSTEP_PROCESSOR_PCORE);
+                       return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
                case 0x0D: /* Pentium M (Dothan) */
                        p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
                        /* fall through */
                case 0x09: /* Pentium M (Banias) */
-                       return speedstep_get_processor_frequency(SPEEDSTEP_PROCESSOR_PM);
+                       return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
                }
        }
 
        if (c->x86 != 0xF) {
                if (!cpu_has(c, X86_FEATURE_EST))
-                       printk(KERN_WARNING PFX "Unknown p4-clockmod-capable CPU. "
-                               "Please send an e-mail to <cpufreq@vger.kernel.org>\n");
+                       printk(KERN_WARNING PFX "Unknown CPU. "
+                               "Please send an e-mail to "
+                               "<cpufreq@vger.kernel.org>\n");
                return 0;
        }
 
@@ -182,16 +190,16 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
         * throttling is active or not. */
        p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
 
-       if (speedstep_detect_processor() == SPEEDSTEP_PROCESSOR_P4M) {
+       if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
                printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
                       "The speedstep-ich or acpi cpufreq modules offer "
                       "voltage scaling in addition of frequency scaling. "
                       "You should use either one instead of p4-clockmod, "
                       "if possible.\n");
-               return speedstep_get_processor_frequency(SPEEDSTEP_PROCESSOR_P4M);
+               return speedstep_get_frequency(SPEEDSTEP_CPU_P4M);
        }
 
-       return speedstep_get_processor_frequency(SPEEDSTEP_PROCESSOR_P4D);
+       return speedstep_get_frequency(SPEEDSTEP_CPU_P4D);
 }
 
 
@@ -217,14 +225,20 @@ static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)
                dprintk("has errata -- disabling low frequencies\n");
        }
 
+       if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4D &&
+           c->x86_model < 2) {
+               /* switch to maximum frequency and measure result */
+               cpufreq_p4_setdc(policy->cpu, DC_DISABLE);
+               recalibrate_cpu_khz();
+       }
        /* get max frequency */
        stock_freq = cpufreq_p4_get_frequency(c);
        if (!stock_freq)
                return -EINVAL;
 
        /* table init */
-       for (i=1; (p4clockmod_table[i].frequency != CPUFREQ_TABLE_END); i++) {
-               if ((i<2) && (has_N44_O17_errata[policy->cpu]))
+       for (i = 1; (p4clockmod_table[i].frequency != CPUFREQ_TABLE_END); i++) {
+               if ((i < 2) && (has_N44_O17_errata[policy->cpu]))
                        p4clockmod_table[i].frequency = CPUFREQ_ENTRY_INVALID;
                else
                        p4clockmod_table[i].frequency = (stock_freq * i)/8;
@@ -232,7 +246,10 @@ static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)
        cpufreq_frequency_table_get_attr(p4clockmod_table, policy->cpu);
 
        /* cpuinfo and default policy values */
-       policy->cpuinfo.transition_latency = 1000000; /* assumed */
+
+       /* the transition latency is set to be 1 higher than the maximum
+        * transition latency of the ondemand governor */
+       policy->cpuinfo.transition_latency = 10000001;
        policy->cur = stock_freq;
 
        return cpufreq_frequency_table_cpuinfo(policy, &p4clockmod_table[0]);
@@ -258,12 +275,12 @@ static unsigned int cpufreq_p4_get(unsigned int cpu)
                l = DC_DISABLE;
 
        if (l != DC_DISABLE)
-               return (stock_freq * l / 8);
+               return stock_freq * l / 8;
 
        return stock_freq;
 }
 
-static struct freq_attrp4clockmod_attr[] = {
+static struct freq_attr *p4clockmod_attr[] = {
        &cpufreq_freq_attr_scaling_available_freqs,
        NULL,
 };
@@ -298,9 +315,10 @@ static int __init cpufreq_p4_init(void)
 
        ret = cpufreq_register_driver(&p4clockmod_driver);
        if (!ret)
-               printk(KERN_INFO PFX "P4/Xeon(TM) CPU On-Demand Clock Modulation available\n");
+               printk(KERN_INFO PFX "P4/Xeon(TM) CPU On-Demand Clock "
+                               "Modulation available\n");
 
-       return (ret);
+       return ret;
 }
 
 
@@ -310,9 +328,9 @@ static void __exit cpufreq_p4_exit(void)
 }
 
 
-MODULE_AUTHOR ("Zwane Mwaikambo <zwane@commfireservices.com>");
-MODULE_DESCRIPTION ("cpufreq driver for Pentium(TM) 4/Xeon(TM)");
-MODULE_LICENSE ("GPL");
+MODULE_AUTHOR("Zwane Mwaikambo <zwane@commfireservices.com>");
+MODULE_DESCRIPTION("cpufreq driver for Pentium(TM) 4/Xeon(TM)");
+MODULE_LICENSE("GPL");
 
 late_initcall(cpufreq_p4_init);
 module_exit(cpufreq_p4_exit);
index c1ac5790c63e34ec65cfe062f6fbf34c6d3607ce..f10dea409f40c3755754fbad0ae1b91eb6d1f604 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  This file was based upon code in Powertweak Linux (http://powertweak.sf.net)
- *  (C) 2000-2003  Dave Jones, Arjan van de Ven, Janne Pänkälä, Dominik Brodowski.
+ *  (C) 2000-2003  Dave Jones, Arjan van de Ven, Janne Pänkälä,
+ *                 Dominik Brodowski.
  *
  *  Licensed under the terms of the GNU GPL License version 2.
  *
 #include <linux/cpufreq.h>
 #include <linux/ioport.h>
 #include <linux/slab.h>
-
-#include <asm/msr.h>
 #include <linux/timex.h>
 #include <linux/io.h>
 
+#include <asm/msr.h>
+
 #define POWERNOW_IOPORT 0xfff0          /* it doesn't matter where, as long
                                           as it is unused */
 
+#define PFX "powernow-k6: "
 static unsigned int                     busfreq;   /* FSB, in 10 kHz */
 static unsigned int                     max_multiplier;
 
@@ -47,8 +49,8 @@ static struct cpufreq_frequency_table clock_ratio[] = {
  */
 static int powernow_k6_get_cpu_multiplier(void)
 {
-       u64             invalue = 0;
-       u32             msrval;
+       u64 invalue = 0;
+       u32 msrval;
 
        msrval = POWERNOW_IOPORT + 0x1;
        wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
@@ -68,12 +70,12 @@ static int powernow_k6_get_cpu_multiplier(void)
  */
 static void powernow_k6_set_state(unsigned int best_i)
 {
-       unsigned long           outvalue = 0, invalue = 0;
-       unsigned long           msrval;
-       struct cpufreq_freqs    freqs;
+       unsigned long outvalue = 0, invalue = 0;
+       unsigned long msrval;
+       struct cpufreq_freqs freqs;
 
        if (clock_ratio[best_i].index > max_multiplier) {
-               printk(KERN_ERR "cpufreq: invalid target frequency\n");
+               printk(KERN_ERR PFX "invalid target frequency\n");
                return;
        }
 
@@ -119,7 +121,8 @@ static int powernow_k6_verify(struct cpufreq_policy *policy)
  * powernow_k6_setpolicy - sets a new CPUFreq policy
  * @policy: new policy
  * @target_freq: the target frequency
- * @relation: how that frequency relates to achieved frequency (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
+ * @relation: how that frequency relates to achieved frequency
+ *  (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
  *
  * sets a new CPUFreq policy
  */
@@ -127,9 +130,10 @@ static int powernow_k6_target(struct cpufreq_policy *policy,
                               unsigned int target_freq,
                               unsigned int relation)
 {
-       unsigned int    newstate = 0;
+       unsigned int newstate = 0;
 
-       if (cpufreq_frequency_table_target(policy, &clock_ratio[0], target_freq, relation, &newstate))
+       if (cpufreq_frequency_table_target(policy, &clock_ratio[0],
+                               target_freq, relation, &newstate))
                return -EINVAL;
 
        powernow_k6_set_state(newstate);
@@ -140,7 +144,7 @@ static int powernow_k6_target(struct cpufreq_policy *policy,
 
 static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
 {
-       unsigned int i;
+       unsigned int i, f;
        int result;
 
        if (policy->cpu != 0)
@@ -152,10 +156,11 @@ static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
 
        /* table init */
        for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) {
-               if (clock_ratio[i].index > max_multiplier)
+               f = clock_ratio[i].index;
+               if (f > max_multiplier)
                        clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID;
                else
-                       clock_ratio[i].frequency = busfreq * clock_ratio[i].index;
+                       clock_ratio[i].frequency = busfreq * f;
        }
 
        /* cpuinfo and default policy values */
@@ -185,7 +190,9 @@ static int powernow_k6_cpu_exit(struct cpufreq_policy *policy)
 
 static unsigned int powernow_k6_get(unsigned int cpu)
 {
-       return busfreq * powernow_k6_get_cpu_multiplier();
+       unsigned int ret;
+       ret = (busfreq * powernow_k6_get_cpu_multiplier());
+       return ret;
 }
 
 static struct freq_attr *powernow_k6_attr[] = {
@@ -221,7 +228,7 @@ static int __init powernow_k6_init(void)
                return -ENODEV;
 
        if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) {
-               printk("cpufreq: PowerNow IOPORT region already used.\n");
+               printk(KERN_INFO PFX "PowerNow IOPORT region already used.\n");
                return -EIO;
        }
 
@@ -246,7 +253,8 @@ static void __exit powernow_k6_exit(void)
 }
 
 
-MODULE_AUTHOR("Arjan van de Ven, Dave Jones <davej@redhat.com>, Dominik Brodowski <linux@brodo.de>");
+MODULE_AUTHOR("Arjan van de Ven, Dave Jones <davej@redhat.com>, "
+               "Dominik Brodowski <linux@brodo.de>");
 MODULE_DESCRIPTION("PowerNow! driver for AMD K6-2+ / K6-3+ processors.");
 MODULE_LICENSE("GPL");
 
index 1b446d79a8fdd2d2a92f8ea04dbaa41da57a4f88..3c28ccd49742f26022a49ab3bb6a81cfc1713c4a 100644 (file)
@@ -6,10 +6,12 @@
  *  Licensed under the terms of the GNU GPL License version 2.
  *  Based upon datasheets & sample CPUs kindly provided by AMD.
  *
- * Errata 5: Processor may fail to execute a FID/VID change in presence of interrupt.
- * - We cli/sti on stepping A0 CPUs around the FID/VID transition.
- * Errata 15: Processors with half frequency multipliers may hang upon wakeup from disconnect.
- * - We disable half multipliers if ACPI is used on A0 stepping CPUs.
+ * Errata 5:
+ *  CPU may fail to execute a FID/VID change in presence of interrupt.
+ *  - We cli/sti on stepping A0 CPUs around the FID/VID transition.
+ * Errata 15:
+ *  CPU with half frequency multipliers may hang upon wakeup from disconnect.
+ *  - We disable half multipliers if ACPI is used on A0 stepping CPUs.
  */
 
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/dmi.h>
+#include <linux/timex.h>
+#include <linux/io.h>
 
+#include <asm/timer.h>         /* Needed for recalibrate_cpu_khz() */
 #include <asm/msr.h>
-#include <asm/timer.h>
-#include <asm/timex.h>
-#include <asm/io.h>
 #include <asm/system.h>
 
 #ifdef CONFIG_X86_POWERNOW_K7_ACPI
@@ -58,9 +60,9 @@ struct pst_s {
 union powernow_acpi_control_t {
        struct {
                unsigned long fid:5,
-               vid:5,
-               sgtc:20,
-               res1:2;
+                       vid:5,
+                       sgtc:20,
+                       res1:2;
        } bits;
        unsigned long val;
 };
@@ -94,14 +96,15 @@ static struct cpufreq_frequency_table *powernow_table;
 
 static unsigned int can_scale_bus;
 static unsigned int can_scale_vid;
-static unsigned int minimum_speed=-1;
+static unsigned int minimum_speed = -1;
 static unsigned int maximum_speed;
 static unsigned int number_scales;
 static unsigned int fsb;
 static unsigned int latency;
 static char have_a0;
 
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "powernow-k7", msg)
+#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
+               "powernow-k7", msg)
 
 static int check_fsb(unsigned int fsbspeed)
 {
@@ -109,7 +112,7 @@ static int check_fsb(unsigned int fsbspeed)
        unsigned int f = fsb / 1000;
 
        delta = (fsbspeed > f) ? fsbspeed - f : f - fsbspeed;
-       return (delta < 5);
+       return delta < 5;
 }
 
 static int check_powernow(void)
@@ -117,24 +120,26 @@ static int check_powernow(void)
        struct cpuinfo_x86 *c = &cpu_data(0);
        unsigned int maxei, eax, ebx, ecx, edx;
 
-       if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 !=6)) {
+       if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 6)) {
 #ifdef MODULE
-               printk (KERN_INFO PFX "This module only works with AMD K7 CPUs\n");
+               printk(KERN_INFO PFX "This module only works with "
+                               "AMD K7 CPUs\n");
 #endif
                return 0;
        }
 
        /* Get maximum capabilities */
-       maxei = cpuid_eax (0x80000000);
+       maxei = cpuid_eax(0x80000000);
        if (maxei < 0x80000007) {       /* Any powernow info ? */
 #ifdef MODULE
-               printk (KERN_INFO PFX "No powernow capabilities detected\n");
+               printk(KERN_INFO PFX "No powernow capabilities detected\n");
 #endif
                return 0;
        }
 
        if ((c->x86_model == 6) && (c->x86_mask == 0)) {
-               printk (KERN_INFO PFX "K7 660[A0] core detected, enabling errata workarounds\n");
+               printk(KERN_INFO PFX "K7 660[A0] core detected, "
+                               "enabling errata workarounds\n");
                have_a0 = 1;
        }
 
@@ -144,37 +149,42 @@ static int check_powernow(void)
        if (!(edx & (1 << 1 | 1 << 2)))
                return 0;
 
-       printk (KERN_INFO PFX "PowerNOW! Technology present. Can scale: ");
+       printk(KERN_INFO PFX "PowerNOW! Technology present. Can scale: ");
 
        if (edx & 1 << 1) {
-               printk ("frequency");
-               can_scale_bus=1;
+               printk("frequency");
+               can_scale_bus = 1;
        }
 
        if ((edx & (1 << 1 | 1 << 2)) == 0x6)
-               printk (" and ");
+               printk(" and ");
 
        if (edx & 1 << 2) {
-               printk ("voltage");
-               can_scale_vid=1;
+               printk("voltage");
+               can_scale_vid = 1;
        }
 
-       printk (".\n");
+       printk(".\n");
        return 1;
 }
 
+static void invalidate_entry(unsigned int entry)
+{
+       powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID;
+}
 
-static int get_ranges (unsigned char *pst)
+static int get_ranges(unsigned char *pst)
 {
        unsigned int j;
        unsigned int speed;
        u8 fid, vid;
 
-       powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * (number_scales + 1)), GFP_KERNEL);
+       powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) *
+                               (number_scales + 1)), GFP_KERNEL);
        if (!powernow_table)
                return -ENOMEM;
 
-       for (j=0 ; j < number_scales; j++) {
+       for (j = 0 ; j < number_scales; j++) {
                fid = *pst++;
 
                powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10;
@@ -182,10 +192,10 @@ static int get_ranges (unsigned char *pst)
 
                speed = powernow_table[j].frequency;
 
-               if ((fid_codes[fid] % 10)==5) {
+               if ((fid_codes[fid] % 10) == 5) {
 #ifdef CONFIG_X86_POWERNOW_K7_ACPI
                        if (have_a0 == 1)
-                               powernow_table[j].frequency = CPUFREQ_ENTRY_INVALID;
+                               invalidate_entry(j);
 #endif
                }
 
@@ -197,7 +207,7 @@ static int get_ranges (unsigned char *pst)
                vid = *pst++;
                powernow_table[j].index |= (vid << 8); /* upper 8 bits */
 
-               dprintk ("   FID: 0x%x (%d.%dx [%dMHz])  "
+               dprintk("   FID: 0x%x (%d.%dx [%dMHz])  "
                         "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10,
                         fid_codes[fid] % 10, speed/1000, vid,
                         mobile_vid_table[vid]/1000,
@@ -214,13 +224,13 @@ static void change_FID(int fid)
 {
        union msr_fidvidctl fidvidctl;
 
-       rdmsrl (MSR_K7_FID_VID_CTL, fidvidctl.val);
+       rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
        if (fidvidctl.bits.FID != fid) {
                fidvidctl.bits.SGTC = latency;
                fidvidctl.bits.FID = fid;
                fidvidctl.bits.VIDC = 0;
                fidvidctl.bits.FIDC = 1;
-               wrmsrl (MSR_K7_FID_VID_CTL, fidvidctl.val);
+               wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
        }
 }
 
@@ -229,18 +239,18 @@ static void change_VID(int vid)
 {
        union msr_fidvidctl fidvidctl;
 
-       rdmsrl (MSR_K7_FID_VID_CTL, fidvidctl.val);
+       rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
        if (fidvidctl.bits.VID != vid) {
                fidvidctl.bits.SGTC = latency;
                fidvidctl.bits.VID = vid;
                fidvidctl.bits.FIDC = 0;
                fidvidctl.bits.VIDC = 1;
-               wrmsrl (MSR_K7_FID_VID_CTL, fidvidctl.val);
+               wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
        }
 }
 
 
-static void change_speed (unsigned int index)
+static void change_speed(unsigned int index)
 {
        u8 fid, vid;
        struct cpufreq_freqs freqs;
@@ -257,7 +267,7 @@ static void change_speed (unsigned int index)
 
        freqs.cpu = 0;
 
-       rdmsrl (MSR_K7_FID_VID_STATUS, fidvidstatus.val);
+       rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
        cfid = fidvidstatus.bits.CFID;
        freqs.old = fsb * fid_codes[cfid] / 10;
 
@@ -321,12 +331,14 @@ static int powernow_acpi_init(void)
                goto err1;
        }
 
-       if (acpi_processor_perf->control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) {
+       if (acpi_processor_perf->control_register.space_id !=
+                       ACPI_ADR_SPACE_FIXED_HARDWARE) {
                retval = -ENODEV;
                goto err2;
        }
 
-       if (acpi_processor_perf->status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) {
+       if (acpi_processor_perf->status_register.space_id !=
+                       ACPI_ADR_SPACE_FIXED_HARDWARE) {
                retval = -ENODEV;
                goto err2;
        }
@@ -338,7 +350,8 @@ static int powernow_acpi_init(void)
                goto err2;
        }
 
-       powernow_table = kzalloc((number_scales + 1) * (sizeof(struct cpufreq_frequency_table)), GFP_KERNEL);
+       powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) *
+                               (number_scales + 1)), GFP_KERNEL);
        if (!powernow_table) {
                retval = -ENOMEM;
                goto err2;
@@ -352,7 +365,7 @@ static int powernow_acpi_init(void)
                unsigned int speed, speed_mhz;
 
                pc.val = (unsigned long) state->control;
-               dprintk ("acpi:  P%d: %d MHz %d mW %d uS control %08x SGTC %d\n",
+               dprintk("acpi:  P%d: %d MHz %d mW %d uS control %08x SGTC %d\n",
                         i,
                         (u32) state->core_frequency,
                         (u32) state->power,
@@ -381,12 +394,12 @@ static int powernow_acpi_init(void)
                if (speed % 1000 > 0)
                        speed_mhz++;
 
-               if ((fid_codes[fid] % 10)==5) {
+               if ((fid_codes[fid] % 10) == 5) {
                        if (have_a0 == 1)
-                               powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID;
+                               invalidate_entry(i);
                }
 
-               dprintk ("   FID: 0x%x (%d.%dx [%dMHz])  "
+               dprintk("   FID: 0x%x (%d.%dx [%dMHz])  "
                         "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10,
                         fid_codes[fid] % 10, speed_mhz, vid,
                         mobile_vid_table[vid]/1000,
@@ -422,7 +435,8 @@ err1:
 err05:
        kfree(acpi_processor_perf);
 err0:
-       printk(KERN_WARNING PFX "ACPI perflib can not be used in this platform\n");
+       printk(KERN_WARNING PFX "ACPI perflib can not be used on "
+                       "this platform\n");
        acpi_processor_perf = NULL;
        return retval;
 }
@@ -435,7 +449,14 @@ static int powernow_acpi_init(void)
 }
 #endif
 
-static int powernow_decode_bios (int maxfid, int startvid)
+static void print_pst_entry(struct pst_s *pst, unsigned int j)
+{
+       dprintk("PST:%d (@%p)\n", j, pst);
+       dprintk(" cpuid: 0x%x  fsb: %d  maxFID: 0x%x  startvid: 0x%x\n",
+               pst->cpuid, pst->fsbspeed, pst->maxfid, pst->startvid);
+}
+
+static int powernow_decode_bios(int maxfid, int startvid)
 {
        struct psb_s *psb;
        struct pst_s *pst;
@@ -446,61 +467,67 @@ static int powernow_decode_bios (int maxfid, int startvid)
 
        etuple = cpuid_eax(0x80000001);
 
-       for (i=0xC0000; i < 0xffff0 ; i+=16) {
+       for (i = 0xC0000; i < 0xffff0 ; i += 16) {
 
                p = phys_to_virt(i);
 
-               if (memcmp(p, "AMDK7PNOW!",  10) == 0){
-                       dprintk ("Found PSB header at %p\n", p);
+               if (memcmp(p, "AMDK7PNOW!",  10) == 0) {
+                       dprintk("Found PSB header at %p\n", p);
                        psb = (struct psb_s *) p;
-                       dprintk ("Table version: 0x%x\n", psb->tableversion);
+                       dprintk("Table version: 0x%x\n", psb->tableversion);
                        if (psb->tableversion != 0x12) {
-                               printk (KERN_INFO PFX "Sorry, only v1.2 tables supported right now\n");
+                               printk(KERN_INFO PFX "Sorry, only v1.2 tables"
+                                               " supported right now\n");
                                return -ENODEV;
                        }
 
-                       dprintk ("Flags: 0x%x\n", psb->flags);
-                       if ((psb->flags & 1)==0) {
-                               dprintk ("Mobile voltage regulator\n");
-                       } else {
-                               dprintk ("Desktop voltage regulator\n");
-                       }
+                       dprintk("Flags: 0x%x\n", psb->flags);
+                       if ((psb->flags & 1) == 0)
+                               dprintk("Mobile voltage regulator\n");
+                       else
+                               dprintk("Desktop voltage regulator\n");
 
                        latency = psb->settlingtime;
                        if (latency < 100) {
-                               printk(KERN_INFO PFX "BIOS set settling time to %d microseconds. "
-                                               "Should be at least 100. Correcting.\n", latency);
+                               printk(KERN_INFO PFX "BIOS set settling time "
+                                               "to %d microseconds. "
+                                               "Should be at least 100. "
+                                               "Correcting.\n", latency);
                                latency = 100;
                        }
-                       dprintk ("Settling Time: %d microseconds.\n", psb->settlingtime);
-                       dprintk ("Has %d PST tables. (Only dumping ones relevant to this CPU).\n", psb->numpst);
+                       dprintk("Settling Time: %d microseconds.\n",
+                                       psb->settlingtime);
+                       dprintk("Has %d PST tables. (Only dumping ones "
+                                       "relevant to this CPU).\n",
+                                       psb->numpst);
 
-                       p += sizeof (struct psb_s);
+                       p += sizeof(struct psb_s);
 
                        pst = (struct pst_s *) p;
 
-                       for (j=0; j<psb->numpst; j++) {
+                       for (j = 0; j < psb->numpst; j++) {
                                pst = (struct pst_s *) p;
                                number_scales = pst->numpstates;
 
-                               if ((etuple == pst->cpuid) && check_fsb(pst->fsbspeed) &&
-                                   (maxfid==pst->maxfid) && (startvid==pst->startvid))
-                               {
-                                       dprintk ("PST:%d (@%p)\n", j, pst);
-                                       dprintk (" cpuid: 0x%x  fsb: %d  maxFID: 0x%x  startvid: 0x%x\n",
-                                                pst->cpuid, pst->fsbspeed, pst->maxfid, pst->startvid);
-
-                                       ret = get_ranges ((char *) pst + sizeof (struct pst_s));
+                               if ((etuple == pst->cpuid) &&
+                                   check_fsb(pst->fsbspeed) &&
+                                   (maxfid == pst->maxfid) &&
+                                   (startvid == pst->startvid)) {
+                                       print_pst_entry(pst, j);
+                                       p = (char *)pst + sizeof(struct pst_s);
+                                       ret = get_ranges(p);
                                        return ret;
                                } else {
                                        unsigned int k;
-                                       p = (char *) pst + sizeof (struct pst_s);
-                                       for (k=0; k<number_scales; k++)
-                                               p+=2;
+                                       p = (char *)pst + sizeof(struct pst_s);
+                                       for (k = 0; k < number_scales; k++)
+                                               p += 2;
                                }
                        }
-                       printk (KERN_INFO PFX "No PST tables match this cpuid (0x%x)\n", etuple);
-                       printk (KERN_INFO PFX "This is indicative of a broken BIOS.\n");
+                       printk(KERN_INFO PFX "No PST tables match this cpuid "
+                                       "(0x%x)\n", etuple);
+                       printk(KERN_INFO PFX "This is indicative of a broken "
+                                       "BIOS.\n");
 
                        return -EINVAL;
                }
@@ -511,13 +538,14 @@ static int powernow_decode_bios (int maxfid, int startvid)
 }
 
 
-static int powernow_target (struct cpufreq_policy *policy,
+static int powernow_target(struct cpufreq_policy *policy,
                            unsigned int target_freq,
                            unsigned int relation)
 {
        unsigned int newstate;
 
-       if (cpufreq_frequency_table_target(policy, powernow_table, target_freq, relation, &newstate))
+       if (cpufreq_frequency_table_target(policy, powernow_table, target_freq,
+                               relation, &newstate))
                return -EINVAL;
 
        change_speed(newstate);
@@ -526,7 +554,7 @@ static int powernow_target (struct cpufreq_policy *policy,
 }
 
 
-static int powernow_verify (struct cpufreq_policy *policy)
+static int powernow_verify(struct cpufreq_policy *policy)
 {
        return cpufreq_frequency_table_verify(policy, powernow_table);
 }
@@ -566,18 +594,23 @@ static unsigned int powernow_get(unsigned int cpu)
 
        if (cpu)
                return 0;
-       rdmsrl (MSR_K7_FID_VID_STATUS, fidvidstatus.val);
+       rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
        cfid = fidvidstatus.bits.CFID;
 
-       return (fsb * fid_codes[cfid] / 10);
+       return fsb * fid_codes[cfid] / 10;
 }
 
 
 static int __init acer_cpufreq_pst(const struct dmi_system_id *d)
 {
-       printk(KERN_WARNING "%s laptop with broken PST tables in BIOS detected.\n", d->ident);
-       printk(KERN_WARNING "You need to downgrade to 3A21 (09/09/2002), or try a newer BIOS than 3A71 (01/20/2003)\n");
-       printk(KERN_WARNING "cpufreq scaling has been disabled as a result of this.\n");
+       printk(KERN_WARNING PFX
+               "%s laptop with broken PST tables in BIOS detected.\n",
+               d->ident);
+       printk(KERN_WARNING PFX
+               "You need to downgrade to 3A21 (09/09/2002), or try a newer "
+               "BIOS than 3A71 (01/20/2003)\n");
+       printk(KERN_WARNING PFX
+               "cpufreq scaling has been disabled as a result of this.\n");
        return 0;
 }
 
@@ -598,7 +631,7 @@ static struct dmi_system_id __initdata powernow_dmi_table[] = {
        { }
 };
 
-static int __init powernow_cpu_init (struct cpufreq_policy *policy)
+static int __init powernow_cpu_init(struct cpufreq_policy *policy)
 {
        union msr_fidvidstatus fidvidstatus;
        int result;
@@ -606,7 +639,7 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
        if (policy->cpu != 0)
                return -ENODEV;
 
-       rdmsrl (MSR_K7_FID_VID_STATUS, fidvidstatus.val);
+       rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
 
        recalibrate_cpu_khz();
 
@@ -618,19 +651,21 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
        dprintk("FSB: %3dMHz\n", fsb/1000);
 
        if (dmi_check_system(powernow_dmi_table) || acpi_force) {
-               printk (KERN_INFO PFX "PSB/PST known to be broken.  Trying ACPI instead\n");
+               printk(KERN_INFO PFX "PSB/PST known to be broken.  "
+                               "Trying ACPI instead\n");
                result = powernow_acpi_init();
        } else {
-               result = powernow_decode_bios(fidvidstatus.bits.MFID, fidvidstatus.bits.SVID);
+               result = powernow_decode_bios(fidvidstatus.bits.MFID,
+                               fidvidstatus.bits.SVID);
                if (result) {
-                       printk (KERN_INFO PFX "Trying ACPI perflib\n");
+                       printk(KERN_INFO PFX "Trying ACPI perflib\n");
                        maximum_speed = 0;
                        minimum_speed = -1;
                        latency = 0;
                        result = powernow_acpi_init();
                        if (result) {
-                               printk (KERN_INFO PFX "ACPI and legacy methods failed\n");
-                               printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.html\n");
+                               printk(KERN_INFO PFX
+                                       "ACPI and legacy methods failed\n");
                        }
                } else {
                        /* SGTC use the bus clock as timer */
@@ -642,10 +677,11 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
        if (result)
                return result;
 
-       printk (KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n",
+       printk(KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n",
                                minimum_speed/1000, maximum_speed/1000);
 
-       policy->cpuinfo.transition_latency = cpufreq_scale(2000000UL, fsb, latency);
+       policy->cpuinfo.transition_latency =
+               cpufreq_scale(2000000UL, fsb, latency);
 
        policy->cur = powernow_get(0);
 
@@ -654,7 +690,8 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
        return cpufreq_frequency_table_cpuinfo(policy, powernow_table);
 }
 
-static int powernow_cpu_exit (struct cpufreq_policy *policy) {
+static int powernow_cpu_exit(struct cpufreq_policy *policy)
+{
        cpufreq_frequency_table_put_attr(policy->cpu);
 
 #ifdef CONFIG_X86_POWERNOW_K7_ACPI
@@ -669,7 +706,7 @@ static int powernow_cpu_exit (struct cpufreq_policy *policy) {
        return 0;
 }
 
-static struct freq_attrpowernow_table_attr[] = {
+static struct freq_attr *powernow_table_attr[] = {
        &cpufreq_freq_attr_scaling_available_freqs,
        NULL,
 };
@@ -685,15 +722,15 @@ static struct cpufreq_driver powernow_driver = {
        .attr   = powernow_table_attr,
 };
 
-static int __init powernow_init (void)
+static int __init powernow_init(void)
 {
-       if (check_powernow()==0)
+       if (check_powernow() == 0)
                return -ENODEV;
        return cpufreq_register_driver(&powernow_driver);
 }
 
 
-static void __exit powernow_exit (void)
+static void __exit powernow_exit(void)
 {
        cpufreq_unregister_driver(&powernow_driver);
 }
@@ -701,9 +738,9 @@ static void __exit powernow_exit (void)
 module_param(acpi_force,  int, 0444);
 MODULE_PARM_DESC(acpi_force, "Force ACPI to be used.");
 
-MODULE_AUTHOR ("Dave Jones <davej@redhat.com>");
-MODULE_DESCRIPTION ("Powernow driver for AMD K7 processors.");
-MODULE_LICENSE ("GPL");
+MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
+MODULE_DESCRIPTION("Powernow driver for AMD K7 processors.");
+MODULE_LICENSE("GPL");
 
 late_initcall(powernow_init);
 module_exit(powernow_exit);
index 6428aa17b40e794683b5359ed0589dc3dbfbf592..a15ac94e0b9b8c2ad1ee540fc7bad1b5415aff36 100644 (file)
 #include <linux/string.h>
 #include <linux/cpumask.h>
 #include <linux/sched.h>       /* for current / set_cpus_allowed() */
+#include <linux/io.h>
+#include <linux/delay.h>
 
 #include <asm/msr.h>
-#include <asm/io.h>
-#include <asm/delay.h>
 
-#ifdef CONFIG_X86_POWERNOW_K8_ACPI
 #include <linux/acpi.h>
 #include <linux/mutex.h>
 #include <acpi/processor.h>
-#endif
 
 #define PFX "powernow-k8: "
 #define VERSION "version 2.20.00"
@@ -71,7 +69,8 @@ static u32 find_khz_freq_from_fid(u32 fid)
        return 1000 * find_freq_from_fid(fid);
 }
 
-static u32 find_khz_freq_from_pstate(struct cpufreq_frequency_table *data, u32 pstate)
+static u32 find_khz_freq_from_pstate(struct cpufreq_frequency_table *data,
+               u32 pstate)
 {
        return data[pstate].frequency;
 }
@@ -186,7 +185,9 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
                return 1;
        }
 
-       lo = fid | (data->currvid << MSR_C_LO_VID_SHIFT) | MSR_C_LO_INIT_FID_VID;
+       lo = fid;
+       lo |= (data->currvid << MSR_C_LO_VID_SHIFT);
+       lo |= MSR_C_LO_INIT_FID_VID;
 
        dprintk("writing fid 0x%x, lo 0x%x, hi 0x%x\n",
                fid, lo, data->plllock * PLL_LOCK_CONVERSION);
@@ -194,7 +195,9 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
        do {
                wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION);
                if (i++ > 100) {
-                       printk(KERN_ERR PFX "Hardware error - pending bit very stuck - no further pstate changes possible\n");
+                       printk(KERN_ERR PFX
+                               "Hardware error - pending bit very stuck - "
+                               "no further pstate changes possible\n");
                        return 1;
                }
        } while (query_current_values_with_pending_wait(data));
@@ -202,14 +205,16 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
        count_off_irt(data);
 
        if (savevid != data->currvid) {
-               printk(KERN_ERR PFX "vid change on fid trans, old 0x%x, new 0x%x\n",
-                      savevid, data->currvid);
+               printk(KERN_ERR PFX
+                       "vid change on fid trans, old 0x%x, new 0x%x\n",
+                       savevid, data->currvid);
                return 1;
        }
 
        if (fid != data->currfid) {
-               printk(KERN_ERR PFX "fid trans failed, fid 0x%x, curr 0x%x\n", fid,
-                       data->currfid);
+               printk(KERN_ERR PFX
+                       "fid trans failed, fid 0x%x, curr 0x%x\n", fid,
+                       data->currfid);
                return 1;
        }
 
@@ -228,7 +233,9 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
                return 1;
        }
 
-       lo = data->currfid | (vid << MSR_C_LO_VID_SHIFT) | MSR_C_LO_INIT_FID_VID;
+       lo = data->currfid;
+       lo |= (vid << MSR_C_LO_VID_SHIFT);
+       lo |= MSR_C_LO_INIT_FID_VID;
 
        dprintk("writing vid 0x%x, lo 0x%x, hi 0x%x\n",
                vid, lo, STOP_GRANT_5NS);
@@ -236,20 +243,24 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
        do {
                wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS);
                if (i++ > 100) {
-                       printk(KERN_ERR PFX "internal error - pending bit very stuck - no further pstate changes possible\n");
+                       printk(KERN_ERR PFX "internal error - pending bit "
+                                       "very stuck - no further pstate "
+                                       "changes possible\n");
                        return 1;
                }
        } while (query_current_values_with_pending_wait(data));
 
        if (savefid != data->currfid) {
-               printk(KERN_ERR PFX "fid changed on vid trans, old 0x%x new 0x%x\n",
+               printk(KERN_ERR PFX "fid changed on vid trans, old "
+                       "0x%x new 0x%x\n",
                       savefid, data->currfid);
                return 1;
        }
 
        if (vid != data->currvid) {
-               printk(KERN_ERR PFX "vid trans failed, vid 0x%x, curr 0x%x\n", vid,
-                               data->currvid);
+               printk(KERN_ERR PFX "vid trans failed, vid 0x%x, "
+                               "curr 0x%x\n",
+                               vid, data->currvid);
                return 1;
        }
 
@@ -261,7 +272,8 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
  * Decreasing vid codes represent increasing voltages:
  * vid of 0 is 1.550V, vid of 0x1e is 0.800V, vid of VID_OFF is off.
  */
-static int decrease_vid_code_by_step(struct powernow_k8_data *data, u32 reqvid, u32 step)
+static int decrease_vid_code_by_step(struct powernow_k8_data *data,
+               u32 reqvid, u32 step)
 {
        if ((data->currvid - reqvid) > step)
                reqvid = data->currvid - step;
@@ -283,7 +295,8 @@ static int transition_pstate(struct powernow_k8_data *data, u32 pstate)
 }
 
 /* Change Opteron/Athlon64 fid and vid, by the 3 phases. */
-static int transition_fid_vid(struct powernow_k8_data *data, u32 reqfid, u32 reqvid)
+static int transition_fid_vid(struct powernow_k8_data *data,
+               u32 reqfid, u32 reqvid)
 {
        if (core_voltage_pre_transition(data, reqvid))
                return 1;
@@ -298,7 +311,8 @@ static int transition_fid_vid(struct powernow_k8_data *data, u32 reqfid, u32 req
                return 1;
 
        if ((reqfid != data->currfid) || (reqvid != data->currvid)) {
-               printk(KERN_ERR PFX "failed (cpu%d): req 0x%x 0x%x, curr 0x%x 0x%x\n",
+               printk(KERN_ERR PFX "failed (cpu%d): req 0x%x 0x%x, "
+                               "curr 0x%x 0x%x\n",
                                smp_processor_id(),
                                reqfid, reqvid, data->currfid, data->currvid);
                return 1;
@@ -311,13 +325,15 @@ static int transition_fid_vid(struct powernow_k8_data *data, u32 reqfid, u32 req
 }
 
 /* Phase 1 - core voltage transition ... setup voltage */
-static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid)
+static int core_voltage_pre_transition(struct powernow_k8_data *data,
+               u32 reqvid)
 {
        u32 rvosteps = data->rvo;
        u32 savefid = data->currfid;
        u32 maxvid, lo;
 
-       dprintk("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, reqvid 0x%x, rvo 0x%x\n",
+       dprintk("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, "
+               "reqvid 0x%x, rvo 0x%x\n",
                smp_processor_id(),
                data->currfid, data->currvid, reqvid, data->rvo);
 
@@ -340,7 +356,7 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid
                } else {
                        dprintk("ph1: changing vid for rvo, req 0x%x\n",
                                data->currvid - 1);
-                       if (decrease_vid_code_by_step(data, data->currvid - 1, 1))
+                       if (decrease_vid_code_by_step(data, data->currvid-1, 1))
                                return 1;
                        rvosteps--;
                }
@@ -350,7 +366,8 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid
                return 1;
 
        if (savefid != data->currfid) {
-               printk(KERN_ERR PFX "ph1 err, currfid changed 0x%x\n", data->currfid);
+               printk(KERN_ERR PFX "ph1 err, currfid changed 0x%x\n",
+                               data->currfid);
                return 1;
        }
 
@@ -363,20 +380,24 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid
 /* Phase 2 - core frequency transition */
 static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
 {
-       u32 vcoreqfid, vcocurrfid, vcofiddiff, fid_interval, savevid = data->currvid;
+       u32 vcoreqfid, vcocurrfid, vcofiddiff;
+       u32 fid_interval, savevid = data->currvid;
 
-       if ((reqfid < HI_FID_TABLE_BOTTOM) && (data->currfid < HI_FID_TABLE_BOTTOM)) {
-               printk(KERN_ERR PFX "ph2: illegal lo-lo transition 0x%x 0x%x\n",
-                       reqfid, data->currfid);
+       if ((reqfid < HI_FID_TABLE_BOTTOM) &&
+           (data->currfid < HI_FID_TABLE_BOTTOM)) {
+               printk(KERN_ERR PFX "ph2: illegal lo-lo transition "
+                               "0x%x 0x%x\n", reqfid, data->currfid);
                return 1;
        }
 
        if (data->currfid == reqfid) {
-               printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n", data->currfid);
+               printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n",
+                               data->currfid);
                return 0;
        }
 
-       dprintk("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, reqfid 0x%x\n",
+       dprintk("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, "
+               "reqfid 0x%x\n",
                smp_processor_id(),
                data->currfid, data->currvid, reqfid);
 
@@ -390,14 +411,14 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
 
                if (reqfid > data->currfid) {
                        if (data->currfid > LO_FID_TABLE_TOP) {
-                               if (write_new_fid(data, data->currfid + fid_interval)) {
+                               if (write_new_fid(data,
+                                               data->currfid + fid_interval))
                                        return 1;
-                               }
                        } else {
                                if (write_new_fid
-                                   (data, 2 + convert_fid_to_vco_fid(data->currfid))) {
+                                   (data,
+                                    2 + convert_fid_to_vco_fid(data->currfid)))
                                        return 1;
-                               }
                        }
                } else {
                        if (write_new_fid(data, data->currfid - fid_interval))
@@ -417,7 +438,8 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
 
        if (data->currfid != reqfid) {
                printk(KERN_ERR PFX
-                       "ph2: mismatch, failed fid transition, curr 0x%x, req 0x%x\n",
+                       "ph2: mismatch, failed fid transition, "
+                       "curr 0x%x, req 0x%x\n",
                        data->currfid, reqfid);
                return 1;
        }
@@ -435,7 +457,8 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
 }
 
 /* Phase 3 - core voltage transition flow ... jump to the final vid. */
-static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvid)
+static int core_voltage_post_transition(struct powernow_k8_data *data,
+               u32 reqvid)
 {
        u32 savefid = data->currfid;
        u32 savereqvid = reqvid;
@@ -457,7 +480,8 @@ static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvi
 
                if (data->currvid != reqvid) {
                        printk(KERN_ERR PFX
-                              "ph3: failed vid transition\n, req 0x%x, curr 0x%x",
+                              "ph3: failed vid transition\n, "
+                              "req 0x%x, curr 0x%x",
                               reqvid, data->currvid);
                        return 1;
                }
@@ -508,7 +532,8 @@ static int check_supported_cpu(unsigned int cpu)
        if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) {
                if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) ||
                    ((eax & CPUID_XMOD) > CPUID_XMOD_REV_MASK)) {
-                       printk(KERN_INFO PFX "Processor cpuid %x not supported\n", eax);
+                       printk(KERN_INFO PFX
+                               "Processor cpuid %x not supported\n", eax);
                        goto out;
                }
 
@@ -520,8 +545,10 @@ static int check_supported_cpu(unsigned int cpu)
                }
 
                cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx);
-               if ((edx & P_STATE_TRANSITION_CAPABLE) != P_STATE_TRANSITION_CAPABLE) {
-                       printk(KERN_INFO PFX "Power state transitions not supported\n");
+               if ((edx & P_STATE_TRANSITION_CAPABLE)
+                       != P_STATE_TRANSITION_CAPABLE) {
+                       printk(KERN_INFO PFX
+                               "Power state transitions not supported\n");
                        goto out;
                }
        } else { /* must be a HW Pstate capable processor */
@@ -539,7 +566,8 @@ out:
        return rc;
 }
 
-static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8 maxvid)
+static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst,
+               u8 maxvid)
 {
        unsigned int j;
        u8 lastfid = 0xff;
@@ -550,12 +578,14 @@ static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8
                               j, pst[j].vid);
                        return -EINVAL;
                }
-               if (pst[j].vid < data->rvo) {   /* vid + rvo >= 0 */
+               if (pst[j].vid < data->rvo) {
+                       /* vid + rvo >= 0 */
                        printk(KERN_ERR FW_BUG PFX "0 vid exceeded with pstate"
                               " %d\n", j);
                        return -ENODEV;
                }
-               if (pst[j].vid < maxvid + data->rvo) {  /* vid + rvo >= maxvid */
+               if (pst[j].vid < maxvid + data->rvo) {
+                       /* vid + rvo >= maxvid */
                        printk(KERN_ERR FW_BUG PFX "maxvid exceeded with pstate"
                               " %d\n", j);
                        return -ENODEV;
@@ -579,23 +609,31 @@ static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8
                return -EINVAL;
        }
        if (lastfid > LO_FID_TABLE_TOP)
-               printk(KERN_INFO FW_BUG PFX  "first fid not from lo freq table\n");
+               printk(KERN_INFO FW_BUG PFX
+                       "first fid not from lo freq table\n");
 
        return 0;
 }
 
+static void invalidate_entry(struct powernow_k8_data *data, unsigned int entry)
+{
+       data->powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID;
+}
+
 static void print_basics(struct powernow_k8_data *data)
 {
        int j;
        for (j = 0; j < data->numps; j++) {
-               if (data->powernow_table[j].frequency != CPUFREQ_ENTRY_INVALID) {
+               if (data->powernow_table[j].frequency !=
+                               CPUFREQ_ENTRY_INVALID) {
                        if (cpu_family == CPU_HW_PSTATE) {
-                               printk(KERN_INFO PFX "   %d : pstate %d (%d MHz)\n",
-                                       j,
+                               printk(KERN_INFO PFX
+                                       "   %d : pstate %d (%d MHz)\n", j,
                                        data->powernow_table[j].index,
                                        data->powernow_table[j].frequency/1000);
                        } else {
-                               printk(KERN_INFO PFX "   %d : fid 0x%x (%d MHz), vid 0x%x\n",
+                               printk(KERN_INFO PFX
+                                       "   %d : fid 0x%x (%d MHz), vid 0x%x\n",
                                        j,
                                        data->powernow_table[j].index & 0xff,
                                        data->powernow_table[j].frequency/1000,
@@ -604,20 +642,25 @@ static void print_basics(struct powernow_k8_data *data)
                }
        }
        if (data->batps)
-               printk(KERN_INFO PFX "Only %d pstates on battery\n", data->batps);
+               printk(KERN_INFO PFX "Only %d pstates on battery\n",
+                               data->batps);
 }
 
-static int fill_powernow_table(struct powernow_k8_data *data, struct pst_s *pst, u8 maxvid)
+static int fill_powernow_table(struct powernow_k8_data *data,
+               struct pst_s *pst, u8 maxvid)
 {
        struct cpufreq_frequency_table *powernow_table;
        unsigned int j;
 
-       if (data->batps) {    /* use ACPI support to get full speed on mains power */
-               printk(KERN_WARNING PFX "Only %d pstates usable (use ACPI driver for full range\n", data->batps);
+       if (data->batps) {
+               /* use ACPI support to get full speed on mains power */
+               printk(KERN_WARNING PFX
+                       "Only %d pstates usable (use ACPI driver for full "
+                       "range\n", data->batps);
                data->numps = data->batps;
        }
 
-       for ( j=1; j<data->numps; j++ ) {
+       for (j = 1; j < data->numps; j++) {
                if (pst[j-1].fid >= pst[j].fid) {
                        printk(KERN_ERR PFX "PST out of sequence\n");
                        return -EINVAL;
@@ -640,9 +683,11 @@ static int fill_powernow_table(struct powernow_k8_data *data, struct pst_s *pst,
        }
 
        for (j = 0; j < data->numps; j++) {
+               int freq;
                powernow_table[j].index = pst[j].fid; /* lower 8 bits */
                powernow_table[j].index |= (pst[j].vid << 8); /* upper 8 bits */
-               powernow_table[j].frequency = find_khz_freq_from_fid(pst[j].fid);
+               freq = find_khz_freq_from_fid(pst[j].fid);
+               powernow_table[j].frequency = freq;
        }
        powernow_table[data->numps].frequency = CPUFREQ_TABLE_END;
        powernow_table[data->numps].index = 0;
@@ -658,7 +703,8 @@ static int fill_powernow_table(struct powernow_k8_data *data, struct pst_s *pst,
                print_basics(data);
 
        for (j = 0; j < data->numps; j++)
-               if ((pst[j].fid==data->currfid) && (pst[j].vid==data->currvid))
+               if ((pst[j].fid == data->currfid) &&
+                   (pst[j].vid == data->currvid))
                        return 0;
 
        dprintk("currfid/vid do not match PST, ignoring\n");
@@ -698,7 +744,8 @@ static int find_psb_table(struct powernow_k8_data *data)
                }
 
                data->vstable = psb->vstable;
-               dprintk("voltage stabilization time: %d(*20us)\n", data->vstable);
+               dprintk("voltage stabilization time: %d(*20us)\n",
+                               data->vstable);
 
                dprintk("flags2: 0x%x\n", psb->flags2);
                data->rvo = psb->flags2 & 3;
@@ -713,11 +760,12 @@ static int find_psb_table(struct powernow_k8_data *data)
 
                dprintk("numpst: 0x%x\n", psb->num_tables);
                cpst = psb->num_tables;
-               if ((psb->cpuid == 0x00000fc0) || (psb->cpuid == 0x00000fe0) ){
+               if ((psb->cpuid == 0x00000fc0) ||
+                   (psb->cpuid == 0x00000fe0)) {
                        thiscpuid = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
-                       if ((thiscpuid == 0x00000fc0) || (thiscpuid == 0x00000fe0) ) {
+                       if ((thiscpuid == 0x00000fc0) ||
+                           (thiscpuid == 0x00000fe0))
                                cpst = 1;
-                       }
                }
                if (cpst != 1) {
                        printk(KERN_ERR FW_BUG PFX "numpst must be 1\n");
@@ -732,7 +780,8 @@ static int find_psb_table(struct powernow_k8_data *data)
 
                data->numps = psb->numps;
                dprintk("numpstates: 0x%x\n", data->numps);
-               return fill_powernow_table(data, (struct pst_s *)(psb+1), maxvid);
+               return fill_powernow_table(data,
+                               (struct pst_s *)(psb+1), maxvid);
        }
        /*
         * If you see this message, complain to BIOS manufacturer. If
@@ -745,28 +794,31 @@ static int find_psb_table(struct powernow_k8_data *data)
         * BIOS and Kernel Developer's Guide, which is available on
         * www.amd.com
         */
-       printk(KERN_ERR PFX "BIOS error - no PSB or ACPI _PSS objects\n");
+       printk(KERN_ERR FW_BUG PFX "No PSB or ACPI _PSS objects\n");
        return -ENODEV;
 }
 
-#ifdef CONFIG_X86_POWERNOW_K8_ACPI
-static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index)
+static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data,
+               unsigned int index)
 {
+       acpi_integer control;
+
        if (!data->acpi_data.state_count || (cpu_family == CPU_HW_PSTATE))
                return;
 
-       data->irt = (data->acpi_data.states[index].control >> IRT_SHIFT) & IRT_MASK;
-       data->rvo = (data->acpi_data.states[index].control >> RVO_SHIFT) & RVO_MASK;
-       data->exttype = (data->acpi_data.states[index].control >> EXT_TYPE_SHIFT) & EXT_TYPE_MASK;
-       data->plllock = (data->acpi_data.states[index].control >> PLL_L_SHIFT) & PLL_L_MASK;
-       data->vidmvs = 1 << ((data->acpi_data.states[index].control >> MVS_SHIFT) & MVS_MASK);
-       data->vstable = (data->acpi_data.states[index].control >> VST_SHIFT) & VST_MASK;
-}
+       control = data->acpi_data.states[index].control; data->irt = (control
+                       >> IRT_SHIFT) & IRT_MASK; data->rvo = (control >>
+                               RVO_SHIFT) & RVO_MASK; data->exttype = (control
+                                       >> EXT_TYPE_SHIFT) & EXT_TYPE_MASK;
+       data->plllock = (control >> PLL_L_SHIFT) & PLL_L_MASK; data->vidmvs = 1
+               << ((control >> MVS_SHIFT) & MVS_MASK); data->vstable =
+               (control >> VST_SHIFT) & VST_MASK; }
 
 static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
 {
        struct cpufreq_frequency_table *powernow_table;
        int ret_val = -ENODEV;
+       acpi_integer space_id;
 
        if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) {
                dprintk("register performance failed: bad ACPI data\n");
@@ -779,11 +831,12 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
                goto err_out;
        }
 
-       if ((data->acpi_data.control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) ||
-               (data->acpi_data.status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) {
+       space_id = data->acpi_data.control_register.space_id;
+       if ((space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) ||
+               (space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) {
                dprintk("Invalid control/status registers (%x - %x)\n",
                        data->acpi_data.control_register.space_id,
-                       data->acpi_data.status_register.space_id);
+                       space_id);
                goto err_out;
        }
 
@@ -802,7 +855,8 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
        if (ret_val)
                goto err_out_mem;
 
-       powernow_table[data->acpi_data.state_count].frequency = CPUFREQ_TABLE_END;
+       powernow_table[data->acpi_data.state_count].frequency =
+               CPUFREQ_TABLE_END;
        powernow_table[data->acpi_data.state_count].index = 0;
        data->powernow_table = powernow_table;
 
@@ -830,13 +884,15 @@ err_out_mem:
 err_out:
        acpi_processor_unregister_performance(&data->acpi_data, data->cpu);
 
-       /* data->acpi_data.state_count informs us at ->exit() whether ACPI was used */
+       /* data->acpi_data.state_count informs us at ->exit()
+        * whether ACPI was used */
        data->acpi_data.state_count = 0;
 
        return ret_val;
 }
 
-static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table)
+static int fill_powernow_table_pstate(struct powernow_k8_data *data,
+               struct cpufreq_frequency_table *powernow_table)
 {
        int i;
        u32 hi = 0, lo = 0;
@@ -848,84 +904,101 @@ static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpuf
 
                index = data->acpi_data.states[i].control & HW_PSTATE_MASK;
                if (index > data->max_hw_pstate) {
-                       printk(KERN_ERR PFX "invalid pstate %d - bad value %d.\n", i, index);
-                       printk(KERN_ERR PFX "Please report to BIOS manufacturer\n");
-                       powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID;
+                       printk(KERN_ERR PFX "invalid pstate %d - "
+                                       "bad value %d.\n", i, index);
+                       printk(KERN_ERR PFX "Please report to BIOS "
+                                       "manufacturer\n");
+                       invalidate_entry(data, i);
                        continue;
                }
                rdmsr(MSR_PSTATE_DEF_BASE + index, lo, hi);
                if (!(hi & HW_PSTATE_VALID_MASK)) {
                        dprintk("invalid pstate %d, ignoring\n", index);
-                       powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID;
+                       invalidate_entry(data, i);
                        continue;
                }
 
                powernow_table[i].index = index;
 
-               powernow_table[i].frequency = data->acpi_data.states[i].core_frequency * 1000;
+               powernow_table[i].frequency =
+                       data->acpi_data.states[i].core_frequency * 1000;
        }
        return 0;
 }
 
-static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table)
+static int fill_powernow_table_fidvid(struct powernow_k8_data *data,
+               struct cpufreq_frequency_table *powernow_table)
 {
        int i;
        int cntlofreq = 0;
+
        for (i = 0; i < data->acpi_data.state_count; i++) {
                u32 fid;
                u32 vid;
+               u32 freq, index;
+               acpi_integer status, control;
 
                if (data->exttype) {
-                       fid = data->acpi_data.states[i].status & EXT_FID_MASK;
-                       vid = (data->acpi_data.states[i].status >> VID_SHIFT) & EXT_VID_MASK;
+                       status =  data->acpi_data.states[i].status;
+                       fid = status & EXT_FID_MASK;
+                       vid = (status >> VID_SHIFT) & EXT_VID_MASK;
                } else {
-                       fid = data->acpi_data.states[i].control & FID_MASK;
-                       vid = (data->acpi_data.states[i].control >> VID_SHIFT) & VID_MASK;
+                       control =  data->acpi_data.states[i].control;
+                       fid = control & FID_MASK;
+                       vid = (control >> VID_SHIFT) & VID_MASK;
                }
 
                dprintk("   %d : fid 0x%x, vid 0x%x\n", i, fid, vid);
 
-               powernow_table[i].index = fid; /* lower 8 bits */
-               powernow_table[i].index |= (vid << 8); /* upper 8 bits */
-               powernow_table[i].frequency = find_khz_freq_from_fid(fid);
+               index = fid | (vid<<8);
+               powernow_table[i].index = index;
+
+               freq = find_khz_freq_from_fid(fid);
+               powernow_table[i].frequency = freq;
 
                /* verify frequency is OK */
-               if ((powernow_table[i].frequency > (MAX_FREQ * 1000)) ||
-                       (powernow_table[i].frequency < (MIN_FREQ * 1000))) {
-                       dprintk("invalid freq %u kHz, ignoring\n", powernow_table[i].frequency);
-                       powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID;
+               if ((freq > (MAX_FREQ * 1000)) || (freq < (MIN_FREQ * 1000))) {
+                       dprintk("invalid freq %u kHz, ignoring\n", freq);
+                       invalidate_entry(data, i);
                        continue;
                }
 
-               /* verify voltage is OK - BIOSs are using "off" to indicate invalid */
+               /* verify voltage is OK -
+                * BIOSs are using "off" to indicate invalid */
                if (vid == VID_OFF) {
                        dprintk("invalid vid %u, ignoring\n", vid);
-                       powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID;
+                       invalidate_entry(data, i);
                        continue;
                }
 
                /* verify only 1 entry from the lo frequency table */
                if (fid < HI_FID_TABLE_BOTTOM) {
                        if (cntlofreq) {
-                               /* if both entries are the same, ignore this one ... */
-                               if ((powernow_table[i].frequency != powernow_table[cntlofreq].frequency) ||
-                                   (powernow_table[i].index != powernow_table[cntlofreq].index)) {
-                                       printk(KERN_ERR PFX "Too many lo freq table entries\n");
+                               /* if both entries are the same,
+                                * ignore this one ... */
+                               if ((freq != powernow_table[cntlofreq].frequency) ||
+                                   (index != powernow_table[cntlofreq].index)) {
+                                       printk(KERN_ERR PFX
+                                               "Too many lo freq table "
+                                               "entries\n");
                                        return 1;
                                }
 
-                               dprintk("double low frequency table entry, ignoring it.\n");
-                               powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID;
+                               dprintk("double low frequency table entry, "
+                                               "ignoring it.\n");
+                               invalidate_entry(data, i);
                                continue;
                        } else
                                cntlofreq = i;
                }
 
-               if (powernow_table[i].frequency != (data->acpi_data.states[i].core_frequency * 1000)) {
-                       printk(KERN_INFO PFX "invalid freq entries %u kHz vs. %u kHz\n",
-                               powernow_table[i].frequency,
-                               (unsigned int) (data->acpi_data.states[i].core_frequency * 1000));
-                       powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID;
+               if (freq != (data->acpi_data.states[i].core_frequency * 1000)) {
+                       printk(KERN_INFO PFX "invalid freq entries "
+                               "%u kHz vs. %u kHz\n", freq,
+                               (unsigned int)
+                               (data->acpi_data.states[i].core_frequency
+                                * 1000));
+                       invalidate_entry(data, i);
                        continue;
                }
        }
@@ -935,7 +1008,8 @@ static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpuf
 static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data)
 {
        if (data->acpi_data.state_count)
-               acpi_processor_unregister_performance(&data->acpi_data, data->cpu);
+               acpi_processor_unregister_performance(&data->acpi_data,
+                               data->cpu);
        free_cpumask_var(data->acpi_data.shared_cpu_map);
 }
 
@@ -953,15 +1027,9 @@ static int get_transition_latency(struct powernow_k8_data *data)
        return 1000 * max_latency;
 }
 
-#else
-static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) { return -ENODEV; }
-static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) { return; }
-static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index) { return; }
-static int get_transition_latency(struct powernow_k8_data *data) { return 0; }
-#endif /* CONFIG_X86_POWERNOW_K8_ACPI */
-
 /* Take a frequency, and issue the fid/vid transition command */
-static int transition_frequency_fidvid(struct powernow_k8_data *data, unsigned int index)
+static int transition_frequency_fidvid(struct powernow_k8_data *data,
+               unsigned int index)
 {
        u32 fid = 0;
        u32 vid = 0;
@@ -989,7 +1057,8 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data, unsigned i
                return 0;
        }
 
-       if ((fid < HI_FID_TABLE_BOTTOM) && (data->currfid < HI_FID_TABLE_BOTTOM)) {
+       if ((fid < HI_FID_TABLE_BOTTOM) &&
+           (data->currfid < HI_FID_TABLE_BOTTOM)) {
                printk(KERN_ERR PFX
                       "ignoring illegal change in lo freq table-%x to 0x%x\n",
                       data->currfid, fid);
@@ -1017,7 +1086,8 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data, unsigned i
 }
 
 /* Take a frequency, and issue the hardware pstate transition command */
-static int transition_frequency_pstate(struct powernow_k8_data *data, unsigned int index)
+static int transition_frequency_pstate(struct powernow_k8_data *data,
+               unsigned int index)
 {
        u32 pstate = 0;
        int res, i;
@@ -1029,7 +1099,8 @@ static int transition_frequency_pstate(struct powernow_k8_data *data, unsigned i
        pstate = index & HW_PSTATE_MASK;
        if (pstate > data->max_hw_pstate)
                return 0;
-       freqs.old = find_khz_freq_from_pstate(data->powernow_table, data->currpstate);
+       freqs.old = find_khz_freq_from_pstate(data->powernow_table,
+                       data->currpstate);
        freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate);
 
        for_each_cpu_mask_nr(i, *(data->available_cores)) {
@@ -1048,7 +1119,8 @@ static int transition_frequency_pstate(struct powernow_k8_data *data, unsigned i
 }
 
 /* Driver entry point to switch to the target frequency */
-static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsigned relation)
+static int powernowk8_target(struct cpufreq_policy *pol,
+               unsigned targfreq, unsigned relation)
 {
        cpumask_t oldmask;
        struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
@@ -1087,14 +1159,18 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi
                dprintk("targ: curr fid 0x%x, vid 0x%x\n",
                data->currfid, data->currvid);
 
-               if ((checkvid != data->currvid) || (checkfid != data->currfid)) {
+               if ((checkvid != data->currvid) ||
+                   (checkfid != data->currfid)) {
                        printk(KERN_INFO PFX
-                               "error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n",
-                               checkfid, data->currfid, checkvid, data->currvid);
+                               "error - out of sync, fix 0x%x 0x%x, "
+                               "vid 0x%x 0x%x\n",
+                               checkfid, data->currfid,
+                               checkvid, data->currvid);
                }
        }
 
-       if (cpufreq_frequency_table_target(pol, data->powernow_table, targfreq, relation, &newstate))
+       if (cpufreq_frequency_table_target(pol, data->powernow_table,
+                               targfreq, relation, &newstate))
                goto err_out;
 
        mutex_lock(&fidvid_mutex);
@@ -1114,7 +1190,8 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi
        mutex_unlock(&fidvid_mutex);
 
        if (cpu_family == CPU_HW_PSTATE)
-               pol->cur = find_khz_freq_from_pstate(data->powernow_table, newstate);
+               pol->cur = find_khz_freq_from_pstate(data->powernow_table,
+                               newstate);
        else
                pol->cur = find_khz_freq_from_fid(data->currfid);
        ret = 0;
@@ -1141,6 +1218,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
        struct powernow_k8_data *data;
        cpumask_t oldmask;
        int rc;
+       static int print_once;
 
        if (!cpu_online(pol->cpu))
                return -ENODEV;
@@ -1163,33 +1241,31 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
                 * an UP version, and is deprecated by AMD.
                 */
                if (num_online_cpus() != 1) {
-#ifndef CONFIG_ACPI_PROCESSOR
-                       printk(KERN_ERR PFX "ACPI Processor support is required "
-                              "for SMP systems but is absent. Please load the "
-                              "ACPI Processor module before starting this "
-                              "driver.\n");
-#else
-                       printk(KERN_ERR FW_BUG PFX "Your BIOS does not provide"
-                              " ACPI _PSS objects in a way that Linux "
-                              "understands. Please report this to the Linux "
-                              "ACPI maintainers and complain to your BIOS "
-                              "vendor.\n");
-#endif
-                       kfree(data);
-                       return -ENODEV;
+                       /*
+                        * Replace this one with print_once as soon as such a
+                        * thing gets introduced
+                        */
+                       if (!print_once) {
+                               WARN_ONCE(1, KERN_ERR FW_BUG PFX "Your BIOS "
+                                       "does not provide ACPI _PSS objects "
+                                       "in a way that Linux understands. "
+                                       "Please report this to the Linux ACPI"
+                                       " maintainers and complain to your "
+                                       "BIOS vendor.\n");
+                               print_once++;
+                       }
+                       goto err_out;
                }
                if (pol->cpu != 0) {
                        printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for "
                               "CPU other than CPU0. Complain to your BIOS "
                               "vendor.\n");
-                       kfree(data);
-                       return -ENODEV;
+                       goto err_out;
                }
                rc = find_psb_table(data);
-               if (rc) {
-                       kfree(data);
-                       return -ENODEV;
-               }
+               if (rc)
+                       goto err_out;
+
                /* Take a crude guess here.
                 * That guess was in microseconds, so multiply with 1000 */
                pol->cpuinfo.transition_latency = (
@@ -1204,16 +1280,16 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
 
        if (smp_processor_id() != pol->cpu) {
                printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu);
-               goto err_out;
+               goto err_out_unmask;
        }
 
        if (pending_bit_stuck()) {
                printk(KERN_ERR PFX "failing init, change pending bit set\n");
-               goto err_out;
+               goto err_out_unmask;
        }
 
        if (query_current_values_with_pending_wait(data))
-               goto err_out;
+               goto err_out_unmask;
 
        if (cpu_family == CPU_OPTERON)
                fidvid_msr_init();
@@ -1228,7 +1304,8 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
        data->available_cores = pol->cpus;
 
        if (cpu_family == CPU_HW_PSTATE)
-               pol->cur = find_khz_freq_from_pstate(data->powernow_table, data->currpstate);
+               pol->cur = find_khz_freq_from_pstate(data->powernow_table,
+                               data->currpstate);
        else
                pol->cur = find_khz_freq_from_fid(data->currfid);
        dprintk("policy current frequency %d kHz\n", pol->cur);
@@ -1245,7 +1322,8 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
        cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu);
 
        if (cpu_family == CPU_HW_PSTATE)
-               dprintk("cpu_init done, current pstate 0x%x\n", data->currpstate);
+               dprintk("cpu_init done, current pstate 0x%x\n",
+                               data->currpstate);
        else
                dprintk("cpu_init done, current fid 0x%x, vid 0x%x\n",
                        data->currfid, data->currvid);
@@ -1254,15 +1332,16 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
 
        return 0;
 
-err_out:
+err_out_unmask:
        set_cpus_allowed_ptr(current, &oldmask);
        powernow_k8_cpu_exit_acpi(data);
 
+err_out:
        kfree(data);
        return -ENODEV;
 }
 
-static int __devexit powernowk8_cpu_exit (struct cpufreq_policy *pol)
+static int __devexit powernowk8_cpu_exit(struct cpufreq_policy *pol)
 {
        struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
 
@@ -1279,7 +1358,7 @@ static int __devexit powernowk8_cpu_exit (struct cpufreq_policy *pol)
        return 0;
 }
 
-static unsigned int powernowk8_get (unsigned int cpu)
+static unsigned int powernowk8_get(unsigned int cpu)
 {
        struct powernow_k8_data *data;
        cpumask_t oldmask = current->cpus_allowed;
@@ -1315,7 +1394,7 @@ out:
        return khz;
 }
 
-static struct freq_attrpowernow_k8_attr[] = {
+static struct freq_attr *powernow_k8_attr[] = {
        &cpufreq_freq_attr_scaling_available_freqs,
        NULL,
 };
@@ -1360,7 +1439,8 @@ static void __exit powernowk8_exit(void)
        cpufreq_unregister_driver(&cpufreq_amd64_driver);
 }
 
-MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and Mark Langsdorf <mark.langsdorf@amd.com>");
+MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and "
+               "Mark Langsdorf <mark.langsdorf@amd.com>");
 MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver.");
 MODULE_LICENSE("GPL");
 
index 8ecc75b6c7c3b39338ff2991bb413cedf94eebb9..6c6698feade15f7ab034d665874a8f4e4fde8384 100644 (file)
@@ -45,11 +45,10 @@ struct powernow_k8_data {
         * frequency is in kHz */
        struct cpufreq_frequency_table  *powernow_table;
 
-#ifdef CONFIG_X86_POWERNOW_K8_ACPI
        /* the acpi table needs to be kept. it's only available if ACPI was
         * used to determine valid frequency/vid/fid states */
        struct acpi_processor_performance acpi_data;
-#endif
+
        /* we need to keep track of associated cores, but let cpufreq
         * handle hotplug events - so just point at cpufreq pol->cpus
         * structure */
@@ -222,10 +221,8 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid);
 
 static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index);
 
-#ifdef CONFIG_X86_POWERNOW_K8_ACPI
 static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
 static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
-#endif
 
 #ifdef CONFIG_SMP
 static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[])
index 42da9bd677d6ee91ed3cb41f2b09c62d3bf5b26b..435a996a613a6cb3e1a5da201c45ff48b7ac9f3e 100644 (file)
 
 #include <linux/delay.h>
 #include <linux/cpufreq.h>
+#include <linux/timex.h>
+#include <linux/io.h>
 
 #include <asm/msr.h>
-#include <asm/timex.h>
-#include <asm/io.h>
 
 #define MMCR_BASE      0xfffef000      /* The default base address */
 #define OFFS_CPUCTL    0x2   /* CPU Control Register */
 
 static __u8 __iomem *cpuctl;
 
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "sc520_freq", msg)
+#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
+               "sc520_freq", msg)
+#define PFX "sc520_freq: "
 
 static struct cpufreq_frequency_table sc520_freq_table[] = {
        {0x01,  100000},
@@ -43,7 +45,8 @@ static unsigned int sc520_freq_get_cpu_frequency(unsigned int cpu)
 
        switch (clockspeed_reg & 0x03) {
        default:
-               printk(KERN_ERR "sc520_freq: error: cpuctl register has unexpected value %02x\n", clockspeed_reg);
+               printk(KERN_ERR PFX "error: cpuctl register has unexpected "
+                               "value %02x\n", clockspeed_reg);
        case 0x01:
                return 100000;
        case 0x02:
@@ -51,7 +54,7 @@ static unsigned int sc520_freq_get_cpu_frequency(unsigned int cpu)
        }
 }
 
-static void sc520_freq_set_cpu_state (unsigned int state)
+static void sc520_freq_set_cpu_state(unsigned int state)
 {
 
        struct cpufreq_freqs    freqs;
@@ -76,18 +79,19 @@ static void sc520_freq_set_cpu_state (unsigned int state)
        cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
 };
 
-static int sc520_freq_verify (struct cpufreq_policy *policy)
+static int sc520_freq_verify(struct cpufreq_policy *policy)
 {
        return cpufreq_frequency_table_verify(policy, &sc520_freq_table[0]);
 }
 
-static int sc520_freq_target (struct cpufreq_policy *policy,
+static int sc520_freq_target(struct cpufreq_policy *policy,
                            unsigned int target_freq,
                            unsigned int relation)
 {
        unsigned int newstate = 0;
 
-       if (cpufreq_frequency_table_target(policy, sc520_freq_table, target_freq, relation, &newstate))
+       if (cpufreq_frequency_table_target(policy, sc520_freq_table,
+                               target_freq, relation, &newstate))
                return -EINVAL;
 
        sc520_freq_set_cpu_state(newstate);
@@ -116,7 +120,7 @@ static int sc520_freq_cpu_init(struct cpufreq_policy *policy)
 
        result = cpufreq_frequency_table_cpuinfo(policy, sc520_freq_table);
        if (result)
-               return (result);
+               return result;
 
        cpufreq_frequency_table_get_attr(sc520_freq_table, policy->cpu);
 
@@ -131,7 +135,7 @@ static int sc520_freq_cpu_exit(struct cpufreq_policy *policy)
 }
 
 
-static struct freq_attrsc520_freq_attr[] = {
+static struct freq_attr *sc520_freq_attr[] = {
        &cpufreq_freq_attr_scaling_available_freqs,
        NULL,
 };
@@ -155,13 +159,13 @@ static int __init sc520_freq_init(void)
        int err;
 
        /* Test if we have the right hardware */
-       if(c->x86_vendor != X86_VENDOR_AMD ||
-                               c->x86 != 4 || c->x86_model != 9) {
+       if (c->x86_vendor != X86_VENDOR_AMD ||
+           c->x86 != 4 || c->x86_model != 9) {
                dprintk("no Elan SC520 processor found!\n");
                return -ENODEV;
        }
        cpuctl = ioremap((unsigned long)(MMCR_BASE + OFFS_CPUCTL), 1);
-       if(!cpuctl) {
+       if (!cpuctl) {
                printk(KERN_ERR "sc520_freq: error: failed to remap memory\n");
                return -ENOMEM;
        }
index dedc1e98f1683c4e35e0b194b81aed354ab3e55a..8bbb11adb3157d1e0d436910dd6b2423cec025ef 100644 (file)
@@ -39,7 +39,7 @@ static struct pci_dev *speedstep_chipset_dev;
 
 /* speedstep_processor
  */
-static unsigned int speedstep_processor = 0;
+static unsigned int speedstep_processor;
 
 static u32 pmbase;
 
@@ -54,7 +54,8 @@ static struct cpufreq_frequency_table speedstep_freqs[] = {
 };
 
 
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-ich", msg)
+#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
+               "speedstep-ich", msg)
 
 
 /**
@@ -62,7 +63,7 @@ static struct cpufreq_frequency_table speedstep_freqs[] = {
  *
  * Returns: -ENODEV if no register could be found
  */
-static int speedstep_find_register (void)
+static int speedstep_find_register(void)
 {
        if (!speedstep_chipset_dev)
                return -ENODEV;
@@ -90,7 +91,7 @@ static int speedstep_find_register (void)
  *
  *   Tries to change the SpeedStep state.
  */
-static void speedstep_set_state (unsigned int state)
+static void speedstep_set_state(unsigned int state)
 {
        u8 pm2_blk;
        u8 value;
@@ -133,11 +134,11 @@ static void speedstep_set_state (unsigned int state)
 
        dprintk("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value);
 
-       if (state == (value & 0x1)) {
-               dprintk("change to %u MHz succeeded\n", (speedstep_get_processor_frequency(speedstep_processor) / 1000));
-       } else {
-               printk (KERN_ERR "cpufreq: change failed - I/O error\n");
-       }
+       if (state == (value & 0x1))
+               dprintk("change to %u MHz succeeded\n",
+                       speedstep_get_frequency(speedstep_processor) / 1000);
+       else
+               printk(KERN_ERR "cpufreq: change failed - I/O error\n");
 
        return;
 }
@@ -149,7 +150,7 @@ static void speedstep_set_state (unsigned int state)
  *   Tries to activate the SpeedStep status and control registers.
  * Returns -EINVAL on an unsupported chipset, and zero on success.
  */
-static int speedstep_activate (void)
+static int speedstep_activate(void)
 {
        u16 value = 0;
 
@@ -175,20 +176,18 @@ static int speedstep_activate (void)
  * functions. Returns the SPEEDSTEP_CHIPSET_-number for the detected
  * chipset, or zero on failure.
  */
-static unsigned int speedstep_detect_chipset (void)
+static unsigned int speedstep_detect_chipset(void)
 {
        speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
                              PCI_DEVICE_ID_INTEL_82801DB_12,
-                             PCI_ANY_ID,
-                             PCI_ANY_ID,
+                             PCI_ANY_ID, PCI_ANY_ID,
                              NULL);
        if (speedstep_chipset_dev)
                return 4; /* 4-M */
 
        speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
                              PCI_DEVICE_ID_INTEL_82801CA_12,
-                             PCI_ANY_ID,
-                             PCI_ANY_ID,
+                             PCI_ANY_ID, PCI_ANY_ID,
                              NULL);
        if (speedstep_chipset_dev)
                return 3; /* 3-M */
@@ -196,8 +195,7 @@ static unsigned int speedstep_detect_chipset (void)
 
        speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
                              PCI_DEVICE_ID_INTEL_82801BA_10,
-                             PCI_ANY_ID,
-                             PCI_ANY_ID,
+                             PCI_ANY_ID, PCI_ANY_ID,
                              NULL);
        if (speedstep_chipset_dev) {
                /* speedstep.c causes lockups on Dell Inspirons 8000 and
@@ -208,8 +206,7 @@ static unsigned int speedstep_detect_chipset (void)
 
                hostbridge  = pci_get_subsys(PCI_VENDOR_ID_INTEL,
                              PCI_DEVICE_ID_INTEL_82815_MC,
-                             PCI_ANY_ID,
-                             PCI_ANY_ID,
+                             PCI_ANY_ID, PCI_ANY_ID,
                              NULL);
 
                if (!hostbridge)
@@ -236,7 +233,7 @@ static unsigned int _speedstep_get(const struct cpumask *cpus)
 
        cpus_allowed = current->cpus_allowed;
        set_cpus_allowed_ptr(current, cpus);
-       speed = speedstep_get_processor_frequency(speedstep_processor);
+       speed = speedstep_get_frequency(speedstep_processor);
        set_cpus_allowed_ptr(current, &cpus_allowed);
        dprintk("detected %u kHz as current frequency\n", speed);
        return speed;
@@ -251,11 +248,12 @@ static unsigned int speedstep_get(unsigned int cpu)
  * speedstep_target - set a new CPUFreq policy
  * @policy: new policy
  * @target_freq: the target frequency
- * @relation: how that frequency relates to achieved frequency (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
+ * @relation: how that frequency relates to achieved frequency
+ *     (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
  *
  * Sets a new CPUFreq policy.
  */
-static int speedstep_target (struct cpufreq_policy *policy,
+static int speedstep_target(struct cpufreq_policy *policy,
                             unsigned int target_freq,
                             unsigned int relation)
 {
@@ -264,7 +262,8 @@ static int speedstep_target (struct cpufreq_policy *policy,
        cpumask_t cpus_allowed;
        int i;
 
-       if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0], target_freq, relation, &newstate))
+       if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0],
+                               target_freq, relation, &newstate))
                return -EINVAL;
 
        freqs.old = _speedstep_get(policy->cpus);
@@ -308,7 +307,7 @@ static int speedstep_target (struct cpufreq_policy *policy,
  * Limit must be within speedstep_low_freq and speedstep_high_freq, with
  * at least one border included.
  */
-static int speedstep_verify (struct cpufreq_policy *policy)
+static int speedstep_verify(struct cpufreq_policy *policy)
 {
        return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]);
 }
@@ -344,7 +343,8 @@ static int speedstep_cpu_init(struct cpufreq_policy *policy)
                return -EIO;
 
        dprintk("currently at %s speed setting - %i MHz\n",
-               (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency) ? "low" : "high",
+               (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency)
+               ? "low" : "high",
                (speed / 1000));
 
        /* cpuinfo and default policy values */
@@ -352,9 +352,9 @@ static int speedstep_cpu_init(struct cpufreq_policy *policy)
 
        result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs);
        if (result)
-               return (result);
+               return result;
 
-        cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu);
+       cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu);
 
        return 0;
 }
@@ -366,7 +366,7 @@ static int speedstep_cpu_exit(struct cpufreq_policy *policy)
        return 0;
 }
 
-static struct freq_attrspeedstep_attr[] = {
+static struct freq_attr *speedstep_attr[] = {
        &cpufreq_freq_attr_scaling_available_freqs,
        NULL,
 };
@@ -396,13 +396,15 @@ static int __init speedstep_init(void)
        /* detect processor */
        speedstep_processor = speedstep_detect_processor();
        if (!speedstep_processor) {
-               dprintk("Intel(R) SpeedStep(TM) capable processor not found\n");
+               dprintk("Intel(R) SpeedStep(TM) capable processor "
+                               "not found\n");
                return -ENODEV;
        }
 
        /* detect chipset */
        if (!speedstep_detect_chipset()) {
-               dprintk("Intel(R) SpeedStep(TM) for this chipset not (yet) available.\n");
+               dprintk("Intel(R) SpeedStep(TM) for this chipset not "
+                               "(yet) available.\n");
                return -ENODEV;
        }
 
@@ -431,9 +433,11 @@ static void __exit speedstep_exit(void)
 }
 
 
-MODULE_AUTHOR ("Dave Jones <davej@redhat.com>, Dominik Brodowski <linux@brodo.de>");
-MODULE_DESCRIPTION ("Speedstep driver for Intel mobile processors on chipsets with ICH-M southbridges.");
-MODULE_LICENSE ("GPL");
+MODULE_AUTHOR("Dave Jones <davej@redhat.com>, "
+               "Dominik Brodowski <linux@brodo.de>");
+MODULE_DESCRIPTION("Speedstep driver for Intel mobile processors on chipsets "
+               "with ICH-M southbridges.");
+MODULE_LICENSE("GPL");
 
 module_init(speedstep_init);
 module_exit(speedstep_exit);
index cdac7d62369b645a00b15c41c4d617e78b86c3b1..2e3c6862657b2c0b61d5c445edc5bf6927cc626f 100644 (file)
 #include <linux/slab.h>
 
 #include <asm/msr.h>
+#include <asm/tsc.h>
 #include "speedstep-lib.h"
 
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-lib", msg)
+#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
+               "speedstep-lib", msg)
+
+#define PFX "speedstep-lib: "
 
 #ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK
-static int relaxed_check = 0;
+static int relaxed_check;
 #else
 #define relaxed_check 0
 #endif
@@ -30,14 +34,14 @@ static int relaxed_check = 0;
  *                   GET PROCESSOR CORE SPEED IN KHZ                 *
  *********************************************************************/
 
-static unsigned int pentium3_get_frequency (unsigned int processor)
+static unsigned int pentium3_get_frequency(unsigned int processor)
 {
-        /* See table 14 of p3_ds.pdf and table 22 of 29834003.pdf */
+       /* See table 14 of p3_ds.pdf and table 22 of 29834003.pdf */
        struct {
                unsigned int ratio;     /* Frequency Multiplier (x10) */
                u8 bitmap;              /* power on configuration bits
                                        [27, 25:22] (in MSR 0x2a) */
-       } msr_decode_mult [] = {
+       } msr_decode_mult[] = {
                { 30, 0x01 },
                { 35, 0x05 },
                { 40, 0x02 },
@@ -52,7 +56,7 @@ static unsigned int pentium3_get_frequency (unsigned int processor)
                { 85, 0x26 },
                { 90, 0x20 },
                { 100, 0x2b },
-               { 0, 0xff }     /* error or unknown value */
+               { 0, 0xff }     /* error or unknown value */
        };
 
        /* PIII(-M) FSB settings: see table b1-b of 24547206.pdf */
@@ -60,7 +64,7 @@ static unsigned int pentium3_get_frequency (unsigned int processor)
                unsigned int value;     /* Front Side Bus speed in MHz */
                u8 bitmap;              /* power on configuration bits [18: 19]
                                        (in MSR 0x2a) */
-       } msr_decode_fsb [] = {
+       } msr_decode_fsb[] = {
                {  66, 0x0 },
                { 100, 0x2 },
                { 133, 0x1 },
@@ -85,7 +89,7 @@ static unsigned int pentium3_get_frequency (unsigned int processor)
        }
 
        /* decode the multiplier */
-       if (processor == SPEEDSTEP_PROCESSOR_PIII_C_EARLY) {
+       if (processor == SPEEDSTEP_CPU_PIII_C_EARLY) {
                dprintk("workaround for early PIIIs\n");
                msr_lo &= 0x03c00000;
        } else
@@ -97,9 +101,10 @@ static unsigned int pentium3_get_frequency (unsigned int processor)
                j++;
        }
 
-       dprintk("speed is %u\n", (msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100));
+       dprintk("speed is %u\n",
+               (msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100));
 
-       return (msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100);
+       return msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100;
 }
 
 
@@