satasii.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2009 Rudolf Marek <r.marek@assembler.cz>
  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. /* Datasheets can be found on http://www.siliconimage.com. Great thanks! */
  21. #include <stdlib.h>
  22. #include "flash.h"
  23. #include "programmer.h"
  24. #define PCI_VENDOR_ID_SII 0x1095
  25. #define SATASII_MEMMAP_SIZE 0x100
  26. uint8_t *sii_bar;
  27. static uint16_t id;
  28. const struct pcidev_status satas_sii[] = {
  29. {0x1095, 0x0680, OK, "Silicon Image", "PCI0680 Ultra ATA-133 Host Ctrl"},
  30. {0x1095, 0x3112, OK, "Silicon Image", "SiI 3112 [SATALink/SATARaid] SATA Ctrl"},
  31. {0x1095, 0x3114, OK, "Silicon Image", "SiI 3114 [SATALink/SATARaid] SATA Ctrl"},
  32. {0x1095, 0x3124, OK, "Silicon Image", "SiI 3124 PCI-X SATA Ctrl"},
  33. {0x1095, 0x3132, OK, "Silicon Image", "SiI 3132 SATA Raid II Ctrl"},
  34. {0x1095, 0x3512, OK, "Silicon Image", "SiI 3512 [SATALink/SATARaid] SATA Ctrl"},
  35. {},
  36. };
  37. static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val,
  38. chipaddr addr);
  39. static uint8_t satasii_chip_readb(const struct flashctx *flash,
  40. const chipaddr addr);
  41. static const struct par_programmer par_programmer_satasii = {
  42. .chip_readb = satasii_chip_readb,
  43. .chip_readw = fallback_chip_readw,
  44. .chip_readl = fallback_chip_readl,
  45. .chip_readn = fallback_chip_readn,
  46. .chip_writeb = satasii_chip_writeb,
  47. .chip_writew = fallback_chip_writew,
  48. .chip_writel = fallback_chip_writel,
  49. .chip_writen = fallback_chip_writen,
  50. };
  51. static int satasii_shutdown(void *data)
  52. {
  53. physunmap(sii_bar, SATASII_MEMMAP_SIZE);
  54. pci_cleanup(pacc);
  55. release_io_perms();
  56. return 0;
  57. }
  58. int satasii_init(void)
  59. {
  60. uint32_t addr;
  61. uint16_t reg_offset;
  62. get_io_perms();
  63. pcidev_init(PCI_BASE_ADDRESS_0, satas_sii);
  64. id = pcidev_dev->device_id;
  65. if ((id == 0x3132) || (id == 0x3124)) {
  66. addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_0) & ~0x07;
  67. reg_offset = 0x70;
  68. } else {
  69. addr = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_5) & ~0x07;
  70. reg_offset = 0x50;
  71. }
  72. sii_bar = physmap("SATA SIL registers", addr, SATASII_MEMMAP_SIZE) +
  73. reg_offset;
  74. /* Check if ROM cycle are OK. */
  75. if ((id != 0x0680) && (!(pci_mmio_readl(sii_bar) & (1 << 26))))
  76. msg_pinfo("Warning: Flash seems unconnected.\n");
  77. if (register_shutdown(satasii_shutdown, NULL))
  78. return 1;
  79. register_par_programmer(&par_programmer_satasii, BUS_PARALLEL);
  80. return 0;
  81. }
  82. void satasii_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
  83. {
  84. uint32_t ctrl_reg, data_reg;
  85. while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) ;
  86. /* Mask out unused/reserved bits, set writes and start transaction. */
  87. ctrl_reg &= 0xfcf80000;
  88. ctrl_reg |= (1 << 25) | (0 << 24) | ((uint32_t) addr & 0x7ffff);
  89. data_reg = (pci_mmio_readl((sii_bar + 4)) & ~0xff) | val;
  90. pci_mmio_writel(data_reg, (sii_bar + 4));
  91. pci_mmio_writel(ctrl_reg, sii_bar);
  92. while (pci_mmio_readl(sii_bar) & (1 << 25)) ;
  93. }
  94. uint8_t satasii_chip_readb(const struct flashctx *flash, const chipaddr addr)
  95. {
  96. uint32_t ctrl_reg;
  97. while ((ctrl_reg = pci_mmio_readl(sii_bar)) & (1 << 25)) ;
  98. /* Mask out unused/reserved bits, set reads and start transaction. */
  99. ctrl_reg &= 0xfcf80000;
  100. ctrl_reg |= (1 << 25) | (1 << 24) | ((uint32_t) addr & 0x7ffff);
  101. pci_mmio_writel(ctrl_reg, sii_bar);
  102. while (pci_mmio_readl(sii_bar) & (1 << 25)) ;
  103. return (pci_mmio_readl(sii_bar + 4)) & 0xff;
  104. }