mgag200 module for Driver Update Program
02d0e223f5ab6ff537517b6994b095648bd27145..0fb7df598d399c8df654b53c80864bdcee886364
2017-07-11 CentOS Sources
import kmod-redhat-mgag200-4.11.0_dup7.3-5.el7_3
0fb7df diff | tree
15 files added
1 files deleted
558 ■■■■■ changed files
.gitignore 1 ●●●● patch | view | raw | blame | history
.kmod-redhat-mgag200.metadata 1 ●●●● patch | view | raw | blame | history
README.md 4 ●●●● patch | view | raw | blame | history
SOURCES/0000-drm-mgag200-Fix-to-always-set-HiPri-for-G200e4-V2.patch 66 ●●●●● patch | view | raw | blame | history
SOURCES/0000-ttm_bo_reserve-fixup.patch 15 ●●●●● patch | view | raw | blame | history
SOURCES/0001-drm_gem_object_lookup-fixup.patch 37 ●●●●● patch | view | raw | blame | history
SOURCES/0002-drm_fb_helper_remove_conflicting_framebuffers-fixup.patch 28 ●●●●● patch | view | raw | blame | history
SOURCES/0003-mga_crtc_gamma_set-revert.patch 32 ●●●●● patch | view | raw | blame | history
SOURCES/0004-mga_vga_detect-revert.patch 28 ●●●●● patch | view | raw | blame | history
SOURCES/0005-drm_vma_node_verify_access-revert.patch 17 ●●●●● patch | view | raw | blame | history
SOURCES/0006-mgag200_bo_move-revert.patch 34 ●●●●● patch | view | raw | blame | history
SOURCES/0007-module-version.patch 13 ●●●●● patch | view | raw | blame | history
SOURCES/0008-gem_free_object-fixup.patch 16 ●●●●● patch | view | raw | blame | history
SOURCES/0009-remove-unknown-ttm_bo_driver-fields.patch 22 ●●●●● patch | view | raw | blame | history
SOURCES/0010-remove-arch_io_reserve-free_memtype_wc.patch 32 ●●●●● patch | view | raw | blame | history
SPECS/mgag200.spec 212 ●●●●● patch | view | raw | blame | history
.gitignore
New file
@@ -0,0 +1 @@
SOURCES/mgag200-redhat-4.11.0_dup7.3.tar.bz2
.kmod-redhat-mgag200.metadata
New file
@@ -0,0 +1 @@
772bd710b1ee875924efc2de548322ca056f165f SOURCES/mgag200-redhat-4.11.0_dup7.3.tar.bz2
README.md
File was deleted
SOURCES/0000-drm-mgag200-Fix-to-always-set-HiPri-for-G200e4-V2.patch
New file
@@ -0,0 +1,66 @@
From df9d3b2f13d96f30cd49caa634387d49e8a9d2b8 Mon Sep 17 00:00:00 2001
From: Rob Clark <rclark@redhat.com>
Date: Fri, 16 Jun 2017 00:04:07 -0400
Subject: [PATCH] [drm] mgag200: Fix to always set HiPri for G200e4 V2
Message-id: <20170616000407.30823-1-rclark@redhat.com>
Patchwork-id: 179792
O-Subject: [RHEL7 drm] drm/mgag200: Fix to always set HiPri for G200e4 V2
Bugzilla: 1461985
RH-Acked-by: Jeremy McNicoll <jmcnicol@redhat.com>
RH-Acked-by: Dave Airlie <airlied@redhat.com>
Upstream: drm-misc-fixes-2017-06-15
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1461985
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=13446539
commit 426f719e7f1619c5f1b11c3f17a31f97956f5c3a
Author:     Mathieu Larouche <mathieu.larouche@matrox.com>
AuthorDate: Wed Jun 14 10:34:11 2017 -0400
Commit:     Rob Clark <rclark@redhat.com>
CommitDate: Thu Jun 15 16:55:04 2017 -0400
    drm/mgag200: Fix to always set HiPri for G200e4 V2
      - Changed the HiPri value for G200e4 to always be 0.
      - Added Bandwith limitation to block resolution above 1920x1200x60Hz
    Signed-off-by: Mathieu Larouche <mathieu.larouche@matrox.com>
Signed-off-by: Rob Clark <rclark@redhat.com>
Signed-off-by: Rafael Aquini <aquini@redhat.com>
---
 drivers/gpu/drm/mgag200/mgag200_mode.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c
index 83b80ee..dcdb4fc 100644
--- a/drivers/gpu/drm/mgag200/mgag200_mode.c
+++ b/drivers/gpu/drm/mgag200/mgag200_mode.c
@@ -1172,7 +1172,10 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
     if (IS_G200_SE(mdev)) {
-        if (mdev->unique_rev_id >= 0x02) {
+        if  (mdev->unique_rev_id >= 0x04) {
+            WREG8(MGAREG_CRTCEXT_INDEX, 0x06);
+            WREG8(MGAREG_CRTCEXT_DATA, 0);
+        } else if (mdev->unique_rev_id >= 0x02) {
             u8 hi_pri_lvl;
             u32 bpp;
             u32 mb;
@@ -1637,6 +1640,10 @@ static int mga_vga_mode_valid(struct drm_connector *connector,
             if (mga_vga_calculate_mode_bandwidth(mode, bpp)
                 > (30100 * 1024))
                 return MODE_BANDWIDTH;
+        } else {
+            if (mga_vga_calculate_mode_bandwidth(mode, bpp)
+                > (55000 * 1024))
+                return MODE_BANDWIDTH;
         }
     } else if (mdev->type == G200_WB) {
         if (mode->hdisplay > 1280)
--
2.9.3
SOURCES/0000-ttm_bo_reserve-fixup.patch
New file
@@ -0,0 +1,15 @@
Reverting a change introduced in 6de7e7f8b3698 "[drm] upstream sync to v4.10"
(upstream c470abd4fde40ea).
Index: src/drivers/gpu/drm/mgag200/mgag200_drv.h
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_drv.h    2017-06-09 15:07:22.093162348 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_drv.h    2017-06-09 15:19:29.234861443 +0200
@@ -282,7 +282,7 @@
 {
     int ret;
-    ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
+    ret = ttm_bo_reserve(&bo->bo, true, no_wait, false, NULL);
     if (ret) {
         if (ret != -ERESTARTSYS && ret != -EBUSY)
             DRM_ERROR("reserve failed %p\n", bo);
SOURCES/0001-drm_gem_object_lookup-fixup.patch
New file
@@ -0,0 +1,37 @@
Reverting a change introduced in 6de7e7f8b3698 "[drm] upstream sync to v4.10"
(upstream c470abd4fde40ea).
Index: src/drivers/gpu/drm/mgag200/mgag200_main.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_main.c    2017-06-09 15:41:00.280046938 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_main.c    2017-06-09 15:42:10.346236732 +0200
@@ -55,7 +55,7 @@
     struct mga_framebuffer *mga_fb;
     int ret;
-    obj = drm_gem_object_lookup(filp, mode_cmd->handles[0]);
+    obj = drm_gem_object_lookup(dev, filp, mode_cmd->handles[0]);
     if (obj == NULL)
         return ERR_PTR(-ENOENT);
@@ -364,7 +364,7 @@
     struct drm_gem_object *obj;
     struct mgag200_bo *bo;
-    obj = drm_gem_object_lookup(file, handle);
+    obj = drm_gem_object_lookup(dev, file, handle);
     if (obj == NULL)
         return -ENOENT;
Index: src/drivers/gpu/drm/mgag200/mgag200_cursor.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_cursor.c    2017-06-09 15:07:22.093162348 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_cursor.c    2017-06-09 15:42:35.759942862 +0200
@@ -75,7 +75,7 @@
         return 0;
     }
-    obj = drm_gem_object_lookup(file_priv, handle);
+    obj = drm_gem_object_lookup(dev, file_priv, handle);
     if (!obj)
         return -ENOENT;
SOURCES/0002-drm_fb_helper_remove_conflicting_framebuffers-fixup.patch
New file
@@ -0,0 +1,28 @@
Reverting a change introduced in 6de7e7f8b3698 "[drm] upstream sync to v4.10"
(upstream c470abd4fde40ea).
Index: src/drivers/gpu/drm/mgag200/mgag200_drv.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_drv.c    2017-06-09 15:24:20.259565585 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_drv.c    2017-06-09 15:24:53.266191785 +0200
@@ -60,7 +60,7 @@
 #ifdef CONFIG_X86
     primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
 #endif
-    drm_fb_helper_remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
+    remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
     kfree(ap);
 }
Index: src/drivers/gpu/drm/mgag200/mgag200_main.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_main.c    2017-06-09 15:24:53.230192192 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_main.c    2017-06-09 15:25:49.516554749 +0200
@@ -137,7 +137,7 @@
     aper->ranges[0].base = mdev->mc.vram_base;
     aper->ranges[0].size = mdev->mc.vram_window;
-    drm_fb_helper_remove_conflicting_framebuffers(aper, "mgafb", true);
+    remove_conflicting_framebuffers(aper, "mgafb", true);
     kfree(aper);
     if (!devm_request_mem_region(mdev->dev->dev, mdev->mc.vram_base, mdev->mc.vram_window,
SOURCES/0003-mga_crtc_gamma_set-revert.patch
New file
@@ -0,0 +1,32 @@
Reverting a change introduced in 6de7e7f8b3698 "[drm] upstream sync to v4.10"
(upstream c470abd4fde40ea).
Index: src/drivers/gpu/drm/mgag200/mgag200_mode.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_mode.c    2017-06-20 20:40:11.261262778 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_mode.c    2017-06-20 20:40:39.610842564 +0200
@@ -1394,20 +1394,19 @@
  * use this for 8-bit mode so can't perform smooth fades on deeper modes,
  * but it's a requirement that we provide the function
  */
-static int mga_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
-                  u16 *blue, uint32_t size)
+static void mga_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
+                   u16 *blue, uint32_t start, uint32_t size)
 {
     struct mga_crtc *mga_crtc = to_mga_crtc(crtc);
+    int end = (start + size > MGAG200_LUT_SIZE) ? MGAG200_LUT_SIZE : start + size;
     int i;
-    for (i = 0; i < size; i++) {
+    for (i = start; i < end; i++) {
         mga_crtc->lut_r[i] = red[i] >> 8;
         mga_crtc->lut_g[i] = green[i] >> 8;
         mga_crtc->lut_b[i] = blue[i] >> 8;
     }
     mga_crtc_load_lut(crtc);
-
-    return 0;
 }
 /* Simple cleanup function */
SOURCES/0004-mga_vga_detect-revert.patch
New file
@@ -0,0 +1,28 @@
Reverting a change introduced in 6de7e7f8b3698 "[drm] upstream sync to v4.10"
(upstream c470abd4fde40ea).
Index: src/drivers/gpu/drm/mgag200/mgag200_mode.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_mode.c    2017-06-20 20:40:39.610842564 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_mode.c    2017-06-20 20:40:43.294787960 +0200
@@ -1703,6 +1703,12 @@
     return NULL;
 }
+static enum drm_connector_status mga_vga_detect(struct drm_connector
+                        *connector, bool force)
+{
+    return connector_status_connected;
+}
+
 static void mga_connector_destroy(struct drm_connector *connector)
 {
     struct mga_connector *mga_connector = to_mga_connector(connector);
@@ -1719,6 +1725,7 @@
 static const struct drm_connector_funcs mga_vga_connector_funcs = {
     .dpms = drm_helper_connector_dpms,
+    .detect = mga_vga_detect,
     .fill_modes = drm_helper_probe_single_connector_modes,
     .destroy = mga_connector_destroy,
 };
SOURCES/0005-drm_vma_node_verify_access-revert.patch
New file
@@ -0,0 +1,17 @@
Reverting a change introduced in 6de7e7f8b3698 "[drm] upstream sync to v4.10"
(upstream c470abd4fde40ea).
Index: src/drivers/gpu/drm/mgag200/mgag200_ttm.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_ttm.c    2017-06-20 20:40:34.664915876 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_ttm.c    2017-06-20 20:40:45.435756224 +0200
@@ -150,8 +150,7 @@
 {
     struct mgag200_bo *mgabo = mgag200_bo(bo);
-    return drm_vma_node_verify_access(&mgabo->gem.vma_node,
-                      filp->private_data);
+    return drm_vma_node_verify_access(&mgabo->gem.vma_node, filp);
 }
 static int mgag200_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
SOURCES/0006-mgag200_bo_move-revert.patch
New file
@@ -0,0 +1,34 @@
Reverting a change introduced in 6de7e7f8b3698 "[drm] upstream sync to v4.10"
(upstream c470abd4fde40ea).
Index: src/drivers/gpu/drm/mgag200/mgag200_ttm.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_ttm.c    2017-06-20 20:40:45.435756224 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_ttm.c    2017-06-20 20:40:47.431726640 +0200
@@ -186,6 +186,17 @@
 {
 }
+static int mgag200_bo_move(struct ttm_buffer_object *bo,
+               bool evict, bool interruptible,
+               bool no_wait_gpu,
+               struct ttm_mem_reg *new_mem)
+{
+    int r;
+    r = ttm_bo_move_memcpy(bo, evict, no_wait_gpu, new_mem);
+    return r;
+}
+
+
 static void mgag200_ttm_backend_destroy(struct ttm_tt *tt)
 {
     ttm_tt_fini(tt);
@@ -231,7 +242,7 @@
     .init_mem_type = mgag200_bo_init_mem_type,
     .eviction_valuable = ttm_bo_eviction_valuable,
     .evict_flags = mgag200_bo_evict_flags,
-    .move = NULL,
+    .move = mgag200_bo_move,
     .verify_access = mgag200_bo_verify_access,
     .io_mem_reserve = &mgag200_ttm_io_mem_reserve,
     .io_mem_free = &mgag200_ttm_io_mem_free,
SOURCES/0007-module-version.patch
New file
@@ -0,0 +1,13 @@
Adding module version in order to be able to identify driver in use.
Using (upstream) kernel version driver's code from as a driver version.
Index: src/drivers/gpu/drm/mgag200/mgag200_drv.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_drv.c    2017-06-20 20:40:30.541976989 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_drv.c    2017-06-20 20:40:49.310698789 +0200
@@ -145,3 +145,4 @@
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL");
+MODULE_VERSION("4.11.0_dup7.3");
SOURCES/0008-gem_free_object-fixup.patch
New file
@@ -0,0 +1,16 @@
Reverting a change introduced in 6de7e7f8b3698 "[drm] upstream sync to v4.10"
(upstream c470abd4fde40ea).
Index: src/drivers/gpu/drm/mgag200/mgag200_drv.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_drv.c    2017-06-20 20:40:49.310698789 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_drv.c    2017-06-20 20:40:51.234670270 +0200
@@ -103,7 +103,7 @@
     .minor = DRIVER_MINOR,
     .patchlevel = DRIVER_PATCHLEVEL,
-    .gem_free_object_unlocked = mgag200_gem_free_object,
+    .gem_free_object = mgag200_gem_free_object,
     .dumb_create = mgag200_dumb_create,
     .dumb_map_offset = mgag200_dumb_mmap_offset,
     .dumb_destroy = drm_gem_dumb_destroy,
SOURCES/0009-remove-unknown-ttm_bo_driver-fields.patch
New file
@@ -0,0 +1,22 @@
Reverting a change introduced in 6de7e7f8b3698 "[drm] upstream sync to v4.10"
(upstream c470abd4fde40ea).
Index: src/drivers/gpu/drm/mgag200/mgag200_ttm.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_ttm.c    2017-06-20 20:40:47.431726640 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_ttm.c    2017-06-20 20:40:53.018643824 +0200
@@ -240,14 +240,11 @@
     .ttm_tt_populate = mgag200_ttm_tt_populate,
     .ttm_tt_unpopulate = mgag200_ttm_tt_unpopulate,
     .init_mem_type = mgag200_bo_init_mem_type,
-    .eviction_valuable = ttm_bo_eviction_valuable,
     .evict_flags = mgag200_bo_evict_flags,
     .move = mgag200_bo_move,
     .verify_access = mgag200_bo_verify_access,
     .io_mem_reserve = &mgag200_ttm_io_mem_reserve,
     .io_mem_free = &mgag200_ttm_io_mem_free,
-    .lru_tail = &ttm_bo_default_lru_tail,
-    .swap_lru_tail = &ttm_bo_default_swap_lru_tail,
 };
 int mgag200_mm_init(struct mga_device *mdev)
SOURCES/0010-remove-arch_io_reserve-free_memtype_wc.patch
New file
@@ -0,0 +1,32 @@
Reverting a change introduced in 6de7e7f8b3698 "[drm] upstream sync to v4.10"
(upstream c470abd4fde40ea).
Index: src/drivers/gpu/drm/mgag200/mgag200_ttm.c
===================================================================
--- src.orig/drivers/gpu/drm/mgag200/mgag200_ttm.c    2017-06-20 20:40:53.018643824 +0200
+++ src/drivers/gpu/drm/mgag200/mgag200_ttm.c    2017-06-20 20:40:54.786617618 +0200
@@ -274,9 +274,6 @@
         return ret;
     }
-    arch_io_reserve_memtype_wc(pci_resource_start(dev->pdev, 0),
-                   pci_resource_len(dev->pdev, 0));
-
     mdev->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0),
                      pci_resource_len(dev->pdev, 0));
@@ -285,14 +282,10 @@
 void mgag200_mm_fini(struct mga_device *mdev)
 {
-    struct drm_device *dev = mdev->dev;
-
     ttm_bo_device_release(&mdev->ttm.bdev);
     mgag200_ttm_global_release(mdev);
-    arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
-                pci_resource_len(dev->pdev, 0));
     arch_phys_wc_del(mdev->fb_mtrr);
     mdev->fb_mtrr = 0;
 }
SPECS/mgag200.spec
New file
@@ -0,0 +1,212 @@
%define kmod_name        mgag200
%define kmod_vendor        redhat
%define kmod_driver_version    4.11.0_dup7.3
%define kmod_rpm_release    5
%define kmod_kernel_version    3.10.0-514.el7
%define kmod_kbuild_dir        drivers/gpu/drm/mgag200
%define kmod_dependencies       %{nil}
%define kmod_build_dependencies    %{nil}
%define kmod_devel_package    0
%{!?dist: %define dist .el7_3}
Source0:    %{kmod_name}-%{kmod_vendor}-%{kmod_driver_version}.tar.bz2
# Source code patches
Patch0:    0000-drm-mgag200-Fix-to-always-set-HiPri-for-G200e4-V2.patch
Patch1:    0000-ttm_bo_reserve-fixup.patch
Patch2:    0001-drm_gem_object_lookup-fixup.patch
Patch3:    0002-drm_fb_helper_remove_conflicting_framebuffers-fixup.patch
Patch4:    0003-mga_crtc_gamma_set-revert.patch
Patch5:    0004-mga_vga_detect-revert.patch
Patch6:    0005-drm_vma_node_verify_access-revert.patch
Patch7:    0006-mgag200_bo_move-revert.patch
Patch8:    0007-module-version.patch
Patch9:    0008-gem_free_object-fixup.patch
Patch10:    0009-remove-unknown-ttm_bo_driver-fields.patch
Patch11:    0010-remove-arch_io_reserve-free_memtype_wc.patch
%define findpat %( echo "%""P" )
%define __find_requires /usr/lib/rpm/redhat/find-requires.ksyms
%define __find_provides /usr/lib/rpm/redhat/find-provides.ksyms %{kmod_name} %{?epoch:%{epoch}:}%{version}-%{release}
%define sbindir %( if [ -d "/sbin" -a \! -h "/sbin" ]; then echo "/sbin"; else echo %{_sbindir}; fi )
Name:        kmod-redhat-mgag200
Version:    %{kmod_driver_version}
Release:    %{kmod_rpm_release}%{?dist}
Summary:    mgag200 module for Driver Update Program
Group:        System/Kernel
License:    GPLv2
URL:        http://www.kernel.org/
BuildRoot:    %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires:    kernel-devel = %kmod_kernel_version redhat-rpm-config kernel-abi-whitelists
ExclusiveArch:    x86_64
%global kernel_source() /usr/src/kernels/%{kmod_kernel_version}.$(arch)
%global _use_internal_dependency_generator 0
Provides:    kernel-modules = %kmod_kernel_version.%{_target_cpu}
Provides:    kmod-%{kmod_name} = %{?epoch:%{epoch}:}%{version}-%{release}
Requires(post):    %{sbindir}/weak-modules
Requires(postun):    %{sbindir}/weak-modules
Requires:    kernel >= 3.10.0-514.el7
Requires:    kernel < 3.10.0-515.el7
%if 0
Requires: firmware(%{kmod_name}) = ENTER_FIRMWARE_VERSION
%endif
%if "%{kmod_build_dependencies}" != ""
BuildRequires:  %{kmod_build_dependencies}
%endif
%if "%{kmod_dependencies}" != ""
Requires:       %{kmod_dependencies}
%endif
# if there are multiple kmods for the same driver from different vendors,
# they should conflict with each other.
Conflicts:    kmod-%{kmod_name}
%description
mgag200 module for Driver Update Program
%if 0
%package -n kmod-redhat-mgag200-firmware
Version:    ENTER_FIRMWARE_VERSION
Summary:    mgag200 firmware for Driver Update Program
Provides:    firmware(%{kmod_name}) = ENTER_FIRMWARE_VERSION
Provides:    kernel-modules = %{kmod_kernel_version}.%{_target_cpu}
%description -n  kmod-redhat-mgag200-firmware
mgag200 firmware for Driver Update Program
%files -n kmod-redhat-mgag200-firmware
%defattr(644,root,root,755)
%{FIRMWARE_FILES}
%endif
# Development package
%if 0%{kmod_devel_package}
%package -n kmod-redhat-mgag200-devel
Version:    %{kmod_driver_version}
Requires:    kernel >= 3.10.0-514.el7
Requires:    kernel < 3.10.0-515.el7
Summary:    %{DEVEL_SUMMARY}
%description -n  kmod-redhat-mgag200-devel
%{DEVEL_DESCRIPTION_CONTENT}
%files -n kmod-redhat-mgag200-devel
%defattr(644,root,root,755)
/usr/share/kmod-%{kmod_vendor}-%{kmod_name}/Module.symvers
%endif
%post
modules=( $(find /lib/modules/%{kmod_kernel_version}.%(arch)/extra/kmod-%{kmod_vendor}-%{kmod_name} | grep '\.ko$') )
printf '%s\n' "${modules[@]}" >> /var/lib/rpm-kmod-posttrans-weak-modules-add
%pretrans -p <lua>
posix.unlink("/var/lib/rpm-kmod-posttrans-weak-modules-add")
%posttrans
if [ -f "/var/lib/rpm-kmod-posttrans-weak-modules-add" ]; then
    modules=( $(cat /var/lib/rpm-kmod-posttrans-weak-modules-add) )
    rm -rf /var/lib/rpm-kmod-posttrans-weak-modules-add
    printf '%s\n' "${modules[@]}" | %{sbindir}/weak-modules --add-modules
fi
%preun
rpm -ql kmod-redhat-mgag200-%{kmod_driver_version}-%{kmod_rpm_release}%{?dist}.$(arch) | grep '\.ko$' > /var/run/rpm-kmod-%{kmod_name}-modules
%postun
modules=( $(cat /var/run/rpm-kmod-%{kmod_name}-modules) )
rm /var/run/rpm-kmod-%{kmod_name}-modules
printf '%s\n' "${modules[@]}" | %{sbindir}/weak-modules --remove-modules
%files
%defattr(644,root,root,755)
/lib/modules/%{kmod_kernel_version}.%(arch)
/etc/depmod.d/%{kmod_name}.conf
/usr/share/doc/kmod-%{kmod_name}/greylist.txt
%prep
%setup -n %{kmod_name}-%{kmod_vendor}-%{kmod_driver_version}
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
set -- *
mkdir source
mv "$@" source/
mkdir obj
%build
rm -rf obj
cp -r source obj
make -C %{kernel_source} M=$PWD/obj/%{kmod_kbuild_dir} \
    NOSTDINC_FLAGS="-I $PWD/obj/include -I $PWD/obj/include/uapi"
# mark modules executable so that strip-to-file can strip them
find obj/%{kmod_kbuild_dir} -name "*.ko" -type f -exec chmod u+x '{}' +
whitelist="/lib/modules/kabi-current/kabi_whitelist_%{_target_cpu}"
for modules in $( find obj/%{kmod_kbuild_dir} -name "*.ko" -type f -printf "%{findpat}\n" | sed 's|\.ko$||' | sort -u ) ; do
    # update depmod.conf
    module_weak_path=$(echo $modules | sed 's/[\/]*[^\/]*$//')
    if [ -z "$module_weak_path" ]; then
        module_weak_path=%{name}
    else
        module_weak_path=%{name}/$module_weak_path
    fi
    echo "override $(echo $modules | sed 's/.*\///') $(echo %{kmod_kernel_version} | sed 's/\.[^\.]*$//').* weak-updates/$module_weak_path" >> source/depmod.conf
    # update greylist
    nm -u obj/%{kmod_kbuild_dir}/$modules.ko | sed 's/.*U //' |  sed 's/^\.//' | sort -u | while read -r symbol; do
        grep -q "^\s*$symbol\$" $whitelist || echo "$symbol" >> source/greylist
    done
done
sort -u source/greylist | uniq > source/greylist.txt
%install
export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
export INSTALL_MOD_DIR=extra/%{name}
make -C %{kernel_source} modules_install \
    M=$PWD/obj/%{kmod_kbuild_dir}
# Cleanup unnecessary kernel-generated module dependency files.
find $INSTALL_MOD_PATH/lib/modules -iname 'modules.*' -exec rm {} \;
install -m 644 -D source/depmod.conf $RPM_BUILD_ROOT/etc/depmod.d/%{kmod_name}.conf
install -m 644 -D source/greylist.txt $RPM_BUILD_ROOT/usr/share/doc/kmod-%{kmod_name}/greylist.txt
%if 0
%{FIRMWARE_FILES_INSTALL}
%endif
%if 0%{kmod_devel_package}
install -m 644 -D $PWD/obj/%{kmod_kbuild_dir}/Module.symvers $RPM_BUILD_ROOT/usr/share/kmod-%{kmod_vendor}-%{kmod_name}/Module.symvers
%endif
%clean
rm -rf $RPM_BUILD_ROOT
%changelog
* Fri Jun 23 2017 Eugene Syromiatnikov <esyr@redhat.com> 4.11.0_dup7.3-5
- 8d4022de88b02a390621a2bf9614b25b094951f8
- Provide fix for the #bz1463535 as a separate patch in order to preserve
  the integrity of sources.
* Fri Jun 23 2017 Eugene Syromiatnikov <esyr@redhat.com> 4.11.0_dup7.3-4
- Rewrite %pretrans to Lua, which allows using RPM in the installation
  environment.
* Tue Jun 20 2017 Eugene Syromiatnikov <esyr@redhat.com> 4.11.0_dup7.3-3
- Resolves: #bz1463535
- df9d3b2f13d96f30cd49caa634387d49e8a9d2b8
* Mon Jun 19 2017 Eugene Syromiatnikov <esyr@redhat.com> 4.11.0_dup7.3-1
- Resolves: #bz1462099
- 8d4022de88b02a390621a2bf9614b25b094951f8
- mgag200 module for Driver Update Program