Changeset 744 for GPL/branches


Ignore:
Timestamp:
Sep 18, 2022, 11:16:00 AM (3 years ago)
Author:
Paul Smedley
Message:

Add some additional functions to minimise upstream patches

Location:
GPL/branches/uniaud32-exp
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/atiixp.c

    r737 r744  
    15631563        chip->pci = pci;
    15641564        chip->irq = -1;
    1565 #ifndef TARGET_OS2
    15661565        err = pcim_iomap_regions(pci, 1 << 0, "ATI IXP AC97");
    15671566        if (err < 0)
    15681567                return err;
    1569 #else
    1570         err = pci_request_regions(pci, "ATI IXP AC97");
    1571         if (err < 0) {
    1572                 pci_disable_device(pci);
    1573                 kfree(chip);
    1574                 return err;
    1575         }
    1576 #endif
    15771568        chip->addr = pci_resource_start(pci, 0);
    1578 #ifndef TARGET_OS2
    15791569        chip->remap_addr = pcim_iomap_table(pci)[0];
    1580 #else
    1581         chip->remap_addr = pci_ioremap_bar(pci, 0);
    1582 #endif
    15831570        if (devm_request_irq(&pci->dev, pci->irq, snd_atiixp_interrupt,
    15841571                             IRQF_SHARED, KBUILD_MODNAME, chip)) {
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/bt87x.c

    r737 r744  
    706706        spin_lock_init(&chip->reg_lock);
    707707
    708 #ifndef TARGET_OS2
    709708        err = pcim_iomap_regions(pci, 1 << 0, "Bt87x audio");
    710709        if (err < 0)
    711710                return err;
    712711        chip->mmio = pcim_iomap_table(pci)[0];
    713 #else
    714         err = pci_request_regions(pci, "Bt87x audio");
    715         if (err < 0) {
    716                 kfree(chip);
    717                 pci_disable_device(pci);
    718                 return err;
    719         }
    720         chip->mmio = pci_ioremap_bar(pci, 0);
    721 #endif
    722712        chip->reg_control = CTL_A_PWRDN | CTL_DA_ES2 |
    723713                            CTL_PKTP_16 | (15 << CTL_DA_SDR_SHIFT);
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/cs4281.c

    r737 r744  
    13091309        chip->dual_codec = dual_codec;
    13101310
    1311 #ifndef TARGET_OS2
    13121311        err = pcim_iomap_regions(pci, 0x03, "CS4281"); /* 2 BARs */
    13131312        if (err < 0)
    13141313                return err;
    1315 #else
    1316         err = pci_request_regions(pci, "CS4281");
    1317         if (err < 0) {
    1318                 kfree(chip);
    1319                 pci_disable_device(pci);
    1320                 return err;
    1321         }
    1322 #endif
    13231314        chip->ba0_addr = pci_resource_start(pci, 0);
    13241315        chip->ba1_addr = pci_resource_start(pci, 1);
    13251316
    1326 #ifndef TARGET_OS2
    13271317        chip->ba0 = pcim_iomap_table(pci)[0];
    13281318        chip->ba1 = pcim_iomap_table(pci)[1];
    1329 #else
    1330         chip->ba0 = pci_ioremap_bar(pci, 0);
    1331         chip->ba1 = pci_ioremap_bar(pci, 1);
    1332 #endif
    13331319        if (devm_request_irq(&pci->dev, pci->irq, snd_cs4281_interrupt,
    13341320                             IRQF_SHARED, KBUILD_MODNAME, chip)) {
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/cs5530.c

    r710 r744  
    100100                return err;
    101101        chip->pci_base = pci_resource_start(pci, 0);
    102 #ifndef TARGET_OS2
    103102        mem = pcim_iomap_table(pci)[0];
    104 #else
    105         mem = pci_ioremap_bar(pci, 0);
    106 #endif
    107103        map = readw(mem + 0x18);
    108104
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/fm801.c

    r737 r744  
    11951195        int err;
    11961196
    1197 #ifndef TARGET_OS2
    11981197        err = pcim_enable_device(pci);
    11991198        if (err < 0)
    12001199                return err;
    1201 #else
    1202         if ((err = pci_enable_device(pci)) < 0)
    1203                 return err;
    1204 #endif
    12051200        spin_lock_init(&chip->reg_lock);
    12061201        chip->card = card;
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/hda/hda_intel.c

    r740 r744  
    18951895#endif
    18961896
    1897 #ifndef TARGET_OS2
    18981897        err = pcim_iomap_regions(pci, 1 << 0, "ICH HD audio");
    1899 #else
    1900         err = pci_request_regions(pci, "ICH HD audio");
    1901 #endif
    19021898        if (err < 0)
    19031899                return err;
    19041900
    19051901        bus->addr = pci_resource_start(pci, 0);
    1906 #ifndef TARGET_OS2
    19071902        bus->remap_addr = pcim_iomap_table(pci)[0];
    1908 #else
    1909         bus->remap_addr = pci_ioremap_bar(pci, 0);
    1910 #endif
    19111903        if (chip->driver_type == AZX_DRIVER_SKL)
    19121904                snd_hdac_bus_parse_capabilities(bus);
  • GPL/branches/uniaud32-exp/include/linux/pci.h

    r732 r744  
    781781#define dev_is_pci(d) (true)
    782782int pcim_enable_device(struct pci_dev *pdev);
    783 #define pcim_iomap pci_iomap
    784783int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name);
    785784
     
    789788}
    790789void pci_intx(struct pci_dev *pdev, int enable);
     790#define PCI_STD_NUM_BARS        6       /* Number of standard BARs */
     791int __must_check pci_request_region(struct pci_dev *, int, char *);
     792void pci_release_region(struct pci_dev *, int);
     793void __iomem * const *pcim_iomap_table(struct pci_dev *pdev);
    791794
    792795#endif /* LINUX_PCI_H */
  • GPL/branches/uniaud32-exp/lib32/devres.c

    r737 r744  
    99
    1010#include <linux/device.h>
     11#include <linux/pci.h>
    1112#include <linux/module.h>
    1213#include <linux/slab.h>
     
    310311        return NULL;
    311312}
     313
     314/**
     315 * devres_get - Find devres, if non-existent, add one atomically
     316 * @dev: Device to lookup or add devres for
     317 * @new_res: Pointer to new initialized devres to add if not found
     318 * @match: Match function (optional)
     319 * @match_data: Data for the match function
     320 *
     321 * Find the latest devres of @dev which has the same release function
     322 * as @new_res and for which @match return 1.  If found, @new_res is
     323 * freed; otherwise, @new_res is added atomically.
     324 *
     325 * RETURNS:
     326 * Pointer to found or added devres.
     327 */
     328void * devres_get(struct device *dev, void *new_res,
     329                  dr_match_t match, void *match_data)
     330{
     331        struct devres *new_dr = container_of(new_res, struct devres, data);
     332        struct devres *dr;
     333        unsigned long flags;
     334
     335        spin_lock_irqsave(&dev->devres_lock, flags);
     336        dr = find_dr(dev, new_dr->node.release, match, match_data);
     337        if (!dr) {
     338                add_dr(dev, &new_dr->node);
     339                dr = new_dr;
     340                new_res = NULL;
     341        }
     342        spin_unlock_irqrestore(&dev->devres_lock, flags);
     343        devres_free(new_res);
     344
     345        return dr->data;
     346}
     347EXPORT_SYMBOL_GPL(devres_get);
    312348
    313349/*
     
    527563}
    528564EXPORT_SYMBOL_GPL(devm_kasprintf);
     565
     566/*
     567 * PCI iomap devres
     568 */
     569#define PCIM_IOMAP_MAX  PCI_STD_NUM_BARS
     570
     571struct pcim_iomap_devres {
     572        void __iomem *table[PCIM_IOMAP_MAX];
     573};
     574
     575static void pcim_iomap_release(struct device *gendev, void *res)
     576{
     577        struct pci_dev *dev = to_pci_dev(gendev);
     578        struct pcim_iomap_devres *this = res;
     579        int i;
     580
     581        for (i = 0; i < PCIM_IOMAP_MAX; i++)
     582                if (this->table[i])
     583                        pci_iounmap(dev, this->table[i]);
     584}
     585
     586/**
     587 * pcim_iomap_table - access iomap allocation table
     588 * @pdev: PCI device to access iomap table for
     589 *
     590 * Access iomap allocation table for @dev.  If iomap table doesn't
     591 * exist and @pdev is managed, it will be allocated.  All iomaps
     592 * recorded in the iomap table are automatically unmapped on driver
     593 * detach.
     594 *
     595 * This function might sleep when the table is first allocated but can
     596 * be safely called without context and guaranteed to succeed once
     597 * allocated.
     598 */
     599void __iomem * const *pcim_iomap_table(struct pci_dev *pdev)
     600{
     601        struct pcim_iomap_devres *dr, *new_dr;
     602
     603        dr = devres_find(&pdev->dev, pcim_iomap_release, NULL, NULL);
     604        if (dr)
     605                return dr->table;
     606
     607        new_dr = devres_alloc(pcim_iomap_release, sizeof(*new_dr), GFP_KERNEL);
     608        if (!new_dr)
     609                return NULL;
     610        dr = devres_get(&pdev->dev, new_dr, NULL, NULL);
     611        return dr->table;
     612}
     613EXPORT_SYMBOL(pcim_iomap_table);
     614
     615/**
     616 * pcim_iomap - Managed pcim_iomap()
     617 * @pdev: PCI device to iomap for
     618 * @bar: BAR to iomap
     619 * @maxlen: Maximum length of iomap
     620 *
     621 * Managed pci_iomap().  Map is automatically unmapped on driver
     622 * detach.
     623 */
     624void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen)
     625{
     626        void __iomem **tbl;
     627
     628        BUG_ON(bar >= PCIM_IOMAP_MAX);
     629
     630        tbl = (void __iomem **)pcim_iomap_table(pdev);
     631        if (!tbl || tbl[bar])   /* duplicate mappings not allowed */
     632                return NULL;
     633
     634        tbl[bar] = pci_iomap(pdev, bar, maxlen);
     635        return tbl[bar];
     636}
     637EXPORT_SYMBOL(pcim_iomap);
     638
     639/**
     640 * pcim_iounmap - Managed pci_iounmap()
     641 * @pdev: PCI device to iounmap for
     642 * @addr: Address to unmap
     643 *
     644 * Managed pci_iounmap().  @addr must have been mapped using pcim_iomap().
     645 */
     646void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr)
     647{
     648        void __iomem **tbl;
     649        int i;
     650
     651        pci_iounmap(pdev, addr);
     652
     653        tbl = (void __iomem **)pcim_iomap_table(pdev);
     654        BUG_ON(!tbl);
     655
     656        for (i = 0; i < PCIM_IOMAP_MAX; i++)
     657                if (tbl[i] == addr) {
     658                        tbl[i] = NULL;
     659                        return;
     660                }
     661        WARN_ON(1);
     662}
     663EXPORT_SYMBOL(pcim_iounmap);
     664
     665/**
     666 * pcim_iomap_regions - Request and iomap PCI BARs
     667 * @pdev: PCI device to map IO resources for
     668 * @mask: Mask of BARs to request and iomap
     669 * @name: Name used when requesting regions
     670 *
     671 * Request and iomap regions specified by @mask.
     672 */
     673int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name)
     674{
     675        void __iomem * const *iomap;
     676        int i, rc;
     677
     678        iomap = pcim_iomap_table(pdev);
     679        if (!iomap)
     680                return -ENOMEM;
     681
     682        for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
     683                unsigned long len;
     684
     685                if (!(mask & (1 << i)))
     686                        continue;
     687
     688                rc = -EINVAL;
     689                len = pci_resource_len(pdev, i);
     690                if (!len)
     691                        goto err_inval;
     692
     693                rc = pci_request_region(pdev, i, name);
     694                if (rc)
     695                        goto err_inval;
     696
     697                rc = -ENOMEM;
     698                if (!pcim_iomap(pdev, i, 0))
     699                        goto err_region;
     700        }
     701
     702        return 0;
     703
     704 err_region:
     705        pci_release_region(pdev, i);
     706 err_inval:
     707        while (--i >= 0) {
     708                if (!(mask & (1 << i)))
     709                        continue;
     710                pcim_iounmap(pdev, iomap[i]);
     711                pci_release_region(pdev, i);
     712        }
     713
     714        return rc;
     715}
     716EXPORT_SYMBOL(pcim_iomap_regions);
Note: See TracChangeset for help on using the changeset viewer.