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