| 122 | | #ifdef TS5300 |
| 123 | | // FIXME: Wrong place for this decision |
| 124 | | // FIXME: This should be autodetected. It is trivial. |
| 125 | | flash_baseaddr = 0x9400000; |
| 126 | | #else |
| | 122 | |
| | 123 | // FIXME Calculating the flash base address now. This is the |
| | 124 | // wrong place to do this. |
| | 125 | |
| | 126 | /* Usually on the x86 architectures (and on other PC-like |
| | 127 | * platforms like some Alphas or Itanium) the system flash |
| | 128 | * is mapped right below 4G. |
| | 129 | * On the AMD Elan SC520 only a small piece of the system flash |
| | 130 | * is mapped there, but the complete flash is mapped somewhere |
| | 131 | * below 1G. The position can be determined by the BOOTCS PAR |
| | 132 | * register |
| | 133 | */ |
| | 134 | |
| | 135 | /* Assume default PC architecture */ |
| | 138 | if (pci_dev_find(0x1022, 0x3000) != NULL) { /* Elan SC520 */ |
| | 139 | int i, bootcs_found = 0; |
| | 140 | uint32_t parx = 0; |
| | 141 | void *mmcr; |
| | 142 | |
| | 143 | /* 1. Map MMCR */ |
| | 144 | mmcr = mmap(0, getpagesize(), PROT_WRITE | PROT_READ, |
| | 145 | MAP_SHARED, fd_mem, (off_t)0xFFFEF000); |
| | 146 | |
| | 147 | if (mmcr == MAP_FAILED) { |
| | 148 | perror("Can't mmap Elan SC520 specific registers using " MEM_DEV); |
| | 149 | exit(1); |
| | 150 | } |
| | 151 | |
| | 152 | /* 2. Scan PAR0 (0x88) - PAR15 (0xc4) for |
| | 153 | * BOOTCS region (PARx[31:29] = 100b) |
| | 154 | */ |
| | 155 | for (i = 0x88; i <= 0xc4; i += 4) { |
| | 156 | parx = *(volatile uint32_t *)(mmcr + i); |
| | 157 | if ((parx >> 29) == 4) { |
| | 158 | bootcs_found = 1; |
| | 159 | break; /* BOOTCS found */ |
| | 160 | } |
| | 161 | } |
| | 162 | |
| | 163 | /* 3. PARx[25] = 1b --> flash_baseaddr[29:16] = PARx[13:0] |
| | 164 | * PARx[25] = 0b --> flash_baseaddr[29:12] = PARx[17:0] |
| | 165 | */ |
| | 166 | if (bootcs_found) { |
| | 167 | if (parx & (1 << 25)) { |
| | 168 | parx &= (1 << 14) - 1; /* Mask [13:0] */ |
| | 169 | flash_baseaddr = parx << 16; |
| | 170 | } else { |
| | 171 | parx &= (1 << 18) - 1; /* Mask [17:0] */ |
| | 172 | flash_baseaddr = parx << 12; |
| | 173 | } |
| | 174 | } else { |
| | 175 | printf("AMD Elan SC520 detected, but no BOOTCS. Assuming flash at 4G\n"); |
| | 176 | } |
| | 177 | |
| | 178 | /* 4. Clean up */ |
| | 179 | munmap (mmcr, getpagesize()); |
| | 180 | } |
| | 181 | |