|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +/* |
| 3 | + * Copyright(c) 2019-2022, Intel Corporation. All rights reserved. |
| 4 | + */ |
| 5 | + |
| 6 | +#include <linux/irq.h> |
| 7 | +#include <linux/mei_aux.h> |
| 8 | +#include "i915_drv.h" |
| 9 | +#include "i915_reg.h" |
| 10 | +#include "gt/intel_gsc.h" |
| 11 | +#include "gt/intel_gt.h" |
| 12 | + |
| 13 | +#define GSC_BAR_LENGTH 0x00000FFC |
| 14 | + |
| 15 | +static void gsc_irq_mask(struct irq_data *d) |
| 16 | +{ |
| 17 | + /* generic irq handling */ |
| 18 | +} |
| 19 | + |
| 20 | +static void gsc_irq_unmask(struct irq_data *d) |
| 21 | +{ |
| 22 | + /* generic irq handling */ |
| 23 | +} |
| 24 | + |
| 25 | +static struct irq_chip gsc_irq_chip = { |
| 26 | + .name = "gsc_irq_chip", |
| 27 | + .irq_mask = gsc_irq_mask, |
| 28 | + .irq_unmask = gsc_irq_unmask, |
| 29 | +}; |
| 30 | + |
| 31 | +static int gsc_irq_init(int irq) |
| 32 | +{ |
| 33 | + irq_set_chip_and_handler_name(irq, &gsc_irq_chip, |
| 34 | + handle_simple_irq, "gsc_irq_handler"); |
| 35 | + |
| 36 | + return irq_set_chip_data(irq, NULL); |
| 37 | +} |
| 38 | + |
| 39 | +struct gsc_def { |
| 40 | + const char *name; |
| 41 | + unsigned long bar; |
| 42 | + size_t bar_size; |
| 43 | +}; |
| 44 | + |
| 45 | +/* gsc resources and definitions (HECI1 and HECI2) */ |
| 46 | +static const struct gsc_def gsc_def_dg1[] = { |
| 47 | + { |
| 48 | + /* HECI1 not yet implemented. */ |
| 49 | + }, |
| 50 | + { |
| 51 | + .name = "mei-gscfi", |
| 52 | + .bar = DG1_GSC_HECI2_BASE, |
| 53 | + .bar_size = GSC_BAR_LENGTH, |
| 54 | + } |
| 55 | +}; |
| 56 | + |
| 57 | +static void gsc_release_dev(struct device *dev) |
| 58 | +{ |
| 59 | + struct auxiliary_device *aux_dev = to_auxiliary_dev(dev); |
| 60 | + struct mei_aux_device *adev = auxiliary_dev_to_mei_aux_dev(aux_dev); |
| 61 | + |
| 62 | + kfree(adev); |
| 63 | +} |
| 64 | + |
| 65 | +static void gsc_destroy_one(struct intel_gsc_intf *intf) |
| 66 | +{ |
| 67 | + if (intf->adev) { |
| 68 | + auxiliary_device_delete(&intf->adev->aux_dev); |
| 69 | + auxiliary_device_uninit(&intf->adev->aux_dev); |
| 70 | + intf->adev = NULL; |
| 71 | + } |
| 72 | + if (intf->irq >= 0) |
| 73 | + irq_free_desc(intf->irq); |
| 74 | + intf->irq = -1; |
| 75 | +} |
| 76 | + |
| 77 | +static void gsc_init_one(struct drm_i915_private *i915, |
| 78 | + struct intel_gsc_intf *intf, |
| 79 | + unsigned int intf_id) |
| 80 | +{ |
| 81 | + struct pci_dev *pdev = to_pci_dev(i915->drm.dev); |
| 82 | + struct mei_aux_device *adev; |
| 83 | + struct auxiliary_device *aux_dev; |
| 84 | + const struct gsc_def *def; |
| 85 | + int ret; |
| 86 | + |
| 87 | + intf->irq = -1; |
| 88 | + intf->id = intf_id; |
| 89 | + |
| 90 | + if (intf_id == 0 && !HAS_HECI_PXP(i915)) |
| 91 | + return; |
| 92 | + |
| 93 | + def = &gsc_def_dg1[intf_id]; |
| 94 | + |
| 95 | + if (!def->name) { |
| 96 | + drm_warn_once(&i915->drm, "HECI%d is not implemented!\n", intf_id + 1); |
| 97 | + return; |
| 98 | + } |
| 99 | + |
| 100 | + intf->irq = irq_alloc_desc(0); |
| 101 | + if (intf->irq < 0) { |
| 102 | + drm_err(&i915->drm, "gsc irq error %d\n", intf->irq); |
| 103 | + return; |
| 104 | + } |
| 105 | + |
| 106 | + ret = gsc_irq_init(intf->irq); |
| 107 | + if (ret < 0) { |
| 108 | + drm_err(&i915->drm, "gsc irq init failed %d\n", ret); |
| 109 | + goto fail; |
| 110 | + } |
| 111 | + |
| 112 | + adev = kzalloc(sizeof(*adev), GFP_KERNEL); |
| 113 | + if (!adev) |
| 114 | + goto fail; |
| 115 | + |
| 116 | + adev->irq = intf->irq; |
| 117 | + adev->bar.parent = &pdev->resource[0]; |
| 118 | + adev->bar.start = def->bar + pdev->resource[0].start; |
| 119 | + adev->bar.end = adev->bar.start + def->bar_size - 1; |
| 120 | + adev->bar.flags = IORESOURCE_MEM; |
| 121 | + adev->bar.desc = IORES_DESC_NONE; |
| 122 | + |
| 123 | + aux_dev = &adev->aux_dev; |
| 124 | + aux_dev->name = def->name; |
| 125 | + aux_dev->id = (pci_domain_nr(pdev->bus) << 16) | |
| 126 | + PCI_DEVID(pdev->bus->number, pdev->devfn); |
| 127 | + aux_dev->dev.parent = &pdev->dev; |
| 128 | + aux_dev->dev.release = gsc_release_dev; |
| 129 | + |
| 130 | + ret = auxiliary_device_init(aux_dev); |
| 131 | + if (ret < 0) { |
| 132 | + drm_err(&i915->drm, "gsc aux init failed %d\n", ret); |
| 133 | + kfree(adev); |
| 134 | + goto fail; |
| 135 | + } |
| 136 | + |
| 137 | + ret = auxiliary_device_add(aux_dev); |
| 138 | + if (ret < 0) { |
| 139 | + drm_err(&i915->drm, "gsc aux add failed %d\n", ret); |
| 140 | + /* adev will be freed with the put_device() and .release sequence */ |
| 141 | + auxiliary_device_uninit(aux_dev); |
| 142 | + goto fail; |
| 143 | + } |
| 144 | + intf->adev = adev; |
| 145 | + |
| 146 | + return; |
| 147 | +fail: |
| 148 | + gsc_destroy_one(intf); |
| 149 | +} |
| 150 | + |
| 151 | +static void gsc_irq_handler(struct intel_gt *gt, unsigned int intf_id) |
| 152 | +{ |
| 153 | + int ret; |
| 154 | + |
| 155 | + if (intf_id >= INTEL_GSC_NUM_INTERFACES) { |
| 156 | + drm_warn_once(>->i915->drm, "GSC irq: intf_id %d is out of range", intf_id); |
| 157 | + return; |
| 158 | + } |
| 159 | + |
| 160 | + if (!HAS_HECI_GSC(gt->i915)) { |
| 161 | + drm_warn_once(>->i915->drm, "GSC irq: not supported"); |
| 162 | + return; |
| 163 | + } |
| 164 | + |
| 165 | + if (gt->gsc.intf[intf_id].irq < 0) { |
| 166 | + drm_err_ratelimited(>->i915->drm, "GSC irq: irq not set"); |
| 167 | + return; |
| 168 | + } |
| 169 | + |
| 170 | + ret = generic_handle_irq(gt->gsc.intf[intf_id].irq); |
| 171 | + if (ret) |
| 172 | + drm_err_ratelimited(>->i915->drm, "error handling GSC irq: %d\n", ret); |
| 173 | +} |
| 174 | + |
| 175 | +void intel_gsc_irq_handler(struct intel_gt *gt, u32 iir) |
| 176 | +{ |
| 177 | + if (iir & GSC_IRQ_INTF(0)) |
| 178 | + gsc_irq_handler(gt, 0); |
| 179 | + if (iir & GSC_IRQ_INTF(1)) |
| 180 | + gsc_irq_handler(gt, 1); |
| 181 | +} |
| 182 | + |
| 183 | +void intel_gsc_init(struct intel_gsc *gsc, struct drm_i915_private *i915) |
| 184 | +{ |
| 185 | + unsigned int i; |
| 186 | + |
| 187 | + if (!HAS_HECI_GSC(i915)) |
| 188 | + return; |
| 189 | + |
| 190 | + for (i = 0; i < INTEL_GSC_NUM_INTERFACES; i++) |
| 191 | + gsc_init_one(i915, &gsc->intf[i], i); |
| 192 | +} |
| 193 | + |
| 194 | +void intel_gsc_fini(struct intel_gsc *gsc) |
| 195 | +{ |
| 196 | + struct intel_gt *gt = gsc_to_gt(gsc); |
| 197 | + unsigned int i; |
| 198 | + |
| 199 | + if (!HAS_HECI_GSC(gt->i915)) |
| 200 | + return; |
| 201 | + |
| 202 | + for (i = 0; i < INTEL_GSC_NUM_INTERFACES; i++) |
| 203 | + gsc_destroy_one(&gsc->intf[i]); |
| 204 | +} |
0 commit comments