28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/pci.h>
33 #include <linux/slab.h>
37 #define PFX KBUILD_MODNAME ": "
42 #define INTEL_RNG_HW_STATUS 0
43 #define INTEL_RNG_PRESENT 0x40
44 #define INTEL_RNG_ENABLED 0x01
45 #define INTEL_RNG_STATUS 1
46 #define INTEL_RNG_DATA_PRESENT 0x01
47 #define INTEL_RNG_DATA 2
52 #define INTEL_RNG_ADDR 0xFFBC015F
53 #define INTEL_RNG_ADDR_LEN 3
58 #define FWH_DEC_EN1_REG_OLD 0xe3
59 #define FWH_DEC_EN1_REG_NEW 0xd9
60 #define FWH_F8_EN_MASK 0x80
62 #define BIOS_CNTL_REG_OLD 0x4e
63 #define BIOS_CNTL_REG_NEW 0xdc
64 #define BIOS_CNTL_WRITE_ENABLE_MASK 0x01
65 #define BIOS_CNTL_LOCK_ENABLE_MASK 0x02
70 #define INTEL_FWH_ADDR 0xffff0000
71 #define INTEL_FWH_ADDR_LEN 2
76 #define INTEL_FWH_RESET_CMD 0xff
77 #define INTEL_FWH_READ_ID_CMD 0x90
82 #define INTEL_FWH_MANUFACTURER_CODE_ADDRESS 0x000000
83 #define INTEL_FWH_DEVICE_CODE_ADDRESS 0x000001
88 #define INTEL_FWH_MANUFACTURER_CODE 0x89
89 #define INTEL_FWH_DEVICE_CODE_8M 0xac
90 #define INTEL_FWH_DEVICE_CODE_4M 0xad
152 " positive value - skip if FWH space locked read-only\n"
153 " negative value - skip always");
164 return hwstatus_get(mem);
167 static int intel_rng_data_present(
struct hwrng *rng,
int wait)
172 for (
i = 0;
i < 20;
i++) {
182 static int intel_rng_data_read(
struct hwrng *rng,
u32 *data)
191 static int intel_rng_init(
struct hwrng *rng)
201 if ((
hw_status & INTEL_RNG_ENABLED) == 0) {
210 static void intel_rng_cleanup(
struct hwrng *rng)
217 hwstatus_set(mem,
hw_status & ~INTEL_RNG_ENABLED);
223 static struct hwrng intel_rng = {
225 .init = intel_rng_init,
226 .cleanup = intel_rng_cleanup,
227 .data_present = intel_rng_data_present,
228 .data_read = intel_rng_data_read,
240 static int __init intel_rng_hw_init(
void *_intel_rng_hw)
248 pci_write_config_byte(intel_rng_hw->
dev,
253 pci_write_config_byte(intel_rng_hw->
dev,
266 pci_write_config_byte(intel_rng_hw->
dev,
270 pci_write_config_byte(intel_rng_hw->
dev,
292 if (dev->
device < 0x2640) {
310 PFX "Firmware space is locked read-only. If you can't or\n"
311 PFX "don't want to disable this in firmware setup, and if\n"
312 PFX "you are certain that your system has a functional\n"
313 PFX "RNG, try using the 'no_fwh_detect' option.\n";
329 static int __init mod_init(
void)
336 struct intel_rng_hw *intel_rng_hw;
338 for (i = 0; !dev && pci_tbl[
i].
vendor; ++
i)
345 if (no_fwh_detect < 0) {
356 err = intel_init_hw_struct(intel_rng_hw, dev);
373 err = stop_machine(intel_rng_hw_init, intel_rng_hw,
NULL);
385 intel_rng.
priv = (
unsigned long)mem;
389 hw_status = hwstatus_get(mem);
407 static void __exit mod_exit(
void)