drkaiser.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2009 Joerg Fischer <turboj@web.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. #include <stdlib.h>
  21. #include "flash.h"
  22. #include "programmer.h"
  23. #define PCI_VENDOR_ID_DRKAISER 0x1803
  24. #define PCI_MAGIC_DRKAISER_ADDR 0x50
  25. #define PCI_MAGIC_DRKAISER_VALUE 0xa971
  26. #define DRKAISER_MEMMAP_SIZE (1024 * 128)
  27. /* Mask to restrict flash accesses to the 128kB memory window. */
  28. #define DRKAISER_MEMMAP_MASK ((1 << 17) - 1)
  29. const struct pcidev_status drkaiser_pcidev[] = {
  30. {0x1803, 0x5057, OK, "Dr. Kaiser", "PC-Waechter (Actel FPGA)"},
  31. {},
  32. };
  33. static uint8_t *drkaiser_bar;
  34. static void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val,
  35. chipaddr addr);
  36. static uint8_t drkaiser_chip_readb(const struct flashctx *flash,
  37. const chipaddr addr);
  38. static const struct par_programmer par_programmer_drkaiser = {
  39. .chip_readb = drkaiser_chip_readb,
  40. .chip_readw = fallback_chip_readw,
  41. .chip_readl = fallback_chip_readl,
  42. .chip_readn = fallback_chip_readn,
  43. .chip_writeb = drkaiser_chip_writeb,
  44. .chip_writew = fallback_chip_writew,
  45. .chip_writel = fallback_chip_writel,
  46. .chip_writen = fallback_chip_writen,
  47. };
  48. static int drkaiser_shutdown(void *data)
  49. {
  50. physunmap(drkaiser_bar, DRKAISER_MEMMAP_SIZE);
  51. /* Flash write is disabled automatically by PCI restore. */
  52. pci_cleanup(pacc);
  53. release_io_perms();
  54. return 0;
  55. };
  56. int drkaiser_init(void)
  57. {
  58. uint32_t addr;
  59. get_io_perms();
  60. addr = pcidev_init(PCI_BASE_ADDRESS_2, drkaiser_pcidev);
  61. /* Write magic register to enable flash write. */
  62. rpci_write_word(pcidev_dev, PCI_MAGIC_DRKAISER_ADDR,
  63. PCI_MAGIC_DRKAISER_VALUE);
  64. /* Map 128kB flash memory window. */
  65. drkaiser_bar = physmap("Dr. Kaiser PC-Waechter flash memory",
  66. addr, DRKAISER_MEMMAP_SIZE);
  67. if (register_shutdown(drkaiser_shutdown, NULL))
  68. return 1;
  69. max_rom_decode.parallel = 128 * 1024;
  70. register_par_programmer(&par_programmer_drkaiser, BUS_PARALLEL);
  71. return 0;
  72. }
  73. void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
  74. {
  75. pci_mmio_writeb(val, drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK));
  76. }
  77. uint8_t drkaiser_chip_readb(const struct flashctx *flash, const chipaddr addr)
  78. {
  79. return pci_mmio_readb(drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK));
  80. }