From: Stuart Bennett Date: Tue, 24 Mar 2009 23:26:30 +0000 (+0000) Subject: nouveau: add linux compat defines for PCI config access, use them for nvidia IGPs X-Git-Tag: submit/1.0/20121108.012404~510 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03ca202fa56ad7711ad0f7527a1e537154093e8a;p=profile%2Fivi%2Flibdrm.git nouveau: add linux compat defines for PCI config access, use them for nvidia IGPs --- diff --git a/linux-core/drm_os_linux.h b/linux-core/drm_os_linux.h index 4f1e83b..f58296b 100644 --- a/linux-core/drm_os_linux.h +++ b/linux-core/drm_os_linux.h @@ -125,3 +125,7 @@ do { \ #define DRM_SPINLOCK_IRQSAVE(l, _flags) spin_lock_irqsave(l, _flags); #define DRM_SPINUNLOCK_IRQRESTORE(l, _flags) spin_unlock_irqrestore(l, _flags); #define DRM_SPINLOCK_ASSERT(l) do {} while (0) + +#define DRM_PCI_DEV struct pci_dev +#define drm_pci_get_bsf(b, s, f) pci_get_bus_and_slot(b, PCI_DEVFN(s, f)) +#define drm_pci_read_config_dword pci_read_config_dword diff --git a/shared-core/nouveau_mem.c b/shared-core/nouveau_mem.c index 6d928f4..af23214 100644 --- a/shared-core/nouveau_mem.c +++ b/shared-core/nouveau_mem.c @@ -231,34 +231,46 @@ void nouveau_mem_close(struct drm_device *dev) nouveau_mem_takedown(&dev_priv->pci_heap); } -/*XXX won't work on BSD because of pci_read_config_dword */ +/*XXX BSD needs compat functions for pci access + * #define DRM_PCI_DEV struct device + * #define drm_pci_get_bsf pci_get_bsf + * and a small inline to do *val = pci_read_config(pdev->device, where, 4); + * might work + */ +static uint32_t nforce_pci_fn_read_config_dword(int devfn, int where, uint32_t *val) +{ +#ifdef __linux__ + DRM_PCI_DEV *pdev; + + if (!(pdev = drm_pci_get_bsf(0, 0, devfn))) { + DRM_ERROR("nForce PCI device function 0x%02x not found\n", + devfn); + return -ENODEV; + } + + return drm_pci_read_config_dword(pdev, where, val); +#else + DRM_ERROR("BSD compat for checking IGP memory amount needed\n"); + return 0; +#endif +} + static uint32_t nouveau_mem_fb_amount_igp(struct drm_device *dev) { -#if defined(__linux__) struct drm_nouveau_private *dev_priv = dev->dev_private; - struct pci_dev *bridge; - uint32_t mem; - - bridge = pci_get_bus_and_slot(0, PCI_DEVFN(0,1)); - if (!bridge) { - DRM_ERROR("no bridge device\n"); - return 0; - } + uint32_t mem = 0; - if (dev_priv->flags&NV_NFORCE) { - pci_read_config_dword(bridge, 0x7C, &mem); + if (dev_priv->flags & NV_NFORCE) { + nforce_pci_fn_read_config_dword(1, 0x7C, &mem); return (uint64_t)(((mem >> 6) & 31) + 1)*1024*1024; - } else - if(dev_priv->flags&NV_NFORCE2) { - pci_read_config_dword(bridge, 0x84, &mem); + } + if (dev_priv->flags & NV_NFORCE2) { + nforce_pci_fn_read_config_dword(1, 0x84, &mem); return (uint64_t)(((mem >> 4) & 127) + 1)*1024*1024; } DRM_ERROR("impossible!\n"); -#else - DRM_ERROR("Linux kernel >= 2.6.19 required to check for igp memory amount\n"); -#endif return 0; }