2 * RNG driver for AMD RNGs
4 * Copyright 2005 (c) MontaVista Software, Inc.
6 * with the majority of the code coming from:
8 * Hardware driver for the Intel/AMD/VIA Random Number Generators (RNG)
9 * (c) Copyright 2003 Red Hat Inc <jgarzik@redhat.com>
13 * Hardware driver for the AMD 768 Random Number Generator (RNG)
14 * (c) Copyright 2001 Red Hat Inc <alan@redhat.com>
18 * Hardware driver for Intel i810 Random Number Generator (RNG)
19 * Copyright 2000,2001 Jeff Garzik <jgarzik@pobox.com>
20 * Copyright 2000,2001 Philipp Rumpf <prumpf@mandrakesoft.com>
22 * This file is licensed under the terms of the GNU General Public
23 * License version 2. This program is licensed "as is" without any
24 * warranty of any kind, whether express or implied.
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/pci.h>
30 #include <linux/hw_random.h>
34 #define PFX KBUILD_MODNAME ": "
38 * Data for PCI driver interface
40 * This data only exists for exporting the supported
41 * PCI ids via MODULE_DEVICE_TABLE. We do not actually
42 * register a pci_driver, because someone else might one day
43 * want to register another driver on the same PCI id.
45 static const struct pci_device_id pci_tbl
[] = {
46 { 0x1022, 0x7443, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0, },
47 { 0x1022, 0x746b, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0, },
48 { 0, }, /* terminate list */
50 MODULE_DEVICE_TABLE(pci
, pci_tbl
);
52 static struct pci_dev
*amd_pdev
;
55 static int amd_rng_data_present(struct hwrng
*rng
)
57 u32 pmbase
= (u32
)rng
->priv
;
59 return !!(inl(pmbase
+ 0xF4) & 1);
62 static int amd_rng_data_read(struct hwrng
*rng
, u32
*data
)
64 u32 pmbase
= (u32
)rng
->priv
;
66 *data
= inl(pmbase
+ 0xF0);
71 static int amd_rng_init(struct hwrng
*rng
)
75 pci_read_config_byte(amd_pdev
, 0x40, &rnen
);
76 rnen
|= (1 << 7); /* RNG on */
77 pci_write_config_byte(amd_pdev
, 0x40, rnen
);
79 pci_read_config_byte(amd_pdev
, 0x41, &rnen
);
80 rnen
|= (1 << 7); /* PMIO enable */
81 pci_write_config_byte(amd_pdev
, 0x41, rnen
);
86 static void amd_rng_cleanup(struct hwrng
*rng
)
90 pci_read_config_byte(amd_pdev
, 0x40, &rnen
);
91 rnen
&= ~(1 << 7); /* RNG off */
92 pci_write_config_byte(amd_pdev
, 0x40, rnen
);
96 static struct hwrng amd_rng
= {
99 .cleanup
= amd_rng_cleanup
,
100 .data_present
= amd_rng_data_present
,
101 .data_read
= amd_rng_data_read
,
105 static int __init
mod_init(void)
108 struct pci_dev
*pdev
= NULL
;
109 const struct pci_device_id
*ent
;
112 for_each_pci_dev(pdev
) {
113 ent
= pci_match_id(pci_tbl
, pdev
);
117 /* Device not found. */
121 err
= pci_read_config_dword(pdev
, 0x58, &pmbase
);
125 pmbase
&= 0x0000FF00;
128 amd_rng
.priv
= (unsigned long)pmbase
;
131 printk(KERN_INFO
"AMD768 RNG detected\n");
132 err
= hwrng_register(&amd_rng
);
134 printk(KERN_ERR PFX
"RNG registering failed (%d)\n",
142 static void __exit
mod_exit(void)
144 hwrng_unregister(&amd_rng
);
147 module_init(mod_init
);
148 module_exit(mod_exit
);
150 MODULE_AUTHOR("The Linux Kernel team");
151 MODULE_DESCRIPTION("H/W RNG driver for AMD chipsets");
152 MODULE_LICENSE("GPL");