ehl_pse_io.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Intel Elkhart Lake Programmable Service Engine (PSE) I/O
  4. *
  5. * Copyright (c) 2025 Intel Corporation.
  6. *
  7. * Author: Raag Jadav <raag.jadav@intel.com>
  8. */
  9. #include <linux/auxiliary_bus.h>
  10. #include <linux/device/devres.h>
  11. #include <linux/errno.h>
  12. #include <linux/gfp_types.h>
  13. #include <linux/ioport.h>
  14. #include <linux/mod_devicetable.h>
  15. #include <linux/module.h>
  16. #include <linux/pci.h>
  17. #include <linux/sizes.h>
  18. #include <linux/types.h>
  19. #include <linux/ehl_pse_io_aux.h>
  20. #define EHL_PSE_IO_DEV_SIZE SZ_4K
  21. static int ehl_pse_io_dev_create(struct pci_dev *pci, const char *name, int idx)
  22. {
  23. struct device *dev = &pci->dev;
  24. struct auxiliary_device *adev;
  25. struct ehl_pse_io_data *data;
  26. resource_size_t start, offset;
  27. u32 id;
  28. data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
  29. if (!data)
  30. return -ENOMEM;
  31. id = (pci_domain_nr(pci->bus) << 16) | pci_dev_id(pci);
  32. start = pci_resource_start(pci, 0);
  33. offset = EHL_PSE_IO_DEV_SIZE * idx;
  34. data->mem = DEFINE_RES_MEM(start + offset, EHL_PSE_IO_DEV_SIZE);
  35. data->irq = pci_irq_vector(pci, idx);
  36. adev = __devm_auxiliary_device_create(dev, EHL_PSE_IO_NAME, name, data, id);
  37. return adev ? 0 : -ENODEV;
  38. }
  39. static int ehl_pse_io_probe(struct pci_dev *pci, const struct pci_device_id *id)
  40. {
  41. int ret;
  42. ret = pcim_enable_device(pci);
  43. if (ret)
  44. return ret;
  45. pci_set_master(pci);
  46. ret = pci_alloc_irq_vectors(pci, 2, 2, PCI_IRQ_MSI);
  47. if (ret < 0)
  48. return ret;
  49. ret = ehl_pse_io_dev_create(pci, EHL_PSE_GPIO_NAME, 0);
  50. if (ret)
  51. return ret;
  52. return ehl_pse_io_dev_create(pci, EHL_PSE_TIO_NAME, 1);
  53. }
  54. static const struct pci_device_id ehl_pse_io_ids[] = {
  55. { PCI_VDEVICE(INTEL, 0x4b88) },
  56. { PCI_VDEVICE(INTEL, 0x4b89) },
  57. { }
  58. };
  59. MODULE_DEVICE_TABLE(pci, ehl_pse_io_ids);
  60. static struct pci_driver ehl_pse_io_driver = {
  61. .name = EHL_PSE_IO_NAME,
  62. .id_table = ehl_pse_io_ids,
  63. .probe = ehl_pse_io_probe,
  64. };
  65. module_pci_driver(ehl_pse_io_driver);
  66. MODULE_AUTHOR("Raag Jadav <raag.jadav@intel.com>");
  67. MODULE_DESCRIPTION("Intel Elkhart Lake PSE I/O driver");
  68. MODULE_LICENSE("GPL");