Skip to content

Commit

Permalink
Add suspend/resume hooks
Browse files Browse the repository at this point in the history
SIMPLE_DEV_PM_OPS connects them to suspend and hibernate.
  • Loading branch information
alewycky-tenstorrent committed Aug 2, 2024
1 parent 40d3cff commit 5f31856
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions enumerate.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <linux/idr.h>
#include <linux/mutex.h>
#include <linux/version.h>
#include <linux/pm.h>

#include "enumerate.h"
#include "interrupt.h"
Expand Down Expand Up @@ -157,13 +158,39 @@ 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,
.id_table = tenstorrent_ids,
.probe = tenstorrent_pci_probe,
.remove = tenstorrent_pci_remove,
.shutdown = tenstorrent_pci_remove,

.driver.pm = &tenstorrent_pm_ops,
};

int tenstorrent_pci_register_driver(void)
Expand Down

0 comments on commit 5f31856

Please sign in to comment.