nicrealtek.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2009 Joerg Fischer <turboj@gmx.de>
  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; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #if defined(__i386__) || defined(__x86_64__)
  21. #include <stdlib.h>
  22. #include "flash.h"
  23. #include "programmer.h"
  24. #define PCI_VENDOR_ID_REALTEK 0x10ec
  25. #define PCI_VENDOR_ID_SMC1211 0x1113
  26. #define BIOS_ROM_ADDR 0xD4
  27. #define BIOS_ROM_DATA 0xD7
  28. const struct pcidev_status nics_realtek[] = {
  29. {0x10ec, 0x8139, OK, "Realtek", "RTL8139/8139C/8139C+"},
  30. {0x1113, 0x1211, OK, "SMC2", "1211TX"}, /* RTL8139 clone */
  31. {},
  32. };
  33. static void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val,
  34. chipaddr addr);
  35. static uint8_t nicrealtek_chip_readb(const struct flashctx *flash,
  36. const chipaddr addr);
  37. static const struct par_programmer par_programmer_nicrealtek = {
  38. .chip_readb = nicrealtek_chip_readb,
  39. .chip_readw = fallback_chip_readw,
  40. .chip_readl = fallback_chip_readl,
  41. .chip_readn = fallback_chip_readn,
  42. .chip_writeb = nicrealtek_chip_writeb,
  43. .chip_writew = fallback_chip_writew,
  44. .chip_writel = fallback_chip_writel,
  45. .chip_writen = fallback_chip_writen,
  46. };
  47. static int nicrealtek_shutdown(void *data)
  48. {
  49. /* FIXME: We forgot to disable software access again. */
  50. pci_cleanup(pacc);
  51. release_io_perms();
  52. return 0;
  53. }
  54. int nicrealtek_init(void)
  55. {
  56. get_io_perms();
  57. io_base_addr = pcidev_init(PCI_BASE_ADDRESS_0, nics_realtek);
  58. if (register_shutdown(nicrealtek_shutdown, NULL))
  59. return 1;
  60. register_par_programmer(&par_programmer_nicrealtek, BUS_PARALLEL);
  61. return 0;
  62. }
  63. void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
  64. {
  65. /* Output addr and data, set WE to 0, set OE to 1, set CS to 0,
  66. * enable software access.
  67. */
  68. OUTL(((uint32_t)addr & 0x01FFFF) | 0x0A0000 | (val << 24),
  69. io_base_addr + BIOS_ROM_ADDR);
  70. /* Output addr and data, set WE to 1, set OE to 1, set CS to 1,
  71. * enable software access.
  72. */
  73. OUTL(((uint32_t)addr & 0x01FFFF) | 0x1E0000 | (val << 24),
  74. io_base_addr + BIOS_ROM_ADDR);
  75. }
  76. uint8_t nicrealtek_chip_readb(const struct flashctx *flash, const chipaddr addr)
  77. {
  78. uint8_t val;
  79. /* FIXME: Can we skip reading the old data and simply use 0? */
  80. /* Read old data. */
  81. val = INB(io_base_addr + BIOS_ROM_DATA);
  82. /* Output new addr and old data, set WE to 1, set OE to 0, set CS to 0,
  83. * enable software access.
  84. */
  85. OUTL(((uint32_t)addr & 0x01FFFF) | 0x060000 | (val << 24),
  86. io_base_addr + BIOS_ROM_ADDR);
  87. /* Read new data. */
  88. val = INB(io_base_addr + BIOS_ROM_DATA);
  89. /* Output addr and new data, set WE to 1, set OE to 1, set CS to 1,
  90. * enable software access.
  91. */
  92. OUTL(((uint32_t)addr & 0x01FFFF) | 0x1E0000 | (val << 24),
  93. io_base_addr + BIOS_ROM_ADDR);
  94. return val;
  95. }
  96. #else
  97. #error PCI port I/O access is not supported on this architecture yet.
  98. #endif