it8212.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2011 Carl-Daniel Hailfinger
  5. * Copyright (C) 2012 Kyösti Mälkki <kyosti.malkki@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  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. #include <stdlib.h>
  21. #include "flash.h"
  22. #include "programmer.h"
  23. #include "hwaccess.h"
  24. static uint8_t *it8212_bar = NULL;
  25. #define PCI_VENDOR_ID_ITE 0x1283
  26. const struct dev_entry devs_it8212[] = {
  27. {PCI_VENDOR_ID_ITE, 0x8212, NT, "ITE", "8212F PATA RAID"},
  28. {},
  29. };
  30. #define IT8212_MEMMAP_SIZE (128 * 1024)
  31. #define IT8212_MEMMAP_MASK (IT8212_MEMMAP_SIZE - 1)
  32. static void it8212_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
  33. static uint8_t it8212_chip_readb(const struct flashctx *flash, const chipaddr addr);
  34. static const struct par_master par_master_it8212 = {
  35. .chip_readb = it8212_chip_readb,
  36. .chip_readw = fallback_chip_readw,
  37. .chip_readl = fallback_chip_readl,
  38. .chip_readn = fallback_chip_readn,
  39. .chip_writeb = it8212_chip_writeb,
  40. .chip_writew = fallback_chip_writew,
  41. .chip_writel = fallback_chip_writel,
  42. .chip_writen = fallback_chip_writen,
  43. };
  44. int it8212_init(void)
  45. {
  46. if (rget_io_perms())
  47. return 1;
  48. struct pci_dev *dev = pcidev_init(devs_it8212, PCI_ROM_ADDRESS);
  49. if (!dev)
  50. return 1;
  51. /* Bit 0 is address decode enable, 17-31 the base address, everything else reserved/zero. */
  52. uint32_t io_base_addr = pcidev_readbar(dev, PCI_ROM_ADDRESS) & 0xFFFFFFFE;
  53. if (!io_base_addr)
  54. return 1;
  55. it8212_bar = rphysmap("IT8212F flash", io_base_addr, IT8212_MEMMAP_SIZE);
  56. if (it8212_bar == ERROR_PTR)
  57. return 1;
  58. /* Restore ROM BAR decode state automatically at shutdown. */
  59. rpci_write_long(dev, PCI_ROM_ADDRESS, io_base_addr | 0x01);
  60. max_rom_decode.parallel = IT8212_MEMMAP_SIZE;
  61. register_par_master(&par_master_it8212, BUS_PARALLEL);
  62. return 0;
  63. }
  64. static void it8212_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
  65. {
  66. pci_mmio_writeb(val, it8212_bar + (addr & IT8212_MEMMAP_MASK));
  67. }
  68. static uint8_t it8212_chip_readb(const struct flashctx *flash, const chipaddr addr)
  69. {
  70. return pci_mmio_readb(it8212_bar + (addr & IT8212_MEMMAP_MASK));
  71. }