atahpt.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #define BIOS_ROM_ADDR 0x90
  26. #define BIOS_ROM_DATA 0x94
  27. #define REG_FLASH_ACCESS 0x58
  28. #define PCI_VENDOR_ID_HPT 0x1103
  29. const struct pcidev_status ata_hpt[] = {
  30. {0x1103, 0x0004, NT, "Highpoint", "HPT366/368/370/370A/372/372N"},
  31. {0x1103, 0x0005, NT, "Highpoint", "HPT372A/372N"},
  32. {0x1103, 0x0006, NT, "Highpoint", "HPT302/302N"},
  33. {},
  34. };
  35. static void atahpt_chip_writeb(const struct flashctx *flash, uint8_t val,
  36. chipaddr addr);
  37. static uint8_t atahpt_chip_readb(const struct flashctx *flash,
  38. const chipaddr addr);
  39. static const struct par_programmer par_programmer_atahpt = {
  40. .chip_readb = atahpt_chip_readb,
  41. .chip_readw = fallback_chip_readw,
  42. .chip_readl = fallback_chip_readl,
  43. .chip_readn = fallback_chip_readn,
  44. .chip_writeb = atahpt_chip_writeb,
  45. .chip_writew = fallback_chip_writew,
  46. .chip_writel = fallback_chip_writel,
  47. .chip_writen = fallback_chip_writen,
  48. };
  49. static int atahpt_shutdown(void *data)
  50. {
  51. /* Flash access is disabled automatically by PCI restore. */
  52. pci_cleanup(pacc);
  53. release_io_perms();
  54. return 0;
  55. }
  56. int atahpt_init(void)
  57. {
  58. uint32_t reg32;
  59. get_io_perms();
  60. io_base_addr = pcidev_init(PCI_BASE_ADDRESS_4, ata_hpt);
  61. /* Enable flash access. */
  62. reg32 = pci_read_long(pcidev_dev, REG_FLASH_ACCESS);
  63. reg32 |= (1 << 24);
  64. rpci_write_long(pcidev_dev, REG_FLASH_ACCESS, reg32);
  65. if (register_shutdown(atahpt_shutdown, NULL))
  66. return 1;
  67. register_par_programmer(&par_programmer_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