| 1 |
|
| 2 |
|
| 3 |
#include <amdblocks/acpimmio.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <device/pci_def.h> |
| 6 |
#include <device/device.h> |
| 7 |
|
| 8 |
|
| 9 |
#include <Porting.h> |
| 10 |
#include <AGESA.h> |
| 11 |
#include <amdlib.h> |
| 12 |
#include <northbridge/amd/pi/dimmSpd.h> |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
static int readSmbusByteData(int iobase, int address, char *buffer, int offset) |
| 20 |
{ |
| 21 |
unsigned int status; |
| 22 |
UINT64 limit; |
| 23 |
|
| 24 |
address |= 1; |
| 25 |
|
| 26 |
__outbyte(iobase + 0, 0xFF); |
| 27 |
__outbyte(iobase + 1, 0x1F); |
| 28 |
__outbyte(iobase + 3, offset); |
| 29 |
__outbyte(iobase + 4, address); |
| 30 |
__outbyte(iobase + 2, 0x48); |
| 31 |
|
| 32 |
|
| 33 |
limit = __rdtsc() + 2000000000 / 10; |
| 34 |
for (;;) |
| 35 |
{ |
| 36 |
status = __inbyte(iobase); |
| 37 |
if (__rdtsc() > limit) break; |
| 38 |
if ((status & 2) == 0) continue; |
| 39 |
if ((status & 1) == 1) continue; |
| 40 |
break; |
| 41 |
} |
| 42 |
|
| 43 |
buffer [0] = __inbyte(iobase + 5); |
| 44 |
if (status == 2) status = 0; |
| 45 |
return status; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
static int readSmbusByte(int iobase, int address, char *buffer) |
| 55 |
{ |
| 56 |
unsigned int status; |
| 57 |
UINT64 limit; |
| 58 |
|
| 59 |
__outbyte(iobase + 0, 0xFF); |
| 60 |
__outbyte(iobase + 2, 0x44); |
| 61 |
|
| 62 |
|
| 63 |
limit = __rdtsc() + 2000000000 / 10; |
| 64 |
for (;;) |
| 65 |
{ |
| 66 |
status = __inbyte(iobase); |
| 67 |
if (__rdtsc() > limit) break; |
| 68 |
if ((status & 2) == 0) continue; |
| 69 |
if ((status & 1) == 1) continue; |
| 70 |
break; |
| 71 |
} |
| 72 |
|
| 73 |
buffer [0] = __inbyte(iobase + 5); |
| 74 |
if (status == 2) status = 0; |
| 75 |
return status; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
static int readspd(int iobase, int SmbusSlaveAddress, char *buffer, int count) |
| 88 |
{ |
| 89 |
int index, error; |
| 90 |
|
| 91 |
printk(BIOS_SPEW, "-------------READING SPD-----------\n"); |
| 92 |
printk(BIOS_SPEW, "iobase: 0x%08X, SmbusSlave: 0x%08X, count: %d\n", |
| 93 |
iobase, SmbusSlaveAddress, count); |
| 94 |
|
| 95 |
|
| 96 |
error = readSmbusByteData(iobase, SmbusSlaveAddress, buffer, 0); |
| 97 |
|
| 98 |
if (error) { |
| 99 |
printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n"); |
| 100 |
return error; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
for (index = 1; index < count; index++) |
| 105 |
{ |
| 106 |
error = readSmbusByte(iobase, SmbusSlaveAddress, &buffer [index]); |
| 107 |
if (error) { |
| 108 |
printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n"); |
| 109 |
return error; |
| 110 |
} |
| 111 |
} |
| 112 |
printk(BIOS_SPEW, "\n"); |
| 113 |
printk(BIOS_SPEW, "-------------FINISHED READING SPD-----------\n"); |
| 114 |
|
| 115 |
return 0; |
| 116 |
} |
| 117 |
|
| 118 |
static void setupFch(int ioBase) |
| 119 |
{ |
| 120 |
pm_write16(0x2c, ioBase | 1); |
| 121 |
__outbyte(ioBase + 0x0E, 66000000 / 400000 / 4); |
| 122 |
} |
| 123 |
|
| 124 |
int hudson_readSpd(int spdAddress, char *buf, size_t len) |
| 125 |
{ |
| 126 |
int ioBase = 0xB00; |
| 127 |
setupFch(ioBase); |
| 128 |
return readspd(ioBase, spdAddress, buf, len); |
| 129 |
} |