blob: 139a172ed5e5d1fada028d212d6b1ecf07c3dfa9 [file] [log] [blame]
uweff4576d2009-09-30 18:29:55 +00001/*
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
21#include <stdlib.h>
22#include <string.h>
uweff4576d2009-09-30 18:29:55 +000023#include "flash.h"
hailfinger428f6852010-07-27 22:41:39 +000024#include "programmer.h"
uweff4576d2009-09-30 18:29:55 +000025
26#define PCI_VENDOR_ID_NVIDIA 0x10de
27
hailfinger69422b82010-07-17 22:42:33 +000028/* Mask to restrict flash accesses to a 128kB memory window.
29 * FIXME: Is this size a one-fits-all or card dependent?
30 */
31#define GFXNVIDIA_MEMMAP_MASK ((1 << 17) - 1)
dhendrix0ffc2eb2011-06-14 01:35:36 +000032#define GFXNVIDIA_MEMMAP_SIZE (16 * 1024 * 1024)
hailfinger69422b82010-07-17 22:42:33 +000033
uweff4576d2009-09-30 18:29:55 +000034uint8_t *nvidia_bar;
35
Patrick Georgi8ae16572017-03-09 15:59:25 +010036const struct dev_entry gfx_nvidia[] = {
mkarcher6475d3f2010-02-24 00:04:40 +000037 {0x10de, 0x0010, NT, "NVIDIA", "Mutara V08 [NV2]" },
38 {0x10de, 0x0018, NT, "NVIDIA", "RIVA 128" },
39 {0x10de, 0x0020, NT, "NVIDIA", "RIVA TNT" },
40 {0x10de, 0x0028, NT, "NVIDIA", "RIVA TNT2/TNT2 Pro" },
41 {0x10de, 0x0029, NT, "NVIDIA", "RIVA TNT2 Ultra" },
42 {0x10de, 0x002c, NT, "NVIDIA", "Vanta/Vanta LT" },
43 {0x10de, 0x002d, OK, "NVIDIA", "RIVA TNT2 Model 64/Model 64 Pro" },
44 {0x10de, 0x00a0, NT, "NVIDIA", "Aladdin TNT2" },
45 {0x10de, 0x0100, NT, "NVIDIA", "GeForce 256" },
46 {0x10de, 0x0101, NT, "NVIDIA", "GeForce DDR" },
47 {0x10de, 0x0103, NT, "NVIDIA", "Quadro" },
48 {0x10de, 0x0110, NT, "NVIDIA", "GeForce2 MX" },
49 {0x10de, 0x0111, NT, "NVIDIA", "GeForce2 MX" },
50 {0x10de, 0x0112, NT, "NVIDIA", "GeForce2 GO" },
51 {0x10de, 0x0113, NT, "NVIDIA", "Quadro2 MXR" },
52 {0x10de, 0x0150, NT, "NVIDIA", "GeForce2 GTS/Pro" },
53 {0x10de, 0x0151, NT, "NVIDIA", "GeForce2 GTS" },
54 {0x10de, 0x0152, NT, "NVIDIA", "GeForce2 Ultra" },
55 {0x10de, 0x0153, NT, "NVIDIA", "Quadro2 Pro" },
56 {0x10de, 0x0200, NT, "NVIDIA", "GeForce 3 nFX" },
57 {0x10de, 0x0201, NT, "NVIDIA", "GeForce 3 nFX" },
58 {0x10de, 0x0202, NT, "NVIDIA", "GeForce 3 nFX Ultra" },
59 {0x10de, 0x0203, NT, "NVIDIA", "Quadro 3 DDC" },
uweff4576d2009-09-30 18:29:55 +000060
Patrick Georgi8ddfee92017-03-20 14:54:28 +010061 {0},
uweff4576d2009-09-30 18:29:55 +000062};
63
Souvik Ghoshd75cd672016-06-17 14:21:39 -070064static void gfxnvidia_chip_writeb(const struct flashctx *flash, uint8_t val,
65 chipaddr addr);
66static uint8_t gfxnvidia_chip_readb(const struct flashctx *flash,
67 const chipaddr addr);
Patrick Georgi0a9533a2017-02-03 19:28:38 +010068static const struct par_master par_master_gfxnvidia = {
hailfinger76bb7e92011-11-09 23:40:00 +000069 .chip_readb = gfxnvidia_chip_readb,
70 .chip_readw = fallback_chip_readw,
71 .chip_readl = fallback_chip_readl,
72 .chip_readn = fallback_chip_readn,
73 .chip_writeb = gfxnvidia_chip_writeb,
74 .chip_writew = fallback_chip_writew,
75 .chip_writel = fallback_chip_writel,
76 .chip_writen = fallback_chip_writen,
77};
78
David Hendricksac1d25c2016-08-09 17:00:58 -070079int gfxnvidia_init(void)
uweff4576d2009-09-30 18:29:55 +000080{
81 uint32_t reg32;
82
Patrick Georgi2a2d67f2017-03-09 10:15:39 +010083 if (rget_io_perms())
84 return 1;
uweff4576d2009-09-30 18:29:55 +000085
Patrick Georgi588515a2017-03-23 11:41:34 +010086 io_base_addr = pcidev_init(gfx_nvidia, PCI_BASE_ADDRESS_0);
hailfinger1ef766d2010-07-06 09:55:48 +000087
uweff4576d2009-09-30 18:29:55 +000088 io_base_addr += 0x300000;
snelsonf07bbdf2010-01-09 23:54:05 +000089 msg_pinfo("Detected NVIDIA I/O base address: 0x%x.\n", io_base_addr);
uweff4576d2009-09-30 18:29:55 +000090
Patrick Georgi124bd002017-03-21 17:25:59 +010091 nvidia_bar = rphysmap("NVIDIA", io_base_addr, GFXNVIDIA_MEMMAP_SIZE);
92 if (nvidia_bar == ERROR_PTR)
dhendrix0ffc2eb2011-06-14 01:35:36 +000093 return 1;
94
uweff4576d2009-09-30 18:29:55 +000095 /* Allow access to flash interface (will disable screen). */
96 reg32 = pci_read_long(pcidev_dev, 0x50);
97 reg32 &= ~(1 << 0);
hailfingerf31cbdc2010-11-10 15:25:18 +000098 rpci_write_long(pcidev_dev, 0x50, reg32);
uweff4576d2009-09-30 18:29:55 +000099
hailfingerdf9b4222010-07-29 14:41:46 +0000100 /* Write/erase doesn't work. */
101 programmer_may_write = 0;
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100102 register_par_master(&par_master_gfxnvidia, BUS_PARALLEL);
hailfingerdf9b4222010-07-29 14:41:46 +0000103
uweff4576d2009-09-30 18:29:55 +0000104 return 0;
105}
106
Patrick Georgid4caa6b2017-03-28 21:22:55 +0200107static void gfxnvidia_chip_writeb(const struct flashctx *flash, uint8_t val,
108 chipaddr addr)
uweff4576d2009-09-30 18:29:55 +0000109{
hailfinger2df6f3e2010-07-27 22:03:46 +0000110 pci_mmio_writeb(val, nvidia_bar + (addr & GFXNVIDIA_MEMMAP_MASK));
uweff4576d2009-09-30 18:29:55 +0000111}
112
Patrick Georgid4caa6b2017-03-28 21:22:55 +0200113static uint8_t gfxnvidia_chip_readb(const struct flashctx *flash,
114 const chipaddr addr)
uweff4576d2009-09-30 18:29:55 +0000115{
hailfinger2df6f3e2010-07-27 22:03:46 +0000116 return pci_mmio_readb(nvidia_bar + (addr & GFXNVIDIA_MEMMAP_MASK));
uweff4576d2009-09-30 18:29:55 +0000117}