cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

pci.c (1788B)


      1// SPDX-License-Identifier: ISC
      2
      3#include <linux/kernel.h>
      4#include <linux/module.h>
      5#include <linux/pci.h>
      6
      7#include "mt7603.h"
      8
      9static const struct pci_device_id mt76pci_device_table[] = {
     10	{ PCI_DEVICE(PCI_VENDOR_ID_MEDIATEK, 0x7603) },
     11	{ },
     12};
     13
     14static int
     15mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     16{
     17	struct mt7603_dev *dev;
     18	struct mt76_dev *mdev;
     19	int ret;
     20
     21	ret = pcim_enable_device(pdev);
     22	if (ret)
     23		return ret;
     24
     25	ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
     26	if (ret)
     27		return ret;
     28
     29	pci_set_master(pdev);
     30
     31	ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
     32	if (ret)
     33		return ret;
     34
     35	mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), &mt7603_ops,
     36				 &mt7603_drv_ops);
     37	if (!mdev)
     38		return -ENOMEM;
     39
     40	dev = container_of(mdev, struct mt7603_dev, mt76);
     41	mt76_mmio_init(mdev, pcim_iomap_table(pdev)[0]);
     42
     43	mdev->rev = (mt76_rr(dev, MT_HW_CHIPID) << 16) |
     44		    (mt76_rr(dev, MT_HW_REV) & 0xff);
     45	dev_info(mdev->dev, "ASIC revision: %04x\n", mdev->rev);
     46
     47	mt76_wr(dev, MT_INT_MASK_CSR, 0);
     48
     49	ret = devm_request_irq(mdev->dev, pdev->irq, mt7603_irq_handler,
     50			       IRQF_SHARED, KBUILD_MODNAME, dev);
     51	if (ret)
     52		goto error;
     53
     54	ret = mt7603_register_device(dev);
     55	if (ret)
     56		goto error;
     57
     58	return 0;
     59error:
     60	mt76_free_device(&dev->mt76);
     61
     62	return ret;
     63}
     64
     65static void
     66mt76pci_remove(struct pci_dev *pdev)
     67{
     68	struct mt76_dev *mdev = pci_get_drvdata(pdev);
     69	struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
     70
     71	mt7603_unregister_device(dev);
     72}
     73
     74MODULE_DEVICE_TABLE(pci, mt76pci_device_table);
     75MODULE_FIRMWARE(MT7603_FIRMWARE_E1);
     76MODULE_FIRMWARE(MT7603_FIRMWARE_E2);
     77
     78struct pci_driver mt7603_pci_driver = {
     79	.name		= KBUILD_MODNAME,
     80	.id_table	= mt76pci_device_table,
     81	.probe		= mt76pci_probe,
     82	.remove		= mt76pci_remove,
     83};