1*0d6140beSAndroid Build Coastguard Worker /*
2*0d6140beSAndroid Build Coastguard Worker * This file is part of the flashrom project.
3*0d6140beSAndroid Build Coastguard Worker *
4*0d6140beSAndroid Build Coastguard Worker * Copyright (C) 2009 Uwe Hermann <[email protected]>
5*0d6140beSAndroid Build Coastguard Worker *
6*0d6140beSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
7*0d6140beSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
8*0d6140beSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
9*0d6140beSAndroid Build Coastguard Worker * (at your option) any later version.
10*0d6140beSAndroid Build Coastguard Worker *
11*0d6140beSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
12*0d6140beSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*0d6140beSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*0d6140beSAndroid Build Coastguard Worker * GNU General Public License for more details.
15*0d6140beSAndroid Build Coastguard Worker */
16*0d6140beSAndroid Build Coastguard Worker
17*0d6140beSAndroid Build Coastguard Worker #include <stdbool.h>
18*0d6140beSAndroid Build Coastguard Worker #include <stdlib.h>
19*0d6140beSAndroid Build Coastguard Worker #include <string.h>
20*0d6140beSAndroid Build Coastguard Worker #include "flash.h"
21*0d6140beSAndroid Build Coastguard Worker #include "programmer.h"
22*0d6140beSAndroid Build Coastguard Worker #include "hwaccess_physmap.h"
23*0d6140beSAndroid Build Coastguard Worker #include "platform/pci.h"
24*0d6140beSAndroid Build Coastguard Worker
25*0d6140beSAndroid Build Coastguard Worker #define PCI_VENDOR_ID_NVIDIA 0x10de
26*0d6140beSAndroid Build Coastguard Worker
27*0d6140beSAndroid Build Coastguard Worker /* Mask to restrict flash accesses to a 128kB memory window.
28*0d6140beSAndroid Build Coastguard Worker * FIXME: Is this size a one-fits-all or card dependent?
29*0d6140beSAndroid Build Coastguard Worker */
30*0d6140beSAndroid Build Coastguard Worker #define GFXNVIDIA_MEMMAP_MASK ((1 << 17) - 1)
31*0d6140beSAndroid Build Coastguard Worker #define GFXNVIDIA_MEMMAP_SIZE (16 * 1024 * 1024)
32*0d6140beSAndroid Build Coastguard Worker
33*0d6140beSAndroid Build Coastguard Worker #define REG_FLASH_ACCESS 0x50
34*0d6140beSAndroid Build Coastguard Worker #define BIT_FLASH_ACCESS BIT(0)
35*0d6140beSAndroid Build Coastguard Worker
36*0d6140beSAndroid Build Coastguard Worker struct gfxnvidia_data {
37*0d6140beSAndroid Build Coastguard Worker struct pci_dev *dev;
38*0d6140beSAndroid Build Coastguard Worker uint8_t *bar;
39*0d6140beSAndroid Build Coastguard Worker uint32_t flash_access;
40*0d6140beSAndroid Build Coastguard Worker };
41*0d6140beSAndroid Build Coastguard Worker
42*0d6140beSAndroid Build Coastguard Worker static const struct dev_entry gfx_nvidia[] = {
43*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0010, NT, "NVIDIA", "Mutara V08 [NV2]" },
44*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0018, NT, "NVIDIA", "RIVA 128" },
45*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0020, NT, "NVIDIA", "RIVA TNT" },
46*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0028, NT, "NVIDIA", "RIVA TNT2/TNT2 Pro" },
47*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0029, NT, "NVIDIA", "RIVA TNT2 Ultra" },
48*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x002c, NT, "NVIDIA", "Vanta/Vanta LT" },
49*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x002d, OK, "NVIDIA", "RIVA TNT2 Model 64/Model 64 Pro" },
50*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x00a0, NT, "NVIDIA", "Aladdin TNT2" },
51*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0100, NT, "NVIDIA", "GeForce 256" },
52*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0101, NT, "NVIDIA", "GeForce DDR" },
53*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0103, NT, "NVIDIA", "Quadro" },
54*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0110, NT, "NVIDIA", "GeForce2 MX" },
55*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0111, NT, "NVIDIA", "GeForce2 MX" },
56*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0112, NT, "NVIDIA", "GeForce2 GO" },
57*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0113, NT, "NVIDIA", "Quadro2 MXR" },
58*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0150, NT, "NVIDIA", "GeForce2 GTS/Pro" },
59*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0151, NT, "NVIDIA", "GeForce2 GTS" },
60*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0152, NT, "NVIDIA", "GeForce2 Ultra" },
61*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0153, NT, "NVIDIA", "Quadro2 Pro" },
62*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0200, NT, "NVIDIA", "GeForce 3 nFX" },
63*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0201, NT, "NVIDIA", "GeForce 3 nFX" },
64*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0202, NT, "NVIDIA", "GeForce 3 nFX Ultra" },
65*0d6140beSAndroid Build Coastguard Worker {0x10de, 0x0203, NT, "NVIDIA", "Quadro 3 DDC" },
66*0d6140beSAndroid Build Coastguard Worker
67*0d6140beSAndroid Build Coastguard Worker {0},
68*0d6140beSAndroid Build Coastguard Worker };
69*0d6140beSAndroid Build Coastguard Worker
gfxnvidia_chip_writeb(const struct flashctx * flash,uint8_t val,chipaddr addr)70*0d6140beSAndroid Build Coastguard Worker static void gfxnvidia_chip_writeb(const struct flashctx *flash, uint8_t val,
71*0d6140beSAndroid Build Coastguard Worker chipaddr addr)
72*0d6140beSAndroid Build Coastguard Worker {
73*0d6140beSAndroid Build Coastguard Worker const struct gfxnvidia_data *data = flash->mst->par.data;
74*0d6140beSAndroid Build Coastguard Worker
75*0d6140beSAndroid Build Coastguard Worker pci_mmio_writeb(val, data->bar + (addr & GFXNVIDIA_MEMMAP_MASK));
76*0d6140beSAndroid Build Coastguard Worker }
77*0d6140beSAndroid Build Coastguard Worker
gfxnvidia_chip_readb(const struct flashctx * flash,const chipaddr addr)78*0d6140beSAndroid Build Coastguard Worker static uint8_t gfxnvidia_chip_readb(const struct flashctx *flash,
79*0d6140beSAndroid Build Coastguard Worker const chipaddr addr)
80*0d6140beSAndroid Build Coastguard Worker {
81*0d6140beSAndroid Build Coastguard Worker const struct gfxnvidia_data *data = flash->mst->par.data;
82*0d6140beSAndroid Build Coastguard Worker
83*0d6140beSAndroid Build Coastguard Worker return pci_mmio_readb(data->bar + (addr & GFXNVIDIA_MEMMAP_MASK));
84*0d6140beSAndroid Build Coastguard Worker }
85*0d6140beSAndroid Build Coastguard Worker
gfxnvidia_shutdown(void * par_data)86*0d6140beSAndroid Build Coastguard Worker static int gfxnvidia_shutdown(void *par_data)
87*0d6140beSAndroid Build Coastguard Worker {
88*0d6140beSAndroid Build Coastguard Worker struct gfxnvidia_data *data = par_data;
89*0d6140beSAndroid Build Coastguard Worker
90*0d6140beSAndroid Build Coastguard Worker /* Restore original flash interface access state. */
91*0d6140beSAndroid Build Coastguard Worker pci_write_long(data->dev, REG_FLASH_ACCESS, data->flash_access);
92*0d6140beSAndroid Build Coastguard Worker
93*0d6140beSAndroid Build Coastguard Worker free(par_data);
94*0d6140beSAndroid Build Coastguard Worker return 0;
95*0d6140beSAndroid Build Coastguard Worker }
96*0d6140beSAndroid Build Coastguard Worker
97*0d6140beSAndroid Build Coastguard Worker static const struct par_master par_master_gfxnvidia = {
98*0d6140beSAndroid Build Coastguard Worker .chip_readb = gfxnvidia_chip_readb,
99*0d6140beSAndroid Build Coastguard Worker .chip_writeb = gfxnvidia_chip_writeb,
100*0d6140beSAndroid Build Coastguard Worker .shutdown = gfxnvidia_shutdown,
101*0d6140beSAndroid Build Coastguard Worker };
102*0d6140beSAndroid Build Coastguard Worker
gfxnvidia_init(const struct programmer_cfg * cfg)103*0d6140beSAndroid Build Coastguard Worker static int gfxnvidia_init(const struct programmer_cfg *cfg)
104*0d6140beSAndroid Build Coastguard Worker {
105*0d6140beSAndroid Build Coastguard Worker struct pci_dev *dev = NULL;
106*0d6140beSAndroid Build Coastguard Worker uint32_t reg32;
107*0d6140beSAndroid Build Coastguard Worker uint8_t *bar;
108*0d6140beSAndroid Build Coastguard Worker
109*0d6140beSAndroid Build Coastguard Worker dev = pcidev_init(cfg, gfx_nvidia, PCI_BASE_ADDRESS_0);
110*0d6140beSAndroid Build Coastguard Worker if (!dev)
111*0d6140beSAndroid Build Coastguard Worker return 1;
112*0d6140beSAndroid Build Coastguard Worker
113*0d6140beSAndroid Build Coastguard Worker uint32_t io_base_addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0);
114*0d6140beSAndroid Build Coastguard Worker if (!io_base_addr)
115*0d6140beSAndroid Build Coastguard Worker return 1;
116*0d6140beSAndroid Build Coastguard Worker
117*0d6140beSAndroid Build Coastguard Worker io_base_addr += 0x300000;
118*0d6140beSAndroid Build Coastguard Worker msg_pinfo("Detected NVIDIA I/O base address: 0x%"PRIx32".\n", io_base_addr);
119*0d6140beSAndroid Build Coastguard Worker
120*0d6140beSAndroid Build Coastguard Worker bar = rphysmap("NVIDIA", io_base_addr, GFXNVIDIA_MEMMAP_SIZE);
121*0d6140beSAndroid Build Coastguard Worker if (bar == ERROR_PTR)
122*0d6140beSAndroid Build Coastguard Worker return 1;
123*0d6140beSAndroid Build Coastguard Worker
124*0d6140beSAndroid Build Coastguard Worker struct gfxnvidia_data *data = calloc(1, sizeof(*data));
125*0d6140beSAndroid Build Coastguard Worker if (!data) {
126*0d6140beSAndroid Build Coastguard Worker msg_perr("Unable to allocate space for PAR master data\n");
127*0d6140beSAndroid Build Coastguard Worker return 1;
128*0d6140beSAndroid Build Coastguard Worker }
129*0d6140beSAndroid Build Coastguard Worker data->dev = dev;
130*0d6140beSAndroid Build Coastguard Worker data->bar = bar;
131*0d6140beSAndroid Build Coastguard Worker
132*0d6140beSAndroid Build Coastguard Worker /* Allow access to flash interface (will disable screen). */
133*0d6140beSAndroid Build Coastguard Worker data->flash_access = pci_read_long(dev, REG_FLASH_ACCESS);
134*0d6140beSAndroid Build Coastguard Worker reg32 = data->flash_access & ~BIT_FLASH_ACCESS;
135*0d6140beSAndroid Build Coastguard Worker pci_write_long(dev, REG_FLASH_ACCESS, reg32);
136*0d6140beSAndroid Build Coastguard Worker
137*0d6140beSAndroid Build Coastguard Worker /* Write/erase doesn't work. */
138*0d6140beSAndroid Build Coastguard Worker programmer_may_write = false;
139*0d6140beSAndroid Build Coastguard Worker return register_par_master(&par_master_gfxnvidia, BUS_PARALLEL, data);
140*0d6140beSAndroid Build Coastguard Worker }
141*0d6140beSAndroid Build Coastguard Worker
142*0d6140beSAndroid Build Coastguard Worker const struct programmer_entry programmer_gfxnvidia = {
143*0d6140beSAndroid Build Coastguard Worker .name = "gfxnvidia",
144*0d6140beSAndroid Build Coastguard Worker .type = PCI,
145*0d6140beSAndroid Build Coastguard Worker .devs.dev = gfx_nvidia,
146*0d6140beSAndroid Build Coastguard Worker .init = gfxnvidia_init,
147*0d6140beSAndroid Build Coastguard Worker };
148