Home | History | Annotate | Line # | Download | only in fb
      1 /*	$NetBSD: nouveau_nvkm_subdev_fb_ramnv1a.c,v 1.4 2021/12/19 10:51:58 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2013 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  * Authors: Ben Skeggs
     25  */
     26 #include <sys/cdefs.h>
     27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_fb_ramnv1a.c,v 1.4 2021/12/19 10:51:58 riastradh Exp $");
     28 
     29 #include "ram.h"
     30 
     31 int
     32 nv1a_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram)
     33 {
     34 #ifdef __NetBSD__		/* XXX pci */
     35 	return -ENODEV;
     36 #else
     37 	struct pci_dev *bridge;
     38 	u32 mem, mib;
     39 	int domain = 0;
     40 	struct pci_dev *pdev = NULL;
     41 
     42 	if (dev_is_pci(fb->subdev.device->dev))
     43 		pdev = to_pci_dev(fb->subdev.device->dev);
     44 
     45 	if (pdev)
     46 		domain = pci_domain_nr(pdev->bus);
     47 
     48 	bridge = pci_get_domain_bus_and_slot(domain, 0, PCI_DEVFN(0, 1));
     49 	if (!bridge) {
     50 		nvkm_error(&fb->subdev, "no bridge device\n");
     51 		return -ENODEV;
     52 	}
     53 
     54 	if (fb->subdev.device->chipset == 0x1a) {
     55 		pci_read_config_dword(bridge, 0x7c, &mem);
     56 		mib = ((mem >> 6) & 31) + 1;
     57 	} else {
     58 		pci_read_config_dword(bridge, 0x84, &mem);
     59 		mib = ((mem >> 4) & 127) + 1;
     60 	}
     61 
     62 	return nvkm_ram_new_(&nv04_ram_func, fb, NVKM_RAM_TYPE_STOLEN,
     63 			     mib * 1024 * 1024, pram);
     64 #endif
     65 }
     66