2007/04/18

To make fglrx (ATI X driver) works with xen kernel

From http://pastebin.ca/350588
Tested and it really works, even with latest ATI driver.

iwan ~ # cat /usr/local/portage/x11-drivers/ati-drivers-xen/files/fglrx-r3.patch
diff -Nur old/common/lib/modules/fglrx/build_mod/agpgart_be.c new/common/lib/modules/fglrx/build_mod/agpgart_be.c
--- old/common/lib/modules/fglrx/build_mod/agpgart_be.c 2007-01-09 12:26:33.000000000 +0100
+++ new/common/lib/modules/fglrx/build_mod/agpgart_be.c 2007-02-11 15:25:38.694160228 +0100
@@ -128,10 +128,17 @@
#include
#endif
#endif
-#include
#include
+
+#if defined(CONFIG_X86_XEN) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+#include
+#include
+#include
+#else
+#include
#include
#include
+#endif

#include "agp_backend.h"
#include "agp.h"
@@ -1188,7 +1195,11 @@
if (!err)
#endif
{
+#if defined(CONFIG_X86_XEN) && ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+ agp_bridge.gatt_table = ioremap_nocache(virt_to_bus(table),
+#else
agp_bridge.gatt_table = ioremap_nocache(virt_to_phys(table),
+#endif
(PAGE_SIZE * (1 << page_order)));
}
CACHE_FLUSH();
@@ -3225,8 +3236,12 @@
if (!err)
#endif
{
- page_map->remapped = ioremap_nocache(virt_to_phys(page_map->real),
- PAGE_SIZE);
+#if defined(CONFIG_X86_XEN) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+ page_map->remapped = ioremap_nocache(virt_to_bus(page_map->real),
+#else
+ page_map->remapped = ioremap_nocache(virt_to_phys(page_map->real),
+#endif
+ PAGE_SIZE);
}

if ( (page_map->remapped == NULL)
@@ -4698,7 +4713,11 @@
if (!err)
#endif
{
+#if defined(CONFIG_X86_XEN) && ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+ page_map->remapped = ioremap_nocache(virt_to_bus(page_map->real),
+#else
page_map->remapped = ioremap_nocache(virt_to_phys(page_map->real),
+#endif
PAGE_SIZE);
}

@@ -5795,7 +5814,11 @@
err = change_page_attr(virt_to_page(page_map->real), 1, PAGE_KERNEL_NOCACHE);
#endif
CACHE_FLUSH();
+#if defined(CONFIG_X86_XEN) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+ page_map->remapped = ioremap_nocache(virt_to_bus(page_map->real),
+#else
page_map->remapped = ioremap_nocache(virt_to_phys(page_map->real),
+#endif
PAGE_SIZE);
if (page_map->remapped == NULL || err) {
ClearPageReserved(virt_to_page(page_map->real));
diff -Nur old/common/lib/modules/fglrx/build_mod/drmP.h new/common/lib/modules/fglrx/build_mod/drmP.h
--- old/common/lib/modules/fglrx/build_mod/drmP.h 2007-01-09 12:26:33.000000000 +0100
+++ new/common/lib/modules/fglrx/build_mod/drmP.h 2007-02-11 15:21:56.025129785 +0100
@@ -59,7 +59,13 @@
#if defined(__alpha__) || defined(__powerpc__)
#include /* For pte_wrprotect */
#endif
+
+#if defined(CONFIG_X86_XEN) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+#include
+#else
#include
+#endif
+
#include
#include
#ifdef CONFIG_MTRR
@@ -80,7 +86,13 @@
#include
#endif
#include
+
+#if defined(CONFIG_X86_XEN) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+#include
+#else
#include
+#endif
+
#include "drm.h"

#include "drm_os_linux.h"
diff -Nur old/common/lib/modules/fglrx/build_mod/firegl_public.c new/common/lib/modules/fglrx/build_mod/firegl_public.c
--- old/common/lib/modules/fglrx/build_mod/firegl_public.c 2007-02-11 00:47:36.000000000 +0100
+++ new/common/lib/modules/fglrx/build_mod/firegl_public.c 2007-02-11 15:17:24.457559120 +0100
@@ -43,6 +43,7 @@
#if !defined(CONFIG_X86_BIGSMP)
#if !defined(CONFIG_X86_VISWS)
#if !defined(CONFIG_X86_GENERICARCH)
+#if !defined(CONFIG_X86_XEN)
#error unknown or undefined architecture configured
#endif
#endif
@@ -52,6 +53,7 @@
#endif
#endif
#endif
+#endif
#endif /* LINUX_VERSION_CODE */

/* The dirty-page-tracking patch included in NLD 9 SMP kernels defines
@@ -122,12 +124,29 @@
#include

//#include
+#if defined(CONFIG_X86_XEN) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+#include
+#else
#include
+#endif
+
#include
#include
+
+#if defined(CONFIG_X86_XEN) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+#include
+#else
#include
+#endif
+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+
+#if defined(CONFIG_X86_XEN) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+#include
+#else
#include // for flush_tlb_page
+#endif
+
#else
#include // for flush_tlb_page
#endif
@@ -167,6 +186,10 @@

#include
#include "firegl_public.h"
+
+#if defined(CONFIG_X86_XEN) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+#include
+#endif
// ============================================================
#ifndef TRUE
#define TRUE 1
diff -Nur old/common/lib/modules/fglrx/build_mod/firegl_public.h new/common/lib/modules/fglrx/build_mod/firegl_public.h
--- old/common/lib/modules/fglrx/build_mod/firegl_public.h 2007-01-09 12:26:33.000000000 +0100
+++ new/common/lib/modules/fglrx/build_mod/firegl_public.h 2007-02-11 14:26:55.808598509 +0100
@@ -36,8 +36,14 @@

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)

+#if defined(CONFIG_X86_XEN)
+#define REMAP_PAGE_RANGE_FN io_remap_pfn_range
+#define REMAP_PAGE_RANGE_STR "io_remap_pfn_range"
+#else
#define REMAP_PAGE_RANGE_FN remap_pfn_range
#define REMAP_PAGE_RANGE_STR "remap_pfn_range"
+#endif /* CONFIG_X86_XEN */
+
#define REMAP_PAGE_RANGE_OFF(offset) ((offset) >> PAGE_SHIFT)

#else /* LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,9) */
@@ -48,13 +54,24 @@

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

+#if defined(CONFIG_X86_XEN) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9))
+
#define REMAP_PAGE_RANGE(vma,offset) \
- REMAP_PAGE_RANGE_FN(FGL_VMA_API_PASS \
+ REMAP_PAGE_RANGE_FN(vma, \
(vma)->vm_start, \
REMAP_PAGE_RANGE_OFF(offset), \
(vma)->vm_end - (vma)->vm_start, \
(vma)->vm_page_prot)

+#else
+
+#define REMAP_PAGE_RANGE(vma,offset) \
+ REMAP_PAGE_RANGE_FN(FGL_VMA_API_PASS \
+ (vma)->vm_start, \
+ REMAP_PAGE_RANGE_OFF(offset), \
+ (vma)->vm_end - (vma)->vm_start, \
+ (vma)->vm_page_prot)
+#endif

/* Page table macros */