processor_enable.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. * Contains the processor specific flash enables and system settings.
  21. */
  22. #include "flash.h"
  23. #include "programmer.h"
  24. #if defined(__i386__) || defined(__x86_64__)
  25. int processor_flash_enable(void)
  26. {
  27. /* On x86, flash access is not processor specific except on
  28. * AMD Elan SC520, AMD Geode and maybe other SoC-style CPUs.
  29. * FIXME: Move enable_flash_cs5536 and get_flashbase_sc520 here.
  30. */
  31. return 0;
  32. }
  33. #else
  34. #if defined (__MIPSEL__) && defined (__linux)
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include <ctype.h>
  38. static int is_loongson(void)
  39. {
  40. FILE *cpuinfo;
  41. cpuinfo = fopen("/proc/cpuinfo", "rb");
  42. if (!cpuinfo)
  43. return 0;
  44. while (!feof(cpuinfo)) {
  45. char line[512], *ptr;
  46. if (fgets(line, sizeof(line), cpuinfo) == NULL)
  47. break;
  48. ptr = line;
  49. while (*ptr && isspace((unsigned char)*ptr))
  50. ptr++;
  51. /* "cpu" part appears only with some Linux versions. */
  52. if (strncmp(ptr, "cpu", strlen("cpu")) == 0)
  53. ptr += strlen("cpu");
  54. while (*ptr && isspace((unsigned char)*ptr))
  55. ptr++;
  56. if (strncmp(ptr, "model", strlen("model")) != 0)
  57. continue;
  58. ptr += strlen("model");
  59. while (*ptr && isspace((unsigned char)*ptr))
  60. ptr++;
  61. if (*ptr != ':')
  62. continue;
  63. ptr++;
  64. while (*ptr && isspace((unsigned char)*ptr))
  65. ptr++;
  66. fclose(cpuinfo);
  67. return (strncmp(ptr, "ICT Loongson-2 V0.3",
  68. strlen("ICT Loongson-2 V0.3")) == 0)
  69. || (strncmp(ptr, "Godson2 V0.3 FPU V0.1",
  70. strlen("Godson2 V0.3 FPU V0.1")) == 0);
  71. }
  72. fclose(cpuinfo);
  73. return 0;
  74. }
  75. #endif
  76. int processor_flash_enable(void)
  77. {
  78. /* FIXME: detect loongson on FreeBSD and OpenBSD as well. */
  79. #if defined (__MIPSEL__) && defined (__linux)
  80. if (is_loongson()) {
  81. flashbase = 0x1fc00000;
  82. return 0;
  83. }
  84. #endif
  85. /* Not implemented yet. Oh well. */
  86. return 1;
  87. }
  88. #endif