Changeset 679 for GPL/trunk/lib32/pci.c


Ignore:
Timestamp:
Mar 18, 2021, 8:57:36 PM (4 years ago)
Author:
David Azarewicz
Message:

Merge changes from Paul's uniaud32next branch.

Location:
GPL/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

  • GPL/trunk/lib32/pci.c

    r604 r679  
    2525 *
    2626 */
    27 
     27#define CONFIG_PM
    2828#include "linux.h"
    2929#include <linux/init.h>
    3030#include <linux/poll.h>
     31#include <linux/dma-mapping.h>
    3132#include <asm/uaccess.h>
    3233#include <asm/hardirq.h>
     
    183184        memset((void near *)pcidev, 0, sizeof(struct pci_dev));
    184185
    185         pcidev->_class = ulTmp2;
     186        pcidev->class = ulTmp2;
    186187        pcidev->vendor = detectedId & 0xffff;
    187188        pcidev->device = detectedId >> 16;
     
    201202        pcidev->sibling = NULL;
    202203        pcidev->next = NULL;
    203         pcidev->dma_mask = 0xFFFFFFFF;
     204        pcidev->dma_mask = 0xffffffff;
     205        pcidev->dev.dma_mask = &pcidev->dma_mask;
     206        pcidev->dev.coherent_dma_mask = 0xffffffffull;
    204207
    205208        // Subsystem ID
    206209        pci_read_config_word(pcidev, PCI_SUBSYSTEM_VENDOR_ID, &pcidev->subsystem_vendor);
    207210        pci_read_config_word(pcidev, PCI_SUBSYSTEM_ID, &pcidev->subsystem_device);
     211
     212        // revision
     213        pci_read_config_byte(pcidev, PCI_REVISION_ID, &pcidev->revision);
    208214
    209215        // I/O  and MEM
     
    296302  if(a->flags & IORESOURCE_MEM) {
    297303    if(RMRequestMem(/*hResMgr,*/ start, n) == FALSE) {
    298       printk("RMRequestIO failed for io %x, length %x\n", start, n);
     304      printk("RMRequestIO failed for mem %x length %x\n", start, n);
    299305      return NULL;
    300306    }
     
    302308  else if(a->flags & IORESOURCE_IO) {
    303309    if(RMRequestIO(/*hResMgr,*/ start, n) == FALSE) {
    304       printk("RMRequestIO failed for io %x, length %x\n", start, n);
     310      printk("RMRequestIO failed for io %x length %x\n", start, n);
    305311      return NULL;
    306312    }
     
    477483  struct pci_dev *pcidev;
    478484  struct pci_device_id IdTable;
     485  USHORT usVendor, usDevice;
    479486  int iAdapter = 0;
    480487
     
    499506    int iTableIx;
    500507
    501     rprintf(("pci_register_driver: query_device found %x %x:%x class=%x checking %s",
    502       ulLast, pcidev->vendor, pcidev->device, pcidev->_class, driver->name));
     508    rprintf((__func__": query_device found %x %04x:%04x class=%x checking %s",
     509      ulLast, pcidev->vendor, pcidev->device, pcidev->class, driver->name));
     510
     511    usVendor = 0;
     512    usDevice = 0;
    503513
    504514    for( iTableIx = 0; driver->id_table[iTableIx].vendor; iTableIx++)
     
    506516      struct pci_device_id const *pDriverId = &driver->id_table[iTableIx];
    507517
    508       if ( (pDriverId->class) && ((pcidev->_class & pDriverId->class_mask) != pDriverId->class) ) continue;
     518      if ( (pDriverId->class) && ((pcidev->class & pDriverId->class_mask) != pDriverId->class) ) continue;
    509519      if (pDriverId->vendor != pcidev->vendor) continue;
    510520      if ( (pDriverId->device != PCI_ANY_ID) && (pDriverId->device != pcidev->device) ) continue;
    511521
    512       rprintf(("pci_register_driver: matched %d %x:%x/%x with %x:%x/%x %x (%s)", iTableIx,
    513         pcidev->vendor, pcidev->device, pcidev->_class,
     522      /* skip a duplicate device that could be matched by both and exact match and a class match */
     523      if (usVendor == pcidev->vendor && usDevice == pcidev->device) continue;
     524      usVendor = pcidev->vendor;
     525      usDevice = pcidev->device;
     526
     527      rprintf((__func__": matched %d %x:%x/%x with %x:%x/%x %x (%s)", iTableIx,
     528        pcidev->vendor, pcidev->device, pcidev->class,
    514529        pDriverId->vendor, pDriverId->device, pDriverId->class, pDriverId->class_mask, driver->name));
    515530
    516531      if ((iAdapterNumber >= 0) && (iAdapter < iAdapterNumber))
    517532      {
     533        rprintf((__func__": AdapterNumber=%x skipping Adapter=%x", iAdapterNumber, iAdapter));
    518534        iAdapter++;
    519535        continue;
    520536      }
    521537
    522       RMInit();
    523538      if (driver->probe(pcidev, pDriverId) == 0)
    524539      {
     
    527542
    528543        // create adapter
    529         RMDone((pcidev->device << 16) | pcidev->vendor, &pcidev->hAdapter, &pcidev->hDevice);
     544        RMCreateAdapterU32((pcidev->device << 16) | pcidev->vendor, &pcidev->hAdapter, ulLast, iNumCards);
     545
    530546        iNumCards++;
    531547        pcidev = NULL; /* we need a new slot */
    532548        break;
    533549      }
    534       RMDone(0, 0, 0);
     550      // release resources which were possibly allocated during probe()
     551      RMDeallocRes();
    535552    } /* for id_table loop */
    536553
     
    647664    //try not to exhaust low memory (< 16mb) so allocate from the high region first
    648665    //if that doesn't satisfy the dma mask requirement, then get it from the low
    649     //regino anyway
     666    //region anyway
    650667    if(hwdev->dma_mask > 0x00ffffff) {
    651668      order = __compat_get_order(size);
     
    666683    ret = (void *)__get_free_pages(gfp, __compat_get_order(size));
    667684  }
    668 
    669685  if (ret != NULL) {
    670686    memset(ret, 0, size);
     
    672688  }
    673689  return ret;
     690}
     691
     692#if 0
     693void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
     694                      dma_addr_t *dma_handle)
     695 {
     696         return dma_alloc_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, dma_handle, GFP_ATOMIC);
     697 }
     698#endif
     699#if 0
     700void *dma_alloc_coherent(struct device *dev, size_t size,
     701                                dma_addr_t *dma_handle, gfp_t gfp)
     702{
     703  void *ret = NULL;
     704  int order;
     705
     706  dprintf(("dma_alloc_coherent %d mask %x", size, (dev) ? dev->dma_mask : 0));
     707  if (dev == NULL || *dev->dma_mask != 0xffffffff) {
     708  dprintf(("dma_alloc_coherent"));
     709    //try not to exhaust low memory (< 16mb) so allocate from the high region first
     710    //if that doesn't satisfy the dma mask requirement, then get it from the low
     711    //region anyway
     712    if(*dev->dma_mask > 0x00ffffff) {
     713  dprintf(("dma_alloc_coherent2"));
     714      order = __compat_get_order(size);
     715      ret = (void *)__get_free_pages(gfp|GFP_DMAHIGHMEM, order);
     716      *dma_handle = virt_to_bus(ret);
     717      if(*dma_handle > *dev->dma_mask) {
     718  dprintf(("dma_alloc_coherent3"));
     719        free_pages((unsigned long)ret, __compat_get_order(size));
     720        //be sure and allocate below 16 mb
     721        gfp |= GFP_DMA;
     722        ret = NULL;
     723      }
     724  dprintf(("dma_alloc_coherent3a"));
     725    }
     726    else { //must always allocate below 16 mb
     727  dprintf(("dma_alloc_coherent4"));
     728      gfp |= GFP_DMA;
     729    }
     730  }
     731  if(ret == NULL) {
     732  dprintf(("dma_alloc_coherent5"));
     733    ret = (void *)__get_free_pages(gfp, __compat_get_order(size));
     734  }
     735
     736  if (ret != NULL) {
     737    memset(ret, 0, size);
     738    *dma_handle = virt_to_bus(ret);
     739  }
     740  return ret;
     741
     742}
     743#endif
     744
     745int dma_supported(struct device *dev, u64 mask)
     746{
     747  return 1;
     748}
     749
     750int dma_set_coherent_mask(struct device *dev, u64 mask)
     751{
     752        /*
     753         * Truncate the mask to the actually supported dma_addr_t width to
     754         * avoid generating unsupportable addresses.
     755         */
     756        mask = (dma_addr_t)mask;
     757
     758        if (!dma_supported(dev, mask))
     759                return -EIO;
     760
     761        dev->coherent_dma_mask = mask;
     762        return 0;
     763}
     764
     765int dma_set_mask(struct device *dev, u64 mask)
     766{
     767        /*
     768         * Truncate the mask to the actually supported dma_addr_t width to
     769         * avoid generating unsupportable addresses.
     770         */
     771        mask = (dma_addr_t)mask;
     772
     773        if (!dev->dma_mask || !dma_supported(dev, mask))
     774                return -EIO;
     775
     776        *dev->dma_mask = mask;
     777        return 0;
    674778}
    675779
     
    888992}
    889993
    890 const struct pci_device_id * pci_match_device(const struct pci_device_id *ids, struct pci_dev *dev)
     994const struct pci_device_id * pci_match_id(const struct pci_device_id *ids, struct pci_dev *dev)
    891995{
    892996  u16 subsystem_vendor, subsystem_device;
     
    9001004      (ids->subvendor == PCI_ANY_ID || ids->subvendor == subsystem_vendor) &&
    9011005      (ids->subdevice == PCI_ANY_ID || ids->subdevice == subsystem_device) &&
    902       !((ids->class ^ dev->_class) & ids->class_mask))
     1006      !((ids->class ^ dev->class) & ids->class_mask))
    9031007      return ids;
    9041008    ids++;
     
    9811085    if(pci_devices[i].devfn)
    9821086    {
    983       RMSetHandles(pci_devices[i].hAdapter, pci_devices[i].hDevice); /* DAZ - dirty hack */
     1087      RMSetHandles(pci_devices[i].hAdapter); /* DAZ - dirty hack */
    9841088      driver = pci_devices[i].pcidriver;
    9851089      if(driver && driver->resume) {
     
    10041108    if(pci_devices[i].devfn)
    10051109    {
    1006       RMSetHandles(pci_devices[i].hAdapter, pci_devices[i].hDevice); /* DAZ - dirty hack */
     1110      RMSetHandles(pci_devices[i].hAdapter); /* DAZ - dirty hack */
    10071111      driver = pci_devices[i].pcidriver;
    10081112      if(driver && driver->suspend) {
     
    10401144#endif
    10411145
     1146/**
     1147 * pci_status_get_and_clear_errors - return and clear error bits in PCI_STATUS
     1148 * @pdev: the PCI device
     1149 *
     1150 * Returns error bits set in PCI_STATUS and clears them.
     1151 */
     1152int pci_status_get_and_clear_errors(struct pci_dev *pdev)
     1153{
     1154        u16 status;
     1155        int ret;
     1156
     1157        ret = pci_read_config_word(pdev, PCI_STATUS, &status);
     1158        if (ret != PCIBIOS_SUCCESSFUL)
     1159                return -EIO;
     1160
     1161        status &= PCI_STATUS_ERROR_BITS;
     1162        if (status)
     1163                pci_write_config_word(pdev, PCI_STATUS, status);
     1164
     1165        return status;
     1166}
     1167
Note: See TracChangeset for help on using the changeset viewer.