Carl-Daniel Hailfinger | b5b161b | 2010-06-04 19:05:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Carl-Daniel Hailfinger |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Contains the processor specific flash enables and system settings. |
| 22 | */ |
| 23 | |
| 24 | #include "flash.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 25 | #include "programmer.h" |
Carl-Daniel Hailfinger | b5b161b | 2010-06-04 19:05:39 +0000 | [diff] [blame] | 26 | |
| 27 | #if defined(__i386__) || defined(__x86_64__) |
| 28 | |
| 29 | int processor_flash_enable(void) |
| 30 | { |
| 31 | /* On x86, flash access is not processor specific except on |
| 32 | * AMD Elan SC520, AMD Geode and maybe other SoC-style CPUs. |
| 33 | * FIXME: Move enable_flash_cs5536 and get_flashbase_sc520 here. |
| 34 | */ |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | #else |
| 39 | |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 40 | #if defined (__MIPSEL__) && defined (__linux) |
| 41 | #include <stdio.h> |
| 42 | #include <string.h> |
| 43 | #include <ctype.h> |
| 44 | |
| 45 | static int is_loongson(void) |
| 46 | { |
| 47 | FILE *cpuinfo; |
| 48 | cpuinfo = fopen("/proc/cpuinfo", "rb"); |
| 49 | if (!cpuinfo) |
| 50 | return 0; |
| 51 | while (!feof(cpuinfo)) { |
| 52 | char line[512], *ptr; |
| 53 | if (fgets(line, sizeof(line), cpuinfo) == NULL) |
| 54 | break; |
| 55 | ptr = line; |
Carl-Daniel Hailfinger | 9e3a6c4 | 2010-10-08 12:40:09 +0000 | [diff] [blame] | 56 | while (*ptr && isspace((unsigned char)*ptr)) |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 57 | ptr++; |
| 58 | /* "cpu" part appears only with some Linux versions. */ |
| 59 | if (strncmp(ptr, "cpu", sizeof("cpu") - 1) == 0) |
| 60 | ptr += sizeof("cpu") - 1; |
Carl-Daniel Hailfinger | 9e3a6c4 | 2010-10-08 12:40:09 +0000 | [diff] [blame] | 61 | while (*ptr && isspace((unsigned char)*ptr)) |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 62 | ptr++; |
| 63 | if (strncmp(ptr, "model", sizeof("model") - 1) != 0) |
| 64 | continue; |
| 65 | ptr += sizeof("model") - 1; |
Carl-Daniel Hailfinger | 9e3a6c4 | 2010-10-08 12:40:09 +0000 | [diff] [blame] | 66 | while (*ptr && isspace((unsigned char)*ptr)) |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 67 | ptr++; |
| 68 | if (*ptr != ':') |
| 69 | continue; |
| 70 | ptr++; |
Carl-Daniel Hailfinger | 9e3a6c4 | 2010-10-08 12:40:09 +0000 | [diff] [blame] | 71 | while (*ptr && isspace((unsigned char)*ptr)) |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 72 | ptr++; |
| 73 | fclose(cpuinfo); |
| 74 | return (strncmp(ptr, "ICT Loongson-2 V0.3", |
| 75 | sizeof("ICT Loongson-2 V0.3") - 1) == 0) |
| 76 | || (strncmp(ptr, "Godson2 V0.3 FPU V0.1", |
| 77 | sizeof("Godson2 V0.3 FPU V0.1") - 1) == 0); |
| 78 | } |
| 79 | fclose(cpuinfo); |
| 80 | return 0; |
| 81 | } |
| 82 | #endif |
| 83 | |
Carl-Daniel Hailfinger | b5b161b | 2010-06-04 19:05:39 +0000 | [diff] [blame] | 84 | int processor_flash_enable(void) |
| 85 | { |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 86 | /* FIXME: detect loongson on FreeBSD and OpenBSD as well. */ |
| 87 | #if defined (__MIPSEL__) && defined (__linux) |
| 88 | if (is_loongson()) { |
| 89 | flashbase = 0x1fc00000; |
| 90 | return 0; |
| 91 | } |
| 92 | #endif |
Carl-Daniel Hailfinger | b5b161b | 2010-06-04 19:05:39 +0000 | [diff] [blame] | 93 | /* Not implemented yet. Oh well. */ |
| 94 | return 1; |
| 95 | } |
| 96 | |
| 97 | #endif |