atahpt.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2010 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 <string.h>
  23. #include "flash.h"
  24. #include "programmer.h"
  25. #include "hwaccess.h"
  26. #define BIOS_ROM_ADDR 0x90
  27. #define BIOS_ROM_DATA 0x94
  28. #define REG_FLASH_ACCESS 0x58
  29. #define PCI_VENDOR_ID_HPT 0x1103
  30. static uint32_t io_base_addr = 0;
  31. const struct dev_entry ata_hpt[] = {
  32. {0x1103, 0x0004, NT, "Highpoint", "HPT366/368/370/370A/372/372N"},
  33. {0x1103, 0x0005, NT, "Highpoint", "HPT372A/372N"},
  34. {0x1103, 0x0006, NT, "Highpoint", "HPT302/302N"},
  35. {0},
  36. };
  37. static void atahpt_chip_writeb(const struct flashctx *flash, uint8_t val,
  38. chipaddr addr);
  39. static uint8_t atahpt_chip_readb(const struct flashctx *flash,
  40. const chipaddr addr);
  41. static const struct par_master par_master_atahpt = {
  42. .chip_readb = atahpt_chip_readb,
  43. .chip_readw = fallback_chip_readw,
  44. .chip_readl = fallback_chip_readl,
  45. .chip_readn = fallback_chip_readn,
  46. .chip_writeb = atahpt_chip_writeb,
  47. .chip_writew = fallback_chip_writew,
  48. .chip_writel = fallback_chip_writel,
  49. .chip_writen = fallback_chip_writen,
  50. };
  51. int atahpt_init(void)
  52. {
  53. struct pci_dev *dev = NULL;
  54. uint32_t reg32;
  55. if (rget_io_perms())
  56. return 1;
  57. dev = pcidev_init(ata_hpt, PCI_BASE_ADDRESS_4);
  58. if (!dev)
  59. return 1;
  60. io_base_addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_4);
  61. if (!io_base_addr)
  62. return 1;
  63. /* Enable flash access. */
  64. reg32 = pci_read_long(dev, REG_FLASH_ACCESS);
  65. reg32 |= (1 << 24);
  66. rpci_write_long(dev, REG_FLASH_ACCESS, reg32);
  67. register_par_master(&par_master_atahpt, BUS_PARALLEL);
  68. return 0;
  69. }
  70. static void atahpt_chip_writeb(const struct flashctx *flash, uint8_t val,
  71. chipaddr addr)
  72. {
  73. OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
  74. OUTB(val, io_base_addr + BIOS_ROM_DATA);
  75. }
  76. static uint8_t atahpt_chip_readb(const struct flashctx *flash,
  77. const chipaddr addr)
  78. {
  79. OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
  80. return INB(io_base_addr + BIOS_ROM_DATA);
  81. }
  82. #else
  83. #error PCI port I/O access is not supported on this architecture yet.
  84. #endif