/* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved. */ /* Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved. */
struct qaic_device_config { /* Indicates the AIC family the device belongs to */ int family; /* A bitmask representing the available BARs */ int bar_mask; /* An index value used to identify the MHI controller BAR */ unsignedint mhi_bar_idx; /* An index value used to identify the DBCs BAR */ unsignedint dbc_bar_idx;
};
drm_dev_unregister(drm);
qddev->partition_id = 0; /* * Existing users get unresolvable errors till they close FDs. * Need to sync carefully with users calling close(). The * list of users can be modified elsewhere when the lock isn't * held here, but the sync'ing the srcu with the mutex held * could deadlock. Grab the mutex so that the list will be * unmodified. The user we get will exist as long as the * lock is held. Signal that the qcdev is going away, and * grab a reference to the user so they don't go away for * synchronize_srcu(). Then release the mutex to avoid * deadlock and make sure the user has observed the signal. * With the lock released, we cannot maintain any state of the * user list.
*/
mutex_lock(&qddev->users_mutex); while (!list_empty(&qddev->users)) {
usr = list_first_entry(&qddev->users, struct qaic_user, node);
list_del_init(&usr->node);
kref_get(&usr->ref_count);
usr->qddev = NULL;
mutex_unlock(&qddev->users_mutex);
synchronize_srcu(&usr->qddev_lock);
kref_put(&usr->ref_count, free_usr);
mutex_lock(&qddev->users_mutex);
}
mutex_unlock(&qddev->users_mutex);
}
staticint qaic_mhi_probe(struct mhi_device *mhi_dev, conststruct mhi_device_id *id)
{
u16 major = -1, minor = -1; struct qaic_device *qdev; int ret;
/* * Invoking this function indicates that the control channel to the * device is available. We use that as a signal to indicate that * the device side firmware has booted. The device side firmware * manages the device resources, so we need to communicate with it * via the control channel in order to utilize the device. Therefore * we wait until this signal to create the drm dev that userspace will * use to control the device, because without the device side firmware, * userspace can't do anything useful.
*/
staticvoid qaic_mhi_remove(struct mhi_device *mhi_dev)
{ /* This is redundant since we have already observed the device crash */
}
staticvoid qaic_notify_reset(struct qaic_device *qdev)
{ int i;
kobject_uevent(&(to_accel_kdev(qdev->qddev))->kobj, KOBJ_OFFLINE);
qdev->dev_state = QAIC_OFFLINE; /* wake up any waiters to avoid waiting for timeouts at sync */
wake_all_cntl(qdev); for (i = 0; i < qdev->num_dbc; ++i)
wakeup_dbc(qdev, i);
synchronize_srcu(&qdev->dev_lock);
}
void qaic_dev_reset_clean_local_state(struct qaic_device *qdev)
{ int i;
qaic_notify_reset(qdev);
/* start tearing things down */ for (i = 0; i < qdev->num_dbc; ++i)
release_dbc(qdev, i);
}
ret = drmm_mutex_init(drm, &qddev->users_mutex); if (ret) return NULL;
ret = drmm_add_action_or_reset(drm, qaicm_pci_release, NULL); if (ret) return NULL;
ret = drmm_mutex_init(drm, &qdev->cntl_mutex); if (ret) return NULL;
ret = drmm_mutex_init(drm, &qdev->bootlog_mutex); if (ret) return NULL;
qdev->cntl_wq = qaicm_wq_init(drm, "qaic_cntl"); if (IS_ERR(qdev->cntl_wq)) return NULL;
qdev->qts_wq = qaicm_wq_init(drm, "qaic_ts"); if (IS_ERR(qdev->qts_wq)) return NULL;
ret = qaicm_srcu_init(drm, &qdev->dev_lock); if (ret) return NULL;
/* make sure the device has the expected BARs */ if (bars != config->bar_mask) {
pci_dbg(pdev, "%s: expected BARs %#x not found in device. Found %#x\n",
__func__, config->bar_mask, bars); return -EINVAL;
}
ret = pcim_enable_device(pdev); if (ret) return ret;
ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); if (ret) return ret;
dma_set_max_seg_size(&pdev->dev, UINT_MAX);
qdev->bar_mhi = devm_ioremap_resource(&pdev->dev, &pdev->resource[config->mhi_bar_idx]); if (IS_ERR(qdev->bar_mhi)) return PTR_ERR(qdev->bar_mhi);
qdev->bar_dbc = devm_ioremap_resource(&pdev->dev, &pdev->resource[config->dbc_bar_idx]); if (IS_ERR(qdev->bar_dbc)) return PTR_ERR(qdev->bar_dbc);
/* Managed release since we use pcim_enable_device above */
pci_set_master(pdev);
return 0;
}
staticint init_msi(struct qaic_device *qdev, struct pci_dev *pdev)
{ int irq_count = qdev->num_dbc + 1; int mhi_irq; int ret; int i;
/* Managed release since we use pcim_enable_device */
ret = pci_alloc_irq_vectors(pdev, irq_count, irq_count, PCI_IRQ_MSI | PCI_IRQ_MSIX); if (ret == -ENOSPC) {
ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI | PCI_IRQ_MSIX); if (ret < 0) return ret;
/* * Operate in one MSI mode. All interrupts will be directed to * MSI0; every interrupt will wake up all the interrupt handlers * (MHI and DBC[0-15]). Since the interrupt is now shared, it is * not disabled during DBC threaded handler, but only one thread * will be allowed to run per DBC, so while it can be * interrupted, it shouldn't race with itself.
*/
qdev->single_msi = true;
pci_info(pdev, "Allocating %d MSIs failed, operating in 1 MSI mode. Performance may be impacted.\n",
irq_count);
} elseif (ret < 0) { return ret;
}
mhi_irq = pci_irq_vector(pdev, 0); if (mhi_irq < 0) return mhi_irq;
for (i = 0; i < qdev->num_dbc; ++i) {
ret = devm_request_threaded_irq(&pdev->dev,
pci_irq_vector(pdev, qdev->single_msi ? 0 : i + 1),
dbc_irq_handler, dbc_irq_threaded_fn, IRQF_SHARED, "qaic_dbc", &qdev->dbc[i]); if (ret) return ret;
if (datapath_polling) {
qdev->dbc[i].irq = pci_irq_vector(pdev, qdev->single_msi ? 0 : i + 1); if (!qdev->single_msi)
disable_irq_nosync(qdev->dbc[i].irq);
INIT_WORK(&qdev->dbc[i].poll_work, irq_polling_work);
}
}
return mhi_irq;
}
staticint qaic_pci_probe(struct pci_dev *pdev, conststruct pci_device_id *id)
{ struct qaic_device_config *config = (struct qaic_device_config *)id->driver_data; struct qaic_device *qdev; int mhi_irq; int ret; int i;
qdev = create_qdev(pdev, config); if (!qdev) return -ENOMEM;
ret = init_pci(qdev, pdev, config); if (ret) return ret;
for (i = 0; i < qdev->num_dbc; ++i)
qdev->dbc[i].dbc_base = qdev->bar_dbc + QAIC_DBC_OFF(i);
mhi_irq = init_msi(qdev, pdev); if (mhi_irq < 0) return mhi_irq;
ret = qaic_create_drm_device(qdev, QAIC_NO_PARTITION); if (ret) return ret;
qdev->mhi_cntrl = qaic_mhi_register_controller(pdev, qdev->bar_mhi, mhi_irq,
qdev->single_msi, config->family); if (IS_ERR(qdev->mhi_cntrl)) {
ret = PTR_ERR(qdev->mhi_cntrl);
qaic_destroy_drm_device(qdev, QAIC_NO_PARTITION); return ret;
}
staticvoid __exit qaic_exit(void)
{ /* * We assume that qaic_pci_remove() is called due to a hotplug event * which would mean that the link is down, and thus * qaic_mhi_free_controller() should not try to access the device during * cleanup. * We call pci_unregister_driver() below, which also triggers * qaic_pci_remove(), but since this is module exit, we expect the link * to the device to be up, in which case qaic_mhi_free_controller() * should try to access the device during cleanup to put the device in * a sane state. * For that reason, we set link_up here to let qaic_mhi_free_controller * know the expected link state. Since the module is going to be * removed at the end of this, we don't need to worry about * reinitializing the link_up state after the cleanup is done.
*/
link_up = true;
qaic_ras_unregister();
qaic_bootlog_unregister();
qaic_timesync_deinit();
sahara_unregister();
mhi_driver_unregister(&qaic_mhi_driver);
pci_unregister_driver(&qaic_pci_driver);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.