1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs * Copyright 2012 Red Hat Inc.
3c39f472eSBen Skeggs *
4c39f472eSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs *
11c39f472eSBen Skeggs * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs *
14c39f472eSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17c39f472eSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs *
22c39f472eSBen Skeggs */
23c39f472eSBen Skeggs #include "priv.h"
24c39f472eSBen Skeggs
250a34fb31SBen Skeggs #include <subdev/pci.h>
260a34fb31SBen Skeggs
27c39f472eSBen Skeggs static u32
nvbios_prom_read(void * data,u32 offset,u32 length,struct nvkm_bios * bios)28*6aed665fSChristophe Leroy nvbios_prom_read(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
29c39f472eSBen Skeggs {
30d8f266a3SBen Skeggs struct nvkm_device *device = data;
31c39f472eSBen Skeggs u32 i;
32c39f472eSBen Skeggs if (offset + length <= 0x00100000) {
33c39f472eSBen Skeggs for (i = offset; i < offset + length; i += 4)
34d8f266a3SBen Skeggs *(u32 *)&bios->data[i] = nvkm_rd32(device, 0x300000 + i);
35c39f472eSBen Skeggs return length;
36c39f472eSBen Skeggs }
37c39f472eSBen Skeggs return 0;
38c39f472eSBen Skeggs }
39c39f472eSBen Skeggs
40c39f472eSBen Skeggs static void
nvbios_prom_fini(void * data)41*6aed665fSChristophe Leroy nvbios_prom_fini(void *data)
42c39f472eSBen Skeggs {
43d8f266a3SBen Skeggs struct nvkm_device *device = data;
440a34fb31SBen Skeggs nvkm_pci_rom_shadow(device->pci, true);
45c39f472eSBen Skeggs }
46c39f472eSBen Skeggs
47c39f472eSBen Skeggs static void *
nvbios_prom_init(struct nvkm_bios * bios,const char * name)48*6aed665fSChristophe Leroy nvbios_prom_init(struct nvkm_bios *bios, const char *name)
49c39f472eSBen Skeggs {
50d8f266a3SBen Skeggs struct nvkm_device *device = bios->subdev.device;
51d8f266a3SBen Skeggs if (device->card_type == NV_40 && device->chipset >= 0x4c)
52c39f472eSBen Skeggs return ERR_PTR(-ENODEV);
530a34fb31SBen Skeggs nvkm_pci_rom_shadow(device->pci, false);
54d8f266a3SBen Skeggs return device;
55c39f472eSBen Skeggs }
56c39f472eSBen Skeggs
57c39f472eSBen Skeggs const struct nvbios_source
58*6aed665fSChristophe Leroy nvbios_prom = {
59c39f472eSBen Skeggs .name = "PROM",
60*6aed665fSChristophe Leroy .init = nvbios_prom_init,
61*6aed665fSChristophe Leroy .fini = nvbios_prom_fini,
62*6aed665fSChristophe Leroy .read = nvbios_prom_read,
63c39f472eSBen Skeggs .rw = false,
64c39f472eSBen Skeggs };
65