nicintel.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2011 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. /* Datasheet: http://download.intel.com/design/network/datashts/82559_Fast_Ethernet_Multifunction_PCI_Cardbus_Controller_Datasheet.pdf */
  20. #include <stdlib.h>
  21. #include "flash.h"
  22. #include "programmer.h"
  23. #include "hwaccess.h"
  24. uint8_t *nicintel_bar;
  25. uint8_t *nicintel_control_bar;
  26. const struct dev_entry nics_intel[] = {
  27. {PCI_VENDOR_ID_INTEL, 0x1209, NT, "Intel", "8255xER/82551IT Fast Ethernet Controller"},
  28. {PCI_VENDOR_ID_INTEL, 0x1229, OK, "Intel", "82557/8/9/0/1 Ethernet Pro 100"},
  29. {0},
  30. };
  31. /* Arbitrary limit, taken from the datasheet I just had lying around.
  32. * 128 kByte on the 82559 device. Or not. Depends on whom you ask.
  33. */
  34. #define NICINTEL_MEMMAP_SIZE (128 * 1024)
  35. #define NICINTEL_MEMMAP_MASK (NICINTEL_MEMMAP_SIZE - 1)
  36. #define NICINTEL_CONTROL_MEMMAP_SIZE 0x10
  37. #define CSR_FCR 0x0c
  38. static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val,
  39. chipaddr addr);
  40. static uint8_t nicintel_chip_readb(const struct flashctx *flash,
  41. const chipaddr addr);
  42. static const struct par_master par_master_nicintel = {
  43. .chip_readb = nicintel_chip_readb,
  44. .chip_readw = fallback_chip_readw,
  45. .chip_readl = fallback_chip_readl,
  46. .chip_readn = fallback_chip_readn,
  47. .chip_writeb = nicintel_chip_writeb,
  48. .chip_writew = fallback_chip_writew,
  49. .chip_writel = fallback_chip_writel,
  50. .chip_writen = fallback_chip_writen,
  51. };
  52. int nicintel_init(void)
  53. {
  54. struct pci_dev *dev = NULL;
  55. uintptr_t addr;
  56. /* Needed only for PCI accesses on some platforms.
  57. * FIXME: Refactor that into get_mem_perms/rget_io_perms/get_pci_perms?
  58. */
  59. if (rget_io_perms())
  60. return 1;
  61. /* FIXME: BAR2 is not available if the device uses the CardBus function. */
  62. dev = pcidev_init(nics_intel, PCI_BASE_ADDRESS_2);
  63. if (!dev)
  64. return 1;
  65. addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_2);
  66. if (!addr)
  67. return 1;
  68. nicintel_bar = rphysmap("Intel NIC flash", addr, NICINTEL_MEMMAP_SIZE);
  69. if (nicintel_bar == ERROR_PTR)
  70. return 1;
  71. addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0);
  72. if (!addr)
  73. return 1;
  74. nicintel_control_bar = rphysmap("Intel NIC control/status reg", addr, NICINTEL_CONTROL_MEMMAP_SIZE);
  75. if (nicintel_control_bar == ERROR_PTR)
  76. return 1;
  77. /* FIXME: This register is pretty undocumented in all publicly available
  78. * documentation from Intel. Let me quote the complete info we have:
  79. * "Flash Control Register: The Flash Control register allows the CPU to
  80. * enable writes to an external Flash. The Flash Control Register is a
  81. * 32-bit field that allows access to an external Flash device."
  82. * Ah yes, we also know where it is, but we have absolutely _no_ idea
  83. * what we should do with it. Write 0x0001 because we have nothing
  84. * better to do with our time.
  85. */
  86. pci_rmmio_writew(0x0001, nicintel_control_bar + CSR_FCR);
  87. max_rom_decode.parallel = NICINTEL_MEMMAP_SIZE;
  88. register_par_master(&par_master_nicintel, BUS_PARALLEL);
  89. return 0;
  90. }
  91. static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val,
  92. chipaddr addr)
  93. {
  94. pci_mmio_writeb(val, nicintel_bar + (addr & NICINTEL_MEMMAP_MASK));
  95. }
  96. static uint8_t nicintel_chip_readb(const struct flashctx *flash,
  97. const chipaddr addr)
  98. {
  99. return pci_mmio_readb(nicintel_bar + (addr & NICINTEL_MEMMAP_MASK));
  100. }