diff --git a/Makefile b/Makefile index d76de06..5218135 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,14 @@ -obj-m += vendor-reset.o +obj-m := vendor-reset.o +vendor-reset-y := src/vendor-reset.o + +vendor-reset-y += src/amd/vega10.o +vendor-reset-y += src/amd/vega20.o +vendor-reset-y += src/amd/navi10.o + + +ccflags-y := -I$(src)/src +ccflags-y += -I$(src)/include + USER := $(shell whoami) KVER ?= $(shell uname -r) KDIR ?= /lib/modules/$(KVER)/build diff --git a/device-db.h b/src/amd/amd.h similarity index 84% rename from device-db.h rename to src/amd/amd.h index 5a18550..677ce77 100644 --- a/device-db.h +++ b/src/amd/amd.h @@ -16,9 +16,6 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -static struct vendor_reset_device vendor_reset_devices[] = -{ - { - .type = VENDOR_RESET_TYPE_INVALID - } -}; +extern struct vendor_reset_ops amd_vega10_ops; +extern struct vendor_reset_ops amd_vega20_ops; +extern struct vendor_reset_ops amd_navi10_ops; diff --git a/src/amd/navi10.c b/src/amd/navi10.c new file mode 100644 index 0000000..194f877 --- /dev/null +++ b/src/amd/navi10.c @@ -0,0 +1,29 @@ +/* +Vendor Reset - Vendor Specific Reset +Copyright (C) 2020 Geoffrey McRae + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "vendor-reset-dev.h" + +static int amd_navi10_reset(struct pci_dev * dev) +{ + return 0; +} + +const struct vendor_reset_ops amd_navi10_ops = +{ + .reset = amd_navi10_reset +}; diff --git a/src/amd/vega10.c b/src/amd/vega10.c new file mode 100644 index 0000000..c576992 --- /dev/null +++ b/src/amd/vega10.c @@ -0,0 +1,29 @@ +/* +Vendor Reset - Vendor Specific Reset +Copyright (C) 2020 Geoffrey McRae + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "vendor-reset-dev.h" + +static int amd_vega10_reset(struct pci_dev * dev) +{ + return 0; +} + +const struct vendor_reset_ops amd_vega10_ops = +{ + .reset = amd_vega10_reset +}; diff --git a/src/amd/vega20.c b/src/amd/vega20.c new file mode 100644 index 0000000..17d61c5 --- /dev/null +++ b/src/amd/vega20.c @@ -0,0 +1,29 @@ +/* +Vendor Reset - Vendor Specific Reset +Copyright (C) 2020 Geoffrey McRae + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "vendor-reset-dev.h" + +static int amd_vega20_reset(struct pci_dev * dev) +{ + return 0; +} + +const struct vendor_reset_ops amd_vega20_ops = +{ + .reset = amd_vega20_reset +}; diff --git a/src/device-db.h b/src/device-db.h new file mode 100644 index 0000000..02224a1 --- /dev/null +++ b/src/device-db.h @@ -0,0 +1,59 @@ +/* +Vendor Reset - Vendor Specific Reset +Copyright (C) 2020 Geoffrey McRae + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "amd/amd.h" + +static struct vendor_reset_device vendor_reset_devices[] = +{ + /* AMD Vega 10 */ + { PCI_VENDOR_ID_ATI, 0x6860, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x6861, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x6862, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x6863, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x6864, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x6867, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x6868, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x6869, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x686a, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x686b, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x686c, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x686d, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x686e, &amd_vega10_ops }, + { PCI_VENDOR_ID_ATI, 0x686f, &amd_vega10_ops }, + + /* AMD Vega 20 */ + { PCI_VENDOR_ID_ATI, 0x66a0, &amd_vega20_ops }, + { PCI_VENDOR_ID_ATI, 0x66a1, &amd_vega20_ops }, + { PCI_VENDOR_ID_ATI, 0x66a2, &amd_vega20_ops }, + { PCI_VENDOR_ID_ATI, 0x66a3, &amd_vega20_ops }, + { PCI_VENDOR_ID_ATI, 0x66a4, &amd_vega20_ops }, + { PCI_VENDOR_ID_ATI, 0x66a7, &amd_vega20_ops }, + { PCI_VENDOR_ID_ATI, 0x66af, &amd_vega20_ops }, + + /* AMD Navi 10 */ + { PCI_VENDOR_ID_ATI, 0x7310, &amd_navi10_ops }, + { PCI_VENDOR_ID_ATI, 0x7312, &amd_navi10_ops }, + { PCI_VENDOR_ID_ATI, 0x7318, &amd_navi10_ops }, + { PCI_VENDOR_ID_ATI, 0x7319, &amd_navi10_ops }, + { PCI_VENDOR_ID_ATI, 0x731a, &amd_navi10_ops }, + { PCI_VENDOR_ID_ATI, 0x731b, &amd_navi10_ops }, + { PCI_VENDOR_ID_ATI, 0x731e, &amd_navi10_ops }, + { PCI_VENDOR_ID_ATI, 0x731f, &amd_navi10_ops }, + + { 0 } +}; diff --git a/vendor-reset.h b/src/vendor-reset-dev.h similarity index 85% rename from vendor-reset.h rename to src/vendor-reset-dev.h index 0cbee6f..1445daf 100644 --- a/vendor-reset.h +++ b/src/vendor-reset-dev.h @@ -16,11 +16,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _H_VENDOR_RESET -#define _H_VENDOR_RESET - -#define VENDOR_RESET_TYPE_INVALID 0x0 -#define VENDOR_RESET_TYPE_PCI 0x1 +#ifndef _H_VENDOR_RESET_DEV +#define _H_VENDOR_RESET_DEV #define VENDOR_RESET_DEVICE_ALL ((unsigned int)-1) @@ -34,9 +31,6 @@ struct vendor_reset_ops struct vendor_reset_device { - /* one of VENDOR_RESET_TYPE_* */ - unsigned int type; - /* the vendor ID */ unsigned int vendor; @@ -45,7 +39,7 @@ struct vendor_reset_device unsigned int device; /* the reset operations */ - struct vendor_reset_ops ops; + const struct vendor_reset_ops * ops; }; #endif diff --git a/vendor-reset.c b/src/vendor-reset.c similarity index 90% rename from vendor-reset.c rename to src/vendor-reset.c index 3a606b2..c78e8aa 100644 --- a/vendor-reset.c +++ b/src/vendor-reset.c @@ -22,8 +22,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include +#include "vendor-reset-dev.h" #include "vendor-reset.h" -#include "include/vendor-reset.h" #include "device-db.h" @@ -43,25 +43,23 @@ static long vendor_reset_ioctl_reset(struct file * filp, unsigned long arg) if (!pcidev) return -ENODEV; - while(entry->type != VENDOR_RESET_TYPE_INVALID) + for(entry = vendor_reset_devices; entry->vendor; ++entry) { - if (entry->type != VENDOR_RESET_TYPE_PCI || entry->vendor != pcidev->vendor) + if (entry->vendor != pcidev->vendor) continue; if (entry->device == VENDOR_RESET_DEVICE_ALL || entry->device == pcidev->device) break; - - ++entry; } - if (entry->type == VENDOR_RESET_TYPE_INVALID) + if (!entry->vendor) { ret = -EOPNOTSUPP; goto err; } - ret = entry->ops.reset(pcidev); + ret = entry->ops->reset(pcidev); err: pci_dev_put(pcidev);