nic3com.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.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 BIOS_ROM_ADDR 0x04
  25. #define BIOS_ROM_DATA 0x08
  26. #define INT_STATUS 0x0e
  27. #define INTERNAL_CONFIG 0x00
  28. #define SELECT_REG_WINDOW 0x800
  29. #define PCI_VENDOR_ID_3COM 0x10b7
  30. static uint32_t internal_conf;
  31. static uint16_t id;
  32. const struct pcidev_status nics_3com[] = {
  33. /* 3C90xB */
  34. {0x10b7, 0x9055, OK, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-TX"},
  35. {0x10b7, 0x9001, NT, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-T4" },
  36. {0x10b7, 0x9004, OK, "3COM", "3C90xB: PCI 10BASE-T (TPO)" },
  37. {0x10b7, 0x9005, NT, "3COM", "3C90xB: PCI 10BASE-T/10BASE2/AUI (COMBO)" },
  38. {0x10b7, 0x9006, NT, "3COM", "3C90xB: PCI 10BASE-T/10BASE2 (TPC)" },
  39. {0x10b7, 0x900a, NT, "3COM", "3C90xB: PCI 10BASE-FL" },
  40. {0x10b7, 0x905a, NT, "3COM", "3C90xB: PCI 10BASE-FX" },
  41. {0x10b7, 0x9058, OK, "3COM", "3C905B: Cyclone 10/100/BNC" },
  42. /* 3C905C */
  43. {0x10b7, 0x9200, OK, "3COM", "3C905C: EtherLink 10/100 PCI (TX)" },
  44. /* 3C980C */
  45. {0x10b7, 0x9805, NT, "3COM", "3C980C: EtherLink Server 10/100 PCI (TX)" },
  46. {},
  47. };
  48. static void nic3com_chip_writeb(const struct flashctx *flash, uint8_t val,
  49. chipaddr addr);
  50. static uint8_t nic3com_chip_readb(const struct flashctx *flash,
  51. const chipaddr addr);
  52. static const struct par_programmer par_programmer_nic3com = {
  53. .chip_readb = nic3com_chip_readb,
  54. .chip_readw = fallback_chip_readw,
  55. .chip_readl = fallback_chip_readl,
  56. .chip_readn = fallback_chip_readn,
  57. .chip_writeb = nic3com_chip_writeb,
  58. .chip_writew = fallback_chip_writew,
  59. .chip_writel = fallback_chip_writel,
  60. .chip_writen = fallback_chip_writen,
  61. };
  62. static int nic3com_shutdown(void *data)
  63. {
  64. /* 3COM 3C90xB cards need a special fixup. */
  65. if (id == 0x9055 || id == 0x9001 || id == 0x9004 || id == 0x9005
  66. || id == 0x9006 || id == 0x900a || id == 0x905a || id == 0x9058) {
  67. /* Select register window 3 and restore the receiver status. */
  68. OUTW(SELECT_REG_WINDOW + 3, io_base_addr + INT_STATUS);
  69. OUTL(internal_conf, io_base_addr + INTERNAL_CONFIG);
  70. }
  71. pci_cleanup(pacc);
  72. release_io_perms();
  73. return 0;
  74. }
  75. int nic3com_init(void)
  76. {
  77. get_io_perms();
  78. io_base_addr = pcidev_init(PCI_BASE_ADDRESS_0, nics_3com);
  79. id = pcidev_dev->device_id;
  80. /* 3COM 3C90xB cards need a special fixup. */
  81. if (id == 0x9055 || id == 0x9001 || id == 0x9004 || id == 0x9005
  82. || id == 0x9006 || id == 0x900a || id == 0x905a || id == 0x9058) {
  83. /* Select register window 3 and save the receiver status. */
  84. OUTW(SELECT_REG_WINDOW + 3, io_base_addr + INT_STATUS);
  85. internal_conf = INL(io_base_addr + INTERNAL_CONFIG);
  86. /* Set receiver type to MII for full BIOS ROM access. */
  87. OUTL((internal_conf & 0xf00fffff) | 0x00600000, io_base_addr);
  88. }
  89. /*
  90. * The lowest 16 bytes of the I/O mapped register space of (most) 3COM
  91. * cards form a 'register window' into one of multiple (usually 8)
  92. * register banks. For 3C90xB/3C90xC we need register window/bank 0.
  93. */
  94. OUTW(SELECT_REG_WINDOW + 0, io_base_addr + INT_STATUS);
  95. if (register_shutdown(nic3com_shutdown, NULL))
  96. return 1;
  97. max_rom_decode.parallel = 128 * 1024;
  98. register_par_programmer(&par_programmer_nic3com, BUS_PARALLEL);
  99. return 0;
  100. }
  101. void nic3com_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
  102. {
  103. OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
  104. OUTB(val, io_base_addr + BIOS_ROM_DATA);
  105. }
  106. uint8_t nic3com_chip_readb(const struct flashctx *flash, const chipaddr addr)
  107. {
  108. OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
  109. return INB(io_base_addr + BIOS_ROM_DATA);
  110. }
  111. #else
  112. #error PCI port I/O access is not supported on this architecture yet.
  113. #endif