2012-06-14 17:53:07

by Ozan Çağlayan

[permalink] [raw]
Subject: [PATCH 1/3] compat: Backport vga_switcheroo_client_ops

This backports:

From 26ec685ff9d9c16525d8ec4c97e52fcdb187b302 Mon Sep 17 00:00:00

From: Takashi Iwai <[email protected]>
Date: Fri, 11 May 2012 07:51:17 +0200
Subject: [PATCH] vga_switcheroo: Introduce struct vga_switcheroo_client_ops

only for kernels >= 2.6.34 in which vga_switcheroo is available.

Trying kernel 3.4.0-030400-generic [OK]
Trying kernel 3.3.7-030307-generic [OK]
Trying kernel 3.2.2-030202-generic [OK]
Trying kernel 3.1.10-030110-generic [OK]
Trying kernel 3.0.18-030018-generic [OK]
Trying kernel 2.6.39-02063904-generic [OK]
Trying kernel 2.6.38-02063808-generic [OK]
Trying kernel 2.6.37-02063706-generic [OK]
Trying kernel 2.6.36-02063604-generic [OK]
Trying kernel 2.6.35-02063512-generic [OK]
Trying kernel 2.6.34-02063410-generic [OK]
Trying kernel 2.6.33-02063305-generic [OK]
Trying kernel 2.6.32-02063255-generic [OK]
Trying kernel 2.6.31-02063113-generic [OK]
Trying kernel 2.6.30-02063010-generic [OK]
Trying kernel 2.6.29-02062906-generic [OK]
Trying kernel 2.6.28-02062810-generic [OK]
Trying kernel 2.6.27-020627-generic [OK]
Trying kernel 2.6.26-020626-generic [OK]
Trying kernel 2.6.25-020625-generic [OK]
Trying kernel 2.6.24-020624-generic [OK]

Signed-off-by: Ozan Çağlayan <[email protected]>
---
include/linux/compat-3.5.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/include/linux/compat-3.5.h b/include/linux/compat-3.5.h
index 3f97a3d..1d9128a 100644
--- a/include/linux/compat-3.5.h
+++ b/include/linux/compat-3.5.h
@@ -8,6 +8,26 @@

#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0))

+/* switcheroo is available on >= 2.6.34 */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34))
+#include <linux/vga_switcheroo.h>
+/*
+ * This backports:
+ *
+ * From 26ec685ff9d9c16525d8ec4c97e52fcdb187b302 Mon Sep 17 00:00:00 2001
+ * From: Takashi Iwai <[email protected]>
+ * Date: Fri, 11 May 2012 07:51:17 +0200
+ * Subject: [PATCH] vga_switcheroo: Introduce struct vga_switcheroo_client_ops
+ *
+ */
+
+struct vga_switcheroo_client_ops {
+ void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state);
+ void (*reprobe)(struct pci_dev *dev);
+ bool (*can_switch)(struct pci_dev *dev);
+};
+#endif
+
/*
* This backports:
*
--
1.7.10.2



2012-06-14 21:30:25

by Luis R. Rodriguez

[permalink] [raw]
Subject: Re: [PATCH 3/3] compat: Backport fault_in_multipages_{writeable,readable}

T24gVGh1LCBKdW4gMTQsIDIwMTIgYXQgMTA6NTIgQU0sIE96YW4gw4dhxJ9sYXlhbiA8b3phbmNh
Z0BnbWFpbC5jb20+IHdyb3RlOgo+IFRoaXMgYmFja3BvcnRzOgo+Cj4gY29tbWl0IGY1NmY4MjFm
ZWI3YjM2MjIzZjMwOWUwZWMwNTk4NmJiMTM3Y2U0MTgKPiBBdXRob3I6IERhbmllbCBWZXR0ZXIg
PGRhbmllbC52ZXR0ZXJAZmZ3bGwuY2g+Cj4gRGF0ZTogwqAgU3VuIE1hciAyNSAxOTo0Nzo0MSAy
MDEyICswMjAwCj4KPiDCoCDCoG1tOiBleHRlbmQgcHJlZmF1bHQgaGVscGVycyB0byBmYXVsdCBp
biBtb3JlIHRoYW4gUEFHRV9TSVpFCj4KPiBUaGUgbmV3IGZ1bmN0aW9ucyBhcmUgdXNlZCBieSBk
cm0vaTkxNSBkcml2ZXIuCj4KPiBUcnlpbmcga2VybmVsIMKgIMKgIMKgIMKgIMKgIMKgIMKgIMKg
IMKgIMKgIDMuNC4wLTAzMDQwMC1nZW5lcmljIMKgW09LXQo+IFRyeWluZyBrZXJuZWwgwqAgwqAg
wqAgwqAgwqAgwqAgwqAgwqAgwqAgwqAgMy4zLjctMDMwMzA3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MdWlzCg==

2012-06-14 19:52:03

by Luis R. Rodriguez

[permalink] [raw]
Subject: Re: [PATCH 1/3] compat: Backport vga_switcheroo_client_ops

On Thu, Jun 14, 2012 at 10:57 AM, Ozan Çağlayan <[email protected]> wrote:
> On Thu, Jun 14, 2012 at 8:52 PM, Ozan Çağlayan <[email protected]> wrote:
>> This backports:
>>
>>  From 26ec685ff9d9c16525d8ec4c97e52fcdb187b302 Mon Sep 17 00:00:00
>>
>>  From: Takashi Iwai <[email protected]>
>>  Date: Fri, 11 May 2012 07:51:17 +0200
>>  Subject: [PATCH] vga_switcheroo: Introduce struct vga_switcheroo_client_ops
>>
>>  only for kernels >= 2.6.34 in which vga_switcheroo is available.
>
> Do you accept conditional additions like this into compat? If not,
> what is the proper way of doing this?

Sure thing, we do this in numerous places, good stuff!

> Another question, the vga_switcheroo.h which is included here for the
> enum declaration is not guarded against multiple inclusion. So when
> building compat-drm/drm/i915, I get nested declaration error. I looked
> at other headers and they are all guarded, so I sent a patch to
> dri-devel which adds ifndef guard in vga_switcheroo.h. Is this the
> correct way of fixing a second inclusion of an header file which gets
> already included through compat?

Sure thing, the upstream version should have had that check, thanks
for sending that upstream!

I should also note though for future development if you run into a
header that is *not* present on older kernels but you want to bring
forward for older kernels *but* you do not want that compat header to
replace the one on newer kernels you can do something like this (this
is include/linux/kfifo.h on compat.git):

#include <linux/version.h>
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
#include_next <linux/kfifo.h>
#else

/* the rest of the foo kfifo.h */

#endif
#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)) */

In your case you do not seem to need this given that you are not
bringing forward switcheroo to older kernels, but if you could you may
be able to pull it off using a hack like the above.

Luis

2012-06-14 17:53:26

by Ozan Çağlayan

[permalink] [raw]
Subject: [PATCH 3/3] compat: Backport fault_in_multipages_{writeable,readable}

This backports:

commit f56f821feb7b36223f309e0ec05986bb137ce418
Author: Daniel Vetter <[email protected]>
Date: Sun Mar 25 19:47:41 2012 +0200

mm: extend prefault helpers to fault in more than PAGE_SIZE

The new functions are used by drm/i915 driver.

Trying kernel 3.4.0-030400-generic [OK]
Trying kernel 3.3.7-030307-generic [OK]
Trying kernel 3.2.2-030202-generic [OK]
Trying kernel 3.1.10-030110-generic [OK]
Trying kernel 3.0.18-030018-generic [OK]
Trying kernel 2.6.39-02063904-generic [OK]
Trying kernel 2.6.38-02063808-generic [OK]
Trying kernel 2.6.37-02063706-generic [OK]
Trying kernel 2.6.36-02063604-generic [OK]
Trying kernel 2.6.35-02063512-generic [OK]
Trying kernel 2.6.34-02063410-generic [OK]
Trying kernel 2.6.33-02063305-generic [OK]
Trying kernel 2.6.32-02063255-generic [OK]
Trying kernel 2.6.31-02063113-generic [OK]
Trying kernel 2.6.30-02063010-generic [OK]
Trying kernel 2.6.29-02062906-generic [OK]
Trying kernel 2.6.28-02062810-generic [OK]
Trying kernel 2.6.27-020627-generic [OK]
Trying kernel 2.6.26-020626-generic [OK]
Trying kernel 2.6.25-020625-generic [OK]
Trying kernel 2.6.24-020624-generic [OK]

Signed-off-by: Ozan Çağlayan <[email protected]>
---
include/linux/compat-3.5.h | 67 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)

diff --git a/include/linux/compat-3.5.h b/include/linux/compat-3.5.h
index 1d9128a..74c8176 100644
--- a/include/linux/compat-3.5.h
+++ b/include/linux/compat-3.5.h
@@ -8,6 +8,73 @@

#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0))

+/*
+ * This backports:
+ *
+ * commit f56f821feb7b36223f309e0ec05986bb137ce418
+ * Author: Daniel Vetter <[email protected]>
+ * Date: Sun Mar 25 19:47:41 2012 +0200
+ *
+ * mm: extend prefault helpers to fault in more than PAGE_SIZE
+ *
+ * The new functions are used by drm/i915 driver.
+ *
+ */
+
+static inline int fault_in_multipages_writeable(char __user *uaddr, int size)
+{
+ int ret = 0;
+ char __user *end = uaddr + size - 1;
+
+ if (unlikely(size == 0))
+ return ret;
+
+ /*
+ * Writing zeroes into userspace here is OK, because we know that if
+ * the zero gets there, we'll be overwriting it.
+ */
+ while (uaddr <= end) {
+ ret = __put_user(0, uaddr);
+ if (ret != 0)
+ return ret;
+ uaddr += PAGE_SIZE;
+ }
+
+ /* Check whether the range spilled into the next page. */
+ if (((unsigned long)uaddr & PAGE_MASK) ==
+ ((unsigned long)end & PAGE_MASK))
+ ret = __put_user(0, end);
+
+ return ret;
+}
+
+static inline int fault_in_multipages_readable(const char __user *uaddr,
+ int size)
+{
+ volatile char c;
+ int ret = 0;
+ const char __user *end = uaddr + size - 1;
+
+ if (unlikely(size == 0))
+ return ret;
+
+ while (uaddr <= end) {
+ ret = __get_user(c, uaddr);
+ if (ret != 0)
+ return ret;
+ uaddr += PAGE_SIZE;
+ }
+
+ /* Check whether the range spilled into the next page. */
+ if (((unsigned long)uaddr & PAGE_MASK) ==
+ ((unsigned long)end & PAGE_MASK)) {
+ ret = __get_user(c, end);
+ (void)c;
+ }
+
+ return ret;
+}
+
/* switcheroo is available on >= 2.6.34 */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34))
#include <linux/vga_switcheroo.h>
--
1.7.10.2


2012-06-14 17:57:42

by Ozan Çağlayan

[permalink] [raw]
Subject: Re: [PATCH 1/3] compat: Backport vga_switcheroo_client_ops

On Thu, Jun 14, 2012 at 8:52 PM, Ozan Çağlayan <[email protected]> wrote:
> This backports:
>
>  From 26ec685ff9d9c16525d8ec4c97e52fcdb187b302 Mon Sep 17 00:00:00
>
>  From: Takashi Iwai <[email protected]>
>  Date: Fri, 11 May 2012 07:51:17 +0200
>  Subject: [PATCH] vga_switcheroo: Introduce struct vga_switcheroo_client_ops
>
>  only for kernels >= 2.6.34 in which vga_switcheroo is available.

Do you accept conditional additions like this into compat? If not,
what is the proper way of doing this?

Another question, the vga_switcheroo.h which is included here for the
enum declaration is not guarded against multiple inclusion. So when
building compat-drm/drm/i915, I get nested declaration error. I looked
at other headers and they are all guarded, so I sent a patch to
dri-devel which adds ifndef guard in vga_switcheroo.h. Is this the
correct way of fixing a second inclusion of an header file which gets
already included through compat?

Thanks :)



--
Ozan Çağlayan

2012-06-14 17:53:14

by Ozan Çağlayan

[permalink] [raw]
Subject: [PATCH 2/3] compat: Fix cosmetic typo in compat-3.4.c

compat-3.4.c is for kernel version 3.4 not 3.5.

Signed-off-by: Ozan Çağlayan <[email protected]>
---
compat/compat-3.4.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/compat-3.4.c b/compat/compat-3.4.c
index 5d516f0..4721fa2 100644
--- a/compat/compat-3.4.c
+++ b/compat/compat-3.4.c
@@ -5,7 +5,7 @@
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
- * Compatibility file for Linux wireless for kernels 3.5.
+ * Compatibility file for Linux wireless for kernels 3.4.
*/

#include <linux/fs.h>
--
1.7.10.2