From 5f31856fcb2bb07061662f4b04769b834afc038b Mon Sep 17 00:00:00 2001 From: Andrew Lewycky Date: Fri, 28 Jun 2024 12:38:06 -0400 Subject: [PATCH] Add suspend/resume hooks SIMPLE_DEV_PM_OPS connects them to suspend and hibernate. --- enumerate.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/enumerate.c b/enumerate.c index 9161548..131bb9d 100644 --- a/enumerate.c +++ b/enumerate.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "enumerate.h" #include "interrupt.h" @@ -157,6 +158,30 @@ void tenstorrent_device_put(struct tenstorrent_device *tt_dev) { kref_put(&tt_dev->kref, tt_dev_release); } +static int tenstorrent_suspend(struct device *dev) { + struct pci_dev *pdev = to_pci_dev(dev); + struct tenstorrent_device *tt_dev = pci_get_drvdata(pdev); + + tt_dev->dev_class->cleanup_hardware(tt_dev); + + return 0; +} + +static int tenstorrent_resume(struct device *dev) { + struct pci_dev *pdev = to_pci_dev(dev); + struct tenstorrent_device *tt_dev = pci_get_drvdata(pdev); + + int ret = tt_dev->dev_class->init_hardware(tt_dev); + + // Suspend invalidates the saved state. + if (ret == 0) + pci_save_state(pdev); + + return ret; +} + +static SIMPLE_DEV_PM_OPS(tenstorrent_pm_ops, tenstorrent_suspend, tenstorrent_resume); + extern const struct pci_device_id tenstorrent_ids[]; static struct pci_driver tenstorrent_pci_driver = { .name = TENSTORRENT, @@ -164,6 +189,8 @@ static struct pci_driver tenstorrent_pci_driver = { .probe = tenstorrent_pci_probe, .remove = tenstorrent_pci_remove, .shutdown = tenstorrent_pci_remove, + + .driver.pm = &tenstorrent_pm_ops, }; int tenstorrent_pci_register_driver(void)