uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 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. |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 19 | #include "flash.h" |
hailfinger | 428f685 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 20 | #include "programmer.h" |
Patrick Georgi | b6e26e6 | 2017-04-11 20:24:22 +0200 | [diff] [blame] | 21 | #include "hwaccess.h" |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 22 | |
| 23 | #define PCI_VENDOR_ID_NVIDIA 0x10de |
| 24 | |
hailfinger | 69422b8 | 2010-07-17 22:42:33 +0000 | [diff] [blame] | 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) |
dhendrix | 0ffc2eb | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 29 | #define GFXNVIDIA_MEMMAP_SIZE (16 * 1024 * 1024) |
hailfinger | 69422b8 | 2010-07-17 22:42:33 +0000 | [diff] [blame] | 30 | |
Edward O'Callaghan | ef4e28b | 2019-06-28 13:18:41 +1000 | [diff] [blame] | 31 | static uint8_t *nvidia_bar; |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 32 | |
Patrick Georgi | 8ae1657 | 2017-03-09 15:59:25 +0100 | [diff] [blame] | 33 | const struct dev_entry gfx_nvidia[] = { |
mkarcher | 6475d3f | 2010-02-24 00:04:40 +0000 | [diff] [blame] | 34 | {0x10de, 0x0010, NT, "NVIDIA", "Mutara V08 [NV2]" }, |
| 35 | {0x10de, 0x0018, NT, "NVIDIA", "RIVA 128" }, |
| 36 | {0x10de, 0x0020, NT, "NVIDIA", "RIVA TNT" }, |
| 37 | {0x10de, 0x0028, NT, "NVIDIA", "RIVA TNT2/TNT2 Pro" }, |
| 38 | {0x10de, 0x0029, NT, "NVIDIA", "RIVA TNT2 Ultra" }, |
| 39 | {0x10de, 0x002c, NT, "NVIDIA", "Vanta/Vanta LT" }, |
| 40 | {0x10de, 0x002d, OK, "NVIDIA", "RIVA TNT2 Model 64/Model 64 Pro" }, |
| 41 | {0x10de, 0x00a0, NT, "NVIDIA", "Aladdin TNT2" }, |
| 42 | {0x10de, 0x0100, NT, "NVIDIA", "GeForce 256" }, |
| 43 | {0x10de, 0x0101, NT, "NVIDIA", "GeForce DDR" }, |
| 44 | {0x10de, 0x0103, NT, "NVIDIA", "Quadro" }, |
| 45 | {0x10de, 0x0110, NT, "NVIDIA", "GeForce2 MX" }, |
| 46 | {0x10de, 0x0111, NT, "NVIDIA", "GeForce2 MX" }, |
| 47 | {0x10de, 0x0112, NT, "NVIDIA", "GeForce2 GO" }, |
| 48 | {0x10de, 0x0113, NT, "NVIDIA", "Quadro2 MXR" }, |
| 49 | {0x10de, 0x0150, NT, "NVIDIA", "GeForce2 GTS/Pro" }, |
| 50 | {0x10de, 0x0151, NT, "NVIDIA", "GeForce2 GTS" }, |
| 51 | {0x10de, 0x0152, NT, "NVIDIA", "GeForce2 Ultra" }, |
| 52 | {0x10de, 0x0153, NT, "NVIDIA", "Quadro2 Pro" }, |
| 53 | {0x10de, 0x0200, NT, "NVIDIA", "GeForce 3 nFX" }, |
| 54 | {0x10de, 0x0201, NT, "NVIDIA", "GeForce 3 nFX" }, |
| 55 | {0x10de, 0x0202, NT, "NVIDIA", "GeForce 3 nFX Ultra" }, |
| 56 | {0x10de, 0x0203, NT, "NVIDIA", "Quadro 3 DDC" }, |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 57 | |
Patrick Georgi | 8ddfee9 | 2017-03-20 14:54:28 +0100 | [diff] [blame] | 58 | {0}, |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 61 | static void gfxnvidia_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 62 | chipaddr addr); |
| 63 | static uint8_t gfxnvidia_chip_readb(const struct flashctx *flash, |
| 64 | const chipaddr addr); |
Patrick Georgi | 0a9533a | 2017-02-03 19:28:38 +0100 | [diff] [blame] | 65 | static const struct par_master par_master_gfxnvidia = { |
hailfinger | 76bb7e9 | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 66 | .chip_readb = gfxnvidia_chip_readb, |
| 67 | .chip_readw = fallback_chip_readw, |
| 68 | .chip_readl = fallback_chip_readl, |
| 69 | .chip_readn = fallback_chip_readn, |
| 70 | .chip_writeb = gfxnvidia_chip_writeb, |
| 71 | .chip_writew = fallback_chip_writew, |
| 72 | .chip_writel = fallback_chip_writel, |
| 73 | .chip_writen = fallback_chip_writen, |
| 74 | }; |
| 75 | |
David Hendricks | ac1d25c | 2016-08-09 17:00:58 -0700 | [diff] [blame] | 76 | int gfxnvidia_init(void) |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 77 | { |
Patrick Georgi | 7c30fa9 | 2017-03-28 22:47:12 +0200 | [diff] [blame] | 78 | struct pci_dev *dev = NULL; |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 79 | uint32_t reg32; |
| 80 | |
Patrick Georgi | 2a2d67f | 2017-03-09 10:15:39 +0100 | [diff] [blame] | 81 | if (rget_io_perms()) |
| 82 | return 1; |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 83 | |
Patrick Georgi | 7c30fa9 | 2017-03-28 22:47:12 +0200 | [diff] [blame] | 84 | dev = pcidev_init(gfx_nvidia, PCI_BASE_ADDRESS_0); |
| 85 | if (!dev) |
| 86 | return 1; |
| 87 | |
| 88 | uint32_t io_base_addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0); |
| 89 | if (!io_base_addr) |
| 90 | return 1; |
hailfinger | 1ef766d | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 91 | |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 92 | io_base_addr += 0x300000; |
snelson | f07bbdf | 2010-01-09 23:54:05 +0000 | [diff] [blame] | 93 | msg_pinfo("Detected NVIDIA I/O base address: 0x%x.\n", io_base_addr); |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 94 | |
Patrick Georgi | 124bd00 | 2017-03-21 17:25:59 +0100 | [diff] [blame] | 95 | nvidia_bar = rphysmap("NVIDIA", io_base_addr, GFXNVIDIA_MEMMAP_SIZE); |
| 96 | if (nvidia_bar == ERROR_PTR) |
dhendrix | 0ffc2eb | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 97 | return 1; |
| 98 | |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 99 | /* Allow access to flash interface (will disable screen). */ |
Patrick Georgi | d490a17 | 2017-03-28 23:03:47 +0200 | [diff] [blame] | 100 | reg32 = pci_read_long(dev, 0x50); |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 101 | reg32 &= ~(1 << 0); |
Patrick Georgi | d490a17 | 2017-03-28 23:03:47 +0200 | [diff] [blame] | 102 | rpci_write_long(dev, 0x50, reg32); |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 103 | |
hailfinger | df9b422 | 2010-07-29 14:41:46 +0000 | [diff] [blame] | 104 | /* Write/erase doesn't work. */ |
| 105 | programmer_may_write = 0; |
Patrick Georgi | 0a9533a | 2017-02-03 19:28:38 +0100 | [diff] [blame] | 106 | register_par_master(&par_master_gfxnvidia, BUS_PARALLEL); |
hailfinger | df9b422 | 2010-07-29 14:41:46 +0000 | [diff] [blame] | 107 | |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
Patrick Georgi | d4caa6b | 2017-03-28 21:22:55 +0200 | [diff] [blame] | 111 | static void gfxnvidia_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 112 | chipaddr addr) |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 113 | { |
hailfinger | 2df6f3e | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 114 | pci_mmio_writeb(val, nvidia_bar + (addr & GFXNVIDIA_MEMMAP_MASK)); |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Patrick Georgi | d4caa6b | 2017-03-28 21:22:55 +0200 | [diff] [blame] | 117 | static uint8_t gfxnvidia_chip_readb(const struct flashctx *flash, |
| 118 | const chipaddr addr) |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 119 | { |
hailfinger | 2df6f3e | 2010-07-27 22:03:46 +0000 | [diff] [blame] | 120 | return pci_mmio_readb(nvidia_bar + (addr & GFXNVIDIA_MEMMAP_MASK)); |
uwe | ff4576d | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 121 | } |