Subversion Repositories Kolibri OS

Rev

Rev 3480 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* drm_pci.h -- PCI DMA memory management wrappers for DRM -*- linux-c -*- */
  2. /**
  3.  * \file drm_pci.c
  4.  * \brief Functions and ioctls to manage PCI memory
  5.  *
  6.  * \warning These interfaces aren't stable yet.
  7.  *
  8.  * \todo Implement the remaining ioctl's for the PCI pools.
  9.  * \todo The wrappers here are so thin that they would be better off inlined..
  10.  *
  11.  * \author José Fonseca <jrfonseca@tungstengraphics.com>
  12.  * \author Leif Delgass <ldelgass@retinalburn.net>
  13.  */
  14.  
  15. /*
  16.  * Copyright 2003 José Fonseca.
  17.  * Copyright 2003 Leif Delgass.
  18.  * All Rights Reserved.
  19.  *
  20.  * Permission is hereby granted, free of charge, to any person obtaining a
  21.  * copy of this software and associated documentation files (the "Software"),
  22.  * to deal in the Software without restriction, including without limitation
  23.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  24.  * and/or sell copies of the Software, and to permit persons to whom the
  25.  * Software is furnished to do so, subject to the following conditions:
  26.  *
  27.  * The above copyright notice and this permission notice (including the next
  28.  * paragraph) shall be included in all copies or substantial portions of the
  29.  * Software.
  30.  *
  31.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  32.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  33.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  34.  * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  35.  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  36.  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  37.  */
  38.  
  39. //#include <linux/pci.h>
  40. //#include <linux/slab.h>
  41. //#include <linux/dma-mapping.h>
  42. #include <linux/export.h>
  43. #include <drm/drmP.h>
  44.  
  45. #include <syscall.h>
  46.  
  47. /**********************************************************************/
  48. /** \name PCI memory */
  49. /*@{*/
  50.  
  51. /**
  52.  * \brief Allocate a PCI consistent memory block, for DMA.
  53.  */
  54. drm_dma_handle_t *drm_pci_alloc(struct drm_device * dev, size_t size, size_t align)
  55. {
  56.         drm_dma_handle_t *dmah;
  57. #if 1
  58.         unsigned long addr;
  59.         size_t sz;
  60. #endif
  61.  
  62.         /* pci_alloc_consistent only guarantees alignment to the smallest
  63.          * PAGE_SIZE order which is greater than or equal to the requested size.
  64.          * Return NULL here for now to make sure nobody tries for larger alignment
  65.          */
  66.         if (align > size)
  67.                 return NULL;
  68.  
  69.         dmah = kmalloc(sizeof(drm_dma_handle_t), GFP_KERNEL);
  70.         if (!dmah)
  71.                 return NULL;
  72.  
  73.         dmah->size = size;
  74.     dmah->vaddr = (void*)KernelAlloc(size);
  75.     dmah->busaddr = GetPgAddr(dmah->vaddr);
  76.  
  77.         if (dmah->vaddr == NULL) {
  78.                 kfree(dmah);
  79.                 return NULL;
  80.         }
  81.  
  82.         memset(dmah->vaddr, 0, size);
  83.  
  84.         return dmah;
  85. }
  86.  
  87.  
  88. int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *mask)
  89. {
  90.         struct pci_dev *root;
  91.         int pos;
  92.         u32 lnkcap, lnkcap2;
  93.  
  94.         *mask = 0;
  95.         if (!dev->pdev)
  96.                 return -EINVAL;
  97.  
  98.         if (!pci_is_pcie(dev->pdev))
  99.                 return -EINVAL;
  100.  
  101.     return -EINVAL;
  102.  
  103. #if 0
  104.         root = dev->pdev->bus->self;
  105.  
  106.         pos = pci_pcie_cap(root);
  107.         if (!pos)
  108.                 return -EINVAL;
  109.  
  110.         /* we've been informed via and serverworks don't make the cut */
  111. //   if (root->vendor == PCI_VENDOR_ID_VIA ||
  112. //       root->vendor == PCI_VENDOR_ID_SERVERWORKS)
  113. //       return -EINVAL;
  114.  
  115.         pci_read_config_dword(root, pos + PCI_EXP_LNKCAP, &lnkcap);
  116.         pci_read_config_dword(root, pos + PCI_EXP_LNKCAP2, &lnkcap2);
  117.  
  118.         lnkcap &= PCI_EXP_LNKCAP_SLS;
  119.         lnkcap2 &= 0xfe;
  120.  
  121.         if (lnkcap2) { /* PCIE GEN 3.0 */
  122.                 if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB)
  123.                         *mask |= DRM_PCIE_SPEED_25;
  124.                 if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB)
  125.                         *mask |= DRM_PCIE_SPEED_50;
  126.                 if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB)
  127.                         *mask |= DRM_PCIE_SPEED_80;
  128.         } else {
  129.                 if (lnkcap & 1)
  130.                         *mask |= DRM_PCIE_SPEED_25;
  131.                 if (lnkcap & 2)
  132.                         *mask |= DRM_PCIE_SPEED_50;
  133.         }
  134.  
  135.         DRM_INFO("probing gen 2 caps for device %x:%x = %x/%x\n", root->vendor, root->device, lnkcap, lnkcap2);
  136.         return 0;
  137. #endif
  138.  
  139. }
  140. EXPORT_SYMBOL(drm_pcie_get_speed_cap_mask);
  141.