27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/pci.h>
35 #define PFX KBUILD_MODNAME ": "
53 static struct pci_dev *amd_pdev;
56 static int amd_rng_data_present(
struct hwrng *rng,
int wait)
62 data = !!(
inl(pmbase + 0xF4) & 1);
70 static int amd_rng_data_read(
struct hwrng *rng,
u32 *data)
74 *data =
inl(pmbase + 0xF0);
79 static int amd_rng_init(
struct hwrng *rng)
83 pci_read_config_byte(amd_pdev, 0x40, &rnen);
85 pci_write_config_byte(amd_pdev, 0x40, rnen);
87 pci_read_config_byte(amd_pdev, 0x41, &rnen);
89 pci_write_config_byte(amd_pdev, 0x41, rnen);
94 static void amd_rng_cleanup(
struct hwrng *rng)
98 pci_read_config_byte(amd_pdev, 0x40, &rnen);
100 pci_write_config_byte(amd_pdev, 0x40, rnen);
104 static struct hwrng amd_rng = {
106 .init = amd_rng_init,
107 .cleanup = amd_rng_cleanup,
108 .data_present = amd_rng_data_present,
109 .data_read = amd_rng_data_read,
113 static int __init mod_init(
void)
129 err = pci_read_config_dword(pdev, 0x58, &pmbase);
133 pmbase &= 0x0000FF00;
137 dev_err(&pdev->
dev,
"AMD HWRNG region 0x%x already in use!\n",
142 amd_rng.
priv = (
unsigned long)pmbase;
157 static void __exit mod_exit(
void)