gfxnvidia.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2009 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. #include <stdlib.h>
  21. #include <string.h>
  22. #include "flash.h"
  23. #include "programmer.h"
  24. #define PCI_VENDOR_ID_NVIDIA 0x10de
  25. /* Mask to restrict flash accesses to a 128kB memory window.
  26. * FIXME: Is this size a one-fits-all or card dependent?
  27. */
  28. #define GFXNVIDIA_MEMMAP_MASK ((1 << 17) - 1)
  29. #define GFXNVIDIA_MEMMAP_SIZE (16 * 1024 * 1024)
  30. uint8_t *nvidia_bar;
  31. const struct pcidev_status gfx_nvidia[] = {
  32. {0x10de, 0x0010, NT, "NVIDIA", "Mutara V08 [NV2]" },
  33. {0x10de, 0x0018, NT, "NVIDIA", "RIVA 128" },
  34. {0x10de, 0x0020, NT, "NVIDIA", "RIVA TNT" },
  35. {0x10de, 0x0028, NT, "NVIDIA", "RIVA TNT2/TNT2 Pro" },
  36. {0x10de, 0x0029, NT, "NVIDIA", "RIVA TNT2 Ultra" },
  37. {0x10de, 0x002c, NT, "NVIDIA", "Vanta/Vanta LT" },
  38. {0x10de, 0x002d, OK, "NVIDIA", "RIVA TNT2 Model 64/Model 64 Pro" },
  39. {0x10de, 0x00a0, NT, "NVIDIA", "Aladdin TNT2" },
  40. {0x10de, 0x0100, NT, "NVIDIA", "GeForce 256" },
  41. {0x10de, 0x0101, NT, "NVIDIA", "GeForce DDR" },
  42. {0x10de, 0x0103, NT, "NVIDIA", "Quadro" },
  43. {0x10de, 0x0110, NT, "NVIDIA", "GeForce2 MX" },
  44. {0x10de, 0x0111, NT, "NVIDIA", "GeForce2 MX" },
  45. {0x10de, 0x0112, NT, "NVIDIA", "GeForce2 GO" },
  46. {0x10de, 0x0113, NT, "NVIDIA", "Quadro2 MXR" },
  47. {0x10de, 0x0150, NT, "NVIDIA", "GeForce2 GTS/Pro" },
  48. {0x10de, 0x0151, NT, "NVIDIA", "GeForce2 GTS" },
  49. {0x10de, 0x0152, NT, "NVIDIA", "GeForce2 Ultra" },
  50. {0x10de, 0x0153, NT, "NVIDIA", "Quadro2 Pro" },
  51. {0x10de, 0x0200, NT, "NVIDIA", "GeForce 3 nFX" },
  52. {0x10de, 0x0201, NT, "NVIDIA", "GeForce 3 nFX" },
  53. {0x10de, 0x0202, NT, "NVIDIA", "GeForce 3 nFX Ultra" },
  54. {0x10de, 0x0203, NT, "NVIDIA", "Quadro 3 DDC" },
  55. {},
  56. };
  57. static void gfxnvidia_chip_writeb(const struct flashctx *flash, uint8_t val,
  58. chipaddr addr);
  59. static uint8_t gfxnvidia_chip_readb(const struct flashctx *flash,
  60. const chipaddr addr);
  61. static const struct par_programmer par_programmer_gfxnvidia = {
  62. .chip_readb = gfxnvidia_chip_readb,
  63. .chip_readw = fallback_chip_readw,
  64. .chip_readl = fallback_chip_readl,
  65. .chip_readn = fallback_chip_readn,
  66. .chip_writeb = gfxnvidia_chip_writeb,
  67. .chip_writew = fallback_chip_writew,
  68. .chip_writel = fallback_chip_writel,
  69. .chip_writen = fallback_chip_writen,
  70. };
  71. static int gfxnvidia_shutdown(void *data)
  72. {
  73. physunmap(nvidia_bar, GFXNVIDIA_MEMMAP_SIZE);
  74. /* Flash interface access is disabled (and screen enabled) automatically
  75. * by PCI restore.
  76. */
  77. pci_cleanup(pacc);
  78. release_io_perms();
  79. return 0;
  80. }
  81. int gfxnvidia_init(void)
  82. {
  83. uint32_t reg32;
  84. get_io_perms();
  85. io_base_addr = pcidev_init(PCI_BASE_ADDRESS_0, gfx_nvidia);
  86. io_base_addr += 0x300000;
  87. msg_pinfo("Detected NVIDIA I/O base address: 0x%x.\n", io_base_addr);
  88. nvidia_bar = physmap("NVIDIA", io_base_addr, GFXNVIDIA_MEMMAP_SIZE);
  89. /* Must be done before rpci calls. */
  90. if (register_shutdown(gfxnvidia_shutdown, NULL))
  91. return 1;
  92. /* Allow access to flash interface (will disable screen). */
  93. reg32 = pci_read_long(pcidev_dev, 0x50);
  94. reg32 &= ~(1 << 0);
  95. rpci_write_long(pcidev_dev, 0x50, reg32);
  96. /* Write/erase doesn't work. */
  97. programmer_may_write = 0;
  98. register_par_programmer(&par_programmer_gfxnvidia, BUS_PARALLEL);
  99. return 0;
  100. }
  101. void gfxnvidia_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
  102. {
  103. pci_mmio_writeb(val, nvidia_bar + (addr & GFXNVIDIA_MEMMAP_MASK));
  104. }
  105. uint8_t gfxnvidia_chip_readb(const struct flashctx *flash, const chipaddr addr)
  106. {
  107. return pci_mmio_readb(nvidia_bar + (addr & GFXNVIDIA_MEMMAP_MASK));
  108. }