|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +/* |
| 3 | + * Copyright © 2025 Intel Corporation |
| 4 | + */ |
| 5 | + |
| 6 | +#include <linux/component.h> |
| 7 | +#include <linux/delay.h> |
| 8 | + |
| 9 | +#include <drm/drm_managed.h> |
| 10 | +#include <drm/intel/i915_component.h> |
| 11 | +#include <drm/intel/intel_lb_mei_interface.h> |
| 12 | +#include <drm/drm_print.h> |
| 13 | + |
| 14 | +#include "xe_device.h" |
| 15 | +#include "xe_late_bind_fw.h" |
| 16 | + |
| 17 | +static struct xe_device * |
| 18 | +late_bind_to_xe(struct xe_late_bind *late_bind) |
| 19 | +{ |
| 20 | + return container_of(late_bind, struct xe_device, late_bind); |
| 21 | +} |
| 22 | + |
| 23 | +static int xe_late_bind_component_bind(struct device *xe_kdev, |
| 24 | + struct device *mei_kdev, void *data) |
| 25 | +{ |
| 26 | + struct xe_device *xe = kdev_to_xe_device(xe_kdev); |
| 27 | + struct xe_late_bind *late_bind = &xe->late_bind; |
| 28 | + |
| 29 | + late_bind->component.ops = data; |
| 30 | + late_bind->component.mei_dev = mei_kdev; |
| 31 | + |
| 32 | + return 0; |
| 33 | +} |
| 34 | + |
| 35 | +static void xe_late_bind_component_unbind(struct device *xe_kdev, |
| 36 | + struct device *mei_kdev, void *data) |
| 37 | +{ |
| 38 | + struct xe_device *xe = kdev_to_xe_device(xe_kdev); |
| 39 | + struct xe_late_bind *late_bind = &xe->late_bind; |
| 40 | + |
| 41 | + late_bind->component.ops = NULL; |
| 42 | +} |
| 43 | + |
| 44 | +static const struct component_ops xe_late_bind_component_ops = { |
| 45 | + .bind = xe_late_bind_component_bind, |
| 46 | + .unbind = xe_late_bind_component_unbind, |
| 47 | +}; |
| 48 | + |
| 49 | +static void xe_late_bind_remove(void *arg) |
| 50 | +{ |
| 51 | + struct xe_late_bind *late_bind = arg; |
| 52 | + struct xe_device *xe = late_bind_to_xe(late_bind); |
| 53 | + |
| 54 | + component_del(xe->drm.dev, &xe_late_bind_component_ops); |
| 55 | +} |
| 56 | + |
| 57 | +/** |
| 58 | + * xe_late_bind_init() - add xe mei late binding component |
| 59 | + * @late_bind: pointer to late bind structure. |
| 60 | + * |
| 61 | + * Return: 0 if the initialization was successful, a negative errno otherwise. |
| 62 | + */ |
| 63 | +int xe_late_bind_init(struct xe_late_bind *late_bind) |
| 64 | +{ |
| 65 | + struct xe_device *xe = late_bind_to_xe(late_bind); |
| 66 | + int err; |
| 67 | + |
| 68 | + if (!xe->info.has_late_bind) |
| 69 | + return 0; |
| 70 | + |
| 71 | + if (!IS_ENABLED(CONFIG_INTEL_MEI_LB) || !IS_ENABLED(CONFIG_INTEL_MEI_GSC)) { |
| 72 | + drm_info(&xe->drm, "Can't init xe mei late bind missing mei component\n"); |
| 73 | + return 0; |
| 74 | + } |
| 75 | + |
| 76 | + err = component_add_typed(xe->drm.dev, &xe_late_bind_component_ops, |
| 77 | + INTEL_COMPONENT_LB); |
| 78 | + if (err < 0) { |
| 79 | + drm_err(&xe->drm, "Failed to add mei late bind component (%pe)\n", ERR_PTR(err)); |
| 80 | + return err; |
| 81 | + } |
| 82 | + |
| 83 | + return devm_add_action_or_reset(xe->drm.dev, xe_late_bind_remove, late_bind); |
| 84 | +} |
0 commit comments