From fa5bb24685b585521ba7eb52c5d63da43f3e2436 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sat, 5 May 2018 10:50:12 +0200 Subject: Start and shutdown harddoom device --- Kbuild | 2 +- harddoomdev.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ harddoomdev.h | 9 +++++++++ pci.c | 4 ++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 harddoomdev.c create mode 100644 harddoomdev.h diff --git a/Kbuild b/Kbuild index 0214343..fdebf0f 100644 --- a/Kbuild +++ b/Kbuild @@ -1,2 +1,2 @@ obj-m := harddoom.o -harddoom-objs := harddoom_main.o pci.o char.o +harddoom-objs := harddoom_main.o pci.o char.o harddoomdev.o diff --git a/harddoomdev.c b/harddoomdev.c new file mode 100644 index 0000000..f903b10 --- /dev/null +++ b/harddoomdev.c @@ -0,0 +1,58 @@ +#include "harddoomdev.h" + +#include "harddoom.h" +#include "doomcode.h" +#include "pci.h" + +void doomdev_write(void __iomem *iomem, size_t addr, uint32_t data) +{ + iowrite32(data, iomem + addr); +} + +uint32_t doomdev_read(void __iomem *iomem, size_t addr) +{ + return ioread32(iomem + addr); +} + +uint32_t doomdev_read_stat(void __iomem *iomem, size_t stat) +{ + return doomdev_read(iomem, HARDDOOM_STATS(stat)); +} + +void load_microcode(void __iomem *iomem) +{ + int i; + + doomdev_write(iomem, HARDDOOM_FE_CODE_ADDR, 0); + for (i = 0; i < ARRAY_SIZE(doomcode); i++) { + doomdev_write(iomem, HARDDOOM_FE_CODE_WINDOW, doomcode[i]); + } +} + +void start_dev(struct pci_dev *dev) +{ + struct doom_data *data; + void __iomem *iomem; + + data = pci_get_drvdata(dev); + iomem = data->iomem; + + load_microcode(iomem); + doomdev_write(iomem, HARDDOOM_RESET, 0xffffffe); + doomdev_write(iomem, HARDDOOM_INTR, 0x3ff); + doomdev_write(iomem, HARDDOOM_ENABLE, + HARDDOOM_ENABLE_ALL ^ HARDDOOM_ENABLE_FETCH_CMD); +} + +void shutdown_dev(struct pci_dev *dev) +{ + struct doom_data *data; + void __iomem *iomem; + + data = pci_get_drvdata(dev); + iomem = data->iomem; + + doomdev_write(iomem, HARDDOOM_ENABLE, 0); + doomdev_write(iomem, HARDDOOM_INTR_ENABLE, 0); + doomdev_read(iomem, 0); +} diff --git a/harddoomdev.h b/harddoomdev.h new file mode 100644 index 0000000..da8dfe1 --- /dev/null +++ b/harddoomdev.h @@ -0,0 +1,9 @@ +#ifndef HARDDOOMDEV_H +#define HARDDOOMDEV_H + +#include + +void start_dev(struct pci_dev *dev); +void shutdown_dev(struct pci_dev *dev); + +#endif diff --git a/pci.c b/pci.c index f8626d9..833a72e 100644 --- a/pci.c +++ b/pci.c @@ -6,6 +6,7 @@ #include "char.h" #include "harddoom.h" #include "util.h" +#include "harddoomdev.h" int init_pci(struct pci_dev *dev) { struct doom_data *doom_data; @@ -53,11 +54,13 @@ int doom_probe(struct pci_dev *dev, const struct pci_device_id *id) int err = 0; ORFAIL(init_pci(dev), error_pci); + start_dev(dev); ORFAIL(new_doomdev(dev), error_doomdev); return 0; error_doomdev: + shutdown_dev(dev); cleanup_pci(dev); error_pci: return err; @@ -70,6 +73,7 @@ void doom_remove (struct pci_dev *dev) doom_data = pci_get_drvdata(dev); destroy_doomdev(doom_data); + shutdown_dev(dev); cleanup_pci(dev); } -- cgit v1.2.3