Эх сурвалжийг харах

Auto-update from upstream

Tony Luck 20 жил өмнө
parent
commit
55725495f2
100 өөрчлөгдсөн 8119 нэмэгдсэн , 5774 устгасан
  1. 40 1
      Documentation/arm/Samsung-S3C24XX/Overview.txt
  2. 57 9
      Documentation/serial/driver
  3. 16 0
      arch/arm/Kconfig
  4. 1 0
      arch/arm/Makefile
  5. 1 1
      arch/arm/configs/ixp4xx_defconfig
  6. 31 0
      arch/arm/kernel/irq.c
  7. 9 0
      arch/arm/kernel/process.c
  8. 100 9
      arch/arm/kernel/smp.c
  9. 18 4
      arch/arm/lib/Makefile
  10. 52 0
      arch/arm/lib/clear_user.S
  11. 101 0
      arch/arm/lib/copy_from_user.S
  12. 255 0
      arch/arm/lib/copy_template.S
  13. 101 0
      arch/arm/lib/copy_to_user.S
  14. 38 372
      arch/arm/lib/memcpy.S
  15. 206 0
      arch/arm/lib/memmove.S
  16. 0 38
      arch/arm/lib/uaccess.S
  17. 25 1
      arch/arm/mach-ebsa110/core.c
  18. 1 1
      arch/arm/mach-ixp2000/Makefile
  19. 16 17
      arch/arm/mach-ixp2000/core.c
  20. 30 1
      arch/arm/mach-ixp2000/enp2611.c
  21. 2 2
      arch/arm/mach-ixp2000/ixdp2x00.c
  22. 4 5
      arch/arm/mach-ixp2000/ixdp2x01.c
  23. 3 3
      arch/arm/mach-ixp2000/pci.c
  24. 474 0
      arch/arm/mach-ixp2000/uengine.c
  25. 60 3
      arch/arm/mach-pxa/lubbock.c
  26. 11 0
      arch/arm/mach-realview/Kconfig
  27. 6 0
      arch/arm/mach-realview/Makefile
  28. 4 0
      arch/arm/mach-realview/Makefile.boot
  29. 145 0
      arch/arm/mach-realview/clock.c
  30. 25 0
      arch/arm/mach-realview/clock.h
  31. 605 0
      arch/arm/mach-realview/core.c
  32. 118 0
      arch/arm/mach-realview/core.h
  33. 172 0
      arch/arm/mach-realview/realview_eb.c
  34. 66 4
      arch/arm/mach-s3c2410/mach-rx3715.c
  35. 3 3
      arch/arm/mm/Kconfig
  36. 8 1
      arch/arm/mm/init.c
  37. 16 61
      arch/i386/kernel/apic.c
  38. 0 4
      arch/i386/kernel/i8259.c
  39. 1 5
      arch/i386/kernel/io_apic.c
  40. 52 16
      arch/i386/kernel/smpboot.c
  41. 1 11
      arch/i386/kernel/time.c
  42. 1 1
      arch/i386/pci/fixup.c
  43. 4 0
      arch/ia64/Kconfig
  44. 1 1
      arch/ia64/lib/Makefile
  45. 1 2
      arch/m68knommu/defconfig
  46. 1 1
      arch/powerpc/kernel/entry_64.S
  47. 5 4
      arch/um/include/net_kern.h
  48. 0 2
      arch/x86_64/kernel/Makefile
  49. 50 16
      arch/x86_64/lib/bitops.c
  50. 4 9
      drivers/block/aoe/aoecmd.c
  51. 6 1
      drivers/block/elevator.c
  52. 14 15
      drivers/block/genhd.c
  53. 17 30
      drivers/block/ll_rw_blk.c
  54. 86 66
      drivers/char/drm/ati_pcigart.c
  55. 126 169
      drivers/char/drm/drm.h
  56. 446 440
      drivers/char/drm/drmP.h
  57. 79 71
      drivers/char/drm/drm_agpsupport.c
  58. 35 33
      drivers/char/drm/drm_auth.c
  59. 445 446
      drivers/char/drm/drm_bufs.c
  60. 155 153
      drivers/char/drm/drm_context.c
  61. 44 43
      drivers/char/drm/drm_dma.c
  62. 4 4
      drivers/char/drm/drm_drawable.c
  63. 182 179
      drivers/char/drm/drm_drv.c
  64. 152 144
      drivers/char/drm/drm_fops.c
  65. 4 3
      drivers/char/drm/drm_init.c
  66. 113 112
      drivers/char/drm/drm_ioc32.c
  67. 86 82
      drivers/char/drm/drm_ioctl.c
  68. 86 83
      drivers/char/drm/drm_irq.c
  69. 88 89
      drivers/char/drm/drm_lock.c
  70. 28 26
      drivers/char/drm/drm_memory.c
  71. 39 34
      drivers/char/drm/drm_memory.h
  72. 107 117
      drivers/char/drm/drm_memory_debug.h
  73. 7 10
      drivers/char/drm/drm_os_linux.h
  74. 5 5
      drivers/char/drm/drm_pci.c
  75. 0 1
      drivers/char/drm/drm_pciids.h
  76. 140 132
      drivers/char/drm/drm_proc.c
  77. 15 15
      drivers/char/drm/drm_sarea.h
  78. 87 96
      drivers/char/drm/drm_scatter.c
  79. 59 53
      drivers/char/drm/drm_stub.c
  80. 192 173
      drivers/char/drm/drm_vm.c
  81. 113 117
      drivers/char/drm/ffb_context.c
  82. 68 71
      drivers/char/drm/ffb_drv.c
  83. 263 170
      drivers/char/drm/ffb_drv.h
  84. 536 551
      drivers/char/drm/i810_dma.c
  85. 36 39
      drivers/char/drm/i810_drm.h
  86. 31 32
      drivers/char/drm/i810_drv.c
  87. 21 20
      drivers/char/drm/i810_drv.h
  88. 647 668
      drivers/char/drm/i830_dma.c
  89. 41 49
      drivers/char/drm/i830_drm.h
  90. 30 32
      drivers/char/drm/i830_drv.c
  91. 37 46
      drivers/char/drm/i830_drv.h
  92. 66 71
      drivers/char/drm/i830_irq.c
  93. 16 16
      drivers/char/drm/i915_dma.c
  94. 30 34
      drivers/char/drm/i915_drv.c
  95. 9 7
      drivers/char/drm/i915_drv.h
  96. 33 31
      drivers/char/drm/i915_ioc32.c
  97. 5 3
      drivers/char/drm/i915_mem.c
  98. 244 267
      drivers/char/drm/mga_dma.c
  99. 67 75
      drivers/char/drm/mga_drm.h
  100. 38 42
      drivers/char/drm/mga_drv.c

+ 40 - 1
Documentation/arm/Samsung-S3C24XX/Overview.txt

@@ -81,7 +81,8 @@ Adding New Machines
 
 
   Any large scale modifications, or new drivers should be discussed
   Any large scale modifications, or new drivers should be discussed
   on the ARM kernel mailing list (linux-arm-kernel) before being
   on the ARM kernel mailing list (linux-arm-kernel) before being
-  attempted.
+  attempted. See http://www.arm.linux.org.uk/mailinglists/ for the
+  mailing list information.
 
 
 
 
 NAND
 NAND
@@ -120,6 +121,43 @@ Clock Management
   various clock units
   various clock units
 
 
 
 
+Platform Data
+-------------
+
+  Whenever a device has platform specific data that is specified
+  on a per-machine basis, care should be taken to ensure the
+  following:
+
+    1) that default data is not left in the device to confuse the
+       driver if a machine does not set it at startup
+
+    2) the data should (if possible) be marked as __initdata,
+       to ensure that the data is thrown away if the machine is
+       not the one currently in use.
+
+       The best way of doing this is to make a function that
+       kmalloc()s an area of memory, and copies the __initdata
+       and then sets the relevant device's platform data. Making
+       the function `__init` takes care of ensuring it is discarded
+       with the rest of the initialisation code
+
+       static __init void s3c24xx_xxx_set_platdata(struct xxx_data *pd)
+       {
+           struct s3c2410_xxx_mach_info *npd;
+
+	   npd = kmalloc(sizeof(struct s3c2410_xxx_mach_info), GFP_KERNEL);
+	   if (npd) {
+	      memcpy(npd, pd, sizeof(struct s3c2410_xxx_mach_info));
+	      s3c_device_xxx.dev.platform_data = npd;
+	   } else {
+              printk(KERN_ERR "no memory for xxx platform data\n");
+	   }
+	}
+
+	Note, since the code is marked as __init, it should not be
+	exported outside arch/arm/mach-s3c2410/, or exported to
+	modules via EXPORT_SYMBOL() and related functions.
+
 Port Contributors
 Port Contributors
 -----------------
 -----------------
 
 
@@ -149,6 +187,7 @@ Document Changes
   06 Mar 2005 - BJD - Added Christer Weinigel
   06 Mar 2005 - BJD - Added Christer Weinigel
   08 Mar 2005 - BJD - Added LCVR to list of people, updated introduction
   08 Mar 2005 - BJD - Added LCVR to list of people, updated introduction
   08 Mar 2005 - BJD - Added section on adding machines
   08 Mar 2005 - BJD - Added section on adding machines
+  09 Sep 2005 - BJD - Added section on platform data
 
 
 Document Author
 Document Author
 ---------------
 ---------------

+ 57 - 9
Documentation/serial/driver

@@ -116,12 +116,15 @@ hardware.
 	line becoming inactive or the tty layer indicating we want
 	line becoming inactive or the tty layer indicating we want
 	to stop transmission due to an XOFF character.
 	to stop transmission due to an XOFF character.
 
 
+	The driver should stop transmitting characters as soon as
+	possible.
+
 	Locking: port->lock taken.
 	Locking: port->lock taken.
 	Interrupts: locally disabled.
 	Interrupts: locally disabled.
 	This call must not sleep
 	This call must not sleep
 
 
   start_tx(port)
   start_tx(port)
-	start transmitting characters.
+	Start transmitting characters.
 
 
 	Locking: port->lock taken.
 	Locking: port->lock taken.
 	Interrupts: locally disabled.
 	Interrupts: locally disabled.
@@ -281,26 +284,31 @@ hardware.
 Other functions
 Other functions
 ---------------
 ---------------
 
 
-uart_update_timeout(port,cflag,quot)
+uart_update_timeout(port,cflag,baud)
 	Update the FIFO drain timeout, port->timeout, according to the
 	Update the FIFO drain timeout, port->timeout, according to the
-	number of bits, parity, stop bits and quotient.
+	number of bits, parity, stop bits and baud rate.
 
 
 	Locking: caller is expected to take port->lock
 	Locking: caller is expected to take port->lock
 	Interrupts: n/a
 	Interrupts: n/a
 
 
-uart_get_baud_rate(port,termios)
+uart_get_baud_rate(port,termios,old,min,max)
 	Return the numeric baud rate for the specified termios, taking
 	Return the numeric baud rate for the specified termios, taking
 	account of the special 38400 baud "kludge".  The B0 baud rate
 	account of the special 38400 baud "kludge".  The B0 baud rate
 	is mapped to 9600 baud.
 	is mapped to 9600 baud.
 
 
+	If the baud rate is not within min..max, then if old is non-NULL,
+	the original baud rate will be tried.  If that exceeds the
+	min..max constraint, 9600 baud will be returned.  termios will
+	be updated to the baud rate in use.
+
+	Note: min..max must always allow 9600 baud to be selected.
+
 	Locking: caller dependent.
 	Locking: caller dependent.
 	Interrupts: n/a
 	Interrupts: n/a
 
 
-uart_get_divisor(port,termios,oldtermios)
-	Return the divsor (baud_base / baud) for the selected baud rate
-	specified by termios.  If the baud rate is out of range, try
-	the original baud rate specified by oldtermios (if non-NULL).
-	If that fails, try 9600 baud.
+uart_get_divisor(port,baud)
+	Return the divsor (baud_base / baud) for the specified baud
+	rate, appropriately rounded.
 
 
 	If 38400 baud and custom divisor is selected, return the
 	If 38400 baud and custom divisor is selected, return the
 	custom divisor instead.
 	custom divisor instead.
@@ -308,6 +316,46 @@ uart_get_divisor(port,termios,oldtermios)
 	Locking: caller dependent.
 	Locking: caller dependent.
 	Interrupts: n/a
 	Interrupts: n/a
 
 
+uart_match_port(port1,port2)
+	This utility function can be used to determine whether two
+	uart_port structures describe the same port.
+
+	Locking: n/a
+	Interrupts: n/a
+
+uart_write_wakeup(port)
+	A driver is expected to call this function when the number of
+	characters in the transmit buffer have dropped below a threshold.
+
+	Locking: port->lock should be held.
+	Interrupts: n/a
+
+uart_register_driver(drv)
+	Register a uart driver with the core driver.  We in turn register
+	with the tty layer, and initialise the core driver per-port state.
+
+	drv->port should be NULL, and the per-port structures should be
+	registered using uart_add_one_port after this call has succeeded.
+
+	Locking: none
+	Interrupts: enabled
+
+uart_unregister_driver()
+	Remove all references to a driver from the core driver.  The low
+	level driver must have removed all its ports via the
+	uart_remove_one_port() if it registered them with uart_add_one_port().
+
+	Locking: none
+	Interrupts: enabled
+
+uart_suspend_port()
+
+uart_resume_port()
+
+uart_add_one_port()
+
+uart_remove_one_port()
+
 Other notes
 Other notes
 -----------
 -----------
 
 

+ 16 - 0
arch/arm/Kconfig

@@ -194,6 +194,13 @@ config ARCH_VERSATILE
 	help
 	help
 	  This enables support for ARM Ltd Versatile board.
 	  This enables support for ARM Ltd Versatile board.
 
 
+config ARCH_REALVIEW
+	bool "RealView"
+	select ARM_AMBA
+	select ICST307
+	help
+	  This enables support for ARM Ltd RealView boards.
+
 config ARCH_IMX
 config ARCH_IMX
 	bool "IMX"
 	bool "IMX"
 
 
@@ -244,6 +251,8 @@ source "arch/arm/mach-versatile/Kconfig"
 
 
 source "arch/arm/mach-aaec2000/Kconfig"
 source "arch/arm/mach-aaec2000/Kconfig"
 
 
+source "arch/arm/mach-realview/Kconfig"
+
 # Definitions to make life easier
 # Definitions to make life easier
 config ARCH_ACORN
 config ARCH_ACORN
 	bool
 	bool
@@ -340,6 +349,13 @@ config NR_CPUS
 	depends on SMP
 	depends on SMP
 	default "4"
 	default "4"
 
 
+config HOTPLUG_CPU
+	bool "Support for hot-pluggable CPUs (EXPERIMENTAL)"
+	depends on SMP && HOTPLUG && EXPERIMENTAL
+	help
+	  Say Y here to experiment with turning CPUs off and on.  CPUs
+	  can be controlled through /sys/devices/system/cpu.
+
 config PREEMPT
 config PREEMPT
 	bool "Preemptible Kernel (EXPERIMENTAL)"
 	bool "Preemptible Kernel (EXPERIMENTAL)"
 	depends on EXPERIMENTAL
 	depends on EXPERIMENTAL

+ 1 - 0
arch/arm/Makefile

@@ -99,6 +99,7 @@ textaddr-$(CONFIG_ARCH_FORTUNET)   := 0xc0008000
  machine-$(CONFIG_ARCH_IMX)	   := imx
  machine-$(CONFIG_ARCH_IMX)	   := imx
  machine-$(CONFIG_ARCH_H720X)	   := h720x
  machine-$(CONFIG_ARCH_H720X)	   := h720x
  machine-$(CONFIG_ARCH_AAEC2000)   := aaec2000
  machine-$(CONFIG_ARCH_AAEC2000)   := aaec2000
+ machine-$(CONFIG_ARCH_REALVIEW)   := realview
 
 
 ifeq ($(CONFIG_ARCH_EBSA110),y)
 ifeq ($(CONFIG_ARCH_EBSA110),y)
 # This is what happens if you forget the IOCS16 line.
 # This is what happens if you forget the IOCS16 line.

+ 1 - 1
arch/arm/configs/ixp4xx_defconfig

@@ -104,7 +104,7 @@ CONFIG_ARCH_IXCDP1100=y
 CONFIG_ARCH_PRPMC1100=y
 CONFIG_ARCH_PRPMC1100=y
 CONFIG_ARCH_IXDP4XX=y
 CONFIG_ARCH_IXDP4XX=y
 CONFIG_CPU_IXP46X=y
 CONFIG_CPU_IXP46X=y
-CONFIG_MACH_GTWX5715=y
+# CONFIG_MACH_GTWX5715 is not set
 
 
 #
 #
 # IXP4xx Options
 # IXP4xx Options

+ 31 - 0
arch/arm/kernel/irq.c

@@ -1050,3 +1050,34 @@ static int __init noirqdebug_setup(char *str)
 }
 }
 
 
 __setup("noirqdebug", noirqdebug_setup);
 __setup("noirqdebug", noirqdebug_setup);
+
+#ifdef CONFIG_HOTPLUG_CPU
+/*
+ * The CPU has been marked offline.  Migrate IRQs off this CPU.  If
+ * the affinity settings do not allow other CPUs, force them onto any
+ * available CPU.
+ */
+void migrate_irqs(void)
+{
+	unsigned int i, cpu = smp_processor_id();
+
+	for (i = 0; i < NR_IRQS; i++) {
+		struct irqdesc *desc = irq_desc + i;
+
+		if (desc->cpu == cpu) {
+			unsigned int newcpu = any_online_cpu(desc->affinity);
+
+			if (newcpu == NR_CPUS) {
+				if (printk_ratelimit())
+					printk(KERN_INFO "IRQ%u no longer affine to CPU%u\n",
+					       i, cpu);
+
+				cpus_setall(desc->affinity);
+				newcpu = any_online_cpu(desc->affinity);
+			}
+
+			route_irq(desc, i, newcpu);
+		}
+	}
+}
+#endif /* CONFIG_HOTPLUG_CPU */

+ 9 - 0
arch/arm/kernel/process.c

@@ -26,6 +26,7 @@
 #include <linux/interrupt.h>
 #include <linux/interrupt.h>
 #include <linux/kallsyms.h>
 #include <linux/kallsyms.h>
 #include <linux/init.h>
 #include <linux/init.h>
+#include <linux/cpu.h>
 
 
 #include <asm/system.h>
 #include <asm/system.h>
 #include <asm/io.h>
 #include <asm/io.h>
@@ -105,6 +106,14 @@ void cpu_idle(void)
 	/* endless idle loop with no priority at all */
 	/* endless idle loop with no priority at all */
 	while (1) {
 	while (1) {
 		void (*idle)(void) = pm_idle;
 		void (*idle)(void) = pm_idle;
+
+#ifdef CONFIG_HOTPLUG_CPU
+		if (cpu_is_offline(smp_processor_id())) {
+			leds_event(led_idle_start);
+			cpu_die();
+		}
+#endif
+
 		if (!idle)
 		if (!idle)
 			idle = default_idle;
 			idle = default_idle;
 		preempt_disable();
 		preempt_disable();

+ 100 - 9
arch/arm/kernel/smp.c

@@ -80,19 +80,23 @@ static DEFINE_SPINLOCK(smp_call_function_lock);
 
 
 int __cpuinit __cpu_up(unsigned int cpu)
 int __cpuinit __cpu_up(unsigned int cpu)
 {
 {
-	struct task_struct *idle;
+	struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu);
+	struct task_struct *idle = ci->idle;
 	pgd_t *pgd;
 	pgd_t *pgd;
 	pmd_t *pmd;
 	pmd_t *pmd;
 	int ret;
 	int ret;
 
 
 	/*
 	/*
-	 * Spawn a new process manually.  Grab a pointer to
-	 * its task struct so we can mess with it
+	 * Spawn a new process manually, if not already done.
+	 * Grab a pointer to its task struct so we can mess with it
 	 */
 	 */
-	idle = fork_idle(cpu);
-	if (IS_ERR(idle)) {
-		printk(KERN_ERR "CPU%u: fork() failed\n", cpu);
-		return PTR_ERR(idle);
+	if (!idle) {
+		idle = fork_idle(cpu);
+		if (IS_ERR(idle)) {
+			printk(KERN_ERR "CPU%u: fork() failed\n", cpu);
+			return PTR_ERR(idle);
+		}
+		ci->idle = idle;
 	}
 	}
 
 
 	/*
 	/*
@@ -155,6 +159,91 @@ int __cpuinit __cpu_up(unsigned int cpu)
 	return ret;
 	return ret;
 }
 }
 
 
+#ifdef CONFIG_HOTPLUG_CPU
+/*
+ * __cpu_disable runs on the processor to be shutdown.
+ */
+int __cpuexit __cpu_disable(void)
+{
+	unsigned int cpu = smp_processor_id();
+	struct task_struct *p;
+	int ret;
+
+	ret = mach_cpu_disable(cpu);
+	if (ret)
+		return ret;
+
+	/*
+	 * Take this CPU offline.  Once we clear this, we can't return,
+	 * and we must not schedule until we're ready to give up the cpu.
+	 */
+	cpu_clear(cpu, cpu_online_map);
+
+	/*
+	 * OK - migrate IRQs away from this CPU
+	 */
+	migrate_irqs();
+
+	/*
+	 * Flush user cache and TLB mappings, and then remove this CPU
+	 * from the vm mask set of all processes.
+	 */
+	flush_cache_all();
+	local_flush_tlb_all();
+
+	read_lock(&tasklist_lock);
+	for_each_process(p) {
+		if (p->mm)
+			cpu_clear(cpu, p->mm->cpu_vm_mask);
+	}
+	read_unlock(&tasklist_lock);
+
+	return 0;
+}
+
+/*
+ * called on the thread which is asking for a CPU to be shutdown -
+ * waits until shutdown has completed, or it is timed out.
+ */
+void __cpuexit __cpu_die(unsigned int cpu)
+{
+	if (!platform_cpu_kill(cpu))
+		printk("CPU%u: unable to kill\n", cpu);
+}
+
+/*
+ * Called from the idle thread for the CPU which has been shutdown.
+ *
+ * Note that we disable IRQs here, but do not re-enable them
+ * before returning to the caller. This is also the behaviour
+ * of the other hotplug-cpu capable cores, so presumably coming
+ * out of idle fixes this.
+ */
+void __cpuexit cpu_die(void)
+{
+	unsigned int cpu = smp_processor_id();
+
+	local_irq_disable();
+	idle_task_exit();
+
+	/*
+	 * actual CPU shutdown procedure is at least platform (if not
+	 * CPU) specific
+	 */
+	platform_cpu_die(cpu);
+
+	/*
+	 * Do not return to the idle loop - jump back to the secondary
+	 * cpu initialisation.  There's some initialisation which needs
+	 * to be repeated to undo the effects of taking the CPU offline.
+	 */
+	__asm__("mov	sp, %0\n"
+	"	b	secondary_start_kernel"
+		:
+		: "r" ((void *)current->thread_info + THREAD_SIZE - 8));
+}
+#endif /* CONFIG_HOTPLUG_CPU */
+
 /*
 /*
  * This is the secondary CPU boot entry.  We're using this CPUs
  * This is the secondary CPU boot entry.  We're using this CPUs
  * idle thread stack, but a set of temporary page tables.
  * idle thread stack, but a set of temporary page tables.
@@ -236,6 +325,8 @@ void __init smp_prepare_boot_cpu(void)
 {
 {
 	unsigned int cpu = smp_processor_id();
 	unsigned int cpu = smp_processor_id();
 
 
+	per_cpu(cpu_data, cpu).idle = current;
+
 	cpu_set(cpu, cpu_possible_map);
 	cpu_set(cpu, cpu_possible_map);
 	cpu_set(cpu, cpu_present_map);
 	cpu_set(cpu, cpu_present_map);
 	cpu_set(cpu, cpu_online_map);
 	cpu_set(cpu, cpu_online_map);
@@ -309,8 +400,8 @@ int smp_call_function_on_cpu(void (*func)(void *info), void *info, int retry,
 		printk(KERN_CRIT
 		printk(KERN_CRIT
 		       "CPU%u: smp_call_function timeout for %p(%p)\n"
 		       "CPU%u: smp_call_function timeout for %p(%p)\n"
 		       "      callmap %lx pending %lx, %swait\n",
 		       "      callmap %lx pending %lx, %swait\n",
-		       smp_processor_id(), func, info, callmap, data.pending,
-		       wait ? "" : "no ");
+		       smp_processor_id(), func, info, *cpus_addr(callmap),
+		       *cpus_addr(data.pending), wait ? "" : "no ");
 
 
 		/*
 		/*
 		 * TRACE
 		 * TRACE

+ 18 - 4
arch/arm/lib/Makefile

@@ -7,13 +7,27 @@
 lib-y		:= backtrace.o changebit.o csumipv6.o csumpartial.o   \
 lib-y		:= backtrace.o changebit.o csumipv6.o csumpartial.o   \
 		   csumpartialcopy.o csumpartialcopyuser.o clearbit.o \
 		   csumpartialcopy.o csumpartialcopyuser.o clearbit.o \
 		   copy_page.o delay.o findbit.o memchr.o memcpy.o    \
 		   copy_page.o delay.o findbit.o memchr.o memcpy.o    \
-		   memset.o memzero.o setbit.o strncpy_from_user.o    \
-		   strnlen_user.o strchr.o strrchr.o testchangebit.o  \
-		   testclearbit.o testsetbit.o uaccess.o getuser.o    \
-		   putuser.o ashldi3.o ashrdi3.o lshrdi3.o muldi3.o   \
+		   memmove.o memset.o memzero.o setbit.o              \
+		   strncpy_from_user.o strnlen_user.o                 \
+		   strchr.o strrchr.o                                 \
+		   testchangebit.o testclearbit.o testsetbit.o        \
+		   getuser.o putuser.o clear_user.o                   \
+		   ashldi3.o ashrdi3.o lshrdi3.o muldi3.o             \
 		   ucmpdi2.o lib1funcs.o div64.o sha1.o               \
 		   ucmpdi2.o lib1funcs.o div64.o sha1.o               \
 		   io-readsb.o io-writesb.o io-readsl.o io-writesl.o
 		   io-readsb.o io-writesb.o io-readsl.o io-writesl.o
 
 
+# the code in uaccess.S is not preemption safe and
+# probably faster on ARMv3 only
+ifeq ($CONFIG_PREEMPT,y)
+  lib-y	+= copy_from_user.o copy_to_user.o
+else
+ifneq ($(CONFIG_CPU_32v3),y)
+  lib-y	+= copy_from_user.o copy_to_user.o
+else
+  lib-y	+= uaccess.o
+endif
+endif
+
 ifeq ($(CONFIG_CPU_32v3),y)
 ifeq ($(CONFIG_CPU_32v3),y)
   lib-y	+= io-readsw-armv3.o io-writesw-armv3.o
   lib-y	+= io-readsw-armv3.o io-writesw-armv3.o
 else
 else

+ 52 - 0
arch/arm/lib/clear_user.S

@@ -0,0 +1,52 @@
+/*
+ *  linux/arch/arm/lib/clear_user.S
+ *
+ *  Copyright (C) 1995, 1996,1997,1998 Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+		.text
+
+/* Prototype: int __arch_clear_user(void *addr, size_t sz)
+ * Purpose  : clear some user memory
+ * Params   : addr - user memory address to clear
+ *          : sz   - number of bytes to clear
+ * Returns  : number of bytes NOT cleared
+ */
+ENTRY(__arch_clear_user)
+		stmfd	sp!, {r1, lr}
+		mov	r2, #0
+		cmp	r1, #4
+		blt	2f
+		ands	ip, r0, #3
+		beq	1f
+		cmp	ip, #2
+USER(		strbt	r2, [r0], #1)
+USER(		strlebt	r2, [r0], #1)
+USER(		strltbt	r2, [r0], #1)
+		rsb	ip, ip, #4
+		sub	r1, r1, ip		@  7  6  5  4  3  2  1
+1:		subs	r1, r1, #8		@ -1 -2 -3 -4 -5 -6 -7
+USER(		strplt	r2, [r0], #4)
+USER(		strplt	r2, [r0], #4)
+		bpl	1b
+		adds	r1, r1, #4		@  3  2  1  0 -1 -2 -3
+USER(		strplt	r2, [r0], #4)
+2:		tst	r1, #2			@ 1x 1x 0x 0x 1x 1x 0x
+USER(		strnebt	r2, [r0], #1)
+USER(		strnebt	r2, [r0], #1)
+		tst	r1, #1			@ x1 x0 x1 x0 x1 x0 x1
+USER(		strnebt	r2, [r0], #1)
+		mov	r0, #0
+		LOADREGS(fd,sp!, {r1, pc})
+
+		.section .fixup,"ax"
+		.align	0
+9001:		LOADREGS(fd,sp!, {r0, pc})
+		.previous
+

+ 101 - 0
arch/arm/lib/copy_from_user.S

@@ -0,0 +1,101 @@
+/*
+ *  linux/arch/arm/lib/copy_from_user.S
+ *
+ *  Author:	Nicolas Pitre
+ *  Created:	Sep 29, 2005
+ *  Copyright:	MontaVista Software, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+/*
+ * Prototype:
+ *
+ *	size_t __arch_copy_from_user(void *to, const void *from, size_t n)
+ *
+ * Purpose:
+ *
+ *	copy a block to kernel memory from user memory
+ *
+ * Params:
+ *
+ *	to = kernel memory
+ *	from = user memory
+ *	n = number of bytes to copy
+ *
+ * Return value:
+ *
+ *	Number of bytes NOT copied.
+ */
+
+	.macro ldr1w ptr reg abort
+100:	ldrt \reg, [\ptr], #4
+	.section __ex_table, "a"
+	.long 100b, \abort
+	.previous
+	.endm
+
+	.macro ldr4w ptr reg1 reg2 reg3 reg4 abort
+	ldr1w \ptr, \reg1, \abort
+	ldr1w \ptr, \reg2, \abort
+	ldr1w \ptr, \reg3, \abort
+	ldr1w \ptr, \reg4, \abort
+	.endm
+
+	.macro ldr8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
+	ldr4w \ptr, \reg1, \reg2, \reg3, \reg4, \abort
+	ldr4w \ptr, \reg5, \reg6, \reg7, \reg8, \abort
+	.endm
+
+	.macro ldr1b ptr reg cond=al abort
+100:	ldr\cond\()bt \reg, [\ptr], #1
+	.section __ex_table, "a"
+	.long 100b, \abort
+	.previous
+	.endm
+
+	.macro str1w ptr reg abort
+	str \reg, [\ptr], #4
+	.endm
+
+	.macro str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
+	stmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
+	.endm
+
+	.macro str1b ptr reg cond=al abort
+	str\cond\()b \reg, [\ptr], #1
+	.endm
+
+	.macro enter reg1 reg2
+	mov	r3, #0
+	stmdb	sp!, {r0, r2, r3, \reg1, \reg2}
+	.endm
+
+	.macro exit reg1 reg2
+	add	sp, sp, #8
+	ldmfd	sp!, {r0, \reg1, \reg2}
+	.endm
+
+	.text
+
+ENTRY(__arch_copy_from_user)
+
+#include "copy_template.S"
+
+	.section .fixup,"ax"
+	.align 0
+	copy_abort_preamble
+	ldmfd	sp!, {r1, r2}
+	sub	r3, r0, r1
+	rsb	r1, r3, r2
+	str	r1, [sp]
+	bl	__memzero
+	ldr	r0, [sp], #4
+	copy_abort_end
+	.previous
+

+ 255 - 0
arch/arm/lib/copy_template.S

@@ -0,0 +1,255 @@
+/*
+ *  linux/arch/arm/lib/copy_template.s
+ *
+ *  Code template for optimized memory copy functions
+ *
+ *  Author:	Nicolas Pitre
+ *  Created:	Sep 28, 2005
+ *  Copyright:	MontaVista Software, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+/*
+ * This can be used to enable code to cacheline align the source pointer.
+ * Experiments on tested architectures (StrongARM and XScale) didn't show
+ * this a worthwhile thing to do.  That might be different in the future.
+ */
+//#define CALGN(code...)	code
+#define CALGN(code...)
+
+/*
+ * Theory of operation
+ * -------------------
+ *
+ * This file provides the core code for a forward memory copy used in
+ * the implementation of memcopy(), copy_to_user() and copy_from_user().
+ *
+ * The including file must define the following accessor macros
+ * according to the need of the given function:
+ *
+ * ldr1w ptr reg abort
+ *
+ *	This loads one word from 'ptr', stores it in 'reg' and increments
+ *	'ptr' to the next word. The 'abort' argument is used for fixup tables.
+ *
+ * ldr4w ptr reg1 reg2 reg3 reg4 abort
+ * ldr8w ptr, reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
+ *
+ *	This loads four or eight words starting from 'ptr', stores them
+ *	in provided registers and increments 'ptr' past those words.
+ *	The'abort' argument is used for fixup tables.
+ *
+ * ldr1b ptr reg cond abort
+ *
+ *	Similar to ldr1w, but it loads a byte and increments 'ptr' one byte.
+ *	It also must apply the condition code if provided, otherwise the
+ *	"al" condition is assumed by default.
+ *
+ * str1w ptr reg abort
+ * str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
+ * str1b ptr reg cond abort
+ *
+ *	Same as their ldr* counterparts, but data is stored to 'ptr' location
+ *	rather than being loaded.
+ *
+ * enter reg1 reg2
+ *
+ *	Preserve the provided registers on the stack plus any additional
+ *	data as needed by the implementation including this code. Called
+ *	upon code entry.
+ *
+ * exit reg1 reg2
+ *
+ *	Restore registers with the values previously saved with the
+ *	'preserv' macro. Called upon code termination.
+ */
+
+
+		enter	r4, lr
+
+		subs	r2, r2, #4
+		blt	8f
+		ands	ip, r0, #3
+	PLD(	pld	[r1, #0]		)
+		bne	9f
+		ands	ip, r1, #3
+		bne	10f
+
+1:		subs	r2, r2, #(28)
+		stmfd	sp!, {r5 - r8}
+		blt	5f
+
+	CALGN(	ands	ip, r1, #31		)
+	CALGN(	rsb	r3, ip, #32		)
+	CALGN(	sbcnes	r4, r3, r2		)  @ C is always set here
+	CALGN(	bcs	2f			)
+	CALGN(	adr	r4, 6f			)
+	CALGN(	subs	r2, r2, r3		)  @ C gets set
+	CALGN(	add	pc, r4, ip		)
+
+	PLD(	pld	[r1, #0]		)
+2:	PLD(	subs	r2, r2, #96		)
+	PLD(	pld	[r1, #28]		)
+	PLD(	blt	4f			)
+	PLD(	pld	[r1, #60]		)
+	PLD(	pld	[r1, #92]		)
+
+3:	PLD(	pld	[r1, #124]		)
+4:		ldr8w	r1, r3, r4, r5, r6, r7, r8, ip, lr, abort=20f
+		subs	r2, r2, #32
+		str8w	r0, r3, r4, r5, r6, r7, r8, ip, lr, abort=20f
+		bge	3b
+	PLD(	cmn	r2, #96			)
+	PLD(	bge	4b			)
+
+5:		ands	ip, r2, #28
+		rsb	ip, ip, #32
+		addne	pc, pc, ip		@ C is always clear here
+		b	7f
+6:		nop
+		ldr1w	r1, r3, abort=20f
+		ldr1w	r1, r4, abort=20f
+		ldr1w	r1, r5, abort=20f
+		ldr1w	r1, r6, abort=20f
+		ldr1w	r1, r7, abort=20f
+		ldr1w	r1, r8, abort=20f
+		ldr1w	r1, lr, abort=20f
+
+		add	pc, pc, ip
+		nop
+		nop
+		str1w	r0, r3, abort=20f
+		str1w	r0, r4, abort=20f
+		str1w	r0, r5, abort=20f
+		str1w	r0, r6, abort=20f
+		str1w	r0, r7, abort=20f
+		str1w	r0, r8, abort=20f
+		str1w	r0, lr, abort=20f
+
+	CALGN(	bcs	2b			)
+
+7:		ldmfd	sp!, {r5 - r8}
+
+8:		movs	r2, r2, lsl #31
+		ldr1b	r1, r3, ne, abort=21f
+		ldr1b	r1, r4, cs, abort=21f
+		ldr1b	r1, ip, cs, abort=21f
+		str1b	r0, r3, ne, abort=21f
+		str1b	r0, r4, cs, abort=21f
+		str1b	r0, ip, cs, abort=21f
+
+		exit	r4, pc
+
+9:		rsb	ip, ip, #4
+		cmp	ip, #2
+		ldr1b	r1, r3, gt, abort=21f
+		ldr1b	r1, r4, ge, abort=21f
+		ldr1b	r1, lr, abort=21f
+		str1b	r0, r3, gt, abort=21f
+		str1b	r0, r4, ge, abort=21f
+		subs	r2, r2, ip
+		str1b	r0, lr, abort=21f
+		blt	8b
+		ands	ip, r1, #3
+		beq	1b
+
+10:		bic	r1, r1, #3
+		cmp	ip, #2
+		ldr1w	r1, lr, abort=21f
+		beq	17f
+		bgt	18f
+
+
+		.macro	forward_copy_shift pull push
+
+		subs	r2, r2, #28
+		blt	14f
+
+	CALGN(	ands	ip, r1, #31		)
+	CALGN(	rsb	ip, ip, #32		)
+	CALGN(	sbcnes	r4, ip, r2		)  @ C is always set here
+	CALGN(	subcc	r2, r2, ip		)
+	CALGN(	bcc	15f			)
+
+11:		stmfd	sp!, {r5 - r9}
+
+	PLD(	pld	[r1, #0]		)
+	PLD(	subs	r2, r2, #96		)
+	PLD(	pld	[r1, #28]		)
+	PLD(	blt	13f			)
+	PLD(	pld	[r1, #60]		)
+	PLD(	pld	[r1, #92]		)
+
+12:	PLD(	pld	[r1, #124]		)
+13:		ldr4w	r1, r4, r5, r6, r7, abort=19f
+		mov	r3, lr, pull #\pull
+		subs	r2, r2, #32
+		ldr4w	r1, r8, r9, ip, lr, abort=19f
+		orr	r3, r3, r4, push #\push
+		mov	r4, r4, pull #\pull
+		orr	r4, r4, r5, push #\push
+		mov	r5, r5, pull #\pull
+		orr	r5, r5, r6, push #\push
+		mov	r6, r6, pull #\pull
+		orr	r6, r6, r7, push #\push
+		mov	r7, r7, pull #\pull
+		orr	r7, r7, r8, push #\push
+		mov	r8, r8, pull #\pull
+		orr	r8, r8, r9, push #\push
+		mov	r9, r9, pull #\pull
+		orr	r9, r9, ip, push #\push
+		mov	ip, ip, pull #\pull
+		orr	ip, ip, lr, push #\push
+		str8w	r0, r3, r4, r5, r6, r7, r8, r9, ip, , abort=19f
+		bge	12b
+	PLD(	cmn	r2, #96			)
+	PLD(	bge	13b			)
+
+		ldmfd	sp!, {r5 - r9}
+
+14:		ands	ip, r2, #28
+		beq	16f
+
+15:		mov	r3, lr, pull #\pull
+		ldr1w	r1, lr, abort=21f
+		subs	ip, ip, #4
+		orr	r3, r3, lr, push #\push
+		str1w	r0, r3, abort=21f
+		bgt	15b
+	CALGN(	cmp	r2, #0			)
+	CALGN(	bge	11b			)
+
+16:		sub	r1, r1, #(\push / 8)
+		b	8b
+
+		.endm
+
+
+		forward_copy_shift	pull=8	push=24
+
+17:		forward_copy_shift	pull=16	push=16
+
+18:		forward_copy_shift	pull=24	push=8
+
+
+/*
+ * Abort preanble and completion macros.
+ * If a fixup handler is required then those macros must surround it.
+ * It is assumed that the fixup code will handle the private part of
+ * the exit macro.
+ */
+
+	.macro	copy_abort_preamble
+19:	ldmfd	sp!, {r5 - r9}
+	b	21f
+20:	ldmfd	sp!, {r5 - r8}
+21:
+	.endm
+
+	.macro	copy_abort_end
+	ldmfd	sp!, {r4, pc}
+	.endm
+

+ 101 - 0
arch/arm/lib/copy_to_user.S

@@ -0,0 +1,101 @@
+/*
+ *  linux/arch/arm/lib/copy_to_user.S
+ *
+ *  Author:	Nicolas Pitre
+ *  Created:	Sep 29, 2005
+ *  Copyright:	MontaVista Software, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+/*
+ * Prototype:
+ *
+ *	size_t __arch_copy_to_user(void *to, const void *from, size_t n)
+ *
+ * Purpose:
+ *
+ *	copy a block to user memory from kernel memory
+ *
+ * Params:
+ *
+ *	to = user memory
+ *	from = kernel memory
+ *	n = number of bytes to copy
+ *
+ * Return value:
+ *
+ *	Number of bytes NOT copied.
+ */
+
+	.macro ldr1w ptr reg abort
+	ldr \reg, [\ptr], #4
+	.endm
+
+	.macro ldr4w ptr reg1 reg2 reg3 reg4 abort
+	ldmia \ptr!, {\reg1, \reg2, \reg3, \reg4}
+	.endm
+
+	.macro ldr8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
+	ldmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
+	.endm
+
+	.macro ldr1b ptr reg cond=al abort
+	ldr\cond\()b \reg, [\ptr], #1
+	.endm
+
+	.macro str1w ptr reg abort
+100:	strt \reg, [\ptr], #4
+	.section __ex_table, "a"
+	.long 100b, \abort
+	.previous
+	.endm
+
+	.macro str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
+	str1w \ptr, \reg1, \abort
+	str1w \ptr, \reg2, \abort
+	str1w \ptr, \reg3, \abort
+	str1w \ptr, \reg4, \abort
+	str1w \ptr, \reg5, \abort
+	str1w \ptr, \reg6, \abort
+	str1w \ptr, \reg7, \abort
+	str1w \ptr, \reg8, \abort
+	.endm
+
+	.macro str1b ptr reg cond=al abort
+100:	str\cond\()bt \reg, [\ptr], #1
+	.section __ex_table, "a"
+	.long 100b, \abort
+	.previous
+	.endm
+
+	.macro enter reg1 reg2
+	mov	r3, #0
+	stmdb	sp!, {r0, r2, r3, \reg1, \reg2}
+	.endm
+
+	.macro exit reg1 reg2
+	add	sp, sp, #8
+	ldmfd	sp!, {r0, \reg1, \reg2}
+	.endm
+
+	.text
+
+ENTRY(__arch_copy_to_user)
+
+#include "copy_template.S"
+
+	.section .fixup,"ax"
+	.align 0
+	copy_abort_preamble
+	ldmfd	sp!, {r1, r2, r3}
+	sub	r0, r0, r1
+	rsb	r0, r0, r2
+	copy_abort_end
+	.previous
+

+ 38 - 372
arch/arm/lib/memcpy.S

@@ -1,393 +1,59 @@
 /*
 /*
  *  linux/arch/arm/lib/memcpy.S
  *  linux/arch/arm/lib/memcpy.S
  *
  *
- *  Copyright (C) 1995-1999 Russell King
+ *  Author:	Nicolas Pitre
+ *  Created:	Sep 28, 2005
+ *  Copyright:	MontaVista Software, Inc.
  *
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- *  ASM optimised string functions
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
  */
  */
+
 #include <linux/linkage.h>
 #include <linux/linkage.h>
 #include <asm/assembler.h>
 #include <asm/assembler.h>
 
 
-		.text
-
-#define ENTER	\
-		mov	ip,sp	;\
-		stmfd	sp!,{r0,r4-r9,fp,ip,lr,pc}	;\
-		sub	fp,ip,#4
-
-#define EXIT	\
-		LOADREGS(ea, fp, {r0, r4 - r9, fp, sp, pc})
-
-#define EXITEQ	\
-		LOADREGS(eqea, fp, {r0, r4 - r9, fp, sp, pc})
-
-/*
- * Prototype: void memcpy(void *to,const void *from,unsigned long n);
- */
-ENTRY(memcpy)
-ENTRY(memmove)
-		ENTER
-		cmp	r1, r0
-		bcc	23f
-		subs	r2, r2, #4
-		blt	6f
-	PLD(	pld	[r1, #0]		)
-		ands	ip, r0, #3
-		bne	7f
-		ands	ip, r1, #3
-		bne	8f
+	.macro ldr1w ptr reg abort
+	ldr \reg, [\ptr], #4
+	.endm
 
 
-1:		subs	r2, r2, #8
-		blt	5f
-		subs	r2, r2, #20
-		blt	4f
-	PLD(	pld	[r1, #28]		)
-	PLD(	subs	r2, r2, #64		)
-	PLD(	blt	3f			)
-2:	PLD(	pld	[r1, #60]		)
-	PLD(	pld	[r1, #92]		)
-		ldmia	r1!, {r3 - r9, ip}
-		subs	r2, r2, #32
-		stmgeia	r0!, {r3 - r9, ip}
-		ldmgeia	r1!, {r3 - r9, ip}
-		subges	r2, r2, #32
-		stmia	r0!, {r3 - r9, ip}
-		bge	2b
-3:	PLD(	ldmia	r1!, {r3 - r9, ip}	)
-	PLD(	adds	r2, r2, #32		)
-	PLD(	stmgeia	r0!, {r3 - r9, ip}	)
-	PLD(	ldmgeia	r1!, {r3 - r9, ip}	)
-	PLD(	subges	r2, r2, #32		)
-	PLD(	stmia	r0!, {r3 - r9, ip}	)
-4:		cmn	r2, #16
-		ldmgeia	r1!, {r3 - r6}
-		subge	r2, r2, #16
-		stmgeia	r0!, {r3 - r6}
-		adds	r2, r2, #20
-		ldmgeia	r1!, {r3 - r5}
-		subge	r2, r2, #12
-		stmgeia	r0!, {r3 - r5}
-5:		adds	r2, r2, #8
-		blt	6f
-		subs	r2, r2, #4
-		ldrlt	r3, [r1], #4
-		ldmgeia	r1!, {r4, r5}
-		subge	r2, r2, #4
-		strlt	r3, [r0], #4
-		stmgeia	r0!, {r4, r5}
+	.macro ldr4w ptr reg1 reg2 reg3 reg4 abort
+	ldmia \ptr!, {\reg1, \reg2, \reg3, \reg4}
+	.endm
 
 
-6:		adds	r2, r2, #4
-		EXITEQ
-		cmp	r2, #2
-		ldrb	r3, [r1], #1
-		ldrgeb	r4, [r1], #1
-		ldrgtb	r5, [r1], #1
-		strb	r3, [r0], #1
-		strgeb	r4, [r0], #1
-		strgtb	r5, [r0], #1
-		EXIT
+	.macro ldr8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
+	ldmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
+	.endm
 
 
-7:		rsb	ip, ip, #4
-		cmp	ip, #2
-		ldrb	r3, [r1], #1
-		ldrgeb	r4, [r1], #1
-		ldrgtb	r5, [r1], #1
-		strb	r3, [r0], #1
-		strgeb	r4, [r0], #1
-		strgtb	r5, [r0], #1
-		subs	r2, r2, ip
-		blt	6b
-		ands	ip, r1, #3
-		beq	1b
+	.macro ldr1b ptr reg cond=al abort
+	ldr\cond\()b \reg, [\ptr], #1
+	.endm
 
 
-8:		bic	r1, r1, #3
-		ldr	r7, [r1], #4
-		cmp	ip, #2
-		bgt	18f
-		beq	13f
-		cmp	r2, #12
-		blt	11f
-	PLD(	pld	[r1, #12]		)
-		sub	r2, r2, #12
-	PLD(	subs	r2, r2, #32		)
-	PLD(	blt	10f			)
-	PLD(	pld	[r1, #28]		)
-9:	PLD(	pld	[r1, #44]		)
-10:		mov	r3, r7, pull #8
-		ldmia	r1!, {r4 - r7}
-		subs	r2, r2, #16
-		orr	r3, r3, r4, push #24
-		mov	r4, r4, pull #8
-		orr	r4, r4, r5, push #24
-		mov	r5, r5, pull #8
-		orr	r5, r5, r6, push #24
-		mov	r6, r6, pull #8
-		orr	r6, r6, r7, push #24
-		stmia	r0!, {r3 - r6}
-		bge	9b
-	PLD(	cmn	r2, #32			)
-	PLD(	bge	10b			)
-	PLD(	add	r2, r2, #32		)
-		adds	r2, r2, #12
-		blt	12f
-11:		mov	r3, r7, pull #8
-		ldr	r7, [r1], #4
-		subs	r2, r2, #4
-		orr	r3, r3, r7, push #24
-		str	r3, [r0], #4
-		bge	11b
-12:		sub	r1, r1, #3
-		b	6b
+	.macro str1w ptr reg abort
+	str \reg, [\ptr], #4
+	.endm
 
 
-13:		cmp	r2, #12
-		blt	16f
-	PLD(	pld	[r1, #12]		)
-		sub	r2, r2, #12
-	PLD(	subs	r2, r2, #32		)
-	PLD(	blt	15f			)
-	PLD(	pld	[r1, #28]		)
-14:	PLD(	pld	[r1, #44]		)
-15:		mov	r3, r7, pull #16
-		ldmia	r1!, {r4 - r7}
-		subs	r2, r2, #16
-		orr	r3, r3, r4, push #16
-		mov	r4, r4, pull #16
-		orr	r4, r4, r5, push #16
-		mov	r5, r5, pull #16
-		orr	r5, r5, r6, push #16
-		mov	r6, r6, pull #16
-		orr	r6, r6, r7, push #16
-		stmia	r0!, {r3 - r6}
-		bge	14b
-	PLD(	cmn	r2, #32			)
-	PLD(	bge	15b			)
-	PLD(	add	r2, r2, #32		)
-		adds	r2, r2, #12
-		blt	17f
-16:		mov	r3, r7, pull #16
-		ldr	r7, [r1], #4
-		subs	r2, r2, #4
-		orr	r3, r3, r7, push #16
-		str	r3, [r0], #4
-		bge	16b
-17:		sub	r1, r1, #2
-		b	6b
+	.macro str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
+	stmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
+	.endm
 
 
-18:		cmp	r2, #12
-		blt	21f
-	PLD(	pld	[r1, #12]		)
-		sub	r2, r2, #12
-	PLD(	subs	r2, r2, #32		)
-	PLD(	blt	20f			)
-	PLD(	pld	[r1, #28]		)
-19:	PLD(	pld	[r1, #44]		)
-20:		mov	r3, r7, pull #24
-		ldmia	r1!, {r4 - r7}
-		subs	r2, r2, #16
-		orr	r3, r3, r4, push #8
-		mov	r4, r4, pull #24
-		orr	r4, r4, r5, push #8
-		mov	r5, r5, pull #24
-		orr	r5, r5, r6, push #8
-		mov	r6, r6, pull #24
-		orr	r6, r6, r7, push #8
-		stmia	r0!, {r3 - r6}
-		bge	19b
-	PLD(	cmn	r2, #32			)
-	PLD(	bge	20b			)
-	PLD(	add	r2, r2, #32		)
-		adds	r2, r2, #12
-		blt	22f
-21:		mov	r3, r7, pull #24
-		ldr	r7, [r1], #4
-		subs	r2, r2, #4
-		orr	r3, r3, r7, push #8
-		str	r3, [r0], #4
-		bge	21b
-22:		sub	r1, r1, #1
-		b	6b
+	.macro str1b ptr reg cond=al abort
+	str\cond\()b \reg, [\ptr], #1
+	.endm
 
 
+	.macro enter reg1 reg2
+	stmdb sp!, {r0, \reg1, \reg2}
+	.endm
 
 
-23:		add	r1, r1, r2
-		add	r0, r0, r2
-		subs	r2, r2, #4
-		blt	29f
-	PLD(	pld	[r1, #-4]		)
-		ands	ip, r0, #3
-		bne	30f
-		ands	ip, r1, #3
-		bne	31f
+	.macro exit reg1 reg2
+	ldmfd sp!, {r0, \reg1, \reg2}
+	.endm
 
 
-24:		subs	r2, r2, #8
-		blt	28f
-		subs	r2, r2, #20
-		blt	27f
-	PLD(	pld	[r1, #-32]		)
-	PLD(	subs	r2, r2, #64		)
-	PLD(	blt	26f			)
-25:	PLD(	pld	[r1, #-64]		)
-	PLD(	pld	[r1, #-96]		)
-		ldmdb	r1!, {r3 - r9, ip}
-		subs	r2, r2, #32
-		stmgedb	r0!, {r3 - r9, ip}
-		ldmgedb	r1!, {r3 - r9, ip}
-		subges	r2, r2, #32
-		stmdb	r0!, {r3 - r9, ip}
-		bge	25b
-26:	PLD(	ldmdb	r1!, {r3 - r9, ip}	)
-	PLD(	adds	r2, r2, #32		)
-	PLD(	stmgedb	r0!, {r3 - r9, ip}	)
-	PLD(	ldmgedb	r1!, {r3 - r9, ip}	)
-	PLD(	subges	r2, r2, #32		)
-	PLD(	stmdb	r0!, {r3 - r9, ip}	)
-27:		cmn	r2, #16
-		ldmgedb	r1!, {r3 - r6}
-		subge	r2, r2, #16
-		stmgedb	r0!, {r3 - r6}
-		adds	r2, r2, #20
-		ldmgedb	r1!, {r3 - r5}
-		subge	r2, r2, #12
-		stmgedb	r0!, {r3 - r5}
-28:		adds	r2, r2, #8
-		blt	29f
-		subs	r2, r2, #4
-		ldrlt	r3, [r1, #-4]!
-		ldmgedb	r1!, {r4, r5}
-		subge	r2, r2, #4
-		strlt	r3, [r0, #-4]!
-		stmgedb	r0!, {r4, r5}
+	.text
 
 
-29:		adds	r2, r2, #4
-		EXITEQ
-		cmp	r2, #2
-		ldrb	r3, [r1, #-1]!
-		ldrgeb	r4, [r1, #-1]!
-		ldrgtb	r5, [r1, #-1]!
-		strb	r3, [r0, #-1]!
-		strgeb	r4, [r0, #-1]!
-		strgtb	r5, [r0, #-1]!
-		EXIT
+/* Prototype: void *memcpy(void *dest, const void *src, size_t n); */
 
 
-30:		cmp	ip, #2
-		ldrb	r3, [r1, #-1]!
-		ldrgeb	r4, [r1, #-1]!
-		ldrgtb	r5, [r1, #-1]!
-		strb	r3, [r0, #-1]!
-		strgeb	r4, [r0, #-1]!
-		strgtb	r5, [r0, #-1]!
-		subs	r2, r2, ip
-		blt	29b
-		ands	ip, r1, #3
-		beq	24b
-
-31:		bic	r1, r1, #3
-		ldr	r3, [r1], #0
-		cmp	ip, #2
-		blt	41f
-		beq	36f
-		cmp	r2, #12
-		blt	34f
-	PLD(	pld	[r1, #-16]		)
-		sub	r2, r2, #12
-	PLD(	subs	r2, r2, #32		)
-	PLD(	blt	33f			)
-	PLD(	pld	[r1, #-32]		)
-32:	PLD(	pld	[r1, #-48]		)
-33:		mov	r7, r3, push #8
-		ldmdb	r1!, {r3, r4, r5, r6}
-		subs	r2, r2, #16
-		orr	r7, r7, r6, pull #24
-		mov	r6, r6, push #8
-		orr	r6, r6, r5, pull #24
-		mov	r5, r5, push #8
-		orr	r5, r5, r4, pull #24
-		mov	r4, r4, push #8
-		orr	r4, r4, r3, pull #24
-		stmdb	r0!, {r4, r5, r6, r7}
-		bge	32b
-	PLD(	cmn	r2, #32			)
-	PLD(	bge	33b			)
-	PLD(	add	r2, r2, #32		)
-		adds	r2, r2, #12
-		blt	35f
-34:		mov	ip, r3, push #8
-		ldr	r3, [r1, #-4]!
-		subs	r2, r2, #4
-		orr	ip, ip, r3, pull #24
-		str	ip, [r0, #-4]!
-		bge	34b
-35:		add	r1, r1, #3
-		b	29b
-
-36:		cmp	r2, #12
-		blt	39f
-	PLD(	pld	[r1, #-16]		)
-		sub	r2, r2, #12
-	PLD(	subs	r2, r2, #32		)
-	PLD(	blt	38f			)
-	PLD(	pld	[r1, #-32]		)
-37:	PLD(	pld	[r1, #-48]		)
-38:		mov	r7, r3, push #16
-		ldmdb	r1!, {r3, r4, r5, r6}
-		subs	r2, r2, #16
-		orr	r7, r7, r6, pull #16
-		mov	r6, r6, push #16
-		orr	r6, r6, r5, pull #16
-		mov	r5, r5, push #16
-		orr	r5, r5, r4, pull #16
-		mov	r4, r4, push #16
-		orr	r4, r4, r3, pull #16
-		stmdb	r0!, {r4, r5, r6, r7}
-		bge	37b
-	PLD(	cmn	r2, #32			)
-	PLD(	bge	38b			)
-	PLD(	add	r2, r2, #32		)
-		adds	r2, r2, #12
-		blt	40f
-39:		mov	ip, r3, push #16
-		ldr	r3, [r1, #-4]!
-		subs	r2, r2, #4
-		orr	ip, ip, r3, pull #16
-		str	ip, [r0, #-4]!
-		bge	39b
-40:		add	r1, r1, #2
-		b	29b
+ENTRY(memcpy)
 
 
-41:		cmp	r2, #12
-		blt	44f
-	PLD(	pld	[r1, #-16]		)
-		sub	r2, r2, #12
-	PLD(	subs	r2, r2, #32		)
-	PLD(	blt	43f			)
-	PLD(	pld	[r1, #-32]		)
-42:	PLD(	pld	[r1, #-48]		)
-43:		mov	r7, r3, push #24
-		ldmdb	r1!, {r3, r4, r5, r6}
-		subs	r2, r2, #16
-		orr	r7, r7, r6, pull #8
-		mov	r6, r6, push #24
-		orr	r6, r6, r5, pull #8
-		mov	r5, r5, push #24
-		orr	r5, r5, r4, pull #8
-		mov	r4, r4, push #24
-		orr	r4, r4, r3, pull #8
-		stmdb	r0!, {r4, r5, r6, r7}
-		bge	42b
-	PLD(	cmn	r2, #32			)
-	PLD(	bge	43b			)
-	PLD(	add	r2, r2, #32		)
-		adds	r2, r2, #12
-		blt	45f
-44:		mov	ip, r3, push #24
-		ldr	r3, [r1, #-4]!
-		subs	r2, r2, #4
-		orr	ip, ip, r3, pull #8
-		str	ip, [r0, #-4]!
-		bge	44b
-45:		add	r1, r1, #1
-		b	29b
+#include "copy_template.S"
 
 

+ 206 - 0
arch/arm/lib/memmove.S

@@ -0,0 +1,206 @@
+/*
+ *  linux/arch/arm/lib/memmove.S
+ *
+ *  Author:	Nicolas Pitre
+ *  Created:	Sep 28, 2005
+ *  Copyright:	(C) MontaVista Software Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+/*
+ * This can be used to enable code to cacheline align the source pointer.
+ * Experiments on tested architectures (StrongARM and XScale) didn't show
+ * this a worthwhile thing to do.  That might be different in the future.
+ */
+//#define CALGN(code...)        code
+#define CALGN(code...)
+
+		.text
+
+/*
+ * Prototype: void *memmove(void *dest, const void *src, size_t n);
+ *
+ * Note:
+ *
+ * If the memory regions don't overlap, we simply branch to memcpy which is
+ * normally a bit faster. Otherwise the copy is done going downwards.  This
+ * is a transposition of the code from copy_template.S but with the copy
+ * occurring in the opposite direction.
+ */
+
+ENTRY(memmove)
+
+		subs	ip, r0, r1
+		cmphi	r2, ip
+		bls	memcpy
+
+		stmfd	sp!, {r0, r4, lr}
+		add	r1, r1, r2
+		add	r0, r0, r2
+		subs	r2, r2, #4
+		blt	8f
+		ands	ip, r0, #3
+	PLD(	pld	[r1, #-4]		)
+		bne	9f
+		ands	ip, r1, #3
+		bne	10f
+
+1:		subs	r2, r2, #(28)
+		stmfd	sp!, {r5 - r8}
+		blt	5f
+
+	CALGN(	ands	ip, r1, #31		)
+	CALGN(	sbcnes	r4, ip, r2		)  @ C is always set here
+	CALGN(	bcs	2f			)
+	CALGN(	adr	r4, 6f			)
+	CALGN(	subs	r2, r2, ip		)  @ C is set here
+	CALGN(	add	pc, r4, ip		)
+
+	PLD(	pld	[r1, #-4]		)
+2:	PLD(	subs	r2, r2, #96		)
+	PLD(	pld	[r1, #-32]		)
+	PLD(	blt	4f			)
+	PLD(	pld	[r1, #-64]		)
+	PLD(	pld	[r1, #-96]		)
+
+3:	PLD(	pld	[r1, #-128]		)
+4:		ldmdb	r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
+		subs	r2, r2, #32
+		stmdb	r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
+		bge	3b
+	PLD(	cmn	r2, #96			)
+	PLD(	bge	4b			)
+
+5:		ands	ip, r2, #28
+		rsb	ip, ip, #32
+		addne	pc, pc, ip		@ C is always clear here
+		b	7f
+6:		nop
+		ldr	r3, [r1, #-4]!
+		ldr	r4, [r1, #-4]!
+		ldr	r5, [r1, #-4]!
+		ldr	r6, [r1, #-4]!
+		ldr	r7, [r1, #-4]!
+		ldr	r8, [r1, #-4]!
+		ldr	lr, [r1, #-4]!
+
+		add	pc, pc, ip
+		nop
+		nop
+		str	r3, [r0, #-4]!
+		str	r4, [r0, #-4]!
+		str	r5, [r0, #-4]!
+		str	r6, [r0, #-4]!
+		str	r7, [r0, #-4]!
+		str	r8, [r0, #-4]!
+		str	lr, [r0, #-4]!
+
+	CALGN(	bcs	2b			)
+
+7:		ldmfd	sp!, {r5 - r8}
+
+8:		movs	r2, r2, lsl #31
+		ldrneb	r3, [r1, #-1]!
+		ldrcsb	r4, [r1, #-1]!
+		ldrcsb	ip, [r1, #-1]
+		strneb	r3, [r0, #-1]!
+		strcsb	r4, [r0, #-1]!
+		strcsb	ip, [r0, #-1]
+		ldmfd	sp!, {r0, r4, pc}
+
+9:		cmp	ip, #2
+		ldrgtb	r3, [r1, #-1]!
+		ldrgeb	r4, [r1, #-1]!
+		ldrb	lr, [r1, #-1]!
+		strgtb	r3, [r0, #-1]!
+		strgeb	r4, [r0, #-1]!
+		subs	r2, r2, ip
+		strb	lr, [r0, #-1]!
+		blt	8b
+		ands	ip, r1, #3
+		beq	1b
+
+10:		bic	r1, r1, #3
+		cmp	ip, #2
+		ldr	r3, [r1, #0]
+		beq	17f
+		blt	18f
+
+
+		.macro	backward_copy_shift push pull
+
+		subs	r2, r2, #28
+		blt	14f
+
+	CALGN(	ands	ip, r1, #31		)
+	CALGN(	rsb	ip, ip, #32		)
+	CALGN(	sbcnes	r4, ip, r2		)  @ C is always set here
+	CALGN(	subcc	r2, r2, ip		)
+	CALGN(	bcc	15f			)
+
+11:		stmfd	sp!, {r5 - r9}
+
+	PLD(	pld	[r1, #-4]		)
+	PLD(	subs	r2, r2, #96		)
+	PLD(	pld	[r1, #-32]		)
+	PLD(	blt	13f			)
+	PLD(	pld	[r1, #-64]		)
+	PLD(	pld	[r1, #-96]		)
+
+12:	PLD(	pld	[r1, #-128]		)
+13:		ldmdb   r1!, {r7, r8, r9, ip}
+		mov     lr, r3, push #\push
+		subs    r2, r2, #32
+		ldmdb   r1!, {r3, r4, r5, r6}
+		orr     lr, lr, ip, pull #\pull
+		mov     ip, ip, push #\push
+		orr     ip, ip, r9, pull #\pull
+		mov     r9, r9, push #\push
+		orr     r9, r9, r8, pull #\pull
+		mov     r8, r8, push #\push
+		orr     r8, r8, r7, pull #\pull
+		mov     r7, r7, push #\push
+		orr     r7, r7, r6, pull #\pull
+		mov     r6, r6, push #\push
+		orr     r6, r6, r5, pull #\pull
+		mov     r5, r5, push #\push
+		orr     r5, r5, r4, pull #\pull
+		mov     r4, r4, push #\push
+		orr     r4, r4, r3, pull #\pull
+		stmdb   r0!, {r4 - r9, ip, lr}
+		bge	12b
+	PLD(	cmn	r2, #96			)
+	PLD(	bge	13b			)
+
+		ldmfd	sp!, {r5 - r9}
+
+14:		ands	ip, r2, #28
+		beq	16f
+
+15:		mov     lr, r3, push #\push
+		ldr	r3, [r1, #-4]!
+		subs	ip, ip, #4
+		orr	lr, lr, r3, pull #\pull
+		str	lr, [r0, #-4]!
+		bgt	15b
+	CALGN(	cmp	r2, #0			)
+	CALGN(	bge	11b			)
+
+16:		add	r1, r1, #(\pull / 8)
+		b	8b
+
+		.endm
+
+
+		backward_copy_shift	push=8	pull=24
+
+17:		backward_copy_shift	push=16	pull=16
+
+18:		backward_copy_shift	push=24	pull=8
+

+ 0 - 38
arch/arm/lib/uaccess.S

@@ -657,41 +657,3 @@ USER(		ldrgtbt	r3, [r1], #1)			@ May fault
 		LOADREGS(fd,sp!, {r4 - r7, pc})
 		LOADREGS(fd,sp!, {r4 - r7, pc})
 		.previous
 		.previous
 
 
-/* Prototype: int __arch_clear_user(void *addr, size_t sz)
- * Purpose  : clear some user memory
- * Params   : addr - user memory address to clear
- *          : sz   - number of bytes to clear
- * Returns  : number of bytes NOT cleared
- */
-ENTRY(__arch_clear_user)
-		stmfd	sp!, {r1, lr}
-		mov	r2, #0
-		cmp	r1, #4
-		blt	2f
-		ands	ip, r0, #3
-		beq	1f
-		cmp	ip, #2
-USER(		strbt	r2, [r0], #1)
-USER(		strlebt	r2, [r0], #1)
-USER(		strltbt	r2, [r0], #1)
-		rsb	ip, ip, #4
-		sub	r1, r1, ip		@  7  6  5  4  3  2  1
-1:		subs	r1, r1, #8		@ -1 -2 -3 -4 -5 -6 -7
-USER(		strplt	r2, [r0], #4)
-USER(		strplt	r2, [r0], #4)
-		bpl	1b
-		adds	r1, r1, #4		@  3  2  1  0 -1 -2 -3
-USER(		strplt	r2, [r0], #4)
-2:		tst	r1, #2			@ 1x 1x 0x 0x 1x 1x 0x
-USER(		strnebt	r2, [r0], #1)
-USER(		strnebt	r2, [r0], #1)
-		tst	r1, #1			@ x1 x0 x1 x0 x1 x0 x1
-USER(		strnebt	r2, [r0], #1)
-		mov	r0, #0
-		LOADREGS(fd,sp!, {r1, pc})
-
-		.section .fixup,"ax"
-		.align	0
-9001:		LOADREGS(fd,sp!, {r0, pc})
-		.previous
-

+ 25 - 1
arch/arm/mach-ebsa110/core.c

@@ -251,9 +251,33 @@ static struct platform_device serial_device = {
 	},
 	},
 };
 };
 
 
+static struct resource am79c961_resources[] = {
+	{
+		.start		= 0x220,
+		.end		= 0x238,
+		.flags		= IORESOURCE_IO,
+	}, {
+		.start		= IRQ_EBSA110_ETHERNET,
+		.end		= IRQ_EBSA110_ETHERNET,
+		.flags		= IORESOURCE_IRQ,
+	},
+};
+
+static struct platform_device am79c961_device = {
+	.name			= "am79c961",
+	.id			= -1,
+	.num_resources		= ARRAY_SIZE(am79c961_resources),
+	.resource		= am79c961_resources,
+};
+
+static struct platform_device *ebsa110_devices[] = {
+	&serial_device,
+	&am79c961_device,
+};
+
 static int __init ebsa110_init(void)
 static int __init ebsa110_init(void)
 {
 {
-	return platform_device_register(&serial_device);
+	return platform_add_devices(ebsa110_devices, ARRAY_SIZE(ebsa110_devices));
 }
 }
 
 
 arch_initcall(ebsa110_init);
 arch_initcall(ebsa110_init);

+ 1 - 1
arch/arm/mach-ixp2000/Makefile

@@ -1,7 +1,7 @@
 #
 #
 # Makefile for the linux kernel.
 # Makefile for the linux kernel.
 #
 #
-obj-y			:= core.o pci.o
+obj-y			:= core.o pci.o uengine.o
 obj-m			:=
 obj-m			:=
 obj-n			:=
 obj-n			:=
 obj-			:=
 obj-			:=

+ 16 - 17
arch/arm/mach-ixp2000/core.c

@@ -1,5 +1,5 @@
 /*
 /*
- * arch/arm/mach-ixp2000/common.c
+ * arch/arm/mach-ixp2000/core.c
  *
  *
  * Common routines used by all IXP2400/2800 based platforms.
  * Common routines used by all IXP2400/2800 based platforms.
  *
  *
@@ -49,7 +49,6 @@ static unsigned long ixp2000_slowport_irq_flags;
  *************************************************************************/
  *************************************************************************/
 void ixp2000_acquire_slowport(struct slowport_cfg *new_cfg, struct slowport_cfg *old_cfg)
 void ixp2000_acquire_slowport(struct slowport_cfg *new_cfg, struct slowport_cfg *old_cfg)
 {
 {
-
 	spin_lock_irqsave(&ixp2000_slowport_lock, ixp2000_slowport_irq_flags);
 	spin_lock_irqsave(&ixp2000_slowport_lock, ixp2000_slowport_irq_flags);
 
 
 	old_cfg->CCR = *IXP2000_SLOWPORT_CCR;
 	old_cfg->CCR = *IXP2000_SLOWPORT_CCR;
@@ -62,7 +61,7 @@ void ixp2000_acquire_slowport(struct slowport_cfg *new_cfg, struct slowport_cfg
 	ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, new_cfg->WTC);
 	ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, new_cfg->WTC);
 	ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, new_cfg->RTC);
 	ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, new_cfg->RTC);
 	ixp2000_reg_write(IXP2000_SLOWPORT_PCR, new_cfg->PCR);
 	ixp2000_reg_write(IXP2000_SLOWPORT_PCR, new_cfg->PCR);
-	ixp2000_reg_write(IXP2000_SLOWPORT_ADC, new_cfg->ADC);
+	ixp2000_reg_wrb(IXP2000_SLOWPORT_ADC, new_cfg->ADC);
 }
 }
 
 
 void ixp2000_release_slowport(struct slowport_cfg *old_cfg)
 void ixp2000_release_slowport(struct slowport_cfg *old_cfg)
@@ -71,7 +70,7 @@ void ixp2000_release_slowport(struct slowport_cfg *old_cfg)
 	ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, old_cfg->WTC);
 	ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, old_cfg->WTC);
 	ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, old_cfg->RTC);
 	ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, old_cfg->RTC);
 	ixp2000_reg_write(IXP2000_SLOWPORT_PCR, old_cfg->PCR);
 	ixp2000_reg_write(IXP2000_SLOWPORT_PCR, old_cfg->PCR);
-	ixp2000_reg_write(IXP2000_SLOWPORT_ADC, old_cfg->ADC);
+	ixp2000_reg_wrb(IXP2000_SLOWPORT_ADC, old_cfg->ADC);
 
 
 	spin_unlock_irqrestore(&ixp2000_slowport_lock, 
 	spin_unlock_irqrestore(&ixp2000_slowport_lock, 
 					ixp2000_slowport_irq_flags);
 					ixp2000_slowport_irq_flags);
@@ -145,7 +144,7 @@ void __init ixp2000_map_io(void)
 	iotable_init(ixp2000_io_desc, ARRAY_SIZE(ixp2000_io_desc));
 	iotable_init(ixp2000_io_desc, ARRAY_SIZE(ixp2000_io_desc));
 
 
 	/* Set slowport to 8-bit mode.  */
 	/* Set slowport to 8-bit mode.  */
-	ixp2000_reg_write(IXP2000_SLOWPORT_FRM, 1);
+	ixp2000_reg_wrb(IXP2000_SLOWPORT_FRM, 1);
 }
 }
 
 
 
 
@@ -209,7 +208,7 @@ static int ixp2000_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 	write_seqlock(&xtime_lock);
 	write_seqlock(&xtime_lock);
 
 
 	/* clear timer 1 */
 	/* clear timer 1 */
-	ixp2000_reg_write(IXP2000_T1_CLR, 1);
+	ixp2000_reg_wrb(IXP2000_T1_CLR, 1);
 
 
 	while ((next_jiffy_time - *missing_jiffy_timer_csr) > ticks_per_jiffy) {
 	while ((next_jiffy_time - *missing_jiffy_timer_csr) > ticks_per_jiffy) {
 		timer_tick(regs);
 		timer_tick(regs);
@@ -252,12 +251,12 @@ void __init ixp2000_init_time(unsigned long tick_rate)
 
 
 		ixp2000_reg_write(IXP2000_T4_CLR, 0);
 		ixp2000_reg_write(IXP2000_T4_CLR, 0);
 		ixp2000_reg_write(IXP2000_T4_CLD, -1);
 		ixp2000_reg_write(IXP2000_T4_CLD, -1);
-		ixp2000_reg_write(IXP2000_T4_CTL, (1 << 7));
+		ixp2000_reg_wrb(IXP2000_T4_CTL, (1 << 7));
 		missing_jiffy_timer_csr = IXP2000_T4_CSR;
 		missing_jiffy_timer_csr = IXP2000_T4_CSR;
 	} else {
 	} else {
 		ixp2000_reg_write(IXP2000_T2_CLR, 0);
 		ixp2000_reg_write(IXP2000_T2_CLR, 0);
 		ixp2000_reg_write(IXP2000_T2_CLD, -1);
 		ixp2000_reg_write(IXP2000_T2_CLD, -1);
-		ixp2000_reg_write(IXP2000_T2_CTL, (1 << 7));
+		ixp2000_reg_wrb(IXP2000_T2_CTL, (1 << 7));
 		missing_jiffy_timer_csr = IXP2000_T2_CSR;
 		missing_jiffy_timer_csr = IXP2000_T2_CSR;
 	}
 	}
  	next_jiffy_time = 0xffffffff;
  	next_jiffy_time = 0xffffffff;
@@ -279,7 +278,7 @@ static void update_gpio_int_csrs(void)
 	ixp2000_reg_write(IXP2000_GPIO_FEDR, GPIO_IRQ_falling_edge);
 	ixp2000_reg_write(IXP2000_GPIO_FEDR, GPIO_IRQ_falling_edge);
 	ixp2000_reg_write(IXP2000_GPIO_REDR, GPIO_IRQ_rising_edge);
 	ixp2000_reg_write(IXP2000_GPIO_REDR, GPIO_IRQ_rising_edge);
 	ixp2000_reg_write(IXP2000_GPIO_LSLR, GPIO_IRQ_level_low);
 	ixp2000_reg_write(IXP2000_GPIO_LSLR, GPIO_IRQ_level_low);
-	ixp2000_reg_write(IXP2000_GPIO_LSHR, GPIO_IRQ_level_high);
+	ixp2000_reg_wrb(IXP2000_GPIO_LSHR, GPIO_IRQ_level_high);
 }
 }
 
 
 void gpio_line_config(int line, int direction)
 void gpio_line_config(int line, int direction)
@@ -297,9 +296,9 @@ void gpio_line_config(int line, int direction)
 		GPIO_IRQ_level_high &= ~(1 << line);
 		GPIO_IRQ_level_high &= ~(1 << line);
 		update_gpio_int_csrs();
 		update_gpio_int_csrs();
 
 
-		ixp2000_reg_write(IXP2000_GPIO_PDSR, 1 << line);
+		ixp2000_reg_wrb(IXP2000_GPIO_PDSR, 1 << line);
 	} else if (direction == GPIO_IN) {
 	} else if (direction == GPIO_IN) {
-		ixp2000_reg_write(IXP2000_GPIO_PDCR, 1 << line);
+		ixp2000_reg_wrb(IXP2000_GPIO_PDCR, 1 << line);
 	}
 	}
 	local_irq_restore(flags);
 	local_irq_restore(flags);
 }
 }
@@ -365,12 +364,12 @@ static void ixp2000_GPIO_irq_mask_ack(unsigned int irq)
 
 
 	ixp2000_reg_write(IXP2000_GPIO_EDSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
 	ixp2000_reg_write(IXP2000_GPIO_EDSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
 	ixp2000_reg_write(IXP2000_GPIO_LDSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
 	ixp2000_reg_write(IXP2000_GPIO_LDSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
-	ixp2000_reg_write(IXP2000_GPIO_INST, (1 << (irq - IRQ_IXP2000_GPIO0)));
+	ixp2000_reg_wrb(IXP2000_GPIO_INST, (1 << (irq - IRQ_IXP2000_GPIO0)));
 }
 }
 
 
 static void ixp2000_GPIO_irq_mask(unsigned int irq)
 static void ixp2000_GPIO_irq_mask(unsigned int irq)
 {
 {
-	ixp2000_reg_write(IXP2000_GPIO_INCR, (1 << (irq - IRQ_IXP2000_GPIO0)));
+	ixp2000_reg_wrb(IXP2000_GPIO_INCR, (1 << (irq - IRQ_IXP2000_GPIO0)));
 }
 }
 
 
 static void ixp2000_GPIO_irq_unmask(unsigned int irq)
 static void ixp2000_GPIO_irq_unmask(unsigned int irq)
@@ -389,9 +388,9 @@ static void ixp2000_pci_irq_mask(unsigned int irq)
 {
 {
 	unsigned long temp = *IXP2000_PCI_XSCALE_INT_ENABLE;
 	unsigned long temp = *IXP2000_PCI_XSCALE_INT_ENABLE;
 	if (irq == IRQ_IXP2000_PCIA)
 	if (irq == IRQ_IXP2000_PCIA)
-		ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp & ~(1 << 26)));
+		ixp2000_reg_wrb(IXP2000_PCI_XSCALE_INT_ENABLE, (temp & ~(1 << 26)));
 	else if (irq == IRQ_IXP2000_PCIB)
 	else if (irq == IRQ_IXP2000_PCIB)
-		ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp & ~(1 << 27)));
+		ixp2000_reg_wrb(IXP2000_PCI_XSCALE_INT_ENABLE, (temp & ~(1 << 27)));
 }
 }
 
 
 static void ixp2000_pci_irq_unmask(unsigned int irq)
 static void ixp2000_pci_irq_unmask(unsigned int irq)
@@ -411,7 +410,7 @@ static struct irqchip ixp2000_pci_irq_chip = {
 
 
 static void ixp2000_irq_mask(unsigned int irq)
 static void ixp2000_irq_mask(unsigned int irq)
 {
 {
-	ixp2000_reg_write(IXP2000_IRQ_ENABLE_CLR, (1 << irq));
+	ixp2000_reg_wrb(IXP2000_IRQ_ENABLE_CLR, (1 << irq));
 }
 }
 
 
 static void ixp2000_irq_unmask(unsigned int irq)
 static void ixp2000_irq_unmask(unsigned int irq)
@@ -443,7 +442,7 @@ void __init ixp2000_init_irq(void)
 	ixp2000_reg_write(IXP2000_GPIO_INCR, -1);
 	ixp2000_reg_write(IXP2000_GPIO_INCR, -1);
 
 
 	/* clear PCI interrupt sources */
 	/* clear PCI interrupt sources */
-	ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, 0);
+	ixp2000_reg_wrb(IXP2000_PCI_XSCALE_INT_ENABLE, 0);
 
 
 	/*
 	/*
 	 * Certain bits in the IRQ status register of the 
 	 * Certain bits in the IRQ status register of the 

+ 30 - 1
arch/arm/mach-ixp2000/enp2611.c

@@ -63,6 +63,35 @@ static struct sys_timer enp2611_timer = {
 };
 };
 
 
 
 
+/*************************************************************************
+ * ENP-2611 I/O
+ *************************************************************************/
+static struct map_desc enp2611_io_desc[] __initdata = {
+	{
+		.virtual	= ENP2611_CALEB_VIRT_BASE,
+		.physical	= ENP2611_CALEB_PHYS_BASE,
+		.length		= ENP2611_CALEB_SIZE,
+		.type		= MT_IXP2000_DEVICE
+	}, {
+		.virtual	= ENP2611_PM3386_0_VIRT_BASE,
+		.physical	= ENP2611_PM3386_0_PHYS_BASE,
+		.length		= ENP2611_PM3386_0_SIZE,
+		.type		= MT_IXP2000_DEVICE
+	}, {
+		.virtual	= ENP2611_PM3386_1_VIRT_BASE,
+		.physical	= ENP2611_PM3386_1_PHYS_BASE,
+		.length		= ENP2611_PM3386_1_SIZE,
+		.type		= MT_IXP2000_DEVICE
+	}
+};
+
+void __init enp2611_map_io(void)
+{
+	ixp2000_map_io();
+	iotable_init(enp2611_io_desc, ARRAY_SIZE(enp2611_io_desc));
+}
+
+
 /*************************************************************************
 /*************************************************************************
  * ENP-2611 PCI
  * ENP-2611 PCI
  *************************************************************************/
  *************************************************************************/
@@ -229,7 +258,7 @@ MACHINE_START(ENP2611, "Radisys ENP-2611 PCI network processor board")
 	.phys_io	= IXP2000_UART_PHYS_BASE,
 	.phys_io	= IXP2000_UART_PHYS_BASE,
 	.io_pg_offst	= ((IXP2000_UART_VIRT_BASE) >> 18) & 0xfffc,
 	.io_pg_offst	= ((IXP2000_UART_VIRT_BASE) >> 18) & 0xfffc,
 	.boot_params	= 0x00000100,
 	.boot_params	= 0x00000100,
-	.map_io		= ixp2000_map_io,
+	.map_io		= enp2611_map_io,
 	.init_irq	= ixp2000_init_irq,
 	.init_irq	= ixp2000_init_irq,
 	.timer		= &enp2611_timer,
 	.timer		= &enp2611_timer,
 	.init_machine	= enp2611_init_machine,
 	.init_machine	= enp2611_init_machine,

+ 2 - 2
arch/arm/mach-ixp2000/ixdp2x00.c

@@ -81,7 +81,7 @@ static void ixdp2x00_irq_mask(unsigned int irq)
 
 
 	dummy = *board_irq_mask;
 	dummy = *board_irq_mask;
 	dummy |=  IXP2000_BOARD_IRQ_MASK(irq);
 	dummy |=  IXP2000_BOARD_IRQ_MASK(irq);
-	ixp2000_reg_write(board_irq_mask, dummy);
+	ixp2000_reg_wrb(board_irq_mask, dummy);
 
 
 #ifdef CONFIG_ARCH_IXDP2400
 #ifdef CONFIG_ARCH_IXDP2400
 	if (machine_is_ixdp2400())
 	if (machine_is_ixdp2400())
@@ -101,7 +101,7 @@ static void ixdp2x00_irq_unmask(unsigned int irq)
 
 
 	dummy = *board_irq_mask;
 	dummy = *board_irq_mask;
 	dummy &=  ~IXP2000_BOARD_IRQ_MASK(irq);
 	dummy &=  ~IXP2000_BOARD_IRQ_MASK(irq);
-	ixp2000_reg_write(board_irq_mask, dummy);
+	ixp2000_reg_wrb(board_irq_mask, dummy);
 
 
 	if (machine_is_ixdp2400()) 
 	if (machine_is_ixdp2400()) 
 		ixp2000_release_slowport(&old_cfg);
 		ixp2000_release_slowport(&old_cfg);

+ 4 - 5
arch/arm/mach-ixp2000/ixdp2x01.c

@@ -51,7 +51,7 @@
  *************************************************************************/
  *************************************************************************/
 static void ixdp2x01_irq_mask(unsigned int irq)
 static void ixdp2x01_irq_mask(unsigned int irq)
 {
 {
-	ixp2000_reg_write(IXDP2X01_INT_MASK_SET_REG,
+	ixp2000_reg_wrb(IXDP2X01_INT_MASK_SET_REG,
 				IXP2000_BOARD_IRQ_MASK(irq));
 				IXP2000_BOARD_IRQ_MASK(irq));
 }
 }
 
 
@@ -114,7 +114,7 @@ void __init ixdp2x01_init_irq(void)
 
 
 	/* Mask all interrupts from CPLD, disable simulation */
 	/* Mask all interrupts from CPLD, disable simulation */
 	ixp2000_reg_write(IXDP2X01_INT_MASK_SET_REG, 0xffffffff);
 	ixp2000_reg_write(IXDP2X01_INT_MASK_SET_REG, 0xffffffff);
-	ixp2000_reg_write(IXDP2X01_INT_SIM_REG, 0);
+	ixp2000_reg_wrb(IXDP2X01_INT_SIM_REG, 0);
 
 
 	for (irq = NR_IXP2000_IRQS; irq < NR_IXDP2X01_IRQS; irq++) {
 	for (irq = NR_IXP2000_IRQS; irq < NR_IXDP2X01_IRQS; irq++) {
 		if (irq & valid_irq_mask) {
 		if (irq & valid_irq_mask) {
@@ -299,7 +299,6 @@ struct hw_pci ixdp2x01_pci __initdata = {
 
 
 int __init ixdp2x01_pci_init(void)
 int __init ixdp2x01_pci_init(void)
 {
 {
-
 	pci_common_init(&ixdp2x01_pci);
 	pci_common_init(&ixdp2x01_pci);
 	return 0;
 	return 0;
 }
 }
@@ -316,7 +315,7 @@ static struct flash_platform_data ixdp2x01_flash_platform_data = {
 
 
 static unsigned long ixdp2x01_flash_bank_setup(unsigned long ofs)
 static unsigned long ixdp2x01_flash_bank_setup(unsigned long ofs)
 {
 {
-	ixp2000_reg_write(IXDP2X01_CPLD_FLASH_REG,
+	ixp2000_reg_wrb(IXDP2X01_CPLD_FLASH_REG,
 		((ofs >> IXDP2X01_FLASH_WINDOW_BITS) | IXDP2X01_CPLD_FLASH_INTERN));
 		((ofs >> IXDP2X01_FLASH_WINDOW_BITS) | IXDP2X01_CPLD_FLASH_INTERN));
 	return (ofs & IXDP2X01_FLASH_WINDOW_MASK);
 	return (ofs & IXDP2X01_FLASH_WINDOW_MASK);
 }
 }
@@ -363,7 +362,7 @@ static struct platform_device *ixdp2x01_devices[] __initdata = {
 
 
 static void __init ixdp2x01_init_machine(void)
 static void __init ixdp2x01_init_machine(void)
 {
 {
-	ixp2000_reg_write(IXDP2X01_CPLD_FLASH_REG,
+	ixp2000_reg_wrb(IXDP2X01_CPLD_FLASH_REG,
 		(IXDP2X01_CPLD_FLASH_BANK_MASK | IXDP2X01_CPLD_FLASH_INTERN));
 		(IXDP2X01_CPLD_FLASH_BANK_MASK | IXDP2X01_CPLD_FLASH_INTERN));
 	
 	
 	ixdp2x01_flash_data.nr_banks =
 	ixdp2x01_flash_data.nr_banks =

+ 3 - 3
arch/arm/mach-ixp2000/pci.c

@@ -148,7 +148,7 @@ int ixp2000_pci_abort_handler(unsigned long addr, unsigned int fsr, struct pt_re
 	local_irq_save(flags);
 	local_irq_save(flags);
 	temp = *(IXP2000_PCI_CONTROL);
 	temp = *(IXP2000_PCI_CONTROL);
 	if (temp & ((1 << 8) | (1 << 5))) {
 	if (temp & ((1 << 8) | (1 << 5))) {
-		ixp2000_reg_write(IXP2000_PCI_CONTROL, temp);
+		ixp2000_reg_wrb(IXP2000_PCI_CONTROL, temp);
 	}
 	}
 
 
 	temp = *(IXP2000_PCI_CMDSTAT);
 	temp = *(IXP2000_PCI_CMDSTAT);
@@ -178,8 +178,8 @@ clear_master_aborts(void)
 
 
 	local_irq_save(flags);
 	local_irq_save(flags);
 	temp = *(IXP2000_PCI_CONTROL);
 	temp = *(IXP2000_PCI_CONTROL);
-	if (temp & ((1 << 8) | (1 << 5))) {	
-		ixp2000_reg_write(IXP2000_PCI_CONTROL, temp);
+	if (temp & ((1 << 8) | (1 << 5))) {
+		ixp2000_reg_wrb(IXP2000_PCI_CONTROL, temp);
 	}
 	}
 
 
 	temp = *(IXP2000_PCI_CMDSTAT);
 	temp = *(IXP2000_PCI_CMDSTAT);

+ 474 - 0
arch/arm/mach-ixp2000/uengine.c

@@ -0,0 +1,474 @@
+/*
+ * Generic library functions for the microengines found on the Intel
+ * IXP2000 series of network processors.
+ *
+ * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org>
+ * Dedicated to Marija Kulikova.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <asm/hardware.h>
+#include <asm/arch/ixp2000-regs.h>
+#include <asm/arch/uengine.h>
+#include <asm/io.h>
+
+#define USTORE_ADDRESS			0x000
+#define USTORE_DATA_LOWER		0x004
+#define USTORE_DATA_UPPER		0x008
+#define CTX_ENABLES			0x018
+#define CC_ENABLE			0x01c
+#define CSR_CTX_POINTER			0x020
+#define INDIRECT_CTX_STS		0x040
+#define ACTIVE_CTX_STS			0x044
+#define INDIRECT_CTX_SIG_EVENTS		0x048
+#define INDIRECT_CTX_WAKEUP_EVENTS	0x050
+#define NN_PUT				0x080
+#define NN_GET				0x084
+#define TIMESTAMP_LOW			0x0c0
+#define TIMESTAMP_HIGH			0x0c4
+#define T_INDEX_BYTE_INDEX		0x0f4
+#define LOCAL_CSR_STATUS		0x180
+
+u32 ixp2000_uengine_mask;
+
+static void *ixp2000_uengine_csr_area(int uengine)
+{
+	return ((void *)IXP2000_UENGINE_CSR_VIRT_BASE) + (uengine << 10);
+}
+
+/*
+ * LOCAL_CSR_STATUS=1 after a read or write to a microengine's CSR
+ * space means that the microengine we tried to access was also trying
+ * to access its own CSR space on the same clock cycle as we did.  When
+ * this happens, we lose the arbitration process by default, and the
+ * read or write we tried to do was not actually performed, so we try
+ * again until it succeeds.
+ */
+u32 ixp2000_uengine_csr_read(int uengine, int offset)
+{
+	void *uebase;
+	u32 *local_csr_status;
+	u32 *reg;
+	u32 value;
+
+	uebase = ixp2000_uengine_csr_area(uengine);
+
+	local_csr_status = (u32 *)(uebase + LOCAL_CSR_STATUS);
+	reg = (u32 *)(uebase + offset);
+	do {
+		value = ixp2000_reg_read(reg);
+	} while (ixp2000_reg_read(local_csr_status) & 1);
+
+	return value;
+}
+EXPORT_SYMBOL(ixp2000_uengine_csr_read);
+
+void ixp2000_uengine_csr_write(int uengine, int offset, u32 value)
+{
+	void *uebase;
+	u32 *local_csr_status;
+	u32 *reg;
+
+	uebase = ixp2000_uengine_csr_area(uengine);
+
+	local_csr_status = (u32 *)(uebase + LOCAL_CSR_STATUS);
+	reg = (u32 *)(uebase + offset);
+	do {
+		ixp2000_reg_write(reg, value);
+	} while (ixp2000_reg_read(local_csr_status) & 1);
+}
+EXPORT_SYMBOL(ixp2000_uengine_csr_write);
+
+void ixp2000_uengine_reset(u32 uengine_mask)
+{
+	ixp2000_reg_write(IXP2000_RESET1, uengine_mask & ixp2000_uengine_mask);
+	ixp2000_reg_write(IXP2000_RESET1, 0);
+}
+EXPORT_SYMBOL(ixp2000_uengine_reset);
+
+void ixp2000_uengine_set_mode(int uengine, u32 mode)
+{
+	/*
+	 * CTL_STR_PAR_EN: unconditionally enable parity checking on
+	 * control store.
+	 */
+	mode |= 0x10000000;
+	ixp2000_uengine_csr_write(uengine, CTX_ENABLES, mode);
+
+	/*
+	 * Enable updating of condition codes.
+	 */
+	ixp2000_uengine_csr_write(uengine, CC_ENABLE, 0x00002000);
+
+	/*
+	 * Initialise other per-microengine registers.
+	 */
+	ixp2000_uengine_csr_write(uengine, NN_PUT, 0x00);
+	ixp2000_uengine_csr_write(uengine, NN_GET, 0x00);
+	ixp2000_uengine_csr_write(uengine, T_INDEX_BYTE_INDEX, 0);
+}
+EXPORT_SYMBOL(ixp2000_uengine_set_mode);
+
+static int make_even_parity(u32 x)
+{
+	return hweight32(x) & 1;
+}
+
+static void ustore_write(int uengine, u64 insn)
+{
+	/*
+	 * Generate even parity for top and bottom 20 bits.
+	 */
+	insn |= (u64)make_even_parity((insn >> 20) & 0x000fffff) << 41;
+	insn |= (u64)make_even_parity(insn & 0x000fffff) << 40;
+
+	/*
+	 * Write to microstore.  The second write auto-increments
+	 * the USTORE_ADDRESS index register.
+	 */
+	ixp2000_uengine_csr_write(uengine, USTORE_DATA_LOWER, (u32)insn);
+	ixp2000_uengine_csr_write(uengine, USTORE_DATA_UPPER, (u32)(insn >> 32));
+}
+
+void ixp2000_uengine_load_microcode(int uengine, u8 *ucode, int insns)
+{
+	int i;
+
+	/*
+	 * Start writing to microstore at address 0.
+	 */
+	ixp2000_uengine_csr_write(uengine, USTORE_ADDRESS, 0x80000000);
+	for (i = 0; i < insns; i++) {
+		u64 insn;
+
+		insn = (((u64)ucode[0]) << 32) |
+			(((u64)ucode[1]) << 24) |
+			(((u64)ucode[2]) << 16) |
+			(((u64)ucode[3]) << 8) |
+			((u64)ucode[4]);
+		ucode += 5;
+
+		ustore_write(uengine, insn);
+	}
+
+	/*
+ 	 * Pad with a few NOPs at the end (to avoid the microengine
+	 * aborting as it prefetches beyond the last instruction), unless
+	 * we run off the end of the instruction store first, at which
+	 * point the address register will wrap back to zero.
+	 */
+	for (i = 0; i < 4; i++) {
+		u32 addr;
+
+		addr = ixp2000_uengine_csr_read(uengine, USTORE_ADDRESS);
+		if (addr == 0x80000000)
+			break;
+		ustore_write(uengine, 0xf0000c0300ULL);
+	}
+
+	/*
+	 * End programming.
+	 */
+	ixp2000_uengine_csr_write(uengine, USTORE_ADDRESS, 0x00000000);
+}
+EXPORT_SYMBOL(ixp2000_uengine_load_microcode);
+
+void ixp2000_uengine_init_context(int uengine, int context, int pc)
+{
+	/*
+	 * Select the right context for indirect access.
+	 */
+	ixp2000_uengine_csr_write(uengine, CSR_CTX_POINTER, context);
+
+	/*
+	 * Initialise signal masks to immediately go to Ready state.
+	 */
+	ixp2000_uengine_csr_write(uengine, INDIRECT_CTX_SIG_EVENTS, 1);
+	ixp2000_uengine_csr_write(uengine, INDIRECT_CTX_WAKEUP_EVENTS, 1);
+
+	/*
+	 * Set program counter.
+	 */
+	ixp2000_uengine_csr_write(uengine, INDIRECT_CTX_STS, pc);
+}
+EXPORT_SYMBOL(ixp2000_uengine_init_context);
+
+void ixp2000_uengine_start_contexts(int uengine, u8 ctx_mask)
+{
+	u32 mask;
+
+	/*
+	 * Enable the specified context to go to Executing state.
+	 */
+	mask = ixp2000_uengine_csr_read(uengine, CTX_ENABLES);
+	mask |= ctx_mask << 8;
+	ixp2000_uengine_csr_write(uengine, CTX_ENABLES, mask);
+}
+EXPORT_SYMBOL(ixp2000_uengine_start_contexts);
+
+void ixp2000_uengine_stop_contexts(int uengine, u8 ctx_mask)
+{
+	u32 mask;
+
+	/*
+	 * Disable the Ready->Executing transition.  Note that this
+	 * does not stop the context until it voluntarily yields.
+	 */
+	mask = ixp2000_uengine_csr_read(uengine, CTX_ENABLES);
+	mask &= ~(ctx_mask << 8);
+	ixp2000_uengine_csr_write(uengine, CTX_ENABLES, mask);
+}
+EXPORT_SYMBOL(ixp2000_uengine_stop_contexts);
+
+static int check_ixp_type(struct ixp2000_uengine_code *c)
+{
+	u32 product_id;
+	u32 rev;
+
+	product_id = ixp2000_reg_read(IXP2000_PRODUCT_ID);
+	if (((product_id >> 16) & 0x1f) != 0)
+		return 0;
+
+	switch ((product_id >> 8) & 0xff) {
+	case 0:		/* IXP2800 */
+		if (!(c->cpu_model_bitmask & 4))
+			return 0;
+		break;
+
+	case 1:		/* IXP2850 */
+		if (!(c->cpu_model_bitmask & 8))
+			return 0;
+		break;
+
+	case 2:		/* IXP2400 */
+		if (!(c->cpu_model_bitmask & 2))
+			return 0;
+		break;
+
+	default:
+		return 0;
+	}
+
+	rev = product_id & 0xff;
+	if (rev < c->cpu_min_revision || rev > c->cpu_max_revision)
+		return 0;
+
+	return 1;
+}
+
+static void generate_ucode(u8 *ucode, u32 *gpr_a, u32 *gpr_b)
+{
+	int offset;
+	int i;
+
+	offset = 0;
+
+	for (i = 0; i < 128; i++) {
+		u8 b3;
+		u8 b2;
+		u8 b1;
+		u8 b0;
+
+		b3 = (gpr_a[i] >> 24) & 0xff;
+		b2 = (gpr_a[i] >> 16) & 0xff;
+		b1 = (gpr_a[i] >> 8) & 0xff;
+		b0 = gpr_a[i] & 0xff;
+
+		// immed[@ai, (b1 << 8) | b0]
+		// 11110000 0000VVVV VVVV11VV VVVVVV00 1IIIIIII
+		ucode[offset++] = 0xf0;
+		ucode[offset++] = (b1 >> 4);
+		ucode[offset++] = (b1 << 4) | 0x0c | (b0 >> 6);
+		ucode[offset++] = (b0 << 2);
+		ucode[offset++] = 0x80 | i;
+
+		// immed_w1[@ai, (b3 << 8) | b2]
+		// 11110100 0100VVVV VVVV11VV VVVVVV00 1IIIIIII
+		ucode[offset++] = 0xf4;
+		ucode[offset++] = 0x40 | (b3 >> 4);
+		ucode[offset++] = (b3 << 4) | 0x0c | (b2 >> 6);
+		ucode[offset++] = (b2 << 2);
+		ucode[offset++] = 0x80 | i;
+	}
+
+	for (i = 0; i < 128; i++) {
+		u8 b3;
+		u8 b2;
+		u8 b1;
+		u8 b0;
+
+		b3 = (gpr_b[i] >> 24) & 0xff;
+		b2 = (gpr_b[i] >> 16) & 0xff;
+		b1 = (gpr_b[i] >> 8) & 0xff;
+		b0 = gpr_b[i] & 0xff;
+
+		// immed[@bi, (b1 << 8) | b0]
+		// 11110000 0000VVVV VVVV001I IIIIII11 VVVVVVVV
+		ucode[offset++] = 0xf0;
+		ucode[offset++] = (b1 >> 4);
+		ucode[offset++] = (b1 << 4) | 0x02 | (i >> 6);
+		ucode[offset++] = (i << 2) | 0x03;
+		ucode[offset++] = b0;
+
+		// immed_w1[@bi, (b3 << 8) | b2]
+		// 11110100 0100VVVV VVVV001I IIIIII11 VVVVVVVV
+		ucode[offset++] = 0xf4;
+		ucode[offset++] = 0x40 | (b3 >> 4);
+		ucode[offset++] = (b3 << 4) | 0x02 | (i >> 6);
+		ucode[offset++] = (i << 2) | 0x03;
+		ucode[offset++] = b2;
+	}
+
+	// ctx_arb[kill]
+	ucode[offset++] = 0xe0;
+	ucode[offset++] = 0x00;
+	ucode[offset++] = 0x01;
+	ucode[offset++] = 0x00;
+	ucode[offset++] = 0x00;
+}
+
+static int set_initial_registers(int uengine, struct ixp2000_uengine_code *c)
+{
+	int per_ctx_regs;
+	u32 *gpr_a;
+	u32 *gpr_b;
+	u8 *ucode;
+	int i;
+
+	gpr_a = kmalloc(128 * sizeof(u32), GFP_KERNEL);
+	gpr_b = kmalloc(128 * sizeof(u32), GFP_KERNEL);
+	ucode = kmalloc(513 * 5, GFP_KERNEL);
+	if (gpr_a == NULL || gpr_b == NULL || ucode == NULL) {
+		kfree(ucode);
+		kfree(gpr_b);
+		kfree(gpr_a);
+		return 1;
+	}
+
+	per_ctx_regs = 16;
+	if (c->uengine_parameters & IXP2000_UENGINE_4_CONTEXTS)
+		per_ctx_regs = 32;
+
+	memset(gpr_a, 0, sizeof(gpr_a));
+	memset(gpr_b, 0, sizeof(gpr_b));
+	for (i = 0; i < 256; i++) {
+		struct ixp2000_reg_value *r = c->initial_reg_values + i;
+		u32 *bank;
+		int inc;
+		int j;
+
+		if (r->reg == -1)
+			break;
+
+		bank = (r->reg & 0x400) ? gpr_b : gpr_a;
+		inc = (r->reg & 0x80) ? 128 : per_ctx_regs;
+
+		j = r->reg & 0x7f;
+		while (j < 128) {
+			bank[j] = r->value;
+			j += inc;
+		}
+	}
+
+	generate_ucode(ucode, gpr_a, gpr_b);
+	ixp2000_uengine_load_microcode(uengine, ucode, 513);
+	ixp2000_uengine_init_context(uengine, 0, 0);
+	ixp2000_uengine_start_contexts(uengine, 0x01);
+	for (i = 0; i < 100; i++) {
+		u32 status;
+
+		status = ixp2000_uengine_csr_read(uengine, ACTIVE_CTX_STS);
+		if (!(status & 0x80000000))
+			break;
+	}
+	ixp2000_uengine_stop_contexts(uengine, 0x01);
+
+	kfree(ucode);
+	kfree(gpr_b);
+	kfree(gpr_a);
+
+	return !!(i == 100);
+}
+
+int ixp2000_uengine_load(int uengine, struct ixp2000_uengine_code *c)
+{
+	int ctx;
+
+	if (!check_ixp_type(c))
+		return 1;
+
+	if (!(ixp2000_uengine_mask & (1 << uengine)))
+		return 1;
+
+	ixp2000_uengine_reset(1 << uengine);
+	ixp2000_uengine_set_mode(uengine, c->uengine_parameters);
+	if (set_initial_registers(uengine, c))
+		return 1;
+	ixp2000_uengine_load_microcode(uengine, c->insns, c->num_insns);
+
+	for (ctx = 0; ctx < 8; ctx++)
+		ixp2000_uengine_init_context(uengine, ctx, 0);
+
+	return 0;
+}
+EXPORT_SYMBOL(ixp2000_uengine_load);
+
+
+static int __init ixp2000_uengine_init(void)
+{
+	int uengine;
+	u32 value;
+
+	/*
+	 * Determine number of microengines present.
+	 */
+	switch ((ixp2000_reg_read(IXP2000_PRODUCT_ID) >> 8) & 0x1fff) {
+	case 0:		/* IXP2800 */
+	case 1:		/* IXP2850 */
+		ixp2000_uengine_mask = 0x00ff00ff;
+		break;
+
+	case 2:		/* IXP2400 */
+		ixp2000_uengine_mask = 0x000f000f;
+		break;
+
+	default:
+		printk(KERN_INFO "Detected unknown IXP2000 model (%.8x)\n",
+			(unsigned int)ixp2000_reg_read(IXP2000_PRODUCT_ID));
+		ixp2000_uengine_mask = 0x00000000;
+		break;
+	}
+
+	/*
+	 * Reset microengines.
+	 */
+	ixp2000_reg_write(IXP2000_RESET1, ixp2000_uengine_mask);
+	ixp2000_reg_write(IXP2000_RESET1, 0);
+
+	/*
+	 * Synchronise timestamp counters across all microengines.
+	 */
+	value = ixp2000_reg_read(IXP2000_MISC_CONTROL);
+	ixp2000_reg_write(IXP2000_MISC_CONTROL, value & ~0x80);
+	for (uengine = 0; uengine < 32; uengine++) {
+		if (ixp2000_uengine_mask & (1 << uengine)) {
+			ixp2000_uengine_csr_write(uengine, TIMESTAMP_LOW, 0);
+			ixp2000_uengine_csr_write(uengine, TIMESTAMP_HIGH, 0);
+		}
+	}
+	ixp2000_reg_write(IXP2000_MISC_CONTROL, value | 0x80);
+
+	return 0;
+}
+
+subsys_initcall(ixp2000_uengine_init);

+ 60 - 3
arch/arm/mach-pxa/lubbock.c

@@ -175,7 +175,7 @@ static struct platform_device sa1111_device = {
 static struct resource smc91x_resources[] = {
 static struct resource smc91x_resources[] = {
 	[0] = {
 	[0] = {
 		.name	= "smc91x-regs",
 		.name	= "smc91x-regs",
-		.start	= 0x0c000000,
+		.start	= 0x0c000c00,
 		.end	= 0x0c0fffff,
 		.end	= 0x0c0fffff,
 		.flags	= IORESOURCE_MEM,
 		.flags	= IORESOURCE_MEM,
 	},
 	},
@@ -224,18 +224,75 @@ static struct pxafb_mach_info sharp_lm8v31 __initdata = {
 	.lccr3		= LCCR3_PCP | LCCR3_Acb(255),
 	.lccr3		= LCCR3_PCP | LCCR3_Acb(255),
 };
 };
 
 
-static int lubbock_mci_init(struct device *dev, irqreturn_t (*lubbock_detect_int)(int, void *, struct pt_regs *), void *data)
+#define	MMC_POLL_RATE		msecs_to_jiffies(1000)
+
+static void lubbock_mmc_poll(unsigned long);
+static irqreturn_t (*mmc_detect_int)(int, void *, struct pt_regs *);
+
+static struct timer_list mmc_timer = {
+	.function	= lubbock_mmc_poll,
+};
+
+static void lubbock_mmc_poll(unsigned long data)
+{
+	unsigned long flags;
+
+	/* clear any previous irq state, then ... */
+	local_irq_save(flags);
+	LUB_IRQ_SET_CLR &= ~(1 << 0);
+	local_irq_restore(flags);
+
+	/* poll until mmc/sd card is removed */
+	if (LUB_IRQ_SET_CLR & (1 << 0))
+		mod_timer(&mmc_timer, jiffies + MMC_POLL_RATE);
+	else {
+		(void) mmc_detect_int(LUBBOCK_SD_IRQ, (void *)data, NULL);
+		enable_irq(LUBBOCK_SD_IRQ);
+	}
+}
+
+static irqreturn_t lubbock_detect_int(int irq, void *data, struct pt_regs *regs)
+{
+	/* IRQ is level triggered; disable, and poll for removal */
+	disable_irq(irq);
+	mod_timer(&mmc_timer, jiffies + MMC_POLL_RATE);
+
+	return mmc_detect_int(irq, data, regs);
+}
+
+static int lubbock_mci_init(struct device *dev,
+		irqreturn_t (*detect_int)(int, void *, struct pt_regs *),
+		void *data)
 {
 {
 	/* setup GPIO for PXA25x MMC controller	*/
 	/* setup GPIO for PXA25x MMC controller	*/
 	pxa_gpio_mode(GPIO6_MMCCLK_MD);
 	pxa_gpio_mode(GPIO6_MMCCLK_MD);
 	pxa_gpio_mode(GPIO8_MMCCS0_MD);
 	pxa_gpio_mode(GPIO8_MMCCS0_MD);
 
 
-	return 0;
+	/* detect card insert/eject */
+	mmc_detect_int = detect_int;
+	init_timer(&mmc_timer);
+	mmc_timer.data = (unsigned long) data;
+	return request_irq(LUBBOCK_SD_IRQ, lubbock_detect_int,
+			SA_SAMPLE_RANDOM, "lubbock-sd-detect", data);
+}
+
+static int lubbock_mci_get_ro(struct device *dev)
+{
+	return (LUB_MISC_RD & (1 << 2)) != 0;
+}
+
+static void lubbock_mci_exit(struct device *dev, void *data)
+{
+	free_irq(LUBBOCK_SD_IRQ, data);
+	del_timer_sync(&mmc_timer);
 }
 }
 
 
 static struct pxamci_platform_data lubbock_mci_platform_data = {
 static struct pxamci_platform_data lubbock_mci_platform_data = {
 	.ocr_mask	= MMC_VDD_32_33|MMC_VDD_33_34,
 	.ocr_mask	= MMC_VDD_32_33|MMC_VDD_33_34,
+	.detect_delay	= 1,
 	.init 		= lubbock_mci_init,
 	.init 		= lubbock_mci_init,
+	.get_ro		= lubbock_mci_get_ro,
+	.exit 		= lubbock_mci_exit,
 };
 };
 
 
 static void lubbock_irda_transceiver_mode(struct device *dev, int mode)
 static void lubbock_irda_transceiver_mode(struct device *dev, int mode)

+ 11 - 0
arch/arm/mach-realview/Kconfig

@@ -0,0 +1,11 @@
+menu "RealView platform type"
+	depends on ARCH_REALVIEW
+
+config MACH_REALVIEW_EB
+	bool "Support RealView/EB platform"
+	default n
+	select ARM_GIC
+	help
+	  Include support for the ARM(R) RealView Emulation Baseboard platform.
+
+endmenu

+ 6 - 0
arch/arm/mach-realview/Makefile

@@ -0,0 +1,6 @@
+#
+# Makefile for the linux kernel.
+#
+
+obj-y					:= core.o clock.o
+obj-$(CONFIG_MACH_REALVIEW_EB)		+= realview_eb.o

+ 4 - 0
arch/arm/mach-realview/Makefile.boot

@@ -0,0 +1,4 @@
+   zreladdr-y	:= 0x00008000
+params_phys-y	:= 0x00000100
+initrd_phys-y	:= 0x00800000
+

+ 145 - 0
arch/arm/mach-realview/clock.c

@@ -0,0 +1,145 @@
+/*
+ *  linux/arch/arm/mach-realview/clock.c
+ *
+ *  Copyright (C) 2004 ARM Limited.
+ *  Written by Deep Blue Solutions Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+
+#include <asm/semaphore.h>
+#include <asm/hardware/clock.h>
+#include <asm/hardware/icst307.h>
+
+#include "clock.h"
+
+static LIST_HEAD(clocks);
+static DECLARE_MUTEX(clocks_sem);
+
+struct clk *clk_get(struct device *dev, const char *id)
+{
+	struct clk *p, *clk = ERR_PTR(-ENOENT);
+
+	down(&clocks_sem);
+	list_for_each_entry(p, &clocks, node) {
+		if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
+			clk = p;
+			break;
+		}
+	}
+	up(&clocks_sem);
+
+	return clk;
+}
+EXPORT_SYMBOL(clk_get);
+
+void clk_put(struct clk *clk)
+{
+	module_put(clk->owner);
+}
+EXPORT_SYMBOL(clk_put);
+
+int clk_enable(struct clk *clk)
+{
+	return 0;
+}
+EXPORT_SYMBOL(clk_enable);
+
+void clk_disable(struct clk *clk)
+{
+}
+EXPORT_SYMBOL(clk_disable);
+
+int clk_use(struct clk *clk)
+{
+	return 0;
+}
+EXPORT_SYMBOL(clk_use);
+
+void clk_unuse(struct clk *clk)
+{
+}
+EXPORT_SYMBOL(clk_unuse);
+
+unsigned long clk_get_rate(struct clk *clk)
+{
+	return clk->rate;
+}
+EXPORT_SYMBOL(clk_get_rate);
+
+long clk_round_rate(struct clk *clk, unsigned long rate)
+{
+	return rate;
+}
+EXPORT_SYMBOL(clk_round_rate);
+
+int clk_set_rate(struct clk *clk, unsigned long rate)
+{
+	int ret = -EIO;
+
+	if (clk->setvco) {
+		struct icst307_vco vco;
+
+		vco = icst307_khz_to_vco(clk->params, rate / 1000);
+		clk->rate = icst307_khz(clk->params, vco) * 1000;
+
+		printk("Clock %s: setting VCO reg params: S=%d R=%d V=%d\n",
+			clk->name, vco.s, vco.r, vco.v);
+
+		clk->setvco(clk, vco);
+		ret = 0;
+	}
+	return ret;
+}
+EXPORT_SYMBOL(clk_set_rate);
+
+/*
+ * These are fixed clocks.
+ */
+static struct clk kmi_clk = {
+	.name	= "KMIREFCLK",
+	.rate	= 24000000,
+};
+
+static struct clk uart_clk = {
+	.name	= "UARTCLK",
+	.rate	= 24000000,
+};
+
+static struct clk mmci_clk = {
+	.name	= "MCLK",
+	.rate	= 33000000,
+};
+
+int clk_register(struct clk *clk)
+{
+	down(&clocks_sem);
+	list_add(&clk->node, &clocks);
+	up(&clocks_sem);
+	return 0;
+}
+EXPORT_SYMBOL(clk_register);
+
+void clk_unregister(struct clk *clk)
+{
+	down(&clocks_sem);
+	list_del(&clk->node);
+	up(&clocks_sem);
+}
+EXPORT_SYMBOL(clk_unregister);
+
+static int __init clk_init(void)
+{
+	clk_register(&kmi_clk);
+	clk_register(&uart_clk);
+	clk_register(&mmci_clk);
+	return 0;
+}
+arch_initcall(clk_init);

+ 25 - 0
arch/arm/mach-realview/clock.h

@@ -0,0 +1,25 @@
+/*
+ *  linux/arch/arm/mach-realview/clock.h
+ *
+ *  Copyright (C) 2004 ARM Limited.
+ *  Written by Deep Blue Solutions Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+struct module;
+struct icst307_params;
+
+struct clk {
+	struct list_head	node;
+	unsigned long		rate;
+	struct module		*owner;
+	const char		*name;
+	const struct icst307_params *params;
+	void			*data;
+	void			(*setvco)(struct clk *, struct icst307_vco vco);
+};
+
+int clk_register(struct clk *clk);
+void clk_unregister(struct clk *clk);

+ 605 - 0
arch/arm/mach-realview/core.c

@@ -0,0 +1,605 @@
+/*
+ *  linux/arch/arm/mach-realview/core.c
+ *
+ *  Copyright (C) 1999 - 2003 ARM Limited
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *
+ * 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 <linux/config.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/sysdev.h>
+#include <linux/interrupt.h>
+
+#include <asm/system.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/leds.h>
+#include <asm/mach-types.h>
+#include <asm/hardware/amba.h>
+#include <asm/hardware/amba_clcd.h>
+#include <asm/hardware/arm_timer.h>
+#include <asm/hardware/icst307.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/flash.h>
+#include <asm/mach/irq.h>
+#include <asm/mach/time.h>
+#include <asm/mach/map.h>
+#include <asm/mach/mmc.h>
+
+#include <asm/hardware/gic.h>
+
+#include "core.h"
+#include "clock.h"
+
+#define REALVIEW_REFCOUNTER	(__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_24MHz_OFFSET)
+
+/*
+ * This is the RealView sched_clock implementation.  This has
+ * a resolution of 41.7ns, and a maximum value of about 179s.
+ */
+unsigned long long sched_clock(void)
+{
+	unsigned long long v;
+
+	v = (unsigned long long)readl(REALVIEW_REFCOUNTER) * 125;
+	do_div(v, 3);
+
+	return v;
+}
+
+
+#define REALVIEW_FLASHCTRL    (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
+
+static int realview_flash_init(void)
+{
+	u32 val;
+
+	val = __raw_readl(REALVIEW_FLASHCTRL);
+	val &= ~REALVIEW_FLASHPROG_FLVPPEN;
+	__raw_writel(val, REALVIEW_FLASHCTRL);
+
+	return 0;
+}
+
+static void realview_flash_exit(void)
+{
+	u32 val;
+
+	val = __raw_readl(REALVIEW_FLASHCTRL);
+	val &= ~REALVIEW_FLASHPROG_FLVPPEN;
+	__raw_writel(val, REALVIEW_FLASHCTRL);
+}
+
+static void realview_flash_set_vpp(int on)
+{
+	u32 val;
+
+	val = __raw_readl(REALVIEW_FLASHCTRL);
+	if (on)
+		val |= REALVIEW_FLASHPROG_FLVPPEN;
+	else
+		val &= ~REALVIEW_FLASHPROG_FLVPPEN;
+	__raw_writel(val, REALVIEW_FLASHCTRL);
+}
+
+static struct flash_platform_data realview_flash_data = {
+	.map_name		= "cfi_probe",
+	.width			= 4,
+	.init			= realview_flash_init,
+	.exit			= realview_flash_exit,
+	.set_vpp		= realview_flash_set_vpp,
+};
+
+static struct resource realview_flash_resource = {
+	.start			= REALVIEW_FLASH_BASE,
+	.end			= REALVIEW_FLASH_BASE + REALVIEW_FLASH_SIZE,
+	.flags			= IORESOURCE_MEM,
+};
+
+struct platform_device realview_flash_device = {
+	.name			= "armflash",
+	.id			= 0,
+	.dev			= {
+		.platform_data	= &realview_flash_data,
+	},
+	.num_resources		= 1,
+	.resource		= &realview_flash_resource,
+};
+
+static struct resource realview_smc91x_resources[] = {
+	[0] = {
+		.start		= REALVIEW_ETH_BASE,
+		.end		= REALVIEW_ETH_BASE + SZ_64K - 1,
+		.flags		= IORESOURCE_MEM,
+	},
+	[1] = {
+		.start		= IRQ_ETH,
+		.end		= IRQ_ETH,
+		.flags		= IORESOURCE_IRQ,
+	},
+};
+
+struct platform_device realview_smc91x_device = {
+	.name		= "smc91x",
+	.id		= 0,
+	.num_resources	= ARRAY_SIZE(realview_smc91x_resources),
+	.resource	= realview_smc91x_resources,
+};
+
+#define REALVIEW_SYSMCI	(__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
+
+static unsigned int realview_mmc_status(struct device *dev)
+{
+	struct amba_device *adev = container_of(dev, struct amba_device, dev);
+	u32 mask;
+
+	if (adev->res.start == REALVIEW_MMCI0_BASE)
+		mask = 1;
+	else
+		mask = 2;
+
+	return readl(REALVIEW_SYSMCI) & mask;
+}
+
+struct mmc_platform_data realview_mmc0_plat_data = {
+	.ocr_mask	= MMC_VDD_32_33|MMC_VDD_33_34,
+	.status		= realview_mmc_status,
+};
+
+struct mmc_platform_data realview_mmc1_plat_data = {
+	.ocr_mask	= MMC_VDD_32_33|MMC_VDD_33_34,
+	.status		= realview_mmc_status,
+};
+
+/*
+ * Clock handling
+ */
+static const struct icst307_params realview_oscvco_params = {
+	.ref		= 24000,
+	.vco_max	= 200000,
+	.vd_min		= 4 + 8,
+	.vd_max		= 511 + 8,
+	.rd_min		= 1 + 2,
+	.rd_max		= 127 + 2,
+};
+
+static void realview_oscvco_set(struct clk *clk, struct icst307_vco vco)
+{
+	void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
+	void __iomem *sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC1_OFFSET;
+	u32 val;
+
+	val = readl(sys_osc) & ~0x7ffff;
+	val |= vco.v | (vco.r << 9) | (vco.s << 16);
+
+	writel(0xa05f, sys_lock);
+	writel(val, sys_osc);
+	writel(0, sys_lock);
+}
+
+struct clk realview_clcd_clk = {
+	.name	= "CLCDCLK",
+	.params	= &realview_oscvco_params,
+	.setvco = realview_oscvco_set,
+};
+
+/*
+ * CLCD support.
+ */
+#define SYS_CLCD_MODE_MASK	(3 << 0)
+#define SYS_CLCD_MODE_888	(0 << 0)
+#define SYS_CLCD_MODE_5551	(1 << 0)
+#define SYS_CLCD_MODE_565_RLSB	(2 << 0)
+#define SYS_CLCD_MODE_565_BLSB	(3 << 0)
+#define SYS_CLCD_NLCDIOON	(1 << 2)
+#define SYS_CLCD_VDDPOSSWITCH	(1 << 3)
+#define SYS_CLCD_PWR3V5SWITCH	(1 << 4)
+#define SYS_CLCD_ID_MASK	(0x1f << 8)
+#define SYS_CLCD_ID_SANYO_3_8	(0x00 << 8)
+#define SYS_CLCD_ID_UNKNOWN_8_4	(0x01 << 8)
+#define SYS_CLCD_ID_EPSON_2_2	(0x02 << 8)
+#define SYS_CLCD_ID_SANYO_2_5	(0x07 << 8)
+#define SYS_CLCD_ID_VGA		(0x1f << 8)
+
+static struct clcd_panel vga = {
+	.mode		= {
+		.name		= "VGA",
+		.refresh	= 60,
+		.xres		= 640,
+		.yres		= 480,
+		.pixclock	= 39721,
+		.left_margin	= 40,
+		.right_margin	= 24,
+		.upper_margin	= 32,
+		.lower_margin	= 11,
+		.hsync_len	= 96,
+		.vsync_len	= 2,
+		.sync		= 0,
+		.vmode		= FB_VMODE_NONINTERLACED,
+	},
+	.width		= -1,
+	.height		= -1,
+	.tim2		= TIM2_BCD | TIM2_IPC,
+	.cntl		= CNTL_LCDTFT | CNTL_LCDVCOMP(1),
+	.bpp		= 16,
+};
+
+static struct clcd_panel sanyo_3_8_in = {
+	.mode		= {
+		.name		= "Sanyo QVGA",
+		.refresh	= 116,
+		.xres		= 320,
+		.yres		= 240,
+		.pixclock	= 100000,
+		.left_margin	= 6,
+		.right_margin	= 6,
+		.upper_margin	= 5,
+		.lower_margin	= 5,
+		.hsync_len	= 6,
+		.vsync_len	= 6,
+		.sync		= 0,
+		.vmode		= FB_VMODE_NONINTERLACED,
+	},
+	.width		= -1,
+	.height		= -1,
+	.tim2		= TIM2_BCD,
+	.cntl		= CNTL_LCDTFT | CNTL_LCDVCOMP(1),
+	.bpp		= 16,
+};
+
+static struct clcd_panel sanyo_2_5_in = {
+	.mode		= {
+		.name		= "Sanyo QVGA Portrait",
+		.refresh	= 116,
+		.xres		= 240,
+		.yres		= 320,
+		.pixclock	= 100000,
+		.left_margin	= 20,
+		.right_margin	= 10,
+		.upper_margin	= 2,
+		.lower_margin	= 2,
+		.hsync_len	= 10,
+		.vsync_len	= 2,
+		.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+		.vmode		= FB_VMODE_NONINTERLACED,
+	},
+	.width		= -1,
+	.height		= -1,
+	.tim2		= TIM2_IVS | TIM2_IHS | TIM2_IPC,
+	.cntl		= CNTL_LCDTFT | CNTL_LCDVCOMP(1),
+	.bpp		= 16,
+};
+
+static struct clcd_panel epson_2_2_in = {
+	.mode		= {
+		.name		= "Epson QCIF",
+		.refresh	= 390,
+		.xres		= 176,
+		.yres		= 220,
+		.pixclock	= 62500,
+		.left_margin	= 3,
+		.right_margin	= 2,
+		.upper_margin	= 1,
+		.lower_margin	= 0,
+		.hsync_len	= 3,
+		.vsync_len	= 2,
+		.sync		= 0,
+		.vmode		= FB_VMODE_NONINTERLACED,
+	},
+	.width		= -1,
+	.height		= -1,
+	.tim2		= TIM2_BCD | TIM2_IPC,
+	.cntl		= CNTL_LCDTFT | CNTL_LCDVCOMP(1),
+	.bpp		= 16,
+};
+
+/*
+ * Detect which LCD panel is connected, and return the appropriate
+ * clcd_panel structure.  Note: we do not have any information on
+ * the required timings for the 8.4in panel, so we presently assume
+ * VGA timings.
+ */
+static struct clcd_panel *realview_clcd_panel(void)
+{
+	void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
+	struct clcd_panel *panel = &vga;
+	u32 val;
+
+	val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
+	if (val == SYS_CLCD_ID_SANYO_3_8)
+		panel = &sanyo_3_8_in;
+	else if (val == SYS_CLCD_ID_SANYO_2_5)
+		panel = &sanyo_2_5_in;
+	else if (val == SYS_CLCD_ID_EPSON_2_2)
+		panel = &epson_2_2_in;
+	else if (val == SYS_CLCD_ID_VGA)
+		panel = &vga;
+	else {
+		printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
+			val);
+		panel = &vga;
+	}
+
+	return panel;
+}
+
+/*
+ * Disable all display connectors on the interface module.
+ */
+static void realview_clcd_disable(struct clcd_fb *fb)
+{
+	void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
+	u32 val;
+
+	val = readl(sys_clcd);
+	val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
+	writel(val, sys_clcd);
+}
+
+/*
+ * Enable the relevant connector on the interface module.
+ */
+static void realview_clcd_enable(struct clcd_fb *fb)
+{
+	void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
+	u32 val;
+
+	val = readl(sys_clcd);
+	val &= ~SYS_CLCD_MODE_MASK;
+
+	switch (fb->fb.var.green.length) {
+	case 5:
+		val |= SYS_CLCD_MODE_5551;
+		break;
+	case 6:
+		val |= SYS_CLCD_MODE_565_RLSB;
+		break;
+	case 8:
+		val |= SYS_CLCD_MODE_888;
+		break;
+	}
+
+	/*
+	 * Set the MUX
+	 */
+	writel(val, sys_clcd);
+
+	/*
+	 * And now enable the PSUs
+	 */
+	val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
+	writel(val, sys_clcd);
+}
+
+static unsigned long framesize = SZ_1M;
+
+static int realview_clcd_setup(struct clcd_fb *fb)
+{
+	dma_addr_t dma;
+
+	fb->panel		= realview_clcd_panel();
+
+	fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
+						    &dma, GFP_KERNEL);
+	if (!fb->fb.screen_base) {
+		printk(KERN_ERR "CLCD: unable to map framebuffer\n");
+		return -ENOMEM;
+	}
+
+	fb->fb.fix.smem_start	= dma;
+	fb->fb.fix.smem_len	= framesize;
+
+	return 0;
+}
+
+static int realview_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
+{
+	return dma_mmap_writecombine(&fb->dev->dev, vma,
+				     fb->fb.screen_base,
+				     fb->fb.fix.smem_start,
+				     fb->fb.fix.smem_len);
+}
+
+static void realview_clcd_remove(struct clcd_fb *fb)
+{
+	dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
+			      fb->fb.screen_base, fb->fb.fix.smem_start);
+}
+
+struct clcd_board clcd_plat_data = {
+	.name		= "RealView",
+	.check		= clcdfb_check,
+	.decode		= clcdfb_decode,
+	.disable	= realview_clcd_disable,
+	.enable		= realview_clcd_enable,
+	.setup		= realview_clcd_setup,
+	.mmap		= realview_clcd_mmap,
+	.remove		= realview_clcd_remove,
+};
+
+#ifdef CONFIG_LEDS
+#define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
+
+void realview_leds_event(led_event_t ledevt)
+{
+	unsigned long flags;
+	u32 val;
+
+	local_irq_save(flags);
+	val = readl(VA_LEDS_BASE);
+
+	switch (ledevt) {
+	case led_idle_start:
+		val = val & ~REALVIEW_SYS_LED0;
+		break;
+
+	case led_idle_end:
+		val = val | REALVIEW_SYS_LED0;
+		break;
+
+	case led_timer:
+		val = val ^ REALVIEW_SYS_LED1;
+		break;
+
+	case led_halted:
+		val = 0;
+		break;
+
+	default:
+		break;
+	}
+
+	writel(val, VA_LEDS_BASE);
+	local_irq_restore(flags);
+}
+#endif	/* CONFIG_LEDS */
+
+/*
+ * Where is the timer (VA)?
+ */
+#define TIMER0_VA_BASE		 __io_address(REALVIEW_TIMER0_1_BASE)
+#define TIMER1_VA_BASE		(__io_address(REALVIEW_TIMER0_1_BASE) + 0x20)
+#define TIMER2_VA_BASE		 __io_address(REALVIEW_TIMER2_3_BASE)
+#define TIMER3_VA_BASE		(__io_address(REALVIEW_TIMER2_3_BASE) + 0x20)
+
+/*
+ * How long is the timer interval?
+ */
+#define TIMER_INTERVAL	(TICKS_PER_uSEC * mSEC_10)
+#if TIMER_INTERVAL >= 0x100000
+#define TIMER_RELOAD	(TIMER_INTERVAL >> 8)
+#define TIMER_DIVISOR	(TIMER_CTRL_DIV256)
+#define TICKS2USECS(x)	(256 * (x) / TICKS_PER_uSEC)
+#elif TIMER_INTERVAL >= 0x10000
+#define TIMER_RELOAD	(TIMER_INTERVAL >> 4)		/* Divide by 16 */
+#define TIMER_DIVISOR	(TIMER_CTRL_DIV16)
+#define TICKS2USECS(x)	(16 * (x) / TICKS_PER_uSEC)
+#else
+#define TIMER_RELOAD	(TIMER_INTERVAL)
+#define TIMER_DIVISOR	(TIMER_CTRL_DIV1)
+#define TICKS2USECS(x)	((x) / TICKS_PER_uSEC)
+#endif
+
+/*
+ * Returns number of ms since last clock interrupt.  Note that interrupts
+ * will have been disabled by do_gettimeoffset()
+ */
+static unsigned long realview_gettimeoffset(void)
+{
+	unsigned long ticks1, ticks2, status;
+
+	/*
+	 * Get the current number of ticks.  Note that there is a race
+	 * condition between us reading the timer and checking for
+	 * an interrupt.  We get around this by ensuring that the
+	 * counter has not reloaded between our two reads.
+	 */
+	ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
+	do {
+		ticks1 = ticks2;
+		status = __raw_readl(__io_address(REALVIEW_GIC_DIST_BASE + GIC_DIST_PENDING_SET)
+				     + ((IRQ_TIMERINT0_1 >> 5) << 2));
+		ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
+	} while (ticks2 > ticks1);
+
+	/*
+	 * Number of ticks since last interrupt.
+	 */
+	ticks1 = TIMER_RELOAD - ticks2;
+
+	/*
+	 * Interrupt pending?  If so, we've reloaded once already.
+	 *
+	 * FIXME: Need to check this is effectively timer 0 that expires
+	 */
+	if (status & IRQMASK_TIMERINT0_1)
+		ticks1 += TIMER_RELOAD;
+
+	/*
+	 * Convert the ticks to usecs
+	 */
+	return TICKS2USECS(ticks1);
+}
+
+/*
+ * IRQ handler for the timer
+ */
+static irqreturn_t realview_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+	write_seqlock(&xtime_lock);
+
+	// ...clear the interrupt
+	writel(1, TIMER0_VA_BASE + TIMER_INTCLR);
+
+	timer_tick(regs);
+
+	write_sequnlock(&xtime_lock);
+
+	return IRQ_HANDLED;
+}
+
+static struct irqaction realview_timer_irq = {
+	.name		= "RealView Timer Tick",
+	.flags		= SA_INTERRUPT | SA_TIMER,
+	.handler	= realview_timer_interrupt,
+};
+
+/*
+ * Set up timer interrupt, and return the current time in seconds.
+ */
+static void __init realview_timer_init(void)
+{
+	u32 val;
+
+	/* 
+	 * set clock frequency: 
+	 *	REALVIEW_REFCLK is 32KHz
+	 *	REALVIEW_TIMCLK is 1MHz
+	 */
+	val = readl(__io_address(REALVIEW_SCTL_BASE));
+	writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
+	       (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) | 
+	       (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
+	       (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
+	       __io_address(REALVIEW_SCTL_BASE));
+
+	/*
+	 * Initialise to a known state (all timers off)
+	 */
+	writel(0, TIMER0_VA_BASE + TIMER_CTRL);
+	writel(0, TIMER1_VA_BASE + TIMER_CTRL);
+	writel(0, TIMER2_VA_BASE + TIMER_CTRL);
+	writel(0, TIMER3_VA_BASE + TIMER_CTRL);
+
+	writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_LOAD);
+	writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_VALUE);
+	writel(TIMER_DIVISOR | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC |
+	       TIMER_CTRL_IE, TIMER0_VA_BASE + TIMER_CTRL);
+
+	/* 
+	 * Make irqs happen for the system timer
+	 */
+	setup_irq(IRQ_TIMERINT0_1, &realview_timer_irq);
+}
+
+struct sys_timer realview_timer = {
+	.init		= realview_timer_init,
+	.offset		= realview_gettimeoffset,
+};

+ 118 - 0
arch/arm/mach-realview/core.h

@@ -0,0 +1,118 @@
+/*
+ *  linux/arch/arm/mach-realview/core.h
+ *
+ *  Copyright (C) 2004 ARM Limited
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *
+ * 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
+ */
+
+#ifndef __ASM_ARCH_REALVIEW_H
+#define __ASM_ARCH_REALVIEW_H
+
+#include <asm/hardware/amba.h>
+#include <asm/io.h>
+
+#define __io_address(n)		__io(IO_ADDRESS(n))
+
+extern struct sys_timer realview_timer;
+
+#define AMBA_DEVICE(name,busid,base,plat)			\
+static struct amba_device name##_device = {			\
+	.dev		= {					\
+		.coherent_dma_mask = ~0,			\
+		.bus_id	= busid,				\
+		.platform_data = plat,				\
+	},							\
+	.res		= {					\
+		.start	= REALVIEW_##base##_BASE,		\
+		.end	= (REALVIEW_##base##_BASE) + SZ_4K - 1,\
+		.flags	= IORESOURCE_MEM,			\
+	},							\
+	.dma_mask	= ~0,					\
+	.irq		= base##_IRQ,				\
+	/* .dma		= base##_DMA,*/				\
+}
+
+/*
+ * These devices are connected via the core APB bridge
+ */
+#define GPIO2_IRQ	{ IRQ_GPIOINT2, NO_IRQ }
+#define GPIO2_DMA	{ 0, 0 }
+#define GPIO3_IRQ	{ IRQ_GPIOINT3, NO_IRQ }
+#define GPIO3_DMA	{ 0, 0 }
+
+#define AACI_IRQ	{ IRQ_AACI, NO_IRQ }
+#define AACI_DMA	{ 0x80, 0x81 }
+#define MMCI0_IRQ	{ IRQ_MMCI0A,IRQ_MMCI0B }
+#define MMCI0_DMA	{ 0x84, 0 }
+#define KMI0_IRQ	{ IRQ_KMI0, NO_IRQ }
+#define KMI0_DMA	{ 0, 0 }
+#define KMI1_IRQ	{ IRQ_KMI1, NO_IRQ }
+#define KMI1_DMA	{ 0, 0 }
+
+/*
+ * These devices are connected directly to the multi-layer AHB switch
+ */
+#define SMC_IRQ		{ NO_IRQ, NO_IRQ }
+#define SMC_DMA		{ 0, 0 }
+#define MPMC_IRQ	{ NO_IRQ, NO_IRQ }
+#define MPMC_DMA	{ 0, 0 }
+#define CLCD_IRQ	{ IRQ_CLCDINT, NO_IRQ }
+#define CLCD_DMA	{ 0, 0 }
+#define DMAC_IRQ	{ IRQ_DMAINT, NO_IRQ }
+#define DMAC_DMA	{ 0, 0 }
+
+/*
+ * These devices are connected via the core APB bridge
+ */
+#define SCTL_IRQ	{ NO_IRQ, NO_IRQ }
+#define SCTL_DMA	{ 0, 0 }
+#define WATCHDOG_IRQ	{ IRQ_WDOGINT, NO_IRQ }
+#define WATCHDOG_DMA	{ 0, 0 }
+#define GPIO0_IRQ	{ IRQ_GPIOINT0, NO_IRQ }
+#define GPIO0_DMA	{ 0, 0 }
+#define GPIO1_IRQ	{ IRQ_GPIOINT1, NO_IRQ }
+#define GPIO1_DMA	{ 0, 0 }
+#define RTC_IRQ		{ IRQ_RTCINT, NO_IRQ }
+#define RTC_DMA		{ 0, 0 }
+
+/*
+ * These devices are connected via the DMA APB bridge
+ */
+#define SCI_IRQ		{ IRQ_SCIINT, NO_IRQ }
+#define SCI_DMA		{ 7, 6 }
+#define UART0_IRQ	{ IRQ_UARTINT0, NO_IRQ }
+#define UART0_DMA	{ 15, 14 }
+#define UART1_IRQ	{ IRQ_UARTINT1, NO_IRQ }
+#define UART1_DMA	{ 13, 12 }
+#define UART2_IRQ	{ IRQ_UARTINT2, NO_IRQ }
+#define UART2_DMA	{ 11, 10 }
+#define UART3_IRQ	{ IRQ_UART3, NO_IRQ }
+#define UART3_DMA	{ 0x86, 0x87 }
+#define SSP_IRQ		{ IRQ_SSPINT, NO_IRQ }
+#define SSP_DMA		{ 9, 8 }
+
+
+extern struct platform_device realview_flash_device;
+extern struct platform_device realview_smc91x_device;
+extern struct mmc_platform_data realview_mmc0_plat_data;
+extern struct mmc_platform_data realview_mmc1_plat_data;
+extern struct clk realview_clcd_clk;
+extern struct clcd_board clcd_plat_data;
+
+extern void realview_leds_event(led_event_t ledevt);
+
+#endif

+ 172 - 0
arch/arm/mach-realview/realview_eb.c

@@ -0,0 +1,172 @@
+/*
+ *  linux/arch/arm/mach-realview/realview_eb.c
+ *
+ *  Copyright (C) 2004 ARM Limited
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *
+ * 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 <linux/config.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/sysdev.h>
+
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/leds.h>
+#include <asm/mach-types.h>
+#include <asm/hardware/gic.h>
+#include <asm/hardware/amba.h>
+#include <asm/hardware/icst307.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/mmc.h>
+
+#include <asm/arch/irqs.h>
+
+#include "core.h"
+#include "clock.h"
+
+static struct map_desc realview_eb_io_desc[] __initdata = {
+	{
+		.virtual	= IO_ADDRESS(REALVIEW_SYS_BASE),
+		.pfn		= __phys_to_pfn(REALVIEW_SYS_BASE),
+		.length		= SZ_4K,
+		.type		= MT_DEVICE,
+	}, {
+		.virtual	= IO_ADDRESS(REALVIEW_GIC_CPU_BASE),
+		.pfn		= __phys_to_pfn(REALVIEW_GIC_CPU_BASE),
+		.length		= SZ_4K,
+		.type		= MT_DEVICE,
+	}, {
+		.virtual	= IO_ADDRESS(REALVIEW_GIC_DIST_BASE),
+		.pfn		= __phys_to_pfn(REALVIEW_GIC_DIST_BASE),
+		.length		= SZ_4K,
+		.type		= MT_DEVICE,
+	}, {
+		.virtual	= IO_ADDRESS(REALVIEW_SCTL_BASE),
+		.pfn		= __phys_to_pfn(REALVIEW_SCTL_BASE),
+		.length		= SZ_4K,
+		.type		= MT_DEVICE,
+	}, {
+		.virtual	= IO_ADDRESS(REALVIEW_TIMER0_1_BASE),
+		.pfn		= __phys_to_pfn(REALVIEW_TIMER0_1_BASE),
+		.length		= SZ_4K,
+		.type		= MT_DEVICE,
+	}, {
+		.virtual	= IO_ADDRESS(REALVIEW_TIMER2_3_BASE),
+		.pfn		= __phys_to_pfn(REALVIEW_TIMER2_3_BASE),
+		.length		= SZ_4K,
+		.type		= MT_DEVICE,
+	},
+#ifdef CONFIG_DEBUG_LL
+	{
+		.virtual	= IO_ADDRESS(REALVIEW_UART0_BASE),
+		.pfn		= __phys_to_pfn(REALVIEW_UART0_BASE),
+		.length		= SZ_4K,
+		.type		= MT_DEVICE,
+	}
+#endif
+};
+
+static void __init realview_eb_map_io(void)
+{
+	iotable_init(realview_eb_io_desc, ARRAY_SIZE(realview_eb_io_desc));
+}
+
+/* FPGA Primecells */
+AMBA_DEVICE(aaci,  "fpga:04", AACI,     NULL);
+AMBA_DEVICE(mmc0,  "fpga:05", MMCI0,    &realview_mmc0_plat_data);
+AMBA_DEVICE(kmi0,  "fpga:06", KMI0,     NULL);
+AMBA_DEVICE(kmi1,  "fpga:07", KMI1,     NULL);
+AMBA_DEVICE(uart3, "fpga:09", UART3,    NULL);
+
+/* DevChip Primecells */
+AMBA_DEVICE(smc,   "dev:00",  SMC,      NULL);
+AMBA_DEVICE(clcd,  "dev:20",  CLCD,     &clcd_plat_data);
+AMBA_DEVICE(dmac,  "dev:30",  DMAC,     NULL);
+AMBA_DEVICE(sctl,  "dev:e0",  SCTL,     NULL);
+AMBA_DEVICE(wdog,  "dev:e1",  WATCHDOG, NULL);
+AMBA_DEVICE(gpio0, "dev:e4",  GPIO0,    NULL);
+AMBA_DEVICE(gpio1, "dev:e5",  GPIO1,    NULL);
+AMBA_DEVICE(gpio2, "dev:e6",  GPIO2,    NULL);
+AMBA_DEVICE(rtc,   "dev:e8",  RTC,      NULL);
+AMBA_DEVICE(sci0,  "dev:f0",  SCI,      NULL);
+AMBA_DEVICE(uart0, "dev:f1",  UART0,    NULL);
+AMBA_DEVICE(uart1, "dev:f2",  UART1,    NULL);
+AMBA_DEVICE(uart2, "dev:f3",  UART2,    NULL);
+AMBA_DEVICE(ssp0,  "dev:f4",  SSP,      NULL);
+
+static struct amba_device *amba_devs[] __initdata = {
+	&dmac_device,
+	&uart0_device,
+	&uart1_device,
+	&uart2_device,
+	&uart3_device,
+	&smc_device,
+	&clcd_device,
+	&sctl_device,
+	&wdog_device,
+	&gpio0_device,
+	&gpio1_device,
+	&gpio2_device,
+	&rtc_device,
+	&sci0_device,
+	&ssp0_device,
+	&aaci_device,
+	&mmc0_device,
+	&kmi0_device,
+	&kmi1_device,
+};
+
+static void __init gic_init_irq(void)
+{
+	gic_dist_init(__io_address(REALVIEW_GIC_DIST_BASE));
+	gic_cpu_init(__io_address(REALVIEW_GIC_CPU_BASE));
+}
+
+static void __init realview_eb_init(void)
+{
+	int i;
+
+	clk_register(&realview_clcd_clk);
+
+	platform_device_register(&realview_flash_device);
+	platform_device_register(&realview_smc91x_device);
+
+	for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
+		struct amba_device *d = amba_devs[i];
+		amba_device_register(d, &iomem_resource);
+	}
+
+#ifdef CONFIG_LEDS
+	leds_event = realview_leds_event;
+#endif
+}
+
+MACHINE_START(REALVIEW_EB, "ARM-RealView EB")
+	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
+	.phys_ram	= 0x00000000,
+	.phys_io	= REALVIEW_UART0_BASE,
+	.io_pg_offst	= (IO_ADDRESS(REALVIEW_UART0_BASE) >> 18) & 0xfffc,
+	.boot_params	= 0x00000100,
+	.map_io		= realview_eb_map_io,
+	.init_irq	= gic_init_irq,
+	.timer		= &realview_timer,
+	.init_machine	= realview_eb_init,
+MACHINE_END

+ 66 - 4
arch/arm/mach-s3c2410/mach-rx3715.c

@@ -17,6 +17,7 @@
  *	10-Mar-2005 LCVR Changed S3C2410_VA to S3C24XX_VA
  *	10-Mar-2005 LCVR Changed S3C2410_VA to S3C24XX_VA
  *	14-Mar-2005 BJD  Fixed __iomem warnings
  *	14-Mar-2005 BJD  Fixed __iomem warnings
  *	20-Sep-2005 BJD  Added static to non-exported items
  *	20-Sep-2005 BJD  Added static to non-exported items
+ *	31-Oct-2005 BJD  Added LCD setup for framebuffer
 */
 */
 
 
 #include <linux/kernel.h>
 #include <linux/kernel.h>
@@ -43,6 +44,9 @@
 
 
 #include <asm/arch/regs-serial.h>
 #include <asm/arch/regs-serial.h>
 #include <asm/arch/regs-gpio.h>
 #include <asm/arch/regs-gpio.h>
+#include <asm/arch/regs-lcd.h>
+
+#include <asm/arch/fb.h>
 
 
 #include "clock.h"
 #include "clock.h"
 #include "devs.h"
 #include "devs.h"
@@ -97,6 +101,66 @@ static struct s3c2410_uartcfg rx3715_uartcfgs[] = {
 	}
 	}
 };
 };
 
 
+/* framebuffer lcd controller information */
+
+static struct s3c2410fb_mach_info rx3715_lcdcfg __initdata = {
+	.regs	= {
+		.lcdcon1 =	S3C2410_LCDCON1_TFT16BPP | \
+				S3C2410_LCDCON1_TFT | \
+				S3C2410_LCDCON1_CLKVAL(0x0C),
+
+		.lcdcon2 =	S3C2410_LCDCON2_VBPD(5) | \
+				S3C2410_LCDCON2_LINEVAL(319) | \
+				S3C2410_LCDCON2_VFPD(6) | \
+				S3C2410_LCDCON2_VSPW(2),
+
+		.lcdcon3 =	S3C2410_LCDCON3_HBPD(35) | \
+				S3C2410_LCDCON3_HOZVAL(239) | \
+				S3C2410_LCDCON3_HFPD(35),
+
+		.lcdcon4 =	S3C2410_LCDCON4_MVAL(0) | \
+				S3C2410_LCDCON4_HSPW(7),
+
+		.lcdcon5 =	S3C2410_LCDCON5_INVVLINE |
+				S3C2410_LCDCON5_FRM565 |
+				S3C2410_LCDCON5_HWSWP,
+	},
+
+	.lpcsel =	0xf82,
+
+	.gpccon =	0xaa955699,
+	.gpccon_mask =	0xffc003cc,
+	.gpcup =	0x0000ffff,
+	.gpcup_mask =	0xffffffff,
+
+	.gpdcon =	0xaa95aaa1,
+	.gpdcon_mask =	0xffc0fff0,
+	.gpdup =	0x0000faff,
+	.gpdup_mask =	0xffffffff,
+
+	.fixed_syncs =	1,
+	.width  =	240,
+	.height =	320,
+
+	.xres	= {
+		.min =		240,
+		.max =		240,
+		.defval =	240,
+	},
+
+	.yres	= {
+		.max =		320,
+		.min =		320,
+		.defval	=	320,
+	},
+
+	.bpp	= {
+		.min =		16,
+		.max =		16,
+		.defval =	16,
+	},
+};
+
 static struct platform_device *rx3715_devices[] __initdata = {
 static struct platform_device *rx3715_devices[] __initdata = {
 	&s3c_device_usb,
 	&s3c_device_usb,
 	&s3c_device_lcd,
 	&s3c_device_lcd,
@@ -123,14 +187,12 @@ static void __init rx3715_init_irq(void)
 	s3c24xx_init_irq();
 	s3c24xx_init_irq();
 }
 }
 
 
-#ifdef CONFIG_PM
 static void __init rx3715_init_machine(void)
 static void __init rx3715_init_machine(void)
 {
 {
 	s3c2410_pm_init();
 	s3c2410_pm_init();
+	s3c24xx_fb_set_platdata(&rx3715_lcdcfg);
 }
 }
-#else
-#define rx3715_init_machine NULL
-#endif
+
 
 
 MACHINE_START(RX3715, "IPAQ-RX3715")
 MACHINE_START(RX3715, "IPAQ-RX3715")
 	/* Maintainer: Ben Dooks <ben@fluff.org> */
 	/* Maintainer: Ben Dooks <ben@fluff.org> */

+ 3 - 3
arch/arm/mm/Kconfig

@@ -120,8 +120,8 @@ config CPU_ARM925T
 
 
 # ARM926T
 # ARM926T
 config CPU_ARM926T
 config CPU_ARM926T
-	bool "Support ARM926T processor" if ARCH_INTEGRATOR
-	depends on ARCH_INTEGRATOR || ARCH_VERSATILE_PB || MACH_VERSATILE_AB || ARCH_OMAP730 || ARCH_OMAP16XX
+	bool "Support ARM926T processor"
+	depends on ARCH_INTEGRATOR || ARCH_VERSATILE_PB || MACH_VERSATILE_AB || ARCH_OMAP730 || ARCH_OMAP16XX || MACH_REALVIEW_EB
 	default y if ARCH_VERSATILE_PB || MACH_VERSATILE_AB || ARCH_OMAP730 || ARCH_OMAP16XX
 	default y if ARCH_VERSATILE_PB || MACH_VERSATILE_AB || ARCH_OMAP730 || ARCH_OMAP16XX
 	select CPU_32v5
 	select CPU_32v5
 	select CPU_ABRT_EV5TJ
 	select CPU_ABRT_EV5TJ
@@ -242,7 +242,7 @@ config CPU_XSCALE
 # ARMv6
 # ARMv6
 config CPU_V6
 config CPU_V6
 	bool "Support ARM V6 processor"
 	bool "Support ARM V6 processor"
-	depends on ARCH_INTEGRATOR
+	depends on ARCH_INTEGRATOR || MACH_REALVIEW_EB
 	select CPU_32v6
 	select CPU_32v6
 	select CPU_ABRT_EV6
 	select CPU_ABRT_EV6
 	select CPU_CACHE_V6
 	select CPU_CACHE_V6

+ 8 - 1
arch/arm/mm/init.c

@@ -486,10 +486,17 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
 
 
 	/*
 	/*
 	 * Ask the machine support to map in the statically mapped devices.
 	 * Ask the machine support to map in the statically mapped devices.
-	 * After this point, we can start to touch devices again.
 	 */
 	 */
 	if (mdesc->map_io)
 	if (mdesc->map_io)
 		mdesc->map_io();
 		mdesc->map_io();
+
+	/*
+	 * Finally flush the tlb again - this ensures that we're in a
+	 * consistent state wrt the writebuffer if the writebuffer needs
+	 * draining.  After this point, we can start to touch devices
+	 * again.
+	 */
+	local_flush_tlb_all();
 }
 }
 
 
 /*
 /*

+ 16 - 61
arch/i386/kernel/apic.c

@@ -803,7 +803,6 @@ no_apic:
 
 
 void __init init_apic_mappings(void)
 void __init init_apic_mappings(void)
 {
 {
-	unsigned int orig_apicid;
 	unsigned long apic_phys;
 	unsigned long apic_phys;
 
 
 	/*
 	/*
@@ -825,11 +824,8 @@ void __init init_apic_mappings(void)
 	 * Fetch the APIC ID of the BSP in case we have a
 	 * Fetch the APIC ID of the BSP in case we have a
 	 * default configuration (or the MP table is broken).
 	 * default configuration (or the MP table is broken).
 	 */
 	 */
-	orig_apicid = boot_cpu_physical_apicid;
-	boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
-	if ((orig_apicid != -1U) && (orig_apicid != boot_cpu_physical_apicid))
-		printk(KERN_WARNING "Boot APIC ID in local APIC unexpected (%d vs %d)",
-			orig_apicid, boot_cpu_physical_apicid);
+	if (boot_cpu_physical_apicid == -1U)
+		boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
 
 
 #ifdef CONFIG_X86_IO_APIC
 #ifdef CONFIG_X86_IO_APIC
 	{
 	{
@@ -1259,81 +1255,40 @@ fastcall void smp_error_interrupt(struct pt_regs *regs)
 }
 }
 
 
 /*
 /*
- * This initializes the IO-APIC and APIC hardware.
+ * This initializes the IO-APIC and APIC hardware if this is
+ * a UP kernel.
  */
  */
-int __init APIC_init(void)
+int __init APIC_init_uniprocessor (void)
 {
 {
-	if (enable_local_apic < 0) {
-		printk(KERN_INFO "APIC disabled\n");
-		return -1;
-	}
+	if (enable_local_apic < 0)
+		clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
 
 
-	/* See if we have a SMP configuration or have forced enabled
-	 * the local apic.
-	 */
-	if (!smp_found_config && !acpi_lapic && !cpu_has_apic) {
-		enable_local_apic = -1;
+	if (!smp_found_config && !cpu_has_apic)
 		return -1;
 		return -1;
-	}
 
 
 	/*
 	/*
-	 * Complain if the BIOS pretends there is an apic.
-	 * Then get out because we don't have an a local apic.
+	 * Complain if the BIOS pretends there is one.
 	 */
 	 */
 	if (!cpu_has_apic && APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
 	if (!cpu_has_apic && APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
 		printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
 		printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
 			boot_cpu_physical_apicid);
 			boot_cpu_physical_apicid);
-		printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
-		enable_local_apic = -1;
 		return -1;
 		return -1;
 	}
 	}
 
 
 	verify_local_APIC();
 	verify_local_APIC();
 
 
-	/*
-	 * Should not be necessary because the MP table should list the boot
-	 * CPU too, but we do it for the sake of robustness anyway.
-	 * Makes no sense to do this check in clustered apic mode, so skip it
-	 */
-	if (!check_phys_apicid_present(boot_cpu_physical_apicid)) {
-		printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
-				boot_cpu_physical_apicid);
-		physid_set(boot_cpu_physical_apicid, phys_cpu_present_map);
-	}
-
-	/*
-	 * Switch from PIC to APIC mode.
-	 */
 	connect_bsp_APIC();
 	connect_bsp_APIC();
-	setup_local_APIC();
 
 
-#ifdef CONFIG_X86_IO_APIC
-	/*
-	 * Now start the IO-APICs
-	 */
-	if (smp_found_config && !skip_ioapic_setup && nr_ioapics)
-		setup_IO_APIC();
-#endif
-	return 0;
-}
+	phys_cpu_present_map = physid_mask_of_physid(boot_cpu_physical_apicid);
 
 
-void __init APIC_late_time_init(void)
-{
-	/* Improve our loops per jiffy estimate */
-	loops_per_jiffy = ((1000 + HZ - 1)/HZ)*cpu_khz;
-	boot_cpu_data.loops_per_jiffy = loops_per_jiffy;
-	cpu_data[0].loops_per_jiffy = loops_per_jiffy;
-
-	/* setup_apic_nmi_watchdog doesn't work properly before cpu_khz is
-	 * initialized.  So redo it here to ensure the boot cpu is setup
-	 * properly.
-	 */
-	if (nmi_watchdog == NMI_LOCAL_APIC)
-		setup_apic_nmi_watchdog();
+	setup_local_APIC();
 
 
 #ifdef CONFIG_X86_IO_APIC
 #ifdef CONFIG_X86_IO_APIC
-	if (smp_found_config && !skip_ioapic_setup && nr_ioapics)
-		IO_APIC_late_time_init();
+	if (smp_found_config)
+		if (!skip_ioapic_setup && nr_ioapics)
+			setup_IO_APIC();
 #endif
 #endif
 	setup_boot_APIC_clock();
 	setup_boot_APIC_clock();
+
+	return 0;
 }
 }

+ 0 - 4
arch/i386/kernel/i8259.c

@@ -435,8 +435,4 @@ void __init init_IRQ(void)
 		setup_irq(FPU_IRQ, &fpu_irq);
 		setup_irq(FPU_IRQ, &fpu_irq);
 
 
 	irq_ctx_init(smp_processor_id());
 	irq_ctx_init(smp_processor_id());
-
-#ifdef CONFIG_X86_LOCAL_APIC
-	APIC_init();
-#endif
 }
 }

+ 1 - 5
arch/i386/kernel/io_apic.c

@@ -2387,15 +2387,11 @@ void __init setup_IO_APIC(void)
 	sync_Arb_IDs();
 	sync_Arb_IDs();
 	setup_IO_APIC_irqs();
 	setup_IO_APIC_irqs();
 	init_IO_APIC_traps();
 	init_IO_APIC_traps();
+	check_timer();
 	if (!acpi_ioapic)
 	if (!acpi_ioapic)
 		print_IO_APIC();
 		print_IO_APIC();
 }
 }
 
 
-void __init IO_APIC_late_time_init(void)
-{
-	check_timer();
-}
-
 /*
 /*
  *	Called after all the initialization is done. If we didnt find any
  *	Called after all the initialization is done. If we didnt find any
  *	APIC bugs then we can allow the modify fast path
  *	APIC bugs then we can allow the modify fast path

+ 52 - 16
arch/i386/kernel/smpboot.c

@@ -1078,16 +1078,6 @@ void *xquad_portio;
 EXPORT_SYMBOL(xquad_portio);
 EXPORT_SYMBOL(xquad_portio);
 #endif
 #endif
 
 
-/*
- * Fall back to non SMP mode after errors.
- *
- */
-static __init void disable_smp(void)
-{
-	cpu_set(0, cpu_sibling_map[0]);
-	cpu_set(0, cpu_core_map[0]);
-}
-
 static void __init smp_boot_cpus(unsigned int max_cpus)
 static void __init smp_boot_cpus(unsigned int max_cpus)
 {
 {
 	int apicid, cpu, bit, kicked;
 	int apicid, cpu, bit, kicked;
@@ -1100,6 +1090,7 @@ static void __init smp_boot_cpus(unsigned int max_cpus)
 	printk("CPU%d: ", 0);
 	printk("CPU%d: ", 0);
 	print_cpu_info(&cpu_data[0]);
 	print_cpu_info(&cpu_data[0]);
 
 
+	boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
 	boot_cpu_logical_apicid = logical_smp_processor_id();
 	boot_cpu_logical_apicid = logical_smp_processor_id();
 	x86_cpu_to_apicid[0] = boot_cpu_physical_apicid;
 	x86_cpu_to_apicid[0] = boot_cpu_physical_apicid;
 
 
@@ -1111,27 +1102,68 @@ static void __init smp_boot_cpus(unsigned int max_cpus)
 	cpus_clear(cpu_core_map[0]);
 	cpus_clear(cpu_core_map[0]);
 	cpu_set(0, cpu_core_map[0]);
 	cpu_set(0, cpu_core_map[0]);
 
 
-	map_cpu_to_logical_apicid();
-
 	/*
 	/*
 	 * If we couldn't find an SMP configuration at boot time,
 	 * If we couldn't find an SMP configuration at boot time,
 	 * get out of here now!
 	 * get out of here now!
 	 */
 	 */
 	if (!smp_found_config && !acpi_lapic) {
 	if (!smp_found_config && !acpi_lapic) {
 		printk(KERN_NOTICE "SMP motherboard not detected.\n");
 		printk(KERN_NOTICE "SMP motherboard not detected.\n");
-		disable_smp();
+		smpboot_clear_io_apic_irqs();
+		phys_cpu_present_map = physid_mask_of_physid(0);
+		if (APIC_init_uniprocessor())
+			printk(KERN_NOTICE "Local APIC not detected."
+					   " Using dummy APIC emulation.\n");
+		map_cpu_to_logical_apicid();
+		cpu_set(0, cpu_sibling_map[0]);
+		cpu_set(0, cpu_core_map[0]);
+		return;
+	}
+
+	/*
+	 * Should not be necessary because the MP table should list the boot
+	 * CPU too, but we do it for the sake of robustness anyway.
+	 * Makes no sense to do this check in clustered apic mode, so skip it
+	 */
+	if (!check_phys_apicid_present(boot_cpu_physical_apicid)) {
+		printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
+				boot_cpu_physical_apicid);
+		physid_set(hard_smp_processor_id(), phys_cpu_present_map);
+	}
+
+	/*
+	 * If we couldn't find a local APIC, then get out of here now!
+	 */
+	if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) && !cpu_has_apic) {
+		printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
+			boot_cpu_physical_apicid);
+		printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
+		smpboot_clear_io_apic_irqs();
+		phys_cpu_present_map = physid_mask_of_physid(0);
+		cpu_set(0, cpu_sibling_map[0]);
+		cpu_set(0, cpu_core_map[0]);
 		return;
 		return;
 	}
 	}
 
 
+	verify_local_APIC();
+
 	/*
 	/*
 	 * If SMP should be disabled, then really disable it!
 	 * If SMP should be disabled, then really disable it!
 	 */
 	 */
-	if (!max_cpus || (enable_local_apic < 0)) {
-		printk(KERN_INFO "SMP mode deactivated.\n");
-		disable_smp();
+	if (!max_cpus) {
+		smp_found_config = 0;
+		printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
+		smpboot_clear_io_apic_irqs();
+		phys_cpu_present_map = physid_mask_of_physid(0);
+		cpu_set(0, cpu_sibling_map[0]);
+		cpu_set(0, cpu_core_map[0]);
 		return;
 		return;
 	}
 	}
 
 
+	connect_bsp_APIC();
+	setup_local_APIC();
+	map_cpu_to_logical_apicid();
+
+
 	setup_portio_remap();
 	setup_portio_remap();
 
 
 	/*
 	/*
@@ -1212,6 +1244,10 @@ static void __init smp_boot_cpus(unsigned int max_cpus)
 	cpu_set(0, cpu_sibling_map[0]);
 	cpu_set(0, cpu_sibling_map[0]);
 	cpu_set(0, cpu_core_map[0]);
 	cpu_set(0, cpu_core_map[0]);
 
 
+	smpboot_setup_io_apic();
+
+	setup_boot_APIC_clock();
+
 	/*
 	/*
 	 * Synchronize the TSC with the AP
 	 * Synchronize the TSC with the AP
 	 */
 	 */

+ 1 - 11
arch/i386/kernel/time.c

@@ -440,8 +440,8 @@ static int time_init_device(void)
 
 
 device_initcall(time_init_device);
 device_initcall(time_init_device);
 
 
-extern void (*late_time_init)(void);
 #ifdef CONFIG_HPET_TIMER
 #ifdef CONFIG_HPET_TIMER
+extern void (*late_time_init)(void);
 /* Duplicate of time_init() below, with hpet_enable part added */
 /* Duplicate of time_init() below, with hpet_enable part added */
 static void __init hpet_time_init(void)
 static void __init hpet_time_init(void)
 {
 {
@@ -458,11 +458,6 @@ static void __init hpet_time_init(void)
 	printk(KERN_INFO "Using %s for high-res timesource\n",cur_timer->name);
 	printk(KERN_INFO "Using %s for high-res timesource\n",cur_timer->name);
 
 
 	time_init_hook();
 	time_init_hook();
-
-#ifdef CONFIG_X86_LOCAL_APIC
-	if (enable_local_apic >= 0)
-		APIC_late_time_init();
-#endif
 }
 }
 #endif
 #endif
 
 
@@ -487,9 +482,4 @@ void __init time_init(void)
 	printk(KERN_INFO "Using %s for high-res timesource\n",cur_timer->name);
 	printk(KERN_INFO "Using %s for high-res timesource\n",cur_timer->name);
 
 
 	time_init_hook();
 	time_init_hook();
-
-#ifdef CONFIG_X86_LOCAL_APIC
-	if (enable_local_apic >= 0)
-		late_time_init = APIC_late_time_init;
-#endif
 }
 }

+ 1 - 1
arch/i386/pci/fixup.c

@@ -398,7 +398,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pci_fixup_video);
  */
  */
 static u16 toshiba_line_size;
 static u16 toshiba_line_size;
 
 
-static struct dmi_system_id __devinit toshiba_ohci1394_dmi_table[] = {
+static struct dmi_system_id __devinitdata toshiba_ohci1394_dmi_table[] = {
 	{
 	{
 		.ident = "Toshiba PS5 based laptop",
 		.ident = "Toshiba PS5 based laptop",
 		.matches = {
 		.matches = {

+ 4 - 0
arch/ia64/Kconfig

@@ -26,6 +26,10 @@ config MMU
 	bool
 	bool
 	default y
 	default y
 
 
+config SWIOTLB
+       bool
+       default y
+
 config RWSEM_XCHGADD_ALGORITHM
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 	bool
 	default y
 	default y

+ 1 - 1
arch/ia64/lib/Makefile

@@ -9,7 +9,7 @@ lib-y := __divsi3.o __udivsi3.o __modsi3.o __umodsi3.o			\
 	bitop.o checksum.o clear_page.o csum_partial_copy.o		\
 	bitop.o checksum.o clear_page.o csum_partial_copy.o		\
 	clear_user.o strncpy_from_user.o strlen_user.o strnlen_user.o	\
 	clear_user.o strncpy_from_user.o strlen_user.o strnlen_user.o	\
 	flush.o ip_fast_csum.o do_csum.o				\
 	flush.o ip_fast_csum.o do_csum.o				\
-	memset.o strlen.o swiotlb.o
+	memset.o strlen.o
 
 
 lib-$(CONFIG_ITANIUM)	+= copy_page.o copy_user.o memcpy.o
 lib-$(CONFIG_ITANIUM)	+= copy_page.o copy_user.o memcpy.o
 lib-$(CONFIG_MCKINLEY)	+= copy_page_mck.o memcpy_mck.o
 lib-$(CONFIG_MCKINLEY)	+= copy_page_mck.o memcpy_mck.o

+ 1 - 2
arch/m68knommu/defconfig

@@ -99,7 +99,7 @@ CONFIG_M5272C3=y
 # CONFIG_NETtel is not set
 # CONFIG_NETtel is not set
 # CONFIG_CPU16B is not set
 # CONFIG_CPU16B is not set
 # CONFIG_MOD5272 is not set
 # CONFIG_MOD5272 is not set
-CONFIG_MOTOROLA=y
+CONFIG_FREESCALE=y
 # CONFIG_LARGE_ALLOCS is not set
 # CONFIG_LARGE_ALLOCS is not set
 CONFIG_4KSTACKS=y
 CONFIG_4KSTACKS=y
 CONFIG_RAMAUTO=y
 CONFIG_RAMAUTO=y
@@ -554,7 +554,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_XFS_FS is not set
 # CONFIG_XFS_FS is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_MINIX_FS is not set
 CONFIG_ROMFS_FS=y
 CONFIG_ROMFS_FS=y
-CONFIG_MAGIC_ROM_PTR=y
 # CONFIG_INOTIFY is not set
 # CONFIG_INOTIFY is not set
 # CONFIG_QUOTA is not set
 # CONFIG_QUOTA is not set
 # CONFIG_DNOTIFY is not set
 # CONFIG_DNOTIFY is not set

+ 1 - 1
arch/powerpc/kernel/entry_64.S

@@ -279,7 +279,7 @@ _GLOBAL(ppc32_rt_sigsuspend)
 	bne	syscall_exit
 	bne	syscall_exit
 	/* If sigsuspend() returns zero, we are going into a signal handler. We
 	/* If sigsuspend() returns zero, we are going into a signal handler. We
 	   may need to call audit_syscall_exit() to mark the exit from sigsuspend() */
 	   may need to call audit_syscall_exit() to mark the exit from sigsuspend() */
-#ifdef CONFIG_AUDIT
+#ifdef CONFIG_AUDITSYSCALL
 	ld	r3,PACACURRENT(r13)
 	ld	r3,PACACURRENT(r13)
 	ld	r4,AUDITCONTEXT(r3)
 	ld	r4,AUDITCONTEXT(r3)
 	cmpdi	0,r4,0
 	cmpdi	0,r4,0

+ 5 - 4
arch/um/include/net_kern.h

@@ -6,10 +6,11 @@
 #ifndef __UM_NET_KERN_H
 #ifndef __UM_NET_KERN_H
 #define __UM_NET_KERN_H
 #define __UM_NET_KERN_H
 
 
-#include "linux/netdevice.h"
-#include "linux/skbuff.h"
-#include "linux/socket.h"
-#include "linux/list.h"
+#include <linux/netdevice.h>
+#include <linux/platform_device.h>
+#include <linux/skbuff.h>
+#include <linux/socket.h>
+#include <linux/list.h>
 
 
 struct uml_net {
 struct uml_net {
 	struct list_head list;
 	struct list_head list;

+ 0 - 2
arch/x86_64/kernel/Makefile

@@ -27,7 +27,6 @@ obj-$(CONFIG_CPU_FREQ)		+= cpufreq/
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 obj-$(CONFIG_GART_IOMMU)	+= pci-gart.o aperture.o
 obj-$(CONFIG_GART_IOMMU)	+= pci-gart.o aperture.o
 obj-$(CONFIG_DUMMY_IOMMU)	+= pci-nommu.o pci-dma.o
 obj-$(CONFIG_DUMMY_IOMMU)	+= pci-nommu.o pci-dma.o
-obj-$(CONFIG_SWIOTLB)		+= swiotlb.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
 obj-$(CONFIG_X86_PM_TIMER)	+= pmtimer.o
 obj-$(CONFIG_X86_PM_TIMER)	+= pmtimer.o
 
 
@@ -41,7 +40,6 @@ CFLAGS_vsyscall.o		:= $(PROFILING) -g0
 bootflag-y			+= ../../i386/kernel/bootflag.o
 bootflag-y			+= ../../i386/kernel/bootflag.o
 cpuid-$(subst m,y,$(CONFIG_X86_CPUID))  += ../../i386/kernel/cpuid.o
 cpuid-$(subst m,y,$(CONFIG_X86_CPUID))  += ../../i386/kernel/cpuid.o
 topology-y                     += ../../i386/mach-default/topology.o
 topology-y                     += ../../i386/mach-default/topology.o
-swiotlb-$(CONFIG_SWIOTLB)      += ../../ia64/lib/swiotlb.o
 microcode-$(subst m,y,$(CONFIG_MICROCODE))  += ../../i386/kernel/microcode.o
 microcode-$(subst m,y,$(CONFIG_MICROCODE))  += ../../i386/kernel/microcode.o
 intel_cacheinfo-y		+= ../../i386/kernel/cpu/intel_cacheinfo.o
 intel_cacheinfo-y		+= ../../i386/kernel/cpu/intel_cacheinfo.o
 quirks-y			+= ../../i386/kernel/quirks.o
 quirks-y			+= ../../i386/kernel/quirks.o

+ 50 - 16
arch/x86_64/lib/bitops.c

@@ -5,19 +5,23 @@
 #undef find_first_bit
 #undef find_first_bit
 #undef find_next_bit
 #undef find_next_bit
 
 
-/**
- * find_first_zero_bit - find the first zero bit in a memory region
- * @addr: The address to start the search at
- * @size: The maximum size to search
- *
- * Returns the bit-number of the first zero bit, not the number of the byte
- * containing a bit.
- */
-inline long find_first_zero_bit(const unsigned long * addr, unsigned long size)
+static inline long
+__find_first_zero_bit(const unsigned long * addr, unsigned long size)
 {
 {
 	long d0, d1, d2;
 	long d0, d1, d2;
 	long res;
 	long res;
 
 
+	/*
+	 * We must test the size in words, not in bits, because
+	 * otherwise incoming sizes in the range -63..-1 will not run
+	 * any scasq instructions, and then the flags used by the je
+	 * instruction will have whatever random value was in place
+	 * before.  Nobody should call us like that, but
+	 * find_next_zero_bit() does when offset and size are at the
+	 * same word and it fails to find a zero itself.
+	 */
+	size += 63;
+	size >>= 6;
 	if (!size)
 	if (!size)
 		return 0;
 		return 0;
 	asm volatile(
 	asm volatile(
@@ -30,11 +34,29 @@ inline long find_first_zero_bit(const unsigned long * addr, unsigned long size)
 		"  shlq $3,%%rdi\n"
 		"  shlq $3,%%rdi\n"
 		"  addq %%rdi,%%rdx"
 		"  addq %%rdi,%%rdx"
 		:"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
 		:"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
-		:"0" (0ULL), "1" ((size + 63) >> 6), "2" (addr), "3" (-1ULL),
-		 [addr] "r" (addr) : "memory");
+		:"0" (0ULL), "1" (size), "2" (addr), "3" (-1ULL),
+		 [addr] "S" (addr) : "memory");
+	/*
+	 * Any register would do for [addr] above, but GCC tends to
+	 * prefer rbx over rsi, even though rsi is readily available
+	 * and doesn't have to be saved.
+	 */
 	return res;
 	return res;
 }
 }
 
 
+/**
+ * find_first_zero_bit - find the first zero bit in a memory region
+ * @addr: The address to start the search at
+ * @size: The maximum size to search
+ *
+ * Returns the bit-number of the first zero bit, not the number of the byte
+ * containing a bit.
+ */
+long find_first_zero_bit(const unsigned long * addr, unsigned long size)
+{
+	return __find_first_zero_bit (addr, size);
+}
+
 /**
 /**
  * find_next_zero_bit - find the first zero bit in a memory region
  * find_next_zero_bit - find the first zero bit in a memory region
  * @addr: The address to base the search on
  * @addr: The address to base the search on
@@ -43,7 +65,7 @@ inline long find_first_zero_bit(const unsigned long * addr, unsigned long size)
  */
  */
 long find_next_zero_bit (const unsigned long * addr, long size, long offset)
 long find_next_zero_bit (const unsigned long * addr, long size, long offset)
 {
 {
-	unsigned long * p = ((unsigned long *) addr) + (offset >> 6);
+	const unsigned long * p = addr + (offset >> 6);
 	unsigned long set = 0;
 	unsigned long set = 0;
 	unsigned long res, bit = offset&63;
 	unsigned long res, bit = offset&63;
 
 
@@ -63,8 +85,8 @@ long find_next_zero_bit (const unsigned long * addr, long size, long offset)
 	/*
 	/*
 	 * No zero yet, search remaining full words for a zero
 	 * No zero yet, search remaining full words for a zero
 	 */
 	 */
-	res = find_first_zero_bit ((const unsigned long *)p,
-				   size - 64 * (p - (unsigned long *) addr));
+	res = __find_first_zero_bit (p, size - 64 * (p - addr));
+
 	return (offset + set + res);
 	return (offset + set + res);
 }
 }
 
 
@@ -74,6 +96,19 @@ __find_first_bit(const unsigned long * addr, unsigned long size)
 	long d0, d1;
 	long d0, d1;
 	long res;
 	long res;
 
 
+	/*
+	 * We must test the size in words, not in bits, because
+	 * otherwise incoming sizes in the range -63..-1 will not run
+	 * any scasq instructions, and then the flags used by the jz
+	 * instruction will have whatever random value was in place
+	 * before.  Nobody should call us like that, but
+	 * find_next_bit() does when offset and size are at the same
+	 * word and it fails to find a one itself.
+	 */
+	size += 63;
+	size >>= 6;
+	if (!size)
+		return 0;
 	asm volatile(
 	asm volatile(
 		"   repe; scasq\n"
 		"   repe; scasq\n"
 		"   jz 1f\n"
 		"   jz 1f\n"
@@ -83,8 +118,7 @@ __find_first_bit(const unsigned long * addr, unsigned long size)
 		"   shlq $3,%%rdi\n"
 		"   shlq $3,%%rdi\n"
 		"   addq %%rdi,%%rax"
 		"   addq %%rdi,%%rax"
 		:"=a" (res), "=&c" (d0), "=&D" (d1)
 		:"=a" (res), "=&c" (d0), "=&D" (d1)
-		:"0" (0ULL),
-		 "1" ((size + 63) >> 6), "2" (addr),
+		:"0" (0ULL), "1" (size), "2" (addr),
 		 [addr] "r" (addr) : "memory");
 		 [addr] "r" (addr) : "memory");
 	return res;
 	return res;
 }
 }

+ 4 - 9
drivers/block/aoe/aoecmd.c

@@ -468,16 +468,11 @@ aoecmd_ata_rsp(struct sk_buff *skb)
 			unsigned long duration = jiffies - buf->start_time;
 			unsigned long duration = jiffies - buf->start_time;
 			unsigned long n_sect = buf->bio->bi_size >> 9;
 			unsigned long n_sect = buf->bio->bi_size >> 9;
 			struct gendisk *disk = d->gd;
 			struct gendisk *disk = d->gd;
+			const int rw = bio_data_dir(buf->bio);
 
 
-			if (bio_data_dir(buf->bio) == WRITE) {
-				disk_stat_inc(disk, writes);
-				disk_stat_add(disk, write_ticks, duration);
-				disk_stat_add(disk, write_sectors, n_sect);
-			} else {
-				disk_stat_inc(disk, reads);
-				disk_stat_add(disk, read_ticks, duration);
-				disk_stat_add(disk, read_sectors, n_sect);
-			}
+			disk_stat_inc(disk, ios[rw]);
+			disk_stat_add(disk, ticks[rw], duration);
+			disk_stat_add(disk, sectors[rw], n_sect);
 			disk_stat_add(disk, io_ticks, duration);
 			disk_stat_add(disk, io_ticks, duration);
 			n = (buf->flags & BUFFL_FAIL) ? -EIO : 0;
 			n = (buf->flags & BUFFL_FAIL) ? -EIO : 0;
 			bio_endio(buf->bio, buf->bio->bi_size, n);
 			bio_endio(buf->bio, buf->bio->bi_size, n);

+ 6 - 1
drivers/block/elevator.c

@@ -369,9 +369,14 @@ void __elv_add_request(request_queue_t *q, struct request *rq, int where,
 	case ELEVATOR_INSERT_SORT:
 	case ELEVATOR_INSERT_SORT:
 		BUG_ON(!blk_fs_request(rq));
 		BUG_ON(!blk_fs_request(rq));
 		rq->flags |= REQ_SORTED;
 		rq->flags |= REQ_SORTED;
-		q->elevator->ops->elevator_add_req_fn(q, rq);
 		if (q->last_merge == NULL && rq_mergeable(rq))
 		if (q->last_merge == NULL && rq_mergeable(rq))
 			q->last_merge = rq;
 			q->last_merge = rq;
+		/*
+		 * Some ioscheds (cfq) run q->request_fn directly, so
+		 * rq cannot be accessed after calling
+		 * elevator_add_req_fn.
+		 */
+		q->elevator->ops->elevator_add_req_fn(q, rq);
 		break;
 		break;
 
 
 	default:
 	default:

+ 14 - 15
drivers/block/genhd.c

@@ -391,13 +391,12 @@ static ssize_t disk_stats_read(struct gendisk * disk, char *page)
 		"%8u %8u %8llu %8u "
 		"%8u %8u %8llu %8u "
 		"%8u %8u %8u"
 		"%8u %8u %8u"
 		"\n",
 		"\n",
-		disk_stat_read(disk, reads), disk_stat_read(disk, read_merges),
-		(unsigned long long)disk_stat_read(disk, read_sectors),
-		jiffies_to_msecs(disk_stat_read(disk, read_ticks)),
-		disk_stat_read(disk, writes), 
-		disk_stat_read(disk, write_merges),
-		(unsigned long long)disk_stat_read(disk, write_sectors),
-		jiffies_to_msecs(disk_stat_read(disk, write_ticks)),
+		disk_stat_read(disk, ios[0]), disk_stat_read(disk, merges[0]),
+		(unsigned long long)disk_stat_read(disk, sectors[0]),
+		jiffies_to_msecs(disk_stat_read(disk, ticks[0])),
+		disk_stat_read(disk, ios[1]), disk_stat_read(disk, merges[1]),
+		(unsigned long long)disk_stat_read(disk, sectors[1]),
+		jiffies_to_msecs(disk_stat_read(disk, ticks[1])),
 		disk->in_flight,
 		disk->in_flight,
 		jiffies_to_msecs(disk_stat_read(disk, io_ticks)),
 		jiffies_to_msecs(disk_stat_read(disk, io_ticks)),
 		jiffies_to_msecs(disk_stat_read(disk, time_in_queue)));
 		jiffies_to_msecs(disk_stat_read(disk, time_in_queue)));
@@ -583,12 +582,12 @@ static int diskstats_show(struct seq_file *s, void *v)
 	preempt_enable();
 	preempt_enable();
 	seq_printf(s, "%4d %4d %s %u %u %llu %u %u %u %llu %u %u %u %u\n",
 	seq_printf(s, "%4d %4d %s %u %u %llu %u %u %u %llu %u %u %u %u\n",
 		gp->major, n + gp->first_minor, disk_name(gp, n, buf),
 		gp->major, n + gp->first_minor, disk_name(gp, n, buf),
-		disk_stat_read(gp, reads), disk_stat_read(gp, read_merges),
-		(unsigned long long)disk_stat_read(gp, read_sectors),
-		jiffies_to_msecs(disk_stat_read(gp, read_ticks)),
-		disk_stat_read(gp, writes), disk_stat_read(gp, write_merges),
-		(unsigned long long)disk_stat_read(gp, write_sectors),
-		jiffies_to_msecs(disk_stat_read(gp, write_ticks)),
+		disk_stat_read(gp, ios[0]), disk_stat_read(gp, merges[0]),
+		(unsigned long long)disk_stat_read(gp, sectors[0]),
+		jiffies_to_msecs(disk_stat_read(gp, ticks[0])),
+		disk_stat_read(gp, ios[1]), disk_stat_read(gp, merges[1]),
+		(unsigned long long)disk_stat_read(gp, sectors[1]),
+		jiffies_to_msecs(disk_stat_read(gp, ticks[1])),
 		gp->in_flight,
 		gp->in_flight,
 		jiffies_to_msecs(disk_stat_read(gp, io_ticks)),
 		jiffies_to_msecs(disk_stat_read(gp, io_ticks)),
 		jiffies_to_msecs(disk_stat_read(gp, time_in_queue)));
 		jiffies_to_msecs(disk_stat_read(gp, time_in_queue)));
@@ -601,8 +600,8 @@ static int diskstats_show(struct seq_file *s, void *v)
 			seq_printf(s, "%4d %4d %s %u %u %u %u\n",
 			seq_printf(s, "%4d %4d %s %u %u %u %u\n",
 				gp->major, n + gp->first_minor + 1,
 				gp->major, n + gp->first_minor + 1,
 				disk_name(gp, n + 1, buf),
 				disk_name(gp, n + 1, buf),
-				hd->reads, hd->read_sectors,
-				hd->writes, hd->write_sectors);
+				hd->ios[0], hd->sectors[0],
+				hd->ios[1], hd->sectors[1]);
 	}
 	}
  
  
 	return 0;
 	return 0;

+ 17 - 30
drivers/block/ll_rw_blk.c

@@ -2387,16 +2387,9 @@ static void drive_stat_acct(struct request *rq, int nr_sectors, int new_io)
 	if (!blk_fs_request(rq) || !rq->rq_disk)
 	if (!blk_fs_request(rq) || !rq->rq_disk)
 		return;
 		return;
 
 
-	if (rw == READ) {
-		__disk_stat_add(rq->rq_disk, read_sectors, nr_sectors);
-		if (!new_io)
-			__disk_stat_inc(rq->rq_disk, read_merges);
-	} else if (rw == WRITE) {
-		__disk_stat_add(rq->rq_disk, write_sectors, nr_sectors);
-		if (!new_io)
-			__disk_stat_inc(rq->rq_disk, write_merges);
-	}
-	if (new_io) {
+	if (!new_io) {
+		__disk_stat_inc(rq->rq_disk, merges[rw]);
+	} else {
 		disk_round_stats(rq->rq_disk);
 		disk_round_stats(rq->rq_disk);
 		rq->rq_disk->in_flight++;
 		rq->rq_disk->in_flight++;
 	}
 	}
@@ -2791,17 +2784,11 @@ static inline void blk_partition_remap(struct bio *bio)
 
 
 	if (bdev != bdev->bd_contains) {
 	if (bdev != bdev->bd_contains) {
 		struct hd_struct *p = bdev->bd_part;
 		struct hd_struct *p = bdev->bd_part;
+		const int rw = bio_data_dir(bio);
+
+		p->sectors[rw] += bio_sectors(bio);
+		p->ios[rw]++;
 
 
-		switch (bio_data_dir(bio)) {
-		case READ:
-			p->read_sectors += bio_sectors(bio);
-			p->reads++;
-			break;
-		case WRITE:
-			p->write_sectors += bio_sectors(bio);
-			p->writes++;
-			break;
-		}
 		bio->bi_sector += p->start_sect;
 		bio->bi_sector += p->start_sect;
 		bio->bi_bdev = bdev->bd_contains;
 		bio->bi_bdev = bdev->bd_contains;
 	}
 	}
@@ -3048,6 +3035,12 @@ static int __end_that_request_first(struct request *req, int uptodate,
 				(unsigned long long)req->sector);
 				(unsigned long long)req->sector);
 	}
 	}
 
 
+	if (blk_fs_request(req) && req->rq_disk) {
+		const int rw = rq_data_dir(req);
+
+		__disk_stat_add(req->rq_disk, sectors[rw], nr_bytes >> 9);
+	}
+
 	total_bytes = bio_nbytes = 0;
 	total_bytes = bio_nbytes = 0;
 	while ((bio = req->bio) != NULL) {
 	while ((bio = req->bio) != NULL) {
 		int nbytes;
 		int nbytes;
@@ -3176,16 +3169,10 @@ void end_that_request_last(struct request *req)
 
 
 	if (disk && blk_fs_request(req)) {
 	if (disk && blk_fs_request(req)) {
 		unsigned long duration = jiffies - req->start_time;
 		unsigned long duration = jiffies - req->start_time;
-		switch (rq_data_dir(req)) {
-		    case WRITE:
-			__disk_stat_inc(disk, writes);
-			__disk_stat_add(disk, write_ticks, duration);
-			break;
-		    case READ:
-			__disk_stat_inc(disk, reads);
-			__disk_stat_add(disk, read_ticks, duration);
-			break;
-		}
+		const int rw = rq_data_dir(req);
+
+		__disk_stat_inc(disk, ios[rw]);
+		__disk_stat_add(disk, ticks[rw], duration);
 		disk_round_stats(disk);
 		disk_round_stats(disk);
 		disk->in_flight--;
 		disk->in_flight--;
 	}
 	}

+ 86 - 66
drivers/char/drm/ati_pcigart.c

@@ -1,5 +1,5 @@
 /**
 /**
- * \file ati_pcigart.h 
+ * \file ati_pcigart.c
  * ATI PCI GART support
  * ATI PCI GART support
  *
  *
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
@@ -52,85 +52,91 @@
 # define ATI_MAX_PCIGART_PAGES		8192	/**< 32 MB aperture, 4K pages */
 # define ATI_MAX_PCIGART_PAGES		8192	/**< 32 MB aperture, 4K pages */
 # define ATI_PCIGART_PAGE_SIZE		4096	/**< PCI GART page size */
 # define ATI_PCIGART_PAGE_SIZE		4096	/**< PCI GART page size */
 
 
-static unsigned long drm_ati_alloc_pcigart_table( void )
+static unsigned long drm_ati_alloc_pcigart_table(void)
 {
 {
 	unsigned long address;
 	unsigned long address;
 	struct page *page;
 	struct page *page;
 	int i;
 	int i;
-	DRM_DEBUG( "%s\n", __FUNCTION__ );
+	DRM_DEBUG("%s\n", __FUNCTION__);
 
 
-	address = __get_free_pages( GFP_KERNEL, ATI_PCIGART_TABLE_ORDER );
-	if ( address == 0UL ) {
+	address = __get_free_pages(GFP_KERNEL, ATI_PCIGART_TABLE_ORDER);
+	if (address == 0UL) {
 		return 0;
 		return 0;
 	}
 	}
 
 
-	page = virt_to_page( address );
+	page = virt_to_page(address);
 
 
-	for ( i = 0 ; i < ATI_PCIGART_TABLE_PAGES ; i++, page++ ) {
+	for (i = 0; i < ATI_PCIGART_TABLE_PAGES; i++, page++) {
 		get_page(page);
 		get_page(page);
-		SetPageReserved( page );
+		SetPageReserved(page);
 	}
 	}
 
 
-	DRM_DEBUG( "%s: returning 0x%08lx\n", __FUNCTION__, address );
+	DRM_DEBUG("%s: returning 0x%08lx\n", __FUNCTION__, address);
 	return address;
 	return address;
 }
 }
 
 
-static void drm_ati_free_pcigart_table( unsigned long address )
+static void drm_ati_free_pcigart_table(unsigned long address)
 {
 {
 	struct page *page;
 	struct page *page;
 	int i;
 	int i;
-	DRM_DEBUG( "%s\n", __FUNCTION__ );
+	DRM_DEBUG("%s\n", __FUNCTION__);
 
 
-	page = virt_to_page( address );
+	page = virt_to_page(address);
 
 
-	for ( i = 0 ; i < ATI_PCIGART_TABLE_PAGES ; i++, page++ ) {
+	for (i = 0; i < ATI_PCIGART_TABLE_PAGES; i++, page++) {
 		__put_page(page);
 		__put_page(page);
-		ClearPageReserved( page );
+		ClearPageReserved(page);
 	}
 	}
 
 
-	free_pages( address, ATI_PCIGART_TABLE_ORDER );
+	free_pages(address, ATI_PCIGART_TABLE_ORDER);
 }
 }
 
 
-int drm_ati_pcigart_cleanup( drm_device_t *dev,
-			      unsigned long addr,
-			      dma_addr_t bus_addr)
+int drm_ati_pcigart_cleanup(drm_device_t * dev,
+			    drm_ati_pcigart_info * gart_info)
 {
 {
 	drm_sg_mem_t *entry = dev->sg;
 	drm_sg_mem_t *entry = dev->sg;
 	unsigned long pages;
 	unsigned long pages;
 	int i;
 	int i;
 
 
 	/* we need to support large memory configurations */
 	/* we need to support large memory configurations */
-	if ( !entry ) {
-		DRM_ERROR( "no scatter/gather memory!\n" );
+	if (!entry) {
+		DRM_ERROR("no scatter/gather memory!\n");
 		return 0;
 		return 0;
 	}
 	}
 
 
-	if ( bus_addr ) {
-		pci_unmap_single(dev->pdev, bus_addr,
-				 ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
-				 PCI_DMA_TODEVICE);
+	if (gart_info->bus_addr) {
+		if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
+			pci_unmap_single(dev->pdev, gart_info->bus_addr,
+					 ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
+					 PCI_DMA_TODEVICE);
+		}
 
 
-		pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
-		        ? entry->pages : ATI_MAX_PCIGART_PAGES;
+		pages = (entry->pages <= ATI_MAX_PCIGART_PAGES)
+		    ? entry->pages : ATI_MAX_PCIGART_PAGES;
 
 
-		for ( i = 0 ; i < pages ; i++ ) {
-			if ( !entry->busaddr[i] ) break;
+		for (i = 0; i < pages; i++) {
+			if (!entry->busaddr[i])
+				break;
 			pci_unmap_single(dev->pdev, entry->busaddr[i],
 			pci_unmap_single(dev->pdev, entry->busaddr[i],
 					 PAGE_SIZE, PCI_DMA_TODEVICE);
 					 PAGE_SIZE, PCI_DMA_TODEVICE);
 		}
 		}
+
+		if (gart_info->gart_table_location == DRM_ATI_GART_MAIN)
+			gart_info->bus_addr = 0;
 	}
 	}
 
 
-	if ( addr ) {
-		drm_ati_free_pcigart_table( addr );
+	if (gart_info->gart_table_location == DRM_ATI_GART_MAIN
+	    && gart_info->addr) {
+		drm_ati_free_pcigart_table(gart_info->addr);
+		gart_info->addr = 0;
 	}
 	}
 
 
 	return 1;
 	return 1;
 }
 }
+
 EXPORT_SYMBOL(drm_ati_pcigart_cleanup);
 EXPORT_SYMBOL(drm_ati_pcigart_cleanup);
 
 
-int drm_ati_pcigart_init( drm_device_t *dev,
-			   unsigned long *addr,
-			   dma_addr_t *bus_addr)
+int drm_ati_pcigart_init(drm_device_t * dev, drm_ati_pcigart_info * gart_info)
 {
 {
 	drm_sg_mem_t *entry = dev->sg;
 	drm_sg_mem_t *entry = dev->sg;
 	unsigned long address = 0;
 	unsigned long address = 0;
@@ -138,48 +144,57 @@ int drm_ati_pcigart_init( drm_device_t *dev,
 	u32 *pci_gart, page_base, bus_address = 0;
 	u32 *pci_gart, page_base, bus_address = 0;
 	int i, j, ret = 0;
 	int i, j, ret = 0;
 
 
-	if ( !entry ) {
-		DRM_ERROR( "no scatter/gather memory!\n" );
+	if (!entry) {
+		DRM_ERROR("no scatter/gather memory!\n");
 		goto done;
 		goto done;
 	}
 	}
 
 
-	address = drm_ati_alloc_pcigart_table();
-	if ( !address ) {
-		DRM_ERROR( "cannot allocate PCI GART page!\n" );
-		goto done;
-	}
+	if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
+		DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n");
 
 
-	if ( !dev->pdev ) {
-		DRM_ERROR( "PCI device unknown!\n" );
-		goto done;
-	}
+		address = drm_ati_alloc_pcigart_table();
+		if (!address) {
+			DRM_ERROR("cannot allocate PCI GART page!\n");
+			goto done;
+		}
 
 
-	bus_address = pci_map_single(dev->pdev, (void *)address,
-				  ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
-				  PCI_DMA_TODEVICE);
-	if (bus_address == 0) {
-		DRM_ERROR( "unable to map PCIGART pages!\n" );
-		drm_ati_free_pcigart_table( address );
-		address = 0;
-		goto done;
+		if (!dev->pdev) {
+			DRM_ERROR("PCI device unknown!\n");
+			goto done;
+		}
+
+		bus_address = pci_map_single(dev->pdev, (void *)address,
+					     ATI_PCIGART_TABLE_PAGES *
+					     PAGE_SIZE, PCI_DMA_TODEVICE);
+		if (bus_address == 0) {
+			DRM_ERROR("unable to map PCIGART pages!\n");
+			drm_ati_free_pcigart_table(address);
+			address = 0;
+			goto done;
+		}
+	} else {
+		address = gart_info->addr;
+		bus_address = gart_info->bus_addr;
+		DRM_DEBUG("PCI: Gart Table: VRAM %08X mapped at %08lX\n",
+			  bus_address, address);
 	}
 	}
 
 
-	pci_gart = (u32 *)address;
+	pci_gart = (u32 *) address;
 
 
-	pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
-		? entry->pages : ATI_MAX_PCIGART_PAGES;
+	pages = (entry->pages <= ATI_MAX_PCIGART_PAGES)
+	    ? entry->pages : ATI_MAX_PCIGART_PAGES;
 
 
-	memset( pci_gart, 0, ATI_MAX_PCIGART_PAGES * sizeof(u32) );
+	memset(pci_gart, 0, ATI_MAX_PCIGART_PAGES * sizeof(u32));
 
 
-	for ( i = 0 ; i < pages ; i++ ) {
+	for (i = 0; i < pages; i++) {
 		/* we need to support large memory configurations */
 		/* we need to support large memory configurations */
 		entry->busaddr[i] = pci_map_single(dev->pdev,
 		entry->busaddr[i] = pci_map_single(dev->pdev,
-					   page_address( entry->pagelist[i] ),
-					   PAGE_SIZE,
-					   PCI_DMA_TODEVICE);
+						   page_address(entry->
+								pagelist[i]),
+						   PAGE_SIZE, PCI_DMA_TODEVICE);
 		if (entry->busaddr[i] == 0) {
 		if (entry->busaddr[i] == 0) {
-			DRM_ERROR( "unable to map PCIGART pages!\n" );
-			drm_ati_pcigart_cleanup( dev, address, bus_address );
+			DRM_ERROR("unable to map PCIGART pages!\n");
+			drm_ati_pcigart_cleanup(dev, gart_info);
 			address = 0;
 			address = 0;
 			bus_address = 0;
 			bus_address = 0;
 			goto done;
 			goto done;
@@ -187,7 +202,11 @@ int drm_ati_pcigart_init( drm_device_t *dev,
 		page_base = (u32) entry->busaddr[i];
 		page_base = (u32) entry->busaddr[i];
 
 
 		for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
 		for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
-			*pci_gart++ = cpu_to_le32( page_base );
+			if (gart_info->is_pcie)
+				*pci_gart = (cpu_to_le32(page_base) >> 8) | 0xc;
+			else
+				*pci_gart = cpu_to_le32(page_base);
+			*pci_gart++;
 			page_base += ATI_PCIGART_PAGE_SIZE;
 			page_base += ATI_PCIGART_PAGE_SIZE;
 		}
 		}
 	}
 	}
@@ -200,9 +219,10 @@ int drm_ati_pcigart_init( drm_device_t *dev,
 	mb();
 	mb();
 #endif
 #endif
 
 
-done:
-	*addr = address;
-	*bus_addr = bus_address;
+      done:
+	gart_info->addr = address;
+	gart_info->bus_addr = bus_address;
 	return ret;
 	return ret;
 }
 }
+
 EXPORT_SYMBOL(drm_ati_pcigart_init);
 EXPORT_SYMBOL(drm_ati_pcigart_init);

+ 126 - 169
drivers/char/drm/drm.h

@@ -1,7 +1,7 @@
 /**
 /**
- * \file drm.h 
+ * \file drm.h
  * Header for the Direct Rendering Manager
  * Header for the Direct Rendering Manager
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  *
  *
  * \par Acknowledgments:
  * \par Acknowledgments:
@@ -33,7 +33,6 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  * OTHER DEALINGS IN THE SOFTWARE.
  */
  */
 
 
-
 #ifndef _DRM_H_
 #ifndef _DRM_H_
 #define _DRM_H_
 #define _DRM_H_
 
 
@@ -56,7 +55,7 @@
 #define ioctl(a,b,c)		xf86ioctl(a,b,c)
 #define ioctl(a,b,c)		xf86ioctl(a,b,c)
 #else
 #else
 #include <sys/ioccom.h>
 #include <sys/ioccom.h>
-#endif /* __FreeBSD__ && xf86ioctl */
+#endif				/* __FreeBSD__ && xf86ioctl */
 #define DRM_IOCTL_NR(n)		((n) & 0xff)
 #define DRM_IOCTL_NR(n)		((n) & 0xff)
 #define DRM_IOC_VOID		IOC_VOID
 #define DRM_IOC_VOID		IOC_VOID
 #define DRM_IOC_READ		IOC_OUT
 #define DRM_IOC_READ		IOC_OUT
@@ -97,16 +96,14 @@
 #define _DRM_LOCK_IS_CONT(lock)	   ((lock) & _DRM_LOCK_CONT)
 #define _DRM_LOCK_IS_CONT(lock)	   ((lock) & _DRM_LOCK_CONT)
 #define _DRM_LOCKING_CONTEXT(lock) ((lock) & ~(_DRM_LOCK_HELD|_DRM_LOCK_CONT))
 #define _DRM_LOCKING_CONTEXT(lock) ((lock) & ~(_DRM_LOCK_HELD|_DRM_LOCK_CONT))
 
 
-
-typedef unsigned int  drm_handle_t;
-typedef unsigned int  drm_context_t;
-typedef unsigned int  drm_drawable_t;
-typedef unsigned int  drm_magic_t;
-
+typedef unsigned int drm_handle_t;
+typedef unsigned int drm_context_t;
+typedef unsigned int drm_drawable_t;
+typedef unsigned int drm_magic_t;
 
 
 /**
 /**
  * Cliprect.
  * Cliprect.
- * 
+ *
  * \warning: If you change this structure, make sure you change
  * \warning: If you change this structure, make sure you change
  * XF86DRIClipRectRec in the server as well
  * XF86DRIClipRectRec in the server as well
  *
  *
@@ -114,22 +111,21 @@ typedef unsigned int  drm_magic_t;
  * backwards-compatibility reasons.
  * backwards-compatibility reasons.
  */
  */
 typedef struct drm_clip_rect {
 typedef struct drm_clip_rect {
-	unsigned short	x1;
-	unsigned short	y1;
-	unsigned short	x2;
-	unsigned short	y2;
+	unsigned short x1;
+	unsigned short y1;
+	unsigned short x2;
+	unsigned short y2;
 } drm_clip_rect_t;
 } drm_clip_rect_t;
 
 
-
 /**
 /**
  * Texture region,
  * Texture region,
  */
  */
 typedef struct drm_tex_region {
 typedef struct drm_tex_region {
-	unsigned char	next;
-	unsigned char	prev;
-	unsigned char	in_use;
-	unsigned char	padding;
-	unsigned int	age;
+	unsigned char next;
+	unsigned char prev;
+	unsigned char in_use;
+	unsigned char padding;
+	unsigned int age;
 } drm_tex_region_t;
 } drm_tex_region_t;
 
 
 /**
 /**
@@ -141,28 +137,26 @@ typedef struct drm_tex_region {
  */
  */
 typedef struct drm_hw_lock {
 typedef struct drm_hw_lock {
 	__volatile__ unsigned int lock;		/**< lock variable */
 	__volatile__ unsigned int lock;		/**< lock variable */
-	char			  padding[60];	/**< Pad to cache line */
+	char padding[60];			/**< Pad to cache line */
 } drm_hw_lock_t;
 } drm_hw_lock_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_VERSION ioctl argument type.
  * DRM_IOCTL_VERSION ioctl argument type.
- * 
+ *
  * \sa drmGetVersion().
  * \sa drmGetVersion().
  */
  */
 typedef struct drm_version {
 typedef struct drm_version {
-	int    version_major;	  /**< Major version */
-	int    version_minor;	  /**< Minor version */
-	int    version_patchlevel;/**< Patch level */
+	int version_major;	  /**< Major version */
+	int version_minor;	  /**< Minor version */
+	int version_patchlevel;	  /**< Patch level */
 	size_t name_len;	  /**< Length of name buffer */
 	size_t name_len;	  /**< Length of name buffer */
-	char   __user *name;	  /**< Name of driver */
+	char __user *name;	  /**< Name of driver */
 	size_t date_len;	  /**< Length of date buffer */
 	size_t date_len;	  /**< Length of date buffer */
-	char   __user *date;	  /**< User-space buffer to hold date */
+	char __user *date;	  /**< User-space buffer to hold date */
 	size_t desc_len;	  /**< Length of desc buffer */
 	size_t desc_len;	  /**< Length of desc buffer */
-	char   __user *desc;	  /**< User-space buffer to hold desc */
+	char __user *desc;	  /**< User-space buffer to hold desc */
 } drm_version_t;
 } drm_version_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_GET_UNIQUE ioctl argument type.
  * DRM_IOCTL_GET_UNIQUE ioctl argument type.
  *
  *
@@ -170,21 +164,18 @@ typedef struct drm_version {
  */
  */
 typedef struct drm_unique {
 typedef struct drm_unique {
 	size_t unique_len;	  /**< Length of unique */
 	size_t unique_len;	  /**< Length of unique */
-	char   __user *unique;	  /**< Unique name for driver instantiation */
+	char __user *unique;	  /**< Unique name for driver instantiation */
 } drm_unique_t;
 } drm_unique_t;
 
 
-
 typedef struct drm_list {
 typedef struct drm_list {
-	int		 count;	  /**< Length of user-space structures */
-	drm_version_t	 __user *version;
+	int count;		  /**< Length of user-space structures */
+	drm_version_t __user *version;
 } drm_list_t;
 } drm_list_t;
 
 
-
 typedef struct drm_block {
 typedef struct drm_block {
-	int		 unused;
+	int unused;
 } drm_block_t;
 } drm_block_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_CONTROL ioctl argument type.
  * DRM_IOCTL_CONTROL ioctl argument type.
  *
  *
@@ -196,44 +187,40 @@ typedef struct drm_control {
 		DRM_RM_COMMAND,
 		DRM_RM_COMMAND,
 		DRM_INST_HANDLER,
 		DRM_INST_HANDLER,
 		DRM_UNINST_HANDLER
 		DRM_UNINST_HANDLER
-	}		 func;
-	int		 irq;
+	} func;
+	int irq;
 } drm_control_t;
 } drm_control_t;
 
 
-
 /**
 /**
  * Type of memory to map.
  * Type of memory to map.
  */
  */
 typedef enum drm_map_type {
 typedef enum drm_map_type {
-	_DRM_FRAME_BUFFER   = 0,  /**< WC (no caching), no core dump */
-	_DRM_REGISTERS	    = 1,  /**< no caching, no core dump */
-	_DRM_SHM	    = 2,  /**< shared, cached */
-	_DRM_AGP            = 3,  /**< AGP/GART */
+	_DRM_FRAME_BUFFER = 0,	  /**< WC (no caching), no core dump */
+	_DRM_REGISTERS = 1,	  /**< no caching, no core dump */
+	_DRM_SHM = 2,		  /**< shared, cached */
+	_DRM_AGP = 3,		  /**< AGP/GART */
 	_DRM_SCATTER_GATHER = 4,  /**< Scatter/gather memory for PCI DMA */
 	_DRM_SCATTER_GATHER = 4,  /**< Scatter/gather memory for PCI DMA */
-	_DRM_CONSISTENT     = 5,  /**< Consistent memory for PCI DMA */
+	_DRM_CONSISTENT = 5,	  /**< Consistent memory for PCI DMA */
 } drm_map_type_t;
 } drm_map_type_t;
 
 
-
 /**
 /**
  * Memory mapping flags.
  * Memory mapping flags.
  */
  */
 typedef enum drm_map_flags {
 typedef enum drm_map_flags {
-	_DRM_RESTRICTED	     = 0x01, /**< Cannot be mapped to user-virtual */
-	_DRM_READ_ONLY	     = 0x02,
-	_DRM_LOCKED	     = 0x04, /**< shared, cached, locked */
-	_DRM_KERNEL	     = 0x08, /**< kernel requires access */
+	_DRM_RESTRICTED = 0x01,	     /**< Cannot be mapped to user-virtual */
+	_DRM_READ_ONLY = 0x02,
+	_DRM_LOCKED = 0x04,	     /**< shared, cached, locked */
+	_DRM_KERNEL = 0x08,	     /**< kernel requires access */
 	_DRM_WRITE_COMBINING = 0x10, /**< use write-combining if available */
 	_DRM_WRITE_COMBINING = 0x10, /**< use write-combining if available */
-	_DRM_CONTAINS_LOCK   = 0x20, /**< SHM page that contains lock */
-	_DRM_REMOVABLE	     = 0x40  /**< Removable mapping */
+	_DRM_CONTAINS_LOCK = 0x20,   /**< SHM page that contains lock */
+	_DRM_REMOVABLE = 0x40	     /**< Removable mapping */
 } drm_map_flags_t;
 } drm_map_flags_t;
 
 
-
 typedef struct drm_ctx_priv_map {
 typedef struct drm_ctx_priv_map {
-	unsigned int	ctx_id;  /**< Context requesting private mapping */
-	void		*handle; /**< Handle of map */
+	unsigned int ctx_id;	 /**< Context requesting private mapping */
+	void *handle;		 /**< Handle of map */
 } drm_ctx_priv_map_t;
 } drm_ctx_priv_map_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_GET_MAP, DRM_IOCTL_ADD_MAP and DRM_IOCTL_RM_MAP ioctls
  * DRM_IOCTL_GET_MAP, DRM_IOCTL_ADD_MAP and DRM_IOCTL_RM_MAP ioctls
  * argument type.
  * argument type.
@@ -241,30 +228,28 @@ typedef struct drm_ctx_priv_map {
  * \sa drmAddMap().
  * \sa drmAddMap().
  */
  */
 typedef struct drm_map {
 typedef struct drm_map {
-	unsigned long	offset;	 /**< Requested physical address (0 for SAREA)*/
-	unsigned long	size;	 /**< Requested physical size (bytes) */
-	drm_map_type_t	type;	 /**< Type of memory to map */
+	unsigned long offset;	 /**< Requested physical address (0 for SAREA)*/
+	unsigned long size;	 /**< Requested physical size (bytes) */
+	drm_map_type_t type;	 /**< Type of memory to map */
 	drm_map_flags_t flags;	 /**< Flags */
 	drm_map_flags_t flags;	 /**< Flags */
-	void		*handle; /**< User-space: "Handle" to pass to mmap() */
+	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
 				 /**< Kernel-space: kernel-virtual address */
 				 /**< Kernel-space: kernel-virtual address */
-	int		mtrr;	 /**< MTRR slot used */
-				 /*   Private data */
+	int mtrr;		 /**< MTRR slot used */
+	/*   Private data */
 } drm_map_t;
 } drm_map_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_GET_CLIENT ioctl argument type.
  * DRM_IOCTL_GET_CLIENT ioctl argument type.
  */
  */
 typedef struct drm_client {
 typedef struct drm_client {
-	int		idx;	/**< Which client desired? */
-	int		auth;	/**< Is client authenticated? */
-	unsigned long	pid;	/**< Process ID */
-	unsigned long	uid;	/**< User ID */
-	unsigned long	magic;	/**< Magic */
-	unsigned long	iocs;	/**< Ioctl count */
+	int idx;		/**< Which client desired? */
+	int auth;		/**< Is client authenticated? */
+	unsigned long pid;	/**< Process ID */
+	unsigned long uid;	/**< User ID */
+	unsigned long magic;	/**< Magic */
+	unsigned long iocs;	/**< Ioctl count */
 } drm_client_t;
 } drm_client_t;
 
 
-
 typedef enum {
 typedef enum {
 	_DRM_STAT_LOCK,
 	_DRM_STAT_LOCK,
 	_DRM_STAT_OPENS,
 	_DRM_STAT_OPENS,
@@ -282,63 +267,58 @@ typedef enum {
 	_DRM_STAT_DMA,		/**< DMA */
 	_DRM_STAT_DMA,		/**< DMA */
 	_DRM_STAT_SPECIAL,	/**< Special DMA (e.g., priority or polled) */
 	_DRM_STAT_SPECIAL,	/**< Special DMA (e.g., priority or polled) */
 	_DRM_STAT_MISSED	/**< Missed DMA opportunity */
 	_DRM_STAT_MISSED	/**< Missed DMA opportunity */
-
-				/* Add to the *END* of the list */
+	    /* Add to the *END* of the list */
 } drm_stat_type_t;
 } drm_stat_type_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_GET_STATS ioctl argument type.
  * DRM_IOCTL_GET_STATS ioctl argument type.
  */
  */
 typedef struct drm_stats {
 typedef struct drm_stats {
 	unsigned long count;
 	unsigned long count;
 	struct {
 	struct {
-		unsigned long   value;
+		unsigned long value;
 		drm_stat_type_t type;
 		drm_stat_type_t type;
 	} data[15];
 	} data[15];
 } drm_stats_t;
 } drm_stats_t;
 
 
-
 /**
 /**
  * Hardware locking flags.
  * Hardware locking flags.
  */
  */
 typedef enum drm_lock_flags {
 typedef enum drm_lock_flags {
-	_DRM_LOCK_READY	     = 0x01, /**< Wait until hardware is ready for DMA */
-	_DRM_LOCK_QUIESCENT  = 0x02, /**< Wait until hardware quiescent */
-	_DRM_LOCK_FLUSH	     = 0x04, /**< Flush this context's DMA queue first */
-	_DRM_LOCK_FLUSH_ALL  = 0x08, /**< Flush all DMA queues first */
-				/* These *HALT* flags aren't supported yet
-				   -- they will be used to support the
-				   full-screen DGA-like mode. */
+	_DRM_LOCK_READY = 0x01,	     /**< Wait until hardware is ready for DMA */
+	_DRM_LOCK_QUIESCENT = 0x02,  /**< Wait until hardware quiescent */
+	_DRM_LOCK_FLUSH = 0x04,	     /**< Flush this context's DMA queue first */
+	_DRM_LOCK_FLUSH_ALL = 0x08,  /**< Flush all DMA queues first */
+	/* These *HALT* flags aren't supported yet
+	   -- they will be used to support the
+	   full-screen DGA-like mode. */
 	_DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
 	_DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
 	_DRM_HALT_CUR_QUEUES = 0x20  /**< Halt all current queues */
 	_DRM_HALT_CUR_QUEUES = 0x20  /**< Halt all current queues */
 } drm_lock_flags_t;
 } drm_lock_flags_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_LOCK, DRM_IOCTL_UNLOCK and DRM_IOCTL_FINISH ioctl argument type.
  * DRM_IOCTL_LOCK, DRM_IOCTL_UNLOCK and DRM_IOCTL_FINISH ioctl argument type.
- * 
+ *
  * \sa drmGetLock() and drmUnlock().
  * \sa drmGetLock() and drmUnlock().
  */
  */
 typedef struct drm_lock {
 typedef struct drm_lock {
-	int		 context;
+	int context;
 	drm_lock_flags_t flags;
 	drm_lock_flags_t flags;
 } drm_lock_t;
 } drm_lock_t;
 
 
-
 /**
 /**
  * DMA flags
  * DMA flags
  *
  *
- * \warning 
+ * \warning
  * These values \e must match xf86drm.h.
  * These values \e must match xf86drm.h.
  *
  *
  * \sa drm_dma.
  * \sa drm_dma.
  */
  */
-typedef enum drm_dma_flags {	      
-				      /* Flags for DMA buffer dispatch */
-	_DRM_DMA_BLOCK	      = 0x01, /**<
+typedef enum drm_dma_flags {
+	/* Flags for DMA buffer dispatch */
+	_DRM_DMA_BLOCK = 0x01,	      /**<
 				       * Block until buffer dispatched.
 				       * Block until buffer dispatched.
-				       * 
+				       *
 				       * \note The buffer may not yet have
 				       * \note The buffer may not yet have
 				       * been processed by the hardware --
 				       * been processed by the hardware --
 				       * getting a hardware lock with the
 				       * getting a hardware lock with the
@@ -347,79 +327,73 @@ typedef enum drm_dma_flags {
 				       * processed.
 				       * processed.
 				       */
 				       */
 	_DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
 	_DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
-	_DRM_DMA_PRIORITY     = 0x04, /**< High priority dispatch */
+	_DRM_DMA_PRIORITY = 0x04,     /**< High priority dispatch */
 
 
-				      /* Flags for DMA buffer request */
-	_DRM_DMA_WAIT	      = 0x10, /**< Wait for free buffers */
-	_DRM_DMA_SMALLER_OK   = 0x20, /**< Smaller-than-requested buffers OK */
-	_DRM_DMA_LARGER_OK    = 0x40  /**< Larger-than-requested buffers OK */
+	/* Flags for DMA buffer request */
+	_DRM_DMA_WAIT = 0x10,	      /**< Wait for free buffers */
+	_DRM_DMA_SMALLER_OK = 0x20,   /**< Smaller-than-requested buffers OK */
+	_DRM_DMA_LARGER_OK = 0x40     /**< Larger-than-requested buffers OK */
 } drm_dma_flags_t;
 } drm_dma_flags_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_ADD_BUFS and DRM_IOCTL_MARK_BUFS ioctl argument type.
  * DRM_IOCTL_ADD_BUFS and DRM_IOCTL_MARK_BUFS ioctl argument type.
  *
  *
  * \sa drmAddBufs().
  * \sa drmAddBufs().
  */
  */
 typedef struct drm_buf_desc {
 typedef struct drm_buf_desc {
-	int	      count;	 /**< Number of buffers of this size */
-	int	      size;	 /**< Size in bytes */
-	int	      low_mark;	 /**< Low water mark */
-	int	      high_mark; /**< High water mark */
+	int count;		 /**< Number of buffers of this size */
+	int size;		 /**< Size in bytes */
+	int low_mark;		 /**< Low water mark */
+	int high_mark;		 /**< High water mark */
 	enum {
 	enum {
-		_DRM_PAGE_ALIGN = 0x01, /**< Align on page boundaries for DMA */
-		_DRM_AGP_BUFFER = 0x02, /**< Buffer is in AGP space */
-		_DRM_SG_BUFFER  = 0x04, /**< Scatter/gather memory buffer */
-		_DRM_FB_BUFFER  = 0x08  /**< Buffer is in frame buffer */
-	}	      flags;
-	unsigned long agp_start; /**< 
+		_DRM_PAGE_ALIGN = 0x01,	/**< Align on page boundaries for DMA */
+		_DRM_AGP_BUFFER = 0x02,	/**< Buffer is in AGP space */
+		_DRM_SG_BUFFER = 0x04,	/**< Scatter/gather memory buffer */
+		_DRM_FB_BUFFER = 0x08	/**< Buffer is in frame buffer */
+	} flags;
+	unsigned long agp_start; /**<
 				  * Start address of where the AGP buffers are
 				  * Start address of where the AGP buffers are
 				  * in the AGP aperture
 				  * in the AGP aperture
 				  */
 				  */
 } drm_buf_desc_t;
 } drm_buf_desc_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_INFO_BUFS ioctl argument type.
  * DRM_IOCTL_INFO_BUFS ioctl argument type.
  */
  */
 typedef struct drm_buf_info {
 typedef struct drm_buf_info {
-	int	       count;	/**< Entries in list */
+	int count;		/**< Entries in list */
 	drm_buf_desc_t __user *list;
 	drm_buf_desc_t __user *list;
 } drm_buf_info_t;
 } drm_buf_info_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_FREE_BUFS ioctl argument type.
  * DRM_IOCTL_FREE_BUFS ioctl argument type.
  */
  */
 typedef struct drm_buf_free {
 typedef struct drm_buf_free {
-	int	       count;
-	int	       __user *list;
+	int count;
+	int __user *list;
 } drm_buf_free_t;
 } drm_buf_free_t;
 
 
-
 /**
 /**
  * Buffer information
  * Buffer information
  *
  *
  * \sa drm_buf_map.
  * \sa drm_buf_map.
  */
  */
 typedef struct drm_buf_pub {
 typedef struct drm_buf_pub {
-	int		  idx;	       /**< Index into the master buffer list */
-	int		  total;       /**< Buffer size */
-	int		  used;	       /**< Amount of buffer in use (for DMA) */
-	void	  __user *address;     /**< Address of buffer */
+	int idx;		       /**< Index into the master buffer list */
+	int total;		       /**< Buffer size */
+	int used;		       /**< Amount of buffer in use (for DMA) */
+	void __user *address;	       /**< Address of buffer */
 } drm_buf_pub_t;
 } drm_buf_pub_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_MAP_BUFS ioctl argument type.
  * DRM_IOCTL_MAP_BUFS ioctl argument type.
  */
  */
 typedef struct drm_buf_map {
 typedef struct drm_buf_map {
-	int	      count;	/**< Length of the buffer list */
-	void	      __user *virtual;	/**< Mmap'd area in user-virtual */
+	int count;		/**< Length of the buffer list */
+	void __user *virtual;		/**< Mmap'd area in user-virtual */
 	drm_buf_pub_t __user *list;	/**< Buffer information */
 	drm_buf_pub_t __user *list;	/**< Buffer information */
 } drm_buf_map_t;
 } drm_buf_map_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_DMA ioctl argument type.
  * DRM_IOCTL_DMA ioctl argument type.
  *
  *
@@ -428,61 +402,55 @@ typedef struct drm_buf_map {
  * \sa drmDMA().
  * \sa drmDMA().
  */
  */
 typedef struct drm_dma {
 typedef struct drm_dma {
-	int		context;	  /**< Context handle */
-	int		send_count;	  /**< Number of buffers to send */
-	int	__user *send_indices;	  /**< List of handles to buffers */
-	int	__user *send_sizes;	  /**< Lengths of data to send */
+	int context;			  /**< Context handle */
+	int send_count;			  /**< Number of buffers to send */
+	int __user *send_indices;	  /**< List of handles to buffers */
+	int __user *send_sizes;		  /**< Lengths of data to send */
 	drm_dma_flags_t flags;		  /**< Flags */
 	drm_dma_flags_t flags;		  /**< Flags */
-	int		request_count;	  /**< Number of buffers requested */
-	int		request_size;	  /**< Desired size for buffers */
-	int	__user *request_indices;  /**< Buffer information */
-	int	__user *request_sizes;
-	int		granted_count;	  /**< Number of buffers granted */
+	int request_count;		  /**< Number of buffers requested */
+	int request_size;		  /**< Desired size for buffers */
+	int __user *request_indices;	  /**< Buffer information */
+	int __user *request_sizes;
+	int granted_count;		  /**< Number of buffers granted */
 } drm_dma_t;
 } drm_dma_t;
 
 
-
 typedef enum {
 typedef enum {
 	_DRM_CONTEXT_PRESERVED = 0x01,
 	_DRM_CONTEXT_PRESERVED = 0x01,
-	_DRM_CONTEXT_2DONLY    = 0x02
+	_DRM_CONTEXT_2DONLY = 0x02
 } drm_ctx_flags_t;
 } drm_ctx_flags_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_ADD_CTX ioctl argument type.
  * DRM_IOCTL_ADD_CTX ioctl argument type.
  *
  *
  * \sa drmCreateContext() and drmDestroyContext().
  * \sa drmCreateContext() and drmDestroyContext().
  */
  */
 typedef struct drm_ctx {
 typedef struct drm_ctx {
-	drm_context_t	handle;
+	drm_context_t handle;
 	drm_ctx_flags_t flags;
 	drm_ctx_flags_t flags;
 } drm_ctx_t;
 } drm_ctx_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_RES_CTX ioctl argument type.
  * DRM_IOCTL_RES_CTX ioctl argument type.
  */
  */
 typedef struct drm_ctx_res {
 typedef struct drm_ctx_res {
-	int		count;
-	drm_ctx_t	__user *contexts;
+	int count;
+	drm_ctx_t __user *contexts;
 } drm_ctx_res_t;
 } drm_ctx_res_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_ADD_DRAW and DRM_IOCTL_RM_DRAW ioctl argument type.
  * DRM_IOCTL_ADD_DRAW and DRM_IOCTL_RM_DRAW ioctl argument type.
  */
  */
 typedef struct drm_draw {
 typedef struct drm_draw {
-	drm_drawable_t	handle;
+	drm_drawable_t handle;
 } drm_draw_t;
 } drm_draw_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type.
  * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type.
  */
  */
 typedef struct drm_auth {
 typedef struct drm_auth {
-	drm_magic_t	magic;
+	drm_magic_t magic;
 } drm_auth_t;
 } drm_auth_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_IRQ_BUSID ioctl argument type.
  * DRM_IOCTL_IRQ_BUSID ioctl argument type.
  *
  *
@@ -495,24 +463,20 @@ typedef struct drm_irq_busid {
 	int funcnum;	/**< function number */
 	int funcnum;	/**< function number */
 } drm_irq_busid_t;
 } drm_irq_busid_t;
 
 
-
 typedef enum {
 typedef enum {
-    _DRM_VBLANK_ABSOLUTE = 0x0,		/**< Wait for specific vblank sequence number */
-    _DRM_VBLANK_RELATIVE = 0x1,		/**< Wait for given number of vblanks */
-    _DRM_VBLANK_SIGNAL   = 0x40000000	/**< Send signal instead of blocking */
+	_DRM_VBLANK_ABSOLUTE = 0x0,	/**< Wait for specific vblank sequence number */
+	_DRM_VBLANK_RELATIVE = 0x1,	/**< Wait for given number of vblanks */
+	_DRM_VBLANK_SIGNAL = 0x40000000	/**< Send signal instead of blocking */
 } drm_vblank_seq_type_t;
 } drm_vblank_seq_type_t;
 
 
-
 #define _DRM_VBLANK_FLAGS_MASK _DRM_VBLANK_SIGNAL
 #define _DRM_VBLANK_FLAGS_MASK _DRM_VBLANK_SIGNAL
 
 
-
 struct drm_wait_vblank_request {
 struct drm_wait_vblank_request {
 	drm_vblank_seq_type_t type;
 	drm_vblank_seq_type_t type;
 	unsigned int sequence;
 	unsigned int sequence;
 	unsigned long signal;
 	unsigned long signal;
 };
 };
 
 
-
 struct drm_wait_vblank_reply {
 struct drm_wait_vblank_reply {
 	drm_vblank_seq_type_t type;
 	drm_vblank_seq_type_t type;
 	unsigned int sequence;
 	unsigned int sequence;
@@ -520,7 +484,6 @@ struct drm_wait_vblank_reply {
 	long tval_usec;
 	long tval_usec;
 };
 };
 
 
-
 /**
 /**
  * DRM_IOCTL_WAIT_VBLANK ioctl argument type.
  * DRM_IOCTL_WAIT_VBLANK ioctl argument type.
  *
  *
@@ -531,7 +494,6 @@ typedef union drm_wait_vblank {
 	struct drm_wait_vblank_reply reply;
 	struct drm_wait_vblank_reply reply;
 } drm_wait_vblank_t;
 } drm_wait_vblank_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_AGP_ENABLE ioctl argument type.
  * DRM_IOCTL_AGP_ENABLE ioctl argument type.
  *
  *
@@ -541,7 +503,6 @@ typedef struct drm_agp_mode {
 	unsigned long mode;	/**< AGP mode */
 	unsigned long mode;	/**< AGP mode */
 } drm_agp_mode_t;
 } drm_agp_mode_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_AGP_ALLOC and DRM_IOCTL_AGP_FREE ioctls argument type.
  * DRM_IOCTL_AGP_ALLOC and DRM_IOCTL_AGP_FREE ioctls argument type.
  *
  *
@@ -550,22 +511,20 @@ typedef struct drm_agp_mode {
 typedef struct drm_agp_buffer {
 typedef struct drm_agp_buffer {
 	unsigned long size;	/**< In bytes -- will round to page boundary */
 	unsigned long size;	/**< In bytes -- will round to page boundary */
 	unsigned long handle;	/**< Used for binding / unbinding */
 	unsigned long handle;	/**< Used for binding / unbinding */
-	unsigned long type;     /**< Type of memory to allocate */
-        unsigned long physical; /**< Physical used by i810 */
+	unsigned long type;	/**< Type of memory to allocate */
+	unsigned long physical;	/**< Physical used by i810 */
 } drm_agp_buffer_t;
 } drm_agp_buffer_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_AGP_BIND and DRM_IOCTL_AGP_UNBIND ioctls argument type.
  * DRM_IOCTL_AGP_BIND and DRM_IOCTL_AGP_UNBIND ioctls argument type.
  *
  *
  * \sa drmAgpBind() and drmAgpUnbind().
  * \sa drmAgpBind() and drmAgpUnbind().
  */
  */
 typedef struct drm_agp_binding {
 typedef struct drm_agp_binding {
-	unsigned long handle;   /**< From drm_agp_buffer */
+	unsigned long handle;	/**< From drm_agp_buffer */
 	unsigned long offset;	/**< In bytes -- will round to page boundary */
 	unsigned long offset;	/**< In bytes -- will round to page boundary */
 } drm_agp_binding_t;
 } drm_agp_binding_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_AGP_INFO ioctl argument type.
  * DRM_IOCTL_AGP_INFO ioctl argument type.
  *
  *
@@ -574,20 +533,19 @@ typedef struct drm_agp_binding {
  * drmAgpVendorId() and drmAgpDeviceId().
  * drmAgpVendorId() and drmAgpDeviceId().
  */
  */
 typedef struct drm_agp_info {
 typedef struct drm_agp_info {
-	int            agp_version_major;
-	int            agp_version_minor;
-	unsigned long  mode;
-	unsigned long  aperture_base;  /* physical address */
-	unsigned long  aperture_size;  /* bytes */
-	unsigned long  memory_allowed; /* bytes */
-	unsigned long  memory_used;
-
-				/* PCI information */
+	int agp_version_major;
+	int agp_version_minor;
+	unsigned long mode;
+	unsigned long aperture_base;	/* physical address */
+	unsigned long aperture_size;	/* bytes */
+	unsigned long memory_allowed;	/* bytes */
+	unsigned long memory_used;
+
+	/* PCI information */
 	unsigned short id_vendor;
 	unsigned short id_vendor;
 	unsigned short id_device;
 	unsigned short id_device;
 } drm_agp_info_t;
 } drm_agp_info_t;
 
 
-
 /**
 /**
  * DRM_IOCTL_SG_ALLOC ioctl argument type.
  * DRM_IOCTL_SG_ALLOC ioctl argument type.
  */
  */
@@ -606,7 +564,6 @@ typedef struct drm_set_version {
 	int drm_dd_minor;
 	int drm_dd_minor;
 } drm_set_version_t;
 } drm_set_version_t;
 
 
-
 #define DRM_IOCTL_BASE			'd'
 #define DRM_IOCTL_BASE			'd'
 #define DRM_IO(nr)			_IO(DRM_IOCTL_BASE,nr)
 #define DRM_IO(nr)			_IO(DRM_IOCTL_BASE,nr)
 #define DRM_IOR(nr,type)		_IOR(DRM_IOCTL_BASE,nr,type)
 #define DRM_IOR(nr,type)		_IOR(DRM_IOCTL_BASE,nr,type)

+ 446 - 440
drivers/char/drm/drmP.h

@@ -1,7 +1,7 @@
 /**
 /**
- * \file drmP.h 
+ * \file drmP.h
  * Private header for Direct Rendering Manager
  * Private header for Direct Rendering Manager
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
  */
@@ -43,7 +43,7 @@
  * before static inline funcs in wait.h. Doing this so we
  * before static inline funcs in wait.h. Doing this so we
  * can build the DRM (part of PI DRI). 4/21/2000 S + B */
  * can build the DRM (part of PI DRI). 4/21/2000 S + B */
 #include <asm/current.h>
 #include <asm/current.h>
-#endif /* __alpha__ */
+#endif				/* __alpha__ */
 #include <linux/config.h>
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/kernel.h>
@@ -58,7 +58,7 @@
 #include <linux/mm.h>
 #include <linux/mm.h>
 #include <linux/cdev.h>
 #include <linux/cdev.h>
 #if defined(__alpha__) || defined(__powerpc__)
 #if defined(__alpha__) || defined(__powerpc__)
-#include <asm/pgtable.h> /* For pte_wrprotect */
+#include <asm/pgtable.h>	/* For pte_wrprotect */
 #endif
 #endif
 #include <asm/io.h>
 #include <asm/io.h>
 #include <asm/mman.h>
 #include <asm/mman.h>
@@ -108,7 +108,6 @@
 #define DRM_KERNEL_CONTEXT    0	 /**< Change drm_resctx if changed */
 #define DRM_KERNEL_CONTEXT    0	 /**< Change drm_resctx if changed */
 #define DRM_RESERVED_CONTEXTS 1	 /**< Change drm_resctx if changed */
 #define DRM_RESERVED_CONTEXTS 1	 /**< Change drm_resctx if changed */
 #define DRM_LOOPING_LIMIT     5000000
 #define DRM_LOOPING_LIMIT     5000000
-#define DRM_BSZ		      1024 /**< Buffer size for /dev/drm? output */
 #define DRM_TIME_SLICE	      (HZ/20)  /**< Time slice for GLXContexts */
 #define DRM_TIME_SLICE	      (HZ/20)  /**< Time slice for GLXContexts */
 #define DRM_LOCK_SLICE	      1	/**< Time slice for lock, in jiffies */
 #define DRM_LOCK_SLICE	      1	/**< Time slice for lock, in jiffies */
 
 
@@ -138,16 +137,15 @@
 #define DRM_MEM_CTXLIST  21
 #define DRM_MEM_CTXLIST  21
 
 
 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
-	
-/*@}*/
 
 
+/*@}*/
 
 
 /***********************************************************************/
 /***********************************************************************/
 /** \name Backward compatibility section */
 /** \name Backward compatibility section */
 /*@{*/
 /*@{*/
 
 
 #ifndef MODULE_LICENSE
 #ifndef MODULE_LICENSE
-#define MODULE_LICENSE(x) 
+#define MODULE_LICENSE(x)
 #endif
 #endif
 
 
 #ifndef preempt_disable
 #ifndef preempt_disable
@@ -155,7 +153,7 @@
 #define preempt_enable()
 #define preempt_enable()
 #endif
 #endif
 
 
-#ifndef pte_offset_map 
+#ifndef pte_offset_map
 #define pte_offset_map pte_offset
 #define pte_offset_map pte_offset
 #define pte_unmap(pte)
 #define pte_unmap(pte)
 #endif
 #endif
@@ -166,7 +164,6 @@
 
 
 /*@}*/
 /*@}*/
 
 
-
 /***********************************************************************/
 /***********************************************************************/
 /** \name Macros to make printk easier */
 /** \name Macros to make printk easier */
 /*@{*/
 /*@{*/
@@ -195,7 +192,7 @@
 
 
 /**
 /**
  * Debug output.
  * Debug output.
- * 
+ *
  * \param fmt printf() like format string.
  * \param fmt printf() like format string.
  * \param arg arguments
  * \param arg arguments
  */
  */
@@ -223,14 +220,13 @@
 
 
 /*@}*/
 /*@}*/
 
 
-
 /***********************************************************************/
 /***********************************************************************/
 /** \name Internal types and structures */
 /** \name Internal types and structures */
 /*@{*/
 /*@{*/
 
 
-#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
-#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
-#define DRM_MAX(a,b) ((a)>(b)?(a):(b))
+#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
+#define DRM_MIN(a,b) min(a,b)
+#define DRM_MAX(a,b) max(a,b)
 
 
 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
@@ -275,7 +271,7 @@ do {									\
 		if ( copy_to_user( name, value, len ) )			\
 		if ( copy_to_user( name, value, len ) )			\
 			return -EFAULT;					\
 			return -EFAULT;					\
 	}
 	}
-	
+
 /**
 /**
  * Ioctl function type.
  * Ioctl function type.
  *
  *
@@ -284,25 +280,25 @@ do {									\
  * \param cmd command.
  * \param cmd command.
  * \param arg argument.
  * \param arg argument.
  */
  */
-typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
-			 unsigned int cmd, unsigned long arg );
+typedef int drm_ioctl_t(struct inode *inode, struct file *filp,
+			unsigned int cmd, unsigned long arg);
 
 
 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
 			       unsigned long arg);
 			       unsigned long arg);
 
 
 typedef struct drm_ioctl_desc {
 typedef struct drm_ioctl_desc {
-	drm_ioctl_t	     *func;
-	int		     auth_needed;
-	int		     root_only;
+	drm_ioctl_t *func;
+	int auth_needed;
+	int root_only;
 } drm_ioctl_desc_t;
 } drm_ioctl_desc_t;
 
 
 typedef struct drm_devstate {
 typedef struct drm_devstate {
-	pid_t		  owner;	/**< X server pid holding x_lock */
+	pid_t owner;			/**< X server pid holding x_lock */
 } drm_devstate_t;
 } drm_devstate_t;
 
 
 typedef struct drm_magic_entry {
 typedef struct drm_magic_entry {
-	drm_magic_t	       magic;
-	struct drm_file	       *priv;
+	drm_magic_t magic;
+	struct drm_file *priv;
 	struct drm_magic_entry *next;
 	struct drm_magic_entry *next;
 } drm_magic_entry_t;
 } drm_magic_entry_t;
 
 
@@ -313,111 +309,110 @@ typedef struct drm_magic_head {
 
 
 typedef struct drm_vma_entry {
 typedef struct drm_vma_entry {
 	struct vm_area_struct *vma;
 	struct vm_area_struct *vma;
-	struct drm_vma_entry  *next;
-	pid_t		      pid;
+	struct drm_vma_entry *next;
+	pid_t pid;
 } drm_vma_entry_t;
 } drm_vma_entry_t;
 
 
 /**
 /**
  * DMA buffer.
  * DMA buffer.
  */
  */
 typedef struct drm_buf {
 typedef struct drm_buf {
-	int		  idx;	       /**< Index into master buflist */
-	int		  total;       /**< Buffer size */
-	int		  order;       /**< log-base-2(total) */
-	int		  used;	       /**< Amount of buffer in use (for DMA) */
-	unsigned long	  offset;      /**< Byte offset (used internally) */
-	void		  *address;    /**< Address of buffer */
-	unsigned long	  bus_address; /**< Bus address of buffer */
-	struct drm_buf	  *next;       /**< Kernel-only: used for free list */
-	__volatile__ int  waiting;     /**< On kernel DMA queue */
-	__volatile__ int  pending;     /**< On hardware DMA queue */
+	int idx;		       /**< Index into master buflist */
+	int total;		       /**< Buffer size */
+	int order;		       /**< log-base-2(total) */
+	int used;		       /**< Amount of buffer in use (for DMA) */
+	unsigned long offset;	       /**< Byte offset (used internally) */
+	void *address;		       /**< Address of buffer */
+	unsigned long bus_address;     /**< Bus address of buffer */
+	struct drm_buf *next;	       /**< Kernel-only: used for free list */
+	__volatile__ int waiting;      /**< On kernel DMA queue */
+	__volatile__ int pending;      /**< On hardware DMA queue */
 	wait_queue_head_t dma_wait;    /**< Processes waiting */
 	wait_queue_head_t dma_wait;    /**< Processes waiting */
-	struct file       *filp;       /**< Pointer to holding file descr */
-	int		  context;     /**< Kernel queue for this buffer */
-	int		  while_locked;/**< Dispatch this buffer while locked */
+	struct file *filp;	       /**< Pointer to holding file descr */
+	int context;		       /**< Kernel queue for this buffer */
+	int while_locked;	       /**< Dispatch this buffer while locked */
 	enum {
 	enum {
-		DRM_LIST_NONE	 = 0,
-		DRM_LIST_FREE	 = 1,
-		DRM_LIST_WAIT	 = 2,
-		DRM_LIST_PEND	 = 3,
-		DRM_LIST_PRIO	 = 4,
+		DRM_LIST_NONE = 0,
+		DRM_LIST_FREE = 1,
+		DRM_LIST_WAIT = 2,
+		DRM_LIST_PEND = 3,
+		DRM_LIST_PRIO = 4,
 		DRM_LIST_RECLAIM = 5
 		DRM_LIST_RECLAIM = 5
-	}		  list;	       /**< Which list we're on */
+	} list;			       /**< Which list we're on */
 
 
-	int		  dev_priv_size; /**< Size of buffer private storage */
-	void		  *dev_private;  /**< Per-buffer private storage */
+	int dev_priv_size;		 /**< Size of buffer private storage */
+	void *dev_private;		 /**< Per-buffer private storage */
 } drm_buf_t;
 } drm_buf_t;
 
 
-
 /** bufs is one longer than it has to be */
 /** bufs is one longer than it has to be */
 typedef struct drm_waitlist {
 typedef struct drm_waitlist {
-	int		  count;	/**< Number of possible buffers */
-	drm_buf_t	  **bufs;	/**< List of pointers to buffers */
-	drm_buf_t	  **rp;		/**< Read pointer */
-	drm_buf_t	  **wp;		/**< Write pointer */
-	drm_buf_t	  **end;	/**< End pointer */
-	spinlock_t	  read_lock;
-	spinlock_t	  write_lock;
+	int count;			/**< Number of possible buffers */
+	drm_buf_t **bufs;		/**< List of pointers to buffers */
+	drm_buf_t **rp;			/**< Read pointer */
+	drm_buf_t **wp;			/**< Write pointer */
+	drm_buf_t **end;		/**< End pointer */
+	spinlock_t read_lock;
+	spinlock_t write_lock;
 } drm_waitlist_t;
 } drm_waitlist_t;
 
 
 typedef struct drm_freelist {
 typedef struct drm_freelist {
-	int		  initialized; /**< Freelist in use */
-	atomic_t	  count;       /**< Number of free buffers */
-	drm_buf_t	  *next;       /**< End pointer */
+	int initialized;	       /**< Freelist in use */
+	atomic_t count;		       /**< Number of free buffers */
+	drm_buf_t *next;	       /**< End pointer */
 
 
 	wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
 	wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
-	int		  low_mark;    /**< Low water mark */
-	int		  high_mark;   /**< High water mark */
-	atomic_t	  wfh;	       /**< If waiting for high mark */
-	spinlock_t        lock;
+	int low_mark;		       /**< Low water mark */
+	int high_mark;		       /**< High water mark */
+	atomic_t wfh;		       /**< If waiting for high mark */
+	spinlock_t lock;
 } drm_freelist_t;
 } drm_freelist_t;
 
 
 /**
 /**
  * Buffer entry.  There is one of this for each buffer size order.
  * Buffer entry.  There is one of this for each buffer size order.
  */
  */
 typedef struct drm_buf_entry {
 typedef struct drm_buf_entry {
-	int		  buf_size;	/**< size */
-	int		  buf_count;	/**< number of buffers */
-	drm_buf_t	  *buflist;	/**< buffer list */
-	int		  seg_count;
-	int		  page_order;
-	unsigned long	  *seglist;
-
-	drm_freelist_t	  freelist;
+	int buf_size;			/**< size */
+	int buf_count;			/**< number of buffers */
+	drm_buf_t *buflist;		/**< buffer list */
+	int seg_count;
+	int page_order;
+	unsigned long *seglist;
+
+	drm_freelist_t freelist;
 } drm_buf_entry_t;
 } drm_buf_entry_t;
 
 
 /** File private data */
 /** File private data */
 typedef struct drm_file {
 typedef struct drm_file {
-	int		  authenticated;
-	int		  minor;
-	pid_t		  pid;
-	uid_t		  uid;
-	drm_magic_t	  magic;
-	unsigned long	  ioctl_count;
-	struct drm_file	  *next;
-	struct drm_file	  *prev;
-	struct drm_head   *head;
-	int 		  remove_auth_on_close;
-	unsigned long     lock_count;
-	void              *driver_priv;
+	int authenticated;
+	int minor;
+	pid_t pid;
+	uid_t uid;
+	drm_magic_t magic;
+	unsigned long ioctl_count;
+	struct drm_file *next;
+	struct drm_file *prev;
+	struct drm_head *head;
+	int remove_auth_on_close;
+	unsigned long lock_count;
+	void *driver_priv;
 } drm_file_t;
 } drm_file_t;
 
 
 /** Wait queue */
 /** Wait queue */
 typedef struct drm_queue {
 typedef struct drm_queue {
-	atomic_t	  use_count;	/**< Outstanding uses (+1) */
-	atomic_t	  finalization;	/**< Finalization in progress */
-	atomic_t	  block_count;	/**< Count of processes waiting */
-	atomic_t	  block_read;	/**< Queue blocked for reads */
+	atomic_t use_count;		/**< Outstanding uses (+1) */
+	atomic_t finalization;		/**< Finalization in progress */
+	atomic_t block_count;		/**< Count of processes waiting */
+	atomic_t block_read;		/**< Queue blocked for reads */
 	wait_queue_head_t read_queue;	/**< Processes waiting on block_read */
 	wait_queue_head_t read_queue;	/**< Processes waiting on block_read */
-	atomic_t	  block_write;	/**< Queue blocked for writes */
+	atomic_t block_write;		/**< Queue blocked for writes */
 	wait_queue_head_t write_queue;	/**< Processes waiting on block_write */
 	wait_queue_head_t write_queue;	/**< Processes waiting on block_write */
 #if 1
 #if 1
-	atomic_t	  total_queued;	/**< Total queued statistic */
-	atomic_t	  total_flushed;/**< Total flushes statistic */
-	atomic_t	  total_locks;	/**< Total locks statistics */
+	atomic_t total_queued;		/**< Total queued statistic */
+	atomic_t total_flushed;		/**< Total flushes statistic */
+	atomic_t total_locks;		/**< Total locks statistics */
 #endif
 #endif
-	drm_ctx_flags_t	  flags;	/**< Context preserving and 2D-only */
-	drm_waitlist_t	  waitlist;	/**< Pending buffers */
+	drm_ctx_flags_t flags;		/**< Context preserving and 2D-only */
+	drm_waitlist_t waitlist;	/**< Pending buffers */
 	wait_queue_head_t flush_queue;	/**< Processes waiting until flush */
 	wait_queue_head_t flush_queue;	/**< Processes waiting until flush */
 } drm_queue_t;
 } drm_queue_t;
 
 
@@ -425,10 +420,10 @@ typedef struct drm_queue {
  * Lock data.
  * Lock data.
  */
  */
 typedef struct drm_lock_data {
 typedef struct drm_lock_data {
-	drm_hw_lock_t	  *hw_lock;	/**< Hardware lock */
-	struct file       *filp;	/**< File descr of lock holder (0=kernel) */
+	drm_hw_lock_t *hw_lock;		/**< Hardware lock */
+	struct file *filp;		/**< File descr of lock holder (0=kernel) */
 	wait_queue_head_t lock_queue;	/**< Queue of blocked processes */
 	wait_queue_head_t lock_queue;	/**< Queue of blocked processes */
-	unsigned long	  lock_time;	/**< Time of last lock in jiffies */
+	unsigned long lock_time;	/**< Time of last lock in jiffies */
 } drm_lock_data_t;
 } drm_lock_data_t;
 
 
 /**
 /**
@@ -436,29 +431,29 @@ typedef struct drm_lock_data {
  */
  */
 typedef struct drm_device_dma {
 typedef struct drm_device_dma {
 
 
-	drm_buf_entry_t	  bufs[DRM_MAX_ORDER+1];	/**< buffers, grouped by their size order */
-	int		  buf_count;	/**< total number of buffers */
-	drm_buf_t	  **buflist;	/**< Vector of pointers into drm_device_dma::bufs */
-	int		  seg_count;
-	int		  page_count;	/**< number of pages */
-	unsigned long	  *pagelist;	/**< page list */
-	unsigned long	  byte_count;
+	drm_buf_entry_t bufs[DRM_MAX_ORDER + 1];	/**< buffers, grouped by their size order */
+	int buf_count;			/**< total number of buffers */
+	drm_buf_t **buflist;		/**< Vector of pointers into drm_device_dma::bufs */
+	int seg_count;
+	int page_count;			/**< number of pages */
+	unsigned long *pagelist;	/**< page list */
+	unsigned long byte_count;
 	enum {
 	enum {
 		_DRM_DMA_USE_AGP = 0x01,
 		_DRM_DMA_USE_AGP = 0x01,
-		_DRM_DMA_USE_SG  = 0x02,
-		_DRM_DMA_USE_FB  = 0x04
+		_DRM_DMA_USE_SG = 0x02,
+		_DRM_DMA_USE_FB = 0x04
 	} flags;
 	} flags;
 
 
 } drm_device_dma_t;
 } drm_device_dma_t;
 
 
-/** 
+/**
  * AGP memory entry.  Stored as a doubly linked list.
  * AGP memory entry.  Stored as a doubly linked list.
  */
  */
 typedef struct drm_agp_mem {
 typedef struct drm_agp_mem {
-	unsigned long      handle;	/**< handle */
-	DRM_AGP_MEM        *memory;	
-	unsigned long      bound;	/**< address */
-	int                pages;
+	unsigned long handle;		/**< handle */
+	DRM_AGP_MEM *memory;
+	unsigned long bound;		/**< address */
+	int pages;
 	struct drm_agp_mem *prev;	/**< previous entry */
 	struct drm_agp_mem *prev;	/**< previous entry */
 	struct drm_agp_mem *next;	/**< next entry */
 	struct drm_agp_mem *next;	/**< next entry */
 } drm_agp_mem_t;
 } drm_agp_mem_t;
@@ -469,31 +464,31 @@ typedef struct drm_agp_mem {
  * \sa drm_agp_init() and drm_device::agp.
  * \sa drm_agp_init() and drm_device::agp.
  */
  */
 typedef struct drm_agp_head {
 typedef struct drm_agp_head {
-	DRM_AGP_KERN       agp_info;	/**< AGP device information */
-	drm_agp_mem_t      *memory;	/**< memory entries */
-	unsigned long      mode;	/**< AGP mode */
-	struct agp_bridge_data  *bridge;
-	int                enabled;	/**< whether the AGP bus as been enabled */
-	int                acquired;	/**< whether the AGP device has been acquired */
-	unsigned long      base;
-   	int 		   agp_mtrr;
-	int		   cant_use_aperture;
-	unsigned long	   page_mask;
+	DRM_AGP_KERN agp_info;		/**< AGP device information */
+	drm_agp_mem_t *memory;		/**< memory entries */
+	unsigned long mode;		/**< AGP mode */
+	struct agp_bridge_data *bridge;
+	int enabled;			/**< whether the AGP bus as been enabled */
+	int acquired;			/**< whether the AGP device has been acquired */
+	unsigned long base;
+	int agp_mtrr;
+	int cant_use_aperture;
+	unsigned long page_mask;
 } drm_agp_head_t;
 } drm_agp_head_t;
 
 
 /**
 /**
  * Scatter-gather memory.
  * Scatter-gather memory.
  */
  */
 typedef struct drm_sg_mem {
 typedef struct drm_sg_mem {
-	unsigned long   handle;
-	void            *virtual;
-	int             pages;
-	struct page     **pagelist;
-	dma_addr_t	*busaddr;
+	unsigned long handle;
+	void *virtual;
+	int pages;
+	struct page **pagelist;
+	dma_addr_t *busaddr;
 } drm_sg_mem_t;
 } drm_sg_mem_t;
 
 
 typedef struct drm_sigdata {
 typedef struct drm_sigdata {
-	int           context;
+	int context;
 	drm_hw_lock_t *lock;
 	drm_hw_lock_t *lock;
 } drm_sigdata_t;
 } drm_sigdata_t;
 
 
@@ -507,8 +502,8 @@ typedef struct drm_dma_handle {
  * Mappings list
  * Mappings list
  */
  */
 typedef struct drm_map_list {
 typedef struct drm_map_list {
-	struct list_head	head;	/**< list head */
-	drm_map_t		*map;	/**< mapping */
+	struct list_head head;		/**< list head */
+	drm_map_t *map;			/**< mapping */
 	unsigned int user_token;
 	unsigned int user_token;
 } drm_map_list_t;
 } drm_map_list_t;
 
 
@@ -518,19 +513,28 @@ typedef drm_map_t drm_local_map_t;
  * Context handle list
  * Context handle list
  */
  */
 typedef struct drm_ctx_list {
 typedef struct drm_ctx_list {
-	struct list_head	head;   /**< list head */
-	drm_context_t		handle; /**< context handle */
-	drm_file_t		*tag;   /**< associated fd private data */
+	struct list_head head;		/**< list head */
+	drm_context_t handle;		/**< context handle */
+	drm_file_t *tag;		/**< associated fd private data */
 } drm_ctx_list_t;
 } drm_ctx_list_t;
 
 
-
 typedef struct drm_vbl_sig {
 typedef struct drm_vbl_sig {
-	struct list_head	head;
-	unsigned int		sequence;
-	struct siginfo		info;
-	struct task_struct	*task;
+	struct list_head head;
+	unsigned int sequence;
+	struct siginfo info;
+	struct task_struct *task;
 } drm_vbl_sig_t;
 } drm_vbl_sig_t;
 
 
+/* location of GART table */
+#define DRM_ATI_GART_MAIN 1
+#define DRM_ATI_GART_FB   2
+
+typedef struct ati_pcigart_info {
+	int gart_table_location;
+	int is_pcie;
+	unsigned long addr;
+	dma_addr_t bus_addr;
+} drm_ati_pcigart_info;
 
 
 /**
 /**
  * DRM driver structure. This structure represent the common code for
  * DRM driver structure. This structure represent the common code for
@@ -540,24 +544,26 @@ typedef struct drm_vbl_sig {
 struct drm_device;
 struct drm_device;
 
 
 struct drm_driver {
 struct drm_driver {
-	int (*preinit)(struct drm_device *, unsigned long flags);
-	void (*prerelease)(struct drm_device *, struct file *filp);
-	void (*pretakedown)(struct drm_device *);
-	int (*postcleanup)(struct drm_device *);
-	int (*presetup)(struct drm_device *);
-	int (*postsetup)(struct drm_device *);
- 	int (*dma_ioctl)( DRM_IOCTL_ARGS );
-	int (*open_helper)(struct drm_device *, drm_file_t *);
-	void (*free_filp_priv)(struct drm_device *, drm_file_t *);
-	void (*release)(struct drm_device *, struct file *filp);
-	void (*dma_ready)(struct drm_device *);
-	int (*dma_quiescent)(struct drm_device *);
-	int (*context_ctor)(struct drm_device *dev, int context);
- 	int (*context_dtor)(struct drm_device *dev, int context);
- 	int (*kernel_context_switch)(struct drm_device *dev, int old, int new);
-	void (*kernel_context_switch_unlock)(struct drm_device *dev, drm_lock_t *lock);
-	int (*vblank_wait)(struct drm_device *dev, unsigned int *sequence);
-	
+	int (*preinit) (struct drm_device *, unsigned long flags);
+	void (*prerelease) (struct drm_device *, struct file * filp);
+	void (*pretakedown) (struct drm_device *);
+	int (*postcleanup) (struct drm_device *);
+	int (*presetup) (struct drm_device *);
+	int (*postsetup) (struct drm_device *);
+	int (*dma_ioctl) (DRM_IOCTL_ARGS);
+	int (*open_helper) (struct drm_device *, drm_file_t *);
+	void (*free_filp_priv) (struct drm_device *, drm_file_t *);
+	void (*release) (struct drm_device *, struct file * filp);
+	void (*dma_ready) (struct drm_device *);
+	int (*dma_quiescent) (struct drm_device *);
+	int (*context_ctor) (struct drm_device * dev, int context);
+	int (*context_dtor) (struct drm_device * dev, int context);
+	int (*kernel_context_switch) (struct drm_device * dev, int old,
+				      int new);
+	void (*kernel_context_switch_unlock) (struct drm_device * dev,
+					      drm_lock_t * lock);
+	int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
+
 	/**
 	/**
 	 * Called by \c drm_device_is_agp.  Typically used to determine if a
 	 * Called by \c drm_device_is_agp.  Typically used to determine if a
 	 * card is really attached to AGP or not.
 	 * card is really attached to AGP or not.
@@ -572,17 +578,17 @@ struct drm_driver {
 	int (*device_is_agp) (struct drm_device * dev);
 	int (*device_is_agp) (struct drm_device * dev);
 
 
 	/* these have to be filled in */
 	/* these have to be filled in */
-  
- 	int (*postinit)(struct drm_device *, unsigned long flags);
-	irqreturn_t (*irq_handler)( DRM_IRQ_ARGS );
- 	void (*irq_preinstall)(struct drm_device *dev);
- 	void (*irq_postinstall)(struct drm_device *dev);
- 	void (*irq_uninstall)(struct drm_device *dev);
-	void (*reclaim_buffers)(struct drm_device *dev, struct file *filp);
-	unsigned long (*get_map_ofs)(drm_map_t *map);
-	unsigned long (*get_reg_ofs)(struct drm_device *dev);
-	void (*set_version)(struct drm_device *dev, drm_set_version_t *sv);
- 	int (*version)(drm_version_t *version);
+
+	int (*postinit) (struct drm_device *, unsigned long flags);
+	 irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
+	void (*irq_preinstall) (struct drm_device * dev);
+	void (*irq_postinstall) (struct drm_device * dev);
+	void (*irq_uninstall) (struct drm_device * dev);
+	void (*reclaim_buffers) (struct drm_device * dev, struct file * filp);
+	unsigned long (*get_map_ofs) (drm_map_t * map);
+	unsigned long (*get_reg_ofs) (struct drm_device * dev);
+	void (*set_version) (struct drm_device * dev, drm_set_version_t * sv);
+	int (*version) (drm_version_t * version);
 	u32 driver_features;
 	u32 driver_features;
 	int dev_priv_size;
 	int dev_priv_size;
 	drm_ioctl_desc_t *ioctls;
 	drm_ioctl_desc_t *ioctls;
@@ -609,128 +615,125 @@ typedef struct drm_head {
  * may contain multiple heads.
  * may contain multiple heads.
  */
  */
 typedef struct drm_device {
 typedef struct drm_device {
-	char		  *unique;	/**< Unique identifier: e.g., busid */
-	int		  unique_len;	/**< Length of unique field */
-	char		  *devname;	/**< For /proc/interrupts */
-	int		  if_version;	/**< Highest interface version set */
+	char *unique;			/**< Unique identifier: e.g., busid */
+	int unique_len;			/**< Length of unique field */
+	char *devname;			/**< For /proc/interrupts */
+	int if_version;			/**< Highest interface version set */
 
 
-	int		  blocked;	/**< Blocked due to VC switch? */
+	int blocked;			/**< Blocked due to VC switch? */
 
 
 	/** \name Locks */
 	/** \name Locks */
-	/*@{*/
-	spinlock_t	  count_lock;	/**< For inuse, drm_device::open_count, drm_device::buf_use */
-	struct semaphore  struct_sem;	/**< For others */
-	/*@}*/
+	/*@{ */
+	spinlock_t count_lock;		/**< For inuse, drm_device::open_count, drm_device::buf_use */
+	struct semaphore struct_sem;	/**< For others */
+	/*@} */
 
 
 	/** \name Usage Counters */
 	/** \name Usage Counters */
-	/*@{*/
-	int		  open_count;	/**< Outstanding files open */
-	atomic_t	  ioctl_count;	/**< Outstanding IOCTLs pending */
-	atomic_t	  vma_count;	/**< Outstanding vma areas open */
-	int		  buf_use;	/**< Buffers in use -- cannot alloc */
-	atomic_t	  buf_alloc;	/**< Buffer allocation in progress */
-	/*@}*/
+	/*@{ */
+	int open_count;			/**< Outstanding files open */
+	atomic_t ioctl_count;		/**< Outstanding IOCTLs pending */
+	atomic_t vma_count;		/**< Outstanding vma areas open */
+	int buf_use;			/**< Buffers in use -- cannot alloc */
+	atomic_t buf_alloc;		/**< Buffer allocation in progress */
+	/*@} */
 
 
 	/** \name Performance counters */
 	/** \name Performance counters */
-	/*@{*/
-	unsigned long     counters;
-	drm_stat_type_t   types[15];
-	atomic_t          counts[15];
-	/*@}*/
+	/*@{ */
+	unsigned long counters;
+	drm_stat_type_t types[15];
+	atomic_t counts[15];
+	/*@} */
 
 
 	/** \name Authentication */
 	/** \name Authentication */
-	/*@{*/
-	drm_file_t	  *file_first;	/**< file list head */
-	drm_file_t	  *file_last;	/**< file list tail */
-	drm_magic_head_t  magiclist[DRM_HASH_SIZE];	/**< magic hash table */
-	/*@}*/
+	/*@{ */
+	drm_file_t *file_first;		/**< file list head */
+	drm_file_t *file_last;		/**< file list tail */
+	drm_magic_head_t magiclist[DRM_HASH_SIZE];	/**< magic hash table */
+	/*@} */
 
 
 	/** \name Memory management */
 	/** \name Memory management */
-	/*@{*/
-	drm_map_list_t	  *maplist;	/**< Linked list of regions */
-	int		  map_count;	/**< Number of mappable regions */
+	/*@{ */
+	drm_map_list_t *maplist;	/**< Linked list of regions */
+	int map_count;			/**< Number of mappable regions */
 
 
 	/** \name Context handle management */
 	/** \name Context handle management */
-	/*@{*/
-	drm_ctx_list_t	  *ctxlist;	/**< Linked list of context handles */
-	int		  ctx_count;	/**< Number of context handles */
-	struct semaphore  ctxlist_sem;	/**< For ctxlist */
+	/*@{ */
+	drm_ctx_list_t *ctxlist;	/**< Linked list of context handles */
+	int ctx_count;			/**< Number of context handles */
+	struct semaphore ctxlist_sem;	/**< For ctxlist */
 
 
-	drm_map_t	  **context_sareas; /**< per-context SAREA's */
-	int		  max_context;
+	drm_map_t **context_sareas;	    /**< per-context SAREA's */
+	int max_context;
 
 
-	drm_vma_entry_t	  *vmalist;	/**< List of vmas (for debugging) */
-	drm_lock_data_t	  lock;		/**< Information on hardware lock */
-	/*@}*/
+	drm_vma_entry_t *vmalist;	/**< List of vmas (for debugging) */
+	drm_lock_data_t lock;		/**< Information on hardware lock */
+	/*@} */
 
 
 	/** \name DMA queues (contexts) */
 	/** \name DMA queues (contexts) */
-	/*@{*/
-	int		  queue_count;	/**< Number of active DMA queues */
-	int		  queue_reserved; /**< Number of reserved DMA queues */
-	int		  queue_slots;	/**< Actual length of queuelist */
-	drm_queue_t	  **queuelist;	/**< Vector of pointers to DMA queues */
-	drm_device_dma_t  *dma;		/**< Optional pointer for DMA support */
-	/*@}*/
+	/*@{ */
+	int queue_count;		/**< Number of active DMA queues */
+	int queue_reserved;		  /**< Number of reserved DMA queues */
+	int queue_slots;		/**< Actual length of queuelist */
+	drm_queue_t **queuelist;	/**< Vector of pointers to DMA queues */
+	drm_device_dma_t *dma;		/**< Optional pointer for DMA support */
+	/*@} */
 
 
 	/** \name Context support */
 	/** \name Context support */
-	/*@{*/
-	int		  irq;		/**< Interrupt used by board */
-	int		  irq_enabled;	/**< True if irq handler is enabled */
+	/*@{ */
+	int irq;			/**< Interrupt used by board */
+	int irq_enabled;		/**< True if irq handler is enabled */
 	__volatile__ long context_flag;	/**< Context swapping flag */
 	__volatile__ long context_flag;	/**< Context swapping flag */
 	__volatile__ long interrupt_flag; /**< Interruption handler flag */
 	__volatile__ long interrupt_flag; /**< Interruption handler flag */
 	__volatile__ long dma_flag;	/**< DMA dispatch flag */
 	__volatile__ long dma_flag;	/**< DMA dispatch flag */
 	struct timer_list timer;	/**< Timer for delaying ctx switch */
 	struct timer_list timer;	/**< Timer for delaying ctx switch */
-	wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
-	int		  last_checked;	/**< Last context checked for DMA */
-	int		  last_context;	/**< Last current context */
-	unsigned long	  last_switch;	/**< jiffies at last context switch */
-	/*@}*/
-	
-	struct work_struct	work;
+	wait_queue_head_t context_wait;	/**< Processes waiting on ctx switch */
+	int last_checked;		/**< Last context checked for DMA */
+	int last_context;		/**< Last current context */
+	unsigned long last_switch;	/**< jiffies at last context switch */
+	/*@} */
+
+	struct work_struct work;
 	/** \name VBLANK IRQ support */
 	/** \name VBLANK IRQ support */
-	/*@{*/
-
-   	wait_queue_head_t vbl_queue;	/**< VBLANK wait queue */
-   	atomic_t          vbl_received;
-	spinlock_t        vbl_lock;
-	drm_vbl_sig_t     vbl_sigs;	/**< signal list to send on VBLANK */
-	unsigned int      vbl_pending;
-
-	/*@}*/
-	cycles_t	  ctx_start;
-	cycles_t	  lck_start;
-
-	char		  buf[DRM_BSZ]; /**< Output buffer */
-	char		  *buf_rp;	/**< Read pointer */
-	char		  *buf_wp;	/**< Write pointer */
-	char		  *buf_end;	/**< End pointer */
+	/*@{ */
+
+	wait_queue_head_t vbl_queue;	/**< VBLANK wait queue */
+	atomic_t vbl_received;
+	spinlock_t vbl_lock;
+	drm_vbl_sig_t vbl_sigs;		/**< signal list to send on VBLANK */
+	unsigned int vbl_pending;
+
+	/*@} */
+	cycles_t ctx_start;
+	cycles_t lck_start;
+
 	struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
 	struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
 	wait_queue_head_t buf_readers;	/**< Processes waiting to read */
 	wait_queue_head_t buf_readers;	/**< Processes waiting to read */
 	wait_queue_head_t buf_writers;	/**< Processes waiting to ctx switch */
 	wait_queue_head_t buf_writers;	/**< Processes waiting to ctx switch */
 
 
-	drm_agp_head_t    *agp;	/**< AGP data */
+	drm_agp_head_t *agp;	/**< AGP data */
 
 
-	struct pci_dev    *pdev;	/**< PCI device structure */
-	int               pci_domain;	/**< PCI bus domain number */
-	int               pci_bus;	/**< PCI bus number */
-	int               pci_slot;	/**< PCI slot number */
-	int               pci_func;	/**< PCI function number */
+	struct pci_dev *pdev;		/**< PCI device structure */
+	int pci_domain;			/**< PCI bus domain number */
+	int pci_bus;			/**< PCI bus number */
+	int pci_slot;			/**< PCI slot number */
+	int pci_func;			/**< PCI function number */
 #ifdef __alpha__
 #ifdef __alpha__
 	struct pci_controller *hose;
 	struct pci_controller *hose;
 #endif
 #endif
-	drm_sg_mem_t      *sg;  /**< Scatter gather memory */
-	unsigned long     *ctx_bitmap;	/**< context bitmap */
-	void		  *dev_private; /**< device private data */
-	drm_sigdata_t     sigdata; /**< For block_all_signals */
-	sigset_t          sigmask;
-
-	struct            drm_driver *driver;
-	drm_local_map_t   *agp_buffer_map;
+	drm_sg_mem_t *sg;	/**< Scatter gather memory */
+	unsigned long *ctx_bitmap;	/**< context bitmap */
+	void *dev_private;		/**< device private data */
+	drm_sigdata_t sigdata;	   /**< For block_all_signals */
+	sigset_t sigmask;
+
+	struct drm_driver *driver;
+	drm_local_map_t *agp_buffer_map;
 	unsigned int agp_buffer_token;
 	unsigned int agp_buffer_token;
 	drm_head_t primary;		/**< primary screen head */
 	drm_head_t primary;		/**< primary screen head */
 } drm_device_t;
 } drm_device_t;
 
 
-static __inline__ int drm_core_check_feature(struct drm_device *dev, int feature)
+static __inline__ int drm_core_check_feature(struct drm_device *dev,
+					     int feature)
 {
 {
 	return ((dev->driver->driver_features & feature) ? 1 : 0);
 	return ((dev->driver->driver_features & feature) ? 1 : 0);
 }
 }
@@ -738,7 +741,7 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev, int feature
 #if __OS_HAS_AGP
 #if __OS_HAS_AGP
 static inline int drm_core_has_AGP(struct drm_device *dev)
 static inline int drm_core_has_AGP(struct drm_device *dev)
 {
 {
-  return drm_core_check_feature(dev, DRIVER_USE_AGP);
+	return drm_core_check_feature(dev, DRIVER_USE_AGP);
 }
 }
 #else
 #else
 #define drm_core_has_AGP(dev) (0)
 #define drm_core_has_AGP(dev) (0)
@@ -747,7 +750,7 @@ static inline int drm_core_has_AGP(struct drm_device *dev)
 #if __OS_HAS_MTRR
 #if __OS_HAS_MTRR
 static inline int drm_core_has_MTRR(struct drm_device *dev)
 static inline int drm_core_has_MTRR(struct drm_device *dev)
 {
 {
-  return drm_core_check_feature(dev, DRIVER_USE_MTRR);
+	return drm_core_check_feature(dev, DRIVER_USE_MTRR);
 }
 }
 #else
 #else
 #define drm_core_has_MTRR(dev) (0)
 #define drm_core_has_MTRR(dev) (0)
@@ -758,234 +761,229 @@ static inline int drm_core_has_MTRR(struct drm_device *dev)
 /*@{*/
 /*@{*/
 
 
 				/* Misc. support (drm_init.h) */
 				/* Misc. support (drm_init.h) */
-extern int	     drm_flags;
-extern void	     drm_parse_options( char *s );
-extern int           drm_cpu_valid( void );
+extern int drm_flags;
+extern void drm_parse_options(char *s);
+extern int drm_cpu_valid(void);
 
 
 				/* Driver support (drm_drv.h) */
 				/* Driver support (drm_drv.h) */
-extern int           drm_init(struct drm_driver *driver);
-extern void          drm_exit(struct drm_driver *driver);
-extern int           drm_ioctl(struct inode *inode, struct file *filp,
-				unsigned int cmd, unsigned long arg);
-extern long	     drm_compat_ioctl(struct file *filp,
-				unsigned int cmd, unsigned long arg);
-extern int           drm_takedown(drm_device_t * dev);
+extern int drm_init(struct drm_driver *driver);
+extern void drm_exit(struct drm_driver *driver);
+extern int drm_ioctl(struct inode *inode, struct file *filp,
+		     unsigned int cmd, unsigned long arg);
+extern long drm_compat_ioctl(struct file *filp,
+			     unsigned int cmd, unsigned long arg);
+extern int drm_takedown(drm_device_t * dev);
 
 
 				/* Device support (drm_fops.h) */
 				/* Device support (drm_fops.h) */
-extern int           drm_open(struct inode *inode, struct file *filp);
-extern int           drm_stub_open(struct inode *inode, struct file *filp);
-extern int	     drm_flush(struct file *filp);
-extern int	     drm_fasync(int fd, struct file *filp, int on);
-extern int           drm_release(struct inode *inode, struct file *filp);
+extern int drm_open(struct inode *inode, struct file *filp);
+extern int drm_stub_open(struct inode *inode, struct file *filp);
+extern int drm_flush(struct file *filp);
+extern int drm_fasync(int fd, struct file *filp, int on);
+extern int drm_release(struct inode *inode, struct file *filp);
 
 
 				/* Mapping support (drm_vm.h) */
 				/* Mapping support (drm_vm.h) */
-extern int	     drm_mmap(struct file *filp, struct vm_area_struct *vma);
-extern unsigned int  drm_poll(struct file *filp, struct poll_table_struct *wait);
+extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
+extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
 
 
 				/* Memory management support (drm_memory.h) */
 				/* Memory management support (drm_memory.h) */
 #include "drm_memory.h"
 #include "drm_memory.h"
-extern void	     drm_mem_init(void);
-extern int	     drm_mem_info(char *buf, char **start, off_t offset,
-				   int request, int *eof, void *data);
-extern void	     *drm_realloc(void *oldpt, size_t oldsize, size_t size,
-				   int area);
+extern void drm_mem_init(void);
+extern int drm_mem_info(char *buf, char **start, off_t offset,
+			int request, int *eof, void *data);
+extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
 extern unsigned long drm_alloc_pages(int order, int area);
 extern unsigned long drm_alloc_pages(int order, int area);
-extern void	     drm_free_pages(unsigned long address, int order,
-				     int area);
-extern void	     *drm_ioremap(unsigned long offset, unsigned long size, drm_device_t *dev);
-extern void	     *drm_ioremap_nocache(unsigned long offset, unsigned long size,
-					   drm_device_t *dev);
-extern void	     drm_ioremapfree(void *pt, unsigned long size, drm_device_t *dev);
-
-extern DRM_AGP_MEM   *drm_alloc_agp(drm_device_t *dev, int pages, u32 type);
-extern int           drm_free_agp(DRM_AGP_MEM *handle, int pages);
-extern int           drm_bind_agp(DRM_AGP_MEM *handle, unsigned int start);
-extern int           drm_unbind_agp(DRM_AGP_MEM *handle);
+extern void drm_free_pages(unsigned long address, int order, int area);
+extern void *drm_ioremap(unsigned long offset, unsigned long size,
+			 drm_device_t * dev);
+extern void *drm_ioremap_nocache(unsigned long offset, unsigned long size,
+				 drm_device_t * dev);
+extern void drm_ioremapfree(void *pt, unsigned long size, drm_device_t * dev);
+
+extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type);
+extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
+extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
+extern int drm_unbind_agp(DRM_AGP_MEM * handle);
 
 
 				/* Misc. IOCTL support (drm_ioctl.h) */
 				/* Misc. IOCTL support (drm_ioctl.h) */
-extern int	     drm_irq_by_busid(struct inode *inode, struct file *filp,
-				       unsigned int cmd, unsigned long arg);
-extern int	     drm_getunique(struct inode *inode, struct file *filp,
-				    unsigned int cmd, unsigned long arg);
-extern int	     drm_setunique(struct inode *inode, struct file *filp,
-				    unsigned int cmd, unsigned long arg);
-extern int	     drm_getmap(struct inode *inode, struct file *filp,
-				 unsigned int cmd, unsigned long arg);
-extern int	     drm_getclient(struct inode *inode, struct file *filp,
-				    unsigned int cmd, unsigned long arg);
-extern int	     drm_getstats(struct inode *inode, struct file *filp,
-				   unsigned int cmd, unsigned long arg);
-extern int	     drm_setversion(struct inode *inode, struct file *filp,
-				     unsigned int cmd, unsigned long arg);
+extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
+			    unsigned int cmd, unsigned long arg);
+extern int drm_getunique(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg);
+extern int drm_setunique(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg);
+extern int drm_getmap(struct inode *inode, struct file *filp,
+		      unsigned int cmd, unsigned long arg);
+extern int drm_getclient(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg);
+extern int drm_getstats(struct inode *inode, struct file *filp,
+			unsigned int cmd, unsigned long arg);
+extern int drm_setversion(struct inode *inode, struct file *filp,
+			  unsigned int cmd, unsigned long arg);
 
 
 				/* Context IOCTL support (drm_context.h) */
 				/* Context IOCTL support (drm_context.h) */
-extern int	     drm_resctx( struct inode *inode, struct file *filp,
-				  unsigned int cmd, unsigned long arg );
-extern int	     drm_addctx( struct inode *inode, struct file *filp,
-				  unsigned int cmd, unsigned long arg );
-extern int	     drm_modctx( struct inode *inode, struct file *filp,
-				  unsigned int cmd, unsigned long arg );
-extern int	     drm_getctx( struct inode *inode, struct file *filp,
-				  unsigned int cmd, unsigned long arg );
-extern int	     drm_switchctx( struct inode *inode, struct file *filp,
-				     unsigned int cmd, unsigned long arg );
-extern int	     drm_newctx( struct inode *inode, struct file *filp,
-				  unsigned int cmd, unsigned long arg );
-extern int	     drm_rmctx( struct inode *inode, struct file *filp,
-				 unsigned int cmd, unsigned long arg );
-
-extern int	     drm_ctxbitmap_init( drm_device_t *dev );
-extern void	     drm_ctxbitmap_cleanup( drm_device_t *dev );
-extern void          drm_ctxbitmap_free( drm_device_t *dev, int ctx_handle );
-
-extern int	     drm_setsareactx( struct inode *inode, struct file *filp,
-				       unsigned int cmd, unsigned long arg );
-extern int	     drm_getsareactx( struct inode *inode, struct file *filp,
-				       unsigned int cmd, unsigned long arg );
+extern int drm_resctx(struct inode *inode, struct file *filp,
+		      unsigned int cmd, unsigned long arg);
+extern int drm_addctx(struct inode *inode, struct file *filp,
+		      unsigned int cmd, unsigned long arg);
+extern int drm_modctx(struct inode *inode, struct file *filp,
+		      unsigned int cmd, unsigned long arg);
+extern int drm_getctx(struct inode *inode, struct file *filp,
+		      unsigned int cmd, unsigned long arg);
+extern int drm_switchctx(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg);
+extern int drm_newctx(struct inode *inode, struct file *filp,
+		      unsigned int cmd, unsigned long arg);
+extern int drm_rmctx(struct inode *inode, struct file *filp,
+		     unsigned int cmd, unsigned long arg);
+
+extern int drm_ctxbitmap_init(drm_device_t * dev);
+extern void drm_ctxbitmap_cleanup(drm_device_t * dev);
+extern void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle);
+
+extern int drm_setsareactx(struct inode *inode, struct file *filp,
+			   unsigned int cmd, unsigned long arg);
+extern int drm_getsareactx(struct inode *inode, struct file *filp,
+			   unsigned int cmd, unsigned long arg);
 
 
 				/* Drawable IOCTL support (drm_drawable.h) */
 				/* Drawable IOCTL support (drm_drawable.h) */
-extern int	     drm_adddraw(struct inode *inode, struct file *filp,
-				  unsigned int cmd, unsigned long arg);
-extern int	     drm_rmdraw(struct inode *inode, struct file *filp,
-				 unsigned int cmd, unsigned long arg);
-
+extern int drm_adddraw(struct inode *inode, struct file *filp,
+		       unsigned int cmd, unsigned long arg);
+extern int drm_rmdraw(struct inode *inode, struct file *filp,
+		      unsigned int cmd, unsigned long arg);
 
 
 				/* Authentication IOCTL support (drm_auth.h) */
 				/* Authentication IOCTL support (drm_auth.h) */
-extern int	     drm_getmagic(struct inode *inode, struct file *filp,
-				   unsigned int cmd, unsigned long arg);
-extern int	     drm_authmagic(struct inode *inode, struct file *filp,
-				    unsigned int cmd, unsigned long arg);
+extern int drm_getmagic(struct inode *inode, struct file *filp,
+			unsigned int cmd, unsigned long arg);
+extern int drm_authmagic(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg);
 
 
-                                /* Placeholder for ioctls past */
-extern int	     drm_noop(struct inode *inode, struct file *filp,
-				  unsigned int cmd, unsigned long arg);
+				/* Placeholder for ioctls past */
+extern int drm_noop(struct inode *inode, struct file *filp,
+		    unsigned int cmd, unsigned long arg);
 
 
 				/* Locking IOCTL support (drm_lock.h) */
 				/* Locking IOCTL support (drm_lock.h) */
-extern int           drm_lock(struct inode *inode, struct file *filp,
-			       unsigned int cmd, unsigned long arg);
-extern int           drm_unlock(struct inode *inode, struct file *filp,
-				 unsigned int cmd, unsigned long arg);
-extern int	     drm_lock_take(__volatile__ unsigned int *lock,
-				    unsigned int context);
-extern int	     drm_lock_free(drm_device_t *dev,
-				    __volatile__ unsigned int *lock,
-				    unsigned int context);
+extern int drm_lock(struct inode *inode, struct file *filp,
+		    unsigned int cmd, unsigned long arg);
+extern int drm_unlock(struct inode *inode, struct file *filp,
+		      unsigned int cmd, unsigned long arg);
+extern int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context);
+extern int drm_lock_free(drm_device_t * dev,
+			 __volatile__ unsigned int *lock, unsigned int context);
 
 
 				/* Buffer management support (drm_bufs.h) */
 				/* Buffer management support (drm_bufs.h) */
-extern int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request);
-extern int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request);
-extern int drm_addmap(drm_device_t *dev, unsigned int offset,
+extern int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request);
+extern int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request);
+extern int drm_addmap(drm_device_t * dev, unsigned int offset,
 		      unsigned int size, drm_map_type_t type,
 		      unsigned int size, drm_map_type_t type,
-		      drm_map_flags_t flags, drm_local_map_t **map_ptr);
+		      drm_map_flags_t flags, drm_local_map_t ** map_ptr);
 extern int drm_addmap_ioctl(struct inode *inode, struct file *filp,
 extern int drm_addmap_ioctl(struct inode *inode, struct file *filp,
 			    unsigned int cmd, unsigned long arg);
 			    unsigned int cmd, unsigned long arg);
-extern int drm_rmmap(drm_device_t *dev, drm_local_map_t *map);
-extern int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map);
+extern int drm_rmmap(drm_device_t * dev, drm_local_map_t * map);
+extern int drm_rmmap_locked(drm_device_t * dev, drm_local_map_t * map);
 extern int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
 extern int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
 			   unsigned int cmd, unsigned long arg);
 			   unsigned int cmd, unsigned long arg);
 
 
-extern int	     drm_order( unsigned long size );
-extern int	     drm_addbufs( struct inode *inode, struct file *filp,
-				   unsigned int cmd, unsigned long arg );
-extern int	     drm_infobufs( struct inode *inode, struct file *filp,
-				    unsigned int cmd, unsigned long arg );
-extern int	     drm_markbufs( struct inode *inode, struct file *filp,
-				    unsigned int cmd, unsigned long arg );
-extern int	     drm_freebufs( struct inode *inode, struct file *filp,
-				    unsigned int cmd, unsigned long arg );
-extern int	     drm_mapbufs( struct inode *inode, struct file *filp,
-				   unsigned int cmd, unsigned long arg );
-extern unsigned long drm_get_resource_start(drm_device_t *dev,
+extern int drm_order(unsigned long size);
+extern int drm_addbufs(struct inode *inode, struct file *filp,
+		       unsigned int cmd, unsigned long arg);
+extern int drm_infobufs(struct inode *inode, struct file *filp,
+			unsigned int cmd, unsigned long arg);
+extern int drm_markbufs(struct inode *inode, struct file *filp,
+			unsigned int cmd, unsigned long arg);
+extern int drm_freebufs(struct inode *inode, struct file *filp,
+			unsigned int cmd, unsigned long arg);
+extern int drm_mapbufs(struct inode *inode, struct file *filp,
+		       unsigned int cmd, unsigned long arg);
+extern unsigned long drm_get_resource_start(drm_device_t * dev,
 					    unsigned int resource);
 					    unsigned int resource);
-extern unsigned long drm_get_resource_len(drm_device_t *dev,
+extern unsigned long drm_get_resource_len(drm_device_t * dev,
 					  unsigned int resource);
 					  unsigned int resource);
 
 
 				/* DMA support (drm_dma.h) */
 				/* DMA support (drm_dma.h) */
-extern int	     drm_dma_setup(drm_device_t *dev);
-extern void	     drm_dma_takedown(drm_device_t *dev);
-extern void	     drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
-extern void	     drm_core_reclaim_buffers(drm_device_t *dev, struct file *filp);
+extern int drm_dma_setup(drm_device_t * dev);
+extern void drm_dma_takedown(drm_device_t * dev);
+extern void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf);
+extern void drm_core_reclaim_buffers(drm_device_t * dev, struct file *filp);
 
 
 				/* IRQ support (drm_irq.h) */
 				/* IRQ support (drm_irq.h) */
-extern int           drm_control( struct inode *inode, struct file *filp,
-				   unsigned int cmd, unsigned long arg );
-extern int           drm_irq_uninstall( drm_device_t *dev );
-extern irqreturn_t   drm_irq_handler( DRM_IRQ_ARGS );
-extern void          drm_driver_irq_preinstall( drm_device_t *dev );
-extern void          drm_driver_irq_postinstall( drm_device_t *dev );
-extern void          drm_driver_irq_uninstall( drm_device_t *dev );
-
-extern int           drm_wait_vblank(struct inode *inode, struct file *filp,
-				      unsigned int cmd, unsigned long arg);
-extern int           drm_vblank_wait(drm_device_t *dev, unsigned int *vbl_seq);
-extern void          drm_vbl_send_signals( drm_device_t *dev );
+extern int drm_control(struct inode *inode, struct file *filp,
+		       unsigned int cmd, unsigned long arg);
+extern int drm_irq_uninstall(drm_device_t * dev);
+extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
+extern void drm_driver_irq_preinstall(drm_device_t * dev);
+extern void drm_driver_irq_postinstall(drm_device_t * dev);
+extern void drm_driver_irq_uninstall(drm_device_t * dev);
+
+extern int drm_wait_vblank(struct inode *inode, struct file *filp,
+			   unsigned int cmd, unsigned long arg);
+extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
+extern void drm_vbl_send_signals(drm_device_t * dev);
 
 
 				/* AGP/GART support (drm_agpsupport.h) */
 				/* AGP/GART support (drm_agpsupport.h) */
-extern drm_agp_head_t *drm_agp_init(drm_device_t *dev);
+extern drm_agp_head_t *drm_agp_init(drm_device_t * dev);
 extern int drm_agp_acquire(drm_device_t * dev);
 extern int drm_agp_acquire(drm_device_t * dev);
 extern int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
 extern int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
-			   unsigned int cmd, unsigned long arg);
-extern int drm_agp_release(drm_device_t *dev);
+				 unsigned int cmd, unsigned long arg);
+extern int drm_agp_release(drm_device_t * dev);
 extern int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
 extern int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
-			   unsigned int cmd, unsigned long arg);
-extern int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode);
+				 unsigned int cmd, unsigned long arg);
+extern int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode);
 extern int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
 extern int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
-			  unsigned int cmd, unsigned long arg);
-extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t *info);
+				unsigned int cmd, unsigned long arg);
+extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t * info);
 extern int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
 extern int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
+			      unsigned int cmd, unsigned long arg);
+extern int drm_agp_alloc(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg);
+extern int drm_agp_free(struct inode *inode, struct file *filp,
+			unsigned int cmd, unsigned long arg);
+extern int drm_agp_unbind(struct inode *inode, struct file *filp,
+			  unsigned int cmd, unsigned long arg);
+extern int drm_agp_bind(struct inode *inode, struct file *filp,
 			unsigned int cmd, unsigned long arg);
 			unsigned int cmd, unsigned long arg);
-extern int            drm_agp_alloc(struct inode *inode, struct file *filp,
-				     unsigned int cmd, unsigned long arg);
-extern int            drm_agp_free(struct inode *inode, struct file *filp,
-				    unsigned int cmd, unsigned long arg);
-extern int            drm_agp_unbind(struct inode *inode, struct file *filp,
-				      unsigned int cmd, unsigned long arg);
-extern int            drm_agp_bind(struct inode *inode, struct file *filp,
-				    unsigned int cmd, unsigned long arg);
-extern DRM_AGP_MEM    *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
-extern int            drm_agp_free_memory(DRM_AGP_MEM *handle);
-extern int            drm_agp_bind_memory(DRM_AGP_MEM *handle, off_t start);
-extern int            drm_agp_unbind_memory(DRM_AGP_MEM *handle);
+extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge,
+					    size_t pages, u32 type);
+extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
+extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
+extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
 
 
 				/* Stub support (drm_stub.h) */
 				/* Stub support (drm_stub.h) */
 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
-		     struct drm_driver *driver);
+		       struct drm_driver *driver);
 extern int drm_put_dev(drm_device_t * dev);
 extern int drm_put_dev(drm_device_t * dev);
 extern int drm_put_head(drm_head_t * head);
 extern int drm_put_head(drm_head_t * head);
-extern unsigned int   drm_debug;
-extern unsigned int   drm_cards_limit;
+extern unsigned int drm_debug;
+extern unsigned int drm_cards_limit;
 extern drm_head_t **drm_heads;
 extern drm_head_t **drm_heads;
 extern struct drm_sysfs_class *drm_class;
 extern struct drm_sysfs_class *drm_class;
 extern struct proc_dir_entry *drm_proc_root;
 extern struct proc_dir_entry *drm_proc_root;
 
 
 				/* Proc support (drm_proc.h) */
 				/* Proc support (drm_proc.h) */
-extern int            drm_proc_init(drm_device_t *dev,
-					     int minor,
-					     struct proc_dir_entry *root,
-					     struct proc_dir_entry **dev_root);
-extern int            drm_proc_cleanup(int minor,
-					struct proc_dir_entry *root,
-					struct proc_dir_entry *dev_root);
+extern int drm_proc_init(drm_device_t * dev,
+			 int minor,
+			 struct proc_dir_entry *root,
+			 struct proc_dir_entry **dev_root);
+extern int drm_proc_cleanup(int minor,
+			    struct proc_dir_entry *root,
+			    struct proc_dir_entry *dev_root);
 
 
 				/* Scatter Gather Support (drm_scatter.h) */
 				/* Scatter Gather Support (drm_scatter.h) */
-extern void           drm_sg_cleanup(drm_sg_mem_t *entry);
-extern int            drm_sg_alloc(struct inode *inode, struct file *filp,
-				    unsigned int cmd, unsigned long arg);
-extern int            drm_sg_free(struct inode *inode, struct file *filp,
-				   unsigned int cmd, unsigned long arg);
-
-                               /* ATI PCIGART support (ati_pcigart.h) */
-extern int            drm_ati_pcigart_init(drm_device_t *dev,
-					    unsigned long *addr,
-					    dma_addr_t *bus_addr);
-extern int            drm_ati_pcigart_cleanup(drm_device_t *dev,
-					       unsigned long addr,
-					       dma_addr_t bus_addr);
-
-extern drm_dma_handle_t *drm_pci_alloc(drm_device_t *dev, size_t size,
+extern void drm_sg_cleanup(drm_sg_mem_t * entry);
+extern int drm_sg_alloc(struct inode *inode, struct file *filp,
+			unsigned int cmd, unsigned long arg);
+extern int drm_sg_free(struct inode *inode, struct file *filp,
+		       unsigned int cmd, unsigned long arg);
+
+			       /* ATI PCIGART support (ati_pcigart.h) */
+extern int drm_ati_pcigart_init(drm_device_t * dev,
+				drm_ati_pcigart_info * gart_info);
+extern int drm_ati_pcigart_cleanup(drm_device_t * dev,
+				   drm_ati_pcigart_info * gart_info);
+
+extern drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size,
 				       size_t align, dma_addr_t maxaddr);
 				       size_t align, dma_addr_t maxaddr);
-extern void __drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
-extern void drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
+extern void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
+extern void drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
 
 
 			       /* sysfs support (drm_sysfs.c) */
 			       /* sysfs support (drm_sysfs.c) */
 struct drm_sysfs_class;
 struct drm_sysfs_class;
@@ -998,38 +996,41 @@ extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
 						 const char *fmt, ...);
 						 const char *fmt, ...);
 extern void drm_sysfs_device_remove(dev_t dev);
 extern void drm_sysfs_device_remove(dev_t dev);
 
 
-
 /* Inline replacements for DRM_IOREMAP macros */
 /* Inline replacements for DRM_IOREMAP macros */
-static __inline__ void drm_core_ioremap(struct drm_map *map, struct drm_device *dev)
+static __inline__ void drm_core_ioremap(struct drm_map *map,
+					struct drm_device *dev)
 {
 {
-	map->handle = drm_ioremap( map->offset, map->size, dev );
+	map->handle = drm_ioremap(map->offset, map->size, dev);
 }
 }
 
 
-static __inline__ void drm_core_ioremap_nocache(struct drm_map *map, struct drm_device *dev)
+static __inline__ void drm_core_ioremap_nocache(struct drm_map *map,
+						struct drm_device *dev)
 {
 {
 	map->handle = drm_ioremap_nocache(map->offset, map->size, dev);
 	map->handle = drm_ioremap_nocache(map->offset, map->size, dev);
 }
 }
 
 
-static __inline__ void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev)
+static __inline__ void drm_core_ioremapfree(struct drm_map *map,
+					    struct drm_device *dev)
 {
 {
-	if ( map->handle && map->size )
-		drm_ioremapfree( map->handle, map->size, dev );
+	if (map->handle && map->size)
+		drm_ioremapfree(map->handle, map->size, dev);
 }
 }
 
 
-static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev, unsigned int token)
+static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
+						   unsigned int token)
 {
 {
 	drm_map_list_t *_entry;
 	drm_map_list_t *_entry;
 	list_for_each_entry(_entry, &dev->maplist->head, head)
 	list_for_each_entry(_entry, &dev->maplist->head, head)
-		if (_entry->user_token == token)
-			return _entry->map;
+	    if (_entry->user_token == token)
+		return _entry->map;
 	return NULL;
 	return NULL;
 }
 }
 
 
-static __inline__ int drm_device_is_agp(drm_device_t *dev)
+static __inline__ int drm_device_is_agp(drm_device_t * dev)
 {
 {
-	if ( dev->driver->device_is_agp != NULL ) {
-		int err = (*dev->driver->device_is_agp)( dev );
-	
+	if (dev->driver->device_is_agp != NULL) {
+		int err = (*dev->driver->device_is_agp) (dev);
+
 		if (err != 2) {
 		if (err != 2) {
 			return err;
 			return err;
 		}
 		}
@@ -1038,6 +1039,11 @@ static __inline__ int drm_device_is_agp(drm_device_t *dev)
 	return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
 	return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
 }
 }
 
 
+static __inline__ int drm_device_is_pcie(drm_device_t * dev)
+{
+	return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
+}
+
 static __inline__ void drm_core_dropmap(struct drm_map *map)
 static __inline__ void drm_core_dropmap(struct drm_map *map)
 {
 {
 }
 }
@@ -1068,12 +1074,12 @@ extern void *drm_calloc(size_t nmemb, size_t size, int area);
 
 
 /*@}*/
 /*@}*/
 
 
-extern unsigned long drm_core_get_map_ofs(drm_map_t *map);
+extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
 
 
 #ifndef pci_pretty_name
 #ifndef pci_pretty_name
 #define pci_pretty_name(dev) ""
 #define pci_pretty_name(dev) ""
 #endif
 #endif
 
 
-#endif /* __KERNEL__ */
+#endif				/* __KERNEL__ */
 #endif
 #endif

+ 79 - 71
drivers/char/drm/drm_agpsupport.c

@@ -1,7 +1,7 @@
 /**
 /**
- * \file drm_agpsupport.h 
+ * \file drm_agpsupport.h
  * DRM support for AGP/GART backend
  * DRM support for AGP/GART backend
- *    
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
  */
@@ -48,30 +48,31 @@
  * Verifies the AGP device has been initialized and acquired and fills in the
  * Verifies the AGP device has been initialized and acquired and fills in the
  * drm_agp_info structure with the information in drm_agp_head::agp_info.
  * drm_agp_info structure with the information in drm_agp_head::agp_info.
  */
  */
-int drm_agp_info(drm_device_t *dev, drm_agp_info_t *info)
+int drm_agp_info(drm_device_t * dev, drm_agp_info_t * info)
 {
 {
-	DRM_AGP_KERN     *kern;
+	DRM_AGP_KERN *kern;
 
 
 	if (!dev->agp || !dev->agp->acquired)
 	if (!dev->agp || !dev->agp->acquired)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	kern                   = &dev->agp->agp_info;
+	kern = &dev->agp->agp_info;
 	info->agp_version_major = kern->version.major;
 	info->agp_version_major = kern->version.major;
 	info->agp_version_minor = kern->version.minor;
 	info->agp_version_minor = kern->version.minor;
-	info->mode              = kern->mode;
-	info->aperture_base     = kern->aper_base;
-	info->aperture_size     = kern->aper_size * 1024 * 1024;
-	info->memory_allowed    = kern->max_memory << PAGE_SHIFT;
-	info->memory_used       = kern->current_memory << PAGE_SHIFT;
-	info->id_vendor         = kern->device->vendor;
-	info->id_device         = kern->device->device;
+	info->mode = kern->mode;
+	info->aperture_base = kern->aper_base;
+	info->aperture_size = kern->aper_size * 1024 * 1024;
+	info->memory_allowed = kern->max_memory << PAGE_SHIFT;
+	info->memory_used = kern->current_memory << PAGE_SHIFT;
+	info->id_vendor = kern->device->vendor;
+	info->id_device = kern->device->device;
 
 
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_agp_info);
 EXPORT_SYMBOL(drm_agp_info);
 
 
 int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
 int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
-		 unsigned int cmd, unsigned long arg)
+		       unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -81,7 +82,7 @@ int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
 	err = drm_agp_info(dev, &info);
 	err = drm_agp_info(dev, &info);
 	if (err)
 	if (err)
 		return err;
 		return err;
-	
+
 	if (copy_to_user((drm_agp_info_t __user *) arg, &info, sizeof(info)))
 	if (copy_to_user((drm_agp_info_t __user *) arg, &info, sizeof(info)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
@@ -91,12 +92,12 @@ int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
  * Acquire the AGP device.
  * Acquire the AGP device.
  *
  *
  * \param dev DRM device that is to acquire AGP
  * \param dev DRM device that is to acquire AGP
- * \return zero on success or a negative number on failure. 
+ * \return zero on success or a negative number on failure.
  *
  *
  * Verifies the AGP device hasn't been acquired before and calls
  * Verifies the AGP device hasn't been acquired before and calls
  * \c agp_backend_acquire.
  * \c agp_backend_acquire.
  */
  */
-int drm_agp_acquire(drm_device_t *dev)
+int drm_agp_acquire(drm_device_t * dev)
 {
 {
 	if (!dev->agp)
 	if (!dev->agp)
 		return -ENODEV;
 		return -ENODEV;
@@ -107,6 +108,7 @@ int drm_agp_acquire(drm_device_t *dev)
 	dev->agp->acquired = 1;
 	dev->agp->acquired = 1;
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_agp_acquire);
 EXPORT_SYMBOL(drm_agp_acquire);
 
 
 /**
 /**
@@ -125,8 +127,8 @@ int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
 			  unsigned int cmd, unsigned long arg)
 			  unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
-	
-	return drm_agp_acquire( (drm_device_t *) priv->head->dev );
+
+	return drm_agp_acquire((drm_device_t *) priv->head->dev);
 }
 }
 
 
 /**
 /**
@@ -137,7 +139,7 @@ int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
  *
  *
  * Verifies the AGP device has been acquired and calls \c agp_backend_release.
  * Verifies the AGP device has been acquired and calls \c agp_backend_release.
  */
  */
-int drm_agp_release(drm_device_t *dev)
+int drm_agp_release(drm_device_t * dev)
 {
 {
 	if (!dev->agp || !dev->agp->acquired)
 	if (!dev->agp || !dev->agp->acquired)
 		return -EINVAL;
 		return -EINVAL;
@@ -145,6 +147,7 @@ int drm_agp_release(drm_device_t *dev)
 	dev->agp->acquired = 0;
 	dev->agp->acquired = 0;
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_agp_release);
 EXPORT_SYMBOL(drm_agp_release);
 
 
 int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
 int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
@@ -152,13 +155,13 @@ int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
-	
+
 	return drm_agp_release(dev);
 	return drm_agp_release(dev);
 }
 }
 
 
 /**
 /**
  * Enable the AGP bus.
  * Enable the AGP bus.
- * 
+ *
  * \param dev DRM device that has previously acquired AGP.
  * \param dev DRM device that has previously acquired AGP.
  * \param mode Requested AGP mode.
  * \param mode Requested AGP mode.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
@@ -166,27 +169,27 @@ int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
  * Verifies the AGP device has been acquired but not enabled, and calls
  * Verifies the AGP device has been acquired but not enabled, and calls
  * \c agp_enable.
  * \c agp_enable.
  */
  */
-int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode)
+int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode)
 {
 {
 	if (!dev->agp || !dev->agp->acquired)
 	if (!dev->agp || !dev->agp->acquired)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	dev->agp->mode    = mode.mode;
+	dev->agp->mode = mode.mode;
 	agp_enable(dev->agp->bridge, mode.mode);
 	agp_enable(dev->agp->bridge, mode.mode);
-	dev->agp->base    = dev->agp->agp_info.aper_base;
+	dev->agp->base = dev->agp->agp_info.aper_base;
 	dev->agp->enabled = 1;
 	dev->agp->enabled = 1;
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_agp_enable);
 EXPORT_SYMBOL(drm_agp_enable);
 
 
 int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
 int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg)
+			 unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_agp_mode_t mode;
 	drm_agp_mode_t mode;
 
 
-
 	if (copy_from_user(&mode, (drm_agp_mode_t __user *) arg, sizeof(mode)))
 	if (copy_from_user(&mode, (drm_agp_mode_t __user *) arg, sizeof(mode)))
 		return -EFAULT;
 		return -EFAULT;
 
 
@@ -201,20 +204,20 @@ int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
  * \param cmd command.
  * \param cmd command.
  * \param arg pointer to a drm_agp_buffer structure.
  * \param arg pointer to a drm_agp_buffer structure.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
- * 
+ *
  * Verifies the AGP device is present and has been acquired, allocates the
  * Verifies the AGP device is present and has been acquired, allocates the
  * memory via alloc_agp() and creates a drm_agp_mem entry for it.
  * memory via alloc_agp() and creates a drm_agp_mem entry for it.
  */
  */
 int drm_agp_alloc(struct inode *inode, struct file *filp,
 int drm_agp_alloc(struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg)
+		  unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	 *priv	 = filp->private_data;
-	drm_device_t	 *dev	 = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_agp_buffer_t request;
 	drm_agp_buffer_t request;
-	drm_agp_mem_t    *entry;
-	DRM_AGP_MEM      *memory;
-	unsigned long    pages;
-	u32 		 type;
+	drm_agp_mem_t *entry;
+	DRM_AGP_MEM *memory;
+	unsigned long pages;
+	u32 type;
 	drm_agp_buffer_t __user *argp = (void __user *)arg;
 	drm_agp_buffer_t __user *argp = (void __user *)arg;
 
 
 	if (!dev->agp || !dev->agp->acquired)
 	if (!dev->agp || !dev->agp->acquired)
@@ -224,7 +227,7 @@ int drm_agp_alloc(struct inode *inode, struct file *filp,
 	if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS)))
 	if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS)))
 		return -ENOMEM;
 		return -ENOMEM;
 
 
-   	memset(entry, 0, sizeof(*entry));
+	memset(entry, 0, sizeof(*entry));
 
 
 	pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
 	pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
 	type = (u32) request.type;
 	type = (u32) request.type;
@@ -234,21 +237,21 @@ int drm_agp_alloc(struct inode *inode, struct file *filp,
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 
 
-	entry->handle    = (unsigned long)memory->key + 1;
-	entry->memory    = memory;
-	entry->bound     = 0;
-	entry->pages     = pages;
-	entry->prev      = NULL;
-	entry->next      = dev->agp->memory;
+	entry->handle = (unsigned long)memory->key + 1;
+	entry->memory = memory;
+	entry->bound = 0;
+	entry->pages = pages;
+	entry->prev = NULL;
+	entry->next = dev->agp->memory;
 	if (dev->agp->memory)
 	if (dev->agp->memory)
 		dev->agp->memory->prev = entry;
 		dev->agp->memory->prev = entry;
 	dev->agp->memory = entry;
 	dev->agp->memory = entry;
 
 
-	request.handle   = entry->handle;
+	request.handle = entry->handle;
 	request.physical = memory->physical;
 	request.physical = memory->physical;
 
 
 	if (copy_to_user(argp, &request, sizeof(request))) {
 	if (copy_to_user(argp, &request, sizeof(request))) {
-		dev->agp->memory       = entry->next;
+		dev->agp->memory = entry->next;
 		dev->agp->memory->prev = NULL;
 		dev->agp->memory->prev = NULL;
 		drm_free_agp(memory, pages);
 		drm_free_agp(memory, pages);
 		drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
 		drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
@@ -263,11 +266,11 @@ int drm_agp_alloc(struct inode *inode, struct file *filp,
  * \param dev DRM device structure.
  * \param dev DRM device structure.
  * \param handle AGP memory handle.
  * \param handle AGP memory handle.
  * \return pointer to the drm_agp_mem structure associated with \p handle.
  * \return pointer to the drm_agp_mem structure associated with \p handle.
- * 
+ *
  * Walks through drm_agp_head::memory until finding a matching handle.
  * Walks through drm_agp_head::memory until finding a matching handle.
  */
  */
-static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t *dev,
-					    unsigned long handle)
+static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t * dev,
+					   unsigned long handle)
 {
 {
 	drm_agp_mem_t *entry;
 	drm_agp_mem_t *entry;
 
 
@@ -291,17 +294,18 @@ static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t *dev,
  * entry and passes it to the unbind_agp() function.
  * entry and passes it to the unbind_agp() function.
  */
  */
 int drm_agp_unbind(struct inode *inode, struct file *filp,
 int drm_agp_unbind(struct inode *inode, struct file *filp,
-		    unsigned int cmd, unsigned long arg)
+		   unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	  *priv	 = filp->private_data;
-	drm_device_t	  *dev	 = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_agp_binding_t request;
 	drm_agp_binding_t request;
-	drm_agp_mem_t     *entry;
+	drm_agp_mem_t *entry;
 	int ret;
 	int ret;
 
 
 	if (!dev->agp || !dev->agp->acquired)
 	if (!dev->agp || !dev->agp->acquired)
 		return -EINVAL;
 		return -EINVAL;
-	if (copy_from_user(&request, (drm_agp_binding_t __user *)arg, sizeof(request)))
+	if (copy_from_user
+	    (&request, (drm_agp_binding_t __user *) arg, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 	if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
 	if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
 		return -EINVAL;
 		return -EINVAL;
@@ -309,7 +313,7 @@ int drm_agp_unbind(struct inode *inode, struct file *filp,
 		return -EINVAL;
 		return -EINVAL;
 	ret = drm_unbind_agp(entry->memory);
 	ret = drm_unbind_agp(entry->memory);
 	if (ret == 0)
 	if (ret == 0)
-	    entry->bound = 0;
+		entry->bound = 0;
 	return ret;
 	return ret;
 }
 }
 
 
@@ -327,18 +331,19 @@ int drm_agp_unbind(struct inode *inode, struct file *filp,
  * it to bind_agp() function.
  * it to bind_agp() function.
  */
  */
 int drm_agp_bind(struct inode *inode, struct file *filp,
 int drm_agp_bind(struct inode *inode, struct file *filp,
-		  unsigned int cmd, unsigned long arg)
+		 unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	  *priv	 = filp->private_data;
-	drm_device_t	  *dev	 = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_agp_binding_t request;
 	drm_agp_binding_t request;
-	drm_agp_mem_t     *entry;
-	int               retcode;
-	int               page;
+	drm_agp_mem_t *entry;
+	int retcode;
+	int page;
 
 
 	if (!dev->agp || !dev->agp->acquired)
 	if (!dev->agp || !dev->agp->acquired)
 		return -EINVAL;
 		return -EINVAL;
-	if (copy_from_user(&request, (drm_agp_binding_t __user *)arg, sizeof(request)))
+	if (copy_from_user
+	    (&request, (drm_agp_binding_t __user *) arg, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 	if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
 	if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
 		return -EINVAL;
 		return -EINVAL;
@@ -368,16 +373,17 @@ int drm_agp_bind(struct inode *inode, struct file *filp,
  * and unlinks from the doubly linked list it's inserted in.
  * and unlinks from the doubly linked list it's inserted in.
  */
  */
 int drm_agp_free(struct inode *inode, struct file *filp,
 int drm_agp_free(struct inode *inode, struct file *filp,
-		  unsigned int cmd, unsigned long arg)
+		 unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	 *priv	 = filp->private_data;
-	drm_device_t	 *dev	 = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_agp_buffer_t request;
 	drm_agp_buffer_t request;
-	drm_agp_mem_t    *entry;
+	drm_agp_mem_t *entry;
 
 
 	if (!dev->agp || !dev->agp->acquired)
 	if (!dev->agp || !dev->agp->acquired)
 		return -EINVAL;
 		return -EINVAL;
-	if (copy_from_user(&request, (drm_agp_buffer_t __user *)arg, sizeof(request)))
+	if (copy_from_user
+	    (&request, (drm_agp_buffer_t __user *) arg, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 	if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
 	if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
 		return -EINVAL;
 		return -EINVAL;
@@ -403,9 +409,9 @@ int drm_agp_free(struct inode *inode, struct file *filp,
  * \return pointer to a drm_agp_head structure.
  * \return pointer to a drm_agp_head structure.
  *
  *
  */
  */
-drm_agp_head_t *drm_agp_init(drm_device_t *dev)
+drm_agp_head_t *drm_agp_init(drm_device_t * dev)
 {
 {
-	drm_agp_head_t *head         = NULL;
+	drm_agp_head_t *head = NULL;
 
 
 	if (!(head = drm_alloc(sizeof(*head), DRM_MEM_AGPLISTS)))
 	if (!(head = drm_alloc(sizeof(*head), DRM_MEM_AGPLISTS)))
 		return NULL;
 		return NULL;
@@ -433,13 +439,14 @@ drm_agp_head_t *drm_agp_init(drm_device_t *dev)
 }
 }
 
 
 /** Calls agp_allocate_memory() */
 /** Calls agp_allocate_memory() */
-DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type)
+DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data * bridge,
+				     size_t pages, u32 type)
 {
 {
 	return agp_allocate_memory(bridge, pages, type);
 	return agp_allocate_memory(bridge, pages, type);
 }
 }
 
 
 /** Calls agp_free_memory() */
 /** Calls agp_free_memory() */
-int drm_agp_free_memory(DRM_AGP_MEM *handle)
+int drm_agp_free_memory(DRM_AGP_MEM * handle)
 {
 {
 	if (!handle)
 	if (!handle)
 		return 0;
 		return 0;
@@ -448,20 +455,21 @@ int drm_agp_free_memory(DRM_AGP_MEM *handle)
 }
 }
 
 
 /** Calls agp_bind_memory() */
 /** Calls agp_bind_memory() */
-int drm_agp_bind_memory(DRM_AGP_MEM *handle, off_t start)
+int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start)
 {
 {
 	if (!handle)
 	if (!handle)
 		return -EINVAL;
 		return -EINVAL;
 	return agp_bind_memory(handle, start);
 	return agp_bind_memory(handle, start);
 }
 }
+
 EXPORT_SYMBOL(drm_agp_bind_memory);
 EXPORT_SYMBOL(drm_agp_bind_memory);
 
 
 /** Calls agp_unbind_memory() */
 /** Calls agp_unbind_memory() */
-int drm_agp_unbind_memory(DRM_AGP_MEM *handle)
+int drm_agp_unbind_memory(DRM_AGP_MEM * handle)
 {
 {
 	if (!handle)
 	if (!handle)
 		return -EINVAL;
 		return -EINVAL;
 	return agp_unbind_memory(handle);
 	return agp_unbind_memory(handle);
 }
 }
 
 
-#endif /* __OS_HAS_AGP */
+#endif				/* __OS_HAS_AGP */

+ 35 - 33
drivers/char/drm/drm_auth.c

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_auth.h 
+ * \file drm_auth.c
  * IOCTLs for authentication
  * IOCTLs for authentication
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -46,7 +46,7 @@
  */
  */
 static int drm_hash_magic(drm_magic_t magic)
 static int drm_hash_magic(drm_magic_t magic)
 {
 {
-	return magic & (DRM_HASH_SIZE-1);
+	return magic & (DRM_HASH_SIZE - 1);
 }
 }
 
 
 /**
 /**
@@ -59,11 +59,11 @@ static int drm_hash_magic(drm_magic_t magic)
  * the one with matching magic number, while holding the drm_device::struct_sem
  * the one with matching magic number, while holding the drm_device::struct_sem
  * lock.
  * lock.
  */
  */
-static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
+static drm_file_t *drm_find_file(drm_device_t * dev, drm_magic_t magic)
 {
 {
-	drm_file_t	  *retval = NULL;
+	drm_file_t *retval = NULL;
 	drm_magic_entry_t *pt;
 	drm_magic_entry_t *pt;
-	int		  hash	  = drm_hash_magic(magic);
+	int hash = drm_hash_magic(magic);
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 	for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
 	for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
@@ -78,7 +78,7 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
 
 
 /**
 /**
  * Adds a magic number.
  * Adds a magic number.
- * 
+ *
  * \param dev DRM device.
  * \param dev DRM device.
  * \param priv file private data.
  * \param priv file private data.
  * \param magic magic number.
  * \param magic magic number.
@@ -87,28 +87,30 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
  * associated the magic number hash key in drm_device::magiclist, while holding
  * associated the magic number hash key in drm_device::magiclist, while holding
  * the drm_device::struct_sem lock.
  * the drm_device::struct_sem lock.
  */
  */
-static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
+static int drm_add_magic(drm_device_t * dev, drm_file_t * priv,
+			 drm_magic_t magic)
 {
 {
-	int		  hash;
+	int hash;
 	drm_magic_entry_t *entry;
 	drm_magic_entry_t *entry;
 
 
 	DRM_DEBUG("%d\n", magic);
 	DRM_DEBUG("%d\n", magic);
 
 
-	hash	     = drm_hash_magic(magic);
-	entry	     = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC);
-	if (!entry) return -ENOMEM;
+	hash = drm_hash_magic(magic);
+	entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC);
+	if (!entry)
+		return -ENOMEM;
 	memset(entry, 0, sizeof(*entry));
 	memset(entry, 0, sizeof(*entry));
 	entry->magic = magic;
 	entry->magic = magic;
-	entry->priv  = priv;
-	entry->next  = NULL;
+	entry->priv = priv;
+	entry->next = NULL;
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 	if (dev->magiclist[hash].tail) {
 	if (dev->magiclist[hash].tail) {
 		dev->magiclist[hash].tail->next = entry;
 		dev->magiclist[hash].tail->next = entry;
-		dev->magiclist[hash].tail	= entry;
+		dev->magiclist[hash].tail = entry;
 	} else {
 	} else {
-		dev->magiclist[hash].head	= entry;
-		dev->magiclist[hash].tail	= entry;
+		dev->magiclist[hash].head = entry;
+		dev->magiclist[hash].tail = entry;
 	}
 	}
 	up(&dev->struct_sem);
 	up(&dev->struct_sem);
 
 
@@ -117,19 +119,18 @@ static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
 
 
 /**
 /**
  * Remove a magic number.
  * Remove a magic number.
- * 
+ *
  * \param dev DRM device.
  * \param dev DRM device.
  * \param magic magic number.
  * \param magic magic number.
  *
  *
  * Searches and unlinks the entry in drm_device::magiclist with the magic
  * Searches and unlinks the entry in drm_device::magiclist with the magic
  * number hash key, while holding the drm_device::struct_sem lock.
  * number hash key, while holding the drm_device::struct_sem lock.
  */
  */
-static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
+static int drm_remove_magic(drm_device_t * dev, drm_magic_t magic)
 {
 {
 	drm_magic_entry_t *prev = NULL;
 	drm_magic_entry_t *prev = NULL;
 	drm_magic_entry_t *pt;
 	drm_magic_entry_t *pt;
-	int		  hash;
-
+	int hash;
 
 
 	DRM_DEBUG("%d\n", magic);
 	DRM_DEBUG("%d\n", magic);
 	hash = drm_hash_magic(magic);
 	hash = drm_hash_magic(magic);
@@ -171,21 +172,22 @@ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
  * filp.
  * filp.
  */
  */
 int drm_getmagic(struct inode *inode, struct file *filp,
 int drm_getmagic(struct inode *inode, struct file *filp,
-		  unsigned int cmd, unsigned long arg)
+		 unsigned int cmd, unsigned long arg)
 {
 {
 	static drm_magic_t sequence = 0;
 	static drm_magic_t sequence = 0;
 	static DEFINE_SPINLOCK(lock);
 	static DEFINE_SPINLOCK(lock);
-	drm_file_t	   *priv    = filp->private_data;
-	drm_device_t	   *dev	    = priv->head->dev;
-	drm_auth_t	   auth;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_auth_t auth;
 
 
-				/* Find unique magic */
+	/* Find unique magic */
 	if (priv->magic) {
 	if (priv->magic) {
 		auth.magic = priv->magic;
 		auth.magic = priv->magic;
 	} else {
 	} else {
 		do {
 		do {
 			spin_lock(&lock);
 			spin_lock(&lock);
-			if (!sequence) ++sequence; /* reserve 0 */
+			if (!sequence)
+				++sequence;	/* reserve 0 */
 			auth.magic = sequence++;
 			auth.magic = sequence++;
 			spin_unlock(&lock);
 			spin_unlock(&lock);
 		} while (drm_find_file(dev, auth.magic));
 		} while (drm_find_file(dev, auth.magic));
@@ -194,7 +196,7 @@ int drm_getmagic(struct inode *inode, struct file *filp,
 	}
 	}
 
 
 	DRM_DEBUG("%u\n", auth.magic);
 	DRM_DEBUG("%u\n", auth.magic);
-	if (copy_to_user((drm_auth_t __user *)arg, &auth, sizeof(auth)))
+	if (copy_to_user((drm_auth_t __user *) arg, &auth, sizeof(auth)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
@@ -211,14 +213,14 @@ int drm_getmagic(struct inode *inode, struct file *filp,
  * Checks if \p filp is associated with the magic number passed in \arg.
  * Checks if \p filp is associated with the magic number passed in \arg.
  */
  */
 int drm_authmagic(struct inode *inode, struct file *filp,
 int drm_authmagic(struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg)
+		  unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	   *priv    = filp->private_data;
-	drm_device_t	   *dev	    = priv->head->dev;
-	drm_auth_t	   auth;
-	drm_file_t	   *file;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_auth_t auth;
+	drm_file_t *file;
 
 
-	if (copy_from_user(&auth, (drm_auth_t __user *)arg, sizeof(auth)))
+	if (copy_from_user(&auth, (drm_auth_t __user *) arg, sizeof(auth)))
 		return -EFAULT;
 		return -EFAULT;
 	DRM_DEBUG("%u\n", auth.magic);
 	DRM_DEBUG("%u\n", auth.magic);
 	if ((file = drm_find_file(dev, auth.magic))) {
 	if ((file = drm_find_file(dev, auth.magic))) {

+ 445 - 446
drivers/char/drm/drm_bufs.c

@@ -1,7 +1,7 @@
 /**
 /**
- * \file drm_bufs.h 
+ * \file drm_bufs.c
  * Generic buffer template
  * Generic buffer template
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
  */
@@ -36,20 +36,22 @@
 #include <linux/vmalloc.h>
 #include <linux/vmalloc.h>
 #include "drmP.h"
 #include "drmP.h"
 
 
-unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource)
+unsigned long drm_get_resource_start(drm_device_t * dev, unsigned int resource)
 {
 {
 	return pci_resource_start(dev->pdev, resource);
 	return pci_resource_start(dev->pdev, resource);
 }
 }
+
 EXPORT_SYMBOL(drm_get_resource_start);
 EXPORT_SYMBOL(drm_get_resource_start);
 
 
-unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource)
+unsigned long drm_get_resource_len(drm_device_t * dev, unsigned int resource)
 {
 {
 	return pci_resource_len(dev->pdev, resource);
 	return pci_resource_len(dev->pdev, resource);
 }
 }
+
 EXPORT_SYMBOL(drm_get_resource_len);
 EXPORT_SYMBOL(drm_get_resource_len);
 
 
-static drm_map_list_t *drm_find_matching_map(drm_device_t *dev,
-					     drm_local_map_t *map)
+static drm_map_list_t *drm_find_matching_map(drm_device_t * dev,
+					     drm_local_map_t * map)
 {
 {
 	struct list_head *list;
 	struct list_head *list;
 
 
@@ -71,7 +73,8 @@ static drm_map_list_t *drm_find_matching_map(drm_device_t *dev,
 #define END_RANGE 0x40000000
 #define END_RANGE 0x40000000
 
 
 #ifdef _LP64
 #ifdef _LP64
-static __inline__ unsigned int HandleID(unsigned long lhandle, drm_device_t *dev) 
+static __inline__ unsigned int HandleID(unsigned long lhandle,
+					drm_device_t * dev)
 {
 {
 	static unsigned int map32_handle = START_RANGE;
 	static unsigned int map32_handle = START_RANGE;
 	unsigned int hash;
 	unsigned int hash;
@@ -81,12 +84,12 @@ static __inline__ unsigned int HandleID(unsigned long lhandle, drm_device_t *dev
 		map32_handle += PAGE_SIZE;
 		map32_handle += PAGE_SIZE;
 		if (map32_handle > END_RANGE)
 		if (map32_handle > END_RANGE)
 			map32_handle = START_RANGE;
 			map32_handle = START_RANGE;
-	} else 
+	} else
 		hash = lhandle;
 		hash = lhandle;
 
 
 	while (1) {
 	while (1) {
 		drm_map_list_t *_entry;
 		drm_map_list_t *_entry;
-		list_for_each_entry(_entry, &dev->maplist->head,head) {
+		list_for_each_entry(_entry, &dev->maplist->head, head) {
 			if (_entry->user_token == hash)
 			if (_entry->user_token == hash)
 				break;
 				break;
 		}
 		}
@@ -114,16 +117,16 @@ static __inline__ unsigned int HandleID(unsigned long lhandle, drm_device_t *dev
  * type.  Adds the map to the map list drm_device::maplist. Adds MTRR's where
  * type.  Adds the map to the map list drm_device::maplist. Adds MTRR's where
  * applicable and if supported by the kernel.
  * applicable and if supported by the kernel.
  */
  */
-int drm_addmap_core(drm_device_t * dev, unsigned int offset,
-		    unsigned int size, drm_map_type_t type,
-		    drm_map_flags_t flags, drm_map_list_t **maplist)
+static int drm_addmap_core(drm_device_t * dev, unsigned int offset,
+			   unsigned int size, drm_map_type_t type,
+			   drm_map_flags_t flags, drm_map_list_t ** maplist)
 {
 {
 	drm_map_t *map;
 	drm_map_t *map;
 	drm_map_list_t *list;
 	drm_map_list_t *list;
 	drm_dma_handle_t *dmah;
 	drm_dma_handle_t *dmah;
 
 
-	map = drm_alloc( sizeof(*map), DRM_MEM_MAPS );
-	if ( !map )
+	map = drm_alloc(sizeof(*map), DRM_MEM_MAPS);
+	if (!map)
 		return -ENOMEM;
 		return -ENOMEM;
 
 
 	map->offset = offset;
 	map->offset = offset;
@@ -135,26 +138,26 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
 	 * book keeping information about shared memory to allow for removal
 	 * book keeping information about shared memory to allow for removal
 	 * when processes fork.
 	 * when processes fork.
 	 */
 	 */
-	if ( (map->flags & _DRM_REMOVABLE) && map->type != _DRM_SHM ) {
-		drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+	if ((map->flags & _DRM_REMOVABLE) && map->type != _DRM_SHM) {
+		drm_free(map, sizeof(*map), DRM_MEM_MAPS);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
-	DRM_DEBUG( "offset = 0x%08lx, size = 0x%08lx, type = %d\n",
-		   map->offset, map->size, map->type );
-	if ( (map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK)) ) {
-		drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+	DRM_DEBUG("offset = 0x%08lx, size = 0x%08lx, type = %d\n",
+		  map->offset, map->size, map->type);
+	if ((map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK))) {
+		drm_free(map, sizeof(*map), DRM_MEM_MAPS);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
-	map->mtrr   = -1;
+	map->mtrr = -1;
 	map->handle = NULL;
 	map->handle = NULL;
 
 
-	switch ( map->type ) {
+	switch (map->type) {
 	case _DRM_REGISTERS:
 	case _DRM_REGISTERS:
 	case _DRM_FRAME_BUFFER:
 	case _DRM_FRAME_BUFFER:
 #if !defined(__sparc__) && !defined(__alpha__) && !defined(__ia64__) && !defined(__powerpc64__) && !defined(__x86_64__)
 #if !defined(__sparc__) && !defined(__alpha__) && !defined(__ia64__) && !defined(__powerpc64__) && !defined(__x86_64__)
-		if ( map->offset + map->size < map->offset ||
-		     map->offset < virt_to_phys(high_memory) ) {
-			drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+		if (map->offset + map->size < map->offset ||
+		    map->offset < virt_to_phys(high_memory)) {
+			drm_free(map, sizeof(*map), DRM_MEM_MAPS);
 			return -EINVAL;
 			return -EINVAL;
 		}
 		}
 #endif
 #endif
@@ -169,8 +172,9 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
 		if (list != NULL) {
 		if (list != NULL) {
 			if (list->map->size != map->size) {
 			if (list->map->size != map->size) {
 				DRM_DEBUG("Matching maps of type %d with "
 				DRM_DEBUG("Matching maps of type %d with "
-				   "mismatched sizes, (%ld vs %ld)\n",
-				    map->type, map->size, list->map->size);
+					  "mismatched sizes, (%ld vs %ld)\n",
+					  map->type, map->size,
+					  list->map->size);
 				list->map->size = map->size;
 				list->map->size = map->size;
 			}
 			}
 
 
@@ -180,35 +184,33 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
 		}
 		}
 
 
 		if (drm_core_has_MTRR(dev)) {
 		if (drm_core_has_MTRR(dev)) {
-			if ( map->type == _DRM_FRAME_BUFFER ||
-			     (map->flags & _DRM_WRITE_COMBINING) ) {
-				map->mtrr = mtrr_add( map->offset, map->size,
-						      MTRR_TYPE_WRCOMB, 1 );
+			if (map->type == _DRM_FRAME_BUFFER ||
+			    (map->flags & _DRM_WRITE_COMBINING)) {
+				map->mtrr = mtrr_add(map->offset, map->size,
+						     MTRR_TYPE_WRCOMB, 1);
 			}
 			}
 		}
 		}
 		if (map->type == _DRM_REGISTERS)
 		if (map->type == _DRM_REGISTERS)
-			map->handle = drm_ioremap( map->offset, map->size,
-						    dev );
+			map->handle = drm_ioremap(map->offset, map->size, dev);
 		break;
 		break;
 
 
 	case _DRM_SHM:
 	case _DRM_SHM:
 		map->handle = vmalloc_32(map->size);
 		map->handle = vmalloc_32(map->size);
-		DRM_DEBUG( "%lu %d %p\n",
-			   map->size, drm_order( map->size ), map->handle );
-		if ( !map->handle ) {
-			drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+		DRM_DEBUG("%lu %d %p\n",
+			  map->size, drm_order(map->size), map->handle);
+		if (!map->handle) {
+			drm_free(map, sizeof(*map), DRM_MEM_MAPS);
 			return -ENOMEM;
 			return -ENOMEM;
 		}
 		}
 		map->offset = (unsigned long)map->handle;
 		map->offset = (unsigned long)map->handle;
-		if ( map->flags & _DRM_CONTAINS_LOCK ) {
+		if (map->flags & _DRM_CONTAINS_LOCK) {
 			/* Prevent a 2nd X Server from creating a 2nd lock */
 			/* Prevent a 2nd X Server from creating a 2nd lock */
 			if (dev->lock.hw_lock != NULL) {
 			if (dev->lock.hw_lock != NULL) {
-				vfree( map->handle );
-				drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+				vfree(map->handle);
+				drm_free(map, sizeof(*map), DRM_MEM_MAPS);
 				return -EBUSY;
 				return -EBUSY;
 			}
 			}
-			dev->sigdata.lock =
-			dev->lock.hw_lock = map->handle; /* Pointer to lock */
+			dev->sigdata.lock = dev->lock.hw_lock = map->handle;	/* Pointer to lock */
 		}
 		}
 		break;
 		break;
 	case _DRM_AGP:
 	case _DRM_AGP:
@@ -217,7 +219,7 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
 			map->offset += dev->hose->mem_space->start;
 			map->offset += dev->hose->mem_space->start;
 #endif
 #endif
 			map->offset += dev->agp->base;
 			map->offset += dev->agp->base;
-			map->mtrr   = dev->agp->agp_mtrr; /* for getmap */
+			map->mtrr = dev->agp->agp_mtrr;	/* for getmap */
 		}
 		}
 		break;
 		break;
 	case _DRM_SCATTER_GATHER:
 	case _DRM_SCATTER_GATHER:
@@ -227,7 +229,7 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
 		}
 		}
 		map->offset += (unsigned long)dev->sg->virtual;
 		map->offset += (unsigned long)dev->sg->virtual;
 		break;
 		break;
-	case _DRM_CONSISTENT: 
+	case _DRM_CONSISTENT:
 		/* dma_addr_t is 64bit on i386 with CONFIG_HIGHMEM64G,
 		/* dma_addr_t is 64bit on i386 with CONFIG_HIGHMEM64G,
 		 * As we're limiting the address to 2^32-1 (or less),
 		 * As we're limiting the address to 2^32-1 (or less),
 		 * casting it down to 32 bits is no problem, but we
 		 * casting it down to 32 bits is no problem, but we
@@ -242,12 +244,12 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
 		kfree(dmah);
 		kfree(dmah);
 		break;
 		break;
 	default:
 	default:
-		drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+		drm_free(map, sizeof(*map), DRM_MEM_MAPS);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
 	list = drm_alloc(sizeof(*list), DRM_MEM_MAPS);
 	list = drm_alloc(sizeof(*list), DRM_MEM_MAPS);
-	if(!list) {
+	if (!list) {
 		drm_free(map, sizeof(*map), DRM_MEM_MAPS);
 		drm_free(map, sizeof(*map), DRM_MEM_MAPS);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
@@ -258,18 +260,18 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
 	list_add(&list->head, &dev->maplist->head);
 	list_add(&list->head, &dev->maplist->head);
 	/* Assign a 32-bit handle */
 	/* Assign a 32-bit handle */
 	/* We do it here so that dev->struct_sem protects the increment */
 	/* We do it here so that dev->struct_sem protects the increment */
-	list->user_token = HandleID(map->type==_DRM_SHM
+	list->user_token = HandleID(map->type == _DRM_SHM
 				    ? (unsigned long)map->handle
 				    ? (unsigned long)map->handle
 				    : map->offset, dev);
 				    : map->offset, dev);
- 	up(&dev->struct_sem);
+	up(&dev->struct_sem);
 
 
 	*maplist = list;
 	*maplist = list;
 	return 0;
 	return 0;
 }
 }
 
 
-int drm_addmap(drm_device_t *dev, unsigned int offset,
+int drm_addmap(drm_device_t * dev, unsigned int offset,
 	       unsigned int size, drm_map_type_t type,
 	       unsigned int size, drm_map_type_t type,
-	       drm_map_flags_t flags, drm_local_map_t **map_ptr)
+	       drm_map_flags_t flags, drm_local_map_t ** map_ptr)
 {
 {
 	drm_map_list_t *list;
 	drm_map_list_t *list;
 	int rc;
 	int rc;
@@ -279,6 +281,7 @@ int drm_addmap(drm_device_t *dev, unsigned int offset,
 		*map_ptr = list->map;
 		*map_ptr = list->map;
 	return rc;
 	return rc;
 }
 }
+
 EXPORT_SYMBOL(drm_addmap);
 EXPORT_SYMBOL(drm_addmap);
 
 
 int drm_addmap_ioctl(struct inode *inode, struct file *filp,
 int drm_addmap_ioctl(struct inode *inode, struct file *filp,
@@ -294,24 +297,25 @@ int drm_addmap_ioctl(struct inode *inode, struct file *filp,
 	if (!(filp->f_mode & 3))
 	if (!(filp->f_mode & 3))
 		return -EACCES;	/* Require read/write */
 		return -EACCES;	/* Require read/write */
 
 
-	if (copy_from_user(& map, argp, sizeof(map))) {
+	if (copy_from_user(&map, argp, sizeof(map))) {
 		return -EFAULT;
 		return -EFAULT;
 	}
 	}
 
 
 	err = drm_addmap_core(dev, map.offset, map.size, map.type, map.flags,
 	err = drm_addmap_core(dev, map.offset, map.size, map.type, map.flags,
 			      &maplist);
 			      &maplist);
 
 
-	if (err) 
+	if (err)
 		return err;
 		return err;
 
 
 	if (copy_to_user(argp, maplist->map, sizeof(drm_map_t)))
 	if (copy_to_user(argp, maplist->map, sizeof(drm_map_t)))
 		return -EFAULT;
 		return -EFAULT;
-	if (put_user(maplist->user_token, &argp->handle))
+
+	/* avoid a warning on 64-bit, this casting isn't very nice, but the API is set so too late */
+	if (put_user((void *)(unsigned long)maplist->user_token, &argp->handle))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
 
 
-
 /**
 /**
  * Remove a map private from list and deallocate resources if the mapping
  * Remove a map private from list and deallocate resources if the mapping
  * isn't in use.
  * isn't in use.
@@ -328,7 +332,7 @@ int drm_addmap_ioctl(struct inode *inode, struct file *filp,
  *
  *
  * \sa drm_addmap
  * \sa drm_addmap
  */
  */
-int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map)
+int drm_rmmap_locked(drm_device_t * dev, drm_local_map_t * map)
 {
 {
 	struct list_head *list;
 	struct list_head *list;
 	drm_map_list_t *r_list = NULL;
 	drm_map_list_t *r_list = NULL;
@@ -359,9 +363,8 @@ int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map)
 	case _DRM_FRAME_BUFFER:
 	case _DRM_FRAME_BUFFER:
 		if (drm_core_has_MTRR(dev) && map->mtrr >= 0) {
 		if (drm_core_has_MTRR(dev) && map->mtrr >= 0) {
 			int retcode;
 			int retcode;
-			retcode = mtrr_del(map->mtrr, map->offset,
-					   map->size);
-			DRM_DEBUG ("mtrr_del=%d\n", retcode);
+			retcode = mtrr_del(map->mtrr, map->offset, map->size);
+			DRM_DEBUG("mtrr_del=%d\n", retcode);
 		}
 		}
 		break;
 		break;
 	case _DRM_SHM:
 	case _DRM_SHM:
@@ -381,9 +384,10 @@ int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map)
 
 
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_rmmap_locked);
 EXPORT_SYMBOL(drm_rmmap_locked);
 
 
-int drm_rmmap(drm_device_t *dev, drm_local_map_t *map)
+int drm_rmmap(drm_device_t * dev, drm_local_map_t * map)
 {
 {
 	int ret;
 	int ret;
 
 
@@ -393,6 +397,7 @@ int drm_rmmap(drm_device_t *dev, drm_local_map_t *map)
 
 
 	return ret;
 	return ret;
 }
 }
+
 EXPORT_SYMBOL(drm_rmmap);
 EXPORT_SYMBOL(drm_rmmap);
 
 
 /* The rmmap ioctl appears to be unnecessary.  All mappings are torn down on
 /* The rmmap ioctl appears to be unnecessary.  All mappings are torn down on
@@ -414,7 +419,7 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
 	struct list_head *list;
 	struct list_head *list;
 	int ret;
 	int ret;
 
 
-	if (copy_from_user(&request, (drm_map_t __user *)arg, sizeof(request))) {
+	if (copy_from_user(&request, (drm_map_t __user *) arg, sizeof(request))) {
 		return -EFAULT;
 		return -EFAULT;
 	}
 	}
 
 
@@ -423,7 +428,7 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
 		drm_map_list_t *r_list = list_entry(list, drm_map_list_t, head);
 		drm_map_list_t *r_list = list_entry(list, drm_map_list_t, head);
 
 
 		if (r_list->map &&
 		if (r_list->map &&
-		    r_list->user_token == (unsigned long) request.handle &&
+		    r_list->user_token == (unsigned long)request.handle &&
 		    r_list->map->flags & _DRM_REMOVABLE) {
 		    r_list->map->flags & _DRM_REMOVABLE) {
 			map = r_list->map;
 			map = r_list->map;
 			break;
 			break;
@@ -462,7 +467,7 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
  *
  *
  * Frees any pages and buffers associated with the given entry.
  * Frees any pages and buffers associated with the given entry.
  */
  */
-static void drm_cleanup_buf_error(drm_device_t *dev, drm_buf_entry_t *entry)
+static void drm_cleanup_buf_error(drm_device_t * dev, drm_buf_entry_t * entry)
 {
 {
 	int i;
 	int i;
 
 
@@ -470,30 +475,27 @@ static void drm_cleanup_buf_error(drm_device_t *dev, drm_buf_entry_t *entry)
 		for (i = 0; i < entry->seg_count; i++) {
 		for (i = 0; i < entry->seg_count; i++) {
 			if (entry->seglist[i]) {
 			if (entry->seglist[i]) {
 				drm_free_pages(entry->seglist[i],
 				drm_free_pages(entry->seglist[i],
-					        entry->page_order,
-					        DRM_MEM_DMA);
+					       entry->page_order, DRM_MEM_DMA);
 			}
 			}
 		}
 		}
 		drm_free(entry->seglist,
 		drm_free(entry->seglist,
-			  entry->seg_count *
-			  sizeof(*entry->seglist),
-			  DRM_MEM_SEGS);
+			 entry->seg_count *
+			 sizeof(*entry->seglist), DRM_MEM_SEGS);
 
 
 		entry->seg_count = 0;
 		entry->seg_count = 0;
 	}
 	}
 
 
-   	if (entry->buf_count) {
-	   	for (i = 0; i < entry->buf_count; i++) {
+	if (entry->buf_count) {
+		for (i = 0; i < entry->buf_count; i++) {
 			if (entry->buflist[i].dev_private) {
 			if (entry->buflist[i].dev_private) {
 				drm_free(entry->buflist[i].dev_private,
 				drm_free(entry->buflist[i].dev_private,
-					  entry->buflist[i].dev_priv_size,
-					  DRM_MEM_BUFS);
+					 entry->buflist[i].dev_priv_size,
+					 DRM_MEM_BUFS);
 			}
 			}
 		}
 		}
 		drm_free(entry->buflist,
 		drm_free(entry->buflist,
-			  entry->buf_count *
-			  sizeof(*entry->buflist),
-			  DRM_MEM_BUFS);
+			 entry->buf_count *
+			 sizeof(*entry->buflist), DRM_MEM_BUFS);
 
 
 		entry->buf_count = 0;
 		entry->buf_count = 0;
 	}
 	}
@@ -506,12 +508,12 @@ static void drm_cleanup_buf_error(drm_device_t *dev, drm_buf_entry_t *entry)
  * \param dev drm_device_t to which the buffers are to be added.
  * \param dev drm_device_t to which the buffers are to be added.
  * \param request pointer to a drm_buf_desc_t describing the request.
  * \param request pointer to a drm_buf_desc_t describing the request.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
- * 
+ *
  * After some sanity checks creates a drm_buf structure for each buffer and
  * After some sanity checks creates a drm_buf structure for each buffer and
  * reallocates the buffer list of the same size order to accommodate the new
  * reallocates the buffer list of the same size order to accommodate the new
  * buffers.
  * buffers.
  */
  */
-int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
+int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
 	drm_buf_entry_t *entry;
 	drm_buf_entry_t *entry;
@@ -528,144 +530,145 @@ int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
 	int i;
 	int i;
 	drm_buf_t **temp_buflist;
 	drm_buf_t **temp_buflist;
 
 
-	if ( !dma ) return -EINVAL;
+	if (!dma)
+		return -EINVAL;
 
 
 	count = request->count;
 	count = request->count;
 	order = drm_order(request->size);
 	order = drm_order(request->size);
 	size = 1 << order;
 	size = 1 << order;
 
 
-	alignment  = (request->flags & _DRM_PAGE_ALIGN)
-		? PAGE_ALIGN(size) : size;
+	alignment = (request->flags & _DRM_PAGE_ALIGN)
+	    ? PAGE_ALIGN(size) : size;
 	page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
 	page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
 	total = PAGE_SIZE << page_order;
 	total = PAGE_SIZE << page_order;
 
 
 	byte_count = 0;
 	byte_count = 0;
 	agp_offset = dev->agp->base + request->agp_start;
 	agp_offset = dev->agp->base + request->agp_start;
 
 
-	DRM_DEBUG( "count:      %d\n",  count );
-	DRM_DEBUG( "order:      %d\n",  order );
-	DRM_DEBUG( "size:       %d\n",  size );
-	DRM_DEBUG( "agp_offset: %lu\n", agp_offset );
-	DRM_DEBUG( "alignment:  %d\n",  alignment );
-	DRM_DEBUG( "page_order: %d\n",  page_order );
-	DRM_DEBUG( "total:      %d\n",  total );
+	DRM_DEBUG("count:      %d\n", count);
+	DRM_DEBUG("order:      %d\n", order);
+	DRM_DEBUG("size:       %d\n", size);
+	DRM_DEBUG("agp_offset: %lu\n", agp_offset);
+	DRM_DEBUG("alignment:  %d\n", alignment);
+	DRM_DEBUG("page_order: %d\n", page_order);
+	DRM_DEBUG("total:      %d\n", total);
 
 
-	if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
-	if ( dev->queue_count ) return -EBUSY; /* Not while in use */
+	if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+		return -EINVAL;
+	if (dev->queue_count)
+		return -EBUSY;	/* Not while in use */
 
 
-	spin_lock( &dev->count_lock );
-	if ( dev->buf_use ) {
-		spin_unlock( &dev->count_lock );
+	spin_lock(&dev->count_lock);
+	if (dev->buf_use) {
+		spin_unlock(&dev->count_lock);
 		return -EBUSY;
 		return -EBUSY;
 	}
 	}
-	atomic_inc( &dev->buf_alloc );
-	spin_unlock( &dev->count_lock );
+	atomic_inc(&dev->buf_alloc);
+	spin_unlock(&dev->count_lock);
 
 
-	down( &dev->struct_sem );
+	down(&dev->struct_sem);
 	entry = &dma->bufs[order];
 	entry = &dma->bufs[order];
-	if ( entry->buf_count ) {
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
-		return -ENOMEM; /* May only call once for each order */
+	if (entry->buf_count) {
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
+		return -ENOMEM;	/* May only call once for each order */
 	}
 	}
 
 
 	if (count < 0 || count > 4096) {
 	if (count < 0 || count > 4096) {
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	entry->buflist = drm_alloc( count * sizeof(*entry->buflist),
-				    DRM_MEM_BUFS );
-	if ( !entry->buflist ) {
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+	entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
+				   DRM_MEM_BUFS);
+	if (!entry->buflist) {
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
-	memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
+	memset(entry->buflist, 0, count * sizeof(*entry->buflist));
 
 
 	entry->buf_size = size;
 	entry->buf_size = size;
 	entry->page_order = page_order;
 	entry->page_order = page_order;
 
 
 	offset = 0;
 	offset = 0;
 
 
-	while ( entry->buf_count < count ) {
-		buf          = &entry->buflist[entry->buf_count];
-		buf->idx     = dma->buf_count + entry->buf_count;
-		buf->total   = alignment;
-		buf->order   = order;
-		buf->used    = 0;
+	while (entry->buf_count < count) {
+		buf = &entry->buflist[entry->buf_count];
+		buf->idx = dma->buf_count + entry->buf_count;
+		buf->total = alignment;
+		buf->order = order;
+		buf->used = 0;
 
 
-		buf->offset  = (dma->byte_count + offset);
+		buf->offset = (dma->byte_count + offset);
 		buf->bus_address = agp_offset + offset;
 		buf->bus_address = agp_offset + offset;
 		buf->address = (void *)(agp_offset + offset);
 		buf->address = (void *)(agp_offset + offset);
-		buf->next    = NULL;
+		buf->next = NULL;
 		buf->waiting = 0;
 		buf->waiting = 0;
 		buf->pending = 0;
 		buf->pending = 0;
-		init_waitqueue_head( &buf->dma_wait );
-		buf->filp    = NULL;
+		init_waitqueue_head(&buf->dma_wait);
+		buf->filp = NULL;
 
 
 		buf->dev_priv_size = dev->driver->dev_priv_size;
 		buf->dev_priv_size = dev->driver->dev_priv_size;
-		buf->dev_private = drm_alloc( buf->dev_priv_size,
-					       DRM_MEM_BUFS );
-		if(!buf->dev_private) {
+		buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
+		if (!buf->dev_private) {
 			/* Set count correctly so we free the proper amount. */
 			/* Set count correctly so we free the proper amount. */
 			entry->buf_count = count;
 			entry->buf_count = count;
-			drm_cleanup_buf_error(dev,entry);
-			up( &dev->struct_sem );
-			atomic_dec( &dev->buf_alloc );
+			drm_cleanup_buf_error(dev, entry);
+			up(&dev->struct_sem);
+			atomic_dec(&dev->buf_alloc);
 			return -ENOMEM;
 			return -ENOMEM;
 		}
 		}
-		memset( buf->dev_private, 0, buf->dev_priv_size );
+		memset(buf->dev_private, 0, buf->dev_priv_size);
 
 
-		DRM_DEBUG( "buffer %d @ %p\n",
-			   entry->buf_count, buf->address );
+		DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
 
 
 		offset += alignment;
 		offset += alignment;
 		entry->buf_count++;
 		entry->buf_count++;
 		byte_count += PAGE_SIZE << page_order;
 		byte_count += PAGE_SIZE << page_order;
 	}
 	}
 
 
-	DRM_DEBUG( "byte_count: %d\n", byte_count );
+	DRM_DEBUG("byte_count: %d\n", byte_count);
 
 
-	temp_buflist = drm_realloc( dma->buflist,
-				     dma->buf_count * sizeof(*dma->buflist),
-				     (dma->buf_count + entry->buf_count)
-				     * sizeof(*dma->buflist),
-				     DRM_MEM_BUFS );
-	if(!temp_buflist) {
+	temp_buflist = drm_realloc(dma->buflist,
+				   dma->buf_count * sizeof(*dma->buflist),
+				   (dma->buf_count + entry->buf_count)
+				   * sizeof(*dma->buflist), DRM_MEM_BUFS);
+	if (!temp_buflist) {
 		/* Free the entry because it isn't valid */
 		/* Free the entry because it isn't valid */
-		drm_cleanup_buf_error(dev,entry);
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+		drm_cleanup_buf_error(dev, entry);
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 	dma->buflist = temp_buflist;
 	dma->buflist = temp_buflist;
 
 
-	for ( i = 0 ; i < entry->buf_count ; i++ ) {
+	for (i = 0; i < entry->buf_count; i++) {
 		dma->buflist[i + dma->buf_count] = &entry->buflist[i];
 		dma->buflist[i + dma->buf_count] = &entry->buflist[i];
 	}
 	}
 
 
 	dma->buf_count += entry->buf_count;
 	dma->buf_count += entry->buf_count;
 	dma->byte_count += byte_count;
 	dma->byte_count += byte_count;
 
 
-	DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
-	DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
+	DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
+	DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
 
 
-	up( &dev->struct_sem );
+	up(&dev->struct_sem);
 
 
 	request->count = entry->buf_count;
 	request->count = entry->buf_count;
 	request->size = size;
 	request->size = size;
 
 
 	dma->flags = _DRM_DMA_USE_AGP;
 	dma->flags = _DRM_DMA_USE_AGP;
 
 
-	atomic_dec( &dev->buf_alloc );
+	atomic_dec(&dev->buf_alloc);
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_addbufs_agp);
 EXPORT_SYMBOL(drm_addbufs_agp);
-#endif /* __OS_HAS_AGP */
+#endif				/* __OS_HAS_AGP */
 
 
-int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
+int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
 	int count;
 	int count;
@@ -684,178 +687,174 @@ int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
 	unsigned long *temp_pagelist;
 	unsigned long *temp_pagelist;
 	drm_buf_t **temp_buflist;
 	drm_buf_t **temp_buflist;
 
 
-	if (!drm_core_check_feature(dev, DRIVER_PCI_DMA)) return -EINVAL;
-	if ( !dma ) return -EINVAL;
+	if (!drm_core_check_feature(dev, DRIVER_PCI_DMA))
+		return -EINVAL;
+	if (!dma)
+		return -EINVAL;
 
 
 	count = request->count;
 	count = request->count;
 	order = drm_order(request->size);
 	order = drm_order(request->size);
 	size = 1 << order;
 	size = 1 << order;
 
 
-	DRM_DEBUG( "count=%d, size=%d (%d), order=%d, queue_count=%d\n",
-		   request->count, request->size, size,
-		   order, dev->queue_count );
+	DRM_DEBUG("count=%d, size=%d (%d), order=%d, queue_count=%d\n",
+		  request->count, request->size, size, order, dev->queue_count);
 
 
-	if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
-	if ( dev->queue_count ) return -EBUSY; /* Not while in use */
+	if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+		return -EINVAL;
+	if (dev->queue_count)
+		return -EBUSY;	/* Not while in use */
 
 
 	alignment = (request->flags & _DRM_PAGE_ALIGN)
 	alignment = (request->flags & _DRM_PAGE_ALIGN)
-		? PAGE_ALIGN(size) : size;
+	    ? PAGE_ALIGN(size) : size;
 	page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
 	page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
 	total = PAGE_SIZE << page_order;
 	total = PAGE_SIZE << page_order;
 
 
-	spin_lock( &dev->count_lock );
-	if ( dev->buf_use ) {
-		spin_unlock( &dev->count_lock );
+	spin_lock(&dev->count_lock);
+	if (dev->buf_use) {
+		spin_unlock(&dev->count_lock);
 		return -EBUSY;
 		return -EBUSY;
 	}
 	}
-	atomic_inc( &dev->buf_alloc );
-	spin_unlock( &dev->count_lock );
+	atomic_inc(&dev->buf_alloc);
+	spin_unlock(&dev->count_lock);
 
 
-	down( &dev->struct_sem );
+	down(&dev->struct_sem);
 	entry = &dma->bufs[order];
 	entry = &dma->bufs[order];
-	if ( entry->buf_count ) {
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+	if (entry->buf_count) {
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -ENOMEM;	/* May only call once for each order */
 		return -ENOMEM;	/* May only call once for each order */
 	}
 	}
 
 
 	if (count < 0 || count > 4096) {
 	if (count < 0 || count > 4096) {
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	entry->buflist = drm_alloc( count * sizeof(*entry->buflist),
-				    DRM_MEM_BUFS );
-	if ( !entry->buflist ) {
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+	entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
+				   DRM_MEM_BUFS);
+	if (!entry->buflist) {
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
-	memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
-
-	entry->seglist = drm_alloc( count * sizeof(*entry->seglist),
-				    DRM_MEM_SEGS );
-	if ( !entry->seglist ) {
-		drm_free( entry->buflist,
-			  count * sizeof(*entry->buflist),
-			  DRM_MEM_BUFS );
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+	memset(entry->buflist, 0, count * sizeof(*entry->buflist));
+
+	entry->seglist = drm_alloc(count * sizeof(*entry->seglist),
+				   DRM_MEM_SEGS);
+	if (!entry->seglist) {
+		drm_free(entry->buflist,
+			 count * sizeof(*entry->buflist), DRM_MEM_BUFS);
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
-	memset( entry->seglist, 0, count * sizeof(*entry->seglist) );
+	memset(entry->seglist, 0, count * sizeof(*entry->seglist));
 
 
 	/* Keep the original pagelist until we know all the allocations
 	/* Keep the original pagelist until we know all the allocations
 	 * have succeeded
 	 * have succeeded
 	 */
 	 */
-	temp_pagelist = drm_alloc( (dma->page_count + (count << page_order))
-				    * sizeof(*dma->pagelist),
-				    DRM_MEM_PAGES );
+	temp_pagelist = drm_alloc((dma->page_count + (count << page_order))
+				  * sizeof(*dma->pagelist), DRM_MEM_PAGES);
 	if (!temp_pagelist) {
 	if (!temp_pagelist) {
-		drm_free( entry->buflist,
-			   count * sizeof(*entry->buflist),
-			   DRM_MEM_BUFS );
-		drm_free( entry->seglist,
-			   count * sizeof(*entry->seglist),
-			   DRM_MEM_SEGS );
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+		drm_free(entry->buflist,
+			 count * sizeof(*entry->buflist), DRM_MEM_BUFS);
+		drm_free(entry->seglist,
+			 count * sizeof(*entry->seglist), DRM_MEM_SEGS);
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 	memcpy(temp_pagelist,
 	memcpy(temp_pagelist,
-	       dma->pagelist,
-	       dma->page_count * sizeof(*dma->pagelist));
-	DRM_DEBUG( "pagelist: %d entries\n",
-		   dma->page_count + (count << page_order) );
+	       dma->pagelist, dma->page_count * sizeof(*dma->pagelist));
+	DRM_DEBUG("pagelist: %d entries\n",
+		  dma->page_count + (count << page_order));
 
 
-	entry->buf_size	= size;
+	entry->buf_size = size;
 	entry->page_order = page_order;
 	entry->page_order = page_order;
 	byte_count = 0;
 	byte_count = 0;
 	page_count = 0;
 	page_count = 0;
 
 
-	while ( entry->buf_count < count ) {
-		page = drm_alloc_pages( page_order, DRM_MEM_DMA );
-		if ( !page ) {
+	while (entry->buf_count < count) {
+		page = drm_alloc_pages(page_order, DRM_MEM_DMA);
+		if (!page) {
 			/* Set count correctly so we free the proper amount. */
 			/* Set count correctly so we free the proper amount. */
 			entry->buf_count = count;
 			entry->buf_count = count;
 			entry->seg_count = count;
 			entry->seg_count = count;
 			drm_cleanup_buf_error(dev, entry);
 			drm_cleanup_buf_error(dev, entry);
-			drm_free( temp_pagelist,
-				   (dma->page_count + (count << page_order))
-				   * sizeof(*dma->pagelist),
-				   DRM_MEM_PAGES );
-			up( &dev->struct_sem );
-			atomic_dec( &dev->buf_alloc );
+			drm_free(temp_pagelist,
+				 (dma->page_count + (count << page_order))
+				 * sizeof(*dma->pagelist), DRM_MEM_PAGES);
+			up(&dev->struct_sem);
+			atomic_dec(&dev->buf_alloc);
 			return -ENOMEM;
 			return -ENOMEM;
 		}
 		}
 		entry->seglist[entry->seg_count++] = page;
 		entry->seglist[entry->seg_count++] = page;
-		for ( i = 0 ; i < (1 << page_order) ; i++ ) {
-			DRM_DEBUG( "page %d @ 0x%08lx\n",
-				   dma->page_count + page_count,
-				   page + PAGE_SIZE * i );
+		for (i = 0; i < (1 << page_order); i++) {
+			DRM_DEBUG("page %d @ 0x%08lx\n",
+				  dma->page_count + page_count,
+				  page + PAGE_SIZE * i);
 			temp_pagelist[dma->page_count + page_count++]
 			temp_pagelist[dma->page_count + page_count++]
-				= page + PAGE_SIZE * i;
+			    = page + PAGE_SIZE * i;
 		}
 		}
-		for ( offset = 0 ;
-		      offset + size <= total && entry->buf_count < count ;
-		      offset += alignment, ++entry->buf_count ) {
-			buf	     = &entry->buflist[entry->buf_count];
-			buf->idx     = dma->buf_count + entry->buf_count;
-			buf->total   = alignment;
-			buf->order   = order;
-			buf->used    = 0;
-			buf->offset  = (dma->byte_count + byte_count + offset);
+		for (offset = 0;
+		     offset + size <= total && entry->buf_count < count;
+		     offset += alignment, ++entry->buf_count) {
+			buf = &entry->buflist[entry->buf_count];
+			buf->idx = dma->buf_count + entry->buf_count;
+			buf->total = alignment;
+			buf->order = order;
+			buf->used = 0;
+			buf->offset = (dma->byte_count + byte_count + offset);
 			buf->address = (void *)(page + offset);
 			buf->address = (void *)(page + offset);
-			buf->next    = NULL;
+			buf->next = NULL;
 			buf->waiting = 0;
 			buf->waiting = 0;
 			buf->pending = 0;
 			buf->pending = 0;
-			init_waitqueue_head( &buf->dma_wait );
-			buf->filp    = NULL;
+			init_waitqueue_head(&buf->dma_wait);
+			buf->filp = NULL;
 
 
 			buf->dev_priv_size = dev->driver->dev_priv_size;
 			buf->dev_priv_size = dev->driver->dev_priv_size;
-			buf->dev_private = drm_alloc( buf->dev_priv_size,
-						       DRM_MEM_BUFS );
-			if(!buf->dev_private) {
+			buf->dev_private = drm_alloc(buf->dev_priv_size,
+						     DRM_MEM_BUFS);
+			if (!buf->dev_private) {
 				/* Set count correctly so we free the proper amount. */
 				/* Set count correctly so we free the proper amount. */
 				entry->buf_count = count;
 				entry->buf_count = count;
 				entry->seg_count = count;
 				entry->seg_count = count;
-				drm_cleanup_buf_error(dev,entry);
-				drm_free( temp_pagelist,
-					   (dma->page_count + (count << page_order))
-					   * sizeof(*dma->pagelist),
-					   DRM_MEM_PAGES );
-				up( &dev->struct_sem );
-				atomic_dec( &dev->buf_alloc );
+				drm_cleanup_buf_error(dev, entry);
+				drm_free(temp_pagelist,
+					 (dma->page_count +
+					  (count << page_order))
+					 * sizeof(*dma->pagelist),
+					 DRM_MEM_PAGES);
+				up(&dev->struct_sem);
+				atomic_dec(&dev->buf_alloc);
 				return -ENOMEM;
 				return -ENOMEM;
 			}
 			}
-			memset( buf->dev_private, 0, buf->dev_priv_size );
+			memset(buf->dev_private, 0, buf->dev_priv_size);
 
 
-			DRM_DEBUG( "buffer %d @ %p\n",
-				   entry->buf_count, buf->address );
+			DRM_DEBUG("buffer %d @ %p\n",
+				  entry->buf_count, buf->address);
 		}
 		}
 		byte_count += PAGE_SIZE << page_order;
 		byte_count += PAGE_SIZE << page_order;
 	}
 	}
 
 
-	temp_buflist = drm_realloc( dma->buflist,
-				     dma->buf_count * sizeof(*dma->buflist),
-				     (dma->buf_count + entry->buf_count)
-				     * sizeof(*dma->buflist),
-				     DRM_MEM_BUFS );
+	temp_buflist = drm_realloc(dma->buflist,
+				   dma->buf_count * sizeof(*dma->buflist),
+				   (dma->buf_count + entry->buf_count)
+				   * sizeof(*dma->buflist), DRM_MEM_BUFS);
 	if (!temp_buflist) {
 	if (!temp_buflist) {
 		/* Free the entry because it isn't valid */
 		/* Free the entry because it isn't valid */
-		drm_cleanup_buf_error(dev,entry);
-		drm_free( temp_pagelist,
-			   (dma->page_count + (count << page_order))
-			   * sizeof(*dma->pagelist),
-			   DRM_MEM_PAGES );
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+		drm_cleanup_buf_error(dev, entry);
+		drm_free(temp_pagelist,
+			 (dma->page_count + (count << page_order))
+			 * sizeof(*dma->pagelist), DRM_MEM_PAGES);
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 	dma->buflist = temp_buflist;
 	dma->buflist = temp_buflist;
 
 
-	for ( i = 0 ; i < entry->buf_count ; i++ ) {
+	for (i = 0; i < entry->buf_count; i++) {
 		dma->buflist[i + dma->buf_count] = &entry->buflist[i];
 		dma->buflist[i + dma->buf_count] = &entry->buflist[i];
 	}
 	}
 
 
@@ -864,8 +863,8 @@ int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
 	 */
 	 */
 	if (dma->page_count) {
 	if (dma->page_count) {
 		drm_free(dma->pagelist,
 		drm_free(dma->pagelist,
-			  dma->page_count * sizeof(*dma->pagelist),
-			  DRM_MEM_PAGES);
+			 dma->page_count * sizeof(*dma->pagelist),
+			 DRM_MEM_PAGES);
 	}
 	}
 	dma->pagelist = temp_pagelist;
 	dma->pagelist = temp_pagelist;
 
 
@@ -874,18 +873,19 @@ int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
 	dma->page_count += entry->seg_count << page_order;
 	dma->page_count += entry->seg_count << page_order;
 	dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
 	dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
 
 
-	up( &dev->struct_sem );
+	up(&dev->struct_sem);
 
 
 	request->count = entry->buf_count;
 	request->count = entry->buf_count;
 	request->size = size;
 	request->size = size;
 
 
-	atomic_dec( &dev->buf_alloc );
+	atomic_dec(&dev->buf_alloc);
 	return 0;
 	return 0;
 
 
 }
 }
+
 EXPORT_SYMBOL(drm_addbufs_pci);
 EXPORT_SYMBOL(drm_addbufs_pci);
 
 
-static int drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
+static int drm_addbufs_sg(drm_device_t * dev, drm_buf_desc_t * request)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
 	drm_buf_entry_t *entry;
 	drm_buf_entry_t *entry;
@@ -902,146 +902,147 @@ static int drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
 	int i;
 	int i;
 	drm_buf_t **temp_buflist;
 	drm_buf_t **temp_buflist;
 
 
-	if (!drm_core_check_feature(dev, DRIVER_SG)) return -EINVAL;
-	
-	if ( !dma ) return -EINVAL;
+	if (!drm_core_check_feature(dev, DRIVER_SG))
+		return -EINVAL;
+
+	if (!dma)
+		return -EINVAL;
 
 
 	count = request->count;
 	count = request->count;
 	order = drm_order(request->size);
 	order = drm_order(request->size);
 	size = 1 << order;
 	size = 1 << order;
 
 
-	alignment  = (request->flags & _DRM_PAGE_ALIGN)
-			? PAGE_ALIGN(size) : size;
+	alignment = (request->flags & _DRM_PAGE_ALIGN)
+	    ? PAGE_ALIGN(size) : size;
 	page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
 	page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
 	total = PAGE_SIZE << page_order;
 	total = PAGE_SIZE << page_order;
 
 
 	byte_count = 0;
 	byte_count = 0;
 	agp_offset = request->agp_start;
 	agp_offset = request->agp_start;
 
 
-	DRM_DEBUG( "count:      %d\n",  count );
-	DRM_DEBUG( "order:      %d\n",  order );
-	DRM_DEBUG( "size:       %d\n",  size );
-	DRM_DEBUG( "agp_offset: %lu\n", agp_offset );
-	DRM_DEBUG( "alignment:  %d\n",  alignment );
-	DRM_DEBUG( "page_order: %d\n",  page_order );
-	DRM_DEBUG( "total:      %d\n",  total );
+	DRM_DEBUG("count:      %d\n", count);
+	DRM_DEBUG("order:      %d\n", order);
+	DRM_DEBUG("size:       %d\n", size);
+	DRM_DEBUG("agp_offset: %lu\n", agp_offset);
+	DRM_DEBUG("alignment:  %d\n", alignment);
+	DRM_DEBUG("page_order: %d\n", page_order);
+	DRM_DEBUG("total:      %d\n", total);
 
 
-	if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
-	if ( dev->queue_count ) return -EBUSY; /* Not while in use */
+	if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+		return -EINVAL;
+	if (dev->queue_count)
+		return -EBUSY;	/* Not while in use */
 
 
-	spin_lock( &dev->count_lock );
-	if ( dev->buf_use ) {
-		spin_unlock( &dev->count_lock );
+	spin_lock(&dev->count_lock);
+	if (dev->buf_use) {
+		spin_unlock(&dev->count_lock);
 		return -EBUSY;
 		return -EBUSY;
 	}
 	}
-	atomic_inc( &dev->buf_alloc );
-	spin_unlock( &dev->count_lock );
+	atomic_inc(&dev->buf_alloc);
+	spin_unlock(&dev->count_lock);
 
 
-	down( &dev->struct_sem );
+	down(&dev->struct_sem);
 	entry = &dma->bufs[order];
 	entry = &dma->bufs[order];
-	if ( entry->buf_count ) {
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
-		return -ENOMEM; /* May only call once for each order */
+	if (entry->buf_count) {
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
+		return -ENOMEM;	/* May only call once for each order */
 	}
 	}
 
 
 	if (count < 0 || count > 4096) {
 	if (count < 0 || count > 4096) {
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	entry->buflist = drm_alloc( count * sizeof(*entry->buflist),
-				     DRM_MEM_BUFS );
-	if ( !entry->buflist ) {
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+	entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
+				   DRM_MEM_BUFS);
+	if (!entry->buflist) {
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
-	memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
+	memset(entry->buflist, 0, count * sizeof(*entry->buflist));
 
 
 	entry->buf_size = size;
 	entry->buf_size = size;
 	entry->page_order = page_order;
 	entry->page_order = page_order;
 
 
 	offset = 0;
 	offset = 0;
 
 
-	while ( entry->buf_count < count ) {
-		buf          = &entry->buflist[entry->buf_count];
-		buf->idx     = dma->buf_count + entry->buf_count;
-		buf->total   = alignment;
-		buf->order   = order;
-		buf->used    = 0;
+	while (entry->buf_count < count) {
+		buf = &entry->buflist[entry->buf_count];
+		buf->idx = dma->buf_count + entry->buf_count;
+		buf->total = alignment;
+		buf->order = order;
+		buf->used = 0;
 
 
-		buf->offset  = (dma->byte_count + offset);
+		buf->offset = (dma->byte_count + offset);
 		buf->bus_address = agp_offset + offset;
 		buf->bus_address = agp_offset + offset;
-		buf->address = (void *)(agp_offset + offset 
+		buf->address = (void *)(agp_offset + offset
 					+ (unsigned long)dev->sg->virtual);
 					+ (unsigned long)dev->sg->virtual);
-		buf->next    = NULL;
+		buf->next = NULL;
 		buf->waiting = 0;
 		buf->waiting = 0;
 		buf->pending = 0;
 		buf->pending = 0;
-		init_waitqueue_head( &buf->dma_wait );
-		buf->filp    = NULL;
+		init_waitqueue_head(&buf->dma_wait);
+		buf->filp = NULL;
 
 
 		buf->dev_priv_size = dev->driver->dev_priv_size;
 		buf->dev_priv_size = dev->driver->dev_priv_size;
-		buf->dev_private = drm_alloc( buf->dev_priv_size,
-					       DRM_MEM_BUFS );
-		if(!buf->dev_private) {
+		buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
+		if (!buf->dev_private) {
 			/* Set count correctly so we free the proper amount. */
 			/* Set count correctly so we free the proper amount. */
 			entry->buf_count = count;
 			entry->buf_count = count;
-			drm_cleanup_buf_error(dev,entry);
-			up( &dev->struct_sem );
-			atomic_dec( &dev->buf_alloc );
+			drm_cleanup_buf_error(dev, entry);
+			up(&dev->struct_sem);
+			atomic_dec(&dev->buf_alloc);
 			return -ENOMEM;
 			return -ENOMEM;
 		}
 		}
 
 
-		memset( buf->dev_private, 0, buf->dev_priv_size );
+		memset(buf->dev_private, 0, buf->dev_priv_size);
 
 
-		DRM_DEBUG( "buffer %d @ %p\n",
-			   entry->buf_count, buf->address );
+		DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
 
 
 		offset += alignment;
 		offset += alignment;
 		entry->buf_count++;
 		entry->buf_count++;
 		byte_count += PAGE_SIZE << page_order;
 		byte_count += PAGE_SIZE << page_order;
 	}
 	}
 
 
-	DRM_DEBUG( "byte_count: %d\n", byte_count );
+	DRM_DEBUG("byte_count: %d\n", byte_count);
 
 
-	temp_buflist = drm_realloc( dma->buflist,
-				     dma->buf_count * sizeof(*dma->buflist),
-				     (dma->buf_count + entry->buf_count)
-				     * sizeof(*dma->buflist),
-				     DRM_MEM_BUFS );
-	if(!temp_buflist) {
+	temp_buflist = drm_realloc(dma->buflist,
+				   dma->buf_count * sizeof(*dma->buflist),
+				   (dma->buf_count + entry->buf_count)
+				   * sizeof(*dma->buflist), DRM_MEM_BUFS);
+	if (!temp_buflist) {
 		/* Free the entry because it isn't valid */
 		/* Free the entry because it isn't valid */
-		drm_cleanup_buf_error(dev,entry);
-		up( &dev->struct_sem );
-		atomic_dec( &dev->buf_alloc );
+		drm_cleanup_buf_error(dev, entry);
+		up(&dev->struct_sem);
+		atomic_dec(&dev->buf_alloc);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 	dma->buflist = temp_buflist;
 	dma->buflist = temp_buflist;
 
 
-	for ( i = 0 ; i < entry->buf_count ; i++ ) {
+	for (i = 0; i < entry->buf_count; i++) {
 		dma->buflist[i + dma->buf_count] = &entry->buflist[i];
 		dma->buflist[i + dma->buf_count] = &entry->buflist[i];
 	}
 	}
 
 
 	dma->buf_count += entry->buf_count;
 	dma->buf_count += entry->buf_count;
 	dma->byte_count += byte_count;
 	dma->byte_count += byte_count;
 
 
-	DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
-	DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
+	DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
+	DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
 
 
-	up( &dev->struct_sem );
+	up(&dev->struct_sem);
 
 
 	request->count = entry->buf_count;
 	request->count = entry->buf_count;
 	request->size = size;
 	request->size = size;
 
 
 	dma->flags = _DRM_DMA_USE_SG;
 	dma->flags = _DRM_DMA_USE_SG;
 
 
-	atomic_dec( &dev->buf_alloc );
+	atomic_dec(&dev->buf_alloc);
 	return 0;
 	return 0;
 }
 }
 
 
-static int drm_addbufs_fb(drm_device_t *dev, drm_buf_desc_t *request)
+static int drm_addbufs_fb(drm_device_t * dev, drm_buf_desc_t * request)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
 	drm_buf_entry_t *entry;
 	drm_buf_entry_t *entry;
@@ -1060,7 +1061,7 @@ static int drm_addbufs_fb(drm_device_t *dev, drm_buf_desc_t *request)
 
 
 	if (!drm_core_check_feature(dev, DRIVER_FB_DMA))
 	if (!drm_core_check_feature(dev, DRIVER_FB_DMA))
 		return -EINVAL;
 		return -EINVAL;
-    
+
 	if (!dma)
 	if (!dma)
 		return -EINVAL;
 		return -EINVAL;
 
 
@@ -1210,43 +1211,41 @@ static int drm_addbufs_fb(drm_device_t *dev, drm_buf_desc_t *request)
  * addbufs_sg() or addbufs_pci() for AGP, scatter-gather or consistent
  * addbufs_sg() or addbufs_pci() for AGP, scatter-gather or consistent
  * PCI memory respectively.
  * PCI memory respectively.
  */
  */
-int drm_addbufs( struct inode *inode, struct file *filp,
-		  unsigned int cmd, unsigned long arg )
+int drm_addbufs(struct inode *inode, struct file *filp,
+		unsigned int cmd, unsigned long arg)
 {
 {
 	drm_buf_desc_t request;
 	drm_buf_desc_t request;
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	int ret;
 	int ret;
-	
+
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 		return -EINVAL;
 		return -EINVAL;
 
 
-	if ( copy_from_user( &request, (drm_buf_desc_t __user *)arg,
-			     sizeof(request) ) )
+	if (copy_from_user(&request, (drm_buf_desc_t __user *) arg,
+			   sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 #if __OS_HAS_AGP
 #if __OS_HAS_AGP
-	if ( request.flags & _DRM_AGP_BUFFER )
-		ret=drm_addbufs_agp(dev, &request);
+	if (request.flags & _DRM_AGP_BUFFER)
+		ret = drm_addbufs_agp(dev, &request);
 	else
 	else
 #endif
 #endif
-	if ( request.flags & _DRM_SG_BUFFER )
-		ret=drm_addbufs_sg(dev, &request);
-	else if ( request.flags & _DRM_FB_BUFFER)
-		ret=drm_addbufs_fb(dev, &request);
+	if (request.flags & _DRM_SG_BUFFER)
+		ret = drm_addbufs_sg(dev, &request);
+	else if (request.flags & _DRM_FB_BUFFER)
+		ret = drm_addbufs_fb(dev, &request);
 	else
 	else
-		ret=drm_addbufs_pci(dev, &request);
+		ret = drm_addbufs_pci(dev, &request);
 
 
-	if (ret==0) {
-		if (copy_to_user((void __user *)arg, &request,
-				 sizeof(request))) {
+	if (ret == 0) {
+		if (copy_to_user((void __user *)arg, &request, sizeof(request))) {
 			ret = -EFAULT;
 			ret = -EFAULT;
 		}
 		}
 	}
 	}
 	return ret;
 	return ret;
 }
 }
 
 
-
 /**
 /**
  * Get information about the buffer mappings.
  * Get information about the buffer mappings.
  *
  *
@@ -1264,8 +1263,8 @@ int drm_addbufs( struct inode *inode, struct file *filp,
  * lock, preventing of allocating more buffers after this call. Information
  * lock, preventing of allocating more buffers after this call. Information
  * about each requested buffer is then copied into user space.
  * about each requested buffer is then copied into user space.
  */
  */
-int drm_infobufs( struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg )
+int drm_infobufs(struct inode *inode, struct file *filp,
+		 unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -1278,58 +1277,61 @@ int drm_infobufs( struct inode *inode, struct file *filp,
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 		return -EINVAL;
 		return -EINVAL;
 
 
-	if ( !dma ) return -EINVAL;
+	if (!dma)
+		return -EINVAL;
 
 
-	spin_lock( &dev->count_lock );
-	if ( atomic_read( &dev->buf_alloc ) ) {
-		spin_unlock( &dev->count_lock );
+	spin_lock(&dev->count_lock);
+	if (atomic_read(&dev->buf_alloc)) {
+		spin_unlock(&dev->count_lock);
 		return -EBUSY;
 		return -EBUSY;
 	}
 	}
 	++dev->buf_use;		/* Can't allocate more after this call */
 	++dev->buf_use;		/* Can't allocate more after this call */
-	spin_unlock( &dev->count_lock );
+	spin_unlock(&dev->count_lock);
 
 
-	if ( copy_from_user( &request, argp, sizeof(request) ) )
+	if (copy_from_user(&request, argp, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
-		if ( dma->bufs[i].buf_count ) ++count;
+	for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
+		if (dma->bufs[i].buf_count)
+			++count;
 	}
 	}
 
 
-	DRM_DEBUG( "count = %d\n", count );
+	DRM_DEBUG("count = %d\n", count);
 
 
-	if ( request.count >= count ) {
-		for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
-			if ( dma->bufs[i].buf_count ) {
-				drm_buf_desc_t __user *to = &request.list[count];
+	if (request.count >= count) {
+		for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
+			if (dma->bufs[i].buf_count) {
+				drm_buf_desc_t __user *to =
+				    &request.list[count];
 				drm_buf_entry_t *from = &dma->bufs[i];
 				drm_buf_entry_t *from = &dma->bufs[i];
 				drm_freelist_t *list = &dma->bufs[i].freelist;
 				drm_freelist_t *list = &dma->bufs[i].freelist;
-				if ( copy_to_user( &to->count,
-						   &from->buf_count,
-						   sizeof(from->buf_count) ) ||
-				     copy_to_user( &to->size,
-						   &from->buf_size,
-						   sizeof(from->buf_size) ) ||
-				     copy_to_user( &to->low_mark,
-						   &list->low_mark,
-						   sizeof(list->low_mark) ) ||
-				     copy_to_user( &to->high_mark,
-						   &list->high_mark,
-						   sizeof(list->high_mark) ) )
+				if (copy_to_user(&to->count,
+						 &from->buf_count,
+						 sizeof(from->buf_count)) ||
+				    copy_to_user(&to->size,
+						 &from->buf_size,
+						 sizeof(from->buf_size)) ||
+				    copy_to_user(&to->low_mark,
+						 &list->low_mark,
+						 sizeof(list->low_mark)) ||
+				    copy_to_user(&to->high_mark,
+						 &list->high_mark,
+						 sizeof(list->high_mark)))
 					return -EFAULT;
 					return -EFAULT;
 
 
-				DRM_DEBUG( "%d %d %d %d %d\n",
-					   i,
-					   dma->bufs[i].buf_count,
-					   dma->bufs[i].buf_size,
-					   dma->bufs[i].freelist.low_mark,
-					   dma->bufs[i].freelist.high_mark );
+				DRM_DEBUG("%d %d %d %d %d\n",
+					  i,
+					  dma->bufs[i].buf_count,
+					  dma->bufs[i].buf_size,
+					  dma->bufs[i].freelist.low_mark,
+					  dma->bufs[i].freelist.high_mark);
 				++count;
 				++count;
 			}
 			}
 		}
 		}
 	}
 	}
 	request.count = count;
 	request.count = count;
 
 
-	if ( copy_to_user( argp, &request, sizeof(request) ) )
+	if (copy_to_user(argp, &request, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return 0;
 	return 0;
@@ -1349,8 +1351,8 @@ int drm_infobufs( struct inode *inode, struct file *filp,
  *
  *
  * \note This ioctl is deprecated and mostly never used.
  * \note This ioctl is deprecated and mostly never used.
  */
  */
-int drm_markbufs( struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg )
+int drm_markbufs(struct inode *inode, struct file *filp,
+		 unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -1362,44 +1364,45 @@ int drm_markbufs( struct inode *inode, struct file *filp,
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 		return -EINVAL;
 		return -EINVAL;
 
 
-	if ( !dma ) return -EINVAL;
+	if (!dma)
+		return -EINVAL;
 
 
-	if ( copy_from_user( &request,
-			     (drm_buf_desc_t __user *)arg,
-			     sizeof(request) ) )
+	if (copy_from_user(&request,
+			   (drm_buf_desc_t __user *) arg, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	DRM_DEBUG( "%d, %d, %d\n",
-		   request.size, request.low_mark, request.high_mark );
-	order = drm_order( request.size );
-	if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
+	DRM_DEBUG("%d, %d, %d\n",
+		  request.size, request.low_mark, request.high_mark);
+	order = drm_order(request.size);
+	if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+		return -EINVAL;
 	entry = &dma->bufs[order];
 	entry = &dma->bufs[order];
 
 
-	if ( request.low_mark < 0 || request.low_mark > entry->buf_count )
+	if (request.low_mark < 0 || request.low_mark > entry->buf_count)
 		return -EINVAL;
 		return -EINVAL;
-	if ( request.high_mark < 0 || request.high_mark > entry->buf_count )
+	if (request.high_mark < 0 || request.high_mark > entry->buf_count)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	entry->freelist.low_mark  = request.low_mark;
+	entry->freelist.low_mark = request.low_mark;
 	entry->freelist.high_mark = request.high_mark;
 	entry->freelist.high_mark = request.high_mark;
 
 
 	return 0;
 	return 0;
 }
 }
 
 
 /**
 /**
- * Unreserve the buffers in list, previously reserved using drmDMA. 
+ * Unreserve the buffers in list, previously reserved using drmDMA.
  *
  *
  * \param inode device inode.
  * \param inode device inode.
  * \param filp file pointer.
  * \param filp file pointer.
  * \param cmd command.
  * \param cmd command.
  * \param arg pointer to a drm_buf_free structure.
  * \param arg pointer to a drm_buf_free structure.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
- * 
+ *
  * Calls free_buffer() for each used buffer.
  * Calls free_buffer() for each used buffer.
  * This function is primarily used for debugging.
  * This function is primarily used for debugging.
  */
  */
-int drm_freebufs( struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg )
+int drm_freebufs(struct inode *inode, struct file *filp,
+		 unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -1412,31 +1415,29 @@ int drm_freebufs( struct inode *inode, struct file *filp,
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 		return -EINVAL;
 		return -EINVAL;
 
 
-	if ( !dma ) return -EINVAL;
+	if (!dma)
+		return -EINVAL;
 
 
-	if ( copy_from_user( &request,
-			     (drm_buf_free_t __user *)arg,
-			     sizeof(request) ) )
+	if (copy_from_user(&request,
+			   (drm_buf_free_t __user *) arg, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	DRM_DEBUG( "%d\n", request.count );
-	for ( i = 0 ; i < request.count ; i++ ) {
-		if ( copy_from_user( &idx,
-				     &request.list[i],
-				     sizeof(idx) ) )
+	DRM_DEBUG("%d\n", request.count);
+	for (i = 0; i < request.count; i++) {
+		if (copy_from_user(&idx, &request.list[i], sizeof(idx)))
 			return -EFAULT;
 			return -EFAULT;
-		if ( idx < 0 || idx >= dma->buf_count ) {
-			DRM_ERROR( "Index %d (of %d max)\n",
-				   idx, dma->buf_count - 1 );
+		if (idx < 0 || idx >= dma->buf_count) {
+			DRM_ERROR("Index %d (of %d max)\n",
+				  idx, dma->buf_count - 1);
 			return -EINVAL;
 			return -EINVAL;
 		}
 		}
 		buf = dma->buflist[idx];
 		buf = dma->buflist[idx];
-		if ( buf->filp != filp ) {
-			DRM_ERROR( "Process %d freeing buffer not owned\n",
-				   current->pid );
+		if (buf->filp != filp) {
+			DRM_ERROR("Process %d freeing buffer not owned\n",
+				  current->pid);
 			return -EINVAL;
 			return -EINVAL;
 		}
 		}
-		drm_free_buffer( dev, buf );
+		drm_free_buffer(dev, buf);
 	}
 	}
 
 
 	return 0;
 	return 0;
@@ -1455,8 +1456,8 @@ int drm_freebufs( struct inode *inode, struct file *filp,
  * about each buffer into user space. The PCI buffers are already mapped on the
  * about each buffer into user space. The PCI buffers are already mapped on the
  * addbufs_pci() call.
  * addbufs_pci() call.
  */
  */
-int drm_mapbufs( struct inode *inode, struct file *filp,
-		  unsigned int cmd, unsigned long arg )
+int drm_mapbufs(struct inode *inode, struct file *filp,
+		unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -1472,86 +1473,84 @@ int drm_mapbufs( struct inode *inode, struct file *filp,
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 		return -EINVAL;
 		return -EINVAL;
 
 
-	if ( !dma ) return -EINVAL;
+	if (!dma)
+		return -EINVAL;
 
 
-	spin_lock( &dev->count_lock );
-	if ( atomic_read( &dev->buf_alloc ) ) {
-		spin_unlock( &dev->count_lock );
+	spin_lock(&dev->count_lock);
+	if (atomic_read(&dev->buf_alloc)) {
+		spin_unlock(&dev->count_lock);
 		return -EBUSY;
 		return -EBUSY;
 	}
 	}
 	dev->buf_use++;		/* Can't allocate more after this call */
 	dev->buf_use++;		/* Can't allocate more after this call */
-	spin_unlock( &dev->count_lock );
+	spin_unlock(&dev->count_lock);
 
 
-	if ( copy_from_user( &request, argp, sizeof(request) ) )
+	if (copy_from_user(&request, argp, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	if ( request.count >= dma->buf_count ) {
+	if (request.count >= dma->buf_count) {
 		if ((drm_core_has_AGP(dev) && (dma->flags & _DRM_DMA_USE_AGP))
 		if ((drm_core_has_AGP(dev) && (dma->flags & _DRM_DMA_USE_AGP))
-		    || (drm_core_check_feature(dev, DRIVER_SG) 
+		    || (drm_core_check_feature(dev, DRIVER_SG)
 			&& (dma->flags & _DRM_DMA_USE_SG))
 			&& (dma->flags & _DRM_DMA_USE_SG))
 		    || (drm_core_check_feature(dev, DRIVER_FB_DMA)
 		    || (drm_core_check_feature(dev, DRIVER_FB_DMA)
 			&& (dma->flags & _DRM_DMA_USE_FB))) {
 			&& (dma->flags & _DRM_DMA_USE_FB))) {
 			drm_map_t *map = dev->agp_buffer_map;
 			drm_map_t *map = dev->agp_buffer_map;
 			unsigned long token = dev->agp_buffer_token;
 			unsigned long token = dev->agp_buffer_token;
 
 
-			if ( !map ) {
+			if (!map) {
 				retcode = -EINVAL;
 				retcode = -EINVAL;
 				goto done;
 				goto done;
 			}
 			}
 
 
-			down_write( &current->mm->mmap_sem );
-			virtual = do_mmap( filp, 0, map->size,
-					   PROT_READ | PROT_WRITE,
-					   MAP_SHARED,
-					   token );
-			up_write( &current->mm->mmap_sem );
+			down_write(&current->mm->mmap_sem);
+			virtual = do_mmap(filp, 0, map->size,
+					  PROT_READ | PROT_WRITE,
+					  MAP_SHARED, token);
+			up_write(&current->mm->mmap_sem);
 		} else {
 		} else {
-			down_write( &current->mm->mmap_sem );
-			virtual = do_mmap( filp, 0, dma->byte_count,
-					   PROT_READ | PROT_WRITE,
-					   MAP_SHARED, 0 );
-			up_write( &current->mm->mmap_sem );
+			down_write(&current->mm->mmap_sem);
+			virtual = do_mmap(filp, 0, dma->byte_count,
+					  PROT_READ | PROT_WRITE,
+					  MAP_SHARED, 0);
+			up_write(&current->mm->mmap_sem);
 		}
 		}
-		if ( virtual > -1024UL ) {
+		if (virtual > -1024UL) {
 			/* Real error */
 			/* Real error */
 			retcode = (signed long)virtual;
 			retcode = (signed long)virtual;
 			goto done;
 			goto done;
 		}
 		}
 		request.virtual = (void __user *)virtual;
 		request.virtual = (void __user *)virtual;
 
 
-		for ( i = 0 ; i < dma->buf_count ; i++ ) {
-			if ( copy_to_user( &request.list[i].idx,
-					   &dma->buflist[i]->idx,
-					   sizeof(request.list[0].idx) ) ) {
+		for (i = 0; i < dma->buf_count; i++) {
+			if (copy_to_user(&request.list[i].idx,
+					 &dma->buflist[i]->idx,
+					 sizeof(request.list[0].idx))) {
 				retcode = -EFAULT;
 				retcode = -EFAULT;
 				goto done;
 				goto done;
 			}
 			}
-			if ( copy_to_user( &request.list[i].total,
-					   &dma->buflist[i]->total,
-					   sizeof(request.list[0].total) ) ) {
+			if (copy_to_user(&request.list[i].total,
+					 &dma->buflist[i]->total,
+					 sizeof(request.list[0].total))) {
 				retcode = -EFAULT;
 				retcode = -EFAULT;
 				goto done;
 				goto done;
 			}
 			}
-			if ( copy_to_user( &request.list[i].used,
-					   &zero,
-					   sizeof(zero) ) ) {
+			if (copy_to_user(&request.list[i].used,
+					 &zero, sizeof(zero))) {
 				retcode = -EFAULT;
 				retcode = -EFAULT;
 				goto done;
 				goto done;
 			}
 			}
-			address = virtual + dma->buflist[i]->offset; /* *** */
-			if ( copy_to_user( &request.list[i].address,
-					   &address,
-					   sizeof(address) ) ) {
+			address = virtual + dma->buflist[i]->offset;	/* *** */
+			if (copy_to_user(&request.list[i].address,
+					 &address, sizeof(address))) {
 				retcode = -EFAULT;
 				retcode = -EFAULT;
 				goto done;
 				goto done;
 			}
 			}
 		}
 		}
 	}
 	}
- done:
+      done:
 	request.count = dma->buf_count;
 	request.count = dma->buf_count;
-	DRM_DEBUG( "%d buffers, retcode = %d\n", request.count, retcode );
+	DRM_DEBUG("%d buffers, retcode = %d\n", request.count, retcode);
 
 
-	if ( copy_to_user( argp, &request, sizeof(request) ) )
+	if (copy_to_user(argp, &request, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return retcode;
 	return retcode;
@@ -1560,23 +1559,23 @@ int drm_mapbufs( struct inode *inode, struct file *filp,
 /**
 /**
  * Compute size order.  Returns the exponent of the smaller power of two which
  * Compute size order.  Returns the exponent of the smaller power of two which
  * is greater or equal to given number.
  * is greater or equal to given number.
- * 
+ *
  * \param size size.
  * \param size size.
  * \return order.
  * \return order.
  *
  *
  * \todo Can be made faster.
  * \todo Can be made faster.
  */
  */
-int drm_order( unsigned long size )
+int drm_order(unsigned long size)
 {
 {
 	int order;
 	int order;
 	unsigned long tmp;
 	unsigned long tmp;
 
 
-	for (order = 0, tmp = size >> 1; tmp; tmp >>= 1, order++)
-		;
+	for (order = 0, tmp = size >> 1; tmp; tmp >>= 1, order++) ;
 
 
 	if (size & (size - 1))
 	if (size & (size - 1))
 		++order;
 		++order;
 
 
 	return order;
 	return order;
 }
 }
+
 EXPORT_SYMBOL(drm_order);
 EXPORT_SYMBOL(drm_order);

+ 155 - 153
drivers/char/drm/drm_context.c

@@ -1,7 +1,7 @@
 /**
 /**
- * \file drm_context.h 
+ * \file drm_context.c
  * IOCTLs for generic contexts
  * IOCTLs for generic contexts
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
  */
@@ -56,25 +56,26 @@
  * in drm_device::context_sareas, while holding the drm_device::struct_sem
  * in drm_device::context_sareas, while holding the drm_device::struct_sem
  * lock.
  * lock.
  */
  */
-void drm_ctxbitmap_free( drm_device_t *dev, int ctx_handle )
+void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle)
 {
 {
-	if ( ctx_handle < 0 ) goto failed;
-	if ( !dev->ctx_bitmap ) goto failed;
+	if (ctx_handle < 0)
+		goto failed;
+	if (!dev->ctx_bitmap)
+		goto failed;
 
 
-	if ( ctx_handle < DRM_MAX_CTXBITMAP ) {
+	if (ctx_handle < DRM_MAX_CTXBITMAP) {
 		down(&dev->struct_sem);
 		down(&dev->struct_sem);
-		clear_bit( ctx_handle, dev->ctx_bitmap );
+		clear_bit(ctx_handle, dev->ctx_bitmap);
 		dev->context_sareas[ctx_handle] = NULL;
 		dev->context_sareas[ctx_handle] = NULL;
 		up(&dev->struct_sem);
 		up(&dev->struct_sem);
 		return;
 		return;
 	}
 	}
-failed:
-       	DRM_ERROR( "Attempt to free invalid context handle: %d\n",
-		   ctx_handle );
-       	return;
+      failed:
+	DRM_ERROR("Attempt to free invalid context handle: %d\n", ctx_handle);
+	return;
 }
 }
 
 
-/** 
+/**
  * Context bitmap allocation.
  * Context bitmap allocation.
  *
  *
  * \param dev DRM device.
  * \param dev DRM device.
@@ -84,29 +85,33 @@ failed:
  * drm_device::context_sareas to accommodate the new entry while holding the
  * drm_device::context_sareas to accommodate the new entry while holding the
  * drm_device::struct_sem lock.
  * drm_device::struct_sem lock.
  */
  */
-static int drm_ctxbitmap_next( drm_device_t *dev )
+static int drm_ctxbitmap_next(drm_device_t * dev)
 {
 {
 	int bit;
 	int bit;
 
 
-	if(!dev->ctx_bitmap) return -1;
+	if (!dev->ctx_bitmap)
+		return -1;
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
-	bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP );
-	if ( bit < DRM_MAX_CTXBITMAP ) {
-		set_bit( bit, dev->ctx_bitmap );
-	   	DRM_DEBUG( "drm_ctxbitmap_next bit : %d\n", bit );
-		if((bit+1) > dev->max_context) {
-			dev->max_context = (bit+1);
-			if(dev->context_sareas) {
+	bit = find_first_zero_bit(dev->ctx_bitmap, DRM_MAX_CTXBITMAP);
+	if (bit < DRM_MAX_CTXBITMAP) {
+		set_bit(bit, dev->ctx_bitmap);
+		DRM_DEBUG("drm_ctxbitmap_next bit : %d\n", bit);
+		if ((bit + 1) > dev->max_context) {
+			dev->max_context = (bit + 1);
+			if (dev->context_sareas) {
 				drm_map_t **ctx_sareas;
 				drm_map_t **ctx_sareas;
 
 
 				ctx_sareas = drm_realloc(dev->context_sareas,
 				ctx_sareas = drm_realloc(dev->context_sareas,
-						(dev->max_context - 1) * 
-						sizeof(*dev->context_sareas),
-						dev->max_context * 
-						sizeof(*dev->context_sareas),
-						DRM_MEM_MAPS);
-				if(!ctx_sareas) {
+							 (dev->max_context -
+							  1) *
+							 sizeof(*dev->
+								context_sareas),
+							 dev->max_context *
+							 sizeof(*dev->
+								context_sareas),
+							 DRM_MEM_MAPS);
+				if (!ctx_sareas) {
 					clear_bit(bit, dev->ctx_bitmap);
 					clear_bit(bit, dev->ctx_bitmap);
 					up(&dev->struct_sem);
 					up(&dev->struct_sem);
 					return -1;
 					return -1;
@@ -115,11 +120,11 @@ static int drm_ctxbitmap_next( drm_device_t *dev )
 				dev->context_sareas[bit] = NULL;
 				dev->context_sareas[bit] = NULL;
 			} else {
 			} else {
 				/* max_context == 1 at this point */
 				/* max_context == 1 at this point */
-				dev->context_sareas = drm_alloc(
-						dev->max_context * 
-						sizeof(*dev->context_sareas),
-						DRM_MEM_MAPS);
-				if(!dev->context_sareas) {
+				dev->context_sareas =
+				    drm_alloc(dev->max_context *
+					      sizeof(*dev->context_sareas),
+					      DRM_MEM_MAPS);
+				if (!dev->context_sareas) {
 					clear_bit(bit, dev->ctx_bitmap);
 					clear_bit(bit, dev->ctx_bitmap);
 					up(&dev->struct_sem);
 					up(&dev->struct_sem);
 					return -1;
 					return -1;
@@ -142,26 +147,26 @@ static int drm_ctxbitmap_next( drm_device_t *dev )
  * Allocates and initialize drm_device::ctx_bitmap and drm_device::context_sareas, while holding
  * Allocates and initialize drm_device::ctx_bitmap and drm_device::context_sareas, while holding
  * the drm_device::struct_sem lock.
  * the drm_device::struct_sem lock.
  */
  */
-int drm_ctxbitmap_init( drm_device_t *dev )
+int drm_ctxbitmap_init(drm_device_t * dev)
 {
 {
 	int i;
 	int i;
-   	int temp;
+	int temp;
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
-	dev->ctx_bitmap = (unsigned long *) drm_alloc( PAGE_SIZE,
-							DRM_MEM_CTXBITMAP );
-	if ( dev->ctx_bitmap == NULL ) {
+	dev->ctx_bitmap = (unsigned long *)drm_alloc(PAGE_SIZE,
+						     DRM_MEM_CTXBITMAP);
+	if (dev->ctx_bitmap == NULL) {
 		up(&dev->struct_sem);
 		up(&dev->struct_sem);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
-	memset( (void *)dev->ctx_bitmap, 0, PAGE_SIZE );
+	memset((void *)dev->ctx_bitmap, 0, PAGE_SIZE);
 	dev->context_sareas = NULL;
 	dev->context_sareas = NULL;
 	dev->max_context = -1;
 	dev->max_context = -1;
 	up(&dev->struct_sem);
 	up(&dev->struct_sem);
 
 
-	for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
-		temp = drm_ctxbitmap_next( dev );
-	   	DRM_DEBUG( "drm_ctxbitmap_init : %d\n", temp );
+	for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
+		temp = drm_ctxbitmap_next(dev);
+		DRM_DEBUG("drm_ctxbitmap_init : %d\n", temp);
 	}
 	}
 
 
 	return 0;
 	return 0;
@@ -175,14 +180,14 @@ int drm_ctxbitmap_init( drm_device_t *dev )
  * Frees drm_device::ctx_bitmap and drm_device::context_sareas, while holding
  * Frees drm_device::ctx_bitmap and drm_device::context_sareas, while holding
  * the drm_device::struct_sem lock.
  * the drm_device::struct_sem lock.
  */
  */
-void drm_ctxbitmap_cleanup( drm_device_t *dev )
+void drm_ctxbitmap_cleanup(drm_device_t * dev)
 {
 {
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
-	if( dev->context_sareas ) drm_free( dev->context_sareas,
-					     sizeof(*dev->context_sareas) * 
-					     dev->max_context,
-					     DRM_MEM_MAPS );
-	drm_free( (void *)dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP );
+	if (dev->context_sareas)
+		drm_free(dev->context_sareas,
+			 sizeof(*dev->context_sareas) *
+			 dev->max_context, DRM_MEM_MAPS);
+	drm_free((void *)dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP);
 	up(&dev->struct_sem);
 	up(&dev->struct_sem);
 }
 }
 
 
@@ -194,7 +199,7 @@ void drm_ctxbitmap_cleanup( drm_device_t *dev )
 
 
 /**
 /**
  * Get per-context SAREA.
  * Get per-context SAREA.
- * 
+ *
  * \param inode device inode.
  * \param inode device inode.
  * \param filp file pointer.
  * \param filp file pointer.
  * \param cmd command.
  * \param cmd command.
@@ -205,10 +210,10 @@ void drm_ctxbitmap_cleanup( drm_device_t *dev )
  * returns its handle.
  * returns its handle.
  */
  */
 int drm_getsareactx(struct inode *inode, struct file *filp,
 int drm_getsareactx(struct inode *inode, struct file *filp,
-		     unsigned int cmd, unsigned long arg)
+		    unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	*priv	= filp->private_data;
-	drm_device_t	*dev	= priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_ctx_priv_map_t __user *argp = (void __user *)arg;
 	drm_ctx_priv_map_t __user *argp = (void __user *)arg;
 	drm_ctx_priv_map_t request;
 	drm_ctx_priv_map_t request;
 	drm_map_t *map;
 	drm_map_t *map;
@@ -218,7 +223,8 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
-	if (dev->max_context < 0 || request.ctx_id >= (unsigned) dev->max_context) {
+	if (dev->max_context < 0
+	    || request.ctx_id >= (unsigned)dev->max_context) {
 		up(&dev->struct_sem);
 		up(&dev->struct_sem);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
@@ -226,17 +232,17 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
 	map = dev->context_sareas[request.ctx_id];
 	map = dev->context_sareas[request.ctx_id];
 	up(&dev->struct_sem);
 	up(&dev->struct_sem);
 
 
-	request.handle = 0;
-	list_for_each_entry(_entry, &dev->maplist->head,head) {
+	request.handle = NULL;
+	list_for_each_entry(_entry, &dev->maplist->head, head) {
 		if (_entry->map == map) {
 		if (_entry->map == map) {
-			request.handle = (void *)(unsigned long)_entry->user_token;
+			request.handle =
+			    (void *)(unsigned long)_entry->user_token;
 			break;
 			break;
 		}
 		}
 	}
 	}
-	if (request.handle == 0)
+	if (request.handle == NULL)
 		return -EINVAL;
 		return -EINVAL;
 
 
-
 	if (copy_to_user(argp, &request, sizeof(request)))
 	if (copy_to_user(argp, &request, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
@@ -244,7 +250,7 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
 
 
 /**
 /**
  * Set per-context SAREA.
  * Set per-context SAREA.
- * 
+ *
  * \param inode device inode.
  * \param inode device inode.
  * \param filp file pointer.
  * \param filp file pointer.
  * \param cmd command.
  * \param cmd command.
@@ -255,37 +261,37 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
  * drm_device::context_sareas with it.
  * drm_device::context_sareas with it.
  */
  */
 int drm_setsareactx(struct inode *inode, struct file *filp,
 int drm_setsareactx(struct inode *inode, struct file *filp,
-		     unsigned int cmd, unsigned long arg)
+		    unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	*priv	= filp->private_data;
-	drm_device_t	*dev	= priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_ctx_priv_map_t request;
 	drm_ctx_priv_map_t request;
 	drm_map_t *map = NULL;
 	drm_map_t *map = NULL;
 	drm_map_list_t *r_list = NULL;
 	drm_map_list_t *r_list = NULL;
 	struct list_head *list;
 	struct list_head *list;
 
 
 	if (copy_from_user(&request,
 	if (copy_from_user(&request,
-			   (drm_ctx_priv_map_t __user *)arg,
-			   sizeof(request)))
+			   (drm_ctx_priv_map_t __user *) arg, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 	list_for_each(list, &dev->maplist->head) {
 	list_for_each(list, &dev->maplist->head) {
 		r_list = list_entry(list, drm_map_list_t, head);
 		r_list = list_entry(list, drm_map_list_t, head);
 		if (r_list->map
 		if (r_list->map
-		    && r_list->user_token == (unsigned long) request.handle)
+		    && r_list->user_token == (unsigned long)request.handle)
 			goto found;
 			goto found;
 	}
 	}
-bad:
+      bad:
 	up(&dev->struct_sem);
 	up(&dev->struct_sem);
 	return -EINVAL;
 	return -EINVAL;
 
 
-found:
+      found:
 	map = r_list->map;
 	map = r_list->map;
-	if (!map) goto bad;
+	if (!map)
+		goto bad;
 	if (dev->max_context < 0)
 	if (dev->max_context < 0)
 		goto bad;
 		goto bad;
-	if (request.ctx_id >= (unsigned) dev->max_context)
+	if (request.ctx_id >= (unsigned)dev->max_context)
 		goto bad;
 		goto bad;
 	dev->context_sareas[request.ctx_id] = map;
 	dev->context_sareas[request.ctx_id] = map;
 	up(&dev->struct_sem);
 	up(&dev->struct_sem);
@@ -308,22 +314,21 @@ found:
  *
  *
  * Attempt to set drm_device::context_flag.
  * Attempt to set drm_device::context_flag.
  */
  */
-static int drm_context_switch( drm_device_t *dev, int old, int new )
+static int drm_context_switch(drm_device_t * dev, int old, int new)
 {
 {
-        if ( test_and_set_bit( 0, &dev->context_flag ) ) {
-                DRM_ERROR( "Reentering -- FIXME\n" );
-                return -EBUSY;
-        }
-
+	if (test_and_set_bit(0, &dev->context_flag)) {
+		DRM_ERROR("Reentering -- FIXME\n");
+		return -EBUSY;
+	}
 
 
-        DRM_DEBUG( "Context switch from %d to %d\n", old, new );
+	DRM_DEBUG("Context switch from %d to %d\n", old, new);
 
 
-        if ( new == dev->last_context ) {
-                clear_bit( 0, &dev->context_flag );
-                return 0;
-        }
+	if (new == dev->last_context) {
+		clear_bit(0, &dev->context_flag);
+		return 0;
+	}
 
 
-        return 0;
+	return 0;
 }
 }
 
 
 /**
 /**
@@ -337,22 +342,22 @@ static int drm_context_switch( drm_device_t *dev, int old, int new )
  * hardware lock is held, clears the drm_device::context_flag and wakes up
  * hardware lock is held, clears the drm_device::context_flag and wakes up
  * drm_device::context_wait.
  * drm_device::context_wait.
  */
  */
-static int drm_context_switch_complete( drm_device_t *dev, int new )
+static int drm_context_switch_complete(drm_device_t * dev, int new)
 {
 {
-        dev->last_context = new;  /* PRE/POST: This is the _only_ writer. */
-        dev->last_switch  = jiffies;
+	dev->last_context = new;	/* PRE/POST: This is the _only_ writer. */
+	dev->last_switch = jiffies;
 
 
-        if ( !_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ) {
-                DRM_ERROR( "Lock isn't held after context switch\n" );
-        }
+	if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
+		DRM_ERROR("Lock isn't held after context switch\n");
+	}
 
 
-				/* If a context switch is ever initiated
-                                   when the kernel holds the lock, release
-                                   that lock here. */
-        clear_bit( 0, &dev->context_flag );
-        wake_up( &dev->context_wait );
+	/* If a context switch is ever initiated
+	   when the kernel holds the lock, release
+	   that lock here. */
+	clear_bit(0, &dev->context_flag);
+	wake_up(&dev->context_wait);
 
 
-        return 0;
+	return 0;
 }
 }
 
 
 /**
 /**
@@ -364,29 +369,28 @@ static int drm_context_switch_complete( drm_device_t *dev, int new )
  * \param arg user argument pointing to a drm_ctx_res structure.
  * \param arg user argument pointing to a drm_ctx_res structure.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
  */
  */
-int drm_resctx( struct inode *inode, struct file *filp,
-		 unsigned int cmd, unsigned long arg )
+int drm_resctx(struct inode *inode, struct file *filp,
+	       unsigned int cmd, unsigned long arg)
 {
 {
 	drm_ctx_res_t res;
 	drm_ctx_res_t res;
 	drm_ctx_t __user *argp = (void __user *)arg;
 	drm_ctx_t __user *argp = (void __user *)arg;
 	drm_ctx_t ctx;
 	drm_ctx_t ctx;
 	int i;
 	int i;
 
 
-	if ( copy_from_user( &res, argp, sizeof(res) ) )
+	if (copy_from_user(&res, argp, sizeof(res)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	if ( res.count >= DRM_RESERVED_CONTEXTS ) {
-		memset( &ctx, 0, sizeof(ctx) );
-		for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
+	if (res.count >= DRM_RESERVED_CONTEXTS) {
+		memset(&ctx, 0, sizeof(ctx));
+		for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
 			ctx.handle = i;
 			ctx.handle = i;
-			if ( copy_to_user( &res.contexts[i],
-					   &ctx, sizeof(ctx) ) )
+			if (copy_to_user(&res.contexts[i], &ctx, sizeof(ctx)))
 				return -EFAULT;
 				return -EFAULT;
 		}
 		}
 	}
 	}
 	res.count = DRM_RESERVED_CONTEXTS;
 	res.count = DRM_RESERVED_CONTEXTS;
 
 
-	if ( copy_to_user( argp, &res, sizeof(res) ) )
+	if (copy_to_user(argp, &res, sizeof(res)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
@@ -402,58 +406,57 @@ int drm_resctx( struct inode *inode, struct file *filp,
  *
  *
  * Get a new handle for the context and copy to userspace.
  * Get a new handle for the context and copy to userspace.
  */
  */
-int drm_addctx( struct inode *inode, struct file *filp,
-		 unsigned int cmd, unsigned long arg )
+int drm_addctx(struct inode *inode, struct file *filp,
+	       unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
-	drm_ctx_list_t * ctx_entry;
+	drm_ctx_list_t *ctx_entry;
 	drm_ctx_t __user *argp = (void __user *)arg;
 	drm_ctx_t __user *argp = (void __user *)arg;
 	drm_ctx_t ctx;
 	drm_ctx_t ctx;
 
 
-	if ( copy_from_user( &ctx, argp, sizeof(ctx) ) )
+	if (copy_from_user(&ctx, argp, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	ctx.handle = drm_ctxbitmap_next( dev );
-	if ( ctx.handle == DRM_KERNEL_CONTEXT ) {
-				/* Skip kernel's context and get a new one. */
-		ctx.handle = drm_ctxbitmap_next( dev );
+	ctx.handle = drm_ctxbitmap_next(dev);
+	if (ctx.handle == DRM_KERNEL_CONTEXT) {
+		/* Skip kernel's context and get a new one. */
+		ctx.handle = drm_ctxbitmap_next(dev);
 	}
 	}
-	DRM_DEBUG( "%d\n", ctx.handle );
-	if ( ctx.handle == -1 ) {
-		DRM_DEBUG( "Not enough free contexts.\n" );
-				/* Should this return -EBUSY instead? */
+	DRM_DEBUG("%d\n", ctx.handle);
+	if (ctx.handle == -1) {
+		DRM_DEBUG("Not enough free contexts.\n");
+		/* Should this return -EBUSY instead? */
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 
 
-	if ( ctx.handle != DRM_KERNEL_CONTEXT )
-	{
+	if (ctx.handle != DRM_KERNEL_CONTEXT) {
 		if (dev->driver->context_ctor)
 		if (dev->driver->context_ctor)
 			dev->driver->context_ctor(dev, ctx.handle);
 			dev->driver->context_ctor(dev, ctx.handle);
 	}
 	}
 
 
-	ctx_entry = drm_alloc( sizeof(*ctx_entry), DRM_MEM_CTXLIST );
-	if ( !ctx_entry ) {
+	ctx_entry = drm_alloc(sizeof(*ctx_entry), DRM_MEM_CTXLIST);
+	if (!ctx_entry) {
 		DRM_DEBUG("out of memory\n");
 		DRM_DEBUG("out of memory\n");
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 
 
-	INIT_LIST_HEAD( &ctx_entry->head );
+	INIT_LIST_HEAD(&ctx_entry->head);
 	ctx_entry->handle = ctx.handle;
 	ctx_entry->handle = ctx.handle;
 	ctx_entry->tag = priv;
 	ctx_entry->tag = priv;
 
 
-	down( &dev->ctxlist_sem );
-	list_add( &ctx_entry->head, &dev->ctxlist->head );
+	down(&dev->ctxlist_sem);
+	list_add(&ctx_entry->head, &dev->ctxlist->head);
 	++dev->ctx_count;
 	++dev->ctx_count;
-	up( &dev->ctxlist_sem );
+	up(&dev->ctxlist_sem);
 
 
-	if ( copy_to_user( argp, &ctx, sizeof(ctx) ) )
+	if (copy_to_user(argp, &ctx, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
 
 
-int drm_modctx( struct inode *inode, struct file *filp,
-		 unsigned int cmd, unsigned long arg )
+int drm_modctx(struct inode *inode, struct file *filp,
+	       unsigned int cmd, unsigned long arg)
 {
 {
 	/* This does nothing */
 	/* This does nothing */
 	return 0;
 	return 0;
@@ -468,19 +471,19 @@ int drm_modctx( struct inode *inode, struct file *filp,
  * \param arg user argument pointing to a drm_ctx structure.
  * \param arg user argument pointing to a drm_ctx structure.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
  */
  */
-int drm_getctx( struct inode *inode, struct file *filp,
-		 unsigned int cmd, unsigned long arg )
+int drm_getctx(struct inode *inode, struct file *filp,
+	       unsigned int cmd, unsigned long arg)
 {
 {
 	drm_ctx_t __user *argp = (void __user *)arg;
 	drm_ctx_t __user *argp = (void __user *)arg;
 	drm_ctx_t ctx;
 	drm_ctx_t ctx;
 
 
-	if ( copy_from_user( &ctx, argp, sizeof(ctx) ) )
+	if (copy_from_user(&ctx, argp, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	/* This is 0, because we don't handle any context flags */
 	/* This is 0, because we don't handle any context flags */
 	ctx.flags = 0;
 	ctx.flags = 0;
 
 
-	if ( copy_to_user( argp, &ctx, sizeof(ctx) ) )
+	if (copy_to_user(argp, &ctx, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
@@ -496,18 +499,18 @@ int drm_getctx( struct inode *inode, struct file *filp,
  *
  *
  * Calls context_switch().
  * Calls context_switch().
  */
  */
-int drm_switchctx( struct inode *inode, struct file *filp,
-		    unsigned int cmd, unsigned long arg )
+int drm_switchctx(struct inode *inode, struct file *filp,
+		  unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_ctx_t ctx;
 	drm_ctx_t ctx;
 
 
-	if ( copy_from_user( &ctx, (drm_ctx_t __user *)arg, sizeof(ctx) ) )
+	if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	DRM_DEBUG( "%d\n", ctx.handle );
-	return drm_context_switch( dev, dev->last_context, ctx.handle );
+	DRM_DEBUG("%d\n", ctx.handle);
+	return drm_context_switch(dev, dev->last_context, ctx.handle);
 }
 }
 
 
 /**
 /**
@@ -521,18 +524,18 @@ int drm_switchctx( struct inode *inode, struct file *filp,
  *
  *
  * Calls context_switch_complete().
  * Calls context_switch_complete().
  */
  */
-int drm_newctx( struct inode *inode, struct file *filp,
-		 unsigned int cmd, unsigned long arg )
+int drm_newctx(struct inode *inode, struct file *filp,
+	       unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_ctx_t ctx;
 	drm_ctx_t ctx;
 
 
-	if ( copy_from_user( &ctx, (drm_ctx_t __user *)arg, sizeof(ctx) ) )
+	if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	DRM_DEBUG( "%d\n", ctx.handle );
-	drm_context_switch_complete( dev, ctx.handle );
+	DRM_DEBUG("%d\n", ctx.handle);
+	drm_context_switch_complete(dev, ctx.handle);
 
 
 	return 0;
 	return 0;
 }
 }
@@ -548,42 +551,41 @@ int drm_newctx( struct inode *inode, struct file *filp,
  *
  *
  * If not the special kernel context, calls ctxbitmap_free() to free the specified context.
  * If not the special kernel context, calls ctxbitmap_free() to free the specified context.
  */
  */
-int drm_rmctx( struct inode *inode, struct file *filp,
-		unsigned int cmd, unsigned long arg )
+int drm_rmctx(struct inode *inode, struct file *filp,
+	      unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_ctx_t ctx;
 	drm_ctx_t ctx;
 
 
-	if ( copy_from_user( &ctx, (drm_ctx_t __user *)arg, sizeof(ctx) ) )
+	if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	DRM_DEBUG( "%d\n", ctx.handle );
-	if ( ctx.handle == DRM_KERNEL_CONTEXT + 1 ) {
+	DRM_DEBUG("%d\n", ctx.handle);
+	if (ctx.handle == DRM_KERNEL_CONTEXT + 1) {
 		priv->remove_auth_on_close = 1;
 		priv->remove_auth_on_close = 1;
 	}
 	}
-	if ( ctx.handle != DRM_KERNEL_CONTEXT ) {
+	if (ctx.handle != DRM_KERNEL_CONTEXT) {
 		if (dev->driver->context_dtor)
 		if (dev->driver->context_dtor)
 			dev->driver->context_dtor(dev, ctx.handle);
 			dev->driver->context_dtor(dev, ctx.handle);
-		drm_ctxbitmap_free( dev, ctx.handle );
+		drm_ctxbitmap_free(dev, ctx.handle);
 	}
 	}
 
 
-	down( &dev->ctxlist_sem );
-	if ( !list_empty( &dev->ctxlist->head ) ) {
+	down(&dev->ctxlist_sem);
+	if (!list_empty(&dev->ctxlist->head)) {
 		drm_ctx_list_t *pos, *n;
 		drm_ctx_list_t *pos, *n;
 
 
-		list_for_each_entry_safe( pos, n, &dev->ctxlist->head, head ) {
-			if ( pos->handle == ctx.handle ) {
-				list_del( &pos->head );
-				drm_free( pos, sizeof(*pos), DRM_MEM_CTXLIST );
+		list_for_each_entry_safe(pos, n, &dev->ctxlist->head, head) {
+			if (pos->handle == ctx.handle) {
+				list_del(&pos->head);
+				drm_free(pos, sizeof(*pos), DRM_MEM_CTXLIST);
 				--dev->ctx_count;
 				--dev->ctx_count;
 			}
 			}
 		}
 		}
 	}
 	}
-	up( &dev->ctxlist_sem );
+	up(&dev->ctxlist_sem);
 
 
 	return 0;
 	return 0;
 }
 }
 
 
 /*@}*/
 /*@}*/
-

+ 44 - 43
drivers/char/drm/drm_dma.c

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_dma.h 
+ * \file drm_dma.c
  * DMA IOCTL and function support
  * DMA IOCTL and function support
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -37,23 +37,23 @@
 
 
 /**
 /**
  * Initialize the DMA data.
  * Initialize the DMA data.
- * 
+ *
  * \param dev DRM device.
  * \param dev DRM device.
  * \return zero on success or a negative value on failure.
  * \return zero on success or a negative value on failure.
  *
  *
  * Allocate and initialize a drm_device_dma structure.
  * Allocate and initialize a drm_device_dma structure.
  */
  */
-int drm_dma_setup( drm_device_t *dev )
+int drm_dma_setup(drm_device_t * dev)
 {
 {
 	int i;
 	int i;
 
 
-	dev->dma = drm_alloc( sizeof(*dev->dma), DRM_MEM_DRIVER );
-	if ( !dev->dma )
+	dev->dma = drm_alloc(sizeof(*dev->dma), DRM_MEM_DRIVER);
+	if (!dev->dma)
 		return -ENOMEM;
 		return -ENOMEM;
 
 
-	memset( dev->dma, 0, sizeof(*dev->dma) );
+	memset(dev->dma, 0, sizeof(*dev->dma));
 
 
-	for ( i = 0 ; i <= DRM_MAX_ORDER ; i++ )
+	for (i = 0; i <= DRM_MAX_ORDER; i++)
 		memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
 		memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
 
 
 	return 0;
 	return 0;
@@ -67,14 +67,15 @@ int drm_dma_setup( drm_device_t *dev )
  * Free all pages associated with DMA buffers, the buffers and pages lists, and
  * Free all pages associated with DMA buffers, the buffers and pages lists, and
  * finally the the drm_device::dma structure itself.
  * finally the the drm_device::dma structure itself.
  */
  */
-void drm_dma_takedown(drm_device_t *dev)
+void drm_dma_takedown(drm_device_t * dev)
 {
 {
-	drm_device_dma_t  *dma = dev->dma;
-	int		  i, j;
+	drm_device_dma_t *dma = dev->dma;
+	int i, j;
 
 
-	if (!dma) return;
+	if (!dma)
+		return;
 
 
-				/* Clear dma buffers */
+	/* Clear dma buffers */
 	for (i = 0; i <= DRM_MAX_ORDER; i++) {
 	for (i = 0; i <= DRM_MAX_ORDER; i++) {
 		if (dma->bufs[i].seg_count) {
 		if (dma->bufs[i].seg_count) {
 			DRM_DEBUG("order %d: buf_count = %d,"
 			DRM_DEBUG("order %d: buf_count = %d,"
@@ -85,64 +86,63 @@ void drm_dma_takedown(drm_device_t *dev)
 			for (j = 0; j < dma->bufs[i].seg_count; j++) {
 			for (j = 0; j < dma->bufs[i].seg_count; j++) {
 				if (dma->bufs[i].seglist[j]) {
 				if (dma->bufs[i].seglist[j]) {
 					drm_free_pages(dma->bufs[i].seglist[j],
 					drm_free_pages(dma->bufs[i].seglist[j],
-							dma->bufs[i].page_order,
-							DRM_MEM_DMA);
+						       dma->bufs[i].page_order,
+						       DRM_MEM_DMA);
 				}
 				}
 			}
 			}
 			drm_free(dma->bufs[i].seglist,
 			drm_free(dma->bufs[i].seglist,
-				  dma->bufs[i].seg_count
-				  * sizeof(*dma->bufs[0].seglist),
-				  DRM_MEM_SEGS);
+				 dma->bufs[i].seg_count
+				 * sizeof(*dma->bufs[0].seglist), DRM_MEM_SEGS);
 		}
 		}
-	   	if (dma->bufs[i].buf_count) {
-		   	for (j = 0; j < dma->bufs[i].buf_count; j++) {
+		if (dma->bufs[i].buf_count) {
+			for (j = 0; j < dma->bufs[i].buf_count; j++) {
 				if (dma->bufs[i].buflist[j].dev_private) {
 				if (dma->bufs[i].buflist[j].dev_private) {
-					drm_free(dma->bufs[i].buflist[j].dev_private,
-						  dma->bufs[i].buflist[j].dev_priv_size,
-						  DRM_MEM_BUFS);
+					drm_free(dma->bufs[i].buflist[j].
+						 dev_private,
+						 dma->bufs[i].buflist[j].
+						 dev_priv_size, DRM_MEM_BUFS);
 				}
 				}
 			}
 			}
-		   	drm_free(dma->bufs[i].buflist,
-				  dma->bufs[i].buf_count *
-				  sizeof(*dma->bufs[0].buflist),
-				  DRM_MEM_BUFS);
+			drm_free(dma->bufs[i].buflist,
+				 dma->bufs[i].buf_count *
+				 sizeof(*dma->bufs[0].buflist), DRM_MEM_BUFS);
 		}
 		}
 	}
 	}
 
 
 	if (dma->buflist) {
 	if (dma->buflist) {
 		drm_free(dma->buflist,
 		drm_free(dma->buflist,
-			  dma->buf_count * sizeof(*dma->buflist),
-			  DRM_MEM_BUFS);
+			 dma->buf_count * sizeof(*dma->buflist), DRM_MEM_BUFS);
 	}
 	}
 
 
 	if (dma->pagelist) {
 	if (dma->pagelist) {
 		drm_free(dma->pagelist,
 		drm_free(dma->pagelist,
-			  dma->page_count * sizeof(*dma->pagelist),
-			  DRM_MEM_PAGES);
+			 dma->page_count * sizeof(*dma->pagelist),
+			 DRM_MEM_PAGES);
 	}
 	}
 	drm_free(dev->dma, sizeof(*dev->dma), DRM_MEM_DRIVER);
 	drm_free(dev->dma, sizeof(*dev->dma), DRM_MEM_DRIVER);
 	dev->dma = NULL;
 	dev->dma = NULL;
 }
 }
 
 
-
 /**
 /**
  * Free a buffer.
  * Free a buffer.
  *
  *
  * \param dev DRM device.
  * \param dev DRM device.
  * \param buf buffer to free.
  * \param buf buffer to free.
- * 
+ *
  * Resets the fields of \p buf.
  * Resets the fields of \p buf.
  */
  */
-void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf)
+void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf)
 {
 {
-	if (!buf) return;
+	if (!buf)
+		return;
 
 
-	buf->waiting  = 0;
-	buf->pending  = 0;
-	buf->filp     = NULL;
-	buf->used     = 0;
+	buf->waiting = 0;
+	buf->pending = 0;
+	buf->filp = NULL;
+	buf->used = 0;
 
 
-	if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && waitqueue_active(&buf->dma_wait)) {
+	if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE)
+	    && waitqueue_active(&buf->dma_wait)) {
 		wake_up_interruptible(&buf->dma_wait);
 		wake_up_interruptible(&buf->dma_wait);
 	}
 	}
 }
 }
@@ -154,12 +154,13 @@ void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf)
  *
  *
  * Frees each buffer associated with \p filp not already on the hardware.
  * Frees each buffer associated with \p filp not already on the hardware.
  */
  */
-void drm_core_reclaim_buffers(drm_device_t *dev, struct file *filp)
+void drm_core_reclaim_buffers(drm_device_t * dev, struct file *filp)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
-	int		 i;
+	int i;
 
 
-	if (!dma) return;
+	if (!dma)
+		return;
 	for (i = 0; i < dma->buf_count; i++) {
 	for (i = 0; i < dma->buf_count; i++) {
 		if (dma->buflist[i]->filp == filp) {
 		if (dma->buflist[i]->filp == filp) {
 			switch (dma->buflist[i]->list) {
 			switch (dma->buflist[i]->list) {
@@ -176,5 +177,5 @@ void drm_core_reclaim_buffers(drm_device_t *dev, struct file *filp)
 		}
 		}
 	}
 	}
 }
 }
-EXPORT_SYMBOL(drm_core_reclaim_buffers);
 
 
+EXPORT_SYMBOL(drm_core_reclaim_buffers);

+ 4 - 4
drivers/char/drm/drm_drawable.c

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_drawable.h 
+ * \file drm_drawable.c
  * IOCTLs for drawables
  * IOCTLs for drawables
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -37,20 +37,20 @@
 
 
 /** No-op. */
 /** No-op. */
 int drm_adddraw(struct inode *inode, struct file *filp,
 int drm_adddraw(struct inode *inode, struct file *filp,
-		 unsigned int cmd, unsigned long arg)
+		unsigned int cmd, unsigned long arg)
 {
 {
 	drm_draw_t draw;
 	drm_draw_t draw;
 
 
 	draw.handle = 0;	/* NOOP */
 	draw.handle = 0;	/* NOOP */
 	DRM_DEBUG("%d\n", draw.handle);
 	DRM_DEBUG("%d\n", draw.handle);
-	if (copy_to_user((drm_draw_t __user *)arg, &draw, sizeof(draw)))
+	if (copy_to_user((drm_draw_t __user *) arg, &draw, sizeof(draw)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
 
 
 /** No-op. */
 /** No-op. */
 int drm_rmdraw(struct inode *inode, struct file *filp,
 int drm_rmdraw(struct inode *inode, struct file *filp,
-		unsigned int cmd, unsigned long arg)
+	       unsigned int cmd, unsigned long arg)
 {
 {
 	return 0;		/* NOOP */
 	return 0;		/* NOOP */
 }
 }

+ 182 - 179
drivers/char/drm/drm_drv.c

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_drv.h 
+ * \file drm_drv.c
  * Generic driver template
  * Generic driver template
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -55,67 +55,67 @@ static int drm_version(struct inode *inode, struct file *filp,
 		       unsigned int cmd, unsigned long arg);
 		       unsigned int cmd, unsigned long arg);
 
 
 /** Ioctl table */
 /** Ioctl table */
-static drm_ioctl_desc_t		  drm_ioctls[] = {
-	[DRM_IOCTL_NR(DRM_IOCTL_VERSION)]       = { drm_version,     0, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)]    = { drm_getunique,   0, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)]     = { drm_getmagic,    0, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)]     = { drm_irq_by_busid, 0, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_GET_MAP)]       = { drm_getmap,      0, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT)]    = { drm_getclient,   0, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_GET_STATS)]     = { drm_getstats,    0, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_SET_VERSION)]   = { drm_setversion,  0, 1 },
-
-	[DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)]    = { drm_setunique,   1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_BLOCK)]         = { drm_noop,        1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)]       = { drm_noop,        1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)]    = { drm_authmagic,   1, 1 },
-
-	[DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)]       = { drm_addmap_ioctl,1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_RM_MAP)]        = { drm_rmmap_ioctl, 1, 0 },
-
-	[DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX)] = { drm_setsareactx, 1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX)] = { drm_getsareactx, 1, 0 },
-
-	[DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)]       = { drm_addctx,      1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)]        = { drm_rmctx,       1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)]       = { drm_modctx,      1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)]       = { drm_getctx,      1, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)]    = { drm_switchctx,   1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)]       = { drm_newctx,      1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)]       = { drm_resctx,      1, 0 },
-
-	[DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)]      = { drm_adddraw,     1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)]       = { drm_rmdraw,      1, 1 },
-
-	[DRM_IOCTL_NR(DRM_IOCTL_LOCK)]	        = { drm_lock,        1, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)]        = { drm_unlock,      1, 0 },
-
-	[DRM_IOCTL_NR(DRM_IOCTL_FINISH)]        = { drm_noop,      1, 0 },
-
-	[DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)]      = { drm_addbufs,     1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)]     = { drm_markbufs,    1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)]     = { drm_infobufs,    1, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)]      = { drm_mapbufs,     1, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)]     = { drm_freebufs,    1, 0 },
+static drm_ioctl_desc_t drm_ioctls[] = {
+	[DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = {drm_version, 0, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = {drm_getunique, 0, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = {drm_getmagic, 0, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = {drm_irq_by_busid, 0, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_GET_MAP)] = {drm_getmap, 0, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT)] = {drm_getclient, 0, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_GET_STATS)] = {drm_getstats, 0, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_SET_VERSION)] = {drm_setversion, 0, 1},
+
+	[DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = {drm_setunique, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = {drm_noop, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = {drm_noop, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = {drm_authmagic, 1, 1},
+
+	[DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = {drm_addmap_ioctl, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_RM_MAP)] = {drm_rmmap_ioctl, 1, 0},
+
+	[DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX)] = {drm_setsareactx, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX)] = {drm_getsareactx, 1, 0},
+
+	[DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = {drm_addctx, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = {drm_rmctx, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = {drm_modctx, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = {drm_getctx, 1, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = {drm_switchctx, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = {drm_newctx, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = {drm_resctx, 1, 0},
+
+	[DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = {drm_adddraw, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = {drm_rmdraw, 1, 1},
+
+	[DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = {drm_lock, 1, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = {drm_unlock, 1, 0},
+
+	[DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = {drm_noop, 1, 0},
+
+	[DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = {drm_addbufs, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = {drm_markbufs, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = {drm_infobufs, 1, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = {drm_mapbufs, 1, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = {drm_freebufs, 1, 0},
 	/* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
 	/* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
 
 
-	[DRM_IOCTL_NR(DRM_IOCTL_CONTROL)]       = { drm_control,     1, 1 },
+	[DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = {drm_control, 1, 1},
 
 
 #if __OS_HAS_AGP
 #if __OS_HAS_AGP
-	[DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)]   = { drm_agp_acquire_ioctl, 1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)]   = { drm_agp_release_ioctl, 1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)]    = { drm_agp_enable_ioctl, 1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)]      = { drm_agp_info_ioctl, 1, 0 },
-	[DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)]     = { drm_agp_alloc,   1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)]      = { drm_agp_free,    1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)]      = { drm_agp_bind,    1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)]    = { drm_agp_unbind,  1, 1 },
+	[DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = {drm_agp_acquire_ioctl, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = {drm_agp_release_ioctl, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = {drm_agp_enable_ioctl, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = {drm_agp_info_ioctl, 1, 0},
+	[DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = {drm_agp_alloc, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = {drm_agp_free, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = {drm_agp_bind, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = {drm_agp_unbind, 1, 1},
 #endif
 #endif
 
 
-	[DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC)]      = { drm_sg_alloc,    1, 1 },
-	[DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)]       = { drm_sg_free,     1, 1 },
+	[DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC)] = {drm_sg_alloc, 1, 1},
+	[DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)] = {drm_sg_free, 1, 1},
 
 
-	[DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)]   = { drm_wait_vblank, 0, 0 },
+	[DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0, 0},
 };
 };
 
 
 #define DRIVER_IOCTL_COUNT	DRM_ARRAY_SIZE( drm_ioctls )
 #define DRIVER_IOCTL_COUNT	DRM_ARRAY_SIZE( drm_ioctls )
@@ -129,17 +129,17 @@ static drm_ioctl_desc_t		  drm_ioctls[] = {
  *
  *
  * \sa drm_device
  * \sa drm_device
  */
  */
-int drm_takedown( drm_device_t *dev )
+int drm_takedown(drm_device_t * dev)
 {
 {
 	drm_magic_entry_t *pt, *next;
 	drm_magic_entry_t *pt, *next;
 	drm_map_list_t *r_list;
 	drm_map_list_t *r_list;
 	drm_vma_entry_t *vma, *vma_next;
 	drm_vma_entry_t *vma, *vma_next;
 	int i;
 	int i;
 
 
-	DRM_DEBUG( "\n" );
+	DRM_DEBUG("\n");
 
 
 	if (dev->driver->pretakedown)
 	if (dev->driver->pretakedown)
-	  dev->driver->pretakedown(dev);
+		dev->driver->pretakedown(dev);
 	DRM_DEBUG("driver pretakedown completed\n");
 	DRM_DEBUG("driver pretakedown completed\n");
 
 
 	if (dev->unique) {
 	if (dev->unique) {
@@ -148,95 +148,95 @@ int drm_takedown( drm_device_t *dev )
 		dev->unique_len = 0;
 		dev->unique_len = 0;
 	}
 	}
 
 
-	if ( dev->irq_enabled ) drm_irq_uninstall( dev );
+	if (dev->irq_enabled)
+		drm_irq_uninstall(dev);
 
 
-	down( &dev->struct_sem );
-	del_timer( &dev->timer );
+	down(&dev->struct_sem);
+	del_timer(&dev->timer);
 
 
-				/* Clear pid list */
-	for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {
-		for ( pt = dev->magiclist[i].head ; pt ; pt = next ) {
+	/* Clear pid list */
+	for (i = 0; i < DRM_HASH_SIZE; i++) {
+		for (pt = dev->magiclist[i].head; pt; pt = next) {
 			next = pt->next;
 			next = pt->next;
-			drm_free( pt, sizeof(*pt), DRM_MEM_MAGIC );
+			drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
 		}
 		}
 		dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
 		dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
 	}
 	}
 
 
-				/* Clear AGP information */
+	/* Clear AGP information */
 	if (drm_core_has_AGP(dev) && dev->agp) {
 	if (drm_core_has_AGP(dev) && dev->agp) {
 		drm_agp_mem_t *entry;
 		drm_agp_mem_t *entry;
 		drm_agp_mem_t *nexte;
 		drm_agp_mem_t *nexte;
 
 
-				/* Remove AGP resources, but leave dev->agp
-                                   intact until drv_cleanup is called. */
-		for ( entry = dev->agp->memory ; entry ; entry = nexte ) {
+		/* Remove AGP resources, but leave dev->agp
+		   intact until drv_cleanup is called. */
+		for (entry = dev->agp->memory; entry; entry = nexte) {
 			nexte = entry->next;
 			nexte = entry->next;
-			if ( entry->bound ) drm_unbind_agp( entry->memory );
-			drm_free_agp( entry->memory, entry->pages );
-			drm_free( entry, sizeof(*entry), DRM_MEM_AGPLISTS );
+			if (entry->bound)
+				drm_unbind_agp(entry->memory);
+			drm_free_agp(entry->memory, entry->pages);
+			drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
 		}
 		}
 		dev->agp->memory = NULL;
 		dev->agp->memory = NULL;
 
 
 		if (dev->agp->acquired)
 		if (dev->agp->acquired)
-		  drm_agp_release(dev);
+			drm_agp_release(dev);
 
 
 		dev->agp->acquired = 0;
 		dev->agp->acquired = 0;
-		dev->agp->enabled  = 0;
+		dev->agp->enabled = 0;
 	}
 	}
 	if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) {
 	if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) {
 		drm_sg_cleanup(dev->sg);
 		drm_sg_cleanup(dev->sg);
 		dev->sg = NULL;
 		dev->sg = NULL;
 	}
 	}
 
 
-				/* Clear vma list (only built for debugging) */
-	if ( dev->vmalist ) {
-		for ( vma = dev->vmalist ; vma ; vma = vma_next ) {
+	/* Clear vma list (only built for debugging) */
+	if (dev->vmalist) {
+		for (vma = dev->vmalist; vma; vma = vma_next) {
 			vma_next = vma->next;
 			vma_next = vma->next;
-			drm_free( vma, sizeof(*vma), DRM_MEM_VMAS );
+			drm_free(vma, sizeof(*vma), DRM_MEM_VMAS);
 		}
 		}
 		dev->vmalist = NULL;
 		dev->vmalist = NULL;
 	}
 	}
 
 
-	if( dev->maplist ) {
+	if (dev->maplist) {
 		while (!list_empty(&dev->maplist->head)) {
 		while (!list_empty(&dev->maplist->head)) {
 			struct list_head *list = dev->maplist->head.next;
 			struct list_head *list = dev->maplist->head.next;
 			r_list = list_entry(list, drm_map_list_t, head);
 			r_list = list_entry(list, drm_map_list_t, head);
 			drm_rmmap_locked(dev, r_list->map);
 			drm_rmmap_locked(dev, r_list->map);
 		}
 		}
- 	}
-
-	if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist ) {
-		for ( i = 0 ; i < dev->queue_count ; i++ ) {
-			if ( dev->queuelist[i] ) {
-				drm_free( dev->queuelist[i],
-					  sizeof(*dev->queuelist[0]),
-					  DRM_MEM_QUEUES );
+	}
+
+	if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist) {
+		for (i = 0; i < dev->queue_count; i++) {
+			if (dev->queuelist[i]) {
+				drm_free(dev->queuelist[i],
+					 sizeof(*dev->queuelist[0]),
+					 DRM_MEM_QUEUES);
 				dev->queuelist[i] = NULL;
 				dev->queuelist[i] = NULL;
 			}
 			}
 		}
 		}
-		drm_free( dev->queuelist,
-			  dev->queue_slots * sizeof(*dev->queuelist),
-			  DRM_MEM_QUEUES );
+		drm_free(dev->queuelist,
+			 dev->queue_slots * sizeof(*dev->queuelist),
+			 DRM_MEM_QUEUES);
 		dev->queuelist = NULL;
 		dev->queuelist = NULL;
 	}
 	}
 	dev->queue_count = 0;
 	dev->queue_count = 0;
 
 
 	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
 	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
-		drm_dma_takedown( dev );
+		drm_dma_takedown(dev);
 
 
-	if ( dev->lock.hw_lock ) {
-		dev->sigdata.lock = dev->lock.hw_lock = NULL; /* SHM removed */
+	if (dev->lock.hw_lock) {
+		dev->sigdata.lock = dev->lock.hw_lock = NULL;	/* SHM removed */
 		dev->lock.filp = NULL;
 		dev->lock.filp = NULL;
-		wake_up_interruptible( &dev->lock.lock_queue );
+		wake_up_interruptible(&dev->lock.lock_queue);
 	}
 	}
-	up( &dev->struct_sem );
+	up(&dev->struct_sem);
 
 
 	DRM_DEBUG("takedown completed\n");
 	DRM_DEBUG("takedown completed\n");
 	return 0;
 	return 0;
 }
 }
 
 
-
-
 /**
 /**
  * Module initialization. Called via init_module at module load time, or via
  * Module initialization. Called via init_module at module load time, or via
  * linux/init/main.c (this is not currently supported).
  * linux/init/main.c (this is not currently supported).
@@ -246,26 +246,28 @@ int drm_takedown( drm_device_t *dev )
  * Initializes an array of drm_device structures, and attempts to
  * Initializes an array of drm_device structures, and attempts to
  * initialize all available devices, using consecutive minors, registering the
  * initialize all available devices, using consecutive minors, registering the
  * stubs and initializing the AGP device.
  * stubs and initializing the AGP device.
- * 
+ *
  * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
  * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
  * after the initialization for driver customization.
  * after the initialization for driver customization.
  */
  */
-int drm_init( struct drm_driver *driver )
+int drm_init(struct drm_driver *driver)
 {
 {
 	struct pci_dev *pdev = NULL;
 	struct pci_dev *pdev = NULL;
 	struct pci_device_id *pid;
 	struct pci_device_id *pid;
 	int i;
 	int i;
 
 
-	DRM_DEBUG( "\n" );
+	DRM_DEBUG("\n");
 
 
 	drm_mem_init();
 	drm_mem_init();
 
 
-	for (i=0; driver->pci_driver.id_table[i].vendor != 0; i++) {
+	for (i = 0; driver->pci_driver.id_table[i].vendor != 0; i++) {
 		pid = (struct pci_device_id *)&driver->pci_driver.id_table[i];
 		pid = (struct pci_device_id *)&driver->pci_driver.id_table[i];
-		
-		pdev=NULL;
-		/* pass back in pdev to account for multiple identical cards */		
-		while ((pdev = pci_get_subsys(pid->vendor, pid->device, pid->subvendor, pid->subdevice, pdev)) != NULL) {
+
+		pdev = NULL;
+		/* pass back in pdev to account for multiple identical cards */
+		while ((pdev =
+			pci_get_subsys(pid->vendor, pid->device, pid->subvendor,
+				       pid->subdevice, pdev)) != NULL) {
 			/* stealth mode requires a manual probe */
 			/* stealth mode requires a manual probe */
 			pci_dev_get(pdev);
 			pci_dev_get(pdev);
 			drm_get_dev(pdev, pid, driver);
 			drm_get_dev(pdev, pid, driver);
@@ -273,62 +275,63 @@ int drm_init( struct drm_driver *driver )
 	}
 	}
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_init);
 EXPORT_SYMBOL(drm_init);
 
 
 /**
 /**
  * Called via cleanup_module() at module unload time.
  * Called via cleanup_module() at module unload time.
  *
  *
  * Cleans up all DRM device, calling takedown().
  * Cleans up all DRM device, calling takedown().
- * 
+ *
  * \sa drm_init
  * \sa drm_init
  */
  */
-static void drm_cleanup( drm_device_t *dev )
+static void drm_cleanup(drm_device_t * dev)
 {
 {
-	DRM_DEBUG( "\n" );
+	DRM_DEBUG("\n");
 
 
 	if (!dev) {
 	if (!dev) {
 		DRM_ERROR("cleanup called no dev\n");
 		DRM_ERROR("cleanup called no dev\n");
 		return;
 		return;
 	}
 	}
 
 
-	drm_takedown( dev );	
+	drm_takedown(dev);
 
 
 	if (dev->maplist) {
 	if (dev->maplist) {
 		drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS);
 		drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS);
 		dev->maplist = NULL;
 		dev->maplist = NULL;
 	}
 	}
 
 
-	drm_ctxbitmap_cleanup( dev );
-	
+	drm_ctxbitmap_cleanup(dev);
+
 	if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) &&
 	if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) &&
 	    dev->agp && dev->agp->agp_mtrr >= 0) {
 	    dev->agp && dev->agp->agp_mtrr >= 0) {
 		int retval;
 		int retval;
-		retval = mtrr_del( dev->agp->agp_mtrr,
-				   dev->agp->agp_info.aper_base,
-				   dev->agp->agp_info.aper_size*1024*1024 );
-		DRM_DEBUG( "mtrr_del=%d\n", retval );
+		retval = mtrr_del(dev->agp->agp_mtrr,
+				  dev->agp->agp_info.aper_base,
+				  dev->agp->agp_info.aper_size * 1024 * 1024);
+		DRM_DEBUG("mtrr_del=%d\n", retval);
 	}
 	}
-	
-	if (drm_core_has_AGP(dev) && dev->agp ) {
-		drm_free( dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS );
+
+	if (drm_core_has_AGP(dev) && dev->agp) {
+		drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS);
 		dev->agp = NULL;
 		dev->agp = NULL;
 	}
 	}
 
 
 	if (dev->driver->postcleanup)
 	if (dev->driver->postcleanup)
 		dev->driver->postcleanup(dev);
 		dev->driver->postcleanup(dev);
-	
+
 	drm_put_head(&dev->primary);
 	drm_put_head(&dev->primary);
-	if ( drm_put_dev(dev) )
-		DRM_ERROR( "Cannot unload module\n" );
+	if (drm_put_dev(dev))
+		DRM_ERROR("Cannot unload module\n");
 }
 }
 
 
-void drm_exit (struct drm_driver *driver)
+void drm_exit(struct drm_driver *driver)
 {
 {
 	int i;
 	int i;
 	drm_device_t *dev = NULL;
 	drm_device_t *dev = NULL;
 	drm_head_t *head;
 	drm_head_t *head;
-	
-	DRM_DEBUG( "\n" );
+
+	DRM_DEBUG("\n");
 
 
 	for (i = 0; i < drm_cards_limit; i++) {
 	for (i = 0; i < drm_cards_limit; i++) {
 		head = drm_heads[i];
 		head = drm_heads[i];
@@ -336,9 +339,9 @@ void drm_exit (struct drm_driver *driver)
 			continue;
 			continue;
 		if (!head->dev)
 		if (!head->dev)
 			continue;
 			continue;
-		if (head->dev->driver!=driver)
+		if (head->dev->driver != driver)
 			continue;
 			continue;
-		dev=head->dev;
+		dev = head->dev;
 	}
 	}
 	if (dev) {
 	if (dev) {
 		/* release the pci driver */
 		/* release the pci driver */
@@ -346,32 +349,35 @@ void drm_exit (struct drm_driver *driver)
 			pci_dev_put(dev->pdev);
 			pci_dev_put(dev->pdev);
 		drm_cleanup(dev);
 		drm_cleanup(dev);
 	}
 	}
-	DRM_INFO( "Module unloaded\n" );
+	DRM_INFO("Module unloaded\n");
 }
 }
+
 EXPORT_SYMBOL(drm_exit);
 EXPORT_SYMBOL(drm_exit);
 
 
 /** File operations structure */
 /** File operations structure */
 static struct file_operations drm_stub_fops = {
 static struct file_operations drm_stub_fops = {
 	.owner = THIS_MODULE,
 	.owner = THIS_MODULE,
-	.open  = drm_stub_open
+	.open = drm_stub_open
 };
 };
 
 
 static int __init drm_core_init(void)
 static int __init drm_core_init(void)
 {
 {
 	int ret = -ENOMEM;
 	int ret = -ENOMEM;
-	
-	drm_cards_limit = (drm_cards_limit < DRM_MAX_MINOR + 1 ? drm_cards_limit : DRM_MAX_MINOR + 1);
-	drm_heads = drm_calloc(drm_cards_limit,
-				sizeof(*drm_heads), DRM_MEM_STUB);
-	if(!drm_heads) 
+
+	drm_cards_limit =
+	    (drm_cards_limit <
+	     DRM_MAX_MINOR + 1 ? drm_cards_limit : DRM_MAX_MINOR + 1);
+	drm_heads =
+	    drm_calloc(drm_cards_limit, sizeof(*drm_heads), DRM_MEM_STUB);
+	if (!drm_heads)
 		goto err_p1;
 		goto err_p1;
-	
+
 	if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
 	if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
 		goto err_p1;
 		goto err_p1;
-	
+
 	drm_class = drm_sysfs_create(THIS_MODULE, "drm");
 	drm_class = drm_sysfs_create(THIS_MODULE, "drm");
 	if (IS_ERR(drm_class)) {
 	if (IS_ERR(drm_class)) {
-		printk (KERN_ERR "DRM: Error creating drm class.\n");
+		printk(KERN_ERR "DRM: Error creating drm class.\n");
 		ret = PTR_ERR(drm_class);
 		ret = PTR_ERR(drm_class);
 		goto err_p2;
 		goto err_p2;
 	}
 	}
@@ -382,35 +388,31 @@ static int __init drm_core_init(void)
 		ret = -1;
 		ret = -1;
 		goto err_p3;
 		goto err_p3;
 	}
 	}
-		
-	DRM_INFO( "Initialized %s %d.%d.%d %s\n",
-		CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL,
-		CORE_DATE);
+
+	DRM_INFO("Initialized %s %d.%d.%d %s\n",
+		 CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
 	return 0;
 	return 0;
-err_p3:
+      err_p3:
 	drm_sysfs_destroy(drm_class);
 	drm_sysfs_destroy(drm_class);
-err_p2:
+      err_p2:
 	unregister_chrdev(DRM_MAJOR, "drm");
 	unregister_chrdev(DRM_MAJOR, "drm");
 	drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
 	drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
-err_p1:	
+      err_p1:
 	return ret;
 	return ret;
 }
 }
 
 
-static void __exit drm_core_exit (void)
+static void __exit drm_core_exit(void)
 {
 {
 	remove_proc_entry("dri", NULL);
 	remove_proc_entry("dri", NULL);
 	drm_sysfs_destroy(drm_class);
 	drm_sysfs_destroy(drm_class);
 
 
 	unregister_chrdev(DRM_MAJOR, "drm");
 	unregister_chrdev(DRM_MAJOR, "drm");
 
 
-	drm_free(drm_heads, sizeof(*drm_heads) *
-				drm_cards_limit, DRM_MEM_STUB);
+	drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
 }
 }
 
 
-
-module_init( drm_core_init );
-module_exit( drm_core_exit );
-
+module_init(drm_core_init);
+module_exit(drm_core_exit);
 
 
 /**
 /**
  * Get version information
  * Get version information
@@ -423,8 +425,8 @@ module_exit( drm_core_exit );
  *
  *
  * Fills in the version information in \p arg.
  * Fills in the version information in \p arg.
  */
  */
-static int drm_version( struct inode *inode, struct file *filp,
-			unsigned int cmd, unsigned long arg )
+static int drm_version(struct inode *inode, struct file *filp,
+		       unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -432,21 +434,19 @@ static int drm_version( struct inode *inode, struct file *filp,
 	drm_version_t version;
 	drm_version_t version;
 	int ret;
 	int ret;
 
 
-	if ( copy_from_user( &version, argp, sizeof(version) ) )
+	if (copy_from_user(&version, argp, sizeof(version)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	/* version is a required function to return the personality module version */
 	/* version is a required function to return the personality module version */
 	if ((ret = dev->driver->version(&version)))
 	if ((ret = dev->driver->version(&version)))
 		return ret;
 		return ret;
-		
-	if ( copy_to_user( argp, &version, sizeof(version) ) )
+
+	if (copy_to_user(argp, &version, sizeof(version)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
 
 
-
-
-/** 
+/**
  * Called whenever a process performs an ioctl on /dev/drm.
  * Called whenever a process performs an ioctl on /dev/drm.
  *
  *
  * \param inode device inode.
  * \param inode device inode.
@@ -458,8 +458,8 @@ static int drm_version( struct inode *inode, struct file *filp,
  * Looks up the ioctl function in the ::ioctls table, checking for root
  * Looks up the ioctl function in the ::ioctls table, checking for root
  * previleges if so required, and dispatches to the respective function.
  * previleges if so required, and dispatches to the respective function.
  */
  */
-int drm_ioctl( struct inode *inode, struct file *filp,
-		unsigned int cmd, unsigned long arg )
+int drm_ioctl(struct inode *inode, struct file *filp,
+	      unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -468,40 +468,43 @@ int drm_ioctl( struct inode *inode, struct file *filp,
 	unsigned int nr = DRM_IOCTL_NR(cmd);
 	unsigned int nr = DRM_IOCTL_NR(cmd);
 	int retcode = -EINVAL;
 	int retcode = -EINVAL;
 
 
-	atomic_inc( &dev->ioctl_count );
-	atomic_inc( &dev->counts[_DRM_STAT_IOCTLS] );
+	atomic_inc(&dev->ioctl_count);
+	atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
 	++priv->ioctl_count;
 	++priv->ioctl_count;
 
 
-	DRM_DEBUG( "pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
-		   current->pid, cmd, nr, (long)old_encode_dev(priv->head->device), 
-		   priv->authenticated );
-	
+	DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
+		  current->pid, cmd, nr,
+		  (long)old_encode_dev(priv->head->device),
+		  priv->authenticated);
+
 	if (nr < DRIVER_IOCTL_COUNT)
 	if (nr < DRIVER_IOCTL_COUNT)
 		ioctl = &drm_ioctls[nr];
 		ioctl = &drm_ioctls[nr];
-	else if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls))
+	else if ((nr >= DRM_COMMAND_BASE)
+		 && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls))
 		ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE];
 		ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE];
 	else
 	else
 		goto err_i1;
 		goto err_i1;
-	
+
 	func = ioctl->func;
 	func = ioctl->func;
 	/* is there a local override? */
 	/* is there a local override? */
 	if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl)
 	if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl)
 		func = dev->driver->dma_ioctl;
 		func = dev->driver->dma_ioctl;
-	
-	if ( !func ) {
-		DRM_DEBUG( "no function\n" );
+
+	if (!func) {
+		DRM_DEBUG("no function\n");
 		retcode = -EINVAL;
 		retcode = -EINVAL;
-	} else if ( ( ioctl->root_only && !capable( CAP_SYS_ADMIN ) )||
-		    ( ioctl->auth_needed && !priv->authenticated ) ) {
+	} else if ((ioctl->root_only && !capable(CAP_SYS_ADMIN)) ||
+		   (ioctl->auth_needed && !priv->authenticated)) {
 		retcode = -EACCES;
 		retcode = -EACCES;
 	} else {
 	} else {
-		retcode = func( inode, filp, cmd, arg );
+		retcode = func(inode, filp, cmd, arg);
 	}
 	}
-	
-err_i1:
-	atomic_dec( &dev->ioctl_count );
-	if (retcode) DRM_DEBUG( "ret = %x\n", retcode);
+
+      err_i1:
+	atomic_dec(&dev->ioctl_count);
+	if (retcode)
+		DRM_DEBUG("ret = %x\n", retcode);
 	return retcode;
 	return retcode;
 }
 }
-EXPORT_SYMBOL(drm_ioctl);
 
 
+EXPORT_SYMBOL(drm_ioctl);

+ 152 - 144
drivers/char/drm/drm_fops.c

@@ -1,7 +1,7 @@
 /**
 /**
- * \file drm_fops.h 
+ * \file drm_fops.c
  * File operations for DRM
  * File operations for DRM
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Daryll Strauss <daryll@valinux.com>
  * \author Daryll Strauss <daryll@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
@@ -37,49 +37,48 @@
 #include "drmP.h"
 #include "drmP.h"
 #include <linux/poll.h>
 #include <linux/poll.h>
 
 
-static int drm_open_helper(struct inode *inode, struct file *filp, drm_device_t *dev);
+static int drm_open_helper(struct inode *inode, struct file *filp,
+			   drm_device_t * dev);
 
 
-static int drm_setup( drm_device_t *dev )
+static int drm_setup(drm_device_t * dev)
 {
 {
 	int i;
 	int i;
 	int ret;
 	int ret;
 
 
-	if (dev->driver->presetup)
-	{
-		ret=dev->driver->presetup(dev);
-		if (ret!=0) 
+	if (dev->driver->presetup) {
+		ret = dev->driver->presetup(dev);
+		if (ret != 0)
 			return ret;
 			return ret;
 	}
 	}
 
 
-	atomic_set( &dev->ioctl_count, 0 );
-	atomic_set( &dev->vma_count, 0 );
+	atomic_set(&dev->ioctl_count, 0);
+	atomic_set(&dev->vma_count, 0);
 	dev->buf_use = 0;
 	dev->buf_use = 0;
-	atomic_set( &dev->buf_alloc, 0 );
+	atomic_set(&dev->buf_alloc, 0);
 
 
-	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
-	{
-		i = drm_dma_setup( dev );
-		if ( i < 0 )
+	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) {
+		i = drm_dma_setup(dev);
+		if (i < 0)
 			return i;
 			return i;
 	}
 	}
 
 
-	for ( i = 0 ; i < DRM_ARRAY_SIZE(dev->counts) ; i++ )
-		atomic_set( &dev->counts[i], 0 );
+	for (i = 0; i < DRM_ARRAY_SIZE(dev->counts); i++)
+		atomic_set(&dev->counts[i], 0);
 
 
-	for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {
+	for (i = 0; i < DRM_HASH_SIZE; i++) {
 		dev->magiclist[i].head = NULL;
 		dev->magiclist[i].head = NULL;
 		dev->magiclist[i].tail = NULL;
 		dev->magiclist[i].tail = NULL;
 	}
 	}
 
 
-	dev->ctxlist = drm_alloc(sizeof(*dev->ctxlist),
-				  DRM_MEM_CTXLIST);
-	if(dev->ctxlist == NULL) return -ENOMEM;
+	dev->ctxlist = drm_alloc(sizeof(*dev->ctxlist), DRM_MEM_CTXLIST);
+	if (dev->ctxlist == NULL)
+		return -ENOMEM;
 	memset(dev->ctxlist, 0, sizeof(*dev->ctxlist));
 	memset(dev->ctxlist, 0, sizeof(*dev->ctxlist));
 	INIT_LIST_HEAD(&dev->ctxlist->head);
 	INIT_LIST_HEAD(&dev->ctxlist->head);
 
 
 	dev->vmalist = NULL;
 	dev->vmalist = NULL;
 	dev->sigdata.lock = dev->lock.hw_lock = NULL;
 	dev->sigdata.lock = dev->lock.hw_lock = NULL;
-	init_waitqueue_head( &dev->lock.lock_queue );
+	init_waitqueue_head(&dev->lock.lock_queue);
 	dev->queue_count = 0;
 	dev->queue_count = 0;
 	dev->queue_reserved = 0;
 	dev->queue_reserved = 0;
 	dev->queue_slots = 0;
 	dev->queue_slots = 0;
@@ -91,24 +90,21 @@ static int drm_setup( drm_device_t *dev )
 	dev->last_context = 0;
 	dev->last_context = 0;
 	dev->last_switch = 0;
 	dev->last_switch = 0;
 	dev->last_checked = 0;
 	dev->last_checked = 0;
-	init_waitqueue_head( &dev->context_wait );
+	init_waitqueue_head(&dev->context_wait);
 	dev->if_version = 0;
 	dev->if_version = 0;
 
 
 	dev->ctx_start = 0;
 	dev->ctx_start = 0;
 	dev->lck_start = 0;
 	dev->lck_start = 0;
 
 
-	dev->buf_rp = dev->buf;
-	dev->buf_wp = dev->buf;
-	dev->buf_end = dev->buf + DRM_BSZ;
 	dev->buf_async = NULL;
 	dev->buf_async = NULL;
-	init_waitqueue_head( &dev->buf_readers );
-	init_waitqueue_head( &dev->buf_writers );
+	init_waitqueue_head(&dev->buf_readers);
+	init_waitqueue_head(&dev->buf_writers);
 
 
-	DRM_DEBUG( "\n" );
+	DRM_DEBUG("\n");
 
 
 	/*
 	/*
 	 * The kernel's context could be created here, but is now created
 	 * The kernel's context could be created here, but is now created
-	 * in drm_dma_enqueue.	This is more resource-efficient for
+	 * in drm_dma_enqueue.  This is more resource-efficient for
 	 * hardware that does not do DMA, but may mean that
 	 * hardware that does not do DMA, but may mean that
 	 * drm_select_queue fails between the time the interrupt is
 	 * drm_select_queue fails between the time the interrupt is
 	 * initialized and the time the queues are initialized.
 	 * initialized and the time the queues are initialized.
@@ -121,7 +117,7 @@ static int drm_setup( drm_device_t *dev )
 
 
 /**
 /**
  * Open file.
  * Open file.
- * 
+ *
  * \param inode device inode
  * \param inode device inode
  * \param filp file pointer.
  * \param filp file pointer.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
@@ -130,7 +126,7 @@ static int drm_setup( drm_device_t *dev )
  * increments the device open count. If the open count was previous at zero,
  * increments the device open count. If the open count was previous at zero,
  * i.e., it's the first that the device is open, then calls setup().
  * i.e., it's the first that the device is open, then calls setup().
  */
  */
-int drm_open( struct inode *inode, struct file *filp )
+int drm_open(struct inode *inode, struct file *filp)
 {
 {
 	drm_device_t *dev = NULL;
 	drm_device_t *dev = NULL;
 	int minor = iminor(inode);
 	int minor = iminor(inode);
@@ -138,26 +134,27 @@ int drm_open( struct inode *inode, struct file *filp )
 
 
 	if (!((minor >= 0) && (minor < drm_cards_limit)))
 	if (!((minor >= 0) && (minor < drm_cards_limit)))
 		return -ENODEV;
 		return -ENODEV;
-		
+
 	if (!drm_heads[minor])
 	if (!drm_heads[minor])
 		return -ENODEV;
 		return -ENODEV;
 
 
 	if (!(dev = drm_heads[minor]->dev))
 	if (!(dev = drm_heads[minor]->dev))
 		return -ENODEV;
 		return -ENODEV;
-	
-	retcode = drm_open_helper( inode, filp, dev );
-	if ( !retcode ) {
-		atomic_inc( &dev->counts[_DRM_STAT_OPENS] );
-		spin_lock( &dev->count_lock );
-		if ( !dev->open_count++ ) {
-			spin_unlock( &dev->count_lock );
-			return drm_setup( dev );
+
+	retcode = drm_open_helper(inode, filp, dev);
+	if (!retcode) {
+		atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
+		spin_lock(&dev->count_lock);
+		if (!dev->open_count++) {
+			spin_unlock(&dev->count_lock);
+			return drm_setup(dev);
 		}
 		}
-		spin_unlock( &dev->count_lock );
+		spin_unlock(&dev->count_lock);
 	}
 	}
 
 
 	return retcode;
 	return retcode;
 }
 }
+
 EXPORT_SYMBOL(drm_open);
 EXPORT_SYMBOL(drm_open);
 
 
 /**
 /**
@@ -172,7 +169,7 @@ EXPORT_SYMBOL(drm_open);
  * data from its list and free it. Decreases the open count and if it reaches
  * data from its list and free it. Decreases the open count and if it reaches
  * zero calls takedown().
  * zero calls takedown().
  */
  */
-int drm_release( struct inode *inode, struct file *filp )
+int drm_release(struct inode *inode, struct file *filp)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev;
 	drm_device_t *dev;
@@ -181,7 +178,7 @@ int drm_release( struct inode *inode, struct file *filp )
 	lock_kernel();
 	lock_kernel();
 	dev = priv->head->dev;
 	dev = priv->head->dev;
 
 
-	DRM_DEBUG( "open_count = %d\n", dev->open_count );
+	DRM_DEBUG("open_count = %d\n", dev->open_count);
 
 
 	if (dev->driver->prerelease)
 	if (dev->driver->prerelease)
 		dev->driver->prerelease(dev, filp);
 		dev->driver->prerelease(dev, filp);
@@ -190,194 +187,199 @@ int drm_release( struct inode *inode, struct file *filp )
 	 * Begin inline drm_release
 	 * Begin inline drm_release
 	 */
 	 */
 
 
-	DRM_DEBUG( "pid = %d, device = 0x%lx, open_count = %d\n",
-		   current->pid, (long)old_encode_dev(priv->head->device), dev->open_count );
+	DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
+		  current->pid, (long)old_encode_dev(priv->head->device),
+		  dev->open_count);
+
+	if (priv->lock_count && dev->lock.hw_lock &&
+	    _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) &&
+	    dev->lock.filp == filp) {
+		DRM_DEBUG("File %p released, freeing lock for context %d\n",
+			  filp, _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
 
 
-	if ( priv->lock_count && dev->lock.hw_lock &&
-	     _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) &&
-	     dev->lock.filp == filp ) {
-		DRM_DEBUG( "File %p released, freeing lock for context %d\n",
-			filp,
-			_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) );
-		
 		if (dev->driver->release)
 		if (dev->driver->release)
 			dev->driver->release(dev, filp);
 			dev->driver->release(dev, filp);
 
 
-		drm_lock_free( dev, &dev->lock.hw_lock->lock,
-				_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) );
+		drm_lock_free(dev, &dev->lock.hw_lock->lock,
+			      _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
 
 
-				/* FIXME: may require heavy-handed reset of
-                                   hardware at this point, possibly
-                                   processed via a callback to the X
-                                   server. */
-	}
-	else if ( dev->driver->release && priv->lock_count && dev->lock.hw_lock ) {
+		/* FIXME: may require heavy-handed reset of
+		   hardware at this point, possibly
+		   processed via a callback to the X
+		   server. */
+	} else if (dev->driver->release && priv->lock_count
+		   && dev->lock.hw_lock) {
 		/* The lock is required to reclaim buffers */
 		/* The lock is required to reclaim buffers */
-		DECLARE_WAITQUEUE( entry, current );
+		DECLARE_WAITQUEUE(entry, current);
 
 
-		add_wait_queue( &dev->lock.lock_queue, &entry );
+		add_wait_queue(&dev->lock.lock_queue, &entry);
 		for (;;) {
 		for (;;) {
 			__set_current_state(TASK_INTERRUPTIBLE);
 			__set_current_state(TASK_INTERRUPTIBLE);
-			if ( !dev->lock.hw_lock ) {
+			if (!dev->lock.hw_lock) {
 				/* Device has been unregistered */
 				/* Device has been unregistered */
 				retcode = -EINTR;
 				retcode = -EINTR;
 				break;
 				break;
 			}
 			}
-			if ( drm_lock_take( &dev->lock.hw_lock->lock,
-					     DRM_KERNEL_CONTEXT ) ) {
-				dev->lock.filp	    = filp;
+			if (drm_lock_take(&dev->lock.hw_lock->lock,
+					  DRM_KERNEL_CONTEXT)) {
+				dev->lock.filp = filp;
 				dev->lock.lock_time = jiffies;
 				dev->lock.lock_time = jiffies;
-                                atomic_inc( &dev->counts[_DRM_STAT_LOCKS] );
+				atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
 				break;	/* Got lock */
 				break;	/* Got lock */
 			}
 			}
-				/* Contention */
+			/* Contention */
 			schedule();
 			schedule();
-			if ( signal_pending( current ) ) {
+			if (signal_pending(current)) {
 				retcode = -ERESTARTSYS;
 				retcode = -ERESTARTSYS;
 				break;
 				break;
 			}
 			}
 		}
 		}
 		__set_current_state(TASK_RUNNING);
 		__set_current_state(TASK_RUNNING);
-		remove_wait_queue( &dev->lock.lock_queue, &entry );
-		if( !retcode ) {
+		remove_wait_queue(&dev->lock.lock_queue, &entry);
+		if (!retcode) {
 			if (dev->driver->release)
 			if (dev->driver->release)
 				dev->driver->release(dev, filp);
 				dev->driver->release(dev, filp);
-			drm_lock_free( dev, &dev->lock.hw_lock->lock,
-					DRM_KERNEL_CONTEXT );
+			drm_lock_free(dev, &dev->lock.hw_lock->lock,
+				      DRM_KERNEL_CONTEXT);
 		}
 		}
 	}
 	}
-	
-	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) && !dev->driver->release)
-	{
+
+	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)
+	    && !dev->driver->release) {
 		dev->driver->reclaim_buffers(dev, filp);
 		dev->driver->reclaim_buffers(dev, filp);
 	}
 	}
 
 
-	drm_fasync( -1, filp, 0 );
+	drm_fasync(-1, filp, 0);
 
 
-	down( &dev->ctxlist_sem );
-	if ( dev->ctxlist && (!list_empty(&dev->ctxlist->head))) {
+	down(&dev->ctxlist_sem);
+	if (dev->ctxlist && (!list_empty(&dev->ctxlist->head))) {
 		drm_ctx_list_t *pos, *n;
 		drm_ctx_list_t *pos, *n;
 
 
-		list_for_each_entry_safe( pos, n, &dev->ctxlist->head, head ) {
-			if ( pos->tag == priv &&
-			     pos->handle != DRM_KERNEL_CONTEXT ) {
+		list_for_each_entry_safe(pos, n, &dev->ctxlist->head, head) {
+			if (pos->tag == priv &&
+			    pos->handle != DRM_KERNEL_CONTEXT) {
 				if (dev->driver->context_dtor)
 				if (dev->driver->context_dtor)
-					dev->driver->context_dtor(dev, pos->handle);
+					dev->driver->context_dtor(dev,
+								  pos->handle);
 
 
-				drm_ctxbitmap_free( dev, pos->handle );
+				drm_ctxbitmap_free(dev, pos->handle);
 
 
-				list_del( &pos->head );
-				drm_free( pos, sizeof(*pos), DRM_MEM_CTXLIST );
+				list_del(&pos->head);
+				drm_free(pos, sizeof(*pos), DRM_MEM_CTXLIST);
 				--dev->ctx_count;
 				--dev->ctx_count;
 			}
 			}
 		}
 		}
 	}
 	}
-	up( &dev->ctxlist_sem );
+	up(&dev->ctxlist_sem);
 
 
-	down( &dev->struct_sem );
-	if ( priv->remove_auth_on_close == 1 ) {
+	down(&dev->struct_sem);
+	if (priv->remove_auth_on_close == 1) {
 		drm_file_t *temp = dev->file_first;
 		drm_file_t *temp = dev->file_first;
-		while ( temp ) {
+		while (temp) {
 			temp->authenticated = 0;
 			temp->authenticated = 0;
 			temp = temp->next;
 			temp = temp->next;
 		}
 		}
 	}
 	}
-	if ( priv->prev ) {
+	if (priv->prev) {
 		priv->prev->next = priv->next;
 		priv->prev->next = priv->next;
 	} else {
 	} else {
-		dev->file_first	 = priv->next;
+		dev->file_first = priv->next;
 	}
 	}
-	if ( priv->next ) {
+	if (priv->next) {
 		priv->next->prev = priv->prev;
 		priv->next->prev = priv->prev;
 	} else {
 	} else {
-		dev->file_last	 = priv->prev;
+		dev->file_last = priv->prev;
 	}
 	}
-	up( &dev->struct_sem );
-	
+	up(&dev->struct_sem);
+
 	if (dev->driver->free_filp_priv)
 	if (dev->driver->free_filp_priv)
 		dev->driver->free_filp_priv(dev, priv);
 		dev->driver->free_filp_priv(dev, priv);
 
 
-	drm_free( priv, sizeof(*priv), DRM_MEM_FILES );
+	drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
 
 
 	/* ========================================================
 	/* ========================================================
 	 * End inline drm_release
 	 * End inline drm_release
 	 */
 	 */
 
 
-	atomic_inc( &dev->counts[_DRM_STAT_CLOSES] );
-	spin_lock( &dev->count_lock );
-	if ( !--dev->open_count ) {
-		if ( atomic_read( &dev->ioctl_count ) || dev->blocked ) {
-			DRM_ERROR( "Device busy: %d %d\n",
-				   atomic_read( &dev->ioctl_count ),
-				   dev->blocked );
-			spin_unlock( &dev->count_lock );
+	atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
+	spin_lock(&dev->count_lock);
+	if (!--dev->open_count) {
+		if (atomic_read(&dev->ioctl_count) || dev->blocked) {
+			DRM_ERROR("Device busy: %d %d\n",
+				  atomic_read(&dev->ioctl_count), dev->blocked);
+			spin_unlock(&dev->count_lock);
 			unlock_kernel();
 			unlock_kernel();
 			return -EBUSY;
 			return -EBUSY;
 		}
 		}
-		spin_unlock( &dev->count_lock );
+		spin_unlock(&dev->count_lock);
 		unlock_kernel();
 		unlock_kernel();
-		return drm_takedown( dev );
+		return drm_takedown(dev);
 	}
 	}
-	spin_unlock( &dev->count_lock );
+	spin_unlock(&dev->count_lock);
 
 
 	unlock_kernel();
 	unlock_kernel();
 
 
 	return retcode;
 	return retcode;
 }
 }
+
 EXPORT_SYMBOL(drm_release);
 EXPORT_SYMBOL(drm_release);
 
 
 /**
 /**
- * Called whenever a process opens /dev/drm. 
+ * Called whenever a process opens /dev/drm.
  *
  *
  * \param inode device inode.
  * \param inode device inode.
  * \param filp file pointer.
  * \param filp file pointer.
  * \param dev device.
  * \param dev device.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
- * 
+ *
  * Creates and initializes a drm_file structure for the file private data in \p
  * Creates and initializes a drm_file structure for the file private data in \p
  * filp and add it into the double linked list in \p dev.
  * filp and add it into the double linked list in \p dev.
  */
  */
-static int drm_open_helper(struct inode *inode, struct file *filp, drm_device_t *dev)
+static int drm_open_helper(struct inode *inode, struct file *filp,
+			   drm_device_t * dev)
 {
 {
-	int	     minor = iminor(inode);
-	drm_file_t   *priv;
+	int minor = iminor(inode);
+	drm_file_t *priv;
 	int ret;
 	int ret;
 
 
-	if (filp->f_flags & O_EXCL)   return -EBUSY; /* No exclusive opens */
-	if (!drm_cpu_valid())        return -EINVAL;
+	if (filp->f_flags & O_EXCL)
+		return -EBUSY;	/* No exclusive opens */
+	if (!drm_cpu_valid())
+		return -EINVAL;
 
 
 	DRM_DEBUG("pid = %d, minor = %d\n", current->pid, minor);
 	DRM_DEBUG("pid = %d, minor = %d\n", current->pid, minor);
 
 
-	priv		    = drm_alloc(sizeof(*priv), DRM_MEM_FILES);
-	if(!priv) return -ENOMEM;
+	priv = drm_alloc(sizeof(*priv), DRM_MEM_FILES);
+	if (!priv)
+		return -ENOMEM;
 
 
 	memset(priv, 0, sizeof(*priv));
 	memset(priv, 0, sizeof(*priv));
-	filp->private_data  = priv;
-	priv->uid	    = current->euid;
-	priv->pid	    = current->pid;
-	priv->minor	    = minor;
-	priv->head          = drm_heads[minor];
-	priv->ioctl_count   = 0;
+	filp->private_data = priv;
+	priv->uid = current->euid;
+	priv->pid = current->pid;
+	priv->minor = minor;
+	priv->head = drm_heads[minor];
+	priv->ioctl_count = 0;
 	priv->authenticated = capable(CAP_SYS_ADMIN);
 	priv->authenticated = capable(CAP_SYS_ADMIN);
-	priv->lock_count    = 0;
+	priv->lock_count = 0;
 
 
 	if (dev->driver->open_helper) {
 	if (dev->driver->open_helper) {
-		ret=dev->driver->open_helper(dev, priv);
+		ret = dev->driver->open_helper(dev, priv);
 		if (ret < 0)
 		if (ret < 0)
 			goto out_free;
 			goto out_free;
 	}
 	}
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 	if (!dev->file_last) {
 	if (!dev->file_last) {
-		priv->next	= NULL;
-		priv->prev	= NULL;
+		priv->next = NULL;
+		priv->prev = NULL;
 		dev->file_first = priv;
 		dev->file_first = priv;
-		dev->file_last	= priv;
+		dev->file_last = priv;
 	} else {
 	} else {
-		priv->next	     = NULL;
-		priv->prev	     = dev->file_last;
+		priv->next = NULL;
+		priv->prev = dev->file_last;
 		dev->file_last->next = priv;
 		dev->file_last->next = priv;
-		dev->file_last	     = priv;
+		dev->file_last = priv;
 	}
 	}
 	up(&dev->struct_sem);
 	up(&dev->struct_sem);
 
 
@@ -394,42 +396,48 @@ static int drm_open_helper(struct inode *inode, struct file *filp, drm_device_t
 		}
 		}
 		if (!dev->hose) {
 		if (!dev->hose) {
 			struct pci_bus *b = pci_bus_b(pci_root_buses.next);
 			struct pci_bus *b = pci_bus_b(pci_root_buses.next);
-			if (b) dev->hose = b->sysdata;
+			if (b)
+				dev->hose = b->sysdata;
 		}
 		}
 	}
 	}
 #endif
 #endif
 
 
 	return 0;
 	return 0;
-out_free:
+      out_free:
 	drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
 	drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
-	filp->private_data=NULL;
+	filp->private_data = NULL;
 	return ret;
 	return ret;
 }
 }
 
 
 /** No-op. */
 /** No-op. */
 int drm_flush(struct file *filp)
 int drm_flush(struct file *filp)
 {
 {
-	drm_file_t    *priv   = filp->private_data;
-	drm_device_t  *dev    = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 
 
 	DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
 	DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
-		  current->pid, (long)old_encode_dev(priv->head->device), dev->open_count);
+		  current->pid, (long)old_encode_dev(priv->head->device),
+		  dev->open_count);
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_flush);
 EXPORT_SYMBOL(drm_flush);
 
 
 /** No-op. */
 /** No-op. */
 int drm_fasync(int fd, struct file *filp, int on)
 int drm_fasync(int fd, struct file *filp, int on)
 {
 {
-	drm_file_t    *priv   = filp->private_data;
-	drm_device_t  *dev    = priv->head->dev;
-	int	      retcode;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	int retcode;
 
 
-	DRM_DEBUG("fd = %d, device = 0x%lx\n", fd, (long)old_encode_dev(priv->head->device));
+	DRM_DEBUG("fd = %d, device = 0x%lx\n", fd,
+		  (long)old_encode_dev(priv->head->device));
 	retcode = fasync_helper(fd, filp, on, &dev->buf_async);
 	retcode = fasync_helper(fd, filp, on, &dev->buf_async);
-	if (retcode < 0) return retcode;
+	if (retcode < 0)
+		return retcode;
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_fasync);
 EXPORT_SYMBOL(drm_fasync);
 
 
 /** No-op. */
 /** No-op. */
@@ -437,5 +445,5 @@ unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait)
 {
 {
 	return 0;
 	return 0;
 }
 }
-EXPORT_SYMBOL(drm_poll);
 
 
+EXPORT_SYMBOL(drm_poll);

+ 4 - 3
drivers/char/drm/drm_init.c

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_init.h 
+ * \file drm_init.c
  * Setup/Cleanup for DRM
  * Setup/Cleanup for DRM
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -43,10 +43,11 @@
 int drm_cpu_valid(void)
 int drm_cpu_valid(void)
 {
 {
 #if defined(__i386__)
 #if defined(__i386__)
-	if (boot_cpu_data.x86 == 3) return 0; /* No cmpxchg on a 386 */
+	if (boot_cpu_data.x86 == 3)
+		return 0;	/* No cmpxchg on a 386 */
 #endif
 #endif
 #if defined(__sparc__) && !defined(__sparc_v9__)
 #if defined(__sparc__) && !defined(__sparc_v9__)
-	return 0; /* No cmpxchg before v9 sparc. */
+	return 0;		/* No cmpxchg before v9 sparc. */
 #endif
 #endif
 	return 1;
 	return 1;
 }
 }

+ 113 - 112
drivers/char/drm/drm_ioc32.c

@@ -68,15 +68,15 @@
 #define DRM_IOCTL_WAIT_VBLANK32		DRM_IOWR(0x3a, drm_wait_vblank32_t)
 #define DRM_IOCTL_WAIT_VBLANK32		DRM_IOWR(0x3a, drm_wait_vblank32_t)
 
 
 typedef struct drm_version_32 {
 typedef struct drm_version_32 {
-	int	version_major;	  /**< Major version */
-	int	version_minor;	  /**< Minor version */
-	int	version_patchlevel;/**< Patch level */
-	u32	name_len;	  /**< Length of name buffer */
-	u32	name;		  /**< Name of driver */
-	u32	date_len;	  /**< Length of date buffer */
-	u32	date;		  /**< User-space buffer to hold date */
-	u32	desc_len;	  /**< Length of desc buffer */
-	u32	desc;		  /**< User-space buffer to hold desc */
+	int version_major;	  /**< Major version */
+	int version_minor;	  /**< Minor version */
+	int version_patchlevel;	   /**< Patch level */
+	u32 name_len;		  /**< Length of name buffer */
+	u32 name;		  /**< Name of driver */
+	u32 date_len;		  /**< Length of date buffer */
+	u32 date;		  /**< User-space buffer to hold date */
+	u32 desc_len;		  /**< Length of desc buffer */
+	u32 desc;		  /**< User-space buffer to hold desc */
 } drm_version32_t;
 } drm_version32_t;
 
 
 static int compat_drm_version(struct file *file, unsigned int cmd,
 static int compat_drm_version(struct file *file, unsigned int cmd,
@@ -86,7 +86,7 @@ static int compat_drm_version(struct file *file, unsigned int cmd,
 	drm_version_t __user *version;
 	drm_version_t __user *version;
 	int err;
 	int err;
 
 
-	if (copy_from_user(&v32, (void __user *) arg, sizeof(v32)))
+	if (copy_from_user(&v32, (void __user *)arg, sizeof(v32)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	version = compat_alloc_user_space(sizeof(*version));
 	version = compat_alloc_user_space(sizeof(*version));
@@ -104,7 +104,7 @@ static int compat_drm_version(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_VERSION, (unsigned long) version);
+			DRM_IOCTL_VERSION, (unsigned long)version);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -116,7 +116,7 @@ static int compat_drm_version(struct file *file, unsigned int cmd,
 	    || __get_user(v32.desc_len, &version->desc_len))
 	    || __get_user(v32.desc_len, &version->desc_len))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	if (copy_to_user((void __user *) arg, &v32, sizeof(v32)))
+	if (copy_to_user((void __user *)arg, &v32, sizeof(v32)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
@@ -133,25 +133,25 @@ static int compat_drm_getunique(struct file *file, unsigned int cmd,
 	drm_unique_t __user *u;
 	drm_unique_t __user *u;
 	int err;
 	int err;
 
 
-	if (copy_from_user(&uq32, (void __user *) arg, sizeof(uq32)))
+	if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	u = compat_alloc_user_space(sizeof(*u));
 	u = compat_alloc_user_space(sizeof(*u));
 	if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
 	if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
 		return -EFAULT;
 		return -EFAULT;
 	if (__put_user(uq32.unique_len, &u->unique_len)
 	if (__put_user(uq32.unique_len, &u->unique_len)
-	    || __put_user((void __user *)(unsigned long) uq32.unique,
+	    || __put_user((void __user *)(unsigned long)uq32.unique,
 			  &u->unique))
 			  &u->unique))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_GET_UNIQUE, (unsigned long) u);
+			DRM_IOCTL_GET_UNIQUE, (unsigned long)u);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
 	if (__get_user(uq32.unique_len, &u->unique_len))
 	if (__get_user(uq32.unique_len, &u->unique_len))
 		return -EFAULT;
 		return -EFAULT;
-	if (copy_to_user((void __user *) arg, &uq32, sizeof(uq32)))
+	if (copy_to_user((void __user *)arg, &uq32, sizeof(uq32)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
@@ -162,28 +162,28 @@ static int compat_drm_setunique(struct file *file, unsigned int cmd,
 	drm_unique32_t uq32;
 	drm_unique32_t uq32;
 	drm_unique_t __user *u;
 	drm_unique_t __user *u;
 
 
-	if (copy_from_user(&uq32, (void __user *) arg, sizeof(uq32)))
+	if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	u = compat_alloc_user_space(sizeof(*u));
 	u = compat_alloc_user_space(sizeof(*u));
 	if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
 	if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
 		return -EFAULT;
 		return -EFAULT;
 	if (__put_user(uq32.unique_len, &u->unique_len)
 	if (__put_user(uq32.unique_len, &u->unique_len)
-	    || __put_user((void __user *)(unsigned long) uq32.unique,
+	    || __put_user((void __user *)(unsigned long)uq32.unique,
 			  &u->unique))
 			  &u->unique))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_SET_UNIQUE, (unsigned long) u);
+			 DRM_IOCTL_SET_UNIQUE, (unsigned long)u);
 }
 }
 
 
 typedef struct drm_map32 {
 typedef struct drm_map32 {
-	u32	offset;	 	/**< Requested physical address (0 for SAREA)*/
-	u32	size;	 	/**< Requested physical size (bytes) */
-	drm_map_type_t	type;	/**< Type of memory to map */
+	u32 offset;		/**< Requested physical address (0 for SAREA)*/
+	u32 size;		/**< Requested physical size (bytes) */
+	drm_map_type_t type;	/**< Type of memory to map */
 	drm_map_flags_t flags;	/**< Flags */
 	drm_map_flags_t flags;	/**< Flags */
-	u32	handle;		/**< User-space: "Handle" to pass to mmap() */
-	int	mtrr;		/**< MTRR slot used */
+	u32 handle;		/**< User-space: "Handle" to pass to mmap() */
+	int mtrr;		/**< MTRR slot used */
 } drm_map32_t;
 } drm_map32_t;
 
 
 static int compat_drm_getmap(struct file *file, unsigned int cmd,
 static int compat_drm_getmap(struct file *file, unsigned int cmd,
@@ -205,7 +205,7 @@ static int compat_drm_getmap(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_GET_MAP, (unsigned long) map);
+			DRM_IOCTL_GET_MAP, (unsigned long)map);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -217,7 +217,7 @@ static int compat_drm_getmap(struct file *file, unsigned int cmd,
 	    || __get_user(m32.mtrr, &map->mtrr))
 	    || __get_user(m32.mtrr, &map->mtrr))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	m32.handle = (unsigned long) handle;
+	m32.handle = (unsigned long)handle;
 	if (copy_to_user(argp, &m32, sizeof(m32)))
 	if (copy_to_user(argp, &m32, sizeof(m32)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
@@ -246,7 +246,7 @@ static int compat_drm_addmap(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_ADD_MAP, (unsigned long) map);
+			DRM_IOCTL_ADD_MAP, (unsigned long)map);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -255,8 +255,8 @@ static int compat_drm_addmap(struct file *file, unsigned int cmd,
 	    || __get_user(handle, &map->handle))
 	    || __get_user(handle, &map->handle))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	m32.handle = (unsigned long) handle;
-	if (m32.handle != (unsigned long) handle && printk_ratelimit())
+	m32.handle = (unsigned long)handle;
+	if (m32.handle != (unsigned long)handle && printk_ratelimit())
 		printk(KERN_ERR "compat_drm_addmap truncated handle"
 		printk(KERN_ERR "compat_drm_addmap truncated handle"
 		       " %p for type %d offset %x\n",
 		       " %p for type %d offset %x\n",
 		       handle, m32.type, m32.offset);
 		       handle, m32.type, m32.offset);
@@ -280,20 +280,20 @@ static int compat_drm_rmmap(struct file *file, unsigned int cmd,
 	map = compat_alloc_user_space(sizeof(*map));
 	map = compat_alloc_user_space(sizeof(*map));
 	if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
 	if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
 		return -EFAULT;
 		return -EFAULT;
-	if (__put_user((void *)(unsigned long) handle, &map->handle))
+	if (__put_user((void *)(unsigned long)handle, &map->handle))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_RM_MAP, (unsigned long) map);
+			 DRM_IOCTL_RM_MAP, (unsigned long)map);
 }
 }
 
 
 typedef struct drm_client32 {
 typedef struct drm_client32 {
-	int	idx;	/**< Which client desired? */
-	int	auth;	/**< Is client authenticated? */
-	u32	pid;	/**< Process ID */
-	u32	uid;	/**< User ID */
-	u32	magic;	/**< Magic */
-	u32	iocs;	/**< Ioctl count */
+	int idx;	/**< Which client desired? */
+	int auth;	/**< Is client authenticated? */
+	u32 pid;	/**< Process ID */
+	u32 uid;	/**< User ID */
+	u32 magic;	/**< Magic */
+	u32 iocs;	/**< Ioctl count */
 } drm_client32_t;
 } drm_client32_t;
 
 
 static int compat_drm_getclient(struct file *file, unsigned int cmd,
 static int compat_drm_getclient(struct file *file, unsigned int cmd,
@@ -314,7 +314,7 @@ static int compat_drm_getclient(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_GET_CLIENT, (unsigned long) client);
+			DRM_IOCTL_GET_CLIENT, (unsigned long)client);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -351,7 +351,7 @@ static int compat_drm_getstats(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_GET_STATS, (unsigned long) stats);
+			DRM_IOCTL_GET_STATS, (unsigned long)stats);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -368,12 +368,12 @@ static int compat_drm_getstats(struct file *file, unsigned int cmd,
 }
 }
 
 
 typedef struct drm_buf_desc32 {
 typedef struct drm_buf_desc32 {
-	int	      count;	 /**< Number of buffers of this size */
-	int	      size;	 /**< Size in bytes */
-	int	      low_mark;	 /**< Low water mark */
-	int	      high_mark; /**< High water mark */
-	int	      flags;
-	u32	      agp_start; /**< Start address in the AGP aperture */
+	int count;		 /**< Number of buffers of this size */
+	int size;		 /**< Size in bytes */
+	int low_mark;		 /**< Low water mark */
+	int high_mark;		 /**< High water mark */
+	int flags;
+	u32 agp_start;		 /**< Start address in the AGP aperture */
 } drm_buf_desc32_t;
 } drm_buf_desc32_t;
 
 
 static int compat_drm_addbufs(struct file *file, unsigned int cmd,
 static int compat_drm_addbufs(struct file *file, unsigned int cmd,
@@ -395,7 +395,7 @@ static int compat_drm_addbufs(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_ADD_BUFS, (unsigned long) buf);
+			DRM_IOCTL_ADD_BUFS, (unsigned long)buf);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -427,12 +427,12 @@ static int compat_drm_markbufs(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_MARK_BUFS, (unsigned long) buf);
+			 DRM_IOCTL_MARK_BUFS, (unsigned long)buf);
 }
 }
 
 
 typedef struct drm_buf_info32 {
 typedef struct drm_buf_info32 {
-	int	       count;	/**< Entries in list */
-	u32	       list;
+	int count;		/**< Entries in list */
+	u32 list;
 } drm_buf_info32_t;
 } drm_buf_info32_t;
 
 
 static int compat_drm_infobufs(struct file *file, unsigned int cmd,
 static int compat_drm_infobufs(struct file *file, unsigned int cmd,
@@ -451,7 +451,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	count = req32.count;
 	count = req32.count;
-	to = (drm_buf_desc32_t __user *)(unsigned long) req32.list;
+	to = (drm_buf_desc32_t __user *) (unsigned long)req32.list;
 	if (count < 0)
 	if (count < 0)
 		count = 0;
 		count = 0;
 	if (count > 0
 	if (count > 0
@@ -469,7 +469,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_INFO_BUFS, (unsigned long) request);
+			DRM_IOCTL_INFO_BUFS, (unsigned long)request);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -488,16 +488,16 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
 }
 }
 
 
 typedef struct drm_buf_pub32 {
 typedef struct drm_buf_pub32 {
-	int	idx;		/**< Index into the master buffer list */
-	int	total;		/**< Buffer size */
-	int	used;		/**< Amount of buffer in use (for DMA) */
-	u32	address;	/**< Address of buffer */
+	int idx;		/**< Index into the master buffer list */
+	int total;		/**< Buffer size */
+	int used;		/**< Amount of buffer in use (for DMA) */
+	u32 address;		/**< Address of buffer */
 } drm_buf_pub32_t;
 } drm_buf_pub32_t;
 
 
 typedef struct drm_buf_map32 {
 typedef struct drm_buf_map32 {
-	int	count;		/**< Length of the buffer list */
-	u32	virtual;	/**< Mmap'd area in user-virtual */
-	u32	list;		/**< Buffer information */
+	int count;		/**< Length of the buffer list */
+	u32 virtual;		/**< Mmap'd area in user-virtual */
+	u32 list;		/**< Buffer information */
 } drm_buf_map32_t;
 } drm_buf_map32_t;
 
 
 static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
 static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
@@ -531,7 +531,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_MAP_BUFS, (unsigned long) request);
+			DRM_IOCTL_MAP_BUFS, (unsigned long)request);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -542,21 +542,21 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
 			if (__copy_in_user(&list32[i], &list[i],
 			if (__copy_in_user(&list32[i], &list[i],
 					   offsetof(drm_buf_pub_t, address))
 					   offsetof(drm_buf_pub_t, address))
 			    || __get_user(addr, &list[i].address)
 			    || __get_user(addr, &list[i].address)
-			    || __put_user((unsigned long) addr,
+			    || __put_user((unsigned long)addr,
 					  &list32[i].address))
 					  &list32[i].address))
 				return -EFAULT;
 				return -EFAULT;
 
 
 	if (__put_user(actual, &argp->count)
 	if (__put_user(actual, &argp->count)
 	    || __get_user(addr, &request->virtual)
 	    || __get_user(addr, &request->virtual)
-	    || __put_user((unsigned long) addr, &argp->virtual))
+	    || __put_user((unsigned long)addr, &argp->virtual))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return 0;
 	return 0;
 }
 }
 
 
 typedef struct drm_buf_free32 {
 typedef struct drm_buf_free32 {
-	int	count;
-	u32	list;
+	int count;
+	u32 list;
 } drm_buf_free32_t;
 } drm_buf_free32_t;
 
 
 static int compat_drm_freebufs(struct file *file, unsigned int cmd,
 static int compat_drm_freebufs(struct file *file, unsigned int cmd,
@@ -573,17 +573,17 @@ static int compat_drm_freebufs(struct file *file, unsigned int cmd,
 	if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
 	if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
 		return -EFAULT;
 		return -EFAULT;
 	if (__put_user(req32.count, &request->count)
 	if (__put_user(req32.count, &request->count)
-	    || __put_user((int __user *)(unsigned long) req32.list,
+	    || __put_user((int __user *)(unsigned long)req32.list,
 			  &request->list))
 			  &request->list))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_FREE_BUFS, (unsigned long) request);
+			 DRM_IOCTL_FREE_BUFS, (unsigned long)request);
 }
 }
 
 
 typedef struct drm_ctx_priv_map32 {
 typedef struct drm_ctx_priv_map32 {
-	unsigned int	ctx_id;  /**< Context requesting private mapping */
-	u32		handle; /**< Handle of map */
+	unsigned int ctx_id;	 /**< Context requesting private mapping */
+	u32 handle;		/**< Handle of map */
 } drm_ctx_priv_map32_t;
 } drm_ctx_priv_map32_t;
 
 
 static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
 static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
@@ -600,12 +600,12 @@ static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
 	if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
 	if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
 		return -EFAULT;
 		return -EFAULT;
 	if (__put_user(req32.ctx_id, &request->ctx_id)
 	if (__put_user(req32.ctx_id, &request->ctx_id)
-	    || __put_user((void *)(unsigned long) req32.handle,
+	    || __put_user((void *)(unsigned long)req32.handle,
 			  &request->handle))
 			  &request->handle))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_SET_SAREA_CTX, (unsigned long) request);
+			 DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request);
 }
 }
 
 
 static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
 static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
@@ -628,20 +628,20 @@ static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_GET_SAREA_CTX, (unsigned long) request);
+			DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
 	if (__get_user(handle, &request->handle)
 	if (__get_user(handle, &request->handle)
-	    || __put_user((unsigned long) handle, &argp->handle))
+	    || __put_user((unsigned long)handle, &argp->handle))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return 0;
 	return 0;
 }
 }
 
 
 typedef struct drm_ctx_res32 {
 typedef struct drm_ctx_res32 {
-	int	count;
-	u32	contexts;
+	int count;
+	u32 contexts;
 } drm_ctx_res32_t;
 } drm_ctx_res32_t;
 
 
 static int compat_drm_resctx(struct file *file, unsigned int cmd,
 static int compat_drm_resctx(struct file *file, unsigned int cmd,
@@ -659,12 +659,12 @@ static int compat_drm_resctx(struct file *file, unsigned int cmd,
 	if (!access_ok(VERIFY_WRITE, res, sizeof(*res)))
 	if (!access_ok(VERIFY_WRITE, res, sizeof(*res)))
 		return -EFAULT;
 		return -EFAULT;
 	if (__put_user(res32.count, &res->count)
 	if (__put_user(res32.count, &res->count)
-	    || __put_user((drm_ctx_t __user *)(unsigned long) res32.contexts,
+	    || __put_user((drm_ctx_t __user *) (unsigned long)res32.contexts,
 			  &res->contexts))
 			  &res->contexts))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_RES_CTX, (unsigned long) res);
+			DRM_IOCTL_RES_CTX, (unsigned long)res);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -676,23 +676,23 @@ static int compat_drm_resctx(struct file *file, unsigned int cmd,
 }
 }
 
 
 typedef struct drm_dma32 {
 typedef struct drm_dma32 {
-	int	context;	  /**< Context handle */
-	int	send_count;	  /**< Number of buffers to send */
-	u32	send_indices;	  /**< List of handles to buffers */
-	u32	send_sizes;	  /**< Lengths of data to send */
+	int context;		  /**< Context handle */
+	int send_count;		  /**< Number of buffers to send */
+	u32 send_indices;	  /**< List of handles to buffers */
+	u32 send_sizes;		  /**< Lengths of data to send */
 	drm_dma_flags_t flags;		  /**< Flags */
 	drm_dma_flags_t flags;		  /**< Flags */
-	int	request_count;	  /**< Number of buffers requested */
-	int	request_size;	  /**< Desired size for buffers */
-	u32	request_indices;  /**< Buffer information */
-	u32	request_sizes;
-	int	granted_count;	  /**< Number of buffers granted */
+	int request_count;	  /**< Number of buffers requested */
+	int request_size;	  /**< Desired size for buffers */
+	u32 request_indices;	  /**< Buffer information */
+	u32 request_sizes;
+	int granted_count;	  /**< Number of buffers granted */
 } drm_dma32_t;
 } drm_dma32_t;
 
 
 static int compat_drm_dma(struct file *file, unsigned int cmd,
 static int compat_drm_dma(struct file *file, unsigned int cmd,
 			  unsigned long arg)
 			  unsigned long arg)
 {
 {
 	drm_dma32_t d32;
 	drm_dma32_t d32;
-	drm_dma32_t __user *argp = (void __user *) arg;
+	drm_dma32_t __user *argp = (void __user *)arg;
 	drm_dma_t __user *d;
 	drm_dma_t __user *d;
 	int err;
 	int err;
 
 
@@ -705,20 +705,20 @@ static int compat_drm_dma(struct file *file, unsigned int cmd,
 
 
 	if (__put_user(d32.context, &d->context)
 	if (__put_user(d32.context, &d->context)
 	    || __put_user(d32.send_count, &d->send_count)
 	    || __put_user(d32.send_count, &d->send_count)
-	    || __put_user((int __user *)(unsigned long) d32.send_indices,
+	    || __put_user((int __user *)(unsigned long)d32.send_indices,
 			  &d->send_indices)
 			  &d->send_indices)
-	    || __put_user((int __user *)(unsigned long) d32.send_sizes,
+	    || __put_user((int __user *)(unsigned long)d32.send_sizes,
 			  &d->send_sizes)
 			  &d->send_sizes)
 	    || __put_user(d32.flags, &d->flags)
 	    || __put_user(d32.flags, &d->flags)
 	    || __put_user(d32.request_count, &d->request_count)
 	    || __put_user(d32.request_count, &d->request_count)
-	    || __put_user((int __user *)(unsigned long) d32.request_indices,
+	    || __put_user((int __user *)(unsigned long)d32.request_indices,
 			  &d->request_indices)
 			  &d->request_indices)
-	    || __put_user((int __user *)(unsigned long) d32.request_sizes,
+	    || __put_user((int __user *)(unsigned long)d32.request_sizes,
 			  &d->request_sizes))
 			  &d->request_sizes))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_DMA, (unsigned long) d);
+			DRM_IOCTL_DMA, (unsigned long)d);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -751,19 +751,19 @@ static int compat_drm_agp_enable(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_AGP_ENABLE, (unsigned long) mode);
+			 DRM_IOCTL_AGP_ENABLE, (unsigned long)mode);
 }
 }
 
 
 typedef struct drm_agp_info32 {
 typedef struct drm_agp_info32 {
-	int       agp_version_major;
-	int       agp_version_minor;
-	u32	  mode;
-	u32	  aperture_base;  /* physical address */
-	u32	  aperture_size;  /* bytes */
-	u32	  memory_allowed; /* bytes */
-	u32	  memory_used;
-
-				/* PCI information */
+	int agp_version_major;
+	int agp_version_minor;
+	u32 mode;
+	u32 aperture_base;	/* physical address */
+	u32 aperture_size;	/* bytes */
+	u32 memory_allowed;	/* bytes */
+	u32 memory_used;
+
+	/* PCI information */
 	unsigned short id_vendor;
 	unsigned short id_vendor;
 	unsigned short id_device;
 	unsigned short id_device;
 } drm_agp_info32_t;
 } drm_agp_info32_t;
@@ -781,7 +781,7 @@ static int compat_drm_agp_info(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_AGP_INFO, (unsigned long) info);
+			DRM_IOCTL_AGP_INFO, (unsigned long)info);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -806,7 +806,7 @@ typedef struct drm_agp_buffer32 {
 	u32 size;	/**< In bytes -- will round to page boundary */
 	u32 size;	/**< In bytes -- will round to page boundary */
 	u32 handle;	/**< Used for binding / unbinding */
 	u32 handle;	/**< Used for binding / unbinding */
 	u32 type;	/**< Type of memory to allocate */
 	u32 type;	/**< Type of memory to allocate */
-        u32 physical;	/**< Physical used by i810 */
+	u32 physical;	/**< Physical used by i810 */
 } drm_agp_buffer32_t;
 } drm_agp_buffer32_t;
 
 
 static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
 static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
@@ -827,7 +827,7 @@ static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_AGP_ALLOC, (unsigned long) request);
+			DRM_IOCTL_AGP_ALLOC, (unsigned long)request);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -835,7 +835,7 @@ static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
 	    || __get_user(req32.physical, &request->physical)
 	    || __get_user(req32.physical, &request->physical)
 	    || copy_to_user(argp, &req32, sizeof(req32))) {
 	    || copy_to_user(argp, &req32, sizeof(req32))) {
 		drm_ioctl(file->f_dentry->d_inode, file,
 		drm_ioctl(file->f_dentry->d_inode, file,
-			  DRM_IOCTL_AGP_FREE, (unsigned long) request);
+			  DRM_IOCTL_AGP_FREE, (unsigned long)request);
 		return -EFAULT;
 		return -EFAULT;
 	}
 	}
 
 
@@ -856,7 +856,7 @@ static int compat_drm_agp_free(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_AGP_FREE, (unsigned long) request);
+			 DRM_IOCTL_AGP_FREE, (unsigned long)request);
 }
 }
 
 
 typedef struct drm_agp_binding32 {
 typedef struct drm_agp_binding32 {
@@ -881,7 +881,7 @@ static int compat_drm_agp_bind(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_AGP_BIND, (unsigned long) request);
+			 DRM_IOCTL_AGP_BIND, (unsigned long)request);
 }
 }
 
 
 static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
 static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
@@ -898,9 +898,9 @@ static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_AGP_UNBIND, (unsigned long) request);
+			 DRM_IOCTL_AGP_UNBIND, (unsigned long)request);
 }
 }
-#endif /* __OS_HAS_AGP */
+#endif				/* __OS_HAS_AGP */
 
 
 typedef struct drm_scatter_gather32 {
 typedef struct drm_scatter_gather32 {
 	u32 size;	/**< In bytes -- will round to page boundary */
 	u32 size;	/**< In bytes -- will round to page boundary */
@@ -923,7 +923,7 @@ static int compat_drm_sg_alloc(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_SG_ALLOC, (unsigned long) request);
+			DRM_IOCTL_SG_ALLOC, (unsigned long)request);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -950,7 +950,7 @@ static int compat_drm_sg_free(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_SG_FREE, (unsigned long) request);
+			 DRM_IOCTL_SG_FREE, (unsigned long)request);
 }
 }
 
 
 struct drm_wait_vblank_request32 {
 struct drm_wait_vblank_request32 {
@@ -990,7 +990,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	err = drm_ioctl(file->f_dentry->d_inode, file,
 	err = drm_ioctl(file->f_dentry->d_inode, file,
-			DRM_IOCTL_WAIT_VBLANK, (unsigned long) request);
+			DRM_IOCTL_WAIT_VBLANK, (unsigned long)request);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -1059,11 +1059,12 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 
 
 	lock_kernel();		/* XXX for now */
 	lock_kernel();		/* XXX for now */
 	if (fn != NULL)
 	if (fn != NULL)
-		ret = (*fn)(filp, cmd, arg);
+		ret = (*fn) (filp, cmd, arg);
 	else
 	else
 		ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
 		ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
 	unlock_kernel();
 	unlock_kernel();
 
 
 	return ret;
 	return ret;
 }
 }
+
 EXPORT_SYMBOL(drm_compat_ioctl);
 EXPORT_SYMBOL(drm_compat_ioctl);

+ 86 - 82
drivers/char/drm/drm_ioctl.c

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_ioctl.h 
+ * \file drm_ioctl.c
  * IOCTL processing for DRM
  * IOCTL processing for DRM
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -40,7 +40,7 @@
 
 
 /**
 /**
  * Get the bus id.
  * Get the bus id.
- * 
+ *
  * \param inode device inode.
  * \param inode device inode.
  * \param filp file pointer.
  * \param filp file pointer.
  * \param cmd command.
  * \param cmd command.
@@ -50,12 +50,12 @@
  * Copies the bus id from drm_device::unique into user space.
  * Copies the bus id from drm_device::unique into user space.
  */
  */
 int drm_getunique(struct inode *inode, struct file *filp,
 int drm_getunique(struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg)
+		  unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	 *priv	 = filp->private_data;
-	drm_device_t	 *dev	 = priv->head->dev;
-	drm_unique_t	 __user *argp = (void __user *)arg;
-	drm_unique_t	 u;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_unique_t __user *argp = (void __user *)arg;
+	drm_unique_t u;
 
 
 	if (copy_from_user(&u, argp, sizeof(u)))
 	if (copy_from_user(&u, argp, sizeof(u)))
 		return -EFAULT;
 		return -EFAULT;
@@ -71,7 +71,7 @@ int drm_getunique(struct inode *inode, struct file *filp,
 
 
 /**
 /**
  * Set the bus id.
  * Set the bus id.
- * 
+ *
  * \param inode device inode.
  * \param inode device inode.
  * \param filp file pointer.
  * \param filp file pointer.
  * \param cmd command.
  * \param cmd command.
@@ -84,34 +84,39 @@ int drm_getunique(struct inode *inode, struct file *filp,
  * version 1.1 or greater.
  * version 1.1 or greater.
  */
  */
 int drm_setunique(struct inode *inode, struct file *filp,
 int drm_setunique(struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg)
+		  unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	 *priv	 = filp->private_data;
-	drm_device_t	 *dev	 = priv->head->dev;
-	drm_unique_t	 u;
-	int		 domain, bus, slot, func, ret;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_unique_t u;
+	int domain, bus, slot, func, ret;
 
 
-	if (dev->unique_len || dev->unique) return -EBUSY;
+	if (dev->unique_len || dev->unique)
+		return -EBUSY;
 
 
-	if (copy_from_user(&u, (drm_unique_t __user *)arg, sizeof(u)))
+	if (copy_from_user(&u, (drm_unique_t __user *) arg, sizeof(u)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	if (!u.unique_len || u.unique_len > 1024) return -EINVAL;
+	if (!u.unique_len || u.unique_len > 1024)
+		return -EINVAL;
 
 
 	dev->unique_len = u.unique_len;
 	dev->unique_len = u.unique_len;
-	dev->unique	= drm_alloc(u.unique_len + 1, DRM_MEM_DRIVER);
-	if(!dev->unique) return -ENOMEM;
+	dev->unique = drm_alloc(u.unique_len + 1, DRM_MEM_DRIVER);
+	if (!dev->unique)
+		return -ENOMEM;
 	if (copy_from_user(dev->unique, u.unique, dev->unique_len))
 	if (copy_from_user(dev->unique, u.unique, dev->unique_len))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	dev->unique[dev->unique_len] = '\0';
 	dev->unique[dev->unique_len] = '\0';
 
 
-	dev->devname = drm_alloc(strlen(dev->driver->pci_driver.name) + strlen(dev->unique) + 2,
-				  DRM_MEM_DRIVER);
+	dev->devname =
+	    drm_alloc(strlen(dev->driver->pci_driver.name) +
+		      strlen(dev->unique) + 2, DRM_MEM_DRIVER);
 	if (!dev->devname)
 	if (!dev->devname)
 		return -ENOMEM;
 		return -ENOMEM;
 
 
-	sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name, dev->unique);
+	sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
+		dev->unique);
 
 
 	/* Return error if the busid submitted doesn't match the device's actual
 	/* Return error if the busid submitted doesn't match the device's actual
 	 * busid.
 	 * busid.
@@ -121,18 +126,16 @@ int drm_setunique(struct inode *inode, struct file *filp,
 		return DRM_ERR(EINVAL);
 		return DRM_ERR(EINVAL);
 	domain = bus >> 8;
 	domain = bus >> 8;
 	bus &= 0xff;
 	bus &= 0xff;
-	
+
 	if ((domain != dev->pci_domain) ||
 	if ((domain != dev->pci_domain) ||
 	    (bus != dev->pci_bus) ||
 	    (bus != dev->pci_bus) ||
-	    (slot != dev->pci_slot) ||
-	    (func != dev->pci_func))
+	    (slot != dev->pci_slot) || (func != dev->pci_func))
 		return -EINVAL;
 		return -EINVAL;
 
 
 	return 0;
 	return 0;
 }
 }
 
 
-static int
-drm_set_busid(drm_device_t *dev)
+static int drm_set_busid(drm_device_t * dev)
 {
 {
 	if (dev->unique != NULL)
 	if (dev->unique != NULL)
 		return EBUSY;
 		return EBUSY;
@@ -143,19 +146,20 @@ drm_set_busid(drm_device_t *dev)
 		return ENOMEM;
 		return ENOMEM;
 
 
 	snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d",
 	snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d",
-		dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func);
+		 dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func);
 
 
-	dev->devname = drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len + 2,
-				DRM_MEM_DRIVER);
+	dev->devname =
+	    drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len +
+		      2, DRM_MEM_DRIVER);
 	if (dev->devname == NULL)
 	if (dev->devname == NULL)
 		return ENOMEM;
 		return ENOMEM;
 
 
-	sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name, dev->unique);
+	sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
+		dev->unique);
 
 
 	return 0;
 	return 0;
 }
 }
 
 
-
 /**
 /**
  * Get a mapping information.
  * Get a mapping information.
  *
  *
@@ -163,23 +167,23 @@ drm_set_busid(drm_device_t *dev)
  * \param filp file pointer.
  * \param filp file pointer.
  * \param cmd command.
  * \param cmd command.
  * \param arg user argument, pointing to a drm_map structure.
  * \param arg user argument, pointing to a drm_map structure.
- * 
+ *
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
  *
  *
  * Searches for the mapping with the specified offset and copies its information
  * Searches for the mapping with the specified offset and copies its information
  * into userspace
  * into userspace
  */
  */
-int drm_getmap( struct inode *inode, struct file *filp,
-		 unsigned int cmd, unsigned long arg )
+int drm_getmap(struct inode *inode, struct file *filp,
+	       unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t   *priv = filp->private_data;
-	drm_device_t *dev  = priv->head->dev;
-	drm_map_t    __user *argp = (void __user *)arg;
-	drm_map_t    map;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_map_t __user *argp = (void __user *)arg;
+	drm_map_t map;
 	drm_map_list_t *r_list = NULL;
 	drm_map_list_t *r_list = NULL;
 	struct list_head *list;
 	struct list_head *list;
-	int          idx;
-	int	     i;
+	int idx;
+	int i;
 
 
 	if (copy_from_user(&map, argp, sizeof(map)))
 	if (copy_from_user(&map, argp, sizeof(map)))
 		return -EFAULT;
 		return -EFAULT;
@@ -193,26 +197,27 @@ int drm_getmap( struct inode *inode, struct file *filp,
 
 
 	i = 0;
 	i = 0;
 	list_for_each(list, &dev->maplist->head) {
 	list_for_each(list, &dev->maplist->head) {
-		if(i == idx) {
+		if (i == idx) {
 			r_list = list_entry(list, drm_map_list_t, head);
 			r_list = list_entry(list, drm_map_list_t, head);
 			break;
 			break;
 		}
 		}
 		i++;
 		i++;
 	}
 	}
-	if(!r_list || !r_list->map) {
+	if (!r_list || !r_list->map) {
 		up(&dev->struct_sem);
 		up(&dev->struct_sem);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
 	map.offset = r_list->map->offset;
 	map.offset = r_list->map->offset;
-	map.size   = r_list->map->size;
-	map.type   = r_list->map->type;
-	map.flags  = r_list->map->flags;
-	map.handle = (void *)(unsigned long) r_list->user_token;
-	map.mtrr   = r_list->map->mtrr;
+	map.size = r_list->map->size;
+	map.type = r_list->map->type;
+	map.flags = r_list->map->flags;
+	map.handle = (void *)(unsigned long)r_list->user_token;
+	map.mtrr = r_list->map->mtrr;
 	up(&dev->struct_sem);
 	up(&dev->struct_sem);
 
 
-	if (copy_to_user(argp, &map, sizeof(map))) return -EFAULT;
+	if (copy_to_user(argp, &map, sizeof(map)))
+		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
 
 
@@ -223,83 +228,81 @@ int drm_getmap( struct inode *inode, struct file *filp,
  * \param filp file pointer.
  * \param filp file pointer.
  * \param cmd command.
  * \param cmd command.
  * \param arg user argument, pointing to a drm_client structure.
  * \param arg user argument, pointing to a drm_client structure.
- * 
+ *
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
  *
  *
  * Searches for the client with the specified index and copies its information
  * Searches for the client with the specified index and copies its information
  * into userspace
  * into userspace
  */
  */
-int drm_getclient( struct inode *inode, struct file *filp,
-		    unsigned int cmd, unsigned long arg )
+int drm_getclient(struct inode *inode, struct file *filp,
+		  unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t   *priv = filp->private_data;
-	drm_device_t *dev  = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_client_t __user *argp = (void __user *)arg;
 	drm_client_t __user *argp = (void __user *)arg;
 	drm_client_t client;
 	drm_client_t client;
-	drm_file_t   *pt;
-	int          idx;
-	int          i;
+	drm_file_t *pt;
+	int idx;
+	int i;
 
 
 	if (copy_from_user(&client, argp, sizeof(client)))
 	if (copy_from_user(&client, argp, sizeof(client)))
 		return -EFAULT;
 		return -EFAULT;
 	idx = client.idx;
 	idx = client.idx;
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
-	for (i = 0, pt = dev->file_first; i < idx && pt; i++, pt = pt->next)
-		;
+	for (i = 0, pt = dev->file_first; i < idx && pt; i++, pt = pt->next) ;
 
 
 	if (!pt) {
 	if (!pt) {
 		up(&dev->struct_sem);
 		up(&dev->struct_sem);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
-	client.auth  = pt->authenticated;
-	client.pid   = pt->pid;
-	client.uid   = pt->uid;
+	client.auth = pt->authenticated;
+	client.pid = pt->pid;
+	client.uid = pt->uid;
 	client.magic = pt->magic;
 	client.magic = pt->magic;
-	client.iocs  = pt->ioctl_count;
+	client.iocs = pt->ioctl_count;
 	up(&dev->struct_sem);
 	up(&dev->struct_sem);
 
 
-	if (copy_to_user((drm_client_t __user *)arg, &client, sizeof(client)))
+	if (copy_to_user((drm_client_t __user *) arg, &client, sizeof(client)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
 
 
-/** 
- * Get statistics information. 
- * 
+/**
+ * Get statistics information.
+ *
  * \param inode device inode.
  * \param inode device inode.
  * \param filp file pointer.
  * \param filp file pointer.
  * \param cmd command.
  * \param cmd command.
  * \param arg user argument, pointing to a drm_stats structure.
  * \param arg user argument, pointing to a drm_stats structure.
- * 
+ *
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
  */
  */
-int drm_getstats( struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg )
+int drm_getstats(struct inode *inode, struct file *filp,
+		 unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t   *priv = filp->private_data;
-	drm_device_t *dev  = priv->head->dev;
-	drm_stats_t  stats;
-	int          i;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_stats_t stats;
+	int i;
 
 
 	memset(&stats, 0, sizeof(stats));
 	memset(&stats, 0, sizeof(stats));
-	
+
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 
 
 	for (i = 0; i < dev->counters; i++) {
 	for (i = 0; i < dev->counters; i++) {
 		if (dev->types[i] == _DRM_STAT_LOCK)
 		if (dev->types[i] == _DRM_STAT_LOCK)
 			stats.data[i].value
 			stats.data[i].value
-				= (dev->lock.hw_lock
-				   ? dev->lock.hw_lock->lock : 0);
-		else 
+			    = (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0);
+		else
 			stats.data[i].value = atomic_read(&dev->counts[i]);
 			stats.data[i].value = atomic_read(&dev->counts[i]);
-		stats.data[i].type  = dev->types[i];
+		stats.data[i].type = dev->types[i];
 	}
 	}
-	
+
 	stats.count = dev->counters;
 	stats.count = dev->counters;
 
 
 	up(&dev->struct_sem);
 	up(&dev->struct_sem);
 
 
-	if (copy_to_user((drm_stats_t __user *)arg, &stats, sizeof(stats)))
+	if (copy_to_user((drm_stats_t __user *) arg, &stats, sizeof(stats)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
@@ -352,7 +355,8 @@ int drm_setversion(DRM_IOCTL_ARGS)
 
 
 	if (sv.drm_dd_major != -1) {
 	if (sv.drm_dd_major != -1) {
 		if (sv.drm_dd_major != version.version_major ||
 		if (sv.drm_dd_major != version.version_major ||
-		    sv.drm_dd_minor < 0 || sv.drm_dd_minor > version.version_minor)
+		    sv.drm_dd_minor < 0
+		    || sv.drm_dd_minor > version.version_minor)
 			return EINVAL;
 			return EINVAL;
 
 
 		if (dev->driver->set_version)
 		if (dev->driver->set_version)
@@ -363,7 +367,7 @@ int drm_setversion(DRM_IOCTL_ARGS)
 
 
 /** No-op ioctl. */
 /** No-op ioctl. */
 int drm_noop(struct inode *inode, struct file *filp, unsigned int cmd,
 int drm_noop(struct inode *inode, struct file *filp, unsigned int cmd,
-	       unsigned long arg)
+	     unsigned long arg)
 {
 {
 	DRM_DEBUG("\n");
 	DRM_DEBUG("\n");
 	return 0;
 	return 0;

+ 86 - 83
drivers/char/drm/drm_irq.c

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_irq.h 
+ * \file drm_irq.c
  * IRQ support
  * IRQ support
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -39,19 +39,19 @@
 
 
 /**
 /**
  * Get interrupt from bus id.
  * Get interrupt from bus id.
- * 
+ *
  * \param inode device inode.
  * \param inode device inode.
  * \param filp file pointer.
  * \param filp file pointer.
  * \param cmd command.
  * \param cmd command.
  * \param arg user argument, pointing to a drm_irq_busid structure.
  * \param arg user argument, pointing to a drm_irq_busid structure.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
- * 
+ *
  * Finds the PCI device with the specified bus id and gets its IRQ number.
  * Finds the PCI device with the specified bus id and gets its IRQ number.
  * This IOCTL is deprecated, and will now return EINVAL for any busid not equal
  * This IOCTL is deprecated, and will now return EINVAL for any busid not equal
  * to that of the device that this DRM instance attached to.
  * to that of the device that this DRM instance attached to.
  */
  */
 int drm_irq_by_busid(struct inode *inode, struct file *filp,
 int drm_irq_by_busid(struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg)
+		     unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -66,14 +66,12 @@ int drm_irq_by_busid(struct inode *inode, struct file *filp,
 
 
 	if ((p.busnum >> 8) != dev->pci_domain ||
 	if ((p.busnum >> 8) != dev->pci_domain ||
 	    (p.busnum & 0xff) != dev->pci_bus ||
 	    (p.busnum & 0xff) != dev->pci_bus ||
-	    p.devnum != dev->pci_slot ||
-	    p.funcnum != dev->pci_func)
+	    p.devnum != dev->pci_slot || p.funcnum != dev->pci_func)
 		return -EINVAL;
 		return -EINVAL;
 
 
 	p.irq = dev->irq;
 	p.irq = dev->irq;
 
 
-	DRM_DEBUG("%d:%d:%d => IRQ %d\n",
-		  p.busnum, p.devnum, p.funcnum, p.irq);
+	DRM_DEBUG("%d:%d:%d => IRQ %d\n", p.busnum, p.devnum, p.funcnum, p.irq);
 	if (copy_to_user(argp, &p, sizeof(p)))
 	if (copy_to_user(argp, &p, sizeof(p)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
@@ -89,61 +87,61 @@ int drm_irq_by_busid(struct inode *inode, struct file *filp,
  * \c drm_driver_irq_preinstall() and \c drm_driver_irq_postinstall() functions
  * \c drm_driver_irq_preinstall() and \c drm_driver_irq_postinstall() functions
  * before and after the installation.
  * before and after the installation.
  */
  */
-static int drm_irq_install( drm_device_t *dev )
+static int drm_irq_install(drm_device_t * dev)
 {
 {
 	int ret;
 	int ret;
-	unsigned long sh_flags=0;
+	unsigned long sh_flags = 0;
 
 
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
 		return -EINVAL;
 		return -EINVAL;
 
 
-	if ( dev->irq == 0 )
+	if (dev->irq == 0)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	down( &dev->struct_sem );
+	down(&dev->struct_sem);
 
 
 	/* Driver must have been initialized */
 	/* Driver must have been initialized */
-	if ( !dev->dev_private ) {
-		up( &dev->struct_sem );
+	if (!dev->dev_private) {
+		up(&dev->struct_sem);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	if ( dev->irq_enabled ) {
-		up( &dev->struct_sem );
+	if (dev->irq_enabled) {
+		up(&dev->struct_sem);
 		return -EBUSY;
 		return -EBUSY;
 	}
 	}
 	dev->irq_enabled = 1;
 	dev->irq_enabled = 1;
-	up( &dev->struct_sem );
+	up(&dev->struct_sem);
 
 
-	DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, dev->irq );
+	DRM_DEBUG("%s: irq=%d\n", __FUNCTION__, dev->irq);
 
 
 	if (drm_core_check_feature(dev, DRIVER_IRQ_VBL)) {
 	if (drm_core_check_feature(dev, DRIVER_IRQ_VBL)) {
 		init_waitqueue_head(&dev->vbl_queue);
 		init_waitqueue_head(&dev->vbl_queue);
-		
-		spin_lock_init( &dev->vbl_lock );
-		
-		INIT_LIST_HEAD( &dev->vbl_sigs.head );
-		
+
+		spin_lock_init(&dev->vbl_lock);
+
+		INIT_LIST_HEAD(&dev->vbl_sigs.head);
+
 		dev->vbl_pending = 0;
 		dev->vbl_pending = 0;
 	}
 	}
 
 
-				/* Before installing handler */
+	/* Before installing handler */
 	dev->driver->irq_preinstall(dev);
 	dev->driver->irq_preinstall(dev);
 
 
-				/* Install handler */
+	/* Install handler */
 	if (drm_core_check_feature(dev, DRIVER_IRQ_SHARED))
 	if (drm_core_check_feature(dev, DRIVER_IRQ_SHARED))
 		sh_flags = SA_SHIRQ;
 		sh_flags = SA_SHIRQ;
-	
-	ret = request_irq( dev->irq, dev->driver->irq_handler,
-			   sh_flags, dev->devname, dev );
-	if ( ret < 0 ) {
-		down( &dev->struct_sem );
+
+	ret = request_irq(dev->irq, dev->driver->irq_handler,
+			  sh_flags, dev->devname, dev);
+	if (ret < 0) {
+		down(&dev->struct_sem);
 		dev->irq_enabled = 0;
 		dev->irq_enabled = 0;
-		up( &dev->struct_sem );
+		up(&dev->struct_sem);
 		return ret;
 		return ret;
 	}
 	}
 
 
-				/* After installing handler */
+	/* After installing handler */
 	dev->driver->irq_postinstall(dev);
 	dev->driver->irq_postinstall(dev);
 
 
 	return 0;
 	return 0;
@@ -156,29 +154,30 @@ static int drm_irq_install( drm_device_t *dev )
  *
  *
  * Calls the driver's \c drm_driver_irq_uninstall() function, and stops the irq.
  * Calls the driver's \c drm_driver_irq_uninstall() function, and stops the irq.
  */
  */
-int drm_irq_uninstall( drm_device_t *dev )
+int drm_irq_uninstall(drm_device_t * dev)
 {
 {
 	int irq_enabled;
 	int irq_enabled;
 
 
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
 	if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
 		return -EINVAL;
 		return -EINVAL;
 
 
-	down( &dev->struct_sem );
+	down(&dev->struct_sem);
 	irq_enabled = dev->irq_enabled;
 	irq_enabled = dev->irq_enabled;
 	dev->irq_enabled = 0;
 	dev->irq_enabled = 0;
-	up( &dev->struct_sem );
+	up(&dev->struct_sem);
 
 
-	if ( !irq_enabled )
+	if (!irq_enabled)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, dev->irq );
+	DRM_DEBUG("%s: irq=%d\n", __FUNCTION__, dev->irq);
 
 
 	dev->driver->irq_uninstall(dev);
 	dev->driver->irq_uninstall(dev);
 
 
-	free_irq( dev->irq, dev );
+	free_irq(dev->irq, dev);
 
 
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_irq_uninstall);
 EXPORT_SYMBOL(drm_irq_uninstall);
 
 
 /**
 /**
@@ -192,30 +191,30 @@ EXPORT_SYMBOL(drm_irq_uninstall);
  *
  *
  * Calls irq_install() or irq_uninstall() according to \p arg.
  * Calls irq_install() or irq_uninstall() according to \p arg.
  */
  */
-int drm_control( struct inode *inode, struct file *filp,
-		  unsigned int cmd, unsigned long arg )
+int drm_control(struct inode *inode, struct file *filp,
+		unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_control_t ctl;
 	drm_control_t ctl;
-	
+
 	/* if we haven't irq we fallback for compatibility reasons - this used to be a separate function in drm_dma.h */
 	/* if we haven't irq we fallback for compatibility reasons - this used to be a separate function in drm_dma.h */
 
 
-	if ( copy_from_user( &ctl, (drm_control_t __user *)arg, sizeof(ctl) ) )
+	if (copy_from_user(&ctl, (drm_control_t __user *) arg, sizeof(ctl)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	switch ( ctl.func ) {
+	switch (ctl.func) {
 	case DRM_INST_HANDLER:
 	case DRM_INST_HANDLER:
 		if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
 		if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
 			return 0;
 			return 0;
 		if (dev->if_version < DRM_IF_VERSION(1, 2) &&
 		if (dev->if_version < DRM_IF_VERSION(1, 2) &&
 		    ctl.irq != dev->irq)
 		    ctl.irq != dev->irq)
 			return -EINVAL;
 			return -EINVAL;
-		return drm_irq_install( dev );
+		return drm_irq_install(dev);
 	case DRM_UNINST_HANDLER:
 	case DRM_UNINST_HANDLER:
 		if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
 		if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
 			return 0;
 			return 0;
-		return drm_irq_uninstall( dev );
+		return drm_irq_uninstall(dev);
 	default:
 	default:
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
@@ -230,7 +229,7 @@ int drm_control( struct inode *inode, struct file *filp,
  * \param data user argument, pointing to a drm_wait_vblank structure.
  * \param data user argument, pointing to a drm_wait_vblank structure.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
  *
  *
- * Verifies the IRQ is installed. 
+ * Verifies the IRQ is installed.
  *
  *
  * If a signal is requested checks if this task has already scheduled the same signal
  * If a signal is requested checks if this task has already scheduled the same signal
  * for the same vblank sequence number - nothing to be done in
  * for the same vblank sequence number - nothing to be done in
@@ -240,7 +239,7 @@ int drm_control( struct inode *inode, struct file *filp,
  *
  *
  * If a signal is not requested, then calls vblank_wait().
  * If a signal is not requested, then calls vblank_wait().
  */
  */
-int drm_wait_vblank( DRM_IOCTL_ARGS )
+int drm_wait_vblank(DRM_IOCTL_ARGS)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -256,11 +255,11 @@ int drm_wait_vblank( DRM_IOCTL_ARGS )
 	if (!dev->irq)
 	if (!dev->irq)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	DRM_COPY_FROM_USER_IOCTL( vblwait, argp, sizeof(vblwait) );
+	DRM_COPY_FROM_USER_IOCTL(vblwait, argp, sizeof(vblwait));
 
 
-	switch ( vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK ) {
+	switch (vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK) {
 	case _DRM_VBLANK_RELATIVE:
 	case _DRM_VBLANK_RELATIVE:
-		vblwait.request.sequence += atomic_read( &dev->vbl_received );
+		vblwait.request.sequence += atomic_read(&dev->vbl_received);
 		vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
 		vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
 	case _DRM_VBLANK_ABSOLUTE:
 	case _DRM_VBLANK_ABSOLUTE:
 		break;
 		break;
@@ -269,64 +268,68 @@ int drm_wait_vblank( DRM_IOCTL_ARGS )
 	}
 	}
 
 
 	flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
 	flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
-	
-	if ( flags & _DRM_VBLANK_SIGNAL ) {
+
+	if (flags & _DRM_VBLANK_SIGNAL) {
 		unsigned long irqflags;
 		unsigned long irqflags;
 		drm_vbl_sig_t *vbl_sig;
 		drm_vbl_sig_t *vbl_sig;
-		
-		vblwait.reply.sequence = atomic_read( &dev->vbl_received );
 
 
-		spin_lock_irqsave( &dev->vbl_lock, irqflags );
+		vblwait.reply.sequence = atomic_read(&dev->vbl_received);
+
+		spin_lock_irqsave(&dev->vbl_lock, irqflags);
 
 
 		/* Check if this task has already scheduled the same signal
 		/* Check if this task has already scheduled the same signal
 		 * for the same vblank sequence number; nothing to be done in
 		 * for the same vblank sequence number; nothing to be done in
 		 * that case
 		 * that case
 		 */
 		 */
-		list_for_each_entry( vbl_sig, &dev->vbl_sigs.head, head ) {
+		list_for_each_entry(vbl_sig, &dev->vbl_sigs.head, head) {
 			if (vbl_sig->sequence == vblwait.request.sequence
 			if (vbl_sig->sequence == vblwait.request.sequence
 			    && vbl_sig->info.si_signo == vblwait.request.signal
 			    && vbl_sig->info.si_signo == vblwait.request.signal
-			    && vbl_sig->task == current)
-			{
-				spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+			    && vbl_sig->task == current) {
+				spin_unlock_irqrestore(&dev->vbl_lock,
+						       irqflags);
 				goto done;
 				goto done;
 			}
 			}
 		}
 		}
 
 
-		if ( dev->vbl_pending >= 100 ) {
-			spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+		if (dev->vbl_pending >= 100) {
+			spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
 			return -EBUSY;
 			return -EBUSY;
 		}
 		}
 
 
 		dev->vbl_pending++;
 		dev->vbl_pending++;
 
 
-		spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+		spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
 
 
-		if ( !( vbl_sig = drm_alloc( sizeof( drm_vbl_sig_t ), DRM_MEM_DRIVER ) ) ) {
+		if (!
+		    (vbl_sig =
+		     drm_alloc(sizeof(drm_vbl_sig_t), DRM_MEM_DRIVER))) {
 			return -ENOMEM;
 			return -ENOMEM;
 		}
 		}
 
 
-		memset( (void *)vbl_sig, 0, sizeof(*vbl_sig) );
+		memset((void *)vbl_sig, 0, sizeof(*vbl_sig));
 
 
 		vbl_sig->sequence = vblwait.request.sequence;
 		vbl_sig->sequence = vblwait.request.sequence;
 		vbl_sig->info.si_signo = vblwait.request.signal;
 		vbl_sig->info.si_signo = vblwait.request.signal;
 		vbl_sig->task = current;
 		vbl_sig->task = current;
 
 
-		spin_lock_irqsave( &dev->vbl_lock, irqflags );
+		spin_lock_irqsave(&dev->vbl_lock, irqflags);
 
 
-		list_add_tail( (struct list_head *) vbl_sig, &dev->vbl_sigs.head );
+		list_add_tail((struct list_head *)vbl_sig, &dev->vbl_sigs.head);
 
 
-		spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+		spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
 	} else {
 	} else {
 		if (dev->driver->vblank_wait)
 		if (dev->driver->vblank_wait)
-			ret = dev->driver->vblank_wait( dev, &vblwait.request.sequence );
+			ret =
+			    dev->driver->vblank_wait(dev,
+						     &vblwait.request.sequence);
 
 
-		do_gettimeofday( &now );
+		do_gettimeofday(&now);
 		vblwait.reply.tval_sec = now.tv_sec;
 		vblwait.reply.tval_sec = now.tv_sec;
 		vblwait.reply.tval_usec = now.tv_usec;
 		vblwait.reply.tval_usec = now.tv_usec;
 	}
 	}
 
 
-done:
-	DRM_COPY_TO_USER_IOCTL( argp, vblwait, sizeof(vblwait) );
+      done:
+	DRM_COPY_TO_USER_IOCTL(argp, vblwait, sizeof(vblwait));
 
 
 	return ret;
 	return ret;
 }
 }
@@ -340,31 +343,31 @@ done:
  *
  *
  * If a signal is not requested, then calls vblank_wait().
  * If a signal is not requested, then calls vblank_wait().
  */
  */
-void drm_vbl_send_signals( drm_device_t *dev )
+void drm_vbl_send_signals(drm_device_t * dev)
 {
 {
 	struct list_head *list, *tmp;
 	struct list_head *list, *tmp;
 	drm_vbl_sig_t *vbl_sig;
 	drm_vbl_sig_t *vbl_sig;
-	unsigned int vbl_seq = atomic_read( &dev->vbl_received );
+	unsigned int vbl_seq = atomic_read(&dev->vbl_received);
 	unsigned long flags;
 	unsigned long flags;
 
 
-	spin_lock_irqsave( &dev->vbl_lock, flags );
+	spin_lock_irqsave(&dev->vbl_lock, flags);
 
 
-	list_for_each_safe( list, tmp, &dev->vbl_sigs.head ) {
-		vbl_sig = list_entry( list, drm_vbl_sig_t, head );
-		if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
+	list_for_each_safe(list, tmp, &dev->vbl_sigs.head) {
+		vbl_sig = list_entry(list, drm_vbl_sig_t, head);
+		if ((vbl_seq - vbl_sig->sequence) <= (1 << 23)) {
 			vbl_sig->info.si_code = vbl_seq;
 			vbl_sig->info.si_code = vbl_seq;
-			send_sig_info( vbl_sig->info.si_signo, &vbl_sig->info, vbl_sig->task );
+			send_sig_info(vbl_sig->info.si_signo, &vbl_sig->info,
+				      vbl_sig->task);
 
 
-			list_del( list );
+			list_del(list);
 
 
-			drm_free( vbl_sig, sizeof(*vbl_sig), DRM_MEM_DRIVER );
+			drm_free(vbl_sig, sizeof(*vbl_sig), DRM_MEM_DRIVER);
 
 
 			dev->vbl_pending--;
 			dev->vbl_pending--;
 		}
 		}
 	}
 	}
 
 
-	spin_unlock_irqrestore( &dev->vbl_lock, flags );
+	spin_unlock_irqrestore(&dev->vbl_lock, flags);
 }
 }
-EXPORT_SYMBOL(drm_vbl_send_signals);
-
 
 
+EXPORT_SYMBOL(drm_vbl_send_signals);

+ 88 - 89
drivers/char/drm/drm_lock.c

@@ -1,7 +1,7 @@
 /**
 /**
- * \file drm_lock.h 
+ * \file drm_lock.c
  * IOCTLs for locking
  * IOCTLs for locking
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
  */
@@ -35,12 +35,12 @@
 
 
 #include "drmP.h"
 #include "drmP.h"
 
 
-static int drm_lock_transfer(drm_device_t *dev,
+static int drm_lock_transfer(drm_device_t * dev,
 			     __volatile__ unsigned int *lock,
 			     __volatile__ unsigned int *lock,
 			     unsigned int context);
 			     unsigned int context);
 static int drm_notifier(void *priv);
 static int drm_notifier(void *priv);
 
 
-/** 
+/**
  * Lock ioctl.
  * Lock ioctl.
  *
  *
  * \param inode device inode.
  * \param inode device inode.
@@ -51,91 +51,89 @@ static int drm_notifier(void *priv);
  *
  *
  * Add the current task to the lock wait queue, and attempt to take to lock.
  * Add the current task to the lock wait queue, and attempt to take to lock.
  */
  */
-int drm_lock( struct inode *inode, struct file *filp,
-	       unsigned int cmd, unsigned long arg )
+int drm_lock(struct inode *inode, struct file *filp,
+	     unsigned int cmd, unsigned long arg)
 {
 {
-        drm_file_t *priv = filp->private_data;
-        drm_device_t *dev = priv->head->dev;
-        DECLARE_WAITQUEUE( entry, current );
-        drm_lock_t lock;
-        int ret = 0;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	DECLARE_WAITQUEUE(entry, current);
+	drm_lock_t lock;
+	int ret = 0;
 
 
 	++priv->lock_count;
 	++priv->lock_count;
 
 
-        if ( copy_from_user( &lock, (drm_lock_t __user *)arg, sizeof(lock) ) )
+	if (copy_from_user(&lock, (drm_lock_t __user *) arg, sizeof(lock)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-        if ( lock.context == DRM_KERNEL_CONTEXT ) {
-                DRM_ERROR( "Process %d using kernel context %d\n",
-			   current->pid, lock.context );
-                return -EINVAL;
-        }
+	if (lock.context == DRM_KERNEL_CONTEXT) {
+		DRM_ERROR("Process %d using kernel context %d\n",
+			  current->pid, lock.context);
+		return -EINVAL;
+	}
 
 
-        DRM_DEBUG( "%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
-		   lock.context, current->pid,
-		   dev->lock.hw_lock->lock, lock.flags );
+	DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
+		  lock.context, current->pid,
+		  dev->lock.hw_lock->lock, lock.flags);
 
 
 	if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE))
 	if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE))
-		if ( lock.context < 0 )
+		if (lock.context < 0)
 			return -EINVAL;
 			return -EINVAL;
 
 
-	add_wait_queue( &dev->lock.lock_queue, &entry );
+	add_wait_queue(&dev->lock.lock_queue, &entry);
 	for (;;) {
 	for (;;) {
 		__set_current_state(TASK_INTERRUPTIBLE);
 		__set_current_state(TASK_INTERRUPTIBLE);
-		if ( !dev->lock.hw_lock ) {
+		if (!dev->lock.hw_lock) {
 			/* Device has been unregistered */
 			/* Device has been unregistered */
 			ret = -EINTR;
 			ret = -EINTR;
 			break;
 			break;
 		}
 		}
-		if ( drm_lock_take( &dev->lock.hw_lock->lock,
-				     lock.context ) ) {
-			dev->lock.filp      = filp;
+		if (drm_lock_take(&dev->lock.hw_lock->lock, lock.context)) {
+			dev->lock.filp = filp;
 			dev->lock.lock_time = jiffies;
 			dev->lock.lock_time = jiffies;
-			atomic_inc( &dev->counts[_DRM_STAT_LOCKS] );
-			break;  /* Got lock */
+			atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
+			break;	/* Got lock */
 		}
 		}
-		
+
 		/* Contention */
 		/* Contention */
 		schedule();
 		schedule();
-		if ( signal_pending( current ) ) {
+		if (signal_pending(current)) {
 			ret = -ERESTARTSYS;
 			ret = -ERESTARTSYS;
 			break;
 			break;
 		}
 		}
 	}
 	}
 	__set_current_state(TASK_RUNNING);
 	__set_current_state(TASK_RUNNING);
-	remove_wait_queue( &dev->lock.lock_queue, &entry );
+	remove_wait_queue(&dev->lock.lock_queue, &entry);
 
 
-	sigemptyset( &dev->sigmask );
-	sigaddset( &dev->sigmask, SIGSTOP );
-	sigaddset( &dev->sigmask, SIGTSTP );
-	sigaddset( &dev->sigmask, SIGTTIN );
-	sigaddset( &dev->sigmask, SIGTTOU );
+	sigemptyset(&dev->sigmask);
+	sigaddset(&dev->sigmask, SIGSTOP);
+	sigaddset(&dev->sigmask, SIGTSTP);
+	sigaddset(&dev->sigmask, SIGTTIN);
+	sigaddset(&dev->sigmask, SIGTTOU);
 	dev->sigdata.context = lock.context;
 	dev->sigdata.context = lock.context;
-	dev->sigdata.lock    = dev->lock.hw_lock;
-	block_all_signals( drm_notifier,
-			   &dev->sigdata, &dev->sigmask );
-	
+	dev->sigdata.lock = dev->lock.hw_lock;
+	block_all_signals(drm_notifier, &dev->sigdata, &dev->sigmask);
+
 	if (dev->driver->dma_ready && (lock.flags & _DRM_LOCK_READY))
 	if (dev->driver->dma_ready && (lock.flags & _DRM_LOCK_READY))
 		dev->driver->dma_ready(dev);
 		dev->driver->dma_ready(dev);
-	
-	if ( dev->driver->dma_quiescent && (lock.flags & _DRM_LOCK_QUIESCENT ))
+
+	if (dev->driver->dma_quiescent && (lock.flags & _DRM_LOCK_QUIESCENT))
 		return dev->driver->dma_quiescent(dev);
 		return dev->driver->dma_quiescent(dev);
-	
-	/* dev->driver->kernel_context_switch isn't used by any of the x86 
+
+	/* dev->driver->kernel_context_switch isn't used by any of the x86
 	 *  drivers but is used by the Sparc driver.
 	 *  drivers but is used by the Sparc driver.
 	 */
 	 */
-	
-	if (dev->driver->kernel_context_switch && 
+
+	if (dev->driver->kernel_context_switch &&
 	    dev->last_context != lock.context) {
 	    dev->last_context != lock.context) {
-	  dev->driver->kernel_context_switch(dev, dev->last_context, 
-					    lock.context);
+		dev->driver->kernel_context_switch(dev, dev->last_context,
+						   lock.context);
 	}
 	}
-        DRM_DEBUG( "%d %s\n", lock.context, ret ? "interrupted" : "has lock" );
+	DRM_DEBUG("%d %s\n", lock.context, ret ? "interrupted" : "has lock");
 
 
-        return ret;
+	return ret;
 }
 }
 
 
-/** 
+/**
  * Unlock ioctl.
  * Unlock ioctl.
  *
  *
  * \param inode device inode.
  * \param inode device inode.
@@ -146,23 +144,23 @@ int drm_lock( struct inode *inode, struct file *filp,
  *
  *
  * Transfer and free the lock.
  * Transfer and free the lock.
  */
  */
-int drm_unlock( struct inode *inode, struct file *filp,
-		 unsigned int cmd, unsigned long arg )
+int drm_unlock(struct inode *inode, struct file *filp,
+	       unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_lock_t lock;
 	drm_lock_t lock;
 
 
-	if ( copy_from_user( &lock, (drm_lock_t __user *)arg, sizeof(lock) ) )
+	if (copy_from_user(&lock, (drm_lock_t __user *) arg, sizeof(lock)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	if ( lock.context == DRM_KERNEL_CONTEXT ) {
-		DRM_ERROR( "Process %d using kernel context %d\n",
-			   current->pid, lock.context );
+	if (lock.context == DRM_KERNEL_CONTEXT) {
+		DRM_ERROR("Process %d using kernel context %d\n",
+			  current->pid, lock.context);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	atomic_inc( &dev->counts[_DRM_STAT_UNLOCKS] );
+	atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
 
 
 	/* kernel_context_switch isn't used by any of the x86 drm
 	/* kernel_context_switch isn't used by any of the x86 drm
 	 * modules but is required by the Sparc driver.
 	 * modules but is required by the Sparc driver.
@@ -170,12 +168,12 @@ int drm_unlock( struct inode *inode, struct file *filp,
 	if (dev->driver->kernel_context_switch_unlock)
 	if (dev->driver->kernel_context_switch_unlock)
 		dev->driver->kernel_context_switch_unlock(dev, &lock);
 		dev->driver->kernel_context_switch_unlock(dev, &lock);
 	else {
 	else {
-		drm_lock_transfer( dev, &dev->lock.hw_lock->lock, 
-				    DRM_KERNEL_CONTEXT );
-		
-		if ( drm_lock_free( dev, &dev->lock.hw_lock->lock,
-				     DRM_KERNEL_CONTEXT ) ) {
-			DRM_ERROR( "\n" );
+		drm_lock_transfer(dev, &dev->lock.hw_lock->lock,
+				  DRM_KERNEL_CONTEXT);
+
+		if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
+				  DRM_KERNEL_CONTEXT)) {
+			DRM_ERROR("\n");
 		}
 		}
 	}
 	}
 
 
@@ -198,8 +196,10 @@ int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context)
 
 
 	do {
 	do {
 		old = *lock;
 		old = *lock;
-		if (old & _DRM_LOCK_HELD) new = old | _DRM_LOCK_CONT;
-		else			  new = context | _DRM_LOCK_HELD;
+		if (old & _DRM_LOCK_HELD)
+			new = old | _DRM_LOCK_CONT;
+		else
+			new = context | _DRM_LOCK_HELD;
 		prev = cmpxchg(lock, old, new);
 		prev = cmpxchg(lock, old, new);
 	} while (prev != old);
 	} while (prev != old);
 	if (_DRM_LOCKING_CONTEXT(old) == context) {
 	if (_DRM_LOCKING_CONTEXT(old) == context) {
@@ -212,7 +212,7 @@ int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context)
 		}
 		}
 	}
 	}
 	if (new == (context | _DRM_LOCK_HELD)) {
 	if (new == (context | _DRM_LOCK_HELD)) {
-				/* Have lock */
+		/* Have lock */
 		return 1;
 		return 1;
 	}
 	}
 	return 0;
 	return 0;
@@ -220,8 +220,8 @@ int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context)
 
 
 /**
 /**
  * This takes a lock forcibly and hands it to context.	Should ONLY be used
  * This takes a lock forcibly and hands it to context.	Should ONLY be used
- * inside *_unlock to give lock to kernel before calling *_dma_schedule. 
- * 
+ * inside *_unlock to give lock to kernel before calling *_dma_schedule.
+ *
  * \param dev DRM device.
  * \param dev DRM device.
  * \param lock lock pointer.
  * \param lock lock pointer.
  * \param context locking context.
  * \param context locking context.
@@ -230,7 +230,7 @@ int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context)
  * Resets the lock file pointer.
  * Resets the lock file pointer.
  * Marks the lock as held by the given context, via the \p cmpxchg instruction.
  * Marks the lock as held by the given context, via the \p cmpxchg instruction.
  */
  */
-static int drm_lock_transfer(drm_device_t *dev,
+static int drm_lock_transfer(drm_device_t * dev,
 			     __volatile__ unsigned int *lock,
 			     __volatile__ unsigned int *lock,
 			     unsigned int context)
 			     unsigned int context)
 {
 {
@@ -238,8 +238,8 @@ static int drm_lock_transfer(drm_device_t *dev,
 
 
 	dev->lock.filp = NULL;
 	dev->lock.filp = NULL;
 	do {
 	do {
-		old  = *lock;
-		new  = context | _DRM_LOCK_HELD;
+		old = *lock;
+		new = context | _DRM_LOCK_HELD;
 		prev = cmpxchg(lock, old, new);
 		prev = cmpxchg(lock, old, new);
 	} while (prev != old);
 	} while (prev != old);
 	return 1;
 	return 1;
@@ -247,30 +247,29 @@ static int drm_lock_transfer(drm_device_t *dev,
 
 
 /**
 /**
  * Free lock.
  * Free lock.
- * 
+ *
  * \param dev DRM device.
  * \param dev DRM device.
  * \param lock lock.
  * \param lock lock.
  * \param context context.
  * \param context context.
- * 
+ *
  * Resets the lock file pointer.
  * Resets the lock file pointer.
  * Marks the lock as not held, via the \p cmpxchg instruction. Wakes any task
  * Marks the lock as not held, via the \p cmpxchg instruction. Wakes any task
  * waiting on the lock queue.
  * waiting on the lock queue.
  */
  */
-int drm_lock_free(drm_device_t *dev,
-		   __volatile__ unsigned int *lock, unsigned int context)
+int drm_lock_free(drm_device_t * dev,
+		  __volatile__ unsigned int *lock, unsigned int context)
 {
 {
 	unsigned int old, new, prev;
 	unsigned int old, new, prev;
 
 
 	dev->lock.filp = NULL;
 	dev->lock.filp = NULL;
 	do {
 	do {
-		old  = *lock;
-		new  = 0;
+		old = *lock;
+		new = 0;
 		prev = cmpxchg(lock, old, new);
 		prev = cmpxchg(lock, old, new);
 	} while (prev != old);
 	} while (prev != old);
 	if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
 	if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
 		DRM_ERROR("%d freed heavyweight lock held by %d\n",
 		DRM_ERROR("%d freed heavyweight lock held by %d\n",
-			  context,
-			  _DRM_LOCKING_CONTEXT(old));
+			  context, _DRM_LOCKING_CONTEXT(old));
 		return 1;
 		return 1;
 	}
 	}
 	wake_up_interruptible(&dev->lock.lock_queue);
 	wake_up_interruptible(&dev->lock.lock_queue);
@@ -290,19 +289,19 @@ int drm_lock_free(drm_device_t *dev,
  */
  */
 static int drm_notifier(void *priv)
 static int drm_notifier(void *priv)
 {
 {
-	drm_sigdata_t *s = (drm_sigdata_t *)priv;
-	unsigned int  old, new, prev;
-
+	drm_sigdata_t *s = (drm_sigdata_t *) priv;
+	unsigned int old, new, prev;
 
 
-				/* Allow signal delivery if lock isn't held */
+	/* Allow signal delivery if lock isn't held */
 	if (!s->lock || !_DRM_LOCK_IS_HELD(s->lock->lock)
 	if (!s->lock || !_DRM_LOCK_IS_HELD(s->lock->lock)
-	    || _DRM_LOCKING_CONTEXT(s->lock->lock) != s->context) return 1;
+	    || _DRM_LOCKING_CONTEXT(s->lock->lock) != s->context)
+		return 1;
 
 
-				/* Otherwise, set flag to force call to
-                                   drmUnlock */
+	/* Otherwise, set flag to force call to
+	   drmUnlock */
 	do {
 	do {
-		old  = s->lock->lock;
-		new  = old | _DRM_LOCK_CONT;
+		old = s->lock->lock;
+		new = old | _DRM_LOCK_CONT;
 		prev = cmpxchg(&s->lock->lock, old, new);
 		prev = cmpxchg(&s->lock->lock, old, new);
 	} while (prev != old);
 	} while (prev != old);
 	return 0;
 	return 0;

+ 28 - 26
drivers/char/drm/drm_memory.c

@@ -1,12 +1,12 @@
-/** 
- * \file drm_memory.h 
+/**
+ * \file drm_memory.c
  * Memory management wrappers for DRM
  * Memory management wrappers for DRM
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
  */
 
 
-/* 
+/*
  * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
  * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
  *
  *
  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
@@ -48,7 +48,7 @@ void drm_mem_init(void)
 
 
 /**
 /**
  * Called when "/proc/dri/%dev%/mem" is read.
  * Called when "/proc/dri/%dev%/mem" is read.
- * 
+ *
  * \param buf output buffer.
  * \param buf output buffer.
  * \param start start of output data.
  * \param start start of output data.
  * \param offset requested start offset.
  * \param offset requested start offset.
@@ -57,10 +57,10 @@ void drm_mem_init(void)
  * \param data private data.
  * \param data private data.
  * \return number of written bytes.
  * \return number of written bytes.
  *
  *
- * No-op. 
+ * No-op.
  */
  */
 int drm_mem_info(char *buf, char **start, off_t offset,
 int drm_mem_info(char *buf, char **start, off_t offset,
-		  int len, int *eof, void *data)
+		 int len, int *eof, void *data)
 {
 {
 	return 0;
 	return 0;
 }
 }
@@ -70,7 +70,8 @@ void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
 {
 {
 	void *pt;
 	void *pt;
 
 
-	if (!(pt = kmalloc(size, GFP_KERNEL))) return NULL;
+	if (!(pt = kmalloc(size, GFP_KERNEL)))
+		return NULL;
 	if (oldpt && oldsize) {
 	if (oldpt && oldsize) {
 		memcpy(pt, oldpt, oldsize);
 		memcpy(pt, oldpt, oldsize);
 		kfree(oldpt);
 		kfree(oldpt);
@@ -90,21 +91,20 @@ void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
 unsigned long drm_alloc_pages(int order, int area)
 unsigned long drm_alloc_pages(int order, int area)
 {
 {
 	unsigned long address;
 	unsigned long address;
-	unsigned long bytes	  = PAGE_SIZE << order;
+	unsigned long bytes = PAGE_SIZE << order;
 	unsigned long addr;
 	unsigned long addr;
-	unsigned int  sz;
+	unsigned int sz;
 
 
 	address = __get_free_pages(GFP_KERNEL, order);
 	address = __get_free_pages(GFP_KERNEL, order);
-	if (!address) 
+	if (!address)
 		return 0;
 		return 0;
 
 
-				/* Zero */
+	/* Zero */
 	memset((void *)address, 0, bytes);
 	memset((void *)address, 0, bytes);
 
 
-				/* Reserve */
+	/* Reserve */
 	for (addr = address, sz = bytes;
 	for (addr = address, sz = bytes;
-	     sz > 0;
-	     addr += PAGE_SIZE, sz -= PAGE_SIZE) {
+	     sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
 		SetPageReserved(virt_to_page(addr));
 		SetPageReserved(virt_to_page(addr));
 	}
 	}
 
 
@@ -113,7 +113,7 @@ unsigned long drm_alloc_pages(int order, int area)
 
 
 /**
 /**
  * Free pages.
  * Free pages.
- * 
+ *
  * \param address address of the pages to free.
  * \param address address of the pages to free.
  * \param order size order.
  * \param order size order.
  * \param area memory area. (Not used.)
  * \param area memory area. (Not used.)
@@ -124,49 +124,51 @@ void drm_free_pages(unsigned long address, int order, int area)
 {
 {
 	unsigned long bytes = PAGE_SIZE << order;
 	unsigned long bytes = PAGE_SIZE << order;
 	unsigned long addr;
 	unsigned long addr;
-	unsigned int  sz;
+	unsigned int sz;
 
 
-	if (!address) 
+	if (!address)
 		return;
 		return;
 
 
 	/* Unreserve */
 	/* Unreserve */
 	for (addr = address, sz = bytes;
 	for (addr = address, sz = bytes;
-	     sz > 0;
-	     addr += PAGE_SIZE, sz -= PAGE_SIZE) {
+	     sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
 		ClearPageReserved(virt_to_page(addr));
 		ClearPageReserved(virt_to_page(addr));
 	}
 	}
 
 
 	free_pages(address, order);
 	free_pages(address, order);
 }
 }
 
 
-
 #if __OS_HAS_AGP
 #if __OS_HAS_AGP
 /** Wrapper around agp_allocate_memory() */
 /** Wrapper around agp_allocate_memory() */
-DRM_AGP_MEM *drm_alloc_agp(drm_device_t *dev, int pages, u32 type)
+DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type)
 {
 {
 	return drm_agp_allocate_memory(dev->agp->bridge, pages, type);
 	return drm_agp_allocate_memory(dev->agp->bridge, pages, type);
 }
 }
+
 EXPORT_SYMBOL(drm_alloc_agp);
 EXPORT_SYMBOL(drm_alloc_agp);
 
 
 /** Wrapper around agp_free_memory() */
 /** Wrapper around agp_free_memory() */
-int drm_free_agp(DRM_AGP_MEM *handle, int pages)
+int drm_free_agp(DRM_AGP_MEM * handle, int pages)
 {
 {
 	return drm_agp_free_memory(handle) ? 0 : -EINVAL;
 	return drm_agp_free_memory(handle) ? 0 : -EINVAL;
 }
 }
+
 EXPORT_SYMBOL(drm_free_agp);
 EXPORT_SYMBOL(drm_free_agp);
 
 
 /** Wrapper around agp_bind_memory() */
 /** Wrapper around agp_bind_memory() */
-int drm_bind_agp(DRM_AGP_MEM *handle, unsigned int start)
+int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
 {
 {
 	return drm_agp_bind_memory(handle, start);
 	return drm_agp_bind_memory(handle, start);
 }
 }
+
 EXPORT_SYMBOL(drm_bind_agp);
 EXPORT_SYMBOL(drm_bind_agp);
 
 
 /** Wrapper around agp_unbind_memory() */
 /** Wrapper around agp_unbind_memory() */
-int drm_unbind_agp(DRM_AGP_MEM *handle)
+int drm_unbind_agp(DRM_AGP_MEM * handle)
 {
 {
 	return drm_agp_unbind_memory(handle);
 	return drm_agp_unbind_memory(handle);
 }
 }
+
 EXPORT_SYMBOL(drm_unbind_agp);
 EXPORT_SYMBOL(drm_unbind_agp);
-#endif /* agp */
-#endif /* debug_memory */
+#endif				/* agp */
+#endif				/* debug_memory */

+ 39 - 34
drivers/char/drm/drm_memory.h

@@ -1,12 +1,12 @@
-/** 
- * \file drm_memory.h 
+/**
+ * \file drm_memory.h
  * Memory management wrappers for DRM
  * Memory management wrappers for DRM
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
  */
 
 
-/* 
+/*
  * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
  * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
  *
  *
  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
@@ -40,7 +40,7 @@
 
 
 /**
 /**
  * Cut down version of drm_memory_debug.h, which used to be called
  * Cut down version of drm_memory_debug.h, which used to be called
- * drm_memory.h.  
+ * drm_memory.h.
  */
  */
 
 
 #if __OS_HAS_AGP
 #if __OS_HAS_AGP
@@ -60,8 +60,8 @@
 /*
 /*
  * Find the drm_map that covers the range [offset, offset+size).
  * Find the drm_map that covers the range [offset, offset+size).
  */
  */
-static inline drm_map_t *
-drm_lookup_map (unsigned long offset, unsigned long size, drm_device_t *dev)
+static inline drm_map_t *drm_lookup_map(unsigned long offset,
+					unsigned long size, drm_device_t * dev)
 {
 {
 	struct list_head *list;
 	struct list_head *list;
 	drm_map_list_t *r_list;
 	drm_map_list_t *r_list;
@@ -72,16 +72,18 @@ drm_lookup_map (unsigned long offset, unsigned long size, drm_device_t *dev)
 		map = r_list->map;
 		map = r_list->map;
 		if (!map)
 		if (!map)
 			continue;
 			continue;
-		if (map->offset <= offset && (offset + size) <= (map->offset + map->size))
+		if (map->offset <= offset
+		    && (offset + size) <= (map->offset + map->size))
 			return map;
 			return map;
 	}
 	}
 	return NULL;
 	return NULL;
 }
 }
 
 
-static inline void *
-agp_remap (unsigned long offset, unsigned long size, drm_device_t *dev)
+static inline void *agp_remap(unsigned long offset, unsigned long size,
+			      drm_device_t * dev)
 {
 {
-	unsigned long *phys_addr_map, i, num_pages = PAGE_ALIGN(size) / PAGE_SIZE;
+	unsigned long *phys_addr_map, i, num_pages =
+	    PAGE_ALIGN(size) / PAGE_SIZE;
 	struct drm_agp_mem *agpmem;
 	struct drm_agp_mem *agpmem;
 	struct page **page_map;
 	struct page **page_map;
 	void *addr;
 	void *addr;
@@ -94,7 +96,8 @@ agp_remap (unsigned long offset, unsigned long size, drm_device_t *dev)
 
 
 	for (agpmem = dev->agp->memory; agpmem; agpmem = agpmem->next)
 	for (agpmem = dev->agp->memory; agpmem; agpmem = agpmem->next)
 		if (agpmem->bound <= offset
 		if (agpmem->bound <= offset
-		    && (agpmem->bound + (agpmem->pages << PAGE_SHIFT)) >= (offset + size))
+		    && (agpmem->bound + (agpmem->pages << PAGE_SHIFT)) >=
+		    (offset + size))
 			break;
 			break;
 	if (!agpmem)
 	if (!agpmem)
 		return NULL;
 		return NULL;
@@ -109,7 +112,8 @@ agp_remap (unsigned long offset, unsigned long size, drm_device_t *dev)
 	if (!page_map)
 	if (!page_map)
 		return NULL;
 		return NULL;
 
 
-	phys_addr_map = agpmem->memory->memory + (offset - agpmem->bound) / PAGE_SIZE;
+	phys_addr_map =
+	    agpmem->memory->memory + (offset - agpmem->bound) / PAGE_SIZE;
 	for (i = 0; i < num_pages; ++i)
 	for (i = 0; i < num_pages; ++i)
 		page_map[i] = pfn_to_page(phys_addr_map[i] >> PAGE_SHIFT);
 		page_map[i] = pfn_to_page(phys_addr_map[i] >> PAGE_SHIFT);
 	addr = vmap(page_map, num_pages, VM_IOREMAP, PAGE_AGP);
 	addr = vmap(page_map, num_pages, VM_IOREMAP, PAGE_AGP);
@@ -118,36 +122,38 @@ agp_remap (unsigned long offset, unsigned long size, drm_device_t *dev)
 	return addr;
 	return addr;
 }
 }
 
 
-static inline unsigned long
-drm_follow_page (void *vaddr)
+static inline unsigned long drm_follow_page(void *vaddr)
 {
 {
-	pgd_t *pgd = pgd_offset_k((unsigned long) vaddr);
-	pud_t *pud = pud_offset(pgd, (unsigned long) vaddr);
-	pmd_t *pmd = pmd_offset(pud, (unsigned long) vaddr);
-	pte_t *ptep = pte_offset_kernel(pmd, (unsigned long) vaddr);
+	pgd_t *pgd = pgd_offset_k((unsigned long)vaddr);
+	pud_t *pud = pud_offset(pgd, (unsigned long)vaddr);
+	pmd_t *pmd = pmd_offset(pud, (unsigned long)vaddr);
+	pte_t *ptep = pte_offset_kernel(pmd, (unsigned long)vaddr);
 	return pte_pfn(*ptep) << PAGE_SHIFT;
 	return pte_pfn(*ptep) << PAGE_SHIFT;
 }
 }
 
 
-#else /* __OS_HAS_AGP */
+#else				/* __OS_HAS_AGP */
 
 
-static inline drm_map_t *drm_lookup_map(unsigned long offset, unsigned long size, drm_device_t *dev)
+static inline drm_map_t *drm_lookup_map(unsigned long offset,
+					unsigned long size, drm_device_t * dev)
 {
 {
-  return NULL;
+	return NULL;
 }
 }
 
 
-static inline void *agp_remap(unsigned long offset, unsigned long size, drm_device_t *dev)
+static inline void *agp_remap(unsigned long offset, unsigned long size,
+			      drm_device_t * dev)
 {
 {
-  return NULL;
+	return NULL;
 }
 }
 
 
-static inline unsigned long drm_follow_page (void *vaddr)
+static inline unsigned long drm_follow_page(void *vaddr)
 {
 {
-  return 0;
+	return 0;
 }
 }
 
 
 #endif
 #endif
 
 
-static inline void *drm_ioremap(unsigned long offset, unsigned long size, drm_device_t *dev)
+static inline void *drm_ioremap(unsigned long offset, unsigned long size,
+				drm_device_t * dev)
 {
 {
 	if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) {
 	if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) {
 		drm_map_t *map = drm_lookup_map(offset, size, dev);
 		drm_map_t *map = drm_lookup_map(offset, size, dev);
@@ -158,8 +164,8 @@ static inline void *drm_ioremap(unsigned long offset, unsigned long size, drm_de
 	return ioremap(offset, size);
 	return ioremap(offset, size);
 }
 }
 
 
-static inline void *drm_ioremap_nocache(unsigned long offset, unsigned long size,
-					drm_device_t *dev)
+static inline void *drm_ioremap_nocache(unsigned long offset,
+					unsigned long size, drm_device_t * dev)
 {
 {
 	if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) {
 	if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) {
 		drm_map_t *map = drm_lookup_map(offset, size, dev);
 		drm_map_t *map = drm_lookup_map(offset, size, dev);
@@ -170,7 +176,8 @@ static inline void *drm_ioremap_nocache(unsigned long offset, unsigned long size
 	return ioremap_nocache(offset, size);
 	return ioremap_nocache(offset, size);
 }
 }
 
 
-static inline void drm_ioremapfree(void *pt, unsigned long size, drm_device_t *dev)
+static inline void drm_ioremapfree(void *pt, unsigned long size,
+				   drm_device_t * dev)
 {
 {
 	/*
 	/*
 	 * This is a bit ugly.  It would be much cleaner if the DRM API would use separate
 	 * This is a bit ugly.  It would be much cleaner if the DRM API would use separate
@@ -178,12 +185,12 @@ static inline void drm_ioremapfree(void *pt, unsigned long size, drm_device_t *d
 	 * a future revision of the interface...
 	 * a future revision of the interface...
 	 */
 	 */
 	if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture
 	if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture
-	    && ((unsigned long) pt >= VMALLOC_START && (unsigned long) pt < VMALLOC_END))
-	{
+	    && ((unsigned long)pt >= VMALLOC_START
+		&& (unsigned long)pt < VMALLOC_END)) {
 		unsigned long offset;
 		unsigned long offset;
 		drm_map_t *map;
 		drm_map_t *map;
 
 
-		offset = drm_follow_page(pt) | ((unsigned long) pt & ~PAGE_MASK);
+		offset = drm_follow_page(pt) | ((unsigned long)pt & ~PAGE_MASK);
 		map = drm_lookup_map(offset, size, dev);
 		map = drm_lookup_map(offset, size, dev);
 		if (map && map->type == _DRM_AGP) {
 		if (map && map->type == _DRM_AGP) {
 			vunmap(pt);
 			vunmap(pt);
@@ -193,5 +200,3 @@ static inline void drm_ioremapfree(void *pt, unsigned long size, drm_device_t *d
 
 
 	iounmap(pt);
 	iounmap(pt);
 }
 }
-
-

+ 107 - 117
drivers/char/drm/drm_memory_debug.h

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_memory.h 
+ * \file drm_memory.h
  * Memory management wrappers for DRM.
  * Memory management wrappers for DRM.
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -35,75 +35,75 @@
 #include "drmP.h"
 #include "drmP.h"
 
 
 typedef struct drm_mem_stats {
 typedef struct drm_mem_stats {
-	const char	  *name;
-	int		  succeed_count;
-	int		  free_count;
-	int		  fail_count;
-	unsigned long	  bytes_allocated;
-	unsigned long	  bytes_freed;
+	const char *name;
+	int succeed_count;
+	int free_count;
+	int fail_count;
+	unsigned long bytes_allocated;
+	unsigned long bytes_freed;
 } drm_mem_stats_t;
 } drm_mem_stats_t;
 
 
 static DEFINE_SPINLOCK(DRM(mem_lock));
 static DEFINE_SPINLOCK(DRM(mem_lock));
-static unsigned long	  DRM(ram_available) = 0; /* In pages */
-static unsigned long	  DRM(ram_used)      = 0;
-static drm_mem_stats_t	  DRM(mem_stats)[]   = {
-	[DRM_MEM_DMA]	    = { "dmabufs"  },
-	[DRM_MEM_SAREA]	    = { "sareas"   },
-	[DRM_MEM_DRIVER]    = { "driver"   },
-	[DRM_MEM_MAGIC]	    = { "magic"	   },
-	[DRM_MEM_IOCTLS]    = { "ioctltab" },
-	[DRM_MEM_MAPS]	    = { "maplist"  },
-	[DRM_MEM_VMAS]	    = { "vmalist"  },
-	[DRM_MEM_BUFS]	    = { "buflist"  },
-	[DRM_MEM_SEGS]	    = { "seglist"  },
-	[DRM_MEM_PAGES]	    = { "pagelist" },
-	[DRM_MEM_FILES]	    = { "files"	   },
-	[DRM_MEM_QUEUES]    = { "queues"   },
-	[DRM_MEM_CMDS]	    = { "commands" },
-	[DRM_MEM_MAPPINGS]  = { "mappings" },
-	[DRM_MEM_BUFLISTS]  = { "buflists" },
-	[DRM_MEM_AGPLISTS]  = { "agplist"  },
-	[DRM_MEM_SGLISTS]   = { "sglist"   },
-	[DRM_MEM_TOTALAGP]  = { "totalagp" },
-	[DRM_MEM_BOUNDAGP]  = { "boundagp" },
-	[DRM_MEM_CTXBITMAP] = { "ctxbitmap"},
-	[DRM_MEM_CTXLIST]   = { "ctxlist"  },
-	[DRM_MEM_STUB]      = { "stub"     },
-	{ NULL, 0, }		/* Last entry must be null */
+static unsigned long DRM(ram_available) = 0;	/* In pages */
+static unsigned long DRM(ram_used) = 0;
+static drm_mem_stats_t DRM(mem_stats)[] =
+{
+	[DRM_MEM_DMA] = {
+	"dmabufs"},[DRM_MEM_SAREA] = {
+	"sareas"},[DRM_MEM_DRIVER] = {
+	"driver"},[DRM_MEM_MAGIC] = {
+	"magic"},[DRM_MEM_IOCTLS] = {
+	"ioctltab"},[DRM_MEM_MAPS] = {
+	"maplist"},[DRM_MEM_VMAS] = {
+	"vmalist"},[DRM_MEM_BUFS] = {
+	"buflist"},[DRM_MEM_SEGS] = {
+	"seglist"},[DRM_MEM_PAGES] = {
+	"pagelist"},[DRM_MEM_FILES] = {
+	"files"},[DRM_MEM_QUEUES] = {
+	"queues"},[DRM_MEM_CMDS] = {
+	"commands"},[DRM_MEM_MAPPINGS] = {
+	"mappings"},[DRM_MEM_BUFLISTS] = {
+	"buflists"},[DRM_MEM_AGPLISTS] = {
+	"agplist"},[DRM_MEM_SGLISTS] = {
+	"sglist"},[DRM_MEM_TOTALAGP] = {
+	"totalagp"},[DRM_MEM_BOUNDAGP] = {
+	"boundagp"},[DRM_MEM_CTXBITMAP] = {
+	"ctxbitmap"},[DRM_MEM_CTXLIST] = {
+	"ctxlist"},[DRM_MEM_STUB] = {
+	"stub"}, {
+	NULL, 0,}		/* Last entry must be null */
 };
 };
 
 
-void DRM(mem_init)(void)
-{
+void DRM(mem_init) (void) {
 	drm_mem_stats_t *mem;
 	drm_mem_stats_t *mem;
-	struct sysinfo	si;
+	struct sysinfo si;
 
 
 	for (mem = DRM(mem_stats); mem->name; ++mem) {
 	for (mem = DRM(mem_stats); mem->name; ++mem) {
-		mem->succeed_count   = 0;
-		mem->free_count	     = 0;
-		mem->fail_count	     = 0;
+		mem->succeed_count = 0;
+		mem->free_count = 0;
+		mem->fail_count = 0;
 		mem->bytes_allocated = 0;
 		mem->bytes_allocated = 0;
-		mem->bytes_freed     = 0;
+		mem->bytes_freed = 0;
 	}
 	}
 
 
 	si_meminfo(&si);
 	si_meminfo(&si);
 	DRM(ram_available) = si.totalram;
 	DRM(ram_available) = si.totalram;
-	DRM(ram_used)	   = 0;
+	DRM(ram_used) = 0;
 }
 }
 
 
 /* drm_mem_info is called whenever a process reads /dev/drm/mem. */
 /* drm_mem_info is called whenever a process reads /dev/drm/mem. */
 
 
-static int DRM(_mem_info)(char *buf, char **start, off_t offset,
-			  int request, int *eof, void *data)
-{
+static int DRM(_mem_info) (char *buf, char **start, off_t offset,
+			   int request, int *eof, void *data) {
 	drm_mem_stats_t *pt;
 	drm_mem_stats_t *pt;
-	int             len = 0;
+	int len = 0;
 
 
 	if (offset > DRM_PROC_LIMIT) {
 	if (offset > DRM_PROC_LIMIT) {
 		*eof = 1;
 		*eof = 1;
 		return 0;
 		return 0;
 	}
 	}
 
 
-	*eof   = 0;
+	*eof = 0;
 	*start = &buf[offset];
 	*start = &buf[offset];
 
 
 	DRM_PROC_PRINT("		  total counts			"
 	DRM_PROC_PRINT("		  total counts			"
@@ -129,24 +129,23 @@ static int DRM(_mem_info)(char *buf, char **start, off_t offset,
 			       - (long)pt->bytes_freed);
 			       - (long)pt->bytes_freed);
 	}
 	}
 
 
-	if (len > request + offset) return request;
+	if (len > request + offset)
+		return request;
 	*eof = 1;
 	*eof = 1;
 	return len - offset;
 	return len - offset;
 }
 }
 
 
-int DRM(mem_info)(char *buf, char **start, off_t offset,
-		  int len, int *eof, void *data)
-{
+int DRM(mem_info) (char *buf, char **start, off_t offset,
+		   int len, int *eof, void *data) {
 	int ret;
 	int ret;
 
 
 	spin_lock(&DRM(mem_lock));
 	spin_lock(&DRM(mem_lock));
-	ret = DRM(_mem_info)(buf, start, offset, len, eof, data);
+	ret = DRM(_mem_info) (buf, start, offset, len, eof, data);
 	spin_unlock(&DRM(mem_lock));
 	spin_unlock(&DRM(mem_lock));
 	return ret;
 	return ret;
 }
 }
 
 
-void *DRM(alloc)(size_t size, int area)
-{
+void *DRM(alloc) (size_t size, int area) {
 	void *pt;
 	void *pt;
 
 
 	if (!size) {
 	if (!size) {
@@ -167,40 +166,40 @@ void *DRM(alloc)(size_t size, int area)
 	return pt;
 	return pt;
 }
 }
 
 
-void *DRM(calloc)(size_t nmemb, size_t size, int area)
-{
+void *DRM(calloc) (size_t nmemb, size_t size, int area) {
 	void *addr;
 	void *addr;
 
 
-	addr = DRM(alloc)(nmemb * size, area);
+	addr = DRM(alloc) (nmemb * size, area);
 	if (addr != NULL)
 	if (addr != NULL)
 		memset((void *)addr, 0, size * nmemb);
 		memset((void *)addr, 0, size * nmemb);
 
 
 	return addr;
 	return addr;
 }
 }
 
 
-void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
-{
+void *DRM(realloc) (void *oldpt, size_t oldsize, size_t size, int area) {
 	void *pt;
 	void *pt;
 
 
-	if (!(pt = DRM(alloc)(size, area))) return NULL;
+	if (!(pt = DRM(alloc) (size, area)))
+		return NULL;
 	if (oldpt && oldsize) {
 	if (oldpt && oldsize) {
 		memcpy(pt, oldpt, oldsize);
 		memcpy(pt, oldpt, oldsize);
-		DRM(free)(oldpt, oldsize, area);
+		DRM(free) (oldpt, oldsize, area);
 	}
 	}
 	return pt;
 	return pt;
 }
 }
 
 
-void DRM(free)(void *pt, size_t size, int area)
-{
+void DRM(free) (void *pt, size_t size, int area) {
 	int alloc_count;
 	int alloc_count;
 	int free_count;
 	int free_count;
 
 
-	if (!pt) DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n");
-	else	 kfree(pt);
+	if (!pt)
+		DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n");
+	else
+		kfree(pt);
 	spin_lock(&DRM(mem_lock));
 	spin_lock(&DRM(mem_lock));
 	DRM(mem_stats)[area].bytes_freed += size;
 	DRM(mem_stats)[area].bytes_freed += size;
-	free_count  = ++DRM(mem_stats)[area].free_count;
-	alloc_count =	DRM(mem_stats)[area].succeed_count;
+	free_count = ++DRM(mem_stats)[area].free_count;
+	alloc_count = DRM(mem_stats)[area].succeed_count;
 	spin_unlock(&DRM(mem_lock));
 	spin_unlock(&DRM(mem_lock));
 	if (free_count > alloc_count) {
 	if (free_count > alloc_count) {
 		DRM_MEM_ERROR(area, "Excess frees: %d frees, %d allocs\n",
 		DRM_MEM_ERROR(area, "Excess frees: %d frees, %d allocs\n",
@@ -208,12 +207,11 @@ void DRM(free)(void *pt, size_t size, int area)
 	}
 	}
 }
 }
 
 
-unsigned long DRM(alloc_pages)(int order, int area)
-{
+unsigned long DRM(alloc_pages) (int order, int area) {
 	unsigned long address;
 	unsigned long address;
-	unsigned long bytes	  = PAGE_SIZE << order;
+	unsigned long bytes = PAGE_SIZE << order;
 	unsigned long addr;
 	unsigned long addr;
-	unsigned int  sz;
+	unsigned int sz;
 
 
 	spin_lock(&DRM(mem_lock));
 	spin_lock(&DRM(mem_lock));
 	if ((DRM(ram_used) >> PAGE_SHIFT)
 	if ((DRM(ram_used) >> PAGE_SHIFT)
@@ -233,48 +231,44 @@ unsigned long DRM(alloc_pages)(int order, int area)
 	spin_lock(&DRM(mem_lock));
 	spin_lock(&DRM(mem_lock));
 	++DRM(mem_stats)[area].succeed_count;
 	++DRM(mem_stats)[area].succeed_count;
 	DRM(mem_stats)[area].bytes_allocated += bytes;
 	DRM(mem_stats)[area].bytes_allocated += bytes;
-	DRM(ram_used)		             += bytes;
+	DRM(ram_used) += bytes;
 	spin_unlock(&DRM(mem_lock));
 	spin_unlock(&DRM(mem_lock));
 
 
-
-				/* Zero outside the lock */
+	/* Zero outside the lock */
 	memset((void *)address, 0, bytes);
 	memset((void *)address, 0, bytes);
 
 
-				/* Reserve */
+	/* Reserve */
 	for (addr = address, sz = bytes;
 	for (addr = address, sz = bytes;
-	     sz > 0;
-	     addr += PAGE_SIZE, sz -= PAGE_SIZE) {
+	     sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
 		SetPageReserved(virt_to_page(addr));
 		SetPageReserved(virt_to_page(addr));
 	}
 	}
 
 
 	return address;
 	return address;
 }
 }
 
 
-void DRM(free_pages)(unsigned long address, int order, int area)
-{
+void DRM(free_pages) (unsigned long address, int order, int area) {
 	unsigned long bytes = PAGE_SIZE << order;
 	unsigned long bytes = PAGE_SIZE << order;
-	int		  alloc_count;
-	int		  free_count;
+	int alloc_count;
+	int free_count;
 	unsigned long addr;
 	unsigned long addr;
-	unsigned int  sz;
+	unsigned int sz;
 
 
 	if (!address) {
 	if (!address) {
 		DRM_MEM_ERROR(area, "Attempt to free address 0\n");
 		DRM_MEM_ERROR(area, "Attempt to free address 0\n");
 	} else {
 	} else {
-				/* Unreserve */
+		/* Unreserve */
 		for (addr = address, sz = bytes;
 		for (addr = address, sz = bytes;
-		     sz > 0;
-		     addr += PAGE_SIZE, sz -= PAGE_SIZE) {
+		     sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
 			ClearPageReserved(virt_to_page(addr));
 			ClearPageReserved(virt_to_page(addr));
 		}
 		}
 		free_pages(address, order);
 		free_pages(address, order);
 	}
 	}
 
 
 	spin_lock(&DRM(mem_lock));
 	spin_lock(&DRM(mem_lock));
-	free_count  = ++DRM(mem_stats)[area].free_count;
-	alloc_count =	DRM(mem_stats)[area].succeed_count;
+	free_count = ++DRM(mem_stats)[area].free_count;
+	alloc_count = DRM(mem_stats)[area].succeed_count;
 	DRM(mem_stats)[area].bytes_freed += bytes;
 	DRM(mem_stats)[area].bytes_freed += bytes;
-	DRM(ram_used)			 -= bytes;
+	DRM(ram_used) -= bytes;
 	spin_unlock(&DRM(mem_lock));
 	spin_unlock(&DRM(mem_lock));
 	if (free_count > alloc_count) {
 	if (free_count > alloc_count) {
 		DRM_MEM_ERROR(area,
 		DRM_MEM_ERROR(area,
@@ -283,8 +277,8 @@ void DRM(free_pages)(unsigned long address, int order, int area)
 	}
 	}
 }
 }
 
 
-void *DRM(ioremap)(unsigned long offset, unsigned long size, drm_device_t *dev)
-{
+void *DRM(ioremap) (unsigned long offset, unsigned long size,
+		    drm_device_t * dev) {
 	void *pt;
 	void *pt;
 
 
 	if (!size) {
 	if (!size) {
@@ -306,8 +300,8 @@ void *DRM(ioremap)(unsigned long offset, unsigned long size, drm_device_t *dev)
 	return pt;
 	return pt;
 }
 }
 
 
-void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size, drm_device_t *dev)
-{
+void *DRM(ioremap_nocache) (unsigned long offset, unsigned long size,
+			    drm_device_t * dev) {
 	void *pt;
 	void *pt;
 
 
 	if (!size) {
 	if (!size) {
@@ -329,8 +323,7 @@ void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size, drm_device_
 	return pt;
 	return pt;
 }
 }
 
 
-void DRM(ioremapfree)(void *pt, unsigned long size, drm_device_t *dev)
-{
+void DRM(ioremapfree) (void *pt, unsigned long size, drm_device_t * dev) {
 	int alloc_count;
 	int alloc_count;
 	int free_count;
 	int free_count;
 
 
@@ -342,8 +335,8 @@ void DRM(ioremapfree)(void *pt, unsigned long size, drm_device_t *dev)
 
 
 	spin_lock(&DRM(mem_lock));
 	spin_lock(&DRM(mem_lock));
 	DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_freed += size;
 	DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_freed += size;
-	free_count  = ++DRM(mem_stats)[DRM_MEM_MAPPINGS].free_count;
-	alloc_count =	DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count;
+	free_count = ++DRM(mem_stats)[DRM_MEM_MAPPINGS].free_count;
+	alloc_count = DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count;
 	spin_unlock(&DRM(mem_lock));
 	spin_unlock(&DRM(mem_lock));
 	if (free_count > alloc_count) {
 	if (free_count > alloc_count) {
 		DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
 		DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
@@ -354,8 +347,7 @@ void DRM(ioremapfree)(void *pt, unsigned long size, drm_device_t *dev)
 
 
 #if __OS_HAS_AGP
 #if __OS_HAS_AGP
 
 
-DRM_AGP_MEM *DRM(alloc_agp)(int pages, u32 type)
-{
+DRM_AGP_MEM *DRM(alloc_agp) (int pages, u32 type) {
 	DRM_AGP_MEM *handle;
 	DRM_AGP_MEM *handle;
 
 
 	if (!pages) {
 	if (!pages) {
@@ -363,11 +355,11 @@ DRM_AGP_MEM *DRM(alloc_agp)(int pages, u32 type)
 		return NULL;
 		return NULL;
 	}
 	}
 
 
-	if ((handle = DRM(agp_allocate_memory)(pages, type))) {
+	if ((handle = DRM(agp_allocate_memory) (pages, type))) {
 		spin_lock(&DRM(mem_lock));
 		spin_lock(&DRM(mem_lock));
 		++DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
 		++DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
 		DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_allocated
 		DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_allocated
-			+= pages << PAGE_SHIFT;
+		    += pages << PAGE_SHIFT;
 		spin_unlock(&DRM(mem_lock));
 		spin_unlock(&DRM(mem_lock));
 		return handle;
 		return handle;
 	}
 	}
@@ -377,11 +369,10 @@ DRM_AGP_MEM *DRM(alloc_agp)(int pages, u32 type)
 	return NULL;
 	return NULL;
 }
 }
 
 
-int DRM(free_agp)(DRM_AGP_MEM *handle, int pages)
-{
-	int           alloc_count;
-	int           free_count;
-	int           retval = -EINVAL;
+int DRM(free_agp) (DRM_AGP_MEM * handle, int pages) {
+	int alloc_count;
+	int free_count;
+	int retval = -EINVAL;
 
 
 	if (!handle) {
 	if (!handle) {
 		DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
 		DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
@@ -389,12 +380,12 @@ int DRM(free_agp)(DRM_AGP_MEM *handle, int pages)
 		return retval;
 		return retval;
 	}
 	}
 
 
-	if (DRM(agp_free_memory)(handle)) {
+	if (DRM(agp_free_memory) (handle)) {
 		spin_lock(&DRM(mem_lock));
 		spin_lock(&DRM(mem_lock));
-		free_count  = ++DRM(mem_stats)[DRM_MEM_TOTALAGP].free_count;
-		alloc_count =   DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
+		free_count = ++DRM(mem_stats)[DRM_MEM_TOTALAGP].free_count;
+		alloc_count = DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
 		DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_freed
 		DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_freed
-			+= pages << PAGE_SHIFT;
+		    += pages << PAGE_SHIFT;
 		spin_unlock(&DRM(mem_lock));
 		spin_unlock(&DRM(mem_lock));
 		if (free_count > alloc_count) {
 		if (free_count > alloc_count) {
 			DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
 			DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
@@ -406,8 +397,7 @@ int DRM(free_agp)(DRM_AGP_MEM *handle, int pages)
 	return retval;
 	return retval;
 }
 }
 
 
-int DRM(bind_agp)(DRM_AGP_MEM *handle, unsigned int start)
-{
+int DRM(bind_agp) (DRM_AGP_MEM * handle, unsigned int start) {
 	int retcode = -EINVAL;
 	int retcode = -EINVAL;
 
 
 	if (!handle) {
 	if (!handle) {
@@ -416,11 +406,11 @@ int DRM(bind_agp)(DRM_AGP_MEM *handle, unsigned int start)
 		return retcode;
 		return retcode;
 	}
 	}
 
 
-	if (!(retcode = DRM(agp_bind_memory)(handle, start))) {
+	if (!(retcode = DRM(agp_bind_memory) (handle, start))) {
 		spin_lock(&DRM(mem_lock));
 		spin_lock(&DRM(mem_lock));
 		++DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
 		++DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
 		DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_allocated
 		DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_allocated
-			+= handle->page_count << PAGE_SHIFT;
+		    += handle->page_count << PAGE_SHIFT;
 		spin_unlock(&DRM(mem_lock));
 		spin_unlock(&DRM(mem_lock));
 		return retcode;
 		return retcode;
 	}
 	}
@@ -430,8 +420,7 @@ int DRM(bind_agp)(DRM_AGP_MEM *handle, unsigned int start)
 	return retcode;
 	return retcode;
 }
 }
 
 
-int DRM(unbind_agp)(DRM_AGP_MEM *handle)
-{
+int DRM(unbind_agp) (DRM_AGP_MEM * handle) {
 	int alloc_count;
 	int alloc_count;
 	int free_count;
 	int free_count;
 	int retcode = -EINVAL;
 	int retcode = -EINVAL;
@@ -442,12 +431,13 @@ int DRM(unbind_agp)(DRM_AGP_MEM *handle)
 		return retcode;
 		return retcode;
 	}
 	}
 
 
-	if ((retcode = DRM(agp_unbind_memory)(handle))) return retcode;
+	if ((retcode = DRM(agp_unbind_memory) (handle)))
+		return retcode;
 	spin_lock(&DRM(mem_lock));
 	spin_lock(&DRM(mem_lock));
-	free_count  = ++DRM(mem_stats)[DRM_MEM_BOUNDAGP].free_count;
+	free_count = ++DRM(mem_stats)[DRM_MEM_BOUNDAGP].free_count;
 	alloc_count = DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
 	alloc_count = DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
 	DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
 	DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
-		+= handle->page_count << PAGE_SHIFT;
+	    += handle->page_count << PAGE_SHIFT;
 	spin_unlock(&DRM(mem_lock));
 	spin_unlock(&DRM(mem_lock));
 	if (free_count > alloc_count) {
 	if (free_count > alloc_count) {
 		DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
 		DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,

+ 7 - 10
drivers/char/drm/drm_os_linux.h

@@ -3,7 +3,6 @@
  * OS abstraction macros.
  * OS abstraction macros.
  */
  */
 
 
-
 #include <linux/interrupt.h>	/* For task queue support */
 #include <linux/interrupt.h>	/* For task queue support */
 #include <linux/delay.h>
 #include <linux/delay.h>
 
 
@@ -47,25 +46,25 @@
 #else
 #else
 /* define some dummy types for non AGP supporting kernels */
 /* define some dummy types for non AGP supporting kernels */
 struct no_agp_kern {
 struct no_agp_kern {
-  unsigned long aper_base;
-  unsigned long aper_size;
+	unsigned long aper_base;
+	unsigned long aper_size;
 };
 };
 #define DRM_AGP_MEM             int
 #define DRM_AGP_MEM             int
 #define DRM_AGP_KERN            struct no_agp_kern
 #define DRM_AGP_KERN            struct no_agp_kern
 #endif
 #endif
 
 
 #if !(__OS_HAS_MTRR)
 #if !(__OS_HAS_MTRR)
-static __inline__ int mtrr_add (unsigned long base, unsigned long size,
-                                unsigned int type, char increment)
+static __inline__ int mtrr_add(unsigned long base, unsigned long size,
+			       unsigned int type, char increment)
 {
 {
 	return -ENODEV;
 	return -ENODEV;
 }
 }
 
 
-static __inline__ int mtrr_del (int reg, unsigned long base,
-                                unsigned long size)
+static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
 {
 {
 	return -ENODEV;
 	return -ENODEV;
 }
 }
+
 #define MTRR_TYPE_WRCOMB     1
 #define MTRR_TYPE_WRCOMB     1
 
 
 #endif
 #endif
@@ -99,7 +98,7 @@ static __inline__ int mtrr_del (int reg, unsigned long base,
 
 
 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
 
 
-/** 
+/**
  * Get the pointer to the SAREA.
  * Get the pointer to the SAREA.
  *
  *
  * Searches the SAREA on the mapping lists and points drm_device::sarea to it.
  * Searches the SAREA on the mapping lists and points drm_device::sarea to it.
@@ -143,7 +142,5 @@ do {								\
 	remove_wait_queue(&(queue), &entry);			\
 	remove_wait_queue(&(queue), &entry);			\
 } while (0)
 } while (0)
 
 
-
 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )
 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )
- 

+ 5 - 5
drivers/char/drm/drm_pci.c

@@ -77,7 +77,7 @@ drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size, size_t align,
 	dmah = kmalloc(sizeof(drm_dma_handle_t), GFP_KERNEL);
 	dmah = kmalloc(sizeof(drm_dma_handle_t), GFP_KERNEL);
 	if (!dmah)
 	if (!dmah)
 		return NULL;
 		return NULL;
-	
+
 	dmah->size = size;
 	dmah->size = size;
 	dmah->vaddr = pci_alloc_consistent(dev->pdev, size, &dmah->busaddr);
 	dmah->vaddr = pci_alloc_consistent(dev->pdev, size, &dmah->busaddr);
 
 
@@ -106,6 +106,7 @@ drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size, size_t align,
 
 
 	return dmah;
 	return dmah;
 }
 }
+
 EXPORT_SYMBOL(drm_pci_alloc);
 EXPORT_SYMBOL(drm_pci_alloc);
 
 
 /**
 /**
@@ -113,8 +114,7 @@ EXPORT_SYMBOL(drm_pci_alloc);
  *
  *
  * This function is for internal use in the Linux-specific DRM core code.
  * This function is for internal use in the Linux-specific DRM core code.
  */
  */
-void
-__drm_pci_free(drm_device_t * dev, drm_dma_handle_t *dmah)
+void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah)
 {
 {
 #ifdef DRM_DEBUG_MEMORY
 #ifdef DRM_DEBUG_MEMORY
 	int area = DRM_MEM_DMA;
 	int area = DRM_MEM_DMA;
@@ -150,12 +150,12 @@ __drm_pci_free(drm_device_t * dev, drm_dma_handle_t *dmah)
 /**
 /**
  * \brief Free a PCI consistent memory block
  * \brief Free a PCI consistent memory block
  */
  */
-void
-drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah)
+void drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah)
 {
 {
 	__drm_pci_free(dev, dmah);
 	__drm_pci_free(dev, dmah);
 	kfree(dmah);
 	kfree(dmah);
 }
 }
+
 EXPORT_SYMBOL(drm_pci_free);
 EXPORT_SYMBOL(drm_pci_free);
 
 
 /*@}*/
 /*@}*/

+ 0 - 1
drivers/char/drm/drm_pciids.h

@@ -234,4 +234,3 @@
 	{0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
 	{0, 0, 0}
 	{0, 0, 0}
-

+ 140 - 132
drivers/char/drm/drm_proc.c

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_proc.h 
+ * \file drm_proc.c
  * /proc support for DRM
  * /proc support for DRM
  *
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -39,19 +39,19 @@
 
 
 #include "drmP.h"
 #include "drmP.h"
 
 
-static int	   drm_name_info(char *buf, char **start, off_t offset,
-				  int request, int *eof, void *data);
-static int	   drm_vm_info(char *buf, char **start, off_t offset,
-				int request, int *eof, void *data);
-static int	   drm_clients_info(char *buf, char **start, off_t offset,
-				     int request, int *eof, void *data);
-static int	   drm_queues_info(char *buf, char **start, off_t offset,
-				    int request, int *eof, void *data);
-static int	   drm_bufs_info(char *buf, char **start, off_t offset,
-				  int request, int *eof, void *data);
+static int drm_name_info(char *buf, char **start, off_t offset,
+			 int request, int *eof, void *data);
+static int drm_vm_info(char *buf, char **start, off_t offset,
+		       int request, int *eof, void *data);
+static int drm_clients_info(char *buf, char **start, off_t offset,
+			    int request, int *eof, void *data);
+static int drm_queues_info(char *buf, char **start, off_t offset,
+			   int request, int *eof, void *data);
+static int drm_bufs_info(char *buf, char **start, off_t offset,
+			 int request, int *eof, void *data);
 #if DRM_DEBUG_CODE
 #if DRM_DEBUG_CODE
-static int	   drm_vma_info(char *buf, char **start, off_t offset,
-				 int request, int *eof, void *data);
+static int drm_vma_info(char *buf, char **start, off_t offset,
+			int request, int *eof, void *data);
 #endif
 #endif
 
 
 /**
 /**
@@ -59,18 +59,21 @@ static int	   drm_vma_info(char *buf, char **start, off_t offset,
  */
  */
 static struct drm_proc_list {
 static struct drm_proc_list {
 	const char *name;	/**< file name */
 	const char *name;	/**< file name */
-	int	   (*f)(char *, char **, off_t, int, int *, void *);	/**< proc callback*/
+	int (*f) (char *, char **, off_t, int, int *, void *);		/**< proc callback*/
 } drm_proc_list[] = {
 } drm_proc_list[] = {
-	{ "name",    drm_name_info    },
-	{ "mem",     drm_mem_info     },
-	{ "vm",	     drm_vm_info      },
-	{ "clients", drm_clients_info },
-	{ "queues",  drm_queues_info  },
-	{ "bufs",    drm_bufs_info    },
+	{
+	"name", drm_name_info}, {
+	"mem", drm_mem_info}, {
+	"vm", drm_vm_info}, {
+	"clients", drm_clients_info}, {
+	"queues", drm_queues_info}, {
+	"bufs", drm_bufs_info},
 #if DRM_DEBUG_CODE
 #if DRM_DEBUG_CODE
-	{ "vma",     drm_vma_info     },
+	{
+	"vma", drm_vma_info},
 #endif
 #endif
 };
 };
+
 #define DRM_PROC_ENTRIES (sizeof(drm_proc_list)/sizeof(drm_proc_list[0]))
 #define DRM_PROC_ENTRIES (sizeof(drm_proc_list)/sizeof(drm_proc_list[0]))
 
 
 /**
 /**
@@ -81,18 +84,17 @@ static struct drm_proc_list {
  * \param root DRI proc dir entry.
  * \param root DRI proc dir entry.
  * \param dev_root resulting DRI device proc dir entry.
  * \param dev_root resulting DRI device proc dir entry.
  * \return root entry pointer on success, or NULL on failure.
  * \return root entry pointer on success, or NULL on failure.
- * 
+ *
  * Create the DRI proc root entry "/proc/dri", the device proc root entry
  * Create the DRI proc root entry "/proc/dri", the device proc root entry
  * "/proc/dri/%minor%/", and each entry in proc_list as
  * "/proc/dri/%minor%/", and each entry in proc_list as
  * "/proc/dri/%minor%/%name%".
  * "/proc/dri/%minor%/%name%".
  */
  */
-int drm_proc_init(drm_device_t *dev, int minor,
-		    struct proc_dir_entry *root,
-		    struct proc_dir_entry **dev_root)
+int drm_proc_init(drm_device_t * dev, int minor,
+		  struct proc_dir_entry *root, struct proc_dir_entry **dev_root)
 {
 {
 	struct proc_dir_entry *ent;
 	struct proc_dir_entry *ent;
-	int		      i, j;
-	char                  name[64];
+	int i, j;
+	char name[64];
 
 
 	sprintf(name, "%d", minor);
 	sprintf(name, "%d", minor);
 	*dev_root = proc_mkdir(name, root);
 	*dev_root = proc_mkdir(name, root);
@@ -103,7 +105,7 @@ int drm_proc_init(drm_device_t *dev, int minor,
 
 
 	for (i = 0; i < DRM_PROC_ENTRIES; i++) {
 	for (i = 0; i < DRM_PROC_ENTRIES; i++) {
 		ent = create_proc_entry(drm_proc_list[i].name,
 		ent = create_proc_entry(drm_proc_list[i].name,
-					S_IFREG|S_IRUGO, *dev_root);
+					S_IFREG | S_IRUGO, *dev_root);
 		if (!ent) {
 		if (!ent) {
 			DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
 			DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
 				  name, drm_proc_list[i].name);
 				  name, drm_proc_list[i].name);
@@ -114,13 +116,12 @@ int drm_proc_init(drm_device_t *dev, int minor,
 			return -1;
 			return -1;
 		}
 		}
 		ent->read_proc = drm_proc_list[i].f;
 		ent->read_proc = drm_proc_list[i].f;
-		ent->data      = dev;
+		ent->data = dev;
 	}
 	}
 
 
 	return 0;
 	return 0;
 }
 }
 
 
-
 /**
 /**
  * Cleanup the proc filesystem resources.
  * Cleanup the proc filesystem resources.
  *
  *
@@ -132,12 +133,13 @@ int drm_proc_init(drm_device_t *dev, int minor,
  * Remove all proc entries created by proc_init().
  * Remove all proc entries created by proc_init().
  */
  */
 int drm_proc_cleanup(int minor, struct proc_dir_entry *root,
 int drm_proc_cleanup(int minor, struct proc_dir_entry *root,
-		      struct proc_dir_entry *dev_root)
+		     struct proc_dir_entry *dev_root)
 {
 {
-	int  i;
+	int i;
 	char name[64];
 	char name[64];
 
 
-	if (!root || !dev_root) return 0;
+	if (!root || !dev_root)
+		return 0;
 
 
 	for (i = 0; i < DRM_PROC_ENTRIES; i++)
 	for (i = 0; i < DRM_PROC_ENTRIES; i++)
 		remove_proc_entry(drm_proc_list[i].name, dev_root);
 		remove_proc_entry(drm_proc_list[i].name, dev_root);
@@ -149,7 +151,7 @@ int drm_proc_cleanup(int minor, struct proc_dir_entry *root,
 
 
 /**
 /**
  * Called when "/proc/dri/.../name" is read.
  * Called when "/proc/dri/.../name" is read.
- * 
+ *
  * \param buf output buffer.
  * \param buf output buffer.
  * \param start start of output data.
  * \param start start of output data.
  * \param offset requested start offset.
  * \param offset requested start offset.
@@ -157,14 +159,14 @@ int drm_proc_cleanup(int minor, struct proc_dir_entry *root,
  * \param eof whether there is no more data to return.
  * \param eof whether there is no more data to return.
  * \param data private data.
  * \param data private data.
  * \return number of written bytes.
  * \return number of written bytes.
- * 
+ *
  * Prints the device name together with the bus id if available.
  * Prints the device name together with the bus id if available.
  */
  */
 static int drm_name_info(char *buf, char **start, off_t offset, int request,
 static int drm_name_info(char *buf, char **start, off_t offset, int request,
-			  int *eof, void *data)
+			 int *eof, void *data)
 {
 {
-	drm_device_t *dev = (drm_device_t *)data;
-	int          len  = 0;
+	drm_device_t *dev = (drm_device_t *) data;
+	int len = 0;
 
 
 	if (offset > DRM_PROC_LIMIT) {
 	if (offset > DRM_PROC_LIMIT) {
 		*eof = 1;
 		*eof = 1;
@@ -172,23 +174,26 @@ static int drm_name_info(char *buf, char **start, off_t offset, int request,
 	}
 	}
 
 
 	*start = &buf[offset];
 	*start = &buf[offset];
-	*eof   = 0;
+	*eof = 0;
 
 
 	if (dev->unique) {
 	if (dev->unique) {
 		DRM_PROC_PRINT("%s %s %s\n",
 		DRM_PROC_PRINT("%s %s %s\n",
-			       dev->driver->pci_driver.name, pci_name(dev->pdev), dev->unique);
+			       dev->driver->pci_driver.name,
+			       pci_name(dev->pdev), dev->unique);
 	} else {
 	} else {
-		DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name, pci_name(dev->pdev));
+		DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
+			       pci_name(dev->pdev));
 	}
 	}
 
 
-	if (len > request + offset) return request;
+	if (len > request + offset)
+		return request;
 	*eof = 1;
 	*eof = 1;
 	return len - offset;
 	return len - offset;
 }
 }
 
 
 /**
 /**
  * Called when "/proc/dri/.../vm" is read.
  * Called when "/proc/dri/.../vm" is read.
- * 
+ *
  * \param buf output buffer.
  * \param buf output buffer.
  * \param start start of output data.
  * \param start start of output data.
  * \param offset requested start offset.
  * \param offset requested start offset.
@@ -196,24 +201,24 @@ static int drm_name_info(char *buf, char **start, off_t offset, int request,
  * \param eof whether there is no more data to return.
  * \param eof whether there is no more data to return.
  * \param data private data.
  * \param data private data.
  * \return number of written bytes.
  * \return number of written bytes.
- * 
+ *
  * Prints information about all mappings in drm_device::maplist.
  * Prints information about all mappings in drm_device::maplist.
  */
  */
 static int drm__vm_info(char *buf, char **start, off_t offset, int request,
 static int drm__vm_info(char *buf, char **start, off_t offset, int request,
-			 int *eof, void *data)
+			int *eof, void *data)
 {
 {
-	drm_device_t *dev = (drm_device_t *)data;
-	int          len  = 0;
-	drm_map_t    *map;
+	drm_device_t *dev = (drm_device_t *) data;
+	int len = 0;
+	drm_map_t *map;
 	drm_map_list_t *r_list;
 	drm_map_list_t *r_list;
 	struct list_head *list;
 	struct list_head *list;
 
 
-				/* Hardcoded from _DRM_FRAME_BUFFER,
-                                   _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
-                                   _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
-	const char   *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
-	const char   *type;
-	int	     i;
+	/* Hardcoded from _DRM_FRAME_BUFFER,
+	   _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
+	   _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
+	const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
+	const char *type;
+	int i;
 
 
 	if (offset > DRM_PROC_LIMIT) {
 	if (offset > DRM_PROC_LIMIT) {
 		*eof = 1;
 		*eof = 1;
@@ -221,36 +226,35 @@ static int drm__vm_info(char *buf, char **start, off_t offset, int request,
 	}
 	}
 
 
 	*start = &buf[offset];
 	*start = &buf[offset];
-	*eof   = 0;
+	*eof = 0;
 
 
 	DRM_PROC_PRINT("slot	 offset	      size type flags	 "
 	DRM_PROC_PRINT("slot	 offset	      size type flags	 "
 		       "address mtrr\n\n");
 		       "address mtrr\n\n");
 	i = 0;
 	i = 0;
-	if (dev->maplist != NULL) list_for_each(list, &dev->maplist->head) {
+	if (dev->maplist != NULL)
+		list_for_each(list, &dev->maplist->head) {
 		r_list = list_entry(list, drm_map_list_t, head);
 		r_list = list_entry(list, drm_map_list_t, head);
 		map = r_list->map;
 		map = r_list->map;
-		if(!map)
+		if (!map)
 			continue;
 			continue;
 		if (map->type < 0 || map->type > 5)
 		if (map->type < 0 || map->type > 5)
 			type = "??";
 			type = "??";
-		else	
+		else
 			type = types[map->type];
 			type = types[map->type];
 		DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s  0x%02x 0x%08x ",
 		DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s  0x%02x 0x%08x ",
 			       i,
 			       i,
 			       map->offset,
 			       map->offset,
-			       map->size,
-			       type,
-			       map->flags,
-			       r_list->user_token);
+			       map->size, type, map->flags, r_list->user_token);
 		if (map->mtrr < 0) {
 		if (map->mtrr < 0) {
 			DRM_PROC_PRINT("none\n");
 			DRM_PROC_PRINT("none\n");
 		} else {
 		} else {
 			DRM_PROC_PRINT("%4d\n", map->mtrr);
 			DRM_PROC_PRINT("%4d\n", map->mtrr);
 		}
 		}
 		i++;
 		i++;
-	}
+		}
 
 
-	if (len > request + offset) return request;
+	if (len > request + offset)
+		return request;
 	*eof = 1;
 	*eof = 1;
 	return len - offset;
 	return len - offset;
 }
 }
@@ -259,10 +263,10 @@ static int drm__vm_info(char *buf, char **start, off_t offset, int request,
  * Simply calls _vm_info() while holding the drm_device::struct_sem lock.
  * Simply calls _vm_info() while holding the drm_device::struct_sem lock.
  */
  */
 static int drm_vm_info(char *buf, char **start, off_t offset, int request,
 static int drm_vm_info(char *buf, char **start, off_t offset, int request,
-			int *eof, void *data)
+		       int *eof, void *data)
 {
 {
-	drm_device_t *dev = (drm_device_t *)data;
-	int	     ret;
+	drm_device_t *dev = (drm_device_t *) data;
+	int ret;
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 	ret = drm__vm_info(buf, start, offset, request, eof, data);
 	ret = drm__vm_info(buf, start, offset, request, eof, data);
@@ -272,7 +276,7 @@ static int drm_vm_info(char *buf, char **start, off_t offset, int request,
 
 
 /**
 /**
  * Called when "/proc/dri/.../queues" is read.
  * Called when "/proc/dri/.../queues" is read.
- * 
+ *
  * \param buf output buffer.
  * \param buf output buffer.
  * \param start start of output data.
  * \param start start of output data.
  * \param offset requested start offset.
  * \param offset requested start offset.
@@ -282,12 +286,12 @@ static int drm_vm_info(char *buf, char **start, off_t offset, int request,
  * \return number of written bytes.
  * \return number of written bytes.
  */
  */
 static int drm__queues_info(char *buf, char **start, off_t offset,
 static int drm__queues_info(char *buf, char **start, off_t offset,
-			     int request, int *eof, void *data)
+			    int request, int *eof, void *data)
 {
 {
-	drm_device_t *dev = (drm_device_t *)data;
-	int          len  = 0;
-	int	     i;
-	drm_queue_t  *q;
+	drm_device_t *dev = (drm_device_t *) data;
+	int len = 0;
+	int i;
+	drm_queue_t *q;
 
 
 	if (offset > DRM_PROC_LIMIT) {
 	if (offset > DRM_PROC_LIMIT) {
 		*eof = 1;
 		*eof = 1;
@@ -295,7 +299,7 @@ static int drm__queues_info(char *buf, char **start, off_t offset,
 	}
 	}
 
 
 	*start = &buf[offset];
 	*start = &buf[offset];
-	*eof   = 0;
+	*eof = 0;
 
 
 	DRM_PROC_PRINT("  ctx/flags   use   fin"
 	DRM_PROC_PRINT("  ctx/flags   use   fin"
 		       "   blk/rw/rwf  wait    flushed	   queued"
 		       "   blk/rw/rwf  wait    flushed	   queued"
@@ -313,14 +317,17 @@ static int drm__queues_info(char *buf, char **start, off_t offset,
 				   atomic_read(&q->block_count),
 				   atomic_read(&q->block_count),
 				   atomic_read(&q->block_read) ? 'r' : '-',
 				   atomic_read(&q->block_read) ? 'r' : '-',
 				   atomic_read(&q->block_write) ? 'w' : '-',
 				   atomic_read(&q->block_write) ? 'w' : '-',
-				   waitqueue_active(&q->read_queue) ? 'r':'-',
-				   waitqueue_active(&q->write_queue) ? 'w':'-',
-				   waitqueue_active(&q->flush_queue) ? 'f':'-',
+				   waitqueue_active(&q->read_queue) ? 'r' : '-',
+				   waitqueue_active(&q->
+						    write_queue) ? 'w' : '-',
+				   waitqueue_active(&q->
+						    flush_queue) ? 'f' : '-',
 				   DRM_BUFCOUNT(&q->waitlist));
 				   DRM_BUFCOUNT(&q->waitlist));
 		atomic_dec(&q->use_count);
 		atomic_dec(&q->use_count);
 	}
 	}
 
 
-	if (len > request + offset) return request;
+	if (len > request + offset)
+		return request;
 	*eof = 1;
 	*eof = 1;
 	return len - offset;
 	return len - offset;
 }
 }
@@ -329,10 +336,10 @@ static int drm__queues_info(char *buf, char **start, off_t offset,
  * Simply calls _queues_info() while holding the drm_device::struct_sem lock.
  * Simply calls _queues_info() while holding the drm_device::struct_sem lock.
  */
  */
 static int drm_queues_info(char *buf, char **start, off_t offset, int request,
 static int drm_queues_info(char *buf, char **start, off_t offset, int request,
-			    int *eof, void *data)
+			   int *eof, void *data)
 {
 {
-	drm_device_t *dev = (drm_device_t *)data;
-	int	     ret;
+	drm_device_t *dev = (drm_device_t *) data;
+	int ret;
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 	ret = drm__queues_info(buf, start, offset, request, eof, data);
 	ret = drm__queues_info(buf, start, offset, request, eof, data);
@@ -342,7 +349,7 @@ static int drm_queues_info(char *buf, char **start, off_t offset, int request,
 
 
 /**
 /**
  * Called when "/proc/dri/.../bufs" is read.
  * Called when "/proc/dri/.../bufs" is read.
- * 
+ *
  * \param buf output buffer.
  * \param buf output buffer.
  * \param start start of output data.
  * \param start start of output data.
  * \param offset requested start offset.
  * \param offset requested start offset.
@@ -352,12 +359,12 @@ static int drm_queues_info(char *buf, char **start, off_t offset, int request,
  * \return number of written bytes.
  * \return number of written bytes.
  */
  */
 static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
 static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
-			   int *eof, void *data)
+			  int *eof, void *data)
 {
 {
-	drm_device_t	 *dev = (drm_device_t *)data;
-	int              len  = 0;
+	drm_device_t *dev = (drm_device_t *) data;
+	int len = 0;
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
-	int		 i;
+	int i;
 
 
 	if (!dma || offset > DRM_PROC_LIMIT) {
 	if (!dma || offset > DRM_PROC_LIMIT) {
 		*eof = 1;
 		*eof = 1;
@@ -365,7 +372,7 @@ static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
 	}
 	}
 
 
 	*start = &buf[offset];
 	*start = &buf[offset];
-	*eof   = 0;
+	*eof = 0;
 
 
 	DRM_PROC_PRINT(" o     size count  free	 segs pages    kB\n\n");
 	DRM_PROC_PRINT(" o     size count  free	 segs pages    kB\n\n");
 	for (i = 0; i <= DRM_MAX_ORDER; i++) {
 	for (i = 0; i <= DRM_MAX_ORDER; i++) {
@@ -378,19 +385,21 @@ static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
 						   .freelist.count),
 						   .freelist.count),
 				       dma->bufs[i].seg_count,
 				       dma->bufs[i].seg_count,
 				       dma->bufs[i].seg_count
 				       dma->bufs[i].seg_count
-				       *(1 << dma->bufs[i].page_order),
+				       * (1 << dma->bufs[i].page_order),
 				       (dma->bufs[i].seg_count
 				       (dma->bufs[i].seg_count
 					* (1 << dma->bufs[i].page_order))
 					* (1 << dma->bufs[i].page_order))
 				       * PAGE_SIZE / 1024);
 				       * PAGE_SIZE / 1024);
 	}
 	}
 	DRM_PROC_PRINT("\n");
 	DRM_PROC_PRINT("\n");
 	for (i = 0; i < dma->buf_count; i++) {
 	for (i = 0; i < dma->buf_count; i++) {
-		if (i && !(i%32)) DRM_PROC_PRINT("\n");
+		if (i && !(i % 32))
+			DRM_PROC_PRINT("\n");
 		DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
 		DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
 	}
 	}
 	DRM_PROC_PRINT("\n");
 	DRM_PROC_PRINT("\n");
 
 
-	if (len > request + offset) return request;
+	if (len > request + offset)
+		return request;
 	*eof = 1;
 	*eof = 1;
 	return len - offset;
 	return len - offset;
 }
 }
@@ -399,10 +408,10 @@ static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
  * Simply calls _bufs_info() while holding the drm_device::struct_sem lock.
  * Simply calls _bufs_info() while holding the drm_device::struct_sem lock.
  */
  */
 static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
 static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
-			  int *eof, void *data)
+			 int *eof, void *data)
 {
 {
-	drm_device_t *dev = (drm_device_t *)data;
-	int	     ret;
+	drm_device_t *dev = (drm_device_t *) data;
+	int ret;
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 	ret = drm__bufs_info(buf, start, offset, request, eof, data);
 	ret = drm__bufs_info(buf, start, offset, request, eof, data);
@@ -412,7 +421,7 @@ static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
 
 
 /**
 /**
  * Called when "/proc/dri/.../clients" is read.
  * Called when "/proc/dri/.../clients" is read.
- * 
+ *
  * \param buf output buffer.
  * \param buf output buffer.
  * \param start start of output data.
  * \param start start of output data.
  * \param offset requested start offset.
  * \param offset requested start offset.
@@ -422,11 +431,11 @@ static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
  * \return number of written bytes.
  * \return number of written bytes.
  */
  */
 static int drm__clients_info(char *buf, char **start, off_t offset,
 static int drm__clients_info(char *buf, char **start, off_t offset,
-			      int request, int *eof, void *data)
+			     int request, int *eof, void *data)
 {
 {
-	drm_device_t *dev = (drm_device_t *)data;
-	int          len  = 0;
-	drm_file_t   *priv;
+	drm_device_t *dev = (drm_device_t *) data;
+	int len = 0;
+	drm_file_t *priv;
 
 
 	if (offset > DRM_PROC_LIMIT) {
 	if (offset > DRM_PROC_LIMIT) {
 		*eof = 1;
 		*eof = 1;
@@ -434,7 +443,7 @@ static int drm__clients_info(char *buf, char **start, off_t offset,
 	}
 	}
 
 
 	*start = &buf[offset];
 	*start = &buf[offset];
-	*eof   = 0;
+	*eof = 0;
 
 
 	DRM_PROC_PRINT("a dev	pid    uid	magic	  ioctls\n\n");
 	DRM_PROC_PRINT("a dev	pid    uid	magic	  ioctls\n\n");
 	for (priv = dev->file_first; priv; priv = priv->next) {
 	for (priv = dev->file_first; priv; priv = priv->next) {
@@ -442,12 +451,11 @@ static int drm__clients_info(char *buf, char **start, off_t offset,
 			       priv->authenticated ? 'y' : 'n',
 			       priv->authenticated ? 'y' : 'n',
 			       priv->minor,
 			       priv->minor,
 			       priv->pid,
 			       priv->pid,
-			       priv->uid,
-			       priv->magic,
-			       priv->ioctl_count);
+			       priv->uid, priv->magic, priv->ioctl_count);
 	}
 	}
 
 
-	if (len > request + offset) return request;
+	if (len > request + offset)
+		return request;
 	*eof = 1;
 	*eof = 1;
 	return len - offset;
 	return len - offset;
 }
 }
@@ -456,10 +464,10 @@ static int drm__clients_info(char *buf, char **start, off_t offset,
  * Simply calls _clients_info() while holding the drm_device::struct_sem lock.
  * Simply calls _clients_info() while holding the drm_device::struct_sem lock.
  */
  */
 static int drm_clients_info(char *buf, char **start, off_t offset,
 static int drm_clients_info(char *buf, char **start, off_t offset,
-			     int request, int *eof, void *data)
+			    int request, int *eof, void *data)
 {
 {
-	drm_device_t *dev = (drm_device_t *)data;
-	int	     ret;
+	drm_device_t *dev = (drm_device_t *) data;
+	int ret;
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 	ret = drm__clients_info(buf, start, offset, request, eof, data);
 	ret = drm__clients_info(buf, start, offset, request, eof, data);
@@ -470,14 +478,14 @@ static int drm_clients_info(char *buf, char **start, off_t offset,
 #if DRM_DEBUG_CODE
 #if DRM_DEBUG_CODE
 
 
 static int drm__vma_info(char *buf, char **start, off_t offset, int request,
 static int drm__vma_info(char *buf, char **start, off_t offset, int request,
-			  int *eof, void *data)
+			 int *eof, void *data)
 {
 {
-	drm_device_t	      *dev = (drm_device_t *)data;
-	int                   len  = 0;
-	drm_vma_entry_t	      *pt;
+	drm_device_t *dev = (drm_device_t *) data;
+	int len = 0;
+	drm_vma_entry_t *pt;
 	struct vm_area_struct *vma;
 	struct vm_area_struct *vma;
 #if defined(__i386__)
 #if defined(__i386__)
-	unsigned int	      pgprot;
+	unsigned int pgprot;
 #endif
 #endif
 
 
 	if (offset > DRM_PROC_LIMIT) {
 	if (offset > DRM_PROC_LIMIT) {
@@ -486,51 +494,53 @@ static int drm__vma_info(char *buf, char **start, off_t offset, int request,
 	}
 	}
 
 
 	*start = &buf[offset];
 	*start = &buf[offset];
-	*eof   = 0;
+	*eof = 0;
 
 
 	DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
 	DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
 		       atomic_read(&dev->vma_count),
 		       atomic_read(&dev->vma_count),
 		       high_memory, virt_to_phys(high_memory));
 		       high_memory, virt_to_phys(high_memory));
 	for (pt = dev->vmalist; pt; pt = pt->next) {
 	for (pt = dev->vmalist; pt; pt = pt->next) {
-		if (!(vma = pt->vma)) continue;
+		if (!(vma = pt->vma))
+			continue;
 		DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx",
 		DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx",
 			       pt->pid,
 			       pt->pid,
 			       vma->vm_start,
 			       vma->vm_start,
 			       vma->vm_end,
 			       vma->vm_end,
-			       vma->vm_flags & VM_READ	   ? 'r' : '-',
-			       vma->vm_flags & VM_WRITE	   ? 'w' : '-',
-			       vma->vm_flags & VM_EXEC	   ? 'x' : '-',
+			       vma->vm_flags & VM_READ ? 'r' : '-',
+			       vma->vm_flags & VM_WRITE ? 'w' : '-',
+			       vma->vm_flags & VM_EXEC ? 'x' : '-',
 			       vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
 			       vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
-			       vma->vm_flags & VM_LOCKED   ? 'l' : '-',
-			       vma->vm_flags & VM_IO	   ? 'i' : '-',
+			       vma->vm_flags & VM_LOCKED ? 'l' : '-',
+			       vma->vm_flags & VM_IO ? 'i' : '-',
 			       VM_OFFSET(vma));
 			       VM_OFFSET(vma));
 
 
 #if defined(__i386__)
 #if defined(__i386__)
 		pgprot = pgprot_val(vma->vm_page_prot);
 		pgprot = pgprot_val(vma->vm_page_prot);
 		DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
 		DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
-			       pgprot & _PAGE_PRESENT  ? 'p' : '-',
-			       pgprot & _PAGE_RW       ? 'w' : 'r',
-			       pgprot & _PAGE_USER     ? 'u' : 's',
-			       pgprot & _PAGE_PWT      ? 't' : 'b',
-			       pgprot & _PAGE_PCD      ? 'u' : 'c',
+			       pgprot & _PAGE_PRESENT ? 'p' : '-',
+			       pgprot & _PAGE_RW ? 'w' : 'r',
+			       pgprot & _PAGE_USER ? 'u' : 's',
+			       pgprot & _PAGE_PWT ? 't' : 'b',
+			       pgprot & _PAGE_PCD ? 'u' : 'c',
 			       pgprot & _PAGE_ACCESSED ? 'a' : '-',
 			       pgprot & _PAGE_ACCESSED ? 'a' : '-',
-			       pgprot & _PAGE_DIRTY    ? 'd' : '-',
-			       pgprot & _PAGE_PSE      ? 'm' : 'k',
-			       pgprot & _PAGE_GLOBAL   ? 'g' : 'l' );
+			       pgprot & _PAGE_DIRTY ? 'd' : '-',
+			       pgprot & _PAGE_PSE ? 'm' : 'k',
+			       pgprot & _PAGE_GLOBAL ? 'g' : 'l');
 #endif
 #endif
 		DRM_PROC_PRINT("\n");
 		DRM_PROC_PRINT("\n");
 	}
 	}
 
 
-	if (len > request + offset) return request;
+	if (len > request + offset)
+		return request;
 	*eof = 1;
 	*eof = 1;
 	return len - offset;
 	return len - offset;
 }
 }
 
 
 static int drm_vma_info(char *buf, char **start, off_t offset, int request,
 static int drm_vma_info(char *buf, char **start, off_t offset, int request,
-			 int *eof, void *data)
+			int *eof, void *data)
 {
 {
-	drm_device_t *dev = (drm_device_t *)data;
-	int	     ret;
+	drm_device_t *dev = (drm_device_t *) data;
+	int ret;
 
 
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 	ret = drm__vma_info(buf, start, offset, request, eof, data);
 	ret = drm__vma_info(buf, start, offset, request, eof, data);
@@ -538,5 +548,3 @@ static int drm_vma_info(char *buf, char **start, off_t offset, int request,
 	return ret;
 	return ret;
 }
 }
 #endif
 #endif
-
-

+ 15 - 15
drivers/char/drm/drm_sarea.h

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_sarea.h 
+ * \file drm_sarea.h
  * \brief SAREA definitions
  * \brief SAREA definitions
  *
  *
  * \author Michel Dänzer <michel@daenzer.net>
  * \author Michel Dänzer <michel@daenzer.net>
@@ -38,7 +38,7 @@
 #if defined(__alpha__)
 #if defined(__alpha__)
 #define SAREA_MAX                       0x2000
 #define SAREA_MAX                       0x2000
 #elif defined(__ia64__)
 #elif defined(__ia64__)
-#define SAREA_MAX                       0x10000         /* 64kB */
+#define SAREA_MAX                       0x10000	/* 64kB */
 #else
 #else
 /* Intel 830M driver needs at least 8k SAREA */
 /* Intel 830M driver needs at least 8k SAREA */
 #define SAREA_MAX                       0x2000
 #define SAREA_MAX                       0x2000
@@ -51,28 +51,28 @@
 
 
 /** SAREA drawable */
 /** SAREA drawable */
 typedef struct drm_sarea_drawable {
 typedef struct drm_sarea_drawable {
-    unsigned int	stamp;
-    unsigned int	flags;
+	unsigned int stamp;
+	unsigned int flags;
 } drm_sarea_drawable_t;
 } drm_sarea_drawable_t;
 
 
 /** SAREA frame */
 /** SAREA frame */
 typedef struct drm_sarea_frame {
 typedef struct drm_sarea_frame {
-    unsigned int        x;
-    unsigned int        y;
-    unsigned int        width;
-    unsigned int        height;
-    unsigned int        fullscreen;
+	unsigned int x;
+	unsigned int y;
+	unsigned int width;
+	unsigned int height;
+	unsigned int fullscreen;
 } drm_sarea_frame_t;
 } drm_sarea_frame_t;
 
 
 /** SAREA */
 /** SAREA */
 typedef struct drm_sarea {
 typedef struct drm_sarea {
     /** first thing is always the DRM locking structure */
     /** first thing is always the DRM locking structure */
-    drm_hw_lock_t		lock;
+	drm_hw_lock_t lock;
     /** \todo Use readers/writer lock for drm_sarea::drawable_lock */
     /** \todo Use readers/writer lock for drm_sarea::drawable_lock */
-    drm_hw_lock_t		drawable_lock;
-    drm_sarea_drawable_t	drawableTable[SAREA_MAX_DRAWABLES];	/**< drawables */
-    drm_sarea_frame_t		frame;	/**< frame */
-    drm_context_t		dummy_context;
+	drm_hw_lock_t drawable_lock;
+	drm_sarea_drawable_t drawableTable[SAREA_MAX_DRAWABLES];	/**< drawables */
+	drm_sarea_frame_t frame;	/**< frame */
+	drm_context_t dummy_context;
 } drm_sarea_t;
 } drm_sarea_t;
 
 
-#endif	/* _DRM_SAREA_H_ */
+#endif				/* _DRM_SAREA_H_ */

+ 87 - 96
drivers/char/drm/drm_scatter.c

@@ -1,5 +1,5 @@
 /**
 /**
- * \file drm_scatter.h 
+ * \file drm_scatter.c
  * IOCTLs to manage scatter/gather memory
  * IOCTLs to manage scatter/gather memory
  *
  *
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
@@ -37,28 +37,24 @@
 
 
 #define DEBUG_SCATTER 0
 #define DEBUG_SCATTER 0
 
 
-void drm_sg_cleanup( drm_sg_mem_t *entry )
+void drm_sg_cleanup(drm_sg_mem_t * entry)
 {
 {
 	struct page *page;
 	struct page *page;
 	int i;
 	int i;
 
 
-	for ( i = 0 ; i < entry->pages ; i++ ) {
+	for (i = 0; i < entry->pages; i++) {
 		page = entry->pagelist[i];
 		page = entry->pagelist[i];
-		if ( page )
-			ClearPageReserved( page );
+		if (page)
+			ClearPageReserved(page);
 	}
 	}
 
 
-	vfree( entry->virtual );
-
-	drm_free( entry->busaddr,
-		   entry->pages * sizeof(*entry->busaddr),
-		   DRM_MEM_PAGES );
-	drm_free( entry->pagelist,
-		   entry->pages * sizeof(*entry->pagelist),
-		   DRM_MEM_PAGES );
-	drm_free( entry,
-		   sizeof(*entry),
-		   DRM_MEM_SGLISTS );
+	vfree(entry->virtual);
+
+	drm_free(entry->busaddr,
+		 entry->pages * sizeof(*entry->busaddr), DRM_MEM_PAGES);
+	drm_free(entry->pagelist,
+		 entry->pages * sizeof(*entry->pagelist), DRM_MEM_PAGES);
+	drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
 }
 }
 
 
 #ifdef _LP64
 #ifdef _LP64
@@ -67,8 +63,8 @@ void drm_sg_cleanup( drm_sg_mem_t *entry )
 # define ScatterHandle(x) (unsigned int)(x)
 # define ScatterHandle(x) (unsigned int)(x)
 #endif
 #endif
 
 
-int drm_sg_alloc( struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg )
+int drm_sg_alloc(struct inode *inode, struct file *filp,
+		 unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -77,75 +73,70 @@ int drm_sg_alloc( struct inode *inode, struct file *filp,
 	drm_sg_mem_t *entry;
 	drm_sg_mem_t *entry;
 	unsigned long pages, i, j;
 	unsigned long pages, i, j;
 
 
-	DRM_DEBUG( "%s\n", __FUNCTION__ );
+	DRM_DEBUG("%s\n", __FUNCTION__);
 
 
 	if (!drm_core_check_feature(dev, DRIVER_SG))
 	if (!drm_core_check_feature(dev, DRIVER_SG))
 		return -EINVAL;
 		return -EINVAL;
 
 
-	if ( dev->sg )
+	if (dev->sg)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	if ( copy_from_user( &request, argp, sizeof(request) ) )
+	if (copy_from_user(&request, argp, sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	entry = drm_alloc( sizeof(*entry), DRM_MEM_SGLISTS );
-	if ( !entry )
+	entry = drm_alloc(sizeof(*entry), DRM_MEM_SGLISTS);
+	if (!entry)
 		return -ENOMEM;
 		return -ENOMEM;
 
 
-   	memset( entry, 0, sizeof(*entry) );
+	memset(entry, 0, sizeof(*entry));
 
 
 	pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
 	pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
-	DRM_DEBUG( "sg size=%ld pages=%ld\n", request.size, pages );
+	DRM_DEBUG("sg size=%ld pages=%ld\n", request.size, pages);
 
 
 	entry->pages = pages;
 	entry->pages = pages;
-	entry->pagelist = drm_alloc( pages * sizeof(*entry->pagelist),
-				     DRM_MEM_PAGES );
-	if ( !entry->pagelist ) {
-		drm_free( entry, sizeof(*entry), DRM_MEM_SGLISTS );
+	entry->pagelist = drm_alloc(pages * sizeof(*entry->pagelist),
+				    DRM_MEM_PAGES);
+	if (!entry->pagelist) {
+		drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 
 
 	memset(entry->pagelist, 0, pages * sizeof(*entry->pagelist));
 	memset(entry->pagelist, 0, pages * sizeof(*entry->pagelist));
 
 
-	entry->busaddr = drm_alloc( pages * sizeof(*entry->busaddr),
-				     DRM_MEM_PAGES );
-	if ( !entry->busaddr ) {
-		drm_free( entry->pagelist,
-			   entry->pages * sizeof(*entry->pagelist),
-			   DRM_MEM_PAGES );
-		drm_free( entry,
-			   sizeof(*entry),
-			   DRM_MEM_SGLISTS );
+	entry->busaddr = drm_alloc(pages * sizeof(*entry->busaddr),
+				   DRM_MEM_PAGES);
+	if (!entry->busaddr) {
+		drm_free(entry->pagelist,
+			 entry->pages * sizeof(*entry->pagelist),
+			 DRM_MEM_PAGES);
+		drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
-	memset( (void *)entry->busaddr, 0, pages * sizeof(*entry->busaddr) );
-
-	entry->virtual = vmalloc_32( pages << PAGE_SHIFT );
-	if ( !entry->virtual ) {
-		drm_free( entry->busaddr,
-			   entry->pages * sizeof(*entry->busaddr),
-			   DRM_MEM_PAGES );
-		drm_free( entry->pagelist,
-			   entry->pages * sizeof(*entry->pagelist),
-			   DRM_MEM_PAGES );
-		drm_free( entry,
-			   sizeof(*entry),
-			   DRM_MEM_SGLISTS );
+	memset((void *)entry->busaddr, 0, pages * sizeof(*entry->busaddr));
+
+	entry->virtual = vmalloc_32(pages << PAGE_SHIFT);
+	if (!entry->virtual) {
+		drm_free(entry->busaddr,
+			 entry->pages * sizeof(*entry->busaddr), DRM_MEM_PAGES);
+		drm_free(entry->pagelist,
+			 entry->pages * sizeof(*entry->pagelist),
+			 DRM_MEM_PAGES);
+		drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 
 
 	/* This also forces the mapping of COW pages, so our page list
 	/* This also forces the mapping of COW pages, so our page list
 	 * will be valid.  Please don't remove it...
 	 * will be valid.  Please don't remove it...
 	 */
 	 */
-	memset( entry->virtual, 0, pages << PAGE_SHIFT );
+	memset(entry->virtual, 0, pages << PAGE_SHIFT);
 
 
 	entry->handle = ScatterHandle((unsigned long)entry->virtual);
 	entry->handle = ScatterHandle((unsigned long)entry->virtual);
 
 
-	DRM_DEBUG( "sg alloc handle  = %08lx\n", entry->handle );
-	DRM_DEBUG( "sg alloc virtual = %p\n", entry->virtual );
+	DRM_DEBUG("sg alloc handle  = %08lx\n", entry->handle);
+	DRM_DEBUG("sg alloc virtual = %p\n", entry->virtual);
 
 
-	for (i = (unsigned long)entry->virtual, j = 0; j < pages; 
-		i += PAGE_SIZE, j++) {
+	for (i = (unsigned long)entry->virtual, j = 0; j < pages;
+	     i += PAGE_SIZE, j++) {
 		entry->pagelist[j] = vmalloc_to_page((void *)i);
 		entry->pagelist[j] = vmalloc_to_page((void *)i);
 		if (!entry->pagelist[j])
 		if (!entry->pagelist[j])
 			goto failed;
 			goto failed;
@@ -154,8 +145,8 @@ int drm_sg_alloc( struct inode *inode, struct file *filp,
 
 
 	request.handle = entry->handle;
 	request.handle = entry->handle;
 
 
-	if ( copy_to_user( argp, &request, sizeof(request) ) ) {
-		drm_sg_cleanup( entry );
+	if (copy_to_user(argp, &request, sizeof(request))) {
+		drm_sg_cleanup(entry);
 		return -EFAULT;
 		return -EFAULT;
 	}
 	}
 
 
@@ -166,50 +157,50 @@ int drm_sg_alloc( struct inode *inode, struct file *filp,
 	 * versa.
 	 * versa.
 	 */
 	 */
 	{
 	{
-	int error = 0;
+		int error = 0;
 
 
-	for ( i = 0 ; i < pages ; i++ ) {
-		unsigned long *tmp;
+		for (i = 0; i < pages; i++) {
+			unsigned long *tmp;
 
 
-		tmp = page_address( entry->pagelist[i] );
-		for ( j = 0 ;
-		      j < PAGE_SIZE / sizeof(unsigned long) ;
-		      j++, tmp++ ) {
-			*tmp = 0xcafebabe;
-		}
-		tmp = (unsigned long *)((u8 *)entry->virtual +
-					(PAGE_SIZE * i));
-		for( j = 0 ;
-		     j < PAGE_SIZE / sizeof(unsigned long) ;
-		     j++, tmp++ ) {
-			if ( *tmp != 0xcafebabe && error == 0 ) {
-				error = 1;
-				DRM_ERROR( "Scatter allocation error, "
-					   "pagelist does not match "
-					   "virtual mapping\n" );
+			tmp = page_address(entry->pagelist[i]);
+			for (j = 0;
+			     j < PAGE_SIZE / sizeof(unsigned long);
+			     j++, tmp++) {
+				*tmp = 0xcafebabe;
+			}
+			tmp = (unsigned long *)((u8 *) entry->virtual +
+						(PAGE_SIZE * i));
+			for (j = 0;
+			     j < PAGE_SIZE / sizeof(unsigned long);
+			     j++, tmp++) {
+				if (*tmp != 0xcafebabe && error == 0) {
+					error = 1;
+					DRM_ERROR("Scatter allocation error, "
+						  "pagelist does not match "
+						  "virtual mapping\n");
+				}
+			}
+			tmp = page_address(entry->pagelist[i]);
+			for (j = 0;
+			     j < PAGE_SIZE / sizeof(unsigned long);
+			     j++, tmp++) {
+				*tmp = 0;
 			}
 			}
 		}
 		}
-		tmp = page_address( entry->pagelist[i] );
-		for(j = 0 ;
-		    j < PAGE_SIZE / sizeof(unsigned long) ;
-		    j++, tmp++) {
-			*tmp = 0;
-		}
-	}
-	if (error == 0)
-		DRM_ERROR( "Scatter allocation matches pagelist\n" );
+		if (error == 0)
+			DRM_ERROR("Scatter allocation matches pagelist\n");
 	}
 	}
 #endif
 #endif
 
 
 	return 0;
 	return 0;
 
 
- failed:
-	drm_sg_cleanup( entry );
+      failed:
+	drm_sg_cleanup(entry);
 	return -ENOMEM;
 	return -ENOMEM;
 }
 }
 
 
-int drm_sg_free( struct inode *inode, struct file *filp,
-		 unsigned int cmd, unsigned long arg )
+int drm_sg_free(struct inode *inode, struct file *filp,
+		unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -219,20 +210,20 @@ int drm_sg_free( struct inode *inode, struct file *filp,
 	if (!drm_core_check_feature(dev, DRIVER_SG))
 	if (!drm_core_check_feature(dev, DRIVER_SG))
 		return -EINVAL;
 		return -EINVAL;
 
 
-	if ( copy_from_user( &request,
-			     (drm_scatter_gather_t __user *)arg,
-			     sizeof(request) ) )
+	if (copy_from_user(&request,
+			   (drm_scatter_gather_t __user *) arg,
+			   sizeof(request)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	entry = dev->sg;
 	entry = dev->sg;
 	dev->sg = NULL;
 	dev->sg = NULL;
 
 
-	if ( !entry || entry->handle != request.handle )
+	if (!entry || entry->handle != request.handle)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	DRM_DEBUG( "sg free virtual  = %p\n", entry->virtual );
+	DRM_DEBUG("sg free virtual  = %p\n", entry->virtual);
 
 
-	drm_sg_cleanup( entry );
+	drm_sg_cleanup(entry);
 
 
 	return 0;
 	return 0;
 }
 }

+ 59 - 53
drivers/char/drm/drm_stub.c

@@ -37,11 +37,11 @@
 #include "drm_core.h"
 #include "drm_core.h"
 
 
 unsigned int drm_cards_limit = 16;	/* Enough for one machine */
 unsigned int drm_cards_limit = 16;	/* Enough for one machine */
-unsigned int drm_debug = 0;		/* 1 to enable debug output */
+unsigned int drm_debug = 0;	/* 1 to enable debug output */
 EXPORT_SYMBOL(drm_debug);
 EXPORT_SYMBOL(drm_debug);
 
 
-MODULE_AUTHOR( CORE_AUTHOR );
-MODULE_DESCRIPTION( CORE_DESC );
+MODULE_AUTHOR(CORE_AUTHOR);
+MODULE_DESCRIPTION(CORE_DESC);
 MODULE_LICENSE("GPL and additional rights");
 MODULE_LICENSE("GPL and additional rights");
 MODULE_PARM_DESC(cards_limit, "Maximum number of graphics cards");
 MODULE_PARM_DESC(cards_limit, "Maximum number of graphics cards");
 MODULE_PARM_DESC(debug, "Enable debug output");
 MODULE_PARM_DESC(debug, "Enable debug output");
@@ -53,19 +53,21 @@ drm_head_t **drm_heads;
 struct drm_sysfs_class *drm_class;
 struct drm_sysfs_class *drm_class;
 struct proc_dir_entry *drm_proc_root;
 struct proc_dir_entry *drm_proc_root;
 
 
-static int drm_fill_in_dev(drm_device_t *dev, struct pci_dev *pdev, const struct pci_device_id *ent, struct drm_driver *driver)
+static int drm_fill_in_dev(drm_device_t * dev, struct pci_dev *pdev,
+			   const struct pci_device_id *ent,
+			   struct drm_driver *driver)
 {
 {
 	int retcode;
 	int retcode;
 
 
 	spin_lock_init(&dev->count_lock);
 	spin_lock_init(&dev->count_lock);
-	init_timer( &dev->timer );
-	sema_init( &dev->struct_sem, 1 );
-	sema_init( &dev->ctxlist_sem, 1 );
+	init_timer(&dev->timer);
+	sema_init(&dev->struct_sem, 1);
+	sema_init(&dev->ctxlist_sem, 1);
 
 
-	dev->pdev   = pdev;
+	dev->pdev = pdev;
 
 
 #ifdef __alpha__
 #ifdef __alpha__
-	dev->hose   = pdev->sysdata;
+	dev->hose = pdev->sysdata;
 	dev->pci_domain = dev->hose->bus->number;
 	dev->pci_domain = dev->hose->bus->number;
 #else
 #else
 	dev->pci_domain = 0;
 	dev->pci_domain = 0;
@@ -82,15 +84,15 @@ static int drm_fill_in_dev(drm_device_t *dev, struct pci_dev *pdev, const struct
 
 
 	/* the DRM has 6 basic counters */
 	/* the DRM has 6 basic counters */
 	dev->counters = 6;
 	dev->counters = 6;
-	dev->types[0]  = _DRM_STAT_LOCK;
-	dev->types[1]  = _DRM_STAT_OPENS;
-	dev->types[2]  = _DRM_STAT_CLOSES;
-	dev->types[3]  = _DRM_STAT_IOCTLS;
-	dev->types[4]  = _DRM_STAT_LOCKS;
-	dev->types[5]  = _DRM_STAT_UNLOCKS;
+	dev->types[0] = _DRM_STAT_LOCK;
+	dev->types[1] = _DRM_STAT_OPENS;
+	dev->types[2] = _DRM_STAT_CLOSES;
+	dev->types[3] = _DRM_STAT_IOCTLS;
+	dev->types[4] = _DRM_STAT_LOCKS;
+	dev->types[5] = _DRM_STAT_UNLOCKS;
 
 
 	dev->driver = driver;
 	dev->driver = driver;
-	
+
 	if (dev->driver->preinit)
 	if (dev->driver->preinit)
 		if ((retcode = dev->driver->preinit(dev, ent->driver_data)))
 		if ((retcode = dev->driver->preinit(dev, ent->driver_data)))
 			goto error_out_unreg;
 			goto error_out_unreg;
@@ -98,29 +100,30 @@ static int drm_fill_in_dev(drm_device_t *dev, struct pci_dev *pdev, const struct
 	if (drm_core_has_AGP(dev)) {
 	if (drm_core_has_AGP(dev)) {
 		if (drm_device_is_agp(dev))
 		if (drm_device_is_agp(dev))
 			dev->agp = drm_agp_init(dev);
 			dev->agp = drm_agp_init(dev);
-		if (drm_core_check_feature(dev, DRIVER_REQUIRE_AGP) && (dev->agp == NULL)) {
-			DRM_ERROR( "Cannot initialize the agpgart module.\n" );
+		if (drm_core_check_feature(dev, DRIVER_REQUIRE_AGP)
+		    && (dev->agp == NULL)) {
+			DRM_ERROR("Cannot initialize the agpgart module.\n");
 			retcode = -EINVAL;
 			retcode = -EINVAL;
 			goto error_out_unreg;
 			goto error_out_unreg;
 		}
 		}
 		if (drm_core_has_MTRR(dev)) {
 		if (drm_core_has_MTRR(dev)) {
 			if (dev->agp)
 			if (dev->agp)
-				dev->agp->agp_mtrr = mtrr_add( dev->agp->agp_info.aper_base,
-							       dev->agp->agp_info.aper_size*1024*1024,
-							       MTRR_TYPE_WRCOMB,
-							       1 );
+				dev->agp->agp_mtrr =
+				    mtrr_add(dev->agp->agp_info.aper_base,
+					     dev->agp->agp_info.aper_size *
+					     1024 * 1024, MTRR_TYPE_WRCOMB, 1);
 		}
 		}
 	}
 	}
 
 
-	retcode = drm_ctxbitmap_init( dev );
-	if( retcode ) {
-		DRM_ERROR( "Cannot allocate memory for context bitmap.\n" );
+	retcode = drm_ctxbitmap_init(dev);
+	if (retcode) {
+		DRM_ERROR("Cannot allocate memory for context bitmap.\n");
 		goto error_out_unreg;
 		goto error_out_unreg;
 	}
 	}
 
 
 	return 0;
 	return 0;
-	
-error_out_unreg:
+
+      error_out_unreg:
 	drm_takedown(dev);
 	drm_takedown(dev);
 	return retcode;
 	return retcode;
 }
 }
@@ -140,7 +143,7 @@ int drm_stub_open(struct inode *inode, struct file *filp)
 	int minor = iminor(inode);
 	int minor = iminor(inode);
 	int err = -ENODEV;
 	int err = -ENODEV;
 	struct file_operations *old_fops;
 	struct file_operations *old_fops;
-	
+
 	DRM_DEBUG("\n");
 	DRM_DEBUG("\n");
 
 
 	if (!((minor >= 0) && (minor < drm_cards_limit)))
 	if (!((minor >= 0) && (minor < drm_cards_limit)))
@@ -148,7 +151,7 @@ int drm_stub_open(struct inode *inode, struct file *filp)
 
 
 	if (!drm_heads[minor])
 	if (!drm_heads[minor])
 		return -ENODEV;
 		return -ENODEV;
-	
+
 	if (!(dev = drm_heads[minor]->dev))
 	if (!(dev = drm_heads[minor]->dev))
 		return -ENODEV;
 		return -ENODEV;
 
 
@@ -174,7 +177,7 @@ int drm_stub_open(struct inode *inode, struct file *filp)
  * create the proc init entry via proc_init(). This routines assigns
  * create the proc init entry via proc_init(). This routines assigns
  * minor numbers to secondary heads of multi-headed cards
  * minor numbers to secondary heads of multi-headed cards
  */
  */
-static int drm_get_head(drm_device_t *dev, drm_head_t *head)
+static int drm_get_head(drm_device_t * dev, drm_head_t * head)
 {
 {
 	drm_head_t **heads = drm_heads;
 	drm_head_t **heads = drm_heads;
 	int ret;
 	int ret;
@@ -184,26 +187,27 @@ static int drm_get_head(drm_device_t *dev, drm_head_t *head)
 
 
 	for (minor = 0; minor < drm_cards_limit; minor++, heads++) {
 	for (minor = 0; minor < drm_cards_limit; minor++, heads++) {
 		if (!*heads) {
 		if (!*heads) {
-			
+
 			*head = (drm_head_t) {
 			*head = (drm_head_t) {
-				.dev = dev,
-				.device = MKDEV(DRM_MAJOR, minor),
-				.minor = minor,
-			};
-			
-			if ((ret = drm_proc_init(dev, minor, drm_proc_root, &head->dev_root))) {
-				printk (KERN_ERR "DRM: Failed to initialize /proc/dri.\n");
+			.dev = dev,.device =
+				    MKDEV(DRM_MAJOR, minor),.minor = minor,};
+
+			if ((ret =
+			     drm_proc_init(dev, minor, drm_proc_root,
+					   &head->dev_root))) {
+				printk(KERN_ERR
+				       "DRM: Failed to initialize /proc/dri.\n");
 				goto err_g1;
 				goto err_g1;
 			}
 			}
 
 
-			
 			head->dev_class = drm_sysfs_device_add(drm_class,
 			head->dev_class = drm_sysfs_device_add(drm_class,
 							       MKDEV(DRM_MAJOR,
 							       MKDEV(DRM_MAJOR,
 								     minor),
 								     minor),
 							       &dev->pdev->dev,
 							       &dev->pdev->dev,
 							       "card%d", minor);
 							       "card%d", minor);
 			if (IS_ERR(head->dev_class)) {
 			if (IS_ERR(head->dev_class)) {
-				printk(KERN_ERR "DRM: Error sysfs_device_add.\n");
+				printk(KERN_ERR
+				       "DRM: Error sysfs_device_add.\n");
 				ret = PTR_ERR(head->dev_class);
 				ret = PTR_ERR(head->dev_class);
 				goto err_g2;
 				goto err_g2;
 			}
 			}
@@ -215,13 +219,14 @@ static int drm_get_head(drm_device_t *dev, drm_head_t *head)
 	}
 	}
 	DRM_ERROR("out of minors\n");
 	DRM_ERROR("out of minors\n");
 	return -ENOMEM;
 	return -ENOMEM;
-err_g2:
+      err_g2:
 	drm_proc_cleanup(minor, drm_proc_root, head->dev_root);
 	drm_proc_cleanup(minor, drm_proc_root, head->dev_root);
-err_g1:
-	*head = (drm_head_t) {.dev = NULL};
+      err_g1:
+	*head = (drm_head_t) {
+	.dev = NULL};
 	return ret;
 	return ret;
 }
 }
-		
+
 /**
 /**
  * Register.
  * Register.
  *
  *
@@ -234,7 +239,7 @@ err_g1:
  * Try and register, if we fail to register, backout previous work.
  * Try and register, if we fail to register, backout previous work.
  */
  */
 int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
 int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
-	      struct drm_driver *driver)
+		struct drm_driver *driver)
 {
 {
 	drm_device_t *dev;
 	drm_device_t *dev;
 	int ret;
 	int ret;
@@ -261,10 +266,11 @@ int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
 
 
 	return 0;
 	return 0;
 
 
-err_g1:
+      err_g1:
 	drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
 	drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
 	return ret;
 	return ret;
 }
 }
+
 EXPORT_SYMBOL(drm_get_dev);
 EXPORT_SYMBOL(drm_get_dev);
 
 
 /**
 /**
@@ -305,19 +311,19 @@ int drm_put_dev(drm_device_t * dev)
  * last minor released.
  * last minor released.
  *
  *
  */
  */
-int drm_put_head(drm_head_t *head)
+int drm_put_head(drm_head_t * head)
 {
 {
 	int minor = head->minor;
 	int minor = head->minor;
-	
+
 	DRM_DEBUG("release secondary minor %d\n", minor);
 	DRM_DEBUG("release secondary minor %d\n", minor);
-	
+
 	drm_proc_cleanup(minor, drm_proc_root, head->dev_root);
 	drm_proc_cleanup(minor, drm_proc_root, head->dev_root);
 	drm_sysfs_device_remove(MKDEV(DRM_MAJOR, head->minor));
 	drm_sysfs_device_remove(MKDEV(DRM_MAJOR, head->minor));
-	
-	*head = (drm_head_t){.dev = NULL};
+
+	*head = (drm_head_t) {
+	.dev = NULL};
 
 
 	drm_heads[minor] = NULL;
 	drm_heads[minor] = NULL;
-	
+
 	return 0;
 	return 0;
 }
 }
-

+ 192 - 173
drivers/char/drm/drm_vm.c

@@ -1,7 +1,7 @@
 /**
 /**
- * \file drm_vm.h
+ * \file drm_vm.c
  * Memory mapping for DRM
  * Memory mapping for DRM
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
  */
@@ -47,32 +47,34 @@ static void drm_vm_close(struct vm_area_struct *vma);
  * \param vma virtual memory area.
  * \param vma virtual memory area.
  * \param address access address.
  * \param address access address.
  * \return pointer to the page structure.
  * \return pointer to the page structure.
- * 
+ *
  * Find the right map and if it's AGP memory find the real physical page to
  * Find the right map and if it's AGP memory find the real physical page to
  * map, get the page, increment the use count and return it.
  * map, get the page, increment the use count and return it.
  */
  */
 #if __OS_HAS_AGP
 #if __OS_HAS_AGP
 static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
 static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
-						 unsigned long address)
+						unsigned long address)
 {
 {
-	drm_file_t *priv  = vma->vm_file->private_data;
+	drm_file_t *priv = vma->vm_file->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
-	drm_map_t *map    = NULL;
-	drm_map_list_t  *r_list;
+	drm_map_t *map = NULL;
+	drm_map_list_t *r_list;
 	struct list_head *list;
 	struct list_head *list;
 
 
 	/*
 	/*
-         * Find the right map
-         */
+	 * Find the right map
+	 */
 	if (!drm_core_has_AGP(dev))
 	if (!drm_core_has_AGP(dev))
 		goto vm_nopage_error;
 		goto vm_nopage_error;
 
 
-	if(!dev->agp || !dev->agp->cant_use_aperture) goto vm_nopage_error;
+	if (!dev->agp || !dev->agp->cant_use_aperture)
+		goto vm_nopage_error;
 
 
 	list_for_each(list, &dev->maplist->head) {
 	list_for_each(list, &dev->maplist->head) {
 		r_list = list_entry(list, drm_map_list_t, head);
 		r_list = list_entry(list, drm_map_list_t, head);
 		map = r_list->map;
 		map = r_list->map;
-		if (!map) continue;
+		if (!map)
+			continue;
 		if (r_list->user_token == VM_OFFSET(vma))
 		if (r_list->user_token == VM_OFFSET(vma))
 			break;
 			break;
 	}
 	}
@@ -85,45 +87,47 @@ static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
 
 
 #ifdef __alpha__
 #ifdef __alpha__
 		/*
 		/*
-                 * Adjust to a bus-relative address
-                 */
+		 * Adjust to a bus-relative address
+		 */
 		baddr -= dev->hose->mem_space->start;
 		baddr -= dev->hose->mem_space->start;
 #endif
 #endif
 
 
 		/*
 		/*
-                 * It's AGP memory - find the real physical page to map
-                 */
-		for(agpmem = dev->agp->memory; agpmem; agpmem = agpmem->next) {
+		 * It's AGP memory - find the real physical page to map
+		 */
+		for (agpmem = dev->agp->memory; agpmem; agpmem = agpmem->next) {
 			if (agpmem->bound <= baddr &&
 			if (agpmem->bound <= baddr &&
-			    agpmem->bound + agpmem->pages * PAGE_SIZE > baddr) 
+			    agpmem->bound + agpmem->pages * PAGE_SIZE > baddr)
 				break;
 				break;
 		}
 		}
 
 
-		if (!agpmem) goto vm_nopage_error;
+		if (!agpmem)
+			goto vm_nopage_error;
 
 
 		/*
 		/*
-                 * Get the page, inc the use count, and return it
-                 */
+		 * Get the page, inc the use count, and return it
+		 */
 		offset = (baddr - agpmem->bound) >> PAGE_SHIFT;
 		offset = (baddr - agpmem->bound) >> PAGE_SHIFT;
 		page = virt_to_page(__va(agpmem->memory->memory[offset]));
 		page = virt_to_page(__va(agpmem->memory->memory[offset]));
 		get_page(page);
 		get_page(page);
 
 
-		DRM_DEBUG("baddr = 0x%lx page = 0x%p, offset = 0x%lx, count=%d\n",
-			  baddr, __va(agpmem->memory->memory[offset]), offset,
-			  page_count(page));
+		DRM_DEBUG
+		    ("baddr = 0x%lx page = 0x%p, offset = 0x%lx, count=%d\n",
+		     baddr, __va(agpmem->memory->memory[offset]), offset,
+		     page_count(page));
 
 
 		return page;
 		return page;
-        }
-vm_nopage_error:
-	return NOPAGE_SIGBUS;		/* Disallow mremap */
+	}
+      vm_nopage_error:
+	return NOPAGE_SIGBUS;	/* Disallow mremap */
 }
 }
-#else /* __OS_HAS_AGP */
+#else				/* __OS_HAS_AGP */
 static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
 static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
-						 unsigned long address)
+						unsigned long address)
 {
 {
 	return NOPAGE_SIGBUS;
 	return NOPAGE_SIGBUS;
 }
 }
-#endif /* __OS_HAS_AGP */
+#endif				/* __OS_HAS_AGP */
 
 
 /**
 /**
  * \c nopage method for shared virtual memory.
  * \c nopage method for shared virtual memory.
@@ -131,22 +135,24 @@ static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
  * \param vma virtual memory area.
  * \param vma virtual memory area.
  * \param address access address.
  * \param address access address.
  * \return pointer to the page structure.
  * \return pointer to the page structure.
- * 
+ *
  * Get the the mapping, find the real physical page to map, get the page, and
  * Get the the mapping, find the real physical page to map, get the page, and
  * return it.
  * return it.
  */
  */
 static __inline__ struct page *drm_do_vm_shm_nopage(struct vm_area_struct *vma,
 static __inline__ struct page *drm_do_vm_shm_nopage(struct vm_area_struct *vma,
-						     unsigned long address)
+						    unsigned long address)
 {
 {
-	drm_map_t	 *map	 = (drm_map_t *)vma->vm_private_data;
-	unsigned long	 offset;
-	unsigned long	 i;
-	struct page	 *page;
+	drm_map_t *map = (drm_map_t *) vma->vm_private_data;
+	unsigned long offset;
+	unsigned long i;
+	struct page *page;
 
 
-	if (address > vma->vm_end) return NOPAGE_SIGBUS; /* Disallow mremap */
-	if (!map)    		   return NOPAGE_OOM;  /* Nothing allocated */
+	if (address > vma->vm_end)
+		return NOPAGE_SIGBUS;	/* Disallow mremap */
+	if (!map)
+		return NOPAGE_OOM;	/* Nothing allocated */
 
 
-	offset	 = address - vma->vm_start;
+	offset = address - vma->vm_start;
 	i = (unsigned long)map->handle + offset;
 	i = (unsigned long)map->handle + offset;
 	page = (map->type == _DRM_CONSISTENT) ?
 	page = (map->type == _DRM_CONSISTENT) ?
 		virt_to_page((void *)i) : vmalloc_to_page((void *)i);
 		virt_to_page((void *)i) : vmalloc_to_page((void *)i);
@@ -158,19 +164,18 @@ static __inline__ struct page *drm_do_vm_shm_nopage(struct vm_area_struct *vma,
 	return page;
 	return page;
 }
 }
 
 
-
 /**
 /**
  * \c close method for shared virtual memory.
  * \c close method for shared virtual memory.
- * 
+ *
  * \param vma virtual memory area.
  * \param vma virtual memory area.
- * 
+ *
  * Deletes map information if we are the last
  * Deletes map information if we are the last
  * person to close a mapping and it's not in the global maplist.
  * person to close a mapping and it's not in the global maplist.
  */
  */
 static void drm_vm_shm_close(struct vm_area_struct *vma)
 static void drm_vm_shm_close(struct vm_area_struct *vma)
 {
 {
-	drm_file_t	*priv	= vma->vm_file->private_data;
-	drm_device_t	*dev	= priv->head->dev;
+	drm_file_t *priv = vma->vm_file->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_vma_entry_t *pt, *prev, *next;
 	drm_vma_entry_t *pt, *prev, *next;
 	drm_map_t *map;
 	drm_map_t *map;
 	drm_map_list_t *r_list;
 	drm_map_list_t *r_list;
@@ -186,7 +191,8 @@ static void drm_vm_shm_close(struct vm_area_struct *vma)
 	down(&dev->struct_sem);
 	down(&dev->struct_sem);
 	for (pt = dev->vmalist, prev = NULL; pt; pt = next) {
 	for (pt = dev->vmalist, prev = NULL; pt; pt = next) {
 		next = pt->next;
 		next = pt->next;
-		if (pt->vma->vm_private_data == map) found_maps++;
+		if (pt->vma->vm_private_data == map)
+			found_maps++;
 		if (pt->vma == vma) {
 		if (pt->vma == vma) {
 			if (prev) {
 			if (prev) {
 				prev->next = pt->next;
 				prev->next = pt->next;
@@ -199,8 +205,7 @@ static void drm_vm_shm_close(struct vm_area_struct *vma)
 		}
 		}
 	}
 	}
 	/* We were the only map that was found */
 	/* We were the only map that was found */
-	if(found_maps == 1 &&
-	   map->flags & _DRM_REMOVABLE) {
+	if (found_maps == 1 && map->flags & _DRM_REMOVABLE) {
 		/* Check to see if we are in the maplist, if we are not, then
 		/* Check to see if we are in the maplist, if we are not, then
 		 * we delete this mappings information.
 		 * we delete this mappings information.
 		 */
 		 */
@@ -208,10 +213,11 @@ static void drm_vm_shm_close(struct vm_area_struct *vma)
 		list = &dev->maplist->head;
 		list = &dev->maplist->head;
 		list_for_each(list, &dev->maplist->head) {
 		list_for_each(list, &dev->maplist->head) {
 			r_list = list_entry(list, drm_map_list_t, head);
 			r_list = list_entry(list, drm_map_list_t, head);
-			if (r_list->map == map) found_maps++;
+			if (r_list->map == map)
+				found_maps++;
 		}
 		}
 
 
-		if(!found_maps) {
+		if (!found_maps) {
 			drm_dma_handle_t dmah;
 			drm_dma_handle_t dmah;
 
 
 			switch (map->type) {
 			switch (map->type) {
@@ -251,27 +257,29 @@ static void drm_vm_shm_close(struct vm_area_struct *vma)
  * \param vma virtual memory area.
  * \param vma virtual memory area.
  * \param address access address.
  * \param address access address.
  * \return pointer to the page structure.
  * \return pointer to the page structure.
- * 
+ *
  * Determine the page number from the page offset and get it from drm_device_dma::pagelist.
  * Determine the page number from the page offset and get it from drm_device_dma::pagelist.
  */
  */
 static __inline__ struct page *drm_do_vm_dma_nopage(struct vm_area_struct *vma,
 static __inline__ struct page *drm_do_vm_dma_nopage(struct vm_area_struct *vma,
-						     unsigned long address)
+						    unsigned long address)
 {
 {
-	drm_file_t	 *priv	 = vma->vm_file->private_data;
-	drm_device_t	 *dev	 = priv->head->dev;
-	drm_device_dma_t *dma	 = dev->dma;
-	unsigned long	 offset;
-	unsigned long	 page_nr;
-	struct page	 *page;
-
-	if (!dma)		   return NOPAGE_SIGBUS; /* Error */
-	if (address > vma->vm_end) return NOPAGE_SIGBUS; /* Disallow mremap */
-	if (!dma->pagelist)	   return NOPAGE_OOM ; /* Nothing allocated */
-
-	offset	 = address - vma->vm_start; /* vm_[pg]off[set] should be 0 */
-	page_nr  = offset >> PAGE_SHIFT;
-	page = virt_to_page((dma->pagelist[page_nr] + 
-			     (offset & (~PAGE_MASK))));
+	drm_file_t *priv = vma->vm_file->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_device_dma_t *dma = dev->dma;
+	unsigned long offset;
+	unsigned long page_nr;
+	struct page *page;
+
+	if (!dma)
+		return NOPAGE_SIGBUS;	/* Error */
+	if (address > vma->vm_end)
+		return NOPAGE_SIGBUS;	/* Disallow mremap */
+	if (!dma->pagelist)
+		return NOPAGE_OOM;	/* Nothing allocated */
+
+	offset = address - vma->vm_start;	/* vm_[pg]off[set] should be 0 */
+	page_nr = offset >> PAGE_SHIFT;
+	page = virt_to_page((dma->pagelist[page_nr] + (offset & (~PAGE_MASK))));
 
 
 	get_page(page);
 	get_page(page);
 
 
@@ -285,13 +293,13 @@ static __inline__ struct page *drm_do_vm_dma_nopage(struct vm_area_struct *vma,
  * \param vma virtual memory area.
  * \param vma virtual memory area.
  * \param address access address.
  * \param address access address.
  * \return pointer to the page structure.
  * \return pointer to the page structure.
- * 
+ *
  * Determine the map offset from the page offset and get it from drm_sg_mem::pagelist.
  * Determine the map offset from the page offset and get it from drm_sg_mem::pagelist.
  */
  */
 static __inline__ struct page *drm_do_vm_sg_nopage(struct vm_area_struct *vma,
 static __inline__ struct page *drm_do_vm_sg_nopage(struct vm_area_struct *vma,
-						    unsigned long address)
+						   unsigned long address)
 {
 {
-	drm_map_t        *map    = (drm_map_t *)vma->vm_private_data;
+	drm_map_t *map = (drm_map_t *) vma->vm_private_data;
 	drm_file_t *priv = vma->vm_file->private_data;
 	drm_file_t *priv = vma->vm_file->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_sg_mem_t *entry = dev->sg;
 	drm_sg_mem_t *entry = dev->sg;
@@ -300,10 +308,12 @@ static __inline__ struct page *drm_do_vm_sg_nopage(struct vm_area_struct *vma,
 	unsigned long page_offset;
 	unsigned long page_offset;
 	struct page *page;
 	struct page *page;
 
 
-	if (!entry)                return NOPAGE_SIGBUS; /* Error */
-	if (address > vma->vm_end) return NOPAGE_SIGBUS; /* Disallow mremap */
-	if (!entry->pagelist)      return NOPAGE_OOM ;  /* Nothing allocated */
-
+	if (!entry)
+		return NOPAGE_SIGBUS;	/* Error */
+	if (address > vma->vm_end)
+		return NOPAGE_SIGBUS;	/* Disallow mremap */
+	if (!entry->pagelist)
+		return NOPAGE_OOM;	/* Nothing allocated */
 
 
 	offset = address - vma->vm_start;
 	offset = address - vma->vm_start;
 	map_offset = map->offset - (unsigned long)dev->sg->virtual;
 	map_offset = map->offset - (unsigned long)dev->sg->virtual;
@@ -314,76 +324,78 @@ static __inline__ struct page *drm_do_vm_sg_nopage(struct vm_area_struct *vma,
 	return page;
 	return page;
 }
 }
 
 
-
 static struct page *drm_vm_nopage(struct vm_area_struct *vma,
 static struct page *drm_vm_nopage(struct vm_area_struct *vma,
-				   unsigned long address,
-				   int *type) {
-	if (type) *type = VM_FAULT_MINOR;
+				  unsigned long address, int *type)
+{
+	if (type)
+		*type = VM_FAULT_MINOR;
 	return drm_do_vm_nopage(vma, address);
 	return drm_do_vm_nopage(vma, address);
 }
 }
 
 
 static struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
 static struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
-				       unsigned long address,
-				       int *type) {
-	if (type) *type = VM_FAULT_MINOR;
+				      unsigned long address, int *type)
+{
+	if (type)
+		*type = VM_FAULT_MINOR;
 	return drm_do_vm_shm_nopage(vma, address);
 	return drm_do_vm_shm_nopage(vma, address);
 }
 }
 
 
 static struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
 static struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
-				       unsigned long address,
-				       int *type) {
-	if (type) *type = VM_FAULT_MINOR;
+				      unsigned long address, int *type)
+{
+	if (type)
+		*type = VM_FAULT_MINOR;
 	return drm_do_vm_dma_nopage(vma, address);
 	return drm_do_vm_dma_nopage(vma, address);
 }
 }
 
 
 static struct page *drm_vm_sg_nopage(struct vm_area_struct *vma,
 static struct page *drm_vm_sg_nopage(struct vm_area_struct *vma,
-				      unsigned long address,
-				      int *type) {
-	if (type) *type = VM_FAULT_MINOR;
+				     unsigned long address, int *type)
+{
+	if (type)
+		*type = VM_FAULT_MINOR;
 	return drm_do_vm_sg_nopage(vma, address);
 	return drm_do_vm_sg_nopage(vma, address);
 }
 }
 
 
 /** AGP virtual memory operations */
 /** AGP virtual memory operations */
-static struct vm_operations_struct   drm_vm_ops = {
+static struct vm_operations_struct drm_vm_ops = {
 	.nopage = drm_vm_nopage,
 	.nopage = drm_vm_nopage,
-	.open	= drm_vm_open,
-	.close	= drm_vm_close,
+	.open = drm_vm_open,
+	.close = drm_vm_close,
 };
 };
 
 
 /** Shared virtual memory operations */
 /** Shared virtual memory operations */
-static struct vm_operations_struct   drm_vm_shm_ops = {
+static struct vm_operations_struct drm_vm_shm_ops = {
 	.nopage = drm_vm_shm_nopage,
 	.nopage = drm_vm_shm_nopage,
-	.open	= drm_vm_open,
-	.close	= drm_vm_shm_close,
+	.open = drm_vm_open,
+	.close = drm_vm_shm_close,
 };
 };
 
 
 /** DMA virtual memory operations */
 /** DMA virtual memory operations */
-static struct vm_operations_struct   drm_vm_dma_ops = {
+static struct vm_operations_struct drm_vm_dma_ops = {
 	.nopage = drm_vm_dma_nopage,
 	.nopage = drm_vm_dma_nopage,
-	.open	= drm_vm_open,
-	.close	= drm_vm_close,
+	.open = drm_vm_open,
+	.close = drm_vm_close,
 };
 };
 
 
 /** Scatter-gather virtual memory operations */
 /** Scatter-gather virtual memory operations */
-static struct vm_operations_struct   drm_vm_sg_ops = {
+static struct vm_operations_struct drm_vm_sg_ops = {
 	.nopage = drm_vm_sg_nopage,
 	.nopage = drm_vm_sg_nopage,
-	.open   = drm_vm_open,
-	.close  = drm_vm_close,
+	.open = drm_vm_open,
+	.close = drm_vm_close,
 };
 };
 
 
-
 /**
 /**
  * \c open method for shared virtual memory.
  * \c open method for shared virtual memory.
- * 
+ *
  * \param vma virtual memory area.
  * \param vma virtual memory area.
- * 
+ *
  * Create a new drm_vma_entry structure as the \p vma private data entry and
  * Create a new drm_vma_entry structure as the \p vma private data entry and
  * add it to drm_device::vmalist.
  * add it to drm_device::vmalist.
  */
  */
 static void drm_vm_open(struct vm_area_struct *vma)
 static void drm_vm_open(struct vm_area_struct *vma)
 {
 {
-	drm_file_t	*priv	= vma->vm_file->private_data;
-	drm_device_t	*dev	= priv->head->dev;
+	drm_file_t *priv = vma->vm_file->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_vma_entry_t *vma_entry;
 	drm_vma_entry_t *vma_entry;
 
 
 	DRM_DEBUG("0x%08lx,0x%08lx\n",
 	DRM_DEBUG("0x%08lx,0x%08lx\n",
@@ -393,26 +405,26 @@ static void drm_vm_open(struct vm_area_struct *vma)
 	vma_entry = drm_alloc(sizeof(*vma_entry), DRM_MEM_VMAS);
 	vma_entry = drm_alloc(sizeof(*vma_entry), DRM_MEM_VMAS);
 	if (vma_entry) {
 	if (vma_entry) {
 		down(&dev->struct_sem);
 		down(&dev->struct_sem);
-		vma_entry->vma	= vma;
+		vma_entry->vma = vma;
 		vma_entry->next = dev->vmalist;
 		vma_entry->next = dev->vmalist;
-		vma_entry->pid	= current->pid;
-		dev->vmalist	= vma_entry;
+		vma_entry->pid = current->pid;
+		dev->vmalist = vma_entry;
 		up(&dev->struct_sem);
 		up(&dev->struct_sem);
 	}
 	}
 }
 }
 
 
 /**
 /**
  * \c close method for all virtual memory types.
  * \c close method for all virtual memory types.
- * 
+ *
  * \param vma virtual memory area.
  * \param vma virtual memory area.
- * 
+ *
  * Search the \p vma private data entry in drm_device::vmalist, unlink it, and
  * Search the \p vma private data entry in drm_device::vmalist, unlink it, and
  * free it.
  * free it.
  */
  */
 static void drm_vm_close(struct vm_area_struct *vma)
 static void drm_vm_close(struct vm_area_struct *vma)
 {
 {
-	drm_file_t	*priv	= vma->vm_file->private_data;
-	drm_device_t	*dev	= priv->head->dev;
+	drm_file_t *priv = vma->vm_file->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_vma_entry_t *pt, *prev;
 	drm_vma_entry_t *pt, *prev;
 
 
 	DRM_DEBUG("0x%08lx,0x%08lx\n",
 	DRM_DEBUG("0x%08lx,0x%08lx\n",
@@ -440,43 +452,44 @@ static void drm_vm_close(struct vm_area_struct *vma)
  * \param filp file pointer.
  * \param filp file pointer.
  * \param vma virtual memory area.
  * \param vma virtual memory area.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
- * 
+ *
  * Sets the virtual memory area operations structure to vm_dma_ops, the file
  * Sets the virtual memory area operations structure to vm_dma_ops, the file
  * pointer, and calls vm_open().
  * pointer, and calls vm_open().
  */
  */
 static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
 static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
 {
 {
-	drm_file_t	 *priv	 = filp->private_data;
-	drm_device_t	 *dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev;
 	drm_device_dma_t *dma;
 	drm_device_dma_t *dma;
-	unsigned long	 length	 = vma->vm_end - vma->vm_start;
+	unsigned long length = vma->vm_end - vma->vm_start;
 
 
 	lock_kernel();
 	lock_kernel();
-	dev	 = priv->head->dev;
-	dma	 = dev->dma;
+	dev = priv->head->dev;
+	dma = dev->dma;
 	DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
 	DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
 		  vma->vm_start, vma->vm_end, VM_OFFSET(vma));
 		  vma->vm_start, vma->vm_end, VM_OFFSET(vma));
 
 
-				/* Length must match exact page count */
+	/* Length must match exact page count */
 	if (!dma || (length >> PAGE_SHIFT) != dma->page_count) {
 	if (!dma || (length >> PAGE_SHIFT) != dma->page_count) {
 		unlock_kernel();
 		unlock_kernel();
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 	unlock_kernel();
 	unlock_kernel();
 
 
-	vma->vm_ops   = &drm_vm_dma_ops;
+	vma->vm_ops = &drm_vm_dma_ops;
 
 
-	vma->vm_flags |= VM_RESERVED; /* Don't swap */
+	vma->vm_flags |= VM_RESERVED;	/* Don't swap */
 
 
-	vma->vm_file  =	 filp;	/* Needed for drm_vm_open() */
+	vma->vm_file = filp;	/* Needed for drm_vm_open() */
 	drm_vm_open(vma);
 	drm_vm_open(vma);
 	return 0;
 	return 0;
 }
 }
 
 
-unsigned long drm_core_get_map_ofs(drm_map_t *map)
+unsigned long drm_core_get_map_ofs(drm_map_t * map)
 {
 {
 	return map->offset;
 	return map->offset;
 }
 }
+
 EXPORT_SYMBOL(drm_core_get_map_ofs);
 EXPORT_SYMBOL(drm_core_get_map_ofs);
 
 
 unsigned long drm_core_get_reg_ofs(struct drm_device *dev)
 unsigned long drm_core_get_reg_ofs(struct drm_device *dev)
@@ -487,6 +500,7 @@ unsigned long drm_core_get_reg_ofs(struct drm_device *dev)
 	return 0;
 	return 0;
 #endif
 #endif
 }
 }
+
 EXPORT_SYMBOL(drm_core_get_reg_ofs);
 EXPORT_SYMBOL(drm_core_get_reg_ofs);
 
 
 /**
 /**
@@ -495,7 +509,7 @@ EXPORT_SYMBOL(drm_core_get_reg_ofs);
  * \param filp file pointer.
  * \param filp file pointer.
  * \param vma virtual memory area.
  * \param vma virtual memory area.
  * \return zero on success or a negative number on failure.
  * \return zero on success or a negative number on failure.
- * 
+ *
  * If the virtual memory area has no offset associated with it then it's a DMA
  * If the virtual memory area has no offset associated with it then it's a DMA
  * area, so calls mmap_dma(). Otherwise searches the map in drm_device::maplist,
  * area, so calls mmap_dma(). Otherwise searches the map in drm_device::maplist,
  * checks that the restricted flag is not set, sets the virtual memory operations
  * checks that the restricted flag is not set, sets the virtual memory operations
@@ -504,17 +518,18 @@ EXPORT_SYMBOL(drm_core_get_reg_ofs);
  */
  */
 int drm_mmap(struct file *filp, struct vm_area_struct *vma)
 int drm_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 {
-	drm_file_t	*priv	= filp->private_data;
-	drm_device_t	*dev	= priv->head->dev;
-	drm_map_t	*map	= NULL;
-	drm_map_list_t  *r_list;
-	unsigned long   offset  = 0;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_map_t *map = NULL;
+	drm_map_list_t *r_list;
+	unsigned long offset = 0;
 	struct list_head *list;
 	struct list_head *list;
 
 
 	DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
 	DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
 		  vma->vm_start, vma->vm_end, VM_OFFSET(vma));
 		  vma->vm_start, vma->vm_end, VM_OFFSET(vma));
 
 
-	if ( !priv->authenticated ) return -EACCES;
+	if (!priv->authenticated)
+		return -EACCES;
 
 
 	/* We check for "dma". On Apple's UniNorth, it's valid to have
 	/* We check for "dma". On Apple's UniNorth, it's valid to have
 	 * the AGP mapped at physical address 0
 	 * the AGP mapped at physical address 0
@@ -522,61 +537,66 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
 	 */
 	 */
 	if (!VM_OFFSET(vma)
 	if (!VM_OFFSET(vma)
 #if __OS_HAS_AGP
 #if __OS_HAS_AGP
-	    && (!dev->agp || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE)
+	    && (!dev->agp
+		|| dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE)
 #endif
 #endif
 	    )
 	    )
 		return drm_mmap_dma(filp, vma);
 		return drm_mmap_dma(filp, vma);
 
 
-				/* A sequential search of a linked list is
-				   fine here because: 1) there will only be
-				   about 5-10 entries in the list and, 2) a
-				   DRI client only has to do this mapping
-				   once, so it doesn't have to be optimized
-				   for performance, even if the list was a
-				   bit longer. */
+	/* A sequential search of a linked list is
+	   fine here because: 1) there will only be
+	   about 5-10 entries in the list and, 2) a
+	   DRI client only has to do this mapping
+	   once, so it doesn't have to be optimized
+	   for performance, even if the list was a
+	   bit longer. */
 	list_for_each(list, &dev->maplist->head) {
 	list_for_each(list, &dev->maplist->head) {
 
 
 		r_list = list_entry(list, drm_map_list_t, head);
 		r_list = list_entry(list, drm_map_list_t, head);
 		map = r_list->map;
 		map = r_list->map;
-		if (!map) continue;
+		if (!map)
+			continue;
 		if (r_list->user_token == VM_OFFSET(vma))
 		if (r_list->user_token == VM_OFFSET(vma))
 			break;
 			break;
 	}
 	}
 
 
-	if (!map || ((map->flags&_DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN)))
+	if (!map || ((map->flags & _DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN)))
 		return -EPERM;
 		return -EPERM;
 
 
-				/* Check for valid size. */
-	if (map->size != vma->vm_end - vma->vm_start) return -EINVAL;
+	/* Check for valid size. */
+	if (map->size != vma->vm_end - vma->vm_start)
+		return -EINVAL;
 
 
 	if (!capable(CAP_SYS_ADMIN) && (map->flags & _DRM_READ_ONLY)) {
 	if (!capable(CAP_SYS_ADMIN) && (map->flags & _DRM_READ_ONLY)) {
 		vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
 		vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
 #if defined(__i386__) || defined(__x86_64__)
 #if defined(__i386__) || defined(__x86_64__)
 		pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
 		pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
 #else
 #else
-				/* Ye gads this is ugly.  With more thought
-                                   we could move this up higher and use
-                                   `protection_map' instead.  */
-		vma->vm_page_prot = __pgprot(pte_val(pte_wrprotect(
-			__pte(pgprot_val(vma->vm_page_prot)))));
+		/* Ye gads this is ugly.  With more thought
+		   we could move this up higher and use
+		   `protection_map' instead.  */
+		vma->vm_page_prot =
+		    __pgprot(pte_val
+			     (pte_wrprotect
+			      (__pte(pgprot_val(vma->vm_page_prot)))));
 #endif
 #endif
 	}
 	}
 
 
 	switch (map->type) {
 	switch (map->type) {
-        case _DRM_AGP:
-	  if (drm_core_has_AGP(dev) && dev->agp->cant_use_aperture) {
-                /*
-                 * On some platforms we can't talk to bus dma address from the CPU, so for
-                 * memory of type DRM_AGP, we'll deal with sorting out the real physical
-                 * pages and mappings in nopage()
-                 */
+	case _DRM_AGP:
+		if (drm_core_has_AGP(dev) && dev->agp->cant_use_aperture) {
+			/*
+			 * On some platforms we can't talk to bus dma address from the CPU, so for
+			 * memory of type DRM_AGP, we'll deal with sorting out the real physical
+			 * pages and mappings in nopage()
+			 */
 #if defined(__powerpc__)
 #if defined(__powerpc__)
-		pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
+			pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
 #endif
 #endif
-                vma->vm_ops = &drm_vm_ops;
-                break;
-	  }
-                /* fall through to _DRM_FRAME_BUFFER... */        
+			vma->vm_ops = &drm_vm_ops;
+			break;
+		}
+		/* fall through to _DRM_FRAME_BUFFER... */
 	case _DRM_FRAME_BUFFER:
 	case _DRM_FRAME_BUFFER:
 	case _DRM_REGISTERS:
 	case _DRM_REGISTERS:
 #if defined(__i386__) || defined(__x86_64__)
 #if defined(__i386__) || defined(__x86_64__)
@@ -591,27 +611,25 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
 #endif
 #endif
 		vma->vm_flags |= VM_IO;	/* not in core dump */
 		vma->vm_flags |= VM_IO;	/* not in core dump */
 #if defined(__ia64__)
 #if defined(__ia64__)
-		if (efi_range_is_wc(vma->vm_start, vma->vm_end -
-				    vma->vm_start))
+		if (efi_range_is_wc(vma->vm_start, vma->vm_end - vma->vm_start))
 			vma->vm_page_prot =
 			vma->vm_page_prot =
-				pgprot_writecombine(vma->vm_page_prot);
+			    pgprot_writecombine(vma->vm_page_prot);
 		else
 		else
-			vma->vm_page_prot =
-				pgprot_noncached(vma->vm_page_prot);
+			vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 #endif
 #endif
 		offset = dev->driver->get_reg_ofs(dev);
 		offset = dev->driver->get_reg_ofs(dev);
 #ifdef __sparc__
 #ifdef __sparc__
 		if (io_remap_pfn_range(DRM_RPR_ARG(vma) vma->vm_start,
 		if (io_remap_pfn_range(DRM_RPR_ARG(vma) vma->vm_start,
-					(map->offset + offset) >> PAGE_SHIFT,
-					vma->vm_end - vma->vm_start,
-					vma->vm_page_prot))
+				       (map->offset + offset) >> PAGE_SHIFT,
+				       vma->vm_end - vma->vm_start,
+				       vma->vm_page_prot))
 #else
 #else
 		if (io_remap_pfn_range(vma, vma->vm_start,
 		if (io_remap_pfn_range(vma, vma->vm_start,
-				     (map->offset + offset) >> PAGE_SHIFT,
-				     vma->vm_end - vma->vm_start,
-				     vma->vm_page_prot))
+				       (map->offset + offset) >> PAGE_SHIFT,
+				       vma->vm_end - vma->vm_start,
+				       vma->vm_page_prot))
 #endif
 #endif
-				return -EAGAIN;
+			return -EAGAIN;
 		DRM_DEBUG("   Type = %d; start = 0x%lx, end = 0x%lx,"
 		DRM_DEBUG("   Type = %d; start = 0x%lx, end = 0x%lx,"
 			  " offset = 0x%lx\n",
 			  " offset = 0x%lx\n",
 			  map->type,
 			  map->type,
@@ -624,22 +642,23 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
 		 * allocate in a different way */
 		 * allocate in a different way */
 		vma->vm_ops = &drm_vm_shm_ops;
 		vma->vm_ops = &drm_vm_shm_ops;
 		vma->vm_private_data = (void *)map;
 		vma->vm_private_data = (void *)map;
-				/* Don't let this area swap.  Change when
-				   DRM_KERNEL advisory is supported. */
+		/* Don't let this area swap.  Change when
+		   DRM_KERNEL advisory is supported. */
 		vma->vm_flags |= VM_RESERVED;
 		vma->vm_flags |= VM_RESERVED;
 		break;
 		break;
 	case _DRM_SCATTER_GATHER:
 	case _DRM_SCATTER_GATHER:
 		vma->vm_ops = &drm_vm_sg_ops;
 		vma->vm_ops = &drm_vm_sg_ops;
 		vma->vm_private_data = (void *)map;
 		vma->vm_private_data = (void *)map;
 		vma->vm_flags |= VM_RESERVED;
 		vma->vm_flags |= VM_RESERVED;
-                break;
+		break;
 	default:
 	default:
 		return -EINVAL;	/* This should never happen. */
 		return -EINVAL;	/* This should never happen. */
 	}
 	}
-	vma->vm_flags |= VM_RESERVED; /* Don't swap */
+	vma->vm_flags |= VM_RESERVED;	/* Don't swap */
 
 
-	vma->vm_file  =	 filp;	/* Needed for drm_vm_open() */
+	vma->vm_file = filp;	/* Needed for drm_vm_open() */
 	drm_vm_open(vma);
 	drm_vm_open(vma);
 	return 0;
 	return 0;
 }
 }
+
 EXPORT_SYMBOL(drm_mmap);
 EXPORT_SYMBOL(drm_mmap);

+ 113 - 117
drivers/char/drm/ffb_context.c

@@ -15,8 +15,7 @@
 
 
 #include "ffb_drv.h"
 #include "ffb_drv.h"
 
 
-static int DRM(alloc_queue)(drm_device_t *dev, int is_2d_only)
-{
+static int DRM(alloc_queue) (drm_device_t * dev, int is_2d_only) {
 	ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
 	ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
 	int i;
 	int i;
 
 
@@ -37,7 +36,7 @@ static int DRM(alloc_queue)(drm_device_t *dev, int is_2d_only)
 	return i + 1;
 	return i + 1;
 }
 }
 
 
-static void ffb_save_context(ffb_dev_priv_t *fpriv, int idx)
+static void ffb_save_context(ffb_dev_priv_t * fpriv, int idx)
 {
 {
 	ffb_fbcPtr ffb = fpriv->regs;
 	ffb_fbcPtr ffb = fpriv->regs;
 	struct ffb_hw_context *ctx;
 	struct ffb_hw_context *ctx;
@@ -94,36 +93,36 @@ static void ffb_save_context(ffb_dev_priv_t *fpriv, int idx)
 
 
 	/* Capture rendering attributes. */
 	/* Capture rendering attributes. */
 
 
-	ctx->ppc = upa_readl(&ffb->ppc);		/* Pixel Processor Control */
-	ctx->wid = upa_readl(&ffb->wid);		/* Current WID */
-	ctx->fg = upa_readl(&ffb->fg);			/* Constant FG color */
-	ctx->bg = upa_readl(&ffb->bg);			/* Constant BG color */
-	ctx->consty = upa_readl(&ffb->consty);		/* Constant Y */
-	ctx->constz = upa_readl(&ffb->constz);		/* Constant Z */
-	ctx->xclip = upa_readl(&ffb->xclip);		/* X plane clip */
-	ctx->dcss = upa_readl(&ffb->dcss);		/* Depth Cue Scale Slope */
+	ctx->ppc = upa_readl(&ffb->ppc);	/* Pixel Processor Control */
+	ctx->wid = upa_readl(&ffb->wid);	/* Current WID */
+	ctx->fg = upa_readl(&ffb->fg);	/* Constant FG color */
+	ctx->bg = upa_readl(&ffb->bg);	/* Constant BG color */
+	ctx->consty = upa_readl(&ffb->consty);	/* Constant Y */
+	ctx->constz = upa_readl(&ffb->constz);	/* Constant Z */
+	ctx->xclip = upa_readl(&ffb->xclip);	/* X plane clip */
+	ctx->dcss = upa_readl(&ffb->dcss);	/* Depth Cue Scale Slope */
 	ctx->vclipmin = upa_readl(&ffb->vclipmin);	/* Primary XY clip, minimum */
 	ctx->vclipmin = upa_readl(&ffb->vclipmin);	/* Primary XY clip, minimum */
 	ctx->vclipmax = upa_readl(&ffb->vclipmax);	/* Primary XY clip, maximum */
 	ctx->vclipmax = upa_readl(&ffb->vclipmax);	/* Primary XY clip, maximum */
 	ctx->vclipzmin = upa_readl(&ffb->vclipzmin);	/* Primary Z clip, minimum */
 	ctx->vclipzmin = upa_readl(&ffb->vclipzmin);	/* Primary Z clip, minimum */
 	ctx->vclipzmax = upa_readl(&ffb->vclipzmax);	/* Primary Z clip, maximum */
 	ctx->vclipzmax = upa_readl(&ffb->vclipzmax);	/* Primary Z clip, maximum */
-	ctx->dcsf = upa_readl(&ffb->dcsf);		/* Depth Cue Scale Front Bound */
-	ctx->dcsb = upa_readl(&ffb->dcsb);		/* Depth Cue Scale Back Bound */
-	ctx->dczf = upa_readl(&ffb->dczf);		/* Depth Cue Scale Z Front */
-	ctx->dczb = upa_readl(&ffb->dczb);		/* Depth Cue Scale Z Back */
-	ctx->blendc = upa_readl(&ffb->blendc);		/* Alpha Blend Control */
+	ctx->dcsf = upa_readl(&ffb->dcsf);	/* Depth Cue Scale Front Bound */
+	ctx->dcsb = upa_readl(&ffb->dcsb);	/* Depth Cue Scale Back Bound */
+	ctx->dczf = upa_readl(&ffb->dczf);	/* Depth Cue Scale Z Front */
+	ctx->dczb = upa_readl(&ffb->dczb);	/* Depth Cue Scale Z Back */
+	ctx->blendc = upa_readl(&ffb->blendc);	/* Alpha Blend Control */
 	ctx->blendc1 = upa_readl(&ffb->blendc1);	/* Alpha Blend Color 1 */
 	ctx->blendc1 = upa_readl(&ffb->blendc1);	/* Alpha Blend Color 1 */
 	ctx->blendc2 = upa_readl(&ffb->blendc2);	/* Alpha Blend Color 2 */
 	ctx->blendc2 = upa_readl(&ffb->blendc2);	/* Alpha Blend Color 2 */
-	ctx->fbc = upa_readl(&ffb->fbc);		/* Frame Buffer Control */
-	ctx->rop = upa_readl(&ffb->rop);		/* Raster Operation */
-	ctx->cmp = upa_readl(&ffb->cmp);		/* Compare Controls */
+	ctx->fbc = upa_readl(&ffb->fbc);	/* Frame Buffer Control */
+	ctx->rop = upa_readl(&ffb->rop);	/* Raster Operation */
+	ctx->cmp = upa_readl(&ffb->cmp);	/* Compare Controls */
 	ctx->matchab = upa_readl(&ffb->matchab);	/* Buffer A/B Match Ops */
 	ctx->matchab = upa_readl(&ffb->matchab);	/* Buffer A/B Match Ops */
-	ctx->matchc = upa_readl(&ffb->matchc);		/* Buffer C Match Ops */
-	ctx->magnab = upa_readl(&ffb->magnab);		/* Buffer A/B Magnitude Ops */
-	ctx->magnc = upa_readl(&ffb->magnc);		/* Buffer C Magnitude Ops */
-	ctx->pmask = upa_readl(&ffb->pmask);		/* RGB Plane Mask */
-	ctx->xpmask = upa_readl(&ffb->xpmask);		/* X Plane Mask */
-	ctx->ypmask = upa_readl(&ffb->ypmask);		/* Y Plane Mask */
-	ctx->zpmask = upa_readl(&ffb->zpmask);		/* Z Plane Mask */
+	ctx->matchc = upa_readl(&ffb->matchc);	/* Buffer C Match Ops */
+	ctx->magnab = upa_readl(&ffb->magnab);	/* Buffer A/B Magnitude Ops */
+	ctx->magnc = upa_readl(&ffb->magnc);	/* Buffer C Magnitude Ops */
+	ctx->pmask = upa_readl(&ffb->pmask);	/* RGB Plane Mask */
+	ctx->xpmask = upa_readl(&ffb->xpmask);	/* X Plane Mask */
+	ctx->ypmask = upa_readl(&ffb->ypmask);	/* Y Plane Mask */
+	ctx->zpmask = upa_readl(&ffb->zpmask);	/* Z Plane Mask */
 
 
 	/* Auxiliary Clips. */
 	/* Auxiliary Clips. */
 	ctx->auxclip0min = upa_readl(&ffb->auxclip[0].min);
 	ctx->auxclip0min = upa_readl(&ffb->auxclip[0].min);
@@ -135,9 +134,9 @@ static void ffb_save_context(ffb_dev_priv_t *fpriv, int idx)
 	ctx->auxclip3min = upa_readl(&ffb->auxclip[3].min);
 	ctx->auxclip3min = upa_readl(&ffb->auxclip[3].min);
 	ctx->auxclip3max = upa_readl(&ffb->auxclip[3].max);
 	ctx->auxclip3max = upa_readl(&ffb->auxclip[3].max);
 
 
-	ctx->lpat = upa_readl(&ffb->lpat);		/* Line Pattern */
-	ctx->fontxy = upa_readl(&ffb->fontxy);		/* XY Font Coordinate */
-	ctx->fontw = upa_readl(&ffb->fontw);		/* Font Width */
+	ctx->lpat = upa_readl(&ffb->lpat);	/* Line Pattern */
+	ctx->fontxy = upa_readl(&ffb->fontxy);	/* XY Font Coordinate */
+	ctx->fontw = upa_readl(&ffb->fontw);	/* Font Width */
 	ctx->fontinc = upa_readl(&ffb->fontinc);	/* Font X/Y Increment */
 	ctx->fontinc = upa_readl(&ffb->fontinc);	/* Font X/Y Increment */
 
 
 	/* These registers/features only exist on FFB2 and later chips. */
 	/* These registers/features only exist on FFB2 and later chips. */
@@ -145,12 +144,12 @@ static void ffb_save_context(ffb_dev_priv_t *fpriv, int idx)
 		ctx->dcss1 = upa_readl(&ffb->dcss1);	/* Depth Cue Scale Slope 1 */
 		ctx->dcss1 = upa_readl(&ffb->dcss1);	/* Depth Cue Scale Slope 1 */
 		ctx->dcss2 = upa_readl(&ffb->dcss2);	/* Depth Cue Scale Slope 2 */
 		ctx->dcss2 = upa_readl(&ffb->dcss2);	/* Depth Cue Scale Slope 2 */
 		ctx->dcss2 = upa_readl(&ffb->dcss3);	/* Depth Cue Scale Slope 3 */
 		ctx->dcss2 = upa_readl(&ffb->dcss3);	/* Depth Cue Scale Slope 3 */
-		ctx->dcs2  = upa_readl(&ffb->dcs2);	/* Depth Cue Scale 2 */
-		ctx->dcs3  = upa_readl(&ffb->dcs3);	/* Depth Cue Scale 3 */
-		ctx->dcs4  = upa_readl(&ffb->dcs4);	/* Depth Cue Scale 4 */
-		ctx->dcd2  = upa_readl(&ffb->dcd2);	/* Depth Cue Depth 2 */
-		ctx->dcd3  = upa_readl(&ffb->dcd3);	/* Depth Cue Depth 3 */
-		ctx->dcd4  = upa_readl(&ffb->dcd4);	/* Depth Cue Depth 4 */
+		ctx->dcs2 = upa_readl(&ffb->dcs2);	/* Depth Cue Scale 2 */
+		ctx->dcs3 = upa_readl(&ffb->dcs3);	/* Depth Cue Scale 3 */
+		ctx->dcs4 = upa_readl(&ffb->dcs4);	/* Depth Cue Scale 4 */
+		ctx->dcd2 = upa_readl(&ffb->dcd2);	/* Depth Cue Depth 2 */
+		ctx->dcd3 = upa_readl(&ffb->dcd3);	/* Depth Cue Depth 3 */
+		ctx->dcd4 = upa_readl(&ffb->dcd4);	/* Depth Cue Depth 4 */
 
 
 		/* And stencil/stencilctl only exists on FFB2+ and later
 		/* And stencil/stencilctl only exists on FFB2+ and later
 		 * due to the introduction of 3DRAM-III.
 		 * due to the introduction of 3DRAM-III.
@@ -170,7 +169,7 @@ static void ffb_save_context(ffb_dev_priv_t *fpriv, int idx)
 	ctx->ucsr = upa_readl(&ffb->ucsr);
 	ctx->ucsr = upa_readl(&ffb->ucsr);
 }
 }
 
 
-static void ffb_restore_context(ffb_dev_priv_t *fpriv, int old, int idx)
+static void ffb_restore_context(ffb_dev_priv_t * fpriv, int old, int idx)
 {
 {
 	ffb_fbcPtr ffb = fpriv->regs;
 	ffb_fbcPtr ffb = fpriv->regs;
 	struct ffb_hw_context *ctx;
 	struct ffb_hw_context *ctx;
@@ -193,7 +192,7 @@ static void ffb_restore_context(ffb_dev_priv_t *fpriv, int old, int idx)
 
 
 		upa_writel(ctx->ppc, &ffb->ppc);
 		upa_writel(ctx->ppc, &ffb->ppc);
 		upa_writel(ctx->wid, &ffb->wid);
 		upa_writel(ctx->wid, &ffb->wid);
-		upa_writel(ctx->fg,  &ffb->fg);
+		upa_writel(ctx->fg, &ffb->fg);
 		upa_writel(ctx->bg, &ffb->bg);
 		upa_writel(ctx->bg, &ffb->bg);
 		upa_writel(ctx->xclip, &ffb->xclip);
 		upa_writel(ctx->xclip, &ffb->xclip);
 		upa_writel(ctx->fbc, &ffb->fbc);
 		upa_writel(ctx->fbc, &ffb->fbc);
@@ -237,36 +236,36 @@ static void ffb_restore_context(ffb_dev_priv_t *fpriv, int old, int idx)
 
 
 	/* Restore rendering attributes. */
 	/* Restore rendering attributes. */
 
 
-	upa_writel(ctx->ppc, &ffb->ppc);		/* Pixel Processor Control */
-	upa_writel(ctx->wid, &ffb->wid);		/* Current WID */
-	upa_writel(ctx->fg, &ffb->fg);			/* Constant FG color */
-	upa_writel(ctx->bg, &ffb->bg);			/* Constant BG color */
-	upa_writel(ctx->consty, &ffb->consty);		/* Constant Y */
-	upa_writel(ctx->constz, &ffb->constz);		/* Constant Z */
-	upa_writel(ctx->xclip, &ffb->xclip);		/* X plane clip */
-	upa_writel(ctx->dcss, &ffb->dcss);		/* Depth Cue Scale Slope */
+	upa_writel(ctx->ppc, &ffb->ppc);	/* Pixel Processor Control */
+	upa_writel(ctx->wid, &ffb->wid);	/* Current WID */
+	upa_writel(ctx->fg, &ffb->fg);	/* Constant FG color */
+	upa_writel(ctx->bg, &ffb->bg);	/* Constant BG color */
+	upa_writel(ctx->consty, &ffb->consty);	/* Constant Y */
+	upa_writel(ctx->constz, &ffb->constz);	/* Constant Z */
+	upa_writel(ctx->xclip, &ffb->xclip);	/* X plane clip */
+	upa_writel(ctx->dcss, &ffb->dcss);	/* Depth Cue Scale Slope */
 	upa_writel(ctx->vclipmin, &ffb->vclipmin);	/* Primary XY clip, minimum */
 	upa_writel(ctx->vclipmin, &ffb->vclipmin);	/* Primary XY clip, minimum */
 	upa_writel(ctx->vclipmax, &ffb->vclipmax);	/* Primary XY clip, maximum */
 	upa_writel(ctx->vclipmax, &ffb->vclipmax);	/* Primary XY clip, maximum */
 	upa_writel(ctx->vclipzmin, &ffb->vclipzmin);	/* Primary Z clip, minimum */
 	upa_writel(ctx->vclipzmin, &ffb->vclipzmin);	/* Primary Z clip, minimum */
 	upa_writel(ctx->vclipzmax, &ffb->vclipzmax);	/* Primary Z clip, maximum */
 	upa_writel(ctx->vclipzmax, &ffb->vclipzmax);	/* Primary Z clip, maximum */
-	upa_writel(ctx->dcsf, &ffb->dcsf);		/* Depth Cue Scale Front Bound */
-	upa_writel(ctx->dcsb, &ffb->dcsb);		/* Depth Cue Scale Back Bound */
-	upa_writel(ctx->dczf, &ffb->dczf);		/* Depth Cue Scale Z Front */
-	upa_writel(ctx->dczb, &ffb->dczb);		/* Depth Cue Scale Z Back */
-	upa_writel(ctx->blendc, &ffb->blendc);		/* Alpha Blend Control */
+	upa_writel(ctx->dcsf, &ffb->dcsf);	/* Depth Cue Scale Front Bound */
+	upa_writel(ctx->dcsb, &ffb->dcsb);	/* Depth Cue Scale Back Bound */
+	upa_writel(ctx->dczf, &ffb->dczf);	/* Depth Cue Scale Z Front */
+	upa_writel(ctx->dczb, &ffb->dczb);	/* Depth Cue Scale Z Back */
+	upa_writel(ctx->blendc, &ffb->blendc);	/* Alpha Blend Control */
 	upa_writel(ctx->blendc1, &ffb->blendc1);	/* Alpha Blend Color 1 */
 	upa_writel(ctx->blendc1, &ffb->blendc1);	/* Alpha Blend Color 1 */
 	upa_writel(ctx->blendc2, &ffb->blendc2);	/* Alpha Blend Color 2 */
 	upa_writel(ctx->blendc2, &ffb->blendc2);	/* Alpha Blend Color 2 */
-	upa_writel(ctx->fbc, &ffb->fbc);		/* Frame Buffer Control */
-	upa_writel(ctx->rop, &ffb->rop);		/* Raster Operation */
-	upa_writel(ctx->cmp, &ffb->cmp);		/* Compare Controls */
+	upa_writel(ctx->fbc, &ffb->fbc);	/* Frame Buffer Control */
+	upa_writel(ctx->rop, &ffb->rop);	/* Raster Operation */
+	upa_writel(ctx->cmp, &ffb->cmp);	/* Compare Controls */
 	upa_writel(ctx->matchab, &ffb->matchab);	/* Buffer A/B Match Ops */
 	upa_writel(ctx->matchab, &ffb->matchab);	/* Buffer A/B Match Ops */
-	upa_writel(ctx->matchc, &ffb->matchc);		/* Buffer C Match Ops */
-	upa_writel(ctx->magnab, &ffb->magnab);		/* Buffer A/B Magnitude Ops */
-	upa_writel(ctx->magnc, &ffb->magnc);		/* Buffer C Magnitude Ops */
-	upa_writel(ctx->pmask, &ffb->pmask);		/* RGB Plane Mask */
-	upa_writel(ctx->xpmask, &ffb->xpmask);		/* X Plane Mask */
-	upa_writel(ctx->ypmask, &ffb->ypmask);		/* Y Plane Mask */
-	upa_writel(ctx->zpmask, &ffb->zpmask);		/* Z Plane Mask */
+	upa_writel(ctx->matchc, &ffb->matchc);	/* Buffer C Match Ops */
+	upa_writel(ctx->magnab, &ffb->magnab);	/* Buffer A/B Magnitude Ops */
+	upa_writel(ctx->magnc, &ffb->magnc);	/* Buffer C Magnitude Ops */
+	upa_writel(ctx->pmask, &ffb->pmask);	/* RGB Plane Mask */
+	upa_writel(ctx->xpmask, &ffb->xpmask);	/* X Plane Mask */
+	upa_writel(ctx->ypmask, &ffb->ypmask);	/* Y Plane Mask */
+	upa_writel(ctx->zpmask, &ffb->zpmask);	/* Z Plane Mask */
 
 
 	/* Auxiliary Clips. */
 	/* Auxiliary Clips. */
 	upa_writel(ctx->auxclip0min, &ffb->auxclip[0].min);
 	upa_writel(ctx->auxclip0min, &ffb->auxclip[0].min);
@@ -278,9 +277,9 @@ static void ffb_restore_context(ffb_dev_priv_t *fpriv, int old, int idx)
 	upa_writel(ctx->auxclip3min, &ffb->auxclip[3].min);
 	upa_writel(ctx->auxclip3min, &ffb->auxclip[3].min);
 	upa_writel(ctx->auxclip3max, &ffb->auxclip[3].max);
 	upa_writel(ctx->auxclip3max, &ffb->auxclip[3].max);
 
 
-	upa_writel(ctx->lpat, &ffb->lpat);		/* Line Pattern */
-	upa_writel(ctx->fontxy, &ffb->fontxy);		/* XY Font Coordinate */
-	upa_writel(ctx->fontw, &ffb->fontw);		/* Font Width */
+	upa_writel(ctx->lpat, &ffb->lpat);	/* Line Pattern */
+	upa_writel(ctx->fontxy, &ffb->fontxy);	/* XY Font Coordinate */
+	upa_writel(ctx->fontw, &ffb->fontw);	/* Font Width */
 	upa_writel(ctx->fontinc, &ffb->fontinc);	/* Font X/Y Increment */
 	upa_writel(ctx->fontinc, &ffb->fontinc);	/* Font X/Y Increment */
 
 
 	/* These registers/features only exist on FFB2 and later chips. */
 	/* These registers/features only exist on FFB2 and later chips. */
@@ -354,91 +353,87 @@ static void FFBWait(ffb_fbcPtr ffb)
 	} while (--limit);
 	} while (--limit);
 }
 }
 
 
-int ffb_driver_context_switch(drm_device_t *dev, int old, int new)
+int ffb_driver_context_switch(drm_device_t * dev, int old, int new)
 {
 {
 	ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
 	ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
 
 
 #ifdef DRM_DMA_HISTOGRAM
 #ifdef DRM_DMA_HISTOGRAM
-        dev->ctx_start = get_cycles();
+	dev->ctx_start = get_cycles();
 #endif
 #endif
-        
-        DRM_DEBUG("Context switch from %d to %d\n", old, new);
 
 
-        if (new == dev->last_context ||
-	    dev->last_context == 0) {
+	DRM_DEBUG("Context switch from %d to %d\n", old, new);
+
+	if (new == dev->last_context || dev->last_context == 0) {
 		dev->last_context = new;
 		dev->last_context = new;
-                return 0;
+		return 0;
 	}
 	}
-        
+
 	FFBWait(fpriv->regs);
 	FFBWait(fpriv->regs);
 	ffb_save_context(fpriv, old);
 	ffb_save_context(fpriv, old);
 	ffb_restore_context(fpriv, old, new);
 	ffb_restore_context(fpriv, old, new);
 	FFBWait(fpriv->regs);
 	FFBWait(fpriv->regs);
-        
+
 	dev->last_context = new;
 	dev->last_context = new;
 
 
-        return 0;
+	return 0;
 }
 }
 
 
 int ffb_driver_resctx(struct inode *inode, struct file *filp, unsigned int cmd,
 int ffb_driver_resctx(struct inode *inode, struct file *filp, unsigned int cmd,
-		unsigned long arg)
+		      unsigned long arg)
 {
 {
-	drm_ctx_res_t	res;
-	drm_ctx_t	ctx;
-	int		i;
+	drm_ctx_res_t res;
+	drm_ctx_t ctx;
+	int i;
 
 
 	DRM_DEBUG("%d\n", DRM_RESERVED_CONTEXTS);
 	DRM_DEBUG("%d\n", DRM_RESERVED_CONTEXTS);
-	if (copy_from_user(&res, (drm_ctx_res_t __user *)arg, sizeof(res)))
+	if (copy_from_user(&res, (drm_ctx_res_t __user *) arg, sizeof(res)))
 		return -EFAULT;
 		return -EFAULT;
 	if (res.count >= DRM_RESERVED_CONTEXTS) {
 	if (res.count >= DRM_RESERVED_CONTEXTS) {
 		memset(&ctx, 0, sizeof(ctx));
 		memset(&ctx, 0, sizeof(ctx));
 		for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
 		for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
 			ctx.handle = i;
 			ctx.handle = i;
-			if (copy_to_user(&res.contexts[i],
-					 &i,
-					 sizeof(i)))
+			if (copy_to_user(&res.contexts[i], &i, sizeof(i)))
 				return -EFAULT;
 				return -EFAULT;
 		}
 		}
 	}
 	}
 	res.count = DRM_RESERVED_CONTEXTS;
 	res.count = DRM_RESERVED_CONTEXTS;
-	if (copy_to_user((drm_ctx_res_t __user *)arg, &res, sizeof(res)))
+	if (copy_to_user((drm_ctx_res_t __user *) arg, &res, sizeof(res)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
 
 
-
 int ffb_driver_addctx(struct inode *inode, struct file *filp, unsigned int cmd,
 int ffb_driver_addctx(struct inode *inode, struct file *filp, unsigned int cmd,
-		unsigned long arg)
+		      unsigned long arg)
 {
 {
-	drm_file_t	*priv	= filp->private_data;
-	drm_device_t	*dev	= priv->dev;
-	drm_ctx_t	ctx;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->dev;
+	drm_ctx_t ctx;
 	int idx;
 	int idx;
 
 
-	if (copy_from_user(&ctx, (drm_ctx_t __user *)arg, sizeof(ctx)))
+	if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
-	idx = DRM(alloc_queue)(dev, (ctx.flags & _DRM_CONTEXT_2DONLY));
+	idx = DRM(alloc_queue) (dev, (ctx.flags & _DRM_CONTEXT_2DONLY));
 	if (idx < 0)
 	if (idx < 0)
 		return -ENFILE;
 		return -ENFILE;
 
 
 	DRM_DEBUG("%d\n", ctx.handle);
 	DRM_DEBUG("%d\n", ctx.handle);
 	ctx.handle = idx;
 	ctx.handle = idx;
-	if (copy_to_user((drm_ctx_t __user *)arg, &ctx, sizeof(ctx)))
+	if (copy_to_user((drm_ctx_t __user *) arg, &ctx, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
 
 
 int ffb_driver_modctx(struct inode *inode, struct file *filp, unsigned int cmd,
 int ffb_driver_modctx(struct inode *inode, struct file *filp, unsigned int cmd,
-		unsigned long arg)
+		      unsigned long arg)
 {
 {
-	drm_file_t	*priv	= filp->private_data;
-	drm_device_t	*dev	= priv->dev;
-	ffb_dev_priv_t	*fpriv	= (ffb_dev_priv_t *) dev->dev_private;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->dev;
+	ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
 	struct ffb_hw_context *hwctx;
 	struct ffb_hw_context *hwctx;
 	drm_ctx_t ctx;
 	drm_ctx_t ctx;
 	int idx;
 	int idx;
 
 
-	if (copy_from_user(&ctx, (drm_ctx_t __user *)arg, sizeof(ctx)))
+	if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	idx = ctx.handle;
 	idx = ctx.handle;
@@ -458,16 +453,16 @@ int ffb_driver_modctx(struct inode *inode, struct file *filp, unsigned int cmd,
 }
 }
 
 
 int ffb_driver_getctx(struct inode *inode, struct file *filp, unsigned int cmd,
 int ffb_driver_getctx(struct inode *inode, struct file *filp, unsigned int cmd,
-		unsigned long arg)
+		      unsigned long arg)
 {
 {
-	drm_file_t	*priv	= filp->private_data;
-	drm_device_t	*dev	= priv->dev;
-	ffb_dev_priv_t	*fpriv	= (ffb_dev_priv_t *) dev->dev_private;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->dev;
+	ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
 	struct ffb_hw_context *hwctx;
 	struct ffb_hw_context *hwctx;
 	drm_ctx_t ctx;
 	drm_ctx_t ctx;
 	int idx;
 	int idx;
 
 
-	if (copy_from_user(&ctx, (drm_ctx_t __user *)arg, sizeof(ctx)))
+	if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	idx = ctx.handle;
 	idx = ctx.handle;
@@ -483,31 +478,31 @@ int ffb_driver_getctx(struct inode *inode, struct file *filp, unsigned int cmd,
 	else
 	else
 		ctx.flags = 0;
 		ctx.flags = 0;
 
 
-	if (copy_to_user((drm_ctx_t __user *)arg, &ctx, sizeof(ctx)))
+	if (copy_to_user((drm_ctx_t __user *) arg, &ctx, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return 0;
 	return 0;
 }
 }
 
 
-int ffb_driver_switchctx(struct inode *inode, struct file *filp, unsigned int cmd,
-		   unsigned long arg)
+int ffb_driver_switchctx(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	*priv	= filp->private_data;
-	drm_device_t	*dev	= priv->dev;
-	drm_ctx_t	ctx;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->dev;
+	drm_ctx_t ctx;
 
 
-	if (copy_from_user(&ctx, (drm_ctx_t  __user *)arg, sizeof(ctx)))
+	if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 	DRM_DEBUG("%d\n", ctx.handle);
 	DRM_DEBUG("%d\n", ctx.handle);
 	return ffb_driver_context_switch(dev, dev->last_context, ctx.handle);
 	return ffb_driver_context_switch(dev, dev->last_context, ctx.handle);
 }
 }
 
 
 int ffb_driver_newctx(struct inode *inode, struct file *filp, unsigned int cmd,
 int ffb_driver_newctx(struct inode *inode, struct file *filp, unsigned int cmd,
-		unsigned long arg)
+		      unsigned long arg)
 {
 {
-	drm_ctx_t	ctx;
+	drm_ctx_t ctx;
 
 
-	if (copy_from_user(&ctx, (drm_ctx_t  __user *)arg, sizeof(ctx)))
+	if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 	DRM_DEBUG("%d\n", ctx.handle);
 	DRM_DEBUG("%d\n", ctx.handle);
 
 
@@ -515,15 +510,15 @@ int ffb_driver_newctx(struct inode *inode, struct file *filp, unsigned int cmd,
 }
 }
 
 
 int ffb_driver_rmctx(struct inode *inode, struct file *filp, unsigned int cmd,
 int ffb_driver_rmctx(struct inode *inode, struct file *filp, unsigned int cmd,
-	       unsigned long arg)
+		     unsigned long arg)
 {
 {
-	drm_ctx_t	ctx;
-	drm_file_t	*priv	= filp->private_data;
-	drm_device_t	*dev	= priv->dev;
-	ffb_dev_priv_t	*fpriv	= (ffb_dev_priv_t *) dev->dev_private;
+	drm_ctx_t ctx;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->dev;
+	ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
 	int idx;
 	int idx;
 
 
-	if (copy_from_user(&ctx, (drm_ctx_t __user *)arg, sizeof(ctx)))
+	if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
 		return -EFAULT;
 		return -EFAULT;
 	DRM_DEBUG("%d\n", ctx.handle);
 	DRM_DEBUG("%d\n", ctx.handle);
 
 
@@ -544,7 +539,8 @@ void ffb_set_context_ioctls(void)
 	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)].func = ffb_driver_rmctx;
 	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)].func = ffb_driver_rmctx;
 	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)].func = ffb_driver_modctx;
 	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)].func = ffb_driver_modctx;
 	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)].func = ffb_driver_getctx;
 	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)].func = ffb_driver_getctx;
-	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)].func = ffb_driver_switchctx;
+	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)].func =
+	    ffb_driver_switchctx;
 	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)].func = ffb_driver_newctx;
 	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)].func = ffb_driver_newctx;
 	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)].func = ffb_driver_resctx;
 	DRM(ioctls)[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)].func = ffb_driver_resctx;
 
 

+ 68 - 71
drivers/char/drm/ffb_drv.c

@@ -33,13 +33,13 @@ typedef struct _ffb_position_t {
 
 
 static ffb_position_t *ffb_position;
 static ffb_position_t *ffb_position;
 
 
-static void get_ffb_type(ffb_dev_priv_t *ffb_priv, int instance)
+static void get_ffb_type(ffb_dev_priv_t * ffb_priv, int instance)
 {
 {
 	volatile unsigned char *strap_bits;
 	volatile unsigned char *strap_bits;
 	unsigned char val;
 	unsigned char val;
 
 
 	strap_bits = (volatile unsigned char *)
 	strap_bits = (volatile unsigned char *)
-		(ffb_priv->card_phys_base + 0x00200000UL);
+	    (ffb_priv->card_phys_base + 0x00200000UL);
 
 
 	/* Don't ask, you have to read the value twice for whatever
 	/* Don't ask, you have to read the value twice for whatever
 	 * reason to get correct contents.
 	 * reason to get correct contents.
@@ -61,7 +61,8 @@ static void get_ffb_type(ffb_dev_priv_t *ffb_priv, int instance)
 		break;
 		break;
 	case (0x1 << 5) | (0x0 << 3):
 	case (0x1 << 5) | (0x0 << 3):
 		ffb_priv->ffb_type = ffb2_prototype;
 		ffb_priv->ffb_type = ffb2_prototype;
-		printk("ffb%d: Detected FFB2/vertical pre-FCS prototype\n", instance);
+		printk("ffb%d: Detected FFB2/vertical pre-FCS prototype\n",
+		       instance);
 		break;
 		break;
 	case (0x1 << 5) | (0x1 << 3):
 	case (0x1 << 5) | (0x1 << 3):
 		ffb_priv->ffb_type = ffb2_vertical;
 		ffb_priv->ffb_type = ffb2_vertical;
@@ -81,12 +82,13 @@ static void get_ffb_type(ffb_dev_priv_t *ffb_priv, int instance)
 		break;
 		break;
 	default:
 	default:
 		ffb_priv->ffb_type = ffb2_vertical;
 		ffb_priv->ffb_type = ffb2_vertical;
-		printk("ffb%d: Unknown boardID[%08x], assuming FFB2\n", instance, val);
+		printk("ffb%d: Unknown boardID[%08x], assuming FFB2\n",
+		       instance, val);
 		break;
 		break;
 	};
 	};
 }
 }
 
 
-static void ffb_apply_upa_parent_ranges(int parent, 
+static void ffb_apply_upa_parent_ranges(int parent,
 					struct linux_prom64_registers *regs)
 					struct linux_prom64_registers *regs)
 {
 {
 	struct linux_prom64_ranges ranges[PROMREG_MAX];
 	struct linux_prom64_ranges ranges[PROMREG_MAX];
@@ -97,7 +99,8 @@ static void ffb_apply_upa_parent_ranges(int parent,
 	if (strcmp(name, "upa") != 0)
 	if (strcmp(name, "upa") != 0)
 		return;
 		return;
 
 
-	len = prom_getproperty(parent, "ranges", (void *) ranges, sizeof(ranges));
+	len =
+	    prom_getproperty(parent, "ranges", (void *)ranges, sizeof(ranges));
 	if (len <= 0)
 	if (len <= 0)
 		return;
 		return;
 
 
@@ -117,11 +120,11 @@ static void ffb_apply_upa_parent_ranges(int parent,
 	return;
 	return;
 }
 }
 
 
-static int ffb_init_one(drm_device_t *dev, int prom_node, int parent_node,
+static int ffb_init_one(drm_device_t * dev, int prom_node, int parent_node,
 			int instance)
 			int instance)
 {
 {
-	struct linux_prom64_registers regs[2*PROMREG_MAX];
-	ffb_dev_priv_t *ffb_priv = (ffb_dev_priv_t *)dev->dev_private;
+	struct linux_prom64_registers regs[2 * PROMREG_MAX];
+	ffb_dev_priv_t *ffb_priv = (ffb_dev_priv_t *) dev->dev_private;
 	int i;
 	int i;
 
 
 	ffb_priv->prom_node = prom_node;
 	ffb_priv->prom_node = prom_node;
@@ -132,27 +135,27 @@ static int ffb_init_one(drm_device_t *dev, int prom_node, int parent_node,
 	ffb_apply_upa_parent_ranges(parent_node, &regs[0]);
 	ffb_apply_upa_parent_ranges(parent_node, &regs[0]);
 	ffb_priv->card_phys_base = regs[0].phys_addr;
 	ffb_priv->card_phys_base = regs[0].phys_addr;
 	ffb_priv->regs = (ffb_fbcPtr)
 	ffb_priv->regs = (ffb_fbcPtr)
-		(regs[0].phys_addr + 0x00600000UL);
+	    (regs[0].phys_addr + 0x00600000UL);
 	get_ffb_type(ffb_priv, instance);
 	get_ffb_type(ffb_priv, instance);
 	for (i = 0; i < FFB_MAX_CTXS; i++)
 	for (i = 0; i < FFB_MAX_CTXS; i++)
 		ffb_priv->hw_state[i] = NULL;
 		ffb_priv->hw_state[i] = NULL;
-	
+
 	return 0;
 	return 0;
 }
 }
 
 
 static drm_map_t *ffb_find_map(struct file *filp, unsigned long off)
 static drm_map_t *ffb_find_map(struct file *filp, unsigned long off)
 {
 {
-	drm_file_t	*priv	= filp->private_data;
-	drm_device_t	*dev;
-	drm_map_list_t  *r_list;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev;
+	drm_map_list_t *r_list;
 	struct list_head *list;
 	struct list_head *list;
-	drm_map_t	*map;
+	drm_map_t *map;
 
 
 	if (!priv || (dev = priv->dev) == NULL)
 	if (!priv || (dev = priv->dev) == NULL)
 		return NULL;
 		return NULL;
 
 
 	list_for_each(list, &dev->maplist->head) {
 	list_for_each(list, &dev->maplist->head) {
-		r_list = (drm_map_list_t *)list;
+		r_list = (drm_map_list_t *) list;
 		map = r_list->map;
 		map = r_list->map;
 		if (!map)
 		if (!map)
 			continue;
 			continue;
@@ -166,8 +169,7 @@ static drm_map_t *ffb_find_map(struct file *filp, unsigned long off)
 unsigned long ffb_get_unmapped_area(struct file *filp,
 unsigned long ffb_get_unmapped_area(struct file *filp,
 				    unsigned long hint,
 				    unsigned long hint,
 				    unsigned long len,
 				    unsigned long len,
-				    unsigned long pgoff,
-				    unsigned long flags)
+				    unsigned long pgoff, unsigned long flags)
 {
 {
 	drm_map_t *map = ffb_find_map(filp, pgoff << PAGE_SHIFT);
 	drm_map_t *map = ffb_find_map(filp, pgoff << PAGE_SHIFT);
 	unsigned long addr = -ENOMEM;
 	unsigned long addr = -ENOMEM;
@@ -175,8 +177,7 @@ unsigned long ffb_get_unmapped_area(struct file *filp,
 	if (!map)
 	if (!map)
 		return get_unmapped_area(NULL, hint, len, pgoff, flags);
 		return get_unmapped_area(NULL, hint, len, pgoff, flags);
 
 
-	if (map->type == _DRM_FRAME_BUFFER ||
-	    map->type == _DRM_REGISTERS) {
+	if (map->type == _DRM_FRAME_BUFFER || map->type == _DRM_REGISTERS) {
 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
 		addr = get_fb_unmapped_area(filp, hint, len, pgoff, flags);
 		addr = get_fb_unmapped_area(filp, hint, len, pgoff, flags);
 #else
 #else
@@ -187,7 +188,7 @@ unsigned long ffb_get_unmapped_area(struct file *filp,
 
 
 		addr = get_unmapped_area(NULL, hint, len + slack, pgoff, flags);
 		addr = get_unmapped_area(NULL, hint, len + slack, pgoff, flags);
 		if (!(addr & ~PAGE_MASK)) {
 		if (!(addr & ~PAGE_MASK)) {
-			unsigned long kvirt = (unsigned long) map->handle;
+			unsigned long kvirt = (unsigned long)map->handle;
 
 
 			if ((kvirt & (SHMLBA - 1)) != (addr & (SHMLBA - 1))) {
 			if ((kvirt & (SHMLBA - 1)) != (addr & (SHMLBA - 1))) {
 				unsigned long koff, aoff;
 				unsigned long koff, aoff;
@@ -207,9 +208,9 @@ unsigned long ffb_get_unmapped_area(struct file *filp,
 	return addr;
 	return addr;
 }
 }
 
 
-static int ffb_presetup(drm_device_t *dev)
+static int ffb_presetup(drm_device_t * dev)
 {
 {
-	ffb_dev_priv_t	*ffb_priv;
+	ffb_dev_priv_t *ffb_priv;
 	int ret = 0;
 	int ret = 0;
 	int i = 0;
 	int i = 0;
 
 
@@ -224,14 +225,11 @@ static int ffb_presetup(drm_device_t *dev)
 	memset(ffb_priv, 0, sizeof(*ffb_priv));
 	memset(ffb_priv, 0, sizeof(*ffb_priv));
 	dev->dev_private = ffb_priv;
 	dev->dev_private = ffb_priv;
 
 
-	ret = ffb_init_one(dev,
-			   ffb_position[i].node,
-			   ffb_position[i].root,
-			   i);
+	ret = ffb_init_one(dev, ffb_position[i].node, ffb_position[i].root, i);
 	return ret;
 	return ret;
 }
 }
 
 
-static void ffb_driver_release(drm_device_t *dev, struct file *filp)
+static void ffb_driver_release(drm_device_t * dev, struct file *filp)
 {
 {
 	ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
 	ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
 	int context = _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock);
 	int context = _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock);
@@ -239,84 +237,82 @@ static void ffb_driver_release(drm_device_t *dev, struct file *filp)
 
 
 	idx = context - 1;
 	idx = context - 1;
 	if (fpriv &&
 	if (fpriv &&
-	    context != DRM_KERNEL_CONTEXT &&
-	    fpriv->hw_state[idx] != NULL) {
+	    context != DRM_KERNEL_CONTEXT && fpriv->hw_state[idx] != NULL) {
 		kfree(fpriv->hw_state[idx]);
 		kfree(fpriv->hw_state[idx]);
 		fpriv->hw_state[idx] = NULL;
 		fpriv->hw_state[idx] = NULL;
-	}	
+	}
 }
 }
 
 
-static void ffb_driver_pretakedown(drm_device_t *dev)
+static void ffb_driver_pretakedown(drm_device_t * dev)
 {
 {
-	if (dev->dev_private) kfree(dev->dev_private);
+	if (dev->dev_private)
+		kfree(dev->dev_private);
 }
 }
 
 
-static int ffb_driver_postcleanup(drm_device_t *dev)
+static int ffb_driver_postcleanup(drm_device_t * dev)
 {
 {
-	if (ffb_position != NULL) kfree(ffb_position);
+	if (ffb_position != NULL)
+		kfree(ffb_position);
 	return 0;
 	return 0;
 }
 }
 
 
-static void ffb_driver_kernel_context_switch_unlock(struct drm_device *dev, drm_lock_t *lock)
+static void ffb_driver_kernel_context_switch_unlock(struct drm_device *dev,
+						    drm_lock_t * lock)
 {
 {
 	dev->lock.filp = 0;
 	dev->lock.filp = 0;
 	{
 	{
 		__volatile__ unsigned int *plock = &dev->lock.hw_lock->lock;
 		__volatile__ unsigned int *plock = &dev->lock.hw_lock->lock;
 		unsigned int old, new, prev, ctx;
 		unsigned int old, new, prev, ctx;
-		
+
 		ctx = lock->context;
 		ctx = lock->context;
 		do {
 		do {
-			old  = *plock;
-			new  = ctx;
+			old = *plock;
+			new = ctx;
 			prev = cmpxchg(plock, old, new);
 			prev = cmpxchg(plock, old, new);
 		} while (prev != old);
 		} while (prev != old);
 	}
 	}
 	wake_up_interruptible(&dev->lock.lock_queue);
 	wake_up_interruptible(&dev->lock.lock_queue);
 }
 }
 
 
-static unsigned long ffb_driver_get_map_ofs(drm_map_t *map)
+static unsigned long ffb_driver_get_map_ofs(drm_map_t * map)
 {
 {
 	return (map->offset & 0xffffffff);
 	return (map->offset & 0xffffffff);
 }
 }
 
 
-static unsigned long ffb_driver_get_reg_ofs(drm_device_t *dev)
+static unsigned long ffb_driver_get_reg_ofs(drm_device_t * dev)
 {
 {
-       ffb_dev_priv_t *ffb_priv = (ffb_dev_priv_t *)dev->dev_private;
-       
-       if (ffb_priv)
-               return ffb_priv->card_phys_base;
-       
-       return 0;
+	ffb_dev_priv_t *ffb_priv = (ffb_dev_priv_t *) dev->dev_private;
+
+	if (ffb_priv)
+		return ffb_priv->card_phys_base;
+
+	return 0;
 }
 }
 
 
-static int postinit( struct drm_device *dev, unsigned long flags ) 
+static int postinit(struct drm_device *dev, unsigned long flags)
 {
 {
-	DRM_INFO( "Initialized %s %d.%d.%d %s on minor %d\n",
-		DRIVER_NAME,
-		DRIVER_MAJOR,
-		DRIVER_MINOR,
-		DRIVER_PATCHLEVEL,
-		DRIVER_DATE,
-		dev->minor
-		);
+	DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
+		 DRIVER_NAME,
+		 DRIVER_MAJOR,
+		 DRIVER_MINOR, DRIVER_PATCHLEVEL, DRIVER_DATE, dev->minor);
 	return 0;
 	return 0;
 }
 }
 
 
-static int version( drm_version_t *version )
+static int version(drm_version_t * version)
 {
 {
 	int len;
 	int len;
 
 
 	version->version_major = DRIVER_MAJOR;
 	version->version_major = DRIVER_MAJOR;
 	version->version_minor = DRIVER_MINOR;
 	version->version_minor = DRIVER_MINOR;
 	version->version_patchlevel = DRIVER_PATCHLEVEL;
 	version->version_patchlevel = DRIVER_PATCHLEVEL;
-	DRM_COPY( version->name, DRIVER_NAME );
-	DRM_COPY( version->date, DRIVER_DATE );
-	DRM_COPY( version->desc, DRIVER_DESC );
+	DRM_COPY(version->name, DRIVER_NAME);
+	DRM_COPY(version->date, DRIVER_DATE);
+	DRM_COPY(version->desc, DRIVER_DESC);
 	return 0;
 	return 0;
 }
 }
 
 
 static drm_ioctl_desc_t ioctls[] = {
 static drm_ioctl_desc_t ioctls[] = {
-	
+
 };
 };
 
 
 static struct drm_driver driver = {
 static struct drm_driver driver = {
@@ -335,14 +331,15 @@ static struct drm_driver driver = {
 	.ioctls = ioctls,
 	.ioctls = ioctls,
 	.num_ioctls = DRM_ARRAY_SIZE(ioctls),
 	.num_ioctls = DRM_ARRAY_SIZE(ioctls),
 	.fops = {
 	.fops = {
-		.owner = THIS_MODULE,
-		.open = drm_open,
-		.release = drm_release,
-		.ioctl = drm_ioctl,
-		.mmap = drm_mmap,
-		.poll = drm_poll,
-		.fasync = drm_fasync,
-	},
+		 .owner = THIS_MODULE,
+		 .open = drm_open,
+		 .release = drm_release,
+		 .ioctl = drm_ioctl,
+		 .mmap = drm_mmap,
+		 .poll = drm_poll,
+		 .fasync = drm_fasync,
+		 }
+	,
 };
 };
 
 
 static int __init ffb_init(void)
 static int __init ffb_init(void)
@@ -357,6 +354,6 @@ static void __exit ffb_exit(void)
 module_init(ffb_init);
 module_init(ffb_init);
 module_exit(ffb_exit);
 module_exit(ffb_exit);
 
 
-MODULE_AUTHOR( DRIVER_AUTHOR );
-MODULE_DESCRIPTION( DRIVER_DESC );
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL and additional rights");
 MODULE_LICENSE("GPL and additional rights");

+ 263 - 170
drivers/char/drm/ffb_drv.h

@@ -5,7 +5,7 @@
  */
  */
 
 
 /* Auxilliary clips. */
 /* Auxilliary clips. */
-typedef struct  {
+typedef struct {
 	volatile unsigned int min;
 	volatile unsigned int min;
 	volatile unsigned int max;
 	volatile unsigned int max;
 } ffb_auxclip, *ffb_auxclipPtr;
 } ffb_auxclip, *ffb_auxclipPtr;
@@ -15,172 +15,265 @@ typedef struct _ffb_fbc {
 	/* Next vertex registers, on the right we list which drawops
 	/* Next vertex registers, on the right we list which drawops
 	 * use said register and the logical name the register has in
 	 * use said register and the logical name the register has in
 	 * that context.
 	 * that context.
-	 */					/* DESCRIPTION		DRAWOP(NAME)	*/
-/*0x00*/unsigned int		pad1[3];	/* Reserved				*/
-/*0x0c*/volatile unsigned int	alpha;		/* ALPHA Transparency			*/
-/*0x10*/volatile unsigned int	red;		/* RED					*/
-/*0x14*/volatile unsigned int	green;		/* GREEN				*/
-/*0x18*/volatile unsigned int	blue;		/* BLUE					*/
-/*0x1c*/volatile unsigned int	z;		/* DEPTH				*/
-/*0x20*/volatile unsigned int	y;		/* Y			triangle(DOYF)	*/
-						/*                      aadot(DYF)	*/
-						/*                      ddline(DYF)	*/
-						/*                      aaline(DYF)	*/
-/*0x24*/volatile unsigned int	x;		/* X			triangle(DOXF)	*/
-						/*                      aadot(DXF)	*/
-						/*                      ddline(DXF)	*/
-						/*                      aaline(DXF)	*/
-/*0x28*/unsigned int		pad2[2];	/* Reserved				*/
-/*0x30*/volatile unsigned int	ryf;		/* Y (alias to DOYF)	ddline(RYF)	*/
-						/*			aaline(RYF)	*/
-						/*			triangle(RYF)	*/
-/*0x34*/volatile unsigned int	rxf;		/* X			ddline(RXF)	*/
-						/*			aaline(RXF)	*/
-						/*			triangle(RXF)	*/
-/*0x38*/unsigned int		pad3[2];	/* Reserved				*/
-/*0x40*/volatile unsigned int	dmyf;		/* Y (alias to DOYF)	triangle(DMYF)	*/
-/*0x44*/volatile unsigned int	dmxf;		/* X			triangle(DMXF)	*/
-/*0x48*/unsigned int		pad4[2];	/* Reserved				*/
-/*0x50*/volatile unsigned int	ebyi;		/* Y (alias to RYI)	polygon(EBYI)	*/
-/*0x54*/volatile unsigned int	ebxi;		/* X			polygon(EBXI)	*/
-/*0x58*/unsigned int		pad5[2];	/* Reserved				*/
-/*0x60*/volatile unsigned int	by;		/* Y			brline(RYI)	*/
-						/*			fastfill(OP)	*/
-						/*			polygon(YI)	*/
-						/*			rectangle(YI)	*/
-						/*			bcopy(SRCY)	*/
-						/*			vscroll(SRCY)	*/
-/*0x64*/volatile unsigned int	bx;		/* X			brline(RXI)	*/
-						/*			polygon(XI)	*/
-						/*			rectangle(XI)	*/
-						/*			bcopy(SRCX)	*/
-						/*			vscroll(SRCX)	*/
-						/*			fastfill(GO)	*/
-/*0x68*/volatile unsigned int	dy;		/* destination Y	fastfill(DSTY)	*/
-						/*			bcopy(DSRY)	*/
-						/*			vscroll(DSRY)	*/
-/*0x6c*/volatile unsigned int	dx;		/* destination X	fastfill(DSTX)	*/
-						/*			bcopy(DSTX)	*/
-						/*			vscroll(DSTX)	*/
-/*0x70*/volatile unsigned int	bh;		/* Y (alias to RYI)	brline(DYI)	*/
-						/*			dot(DYI)	*/
-						/*			polygon(ETYI)	*/
-						/* Height		fastfill(H)	*/
-						/*			bcopy(H)	*/
-						/*			vscroll(H)	*/
-						/* Y count		fastfill(NY)	*/
-/*0x74*/volatile unsigned int	bw;		/* X			dot(DXI)	*/
-						/*			brline(DXI)	*/
-						/*			polygon(ETXI)	*/
-						/*			fastfill(W)	*/
-						/*			bcopy(W)	*/
-						/*			vscroll(W)	*/
-						/*			fastfill(NX)	*/
-/*0x78*/unsigned int		pad6[2];	/* Reserved				*/
-/*0x80*/unsigned int		pad7[32];	/* Reserved				*/
-	
+	 *//* DESCRIPTION          DRAWOP(NAME)    */
+					/*0x00*/ unsigned int pad1[3];
+					/* Reserved                             */
+						/*0x0c*/ volatile unsigned int alpha;
+						/* ALPHA Transparency                   */
+						/*0x10*/ volatile unsigned int red;
+						/* RED                                  */
+						/*0x14*/ volatile unsigned int green;
+						/* GREEN                                */
+						/*0x18*/ volatile unsigned int blue;
+						/* BLUE                                 */
+						/*0x1c*/ volatile unsigned int z;
+						/* DEPTH                                */
+						/*0x20*/ volatile unsigned int y;
+						/* Y                    triangle(DOYF)  */
+	/*                      aadot(DYF)      */
+	/*                      ddline(DYF)     */
+	/*                      aaline(DYF)     */
+						/*0x24*/ volatile unsigned int x;
+						/* X                    triangle(DOXF)  */
+	/*                      aadot(DXF)      */
+	/*                      ddline(DXF)     */
+	/*                      aaline(DXF)     */
+					/*0x28*/ unsigned int pad2[2];
+					/* Reserved                             */
+						/*0x30*/ volatile unsigned int ryf;
+						/* Y (alias to DOYF)    ddline(RYF)     */
+	/*                      aaline(RYF)     */
+	/*                      triangle(RYF)   */
+						/*0x34*/ volatile unsigned int rxf;
+						/* X                    ddline(RXF)     */
+	/*                      aaline(RXF)     */
+	/*                      triangle(RXF)   */
+					/*0x38*/ unsigned int pad3[2];
+					/* Reserved                             */
+						/*0x40*/ volatile unsigned int dmyf;
+						/* Y (alias to DOYF)    triangle(DMYF)  */
+						/*0x44*/ volatile unsigned int dmxf;
+						/* X                    triangle(DMXF)  */
+					/*0x48*/ unsigned int pad4[2];
+					/* Reserved                             */
+						/*0x50*/ volatile unsigned int ebyi;
+						/* Y (alias to RYI)     polygon(EBYI)   */
+						/*0x54*/ volatile unsigned int ebxi;
+						/* X                    polygon(EBXI)   */
+					/*0x58*/ unsigned int pad5[2];
+					/* Reserved                             */
+						/*0x60*/ volatile unsigned int by;
+						/* Y                    brline(RYI)     */
+	/*                      fastfill(OP)    */
+	/*                      polygon(YI)     */
+	/*                      rectangle(YI)   */
+	/*                      bcopy(SRCY)     */
+	/*                      vscroll(SRCY)   */
+						/*0x64*/ volatile unsigned int bx;
+						/* X                    brline(RXI)     */
+	/*                      polygon(XI)     */
+	/*                      rectangle(XI)   */
+	/*                      bcopy(SRCX)     */
+	/*                      vscroll(SRCX)   */
+	/*                      fastfill(GO)    */
+						/*0x68*/ volatile unsigned int dy;
+						/* destination Y        fastfill(DSTY)  */
+	/*                      bcopy(DSRY)     */
+	/*                      vscroll(DSRY)   */
+						/*0x6c*/ volatile unsigned int dx;
+						/* destination X        fastfill(DSTX)  */
+	/*                      bcopy(DSTX)     */
+	/*                      vscroll(DSTX)   */
+						/*0x70*/ volatile unsigned int bh;
+						/* Y (alias to RYI)     brline(DYI)     */
+	/*                      dot(DYI)        */
+	/*                      polygon(ETYI)   */
+	/* Height               fastfill(H)     */
+	/*                      bcopy(H)        */
+	/*                      vscroll(H)      */
+	/* Y count              fastfill(NY)    */
+						/*0x74*/ volatile unsigned int bw;
+						/* X                    dot(DXI)        */
+	/*                      brline(DXI)     */
+	/*                      polygon(ETXI)   */
+	/*                      fastfill(W)     */
+	/*                      bcopy(W)        */
+	/*                      vscroll(W)      */
+	/*                      fastfill(NX)    */
+					/*0x78*/ unsigned int pad6[2];
+					/* Reserved                             */
+					/*0x80*/ unsigned int pad7[32];
+					/* Reserved                             */
+
 	/* Setup Unit's vertex state register */
 	/* Setup Unit's vertex state register */
-/*100*/	volatile unsigned int	suvtx;
-/*104*/	unsigned int		pad8[63];	/* Reserved				*/
-	
+/*100*/ volatile unsigned int suvtx;
+					/*104*/ unsigned int pad8[63];
+					/* Reserved                             */
+
 	/* Frame Buffer Control Registers */
 	/* Frame Buffer Control Registers */
-/*200*/	volatile unsigned int	ppc;		/* Pixel Processor Control		*/
-/*204*/	volatile unsigned int	wid;		/* Current WID				*/
-/*208*/	volatile unsigned int	fg;		/* FG data				*/
-/*20c*/	volatile unsigned int	bg;		/* BG data				*/
-/*210*/	volatile unsigned int	consty;		/* Constant Y				*/
-/*214*/	volatile unsigned int	constz;		/* Constant Z				*/
-/*218*/	volatile unsigned int	xclip;		/* X Clip				*/
-/*21c*/	volatile unsigned int	dcss;		/* Depth Cue Scale Slope		*/
-/*220*/	volatile unsigned int	vclipmin;	/* Viewclip XY Min Bounds		*/
-/*224*/	volatile unsigned int	vclipmax;	/* Viewclip XY Max Bounds		*/
-/*228*/	volatile unsigned int	vclipzmin;	/* Viewclip Z Min Bounds		*/
-/*22c*/	volatile unsigned int	vclipzmax;	/* Viewclip Z Max Bounds		*/
-/*230*/	volatile unsigned int	dcsf;		/* Depth Cue Scale Front Bound		*/
-/*234*/	volatile unsigned int	dcsb;		/* Depth Cue Scale Back Bound		*/
-/*238*/	volatile unsigned int	dczf;		/* Depth Cue Z Front			*/
-/*23c*/	volatile unsigned int	dczb;		/* Depth Cue Z Back			*/
-/*240*/	unsigned int		pad9;		/* Reserved				*/
-/*244*/	volatile unsigned int	blendc;		/* Alpha Blend Control			*/
-/*248*/	volatile unsigned int	blendc1;	/* Alpha Blend Color 1			*/
-/*24c*/	volatile unsigned int	blendc2;	/* Alpha Blend Color 2			*/
-/*250*/	volatile unsigned int	fbramitc;	/* FB RAM Interleave Test Control	*/
-/*254*/	volatile unsigned int	fbc;		/* Frame Buffer Control			*/
-/*258*/	volatile unsigned int	rop;		/* Raster OPeration			*/
-/*25c*/	volatile unsigned int	cmp;		/* Frame Buffer Compare			*/
-/*260*/	volatile unsigned int	matchab;	/* Buffer AB Match Mask			*/
-/*264*/	volatile unsigned int	matchc;		/* Buffer C(YZ) Match Mask		*/
-/*268*/	volatile unsigned int	magnab;		/* Buffer AB Magnitude Mask		*/
-/*26c*/	volatile unsigned int	magnc;		/* Buffer C(YZ) Magnitude Mask		*/
-/*270*/	volatile unsigned int	fbcfg0;		/* Frame Buffer Config 0		*/
-/*274*/	volatile unsigned int	fbcfg1;		/* Frame Buffer Config 1		*/
-/*278*/	volatile unsigned int	fbcfg2;		/* Frame Buffer Config 2		*/
-/*27c*/	volatile unsigned int	fbcfg3;		/* Frame Buffer Config 3		*/
-/*280*/	volatile unsigned int	ppcfg;		/* Pixel Processor Config		*/
-/*284*/	volatile unsigned int	pick;		/* Picking Control			*/
-/*288*/	volatile unsigned int	fillmode;	/* FillMode				*/
-/*28c*/	volatile unsigned int	fbramwac;	/* FB RAM Write Address Control		*/
-/*290*/	volatile unsigned int	pmask;		/* RGB PlaneMask			*/
-/*294*/	volatile unsigned int	xpmask;		/* X PlaneMask				*/
-/*298*/	volatile unsigned int	ypmask;		/* Y PlaneMask				*/
-/*29c*/	volatile unsigned int	zpmask;		/* Z PlaneMask				*/
-/*2a0*/	ffb_auxclip		auxclip[4]; 	/* Auxilliary Viewport Clip		*/
-	
+						/*200*/ volatile unsigned int ppc;
+						/* Pixel Processor Control              */
+						/*204*/ volatile unsigned int wid;
+						/* Current WID                          */
+						/*208*/ volatile unsigned int fg;
+						/* FG data                              */
+						/*20c*/ volatile unsigned int bg;
+						/* BG data                              */
+						/*210*/ volatile unsigned int consty;
+						/* Constant Y                           */
+						/*214*/ volatile unsigned int constz;
+						/* Constant Z                           */
+						/*218*/ volatile unsigned int xclip;
+						/* X Clip                               */
+						/*21c*/ volatile unsigned int dcss;
+						/* Depth Cue Scale Slope                */
+						/*220*/ volatile unsigned int vclipmin;
+						/* Viewclip XY Min Bounds               */
+						/*224*/ volatile unsigned int vclipmax;
+						/* Viewclip XY Max Bounds               */
+							/*228*/ volatile unsigned int vclipzmin;
+							/* Viewclip Z Min Bounds                */
+							/*22c*/ volatile unsigned int vclipzmax;
+							/* Viewclip Z Max Bounds                */
+						/*230*/ volatile unsigned int dcsf;
+						/* Depth Cue Scale Front Bound          */
+						/*234*/ volatile unsigned int dcsb;
+						/* Depth Cue Scale Back Bound           */
+						/*238*/ volatile unsigned int dczf;
+						/* Depth Cue Z Front                    */
+						/*23c*/ volatile unsigned int dczb;
+						/* Depth Cue Z Back                     */
+					/*240*/ unsigned int pad9;
+					/* Reserved                             */
+						/*244*/ volatile unsigned int blendc;
+						/* Alpha Blend Control                  */
+						/*248*/ volatile unsigned int blendc1;
+						/* Alpha Blend Color 1                  */
+						/*24c*/ volatile unsigned int blendc2;
+						/* Alpha Blend Color 2                  */
+						/*250*/ volatile unsigned int fbramitc;
+						/* FB RAM Interleave Test Control       */
+						/*254*/ volatile unsigned int fbc;
+						/* Frame Buffer Control                 */
+						/*258*/ volatile unsigned int rop;
+						/* Raster OPeration                     */
+						/*25c*/ volatile unsigned int cmp;
+						/* Frame Buffer Compare                 */
+						/*260*/ volatile unsigned int matchab;
+						/* Buffer AB Match Mask                 */
+						/*264*/ volatile unsigned int matchc;
+						/* Buffer C(YZ) Match Mask              */
+						/*268*/ volatile unsigned int magnab;
+						/* Buffer AB Magnitude Mask             */
+						/*26c*/ volatile unsigned int magnc;
+						/* Buffer C(YZ) Magnitude Mask          */
+						/*270*/ volatile unsigned int fbcfg0;
+						/* Frame Buffer Config 0                */
+						/*274*/ volatile unsigned int fbcfg1;
+						/* Frame Buffer Config 1                */
+						/*278*/ volatile unsigned int fbcfg2;
+						/* Frame Buffer Config 2                */
+						/*27c*/ volatile unsigned int fbcfg3;
+						/* Frame Buffer Config 3                */
+						/*280*/ volatile unsigned int ppcfg;
+						/* Pixel Processor Config               */
+						/*284*/ volatile unsigned int pick;
+						/* Picking Control                      */
+						/*288*/ volatile unsigned int fillmode;
+						/* FillMode                             */
+						/*28c*/ volatile unsigned int fbramwac;
+						/* FB RAM Write Address Control         */
+						/*290*/ volatile unsigned int pmask;
+						/* RGB PlaneMask                        */
+						/*294*/ volatile unsigned int xpmask;
+						/* X PlaneMask                          */
+						/*298*/ volatile unsigned int ypmask;
+						/* Y PlaneMask                          */
+						/*29c*/ volatile unsigned int zpmask;
+						/* Z PlaneMask                          */
+					/*2a0*/ ffb_auxclip auxclip[4];
+					/* Auxilliary Viewport Clip             */
+
 	/* New 3dRAM III support regs */
 	/* New 3dRAM III support regs */
-/*2c0*/	volatile unsigned int	rawblend2;
-/*2c4*/	volatile unsigned int	rawpreblend;
-/*2c8*/	volatile unsigned int	rawstencil;
-/*2cc*/	volatile unsigned int	rawstencilctl;
-/*2d0*/	volatile unsigned int	threedram1;
-/*2d4*/	volatile unsigned int	threedram2;
-/*2d8*/	volatile unsigned int	passin;
-/*2dc*/	volatile unsigned int	rawclrdepth;
-/*2e0*/	volatile unsigned int	rawpmask;
-/*2e4*/	volatile unsigned int	rawcsrc;
-/*2e8*/	volatile unsigned int	rawmatch;
-/*2ec*/	volatile unsigned int	rawmagn;
-/*2f0*/	volatile unsigned int	rawropblend;
-/*2f4*/	volatile unsigned int	rawcmp;
-/*2f8*/	volatile unsigned int	rawwac;
-/*2fc*/	volatile unsigned int	fbramid;
-	
-/*300*/	volatile unsigned int	drawop;		/* Draw OPeration			*/
-/*304*/	unsigned int		pad10[2];	/* Reserved				*/
-/*30c*/	volatile unsigned int	lpat;		/* Line Pattern control			*/
-/*310*/	unsigned int		pad11;		/* Reserved				*/
-/*314*/	volatile unsigned int	fontxy;		/* XY Font coordinate			*/
-/*318*/	volatile unsigned int	fontw;		/* Font Width				*/
-/*31c*/	volatile unsigned int	fontinc;	/* Font Increment			*/
-/*320*/	volatile unsigned int	font;		/* Font bits				*/
-/*324*/	unsigned int		pad12[3];	/* Reserved				*/
-/*330*/	volatile unsigned int	blend2;
-/*334*/	volatile unsigned int	preblend;
-/*338*/	volatile unsigned int	stencil;
-/*33c*/	volatile unsigned int	stencilctl;
+/*2c0*/ volatile unsigned int rawblend2;
+/*2c4*/ volatile unsigned int rawpreblend;
+/*2c8*/ volatile unsigned int rawstencil;
+/*2cc*/ volatile unsigned int rawstencilctl;
+/*2d0*/ volatile unsigned int threedram1;
+/*2d4*/ volatile unsigned int threedram2;
+/*2d8*/ volatile unsigned int passin;
+/*2dc*/ volatile unsigned int rawclrdepth;
+/*2e0*/ volatile unsigned int rawpmask;
+/*2e4*/ volatile unsigned int rawcsrc;
+/*2e8*/ volatile unsigned int rawmatch;
+/*2ec*/ volatile unsigned int rawmagn;
+/*2f0*/ volatile unsigned int rawropblend;
+/*2f4*/ volatile unsigned int rawcmp;
+/*2f8*/ volatile unsigned int rawwac;
+/*2fc*/ volatile unsigned int fbramid;
+
+						/*300*/ volatile unsigned int drawop;
+						/* Draw OPeration                       */
+					/*304*/ unsigned int pad10[2];
+					/* Reserved                             */
+						/*30c*/ volatile unsigned int lpat;
+						/* Line Pattern control                 */
+					/*310*/ unsigned int pad11;
+					/* Reserved                             */
+						/*314*/ volatile unsigned int fontxy;
+						/* XY Font coordinate                   */
+						/*318*/ volatile unsigned int fontw;
+						/* Font Width                           */
+						/*31c*/ volatile unsigned int fontinc;
+						/* Font Increment                       */
+						/*320*/ volatile unsigned int font;
+						/* Font bits                            */
+					/*324*/ unsigned int pad12[3];
+					/* Reserved                             */
+/*330*/ volatile unsigned int blend2;
+/*334*/ volatile unsigned int preblend;
+/*338*/ volatile unsigned int stencil;
+/*33c*/ volatile unsigned int stencilctl;
 
 
-/*340*/	unsigned int		pad13[4];	/* Reserved				*/
-/*350*/	volatile unsigned int	dcss1;		/* Depth Cue Scale Slope 1		*/
-/*354*/	volatile unsigned int	dcss2;		/* Depth Cue Scale Slope 2		*/
-/*358*/	volatile unsigned int	dcss3;		/* Depth Cue Scale Slope 3		*/
-/*35c*/	volatile unsigned int	widpmask;
-/*360*/	volatile unsigned int	dcs2;
-/*364*/	volatile unsigned int	dcs3;
-/*368*/	volatile unsigned int	dcs4;
-/*36c*/	unsigned int		pad14;		/* Reserved				*/
-/*370*/	volatile unsigned int	dcd2;
-/*374*/	volatile unsigned int	dcd3;
-/*378*/	volatile unsigned int	dcd4;
-/*37c*/	unsigned int		pad15;		/* Reserved				*/
-/*380*/	volatile unsigned int	pattern[32];	/* area Pattern				*/
-/*400*/	unsigned int		pad16[8];	/* Reserved				*/
-/*420*/	volatile unsigned int	reset;		/* chip RESET				*/
-/*424*/	unsigned int		pad17[247];	/* Reserved				*/
-/*800*/	volatile unsigned int	devid;		/* Device ID				*/
-/*804*/	unsigned int		pad18[63];	/* Reserved				*/
-/*900*/	volatile unsigned int	ucsr;		/* User Control & Status Register	*/
-/*904*/	unsigned int		pad19[31];	/* Reserved				*/
-/*980*/	volatile unsigned int	mer;		/* Mode Enable Register			*/
-/*984*/	unsigned int		pad20[1439];	/* Reserved				*/
+					/*340*/ unsigned int pad13[4];
+					/* Reserved                             */
+						/*350*/ volatile unsigned int dcss1;
+						/* Depth Cue Scale Slope 1              */
+						/*354*/ volatile unsigned int dcss2;
+						/* Depth Cue Scale Slope 2              */
+						/*358*/ volatile unsigned int dcss3;
+						/* Depth Cue Scale Slope 3              */
+/*35c*/ volatile unsigned int widpmask;
+/*360*/ volatile unsigned int dcs2;
+/*364*/ volatile unsigned int dcs3;
+/*368*/ volatile unsigned int dcs4;
+					/*36c*/ unsigned int pad14;
+					/* Reserved                             */
+/*370*/ volatile unsigned int dcd2;
+/*374*/ volatile unsigned int dcd3;
+/*378*/ volatile unsigned int dcd4;
+					/*37c*/ unsigned int pad15;
+					/* Reserved                             */
+							/*380*/ volatile unsigned int pattern[32];
+							/* area Pattern                         */
+					/*400*/ unsigned int pad16[8];
+					/* Reserved                             */
+						/*420*/ volatile unsigned int reset;
+						/* chip RESET                           */
+						/*424*/ unsigned int pad17[247];
+						/* Reserved                             */
+						/*800*/ volatile unsigned int devid;
+						/* Device ID                            */
+					/*804*/ unsigned int pad18[63];
+					/* Reserved                             */
+						/*900*/ volatile unsigned int ucsr;
+						/* User Control & Status Register       */
+					/*904*/ unsigned int pad19[31];
+					/* Reserved                             */
+						/*980*/ volatile unsigned int mer;
+						/* Mode Enable Register                 */
+						/*984*/ unsigned int pad20[1439];
+						/* Reserved                             */
 } ffb_fbc, *ffb_fbcPtr;
 } ffb_fbc, *ffb_fbcPtr;
 
 
 struct ffb_hw_context {
 struct ffb_hw_context {
@@ -263,16 +356,16 @@ enum ffb_chip_type {
 
 
 typedef struct ffb_dev_priv {
 typedef struct ffb_dev_priv {
 	/* Misc software state. */
 	/* Misc software state. */
-	int			prom_node;
-	enum ffb_chip_type	ffb_type;
-	u64			card_phys_base;
-	struct miscdevice 	miscdev;
+	int prom_node;
+	enum ffb_chip_type ffb_type;
+	u64 card_phys_base;
+	struct miscdevice miscdev;
 
 
 	/* Controller registers. */
 	/* Controller registers. */
-	ffb_fbcPtr		regs;
+	ffb_fbcPtr regs;
 
 
 	/* Context table. */
 	/* Context table. */
-	struct ffb_hw_context	*hw_state[FFB_MAX_CTXS];
+	struct ffb_hw_context *hw_state[FFB_MAX_CTXS];
 } ffb_dev_priv_t;
 } ffb_dev_priv_t;
 
 
 extern unsigned long ffb_get_unmapped_area(struct file *filp,
 extern unsigned long ffb_get_unmapped_area(struct file *filp,
@@ -283,4 +376,4 @@ extern unsigned long ffb_get_unmapped_area(struct file *filp,
 extern void ffb_set_context_ioctls(void);
 extern void ffb_set_context_ioctls(void);
 extern drm_ioctl_desc_t DRM(ioctls)[];
 extern drm_ioctl_desc_t DRM(ioctls)[];
 
 
-extern int ffb_driver_context_switch(drm_device_t *dev, int old, int new);
+extern int ffb_driver_context_switch(drm_device_t * dev, int old, int new);

+ 536 - 551
drivers/char/drm/i810_dma.c

@@ -45,102 +45,101 @@
 #define I810_BUF_UNMAPPED 0
 #define I810_BUF_UNMAPPED 0
 #define I810_BUF_MAPPED   1
 #define I810_BUF_MAPPED   1
 
 
-static drm_buf_t *i810_freelist_get(drm_device_t *dev)
+static drm_buf_t *i810_freelist_get(drm_device_t * dev)
 {
 {
-   	drm_device_dma_t *dma = dev->dma;
-	int		 i;
-   	int 		 used;
+	drm_device_dma_t *dma = dev->dma;
+	int i;
+	int used;
 
 
 	/* Linear search might not be the best solution */
 	/* Linear search might not be the best solution */
 
 
-   	for (i = 0; i < dma->buf_count; i++) {
-	   	drm_buf_t *buf = dma->buflist[ i ];
-	   	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+	for (i = 0; i < dma->buf_count; i++) {
+		drm_buf_t *buf = dma->buflist[i];
+		drm_i810_buf_priv_t *buf_priv = buf->dev_private;
 		/* In use is already a pointer */
 		/* In use is already a pointer */
-	   	used = cmpxchg(buf_priv->in_use, I810_BUF_FREE,
+		used = cmpxchg(buf_priv->in_use, I810_BUF_FREE,
 			       I810_BUF_CLIENT);
 			       I810_BUF_CLIENT);
 		if (used == I810_BUF_FREE) {
 		if (used == I810_BUF_FREE) {
 			return buf;
 			return buf;
 		}
 		}
 	}
 	}
-   	return NULL;
+	return NULL;
 }
 }
 
 
 /* This should only be called if the buffer is not sent to the hardware
 /* This should only be called if the buffer is not sent to the hardware
  * yet, the hardware updates in use for us once its on the ring buffer.
  * yet, the hardware updates in use for us once its on the ring buffer.
  */
  */
 
 
-static int i810_freelist_put(drm_device_t *dev, drm_buf_t *buf)
+static int i810_freelist_put(drm_device_t * dev, drm_buf_t * buf)
 {
 {
-   	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-   	int used;
+	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+	int used;
 
 
-   	/* In use is already a pointer */
-   	used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_FREE);
+	/* In use is already a pointer */
+	used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_FREE);
 	if (used != I810_BUF_CLIENT) {
 	if (used != I810_BUF_CLIENT) {
-	   	DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx);
-	   	return -EINVAL;
+		DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx);
+		return -EINVAL;
 	}
 	}
 
 
-   	return 0;
+	return 0;
 }
 }
 
 
 static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
 static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
 {
 {
-	drm_file_t	    *priv	  = filp->private_data;
-	drm_device_t	    *dev;
-	drm_i810_private_t  *dev_priv;
-	drm_buf_t           *buf;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev;
+	drm_i810_private_t *dev_priv;
+	drm_buf_t *buf;
 	drm_i810_buf_priv_t *buf_priv;
 	drm_i810_buf_priv_t *buf_priv;
 
 
 	lock_kernel();
 	lock_kernel();
-	dev	 = priv->head->dev;
+	dev = priv->head->dev;
 	dev_priv = dev->dev_private;
 	dev_priv = dev->dev_private;
-	buf      = dev_priv->mmap_buffer;
+	buf = dev_priv->mmap_buffer;
 	buf_priv = buf->dev_private;
 	buf_priv = buf->dev_private;
 
 
 	vma->vm_flags |= (VM_IO | VM_DONTCOPY);
 	vma->vm_flags |= (VM_IO | VM_DONTCOPY);
 	vma->vm_file = filp;
 	vma->vm_file = filp;
 
 
-   	buf_priv->currently_mapped = I810_BUF_MAPPED;
+	buf_priv->currently_mapped = I810_BUF_MAPPED;
 	unlock_kernel();
 	unlock_kernel();
 
 
 	if (io_remap_pfn_range(vma, vma->vm_start,
 	if (io_remap_pfn_range(vma, vma->vm_start,
-			     VM_OFFSET(vma) >> PAGE_SHIFT,
-			     vma->vm_end - vma->vm_start,
-			     vma->vm_page_prot)) return -EAGAIN;
+			       VM_OFFSET(vma) >> PAGE_SHIFT,
+			       vma->vm_end - vma->vm_start, vma->vm_page_prot))
+		return -EAGAIN;
 	return 0;
 	return 0;
 }
 }
 
 
 static struct file_operations i810_buffer_fops = {
 static struct file_operations i810_buffer_fops = {
-	.open	 = drm_open,
-	.flush	 = drm_flush,
+	.open = drm_open,
+	.flush = drm_flush,
 	.release = drm_release,
 	.release = drm_release,
-	.ioctl	 = drm_ioctl,
-	.mmap	 = i810_mmap_buffers,
-	.fasync  = drm_fasync,
+	.ioctl = drm_ioctl,
+	.mmap = i810_mmap_buffers,
+	.fasync = drm_fasync,
 };
 };
 
 
-static int i810_map_buffer(drm_buf_t *buf, struct file *filp)
+static int i810_map_buffer(drm_buf_t * buf, struct file *filp)
 {
 {
-	drm_file_t	  *priv	  = filp->private_data;
-	drm_device_t	  *dev	  = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
 	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-      	drm_i810_private_t *dev_priv = dev->dev_private;
-   	struct file_operations *old_fops;
+	drm_i810_private_t *dev_priv = dev->dev_private;
+	struct file_operations *old_fops;
 	int retcode = 0;
 	int retcode = 0;
 
 
-	if (buf_priv->currently_mapped == I810_BUF_MAPPED) 
+	if (buf_priv->currently_mapped == I810_BUF_MAPPED)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	down_write( &current->mm->mmap_sem );
+	down_write(&current->mm->mmap_sem);
 	old_fops = filp->f_op;
 	old_fops = filp->f_op;
 	filp->f_op = &i810_buffer_fops;
 	filp->f_op = &i810_buffer_fops;
 	dev_priv->mmap_buffer = buf;
 	dev_priv->mmap_buffer = buf;
 	buf_priv->virtual = (void *)do_mmap(filp, 0, buf->total,
 	buf_priv->virtual = (void *)do_mmap(filp, 0, buf->total,
-					    PROT_READ|PROT_WRITE,
-					    MAP_SHARED,
-					    buf->bus_address);
+					    PROT_READ | PROT_WRITE,
+					    MAP_SHARED, buf->bus_address);
 	dev_priv->mmap_buffer = NULL;
 	dev_priv->mmap_buffer = NULL;
 	filp->f_op = old_fops;
 	filp->f_op = old_fops;
 	if ((unsigned long)buf_priv->virtual > -1024UL) {
 	if ((unsigned long)buf_priv->virtual > -1024UL) {
@@ -149,12 +148,12 @@ static int i810_map_buffer(drm_buf_t *buf, struct file *filp)
 		retcode = (signed int)buf_priv->virtual;
 		retcode = (signed int)buf_priv->virtual;
 		buf_priv->virtual = NULL;
 		buf_priv->virtual = NULL;
 	}
 	}
-	up_write( &current->mm->mmap_sem );
+	up_write(&current->mm->mmap_sem);
 
 
 	return retcode;
 	return retcode;
 }
 }
 
 
-static int i810_unmap_buffer(drm_buf_t *buf)
+static int i810_unmap_buffer(drm_buf_t * buf)
 {
 {
 	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
 	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
 	int retcode = 0;
 	int retcode = 0;
@@ -168,43 +167,43 @@ static int i810_unmap_buffer(drm_buf_t *buf)
 			    (size_t) buf->total);
 			    (size_t) buf->total);
 	up_write(&current->mm->mmap_sem);
 	up_write(&current->mm->mmap_sem);
 
 
-   	buf_priv->currently_mapped = I810_BUF_UNMAPPED;
-   	buf_priv->virtual = NULL;
+	buf_priv->currently_mapped = I810_BUF_UNMAPPED;
+	buf_priv->virtual = NULL;
 
 
 	return retcode;
 	return retcode;
 }
 }
 
 
-static int i810_dma_get_buffer(drm_device_t *dev, drm_i810_dma_t *d,
+static int i810_dma_get_buffer(drm_device_t * dev, drm_i810_dma_t * d,
 			       struct file *filp)
 			       struct file *filp)
 {
 {
-	drm_buf_t	  *buf;
+	drm_buf_t *buf;
 	drm_i810_buf_priv_t *buf_priv;
 	drm_i810_buf_priv_t *buf_priv;
 	int retcode = 0;
 	int retcode = 0;
 
 
 	buf = i810_freelist_get(dev);
 	buf = i810_freelist_get(dev);
 	if (!buf) {
 	if (!buf) {
 		retcode = -ENOMEM;
 		retcode = -ENOMEM;
-	   	DRM_DEBUG("retcode=%d\n", retcode);
+		DRM_DEBUG("retcode=%d\n", retcode);
 		return retcode;
 		return retcode;
 	}
 	}
 
 
 	retcode = i810_map_buffer(buf, filp);
 	retcode = i810_map_buffer(buf, filp);
 	if (retcode) {
 	if (retcode) {
 		i810_freelist_put(dev, buf);
 		i810_freelist_put(dev, buf);
-	   	DRM_ERROR("mapbuf failed, retcode %d\n", retcode);
+		DRM_ERROR("mapbuf failed, retcode %d\n", retcode);
 		return retcode;
 		return retcode;
 	}
 	}
 	buf->filp = filp;
 	buf->filp = filp;
 	buf_priv = buf->dev_private;
 	buf_priv = buf->dev_private;
 	d->granted = 1;
 	d->granted = 1;
-   	d->request_idx = buf->idx;
-   	d->request_size = buf->total;
-   	d->virtual = buf_priv->virtual;
+	d->request_idx = buf->idx;
+	d->request_size = buf->total;
+	d->virtual = buf_priv->virtual;
 
 
 	return retcode;
 	return retcode;
 }
 }
 
 
-static int i810_dma_cleanup(drm_device_t *dev)
+static int i810_dma_cleanup(drm_device_t * dev)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
 
 
@@ -217,165 +216,167 @@ static int i810_dma_cleanup(drm_device_t *dev)
 
 
 	if (dev->dev_private) {
 	if (dev->dev_private) {
 		int i;
 		int i;
-	   	drm_i810_private_t *dev_priv =
-	     		(drm_i810_private_t *) dev->dev_private;
+		drm_i810_private_t *dev_priv =
+		    (drm_i810_private_t *) dev->dev_private;
 
 
 		if (dev_priv->ring.virtual_start) {
 		if (dev_priv->ring.virtual_start) {
-		   	drm_ioremapfree((void *) dev_priv->ring.virtual_start,
-					 dev_priv->ring.Size, dev);
+			drm_ioremapfree((void *)dev_priv->ring.virtual_start,
+					dev_priv->ring.Size, dev);
 		}
 		}
-	   	if (dev_priv->hw_status_page) {
-		   	pci_free_consistent(dev->pdev, PAGE_SIZE,
+		if (dev_priv->hw_status_page) {
+			pci_free_consistent(dev->pdev, PAGE_SIZE,
 					    dev_priv->hw_status_page,
 					    dev_priv->hw_status_page,
 					    dev_priv->dma_status_page);
 					    dev_priv->dma_status_page);
-		   	/* Need to rewrite hardware status page */
-		   	I810_WRITE(0x02080, 0x1ffff000);
+			/* Need to rewrite hardware status page */
+			I810_WRITE(0x02080, 0x1ffff000);
 		}
 		}
-	   	drm_free(dev->dev_private, sizeof(drm_i810_private_t),
+		drm_free(dev->dev_private, sizeof(drm_i810_private_t),
 			 DRM_MEM_DRIVER);
 			 DRM_MEM_DRIVER);
-	   	dev->dev_private = NULL;
+		dev->dev_private = NULL;
 
 
 		for (i = 0; i < dma->buf_count; i++) {
 		for (i = 0; i < dma->buf_count; i++) {
-			drm_buf_t *buf = dma->buflist[ i ];
+			drm_buf_t *buf = dma->buflist[i];
 			drm_i810_buf_priv_t *buf_priv = buf->dev_private;
 			drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-			if ( buf_priv->kernel_virtual && buf->total )
-				drm_ioremapfree(buf_priv->kernel_virtual, buf->total, dev);
+			if (buf_priv->kernel_virtual && buf->total)
+				drm_ioremapfree(buf_priv->kernel_virtual,
+						buf->total, dev);
 		}
 		}
 	}
 	}
-   	return 0;
+	return 0;
 }
 }
 
 
-static int i810_wait_ring(drm_device_t *dev, int n)
+static int i810_wait_ring(drm_device_t * dev, int n)
 {
 {
-   	drm_i810_private_t *dev_priv = dev->dev_private;
-   	drm_i810_ring_buffer_t *ring = &(dev_priv->ring);
-   	int iters = 0;
-   	unsigned long end;
+	drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_ring_buffer_t *ring = &(dev_priv->ring);
+	int iters = 0;
+	unsigned long end;
 	unsigned int last_head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
 	unsigned int last_head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
 
 
-	end = jiffies + (HZ*3);
-   	while (ring->space < n) {
-	   	ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-	   	ring->space = ring->head - (ring->tail+8);
-		if (ring->space < 0) ring->space += ring->Size;
-	   
+	end = jiffies + (HZ * 3);
+	while (ring->space < n) {
+		ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+		ring->space = ring->head - (ring->tail + 8);
+		if (ring->space < 0)
+			ring->space += ring->Size;
+
 		if (ring->head != last_head) {
 		if (ring->head != last_head) {
-			end = jiffies + (HZ*3);
+			end = jiffies + (HZ * 3);
 			last_head = ring->head;
 			last_head = ring->head;
 		}
 		}
-	  
-	   	iters++;
+
+		iters++;
 		if (time_before(end, jiffies)) {
 		if (time_before(end, jiffies)) {
-		   	DRM_ERROR("space: %d wanted %d\n", ring->space, n);
-		   	DRM_ERROR("lockup\n");
-		   	goto out_wait_ring;
+			DRM_ERROR("space: %d wanted %d\n", ring->space, n);
+			DRM_ERROR("lockup\n");
+			goto out_wait_ring;
 		}
 		}
 		udelay(1);
 		udelay(1);
 	}
 	}
 
 
-out_wait_ring:
-   	return iters;
+      out_wait_ring:
+	return iters;
 }
 }
 
 
-static void i810_kernel_lost_context(drm_device_t *dev)
+static void i810_kernel_lost_context(drm_device_t * dev)
 {
 {
-      	drm_i810_private_t *dev_priv = dev->dev_private;
-   	drm_i810_ring_buffer_t *ring = &(dev_priv->ring);
+	drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_ring_buffer_t *ring = &(dev_priv->ring);
 
 
-   	ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-     	ring->tail = I810_READ(LP_RING + RING_TAIL);
-     	ring->space = ring->head - (ring->tail+8);
-     	if (ring->space < 0) ring->space += ring->Size;
+	ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+	ring->tail = I810_READ(LP_RING + RING_TAIL);
+	ring->space = ring->head - (ring->tail + 8);
+	if (ring->space < 0)
+		ring->space += ring->Size;
 }
 }
 
 
-static int i810_freelist_init(drm_device_t *dev, drm_i810_private_t *dev_priv)
+static int i810_freelist_init(drm_device_t * dev, drm_i810_private_t * dev_priv)
 {
 {
-      	drm_device_dma_t *dma = dev->dma;
-   	int my_idx = 24;
-   	u32 *hw_status = (u32 *)(dev_priv->hw_status_page + my_idx);
-   	int i;
+	drm_device_dma_t *dma = dev->dma;
+	int my_idx = 24;
+	u32 *hw_status = (u32 *) (dev_priv->hw_status_page + my_idx);
+	int i;
 
 
 	if (dma->buf_count > 1019) {
 	if (dma->buf_count > 1019) {
-	   	/* Not enough space in the status page for the freelist */
-	   	return -EINVAL;
+		/* Not enough space in the status page for the freelist */
+		return -EINVAL;
 	}
 	}
 
 
-   	for (i = 0; i < dma->buf_count; i++) {
-	   	drm_buf_t *buf = dma->buflist[ i ];
-	   	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+	for (i = 0; i < dma->buf_count; i++) {
+		drm_buf_t *buf = dma->buflist[i];
+		drm_i810_buf_priv_t *buf_priv = buf->dev_private;
 
 
-	   	buf_priv->in_use = hw_status++;
-	   	buf_priv->my_use_idx = my_idx;
-	   	my_idx += 4;
+		buf_priv->in_use = hw_status++;
+		buf_priv->my_use_idx = my_idx;
+		my_idx += 4;
 
 
-	   	*buf_priv->in_use = I810_BUF_FREE;
+		*buf_priv->in_use = I810_BUF_FREE;
 
 
 		buf_priv->kernel_virtual = drm_ioremap(buf->bus_address,
 		buf_priv->kernel_virtual = drm_ioremap(buf->bus_address,
-							buf->total, dev);
+						       buf->total, dev);
 	}
 	}
 	return 0;
 	return 0;
 }
 }
 
 
-static int i810_dma_initialize(drm_device_t *dev,
-			       drm_i810_private_t *dev_priv,
-			       drm_i810_init_t *init)
+static int i810_dma_initialize(drm_device_t * dev,
+			       drm_i810_private_t * dev_priv,
+			       drm_i810_init_t * init)
 {
 {
 	struct list_head *list;
 	struct list_head *list;
 
 
-   	memset(dev_priv, 0, sizeof(drm_i810_private_t));
+	memset(dev_priv, 0, sizeof(drm_i810_private_t));
 
 
 	list_for_each(list, &dev->maplist->head) {
 	list_for_each(list, &dev->maplist->head) {
 		drm_map_list_t *r_list = list_entry(list, drm_map_list_t, head);
 		drm_map_list_t *r_list = list_entry(list, drm_map_list_t, head);
 		if (r_list->map &&
 		if (r_list->map &&
 		    r_list->map->type == _DRM_SHM &&
 		    r_list->map->type == _DRM_SHM &&
-		    r_list->map->flags & _DRM_CONTAINS_LOCK ) {
+		    r_list->map->flags & _DRM_CONTAINS_LOCK) {
 			dev_priv->sarea_map = r_list->map;
 			dev_priv->sarea_map = r_list->map;
- 			break;
- 		}
- 	}
+			break;
+		}
+	}
 	if (!dev_priv->sarea_map) {
 	if (!dev_priv->sarea_map) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
-	   	i810_dma_cleanup(dev);
-	   	DRM_ERROR("can not find sarea!\n");
-	   	return -EINVAL;
+		i810_dma_cleanup(dev);
+		DRM_ERROR("can not find sarea!\n");
+		return -EINVAL;
 	}
 	}
 	dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
 	dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
 	if (!dev_priv->mmio_map) {
 	if (!dev_priv->mmio_map) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
-	   	i810_dma_cleanup(dev);
-	   	DRM_ERROR("can not find mmio map!\n");
-	   	return -EINVAL;
+		i810_dma_cleanup(dev);
+		DRM_ERROR("can not find mmio map!\n");
+		return -EINVAL;
 	}
 	}
 	dev->agp_buffer_token = init->buffers_offset;
 	dev->agp_buffer_token = init->buffers_offset;
 	dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
 	dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
 	if (!dev->agp_buffer_map) {
 	if (!dev->agp_buffer_map) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
-	   	i810_dma_cleanup(dev);
-	   	DRM_ERROR("can not find dma buffer map!\n");
-	   	return -EINVAL;
+		i810_dma_cleanup(dev);
+		DRM_ERROR("can not find dma buffer map!\n");
+		return -EINVAL;
 	}
 	}
 
 
 	dev_priv->sarea_priv = (drm_i810_sarea_t *)
 	dev_priv->sarea_priv = (drm_i810_sarea_t *)
-		((u8 *)dev_priv->sarea_map->handle +
-		 init->sarea_priv_offset);
+	    ((u8 *) dev_priv->sarea_map->handle + init->sarea_priv_offset);
 
 
-   	dev_priv->ring.Start = init->ring_start;
-   	dev_priv->ring.End = init->ring_end;
-   	dev_priv->ring.Size = init->ring_size;
+	dev_priv->ring.Start = init->ring_start;
+	dev_priv->ring.End = init->ring_end;
+	dev_priv->ring.Size = init->ring_size;
 
 
-   	dev_priv->ring.virtual_start = drm_ioremap(dev->agp->base +
-						    init->ring_start,
-						    init->ring_size, dev);
+	dev_priv->ring.virtual_start = drm_ioremap(dev->agp->base +
+						   init->ring_start,
+						   init->ring_size, dev);
 
 
-   	if (dev_priv->ring.virtual_start == NULL) {
-		dev->dev_private = (void *) dev_priv;
-	   	i810_dma_cleanup(dev);
-	   	DRM_ERROR("can not ioremap virtual address for"
+	if (dev_priv->ring.virtual_start == NULL) {
+		dev->dev_private = (void *)dev_priv;
+		i810_dma_cleanup(dev);
+		DRM_ERROR("can not ioremap virtual address for"
 			  " ring buffer\n");
 			  " ring buffer\n");
-	   	return -ENOMEM;
+		return -ENOMEM;
 	}
 	}
 
 
-   	dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
+	dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
 
 
 	dev_priv->w = init->w;
 	dev_priv->w = init->w;
 	dev_priv->h = init->h;
 	dev_priv->h = init->h;
@@ -391,33 +392,33 @@ static int i810_dma_initialize(drm_device_t *dev,
 	dev_priv->back_di1 = init->back_offset | init->pitch_bits;
 	dev_priv->back_di1 = init->back_offset | init->pitch_bits;
 	dev_priv->zi1 = init->depth_offset | init->pitch_bits;
 	dev_priv->zi1 = init->depth_offset | init->pitch_bits;
 
 
-   	/* Program Hardware Status Page */
-   	dev_priv->hw_status_page =
-		pci_alloc_consistent(dev->pdev, PAGE_SIZE,
-						&dev_priv->dma_status_page);
-   	if (!dev_priv->hw_status_page) {
+	/* Program Hardware Status Page */
+	dev_priv->hw_status_page =
+	    pci_alloc_consistent(dev->pdev, PAGE_SIZE,
+				 &dev_priv->dma_status_page);
+	if (!dev_priv->hw_status_page) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
 		i810_dma_cleanup(dev);
 		i810_dma_cleanup(dev);
 		DRM_ERROR("Can not allocate hardware status page\n");
 		DRM_ERROR("Can not allocate hardware status page\n");
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
-   	memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
-   	DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
+	memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
+	DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
 
 
 	I810_WRITE(0x02080, dev_priv->dma_status_page);
 	I810_WRITE(0x02080, dev_priv->dma_status_page);
-   	DRM_DEBUG("Enabled hardware status page\n");
+	DRM_DEBUG("Enabled hardware status page\n");
 
 
-   	/* Now we need to init our freelist */
+	/* Now we need to init our freelist */
 	if (i810_freelist_init(dev, dev_priv) != 0) {
 	if (i810_freelist_init(dev, dev_priv) != 0) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
-	   	i810_dma_cleanup(dev);
-	   	DRM_ERROR("Not enough space in the status page for"
+		i810_dma_cleanup(dev);
+		DRM_ERROR("Not enough space in the status page for"
 			  " the freelist\n");
 			  " the freelist\n");
-	   	return -ENOMEM;
+		return -ENOMEM;
 	}
 	}
 	dev->dev_private = (void *)dev_priv;
 	dev->dev_private = (void *)dev_priv;
 
 
-   	return 0;
+	return 0;
 }
 }
 
 
 /* i810 DRM version 1.1 used a smaller init structure with different
 /* i810 DRM version 1.1 used a smaller init structure with different
@@ -431,12 +432,12 @@ static int i810_dma_initialize(drm_device_t *dev,
  *    If it isn't then we have a v1.1 client. Fix up params.
  *    If it isn't then we have a v1.1 client. Fix up params.
  *    If it is, then we have a 1.2 client... get the rest of the data.
  *    If it is, then we have a 1.2 client... get the rest of the data.
  */
  */
-static int i810_dma_init_compat(drm_i810_init_t *init, unsigned long arg)
+static int i810_dma_init_compat(drm_i810_init_t * init, unsigned long arg)
 {
 {
 
 
 	/* Get v1.1 init data */
 	/* Get v1.1 init data */
-	if (copy_from_user(init, (drm_i810_pre12_init_t __user *)arg,
-			  sizeof(drm_i810_pre12_init_t))) {
+	if (copy_from_user(init, (drm_i810_pre12_init_t __user *) arg,
+			   sizeof(drm_i810_pre12_init_t))) {
 		return -EFAULT;
 		return -EFAULT;
 	}
 	}
 
 
@@ -444,7 +445,7 @@ static int i810_dma_init_compat(drm_i810_init_t *init, unsigned long arg)
 
 
 		/* This is a v1.2 client, just get the v1.2 init data */
 		/* This is a v1.2 client, just get the v1.2 init data */
 		DRM_INFO("Using POST v1.2 init.\n");
 		DRM_INFO("Using POST v1.2 init.\n");
-		if (copy_from_user(init, (drm_i810_init_t __user *)arg,
+		if (copy_from_user(init, (drm_i810_init_t __user *) arg,
 				   sizeof(drm_i810_init_t))) {
 				   sizeof(drm_i810_init_t))) {
 			return -EFAULT;
 			return -EFAULT;
 		}
 		}
@@ -452,246 +453,239 @@ static int i810_dma_init_compat(drm_i810_init_t *init, unsigned long arg)
 
 
 		/* This is a v1.1 client, fix the params */
 		/* This is a v1.1 client, fix the params */
 		DRM_INFO("Using PRE v1.2 init.\n");
 		DRM_INFO("Using PRE v1.2 init.\n");
-	 	init->pitch_bits = init->h;
-	 	init->pitch = init->w;
-	 	init->h = init->overlay_physical;
-	 	init->w = init->overlay_offset;
-	 	init->overlay_physical = 0;
-	 	init->overlay_offset = 0;
+		init->pitch_bits = init->h;
+		init->pitch = init->w;
+		init->h = init->overlay_physical;
+		init->w = init->overlay_offset;
+		init->overlay_physical = 0;
+		init->overlay_offset = 0;
 	}
 	}
 
 
 	return 0;
 	return 0;
 }
 }
 
 
 static int i810_dma_init(struct inode *inode, struct file *filp,
 static int i810_dma_init(struct inode *inode, struct file *filp,
-		  unsigned int cmd, unsigned long arg)
+			 unsigned int cmd, unsigned long arg)
 {
 {
-   	drm_file_t *priv = filp->private_data;
-   	drm_device_t *dev = priv->head->dev;
-   	drm_i810_private_t *dev_priv;
-   	drm_i810_init_t init;
-   	int retcode = 0;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_i810_private_t *dev_priv;
+	drm_i810_init_t init;
+	int retcode = 0;
 
 
 	/* Get only the init func */
 	/* Get only the init func */
-	if (copy_from_user(&init, (void __user *)arg, sizeof(drm_i810_init_func_t))) 
+	if (copy_from_user
+	    (&init, (void __user *)arg, sizeof(drm_i810_init_func_t)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-   	switch(init.func) {
-	 	case I810_INIT_DMA:
-	 	       	/* This case is for backward compatibility. It
-			 * handles XFree 4.1.0 and 4.2.0, and has to
-			 * do some parameter checking as described below.
-			 * It will someday go away.
-			 */
-			retcode = i810_dma_init_compat(&init, arg);
-			if (retcode)
-				return retcode;
-
-	   		dev_priv = drm_alloc(sizeof(drm_i810_private_t),
-					     DRM_MEM_DRIVER);
-	   		if (dev_priv == NULL)
-				return -ENOMEM;
-	   		retcode = i810_dma_initialize(dev, dev_priv, &init);
-			break;
-
-		default:
-	 	case I810_INIT_DMA_1_4:
-			DRM_INFO("Using v1.4 init.\n");
-  			if (copy_from_user(&init, (drm_i810_init_t __user *)arg,
-					  sizeof(drm_i810_init_t))) {
-				return -EFAULT;
-			}
-	   		dev_priv = drm_alloc(sizeof(drm_i810_private_t),
-					     DRM_MEM_DRIVER);
-			if (dev_priv == NULL) 
-				return -ENOMEM;
-	   		retcode = i810_dma_initialize(dev, dev_priv, &init);
-			break;
-
-	 	case I810_CLEANUP_DMA:
-		        DRM_INFO("DMA Cleanup\n");
-	   		retcode = i810_dma_cleanup(dev);
-              	   	break;
+	switch (init.func) {
+	case I810_INIT_DMA:
+		/* This case is for backward compatibility. It
+		 * handles XFree 4.1.0 and 4.2.0, and has to
+		 * do some parameter checking as described below.
+		 * It will someday go away.
+		 */
+		retcode = i810_dma_init_compat(&init, arg);
+		if (retcode)
+			return retcode;
+
+		dev_priv = drm_alloc(sizeof(drm_i810_private_t),
+				     DRM_MEM_DRIVER);
+		if (dev_priv == NULL)
+			return -ENOMEM;
+		retcode = i810_dma_initialize(dev, dev_priv, &init);
+		break;
+
+	default:
+	case I810_INIT_DMA_1_4:
+		DRM_INFO("Using v1.4 init.\n");
+		if (copy_from_user(&init, (drm_i810_init_t __user *) arg,
+				   sizeof(drm_i810_init_t))) {
+			return -EFAULT;
+		}
+		dev_priv = drm_alloc(sizeof(drm_i810_private_t),
+				     DRM_MEM_DRIVER);
+		if (dev_priv == NULL)
+			return -ENOMEM;
+		retcode = i810_dma_initialize(dev, dev_priv, &init);
+		break;
+
+	case I810_CLEANUP_DMA:
+		DRM_INFO("DMA Cleanup\n");
+		retcode = i810_dma_cleanup(dev);
+		break;
 	}
 	}
 
 
-   	return retcode;
+	return retcode;
 }
 }
 
 
-
-
 /* Most efficient way to verify state for the i810 is as it is
 /* Most efficient way to verify state for the i810 is as it is
  * emitted.  Non-conformant state is silently dropped.
  * emitted.  Non-conformant state is silently dropped.
  *
  *
  * Use 'volatile' & local var tmp to force the emitted values to be
  * Use 'volatile' & local var tmp to force the emitted values to be
  * identical to the verified ones.
  * identical to the verified ones.
  */
  */
-static void i810EmitContextVerified( drm_device_t *dev,
-				     volatile unsigned int *code )
+static void i810EmitContextVerified(drm_device_t * dev,
+				    volatile unsigned int *code)
 {
 {
-   	drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_private_t *dev_priv = dev->dev_private;
 	int i, j = 0;
 	int i, j = 0;
 	unsigned int tmp;
 	unsigned int tmp;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
-	BEGIN_LP_RING( I810_CTX_SETUP_SIZE );
+	BEGIN_LP_RING(I810_CTX_SETUP_SIZE);
 
 
-	OUT_RING( GFX_OP_COLOR_FACTOR );
-	OUT_RING( code[I810_CTXREG_CF1] );
+	OUT_RING(GFX_OP_COLOR_FACTOR);
+	OUT_RING(code[I810_CTXREG_CF1]);
 
 
-	OUT_RING( GFX_OP_STIPPLE );
-	OUT_RING( code[I810_CTXREG_ST1] );
+	OUT_RING(GFX_OP_STIPPLE);
+	OUT_RING(code[I810_CTXREG_ST1]);
 
 
-	for ( i = 4 ; i < I810_CTX_SETUP_SIZE ; i++ ) {
+	for (i = 4; i < I810_CTX_SETUP_SIZE; i++) {
 		tmp = code[i];
 		tmp = code[i];
 
 
-		if ((tmp & (7<<29)) == (3<<29) &&
-		    (tmp & (0x1f<<24)) < (0x1d<<24))
-		{
-			OUT_RING( tmp );
+		if ((tmp & (7 << 29)) == (3 << 29) &&
+		    (tmp & (0x1f << 24)) < (0x1d << 24)) {
+			OUT_RING(tmp);
 			j++;
 			j++;
-		}
-		else printk("constext state dropped!!!\n");
+		} else
+			printk("constext state dropped!!!\n");
 	}
 	}
 
 
 	if (j & 1)
 	if (j & 1)
-		OUT_RING( 0 );
+		OUT_RING(0);
 
 
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 }
 }
 
 
-static void i810EmitTexVerified( drm_device_t *dev,
-				 volatile unsigned int *code )
+static void i810EmitTexVerified(drm_device_t * dev, volatile unsigned int *code)
 {
 {
-   	drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_private_t *dev_priv = dev->dev_private;
 	int i, j = 0;
 	int i, j = 0;
 	unsigned int tmp;
 	unsigned int tmp;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
-	BEGIN_LP_RING( I810_TEX_SETUP_SIZE );
+	BEGIN_LP_RING(I810_TEX_SETUP_SIZE);
 
 
-	OUT_RING( GFX_OP_MAP_INFO );
-	OUT_RING( code[I810_TEXREG_MI1] );
-	OUT_RING( code[I810_TEXREG_MI2] );
-	OUT_RING( code[I810_TEXREG_MI3] );
+	OUT_RING(GFX_OP_MAP_INFO);
+	OUT_RING(code[I810_TEXREG_MI1]);
+	OUT_RING(code[I810_TEXREG_MI2]);
+	OUT_RING(code[I810_TEXREG_MI3]);
 
 
-	for ( i = 4 ; i < I810_TEX_SETUP_SIZE ; i++ ) {
+	for (i = 4; i < I810_TEX_SETUP_SIZE; i++) {
 		tmp = code[i];
 		tmp = code[i];
 
 
-		if ((tmp & (7<<29)) == (3<<29) &&
-		    (tmp & (0x1f<<24)) < (0x1d<<24))
-		{
-			OUT_RING( tmp );
+		if ((tmp & (7 << 29)) == (3 << 29) &&
+		    (tmp & (0x1f << 24)) < (0x1d << 24)) {
+			OUT_RING(tmp);
 			j++;
 			j++;
-		}
-		else printk("texture state dropped!!!\n");
+		} else
+			printk("texture state dropped!!!\n");
 	}
 	}
 
 
 	if (j & 1)
 	if (j & 1)
-		OUT_RING( 0 );
+		OUT_RING(0);
 
 
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 }
 }
 
 
-
 /* Need to do some additional checking when setting the dest buffer.
 /* Need to do some additional checking when setting the dest buffer.
  */
  */
-static void i810EmitDestVerified( drm_device_t *dev,
-				  volatile unsigned int *code )
+static void i810EmitDestVerified(drm_device_t * dev,
+				 volatile unsigned int *code)
 {
 {
-   	drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_private_t *dev_priv = dev->dev_private;
 	unsigned int tmp;
 	unsigned int tmp;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
-	BEGIN_LP_RING( I810_DEST_SETUP_SIZE + 2 );
+	BEGIN_LP_RING(I810_DEST_SETUP_SIZE + 2);
 
 
 	tmp = code[I810_DESTREG_DI1];
 	tmp = code[I810_DESTREG_DI1];
 	if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) {
 	if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) {
-		OUT_RING( CMD_OP_DESTBUFFER_INFO );
-		OUT_RING( tmp );
+		OUT_RING(CMD_OP_DESTBUFFER_INFO);
+		OUT_RING(tmp);
 	} else
 	} else
-	   DRM_DEBUG("bad di1 %x (allow %x or %x)\n",
-		     tmp, dev_priv->front_di1, dev_priv->back_di1);
+		DRM_DEBUG("bad di1 %x (allow %x or %x)\n",
+			  tmp, dev_priv->front_di1, dev_priv->back_di1);
 
 
 	/* invarient:
 	/* invarient:
 	 */
 	 */
-	OUT_RING( CMD_OP_Z_BUFFER_INFO );
-	OUT_RING( dev_priv->zi1 );
+	OUT_RING(CMD_OP_Z_BUFFER_INFO);
+	OUT_RING(dev_priv->zi1);
 
 
-	OUT_RING( GFX_OP_DESTBUFFER_VARS );
-	OUT_RING( code[I810_DESTREG_DV1] );
+	OUT_RING(GFX_OP_DESTBUFFER_VARS);
+	OUT_RING(code[I810_DESTREG_DV1]);
 
 
-	OUT_RING( GFX_OP_DRAWRECT_INFO );
-	OUT_RING( code[I810_DESTREG_DR1] );
-	OUT_RING( code[I810_DESTREG_DR2] );
-	OUT_RING( code[I810_DESTREG_DR3] );
-	OUT_RING( code[I810_DESTREG_DR4] );
-	OUT_RING( 0 );
+	OUT_RING(GFX_OP_DRAWRECT_INFO);
+	OUT_RING(code[I810_DESTREG_DR1]);
+	OUT_RING(code[I810_DESTREG_DR2]);
+	OUT_RING(code[I810_DESTREG_DR3]);
+	OUT_RING(code[I810_DESTREG_DR4]);
+	OUT_RING(0);
 
 
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 }
 }
 
 
-
-
-static void i810EmitState( drm_device_t *dev )
+static void i810EmitState(drm_device_t * dev)
 {
 {
-   	drm_i810_private_t *dev_priv = dev->dev_private;
-      	drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
+	drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
 	unsigned int dirty = sarea_priv->dirty;
 	unsigned int dirty = sarea_priv->dirty;
-	
+
 	DRM_DEBUG("%s %x\n", __FUNCTION__, dirty);
 	DRM_DEBUG("%s %x\n", __FUNCTION__, dirty);
 
 
 	if (dirty & I810_UPLOAD_BUFFERS) {
 	if (dirty & I810_UPLOAD_BUFFERS) {
-		i810EmitDestVerified( dev, sarea_priv->BufferState );
+		i810EmitDestVerified(dev, sarea_priv->BufferState);
 		sarea_priv->dirty &= ~I810_UPLOAD_BUFFERS;
 		sarea_priv->dirty &= ~I810_UPLOAD_BUFFERS;
 	}
 	}
 
 
 	if (dirty & I810_UPLOAD_CTX) {
 	if (dirty & I810_UPLOAD_CTX) {
-		i810EmitContextVerified( dev, sarea_priv->ContextState );
+		i810EmitContextVerified(dev, sarea_priv->ContextState);
 		sarea_priv->dirty &= ~I810_UPLOAD_CTX;
 		sarea_priv->dirty &= ~I810_UPLOAD_CTX;
 	}
 	}
 
 
 	if (dirty & I810_UPLOAD_TEX0) {
 	if (dirty & I810_UPLOAD_TEX0) {
-		i810EmitTexVerified( dev, sarea_priv->TexState[0] );
+		i810EmitTexVerified(dev, sarea_priv->TexState[0]);
 		sarea_priv->dirty &= ~I810_UPLOAD_TEX0;
 		sarea_priv->dirty &= ~I810_UPLOAD_TEX0;
 	}
 	}
 
 
 	if (dirty & I810_UPLOAD_TEX1) {
 	if (dirty & I810_UPLOAD_TEX1) {
-		i810EmitTexVerified( dev, sarea_priv->TexState[1] );
+		i810EmitTexVerified(dev, sarea_priv->TexState[1]);
 		sarea_priv->dirty &= ~I810_UPLOAD_TEX1;
 		sarea_priv->dirty &= ~I810_UPLOAD_TEX1;
 	}
 	}
 }
 }
 
 
-
-
 /* need to verify
 /* need to verify
  */
  */
-static void i810_dma_dispatch_clear( drm_device_t *dev, int flags,
-				     unsigned int clear_color,
-				     unsigned int clear_zval )
+static void i810_dma_dispatch_clear(drm_device_t * dev, int flags,
+				    unsigned int clear_color,
+				    unsigned int clear_zval)
 {
 {
-   	drm_i810_private_t *dev_priv = dev->dev_private;
-      	drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
+	drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
 	int nbox = sarea_priv->nbox;
 	int nbox = sarea_priv->nbox;
 	drm_clip_rect_t *pbox = sarea_priv->boxes;
 	drm_clip_rect_t *pbox = sarea_priv->boxes;
 	int pitch = dev_priv->pitch;
 	int pitch = dev_priv->pitch;
 	int cpp = 2;
 	int cpp = 2;
 	int i;
 	int i;
 	RING_LOCALS;
 	RING_LOCALS;
-	
-	if ( dev_priv->current_page == 1 ) {
-	        unsigned int tmp = flags;
-	       
+
+	if (dev_priv->current_page == 1) {
+		unsigned int tmp = flags;
+
 		flags &= ~(I810_FRONT | I810_BACK);
 		flags &= ~(I810_FRONT | I810_BACK);
-		if (tmp & I810_FRONT) flags |= I810_BACK;
-		if (tmp & I810_BACK) flags |= I810_FRONT;
+		if (tmp & I810_FRONT)
+			flags |= I810_BACK;
+		if (tmp & I810_BACK)
+			flags |= I810_FRONT;
 	}
 	}
 
 
-  	i810_kernel_lost_context(dev);
+	i810_kernel_lost_context(dev);
 
 
-      	if (nbox > I810_NR_SAREA_CLIPRECTS)
-     		nbox = I810_NR_SAREA_CLIPRECTS;
+	if (nbox > I810_NR_SAREA_CLIPRECTS)
+		nbox = I810_NR_SAREA_CLIPRECTS;
 
 
-	for (i = 0 ; i < nbox ; i++, pbox++) {
+	for (i = 0; i < nbox; i++, pbox++) {
 		unsigned int x = pbox->x1;
 		unsigned int x = pbox->x1;
 		unsigned int y = pbox->y1;
 		unsigned int y = pbox->y1;
 		unsigned int width = (pbox->x2 - x) * cpp;
 		unsigned int width = (pbox->x2 - x) * cpp;
@@ -700,52 +694,48 @@ static void i810_dma_dispatch_clear( drm_device_t *dev, int flags,
 
 
 		if (pbox->x1 > pbox->x2 ||
 		if (pbox->x1 > pbox->x2 ||
 		    pbox->y1 > pbox->y2 ||
 		    pbox->y1 > pbox->y2 ||
-		    pbox->x2 > dev_priv->w ||
-		    pbox->y2 > dev_priv->h)
+		    pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
 			continue;
 			continue;
 
 
-	   	if ( flags & I810_FRONT ) {
-			BEGIN_LP_RING( 6 );
-			OUT_RING( BR00_BITBLT_CLIENT |
-				  BR00_OP_COLOR_BLT | 0x3 );
-			OUT_RING( BR13_SOLID_PATTERN | (0xF0 << 16) | pitch );
-			OUT_RING( (height << 16) | width );
-			OUT_RING( start );
-			OUT_RING( clear_color );
-			OUT_RING( 0 );
+		if (flags & I810_FRONT) {
+			BEGIN_LP_RING(6);
+			OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
+			OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
+			OUT_RING((height << 16) | width);
+			OUT_RING(start);
+			OUT_RING(clear_color);
+			OUT_RING(0);
 			ADVANCE_LP_RING();
 			ADVANCE_LP_RING();
 		}
 		}
 
 
-		if ( flags & I810_BACK ) {
-			BEGIN_LP_RING( 6 );
-			OUT_RING( BR00_BITBLT_CLIENT |
-				  BR00_OP_COLOR_BLT | 0x3 );
-			OUT_RING( BR13_SOLID_PATTERN | (0xF0 << 16) | pitch );
-			OUT_RING( (height << 16) | width );
-			OUT_RING( dev_priv->back_offset + start );
-			OUT_RING( clear_color );
-			OUT_RING( 0 );
+		if (flags & I810_BACK) {
+			BEGIN_LP_RING(6);
+			OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
+			OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
+			OUT_RING((height << 16) | width);
+			OUT_RING(dev_priv->back_offset + start);
+			OUT_RING(clear_color);
+			OUT_RING(0);
 			ADVANCE_LP_RING();
 			ADVANCE_LP_RING();
 		}
 		}
 
 
-		if ( flags & I810_DEPTH ) {
-			BEGIN_LP_RING( 6 );
-			OUT_RING( BR00_BITBLT_CLIENT |
-				  BR00_OP_COLOR_BLT | 0x3 );
-			OUT_RING( BR13_SOLID_PATTERN | (0xF0 << 16) | pitch );
-			OUT_RING( (height << 16) | width );
-			OUT_RING( dev_priv->depth_offset + start );
-			OUT_RING( clear_zval );
-			OUT_RING( 0 );
+		if (flags & I810_DEPTH) {
+			BEGIN_LP_RING(6);
+			OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
+			OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
+			OUT_RING((height << 16) | width);
+			OUT_RING(dev_priv->depth_offset + start);
+			OUT_RING(clear_zval);
+			OUT_RING(0);
 			ADVANCE_LP_RING();
 			ADVANCE_LP_RING();
 		}
 		}
 	}
 	}
 }
 }
 
 
-static void i810_dma_dispatch_swap( drm_device_t *dev )
+static void i810_dma_dispatch_swap(drm_device_t * dev)
 {
 {
-   	drm_i810_private_t *dev_priv = dev->dev_private;
-      	drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
+	drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
 	int nbox = sarea_priv->nbox;
 	int nbox = sarea_priv->nbox;
 	drm_clip_rect_t *pbox = sarea_priv->boxes;
 	drm_clip_rect_t *pbox = sarea_priv->boxes;
 	int pitch = dev_priv->pitch;
 	int pitch = dev_priv->pitch;
@@ -755,75 +745,71 @@ static void i810_dma_dispatch_swap( drm_device_t *dev )
 
 
 	DRM_DEBUG("swapbuffers\n");
 	DRM_DEBUG("swapbuffers\n");
 
 
-  	i810_kernel_lost_context(dev);
+	i810_kernel_lost_context(dev);
 
 
-      	if (nbox > I810_NR_SAREA_CLIPRECTS)
-     		nbox = I810_NR_SAREA_CLIPRECTS;
+	if (nbox > I810_NR_SAREA_CLIPRECTS)
+		nbox = I810_NR_SAREA_CLIPRECTS;
 
 
-	for (i = 0 ; i < nbox; i++, pbox++)
-	{
+	for (i = 0; i < nbox; i++, pbox++) {
 		unsigned int w = pbox->x2 - pbox->x1;
 		unsigned int w = pbox->x2 - pbox->x1;
 		unsigned int h = pbox->y2 - pbox->y1;
 		unsigned int h = pbox->y2 - pbox->y1;
-		unsigned int dst = pbox->x1*cpp + pbox->y1*pitch;
+		unsigned int dst = pbox->x1 * cpp + pbox->y1 * pitch;
 		unsigned int start = dst;
 		unsigned int start = dst;
 
 
 		if (pbox->x1 > pbox->x2 ||
 		if (pbox->x1 > pbox->x2 ||
 		    pbox->y1 > pbox->y2 ||
 		    pbox->y1 > pbox->y2 ||
-		    pbox->x2 > dev_priv->w ||
-		    pbox->y2 > dev_priv->h)
+		    pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
 			continue;
 			continue;
 
 
-		BEGIN_LP_RING( 6 );
-		OUT_RING( BR00_BITBLT_CLIENT | BR00_OP_SRC_COPY_BLT | 0x4 );
-		OUT_RING( pitch | (0xCC << 16));
-		OUT_RING( (h << 16) | (w * cpp));
+		BEGIN_LP_RING(6);
+		OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_SRC_COPY_BLT | 0x4);
+		OUT_RING(pitch | (0xCC << 16));
+		OUT_RING((h << 16) | (w * cpp));
 		if (dev_priv->current_page == 0)
 		if (dev_priv->current_page == 0)
-		  OUT_RING(dev_priv->front_offset + start);
+			OUT_RING(dev_priv->front_offset + start);
 		else
 		else
-		  OUT_RING(dev_priv->back_offset + start);
-		OUT_RING( pitch );
+			OUT_RING(dev_priv->back_offset + start);
+		OUT_RING(pitch);
 		if (dev_priv->current_page == 0)
 		if (dev_priv->current_page == 0)
-		  OUT_RING(dev_priv->back_offset + start);
+			OUT_RING(dev_priv->back_offset + start);
 		else
 		else
-		  OUT_RING(dev_priv->front_offset + start);
+			OUT_RING(dev_priv->front_offset + start);
 		ADVANCE_LP_RING();
 		ADVANCE_LP_RING();
 	}
 	}
 }
 }
 
 
-
-static void i810_dma_dispatch_vertex(drm_device_t *dev,
-				     drm_buf_t *buf,
-				     int discard,
-				     int used)
+static void i810_dma_dispatch_vertex(drm_device_t * dev,
+				     drm_buf_t * buf, int discard, int used)
 {
 {
-   	drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_private_t *dev_priv = dev->dev_private;
 	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
 	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-   	drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
-   	drm_clip_rect_t *box = sarea_priv->boxes;
-   	int nbox = sarea_priv->nbox;
+	drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
+	drm_clip_rect_t *box = sarea_priv->boxes;
+	int nbox = sarea_priv->nbox;
 	unsigned long address = (unsigned long)buf->bus_address;
 	unsigned long address = (unsigned long)buf->bus_address;
 	unsigned long start = address - dev->agp->base;
 	unsigned long start = address - dev->agp->base;
 	int i = 0;
 	int i = 0;
-   	RING_LOCALS;
+	RING_LOCALS;
 
 
-   	i810_kernel_lost_context(dev);
+	i810_kernel_lost_context(dev);
 
 
-   	if (nbox > I810_NR_SAREA_CLIPRECTS)
+	if (nbox > I810_NR_SAREA_CLIPRECTS)
 		nbox = I810_NR_SAREA_CLIPRECTS;
 		nbox = I810_NR_SAREA_CLIPRECTS;
 
 
-	if (used > 4*1024)
+	if (used > 4 * 1024)
 		used = 0;
 		used = 0;
 
 
 	if (sarea_priv->dirty)
 	if (sarea_priv->dirty)
-	   i810EmitState( dev );
+		i810EmitState(dev);
 
 
 	if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
 	if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
 		unsigned int prim = (sarea_priv->vertex_prim & PR_MASK);
 		unsigned int prim = (sarea_priv->vertex_prim & PR_MASK);
 
 
-		*(u32 *)buf_priv->kernel_virtual = ((GFX_OP_PRIMITIVE | prim | ((used/4)-2)));
+		*(u32 *) buf_priv->kernel_virtual =
+		    ((GFX_OP_PRIMITIVE | prim | ((used / 4) - 2)));
 
 
 		if (used & 4) {
 		if (used & 4) {
-			*(u32 *)((u32)buf_priv->kernel_virtual + used) = 0;
+			*(u32 *) ((u32) buf_priv->kernel_virtual + used) = 0;
 			used += 4;
 			used += 4;
 		}
 		}
 
 
@@ -834,19 +820,20 @@ static void i810_dma_dispatch_vertex(drm_device_t *dev,
 		do {
 		do {
 			if (i < nbox) {
 			if (i < nbox) {
 				BEGIN_LP_RING(4);
 				BEGIN_LP_RING(4);
-				OUT_RING( GFX_OP_SCISSOR | SC_UPDATE_SCISSOR |
-					  SC_ENABLE );
-				OUT_RING( GFX_OP_SCISSOR_INFO );
-				OUT_RING( box[i].x1 | (box[i].y1<<16) );
-				OUT_RING( (box[i].x2-1) | ((box[i].y2-1)<<16) );
+				OUT_RING(GFX_OP_SCISSOR | SC_UPDATE_SCISSOR |
+					 SC_ENABLE);
+				OUT_RING(GFX_OP_SCISSOR_INFO);
+				OUT_RING(box[i].x1 | (box[i].y1 << 16));
+				OUT_RING((box[i].x2 -
+					  1) | ((box[i].y2 - 1) << 16));
 				ADVANCE_LP_RING();
 				ADVANCE_LP_RING();
 			}
 			}
 
 
 			BEGIN_LP_RING(4);
 			BEGIN_LP_RING(4);
-			OUT_RING( CMD_OP_BATCH_BUFFER );
-			OUT_RING( start | BB1_PROTECTED );
-			OUT_RING( start + used - 4 );
-			OUT_RING( 0 );
+			OUT_RING(CMD_OP_BATCH_BUFFER);
+			OUT_RING(start | BB1_PROTECTED);
+			OUT_RING(start + used - 4);
+			OUT_RING(0);
 			ADVANCE_LP_RING();
 			ADVANCE_LP_RING();
 
 
 		} while (++i < nbox);
 		} while (++i < nbox);
@@ -855,59 +842,59 @@ static void i810_dma_dispatch_vertex(drm_device_t *dev,
 	if (discard) {
 	if (discard) {
 		dev_priv->counter++;
 		dev_priv->counter++;
 
 
-		(void) cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
-			       I810_BUF_HARDWARE);
+		(void)cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
+			      I810_BUF_HARDWARE);
 
 
 		BEGIN_LP_RING(8);
 		BEGIN_LP_RING(8);
-		OUT_RING( CMD_STORE_DWORD_IDX );
-		OUT_RING( 20 );
-		OUT_RING( dev_priv->counter );
-		OUT_RING( CMD_STORE_DWORD_IDX );
-		OUT_RING( buf_priv->my_use_idx );
-		OUT_RING( I810_BUF_FREE );
-		OUT_RING( CMD_REPORT_HEAD );
-		OUT_RING( 0 );
+		OUT_RING(CMD_STORE_DWORD_IDX);
+		OUT_RING(20);
+		OUT_RING(dev_priv->counter);
+		OUT_RING(CMD_STORE_DWORD_IDX);
+		OUT_RING(buf_priv->my_use_idx);
+		OUT_RING(I810_BUF_FREE);
+		OUT_RING(CMD_REPORT_HEAD);
+		OUT_RING(0);
 		ADVANCE_LP_RING();
 		ADVANCE_LP_RING();
 	}
 	}
 }
 }
 
 
-static void i810_dma_dispatch_flip( drm_device_t *dev )
+static void i810_dma_dispatch_flip(drm_device_t * dev)
 {
 {
-        drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_private_t *dev_priv = dev->dev_private;
 	int pitch = dev_priv->pitch;
 	int pitch = dev_priv->pitch;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
-	DRM_DEBUG( "%s: page=%d pfCurrentPage=%d\n", 
-		__FUNCTION__, 
-		dev_priv->current_page,
-		dev_priv->sarea_priv->pf_current_page);
-	
-        i810_kernel_lost_context(dev);
+	DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
+		  __FUNCTION__,
+		  dev_priv->current_page,
+		  dev_priv->sarea_priv->pf_current_page);
+
+	i810_kernel_lost_context(dev);
 
 
-	BEGIN_LP_RING( 2 );
-   	OUT_RING( INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE ); 
-	OUT_RING( 0 );
+	BEGIN_LP_RING(2);
+	OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+	OUT_RING(0);
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 
 
-	BEGIN_LP_RING( I810_DEST_SETUP_SIZE + 2 );
+	BEGIN_LP_RING(I810_DEST_SETUP_SIZE + 2);
 	/* On i815 at least ASYNC is buggy */
 	/* On i815 at least ASYNC is buggy */
 	/* pitch<<5 is from 11.2.8 p158,
 	/* pitch<<5 is from 11.2.8 p158,
 	   its the pitch / 8 then left shifted 8,
 	   its the pitch / 8 then left shifted 8,
 	   so (pitch >> 3) << 8 */
 	   so (pitch >> 3) << 8 */
-	OUT_RING( CMD_OP_FRONTBUFFER_INFO | (pitch<<5) /*| ASYNC_FLIP */ );
-	if ( dev_priv->current_page == 0 ) {
-		OUT_RING( dev_priv->back_offset );
+	OUT_RING(CMD_OP_FRONTBUFFER_INFO | (pitch << 5) /*| ASYNC_FLIP */ );
+	if (dev_priv->current_page == 0) {
+		OUT_RING(dev_priv->back_offset);
 		dev_priv->current_page = 1;
 		dev_priv->current_page = 1;
 	} else {
 	} else {
-		OUT_RING( dev_priv->front_offset );
+		OUT_RING(dev_priv->front_offset);
 		dev_priv->current_page = 0;
 		dev_priv->current_page = 0;
 	}
 	}
 	OUT_RING(0);
 	OUT_RING(0);
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 
 
 	BEGIN_LP_RING(2);
 	BEGIN_LP_RING(2);
-	OUT_RING( CMD_OP_WAIT_FOR_EVENT | WAIT_FOR_PLANE_A_FLIP );
-	OUT_RING( 0 );
+	OUT_RING(CMD_OP_WAIT_FOR_EVENT | WAIT_FOR_PLANE_A_FLIP);
+	OUT_RING(0);
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 
 
 	/* Increment the frame counter.  The client-side 3D driver must
 	/* Increment the frame counter.  The client-side 3D driver must
@@ -918,46 +905,46 @@ static void i810_dma_dispatch_flip( drm_device_t *dev )
 
 
 }
 }
 
 
-static void i810_dma_quiescent(drm_device_t *dev)
+static void i810_dma_quiescent(drm_device_t * dev)
 {
 {
-      	drm_i810_private_t *dev_priv = dev->dev_private;
-   	RING_LOCALS;
+	drm_i810_private_t *dev_priv = dev->dev_private;
+	RING_LOCALS;
 
 
 /*  	printk("%s\n", __FUNCTION__); */
 /*  	printk("%s\n", __FUNCTION__); */
 
 
-  	i810_kernel_lost_context(dev);
+	i810_kernel_lost_context(dev);
 
 
-   	BEGIN_LP_RING(4);
-   	OUT_RING( INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE );
-   	OUT_RING( CMD_REPORT_HEAD );
-      	OUT_RING( 0 );
-      	OUT_RING( 0 );
-   	ADVANCE_LP_RING();
+	BEGIN_LP_RING(4);
+	OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+	OUT_RING(CMD_REPORT_HEAD);
+	OUT_RING(0);
+	OUT_RING(0);
+	ADVANCE_LP_RING();
 
 
-	i810_wait_ring( dev, dev_priv->ring.Size - 8 );
+	i810_wait_ring(dev, dev_priv->ring.Size - 8);
 }
 }
 
 
-static int i810_flush_queue(drm_device_t *dev)
+static int i810_flush_queue(drm_device_t * dev)
 {
 {
-   	drm_i810_private_t *dev_priv = dev->dev_private;
+	drm_i810_private_t *dev_priv = dev->dev_private;
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
-   	int i, ret = 0;
-   	RING_LOCALS;
-	
+	int i, ret = 0;
+	RING_LOCALS;
+
 /*  	printk("%s\n", __FUNCTION__); */
 /*  	printk("%s\n", __FUNCTION__); */
 
 
-   	i810_kernel_lost_context(dev);
+	i810_kernel_lost_context(dev);
 
 
-   	BEGIN_LP_RING(2);
-      	OUT_RING( CMD_REPORT_HEAD );
-      	OUT_RING( 0 );
-      	ADVANCE_LP_RING();
+	BEGIN_LP_RING(2);
+	OUT_RING(CMD_REPORT_HEAD);
+	OUT_RING(0);
+	ADVANCE_LP_RING();
 
 
-	i810_wait_ring( dev, dev_priv->ring.Size - 8 );
+	i810_wait_ring(dev, dev_priv->ring.Size - 8);
 
 
-   	for (i = 0; i < dma->buf_count; i++) {
-	   	drm_buf_t *buf = dma->buflist[ i ];
-	   	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+	for (i = 0; i < dma->buf_count; i++) {
+		drm_buf_t *buf = dma->buflist[i];
+		drm_i810_buf_priv_t *buf_priv = buf->dev_private;
 
 
 		int used = cmpxchg(buf_priv->in_use, I810_BUF_HARDWARE,
 		int used = cmpxchg(buf_priv->in_use, I810_BUF_HARDWARE,
 				   I810_BUF_FREE);
 				   I810_BUF_FREE);
@@ -968,24 +955,27 @@ static int i810_flush_queue(drm_device_t *dev)
 			DRM_DEBUG("still on client\n");
 			DRM_DEBUG("still on client\n");
 	}
 	}
 
 
-   	return ret;
+	return ret;
 }
 }
 
 
 /* Must be called with the lock held */
 /* Must be called with the lock held */
-void i810_reclaim_buffers(drm_device_t *dev, struct file *filp)
+void i810_reclaim_buffers(drm_device_t * dev, struct file *filp)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
-	int		 i;
+	int i;
 
 
-	if (!dma) return;
-      	if (!dev->dev_private) return;
-	if (!dma->buflist) return;
+	if (!dma)
+		return;
+	if (!dev->dev_private)
+		return;
+	if (!dma->buflist)
+		return;
 
 
-        i810_flush_queue(dev);
+	i810_flush_queue(dev);
 
 
 	for (i = 0; i < dma->buf_count; i++) {
 	for (i = 0; i < dma->buf_count; i++) {
-	   	drm_buf_t *buf = dma->buflist[ i ];
-	   	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+		drm_buf_t *buf = dma->buflist[i];
+		drm_i810_buf_priv_t *buf_priv = buf->dev_private;
 
 
 		if (buf->filp == filp && buf_priv) {
 		if (buf->filp == filp && buf_priv) {
 			int used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
 			int used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
@@ -994,7 +984,7 @@ void i810_reclaim_buffers(drm_device_t *dev, struct file *filp)
 			if (used == I810_BUF_CLIENT)
 			if (used == I810_BUF_CLIENT)
 				DRM_DEBUG("reclaimed from client\n");
 				DRM_DEBUG("reclaimed from client\n");
 			if (buf_priv->currently_mapped == I810_BUF_MAPPED)
 			if (buf_priv->currently_mapped == I810_BUF_MAPPED)
-		     		buf_priv->currently_mapped = I810_BUF_UNMAPPED;
+				buf_priv->currently_mapped = I810_BUF_UNMAPPED;
 		}
 		}
 	}
 	}
 }
 }
@@ -1002,29 +992,29 @@ void i810_reclaim_buffers(drm_device_t *dev, struct file *filp)
 static int i810_flush_ioctl(struct inode *inode, struct file *filp,
 static int i810_flush_ioctl(struct inode *inode, struct file *filp,
 			    unsigned int cmd, unsigned long arg)
 			    unsigned int cmd, unsigned long arg)
 {
 {
-   	drm_file_t	  *priv	  = filp->private_data;
-   	drm_device_t	  *dev	  = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
-   	i810_flush_queue(dev);
-   	return 0;
+	i810_flush_queue(dev);
+	return 0;
 }
 }
 
 
-
 static int i810_dma_vertex(struct inode *inode, struct file *filp,
 static int i810_dma_vertex(struct inode *inode, struct file *filp,
-	       unsigned int cmd, unsigned long arg)
+			   unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
-   	drm_i810_private_t *dev_priv = (drm_i810_private_t *)dev->dev_private;
-      	u32 *hw_status = dev_priv->hw_status_page;
-   	drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
-     					dev_priv->sarea_priv;
+	drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+	u32 *hw_status = dev_priv->hw_status_page;
+	drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
+	    dev_priv->sarea_priv;
 	drm_i810_vertex_t vertex;
 	drm_i810_vertex_t vertex;
 
 
-	if (copy_from_user(&vertex, (drm_i810_vertex_t __user *)arg, sizeof(vertex)))
+	if (copy_from_user
+	    (&vertex, (drm_i810_vertex_t __user *) arg, sizeof(vertex)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
@@ -1032,48 +1022,46 @@ static int i810_dma_vertex(struct inode *inode, struct file *filp,
 	DRM_DEBUG("i810 dma vertex, idx %d used %d discard %d\n",
 	DRM_DEBUG("i810 dma vertex, idx %d used %d discard %d\n",
 		  vertex.idx, vertex.used, vertex.discard);
 		  vertex.idx, vertex.used, vertex.discard);
 
 
-	if (vertex.idx < 0 || vertex.idx > dma->buf_count) 
+	if (vertex.idx < 0 || vertex.idx > dma->buf_count)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	i810_dma_dispatch_vertex( dev,
-				  dma->buflist[ vertex.idx ],
-				  vertex.discard, vertex.used );
+	i810_dma_dispatch_vertex(dev,
+				 dma->buflist[vertex.idx],
+				 vertex.discard, vertex.used);
 
 
-   	atomic_add(vertex.used, &dev->counts[_DRM_STAT_SECONDARY]);
+	atomic_add(vertex.used, &dev->counts[_DRM_STAT_SECONDARY]);
 	atomic_inc(&dev->counts[_DRM_STAT_DMA]);
 	atomic_inc(&dev->counts[_DRM_STAT_DMA]);
-	sarea_priv->last_enqueue = dev_priv->counter-1;
-   	sarea_priv->last_dispatch = (int) hw_status[5];
+	sarea_priv->last_enqueue = dev_priv->counter - 1;
+	sarea_priv->last_dispatch = (int)hw_status[5];
 
 
 	return 0;
 	return 0;
 }
 }
 
 
-
-
 static int i810_clear_bufs(struct inode *inode, struct file *filp,
 static int i810_clear_bufs(struct inode *inode, struct file *filp,
-		   unsigned int cmd, unsigned long arg)
+			   unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_i810_clear_t clear;
 	drm_i810_clear_t clear;
 
 
-   	if (copy_from_user(&clear, (drm_i810_clear_t __user *)arg, sizeof(clear)))
+	if (copy_from_user
+	    (&clear, (drm_i810_clear_t __user *) arg, sizeof(clear)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
- 	/* GH: Someone's doing nasty things... */
- 	if (!dev->dev_private) {
- 		return -EINVAL;
- 	}
+	/* GH: Someone's doing nasty things... */
+	if (!dev->dev_private) {
+		return -EINVAL;
+	}
 
 
-	i810_dma_dispatch_clear( dev, clear.flags,
-				 clear.clear_color,
-				 clear.clear_depth );
-   	return 0;
+	i810_dma_dispatch_clear(dev, clear.flags,
+				clear.clear_color, clear.clear_depth);
+	return 0;
 }
 }
 
 
 static int i810_swap_bufs(struct inode *inode, struct file *filp,
 static int i810_swap_bufs(struct inode *inode, struct file *filp,
-		  unsigned int cmd, unsigned long arg)
+			  unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -1082,37 +1070,37 @@ static int i810_swap_bufs(struct inode *inode, struct file *filp,
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
-	i810_dma_dispatch_swap( dev );
-   	return 0;
+	i810_dma_dispatch_swap(dev);
+	return 0;
 }
 }
 
 
 static int i810_getage(struct inode *inode, struct file *filp, unsigned int cmd,
 static int i810_getage(struct inode *inode, struct file *filp, unsigned int cmd,
-		unsigned long arg)
+		       unsigned long arg)
 {
 {
-   	drm_file_t	  *priv	    = filp->private_data;
-	drm_device_t	  *dev	    = priv->head->dev;
-   	drm_i810_private_t *dev_priv = (drm_i810_private_t *)dev->dev_private;
-      	u32 *hw_status = dev_priv->hw_status_page;
-   	drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
-     					dev_priv->sarea_priv;
-
-      	sarea_priv->last_dispatch = (int) hw_status[5];
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+	u32 *hw_status = dev_priv->hw_status_page;
+	drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
+	    dev_priv->sarea_priv;
+
+	sarea_priv->last_dispatch = (int)hw_status[5];
 	return 0;
 	return 0;
 }
 }
 
 
 static int i810_getbuf(struct inode *inode, struct file *filp, unsigned int cmd,
 static int i810_getbuf(struct inode *inode, struct file *filp, unsigned int cmd,
-		unsigned long arg)
+		       unsigned long arg)
 {
 {
-	drm_file_t	  *priv	    = filp->private_data;
-	drm_device_t	  *dev	    = priv->head->dev;
-	int		  retcode   = 0;
-	drm_i810_dma_t	  d;
-   	drm_i810_private_t *dev_priv = (drm_i810_private_t *)dev->dev_private;
-   	u32 *hw_status = dev_priv->hw_status_page;
-   	drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
-     					dev_priv->sarea_priv;
-
-   	if (copy_from_user(&d, (drm_i810_dma_t __user *)arg, sizeof(d)))
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	int retcode = 0;
+	drm_i810_dma_t d;
+	drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+	u32 *hw_status = dev_priv->hw_status_page;
+	drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
+	    dev_priv->sarea_priv;
+
+	if (copy_from_user(&d, (drm_i810_dma_t __user *) arg, sizeof(d)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
@@ -1124,29 +1112,29 @@ static int i810_getbuf(struct inode *inode, struct file *filp, unsigned int cmd,
 	DRM_DEBUG("i810_dma: %d returning %d, granted = %d\n",
 	DRM_DEBUG("i810_dma: %d returning %d, granted = %d\n",
 		  current->pid, retcode, d.granted);
 		  current->pid, retcode, d.granted);
 
 
-	if (copy_to_user((drm_dma_t __user *)arg, &d, sizeof(d)))
+	if (copy_to_user((drm_dma_t __user *) arg, &d, sizeof(d)))
 		return -EFAULT;
 		return -EFAULT;
-   	sarea_priv->last_dispatch = (int) hw_status[5];
+	sarea_priv->last_dispatch = (int)hw_status[5];
 
 
 	return retcode;
 	return retcode;
 }
 }
 
 
 static int i810_copybuf(struct inode *inode,
 static int i810_copybuf(struct inode *inode,
-			 struct file *filp, unsigned int cmd, unsigned long arg)
+			struct file *filp, unsigned int cmd, unsigned long arg)
 {
 {
 	/* Never copy - 2.4.x doesn't need it */
 	/* Never copy - 2.4.x doesn't need it */
 	return 0;
 	return 0;
 }
 }
 
 
 static int i810_docopy(struct inode *inode, struct file *filp, unsigned int cmd,
 static int i810_docopy(struct inode *inode, struct file *filp, unsigned int cmd,
-			unsigned long arg)
+		       unsigned long arg)
 {
 {
 	/* Never copy - 2.4.x doesn't need it */
 	/* Never copy - 2.4.x doesn't need it */
 	return 0;
 	return 0;
 }
 }
 
 
-static void i810_dma_dispatch_mc(drm_device_t *dev, drm_buf_t *buf, int used,
-		unsigned int last_render)
+static void i810_dma_dispatch_mc(drm_device_t * dev, drm_buf_t * buf, int used,
+				 unsigned int last_render)
 {
 {
 	drm_i810_private_t *dev_priv = dev->dev_private;
 	drm_i810_private_t *dev_priv = dev->dev_private;
 	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
 	drm_i810_buf_priv_t *buf_priv = buf->dev_private;
@@ -1158,19 +1146,17 @@ static void i810_dma_dispatch_mc(drm_device_t *dev, drm_buf_t *buf, int used,
 
 
 	i810_kernel_lost_context(dev);
 	i810_kernel_lost_context(dev);
 
 
-	u = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
-		I810_BUF_HARDWARE);
+	u = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_HARDWARE);
 	if (u != I810_BUF_CLIENT) {
 	if (u != I810_BUF_CLIENT) {
 		DRM_DEBUG("MC found buffer that isn't mine!\n");
 		DRM_DEBUG("MC found buffer that isn't mine!\n");
 	}
 	}
 
 
-	if (used > 4*1024)
+	if (used > 4 * 1024)
 		used = 0;
 		used = 0;
 
 
 	sarea_priv->dirty = 0x7f;
 	sarea_priv->dirty = 0x7f;
 
 
-	DRM_DEBUG("dispatch mc addr 0x%lx, used 0x%x\n",
-		address, used);
+	DRM_DEBUG("dispatch mc addr 0x%lx, used 0x%x\n", address, used);
 
 
 	dev_priv->counter++;
 	dev_priv->counter++;
 	DRM_DEBUG("dispatch counter : %ld\n", dev_priv->counter);
 	DRM_DEBUG("dispatch counter : %ld\n", dev_priv->counter);
@@ -1181,46 +1167,45 @@ static void i810_dma_dispatch_mc(drm_device_t *dev, drm_buf_t *buf, int used,
 
 
 	if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
 	if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
 		if (used & 4) {
 		if (used & 4) {
-			*(u32 *)((u32)buf_priv->virtual + used) = 0;
+			*(u32 *) ((u32) buf_priv->virtual + used) = 0;
 			used += 4;
 			used += 4;
 		}
 		}
 
 
 		i810_unmap_buffer(buf);
 		i810_unmap_buffer(buf);
 	}
 	}
 	BEGIN_LP_RING(4);
 	BEGIN_LP_RING(4);
-	OUT_RING( CMD_OP_BATCH_BUFFER );
-	OUT_RING( start | BB1_PROTECTED );
-	OUT_RING( start + used - 4 );
-	OUT_RING( 0 );
+	OUT_RING(CMD_OP_BATCH_BUFFER);
+	OUT_RING(start | BB1_PROTECTED);
+	OUT_RING(start + used - 4);
+	OUT_RING(0);
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 
 
-
 	BEGIN_LP_RING(8);
 	BEGIN_LP_RING(8);
-	OUT_RING( CMD_STORE_DWORD_IDX );
-	OUT_RING( buf_priv->my_use_idx );
-	OUT_RING( I810_BUF_FREE );
-	OUT_RING( 0 );
-
-	OUT_RING( CMD_STORE_DWORD_IDX );
-	OUT_RING( 16 );
-	OUT_RING( last_render );
-	OUT_RING( 0 );
+	OUT_RING(CMD_STORE_DWORD_IDX);
+	OUT_RING(buf_priv->my_use_idx);
+	OUT_RING(I810_BUF_FREE);
+	OUT_RING(0);
+
+	OUT_RING(CMD_STORE_DWORD_IDX);
+	OUT_RING(16);
+	OUT_RING(last_render);
+	OUT_RING(0);
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 }
 }
 
 
 static int i810_dma_mc(struct inode *inode, struct file *filp,
 static int i810_dma_mc(struct inode *inode, struct file *filp,
-	unsigned int cmd, unsigned long arg)
+		       unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
-	drm_i810_private_t *dev_priv = (drm_i810_private_t *)dev->dev_private;
+	drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
 	u32 *hw_status = dev_priv->hw_status_page;
 	u32 *hw_status = dev_priv->hw_status_page;
 	drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
 	drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
-		dev_priv->sarea_priv;
+	    dev_priv->sarea_priv;
 	drm_i810_mc_t mc;
 	drm_i810_mc_t mc;
 
 
-	if (copy_from_user(&mc, (drm_i810_mc_t __user *)arg, sizeof(mc)))
+	if (copy_from_user(&mc, (drm_i810_mc_t __user *) arg, sizeof(mc)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
@@ -1229,12 +1214,12 @@ static int i810_dma_mc(struct inode *inode, struct file *filp,
 		return -EINVAL;
 		return -EINVAL;
 
 
 	i810_dma_dispatch_mc(dev, dma->buflist[mc.idx], mc.used,
 	i810_dma_dispatch_mc(dev, dma->buflist[mc.idx], mc.used,
-		mc.last_render );
+			     mc.last_render);
 
 
 	atomic_add(mc.used, &dev->counts[_DRM_STAT_SECONDARY]);
 	atomic_add(mc.used, &dev->counts[_DRM_STAT_SECONDARY]);
 	atomic_inc(&dev->counts[_DRM_STAT_DMA]);
 	atomic_inc(&dev->counts[_DRM_STAT_DMA]);
-	sarea_priv->last_enqueue = dev_priv->counter-1;
-	sarea_priv->last_dispatch = (int) hw_status[5];
+	sarea_priv->last_enqueue = dev_priv->counter - 1;
+	sarea_priv->last_dispatch = (int)hw_status[5];
 
 
 	return 0;
 	return 0;
 }
 }
@@ -1244,22 +1229,23 @@ static int i810_rstatus(struct inode *inode, struct file *filp,
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
-	drm_i810_private_t *dev_priv = (drm_i810_private_t *)dev->dev_private;
+	drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
 
 
-	return (int)(((u32 *)(dev_priv->hw_status_page))[4]);
+	return (int)(((u32 *) (dev_priv->hw_status_page))[4]);
 }
 }
 
 
 static int i810_ov0_info(struct inode *inode, struct file *filp,
 static int i810_ov0_info(struct inode *inode, struct file *filp,
-			unsigned int cmd, unsigned long arg)
+			 unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
-	drm_i810_private_t *dev_priv = (drm_i810_private_t *)dev->dev_private;
+	drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
 	drm_i810_overlay_t data;
 	drm_i810_overlay_t data;
 
 
 	data.offset = dev_priv->overlay_offset;
 	data.offset = dev_priv->overlay_offset;
 	data.physical = dev_priv->overlay_physical;
 	data.physical = dev_priv->overlay_physical;
-	if (copy_to_user((drm_i810_overlay_t __user *)arg,&data,sizeof(data)))
+	if (copy_to_user
+	    ((drm_i810_overlay_t __user *) arg, &data, sizeof(data)))
 		return -EFAULT;
 		return -EFAULT;
 	return 0;
 	return 0;
 }
 }
@@ -1269,7 +1255,7 @@ static int i810_fstatus(struct inode *inode, struct file *filp,
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
-	drm_i810_private_t *dev_priv = (drm_i810_private_t *)dev->dev_private;
+	drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
@@ -1277,47 +1263,46 @@ static int i810_fstatus(struct inode *inode, struct file *filp,
 }
 }
 
 
 static int i810_ov0_flip(struct inode *inode, struct file *filp,
 static int i810_ov0_flip(struct inode *inode, struct file *filp,
-			unsigned int cmd, unsigned long arg)
+			 unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
-	drm_i810_private_t *dev_priv = (drm_i810_private_t *)dev->dev_private;
+	drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
 	//Tell the overlay to update
 	//Tell the overlay to update
-	I810_WRITE(0x30000,dev_priv->overlay_physical | 0x80000000);
+	I810_WRITE(0x30000, dev_priv->overlay_physical | 0x80000000);
 
 
 	return 0;
 	return 0;
 }
 }
 
 
-
 /* Not sure why this isn't set all the time:
 /* Not sure why this isn't set all the time:
- */ 
-static void i810_do_init_pageflip( drm_device_t *dev )
+ */
+static void i810_do_init_pageflip(drm_device_t * dev)
 {
 {
 	drm_i810_private_t *dev_priv = dev->dev_private;
 	drm_i810_private_t *dev_priv = dev->dev_private;
-	
+
 	DRM_DEBUG("%s\n", __FUNCTION__);
 	DRM_DEBUG("%s\n", __FUNCTION__);
 	dev_priv->page_flipping = 1;
 	dev_priv->page_flipping = 1;
 	dev_priv->current_page = 0;
 	dev_priv->current_page = 0;
 	dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
 	dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
 }
 }
 
 
-static int i810_do_cleanup_pageflip( drm_device_t *dev )
+static int i810_do_cleanup_pageflip(drm_device_t * dev)
 {
 {
 	drm_i810_private_t *dev_priv = dev->dev_private;
 	drm_i810_private_t *dev_priv = dev->dev_private;
 
 
 	DRM_DEBUG("%s\n", __FUNCTION__);
 	DRM_DEBUG("%s\n", __FUNCTION__);
 	if (dev_priv->current_page != 0)
 	if (dev_priv->current_page != 0)
-		i810_dma_dispatch_flip( dev );
+		i810_dma_dispatch_flip(dev);
 
 
 	dev_priv->page_flipping = 0;
 	dev_priv->page_flipping = 0;
 	return 0;
 	return 0;
 }
 }
 
 
 static int i810_flip_bufs(struct inode *inode, struct file *filp,
 static int i810_flip_bufs(struct inode *inode, struct file *filp,
-			unsigned int cmd, unsigned long arg)
+			  unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -1327,19 +1312,19 @@ static int i810_flip_bufs(struct inode *inode, struct file *filp,
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
-	if (!dev_priv->page_flipping) 
-		i810_do_init_pageflip( dev );
+	if (!dev_priv->page_flipping)
+		i810_do_init_pageflip(dev);
 
 
-	i810_dma_dispatch_flip( dev );
-   	return 0;
+	i810_dma_dispatch_flip(dev);
+	return 0;
 }
 }
 
 
-void i810_driver_pretakedown(drm_device_t *dev)
+void i810_driver_pretakedown(drm_device_t * dev)
 {
 {
-	i810_dma_cleanup( dev );
+	i810_dma_cleanup(dev);
 }
 }
 
 
-void i810_driver_prerelease(drm_device_t *dev, DRMFILE filp)
+void i810_driver_prerelease(drm_device_t * dev, DRMFILE filp)
 {
 {
 	if (dev->dev_private) {
 	if (dev->dev_private) {
 		drm_i810_private_t *dev_priv = dev->dev_private;
 		drm_i810_private_t *dev_priv = dev->dev_private;
@@ -1349,33 +1334,33 @@ void i810_driver_prerelease(drm_device_t *dev, DRMFILE filp)
 	}
 	}
 }
 }
 
 
-void i810_driver_release(drm_device_t *dev, struct file *filp)
+void i810_driver_release(drm_device_t * dev, struct file *filp)
 {
 {
 	i810_reclaim_buffers(dev, filp);
 	i810_reclaim_buffers(dev, filp);
 }
 }
 
 
-int i810_driver_dma_quiescent(drm_device_t *dev)
+int i810_driver_dma_quiescent(drm_device_t * dev)
 {
 {
-	i810_dma_quiescent( dev );
+	i810_dma_quiescent(dev);
 	return 0;
 	return 0;
 }
 }
 
 
 drm_ioctl_desc_t i810_ioctls[] = {
 drm_ioctl_desc_t i810_ioctls[] = {
-	[DRM_IOCTL_NR(DRM_I810_INIT)]    = { i810_dma_init,    1, 1 },
-	[DRM_IOCTL_NR(DRM_I810_VERTEX)]  = { i810_dma_vertex,  1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_CLEAR)]   = { i810_clear_bufs,  1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_FLUSH)]   = { i810_flush_ioctl, 1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_GETAGE)]  = { i810_getage,      1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_GETBUF)]  = { i810_getbuf,      1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_SWAP)]    = { i810_swap_bufs,   1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_COPY)]    = { i810_copybuf,     1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_DOCOPY)]  = { i810_docopy,      1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_OV0INFO)] = { i810_ov0_info,    1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_FSTATUS)] = { i810_fstatus,     1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_OV0FLIP)] = { i810_ov0_flip,    1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_MC)]      = { i810_dma_mc,      1, 1 },
-	[DRM_IOCTL_NR(DRM_I810_RSTATUS)] = { i810_rstatus,     1, 0 },
-	[DRM_IOCTL_NR(DRM_I810_FLIP)]    = { i810_flip_bufs,   1, 0 }
+	[DRM_IOCTL_NR(DRM_I810_INIT)] = {i810_dma_init, 1, 1},
+	[DRM_IOCTL_NR(DRM_I810_VERTEX)] = {i810_dma_vertex, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_CLEAR)] = {i810_clear_bufs, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_FLUSH)] = {i810_flush_ioctl, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_GETAGE)] = {i810_getage, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_GETBUF)] = {i810_getbuf, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_SWAP)] = {i810_swap_bufs, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_COPY)] = {i810_copybuf, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_DOCOPY)] = {i810_docopy, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_OV0INFO)] = {i810_ov0_info, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_FSTATUS)] = {i810_fstatus, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_OV0FLIP)] = {i810_ov0_flip, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_MC)] = {i810_dma_mc, 1, 1},
+	[DRM_IOCTL_NR(DRM_I810_RSTATUS)] = {i810_rstatus, 1, 0},
+	[DRM_IOCTL_NR(DRM_I810_FLIP)] = {i810_flip_bufs, 1, 0}
 };
 };
 
 
 int i810_max_ioctl = DRM_ARRAY_SIZE(i810_ioctls);
 int i810_max_ioctl = DRM_ARRAY_SIZE(i810_ioctls);

+ 36 - 39
drivers/char/drm/i810_drm.h

@@ -19,21 +19,20 @@
 #define I810_LOG_MIN_TEX_REGION_SIZE 16
 #define I810_LOG_MIN_TEX_REGION_SIZE 16
 #endif
 #endif
 
 
-#define I810_UPLOAD_TEX0IMAGE  0x1 /* handled clientside */
-#define I810_UPLOAD_TEX1IMAGE  0x2 /* handled clientside */
+#define I810_UPLOAD_TEX0IMAGE  0x1	/* handled clientside */
+#define I810_UPLOAD_TEX1IMAGE  0x2	/* handled clientside */
 #define I810_UPLOAD_CTX        0x4
 #define I810_UPLOAD_CTX        0x4
 #define I810_UPLOAD_BUFFERS    0x8
 #define I810_UPLOAD_BUFFERS    0x8
 #define I810_UPLOAD_TEX0       0x10
 #define I810_UPLOAD_TEX0       0x10
 #define I810_UPLOAD_TEX1       0x20
 #define I810_UPLOAD_TEX1       0x20
 #define I810_UPLOAD_CLIPRECTS  0x40
 #define I810_UPLOAD_CLIPRECTS  0x40
 
 
-
 /* Indices into buf.Setup where various bits of state are mirrored per
 /* Indices into buf.Setup where various bits of state are mirrored per
  * context and per buffer.  These can be fired at the card as a unit,
  * context and per buffer.  These can be fired at the card as a unit,
  * or in a piecewise fashion as required.
  * or in a piecewise fashion as required.
  */
  */
 
 
-/* Destbuffer state 
+/* Destbuffer state
  *    - backbuffer linear offset and pitch -- invarient in the current dri
  *    - backbuffer linear offset and pitch -- invarient in the current dri
  *    - zbuffer linear offset and pitch -- also invarient
  *    - zbuffer linear offset and pitch -- also invarient
  *    - drawing origin in back and depth buffers.
  *    - drawing origin in back and depth buffers.
@@ -55,13 +54,13 @@
 /* Context state
 /* Context state
  */
  */
 #define I810_CTXREG_CF0   0	/* GFX_OP_COLOR_FACTOR */
 #define I810_CTXREG_CF0   0	/* GFX_OP_COLOR_FACTOR */
-#define I810_CTXREG_CF1   1	
-#define I810_CTXREG_ST0   2     /* GFX_OP_STIPPLE */
+#define I810_CTXREG_CF1   1
+#define I810_CTXREG_ST0   2	/* GFX_OP_STIPPLE */
 #define I810_CTXREG_ST1   3
 #define I810_CTXREG_ST1   3
 #define I810_CTXREG_VF    4	/* GFX_OP_VERTEX_FMT */
 #define I810_CTXREG_VF    4	/* GFX_OP_VERTEX_FMT */
 #define I810_CTXREG_MT    5	/* GFX_OP_MAP_TEXELS */
 #define I810_CTXREG_MT    5	/* GFX_OP_MAP_TEXELS */
 #define I810_CTXREG_MC0   6	/* GFX_OP_MAP_COLOR_STAGES - stage 0 */
 #define I810_CTXREG_MC0   6	/* GFX_OP_MAP_COLOR_STAGES - stage 0 */
-#define I810_CTXREG_MC1   7     /* GFX_OP_MAP_COLOR_STAGES - stage 1 */
+#define I810_CTXREG_MC1   7	/* GFX_OP_MAP_COLOR_STAGES - stage 1 */
 #define I810_CTXREG_MC2   8	/* GFX_OP_MAP_COLOR_STAGES - stage 2 */
 #define I810_CTXREG_MC2   8	/* GFX_OP_MAP_COLOR_STAGES - stage 2 */
 #define I810_CTXREG_MA0   9	/* GFX_OP_MAP_ALPHA_STAGES - stage 0 */
 #define I810_CTXREG_MA0   9	/* GFX_OP_MAP_ALPHA_STAGES - stage 0 */
 #define I810_CTXREG_MA1   10	/* GFX_OP_MAP_ALPHA_STAGES - stage 1 */
 #define I810_CTXREG_MA1   10	/* GFX_OP_MAP_ALPHA_STAGES - stage 1 */
@@ -74,14 +73,14 @@
 #define I810_CTXREG_PV    17	/* GFX_OP_PV_RULE -- Invarient! */
 #define I810_CTXREG_PV    17	/* GFX_OP_PV_RULE -- Invarient! */
 #define I810_CTXREG_ZA    18	/* GFX_OP_ZBIAS_ALPHAFUNC */
 #define I810_CTXREG_ZA    18	/* GFX_OP_ZBIAS_ALPHAFUNC */
 #define I810_CTXREG_AA    19	/* GFX_OP_ANTIALIAS */
 #define I810_CTXREG_AA    19	/* GFX_OP_ANTIALIAS */
-#define I810_CTX_SETUP_SIZE 20 
+#define I810_CTX_SETUP_SIZE 20
 
 
 /* Texture state (per tex unit)
 /* Texture state (per tex unit)
  */
  */
 #define I810_TEXREG_MI0  0	/* GFX_OP_MAP_INFO (4 dwords) */
 #define I810_TEXREG_MI0  0	/* GFX_OP_MAP_INFO (4 dwords) */
-#define I810_TEXREG_MI1  1	
-#define I810_TEXREG_MI2  2	
-#define I810_TEXREG_MI3  3	
+#define I810_TEXREG_MI1  1
+#define I810_TEXREG_MI2  2
+#define I810_TEXREG_MI3  3
 #define I810_TEXREG_MF   4	/* GFX_OP_MAP_FILTER */
 #define I810_TEXREG_MF   4	/* GFX_OP_MAP_FILTER */
 #define I810_TEXREG_MLC  5	/* GFX_OP_MAP_LOD_CTL */
 #define I810_TEXREG_MLC  5	/* GFX_OP_MAP_LOD_CTL */
 #define I810_TEXREG_MLL  6	/* GFX_OP_MAP_LOD_LIMITS */
 #define I810_TEXREG_MLL  6	/* GFX_OP_MAP_LOD_LIMITS */
@@ -98,7 +97,7 @@ typedef enum _drm_i810_init_func {
 	I810_INIT_DMA = 0x01,
 	I810_INIT_DMA = 0x01,
 	I810_CLEANUP_DMA = 0x02,
 	I810_CLEANUP_DMA = 0x02,
 	I810_INIT_DMA_1_4 = 0x03
 	I810_INIT_DMA_1_4 = 0x03
- } drm_i810_init_func_t;
+} drm_i810_init_func_t;
 
 
 /* This is the init structure after v1.2 */
 /* This is the init structure after v1.2 */
 typedef struct _drm_i810_init {
 typedef struct _drm_i810_init {
@@ -122,7 +121,7 @@ typedef struct _drm_i810_init {
 	unsigned int w;
 	unsigned int w;
 	unsigned int h;
 	unsigned int h;
 	unsigned int pitch;
 	unsigned int pitch;
-	unsigned int pitch_bits; 
+	unsigned int pitch_bits;
 } drm_i810_init_t;
 } drm_i810_init_t;
 
 
 /* This is the init structure prior to v1.2 */
 /* This is the init structure prior to v1.2 */
@@ -140,23 +139,23 @@ typedef struct _drm_i810_pre12_init {
 	unsigned int w;
 	unsigned int w;
 	unsigned int h;
 	unsigned int h;
 	unsigned int pitch;
 	unsigned int pitch;
-	unsigned int pitch_bits; 
+	unsigned int pitch_bits;
 } drm_i810_pre12_init_t;
 } drm_i810_pre12_init_t;
 
 
 /* Warning: If you change the SAREA structure you must change the Xserver
 /* Warning: If you change the SAREA structure you must change the Xserver
  * structure as well */
  * structure as well */
 
 
 typedef struct _drm_i810_tex_region {
 typedef struct _drm_i810_tex_region {
-	unsigned char next, prev; /* indices to form a circular LRU  */
+	unsigned char next, prev;	/* indices to form a circular LRU  */
 	unsigned char in_use;	/* owned by a client, or free? */
 	unsigned char in_use;	/* owned by a client, or free? */
 	int age;		/* tracked by clients to update local LRU's */
 	int age;		/* tracked by clients to update local LRU's */
 } drm_i810_tex_region_t;
 } drm_i810_tex_region_t;
 
 
 typedef struct _drm_i810_sarea {
 typedef struct _drm_i810_sarea {
-   	unsigned int ContextState[I810_CTX_SETUP_SIZE];
-   	unsigned int BufferState[I810_DEST_SETUP_SIZE];
-   	unsigned int TexState[2][I810_TEX_SETUP_SIZE];
-   	unsigned int dirty;
+	unsigned int ContextState[I810_CTX_SETUP_SIZE];
+	unsigned int BufferState[I810_DEST_SETUP_SIZE];
+	unsigned int TexState[2][I810_TEX_SETUP_SIZE];
+	unsigned int dirty;
 
 
 	unsigned int nbox;
 	unsigned int nbox;
 	drm_clip_rect_t boxes[I810_NR_SAREA_CLIPRECTS];
 	drm_clip_rect_t boxes[I810_NR_SAREA_CLIPRECTS];
@@ -174,22 +173,22 @@ typedef struct _drm_i810_sarea {
 	 * texture space, and can make informed decisions as to which
 	 * texture space, and can make informed decisions as to which
 	 * areas to kick out.  There is no need to choose whether to
 	 * areas to kick out.  There is no need to choose whether to
 	 * kick out your own texture or someone else's - simply eject
 	 * kick out your own texture or someone else's - simply eject
-	 * them all in LRU order.  
+	 * them all in LRU order.
 	 */
 	 */
-   
-	drm_i810_tex_region_t texList[I810_NR_TEX_REGIONS+1]; 
-				/* Last elt is sentinal */
-        int texAge;		/* last time texture was uploaded */
-        int last_enqueue;	/* last time a buffer was enqueued */
+
+	drm_i810_tex_region_t texList[I810_NR_TEX_REGIONS + 1];
+	/* Last elt is sentinal */
+	int texAge;		/* last time texture was uploaded */
+	int last_enqueue;	/* last time a buffer was enqueued */
 	int last_dispatch;	/* age of the most recently dispatched buffer */
 	int last_dispatch;	/* age of the most recently dispatched buffer */
-	int last_quiescent;     /*  */
+	int last_quiescent;	/*  */
 	int ctxOwner;		/* last context to upload state */
 	int ctxOwner;		/* last context to upload state */
 
 
 	int vertex_prim;
 	int vertex_prim;
 
 
-	int pf_enabled;               /* is pageflipping allowed? */
+	int pf_enabled;		/* is pageflipping allowed? */
 	int pf_active;
 	int pf_active;
-	int pf_current_page;	    /* which buffer is being displayed? */
+	int pf_current_page;	/* which buffer is being displayed? */
 } drm_i810_sarea_t;
 } drm_i810_sarea_t;
 
 
 /* WARNING: If you change any of these defines, make sure to change the
 /* WARNING: If you change any of these defines, make sure to change the
@@ -243,13 +242,13 @@ typedef struct _drm_i810_clear {
  * new set of cliprects.
  * new set of cliprects.
  */
  */
 typedef struct _drm_i810_vertex {
 typedef struct _drm_i810_vertex {
-   	int idx;		/* buffer index */
+	int idx;		/* buffer index */
 	int used;		/* nr bytes in use */
 	int used;		/* nr bytes in use */
 	int discard;		/* client is finished with the buffer? */
 	int discard;		/* client is finished with the buffer? */
 } drm_i810_vertex_t;
 } drm_i810_vertex_t;
 
 
 typedef struct _drm_i810_copy_t {
 typedef struct _drm_i810_copy_t {
-   	int idx;		/* buffer index */
+	int idx;		/* buffer index */
 	int used;		/* nr bytes in use */
 	int used;		/* nr bytes in use */
 	void *address;		/* Address to copy from */
 	void *address;		/* Address to copy from */
 } drm_i810_copy_t;
 } drm_i810_copy_t;
@@ -264,7 +263,6 @@ typedef struct _drm_i810_copy_t {
 #define PR_RECTS             (0x7<<18)
 #define PR_RECTS             (0x7<<18)
 #define PR_MASK              (0x7<<18)
 #define PR_MASK              (0x7<<18)
 
 
-
 typedef struct drm_i810_dma {
 typedef struct drm_i810_dma {
 	void *virtual;
 	void *virtual;
 	int request_idx;
 	int request_idx;
@@ -273,17 +271,16 @@ typedef struct drm_i810_dma {
 } drm_i810_dma_t;
 } drm_i810_dma_t;
 
 
 typedef struct _drm_i810_overlay_t {
 typedef struct _drm_i810_overlay_t {
-	unsigned int offset;    /* Address of the Overlay Regs */
+	unsigned int offset;	/* Address of the Overlay Regs */
 	unsigned int physical;
 	unsigned int physical;
 } drm_i810_overlay_t;
 } drm_i810_overlay_t;
 
 
 typedef struct _drm_i810_mc {
 typedef struct _drm_i810_mc {
-	int idx;                /* buffer index */
-	int used;               /* nr bytes in use */
-	int num_blocks;         /* number of GFXBlocks */
-	int *length;            /* List of lengths for GFXBlocks (FUTURE)*/
-	unsigned int last_render; /* Last Render Request */
+	int idx;		/* buffer index */
+	int used;		/* nr bytes in use */
+	int num_blocks;		/* number of GFXBlocks */
+	int *length;		/* List of lengths for GFXBlocks (FUTURE) */
+	unsigned int last_render;	/* Last Render Request */
 } drm_i810_mc_t;
 } drm_i810_mc_t;
 
 
-
-#endif /* _I810_DRM_H_ */
+#endif				/* _I810_DRM_H_ */

+ 31 - 32
drivers/char/drm/i810_drv.c

@@ -38,7 +38,7 @@
 
 
 #include "drm_pciids.h"
 #include "drm_pciids.h"
 
 
-static int postinit( struct drm_device *dev, unsigned long flags )
+static int postinit(struct drm_device *dev, unsigned long flags)
 {
 {
 	/* i810 has 4 more counters */
 	/* i810 has 4 more counters */
 	dev->counters += 4;
 	dev->counters += 4;
@@ -46,29 +46,27 @@ static int postinit( struct drm_device *dev, unsigned long flags )
 	dev->types[7] = _DRM_STAT_PRIMARY;
 	dev->types[7] = _DRM_STAT_PRIMARY;
 	dev->types[8] = _DRM_STAT_SECONDARY;
 	dev->types[8] = _DRM_STAT_SECONDARY;
 	dev->types[9] = _DRM_STAT_DMA;
 	dev->types[9] = _DRM_STAT_DMA;
-	
-	DRM_INFO( "Initialized %s %d.%d.%d %s on minor %d: %s\n",
-		DRIVER_NAME,
-		DRIVER_MAJOR,
-		DRIVER_MINOR,
-		DRIVER_PATCHLEVEL,
-		DRIVER_DATE,
-		dev->primary.minor,
-		pci_pretty_name(dev->pdev)
-		);
+
+	DRM_INFO("Initialized %s %d.%d.%d %s on minor %d: %s\n",
+		 DRIVER_NAME,
+		 DRIVER_MAJOR,
+		 DRIVER_MINOR,
+		 DRIVER_PATCHLEVEL,
+		 DRIVER_DATE, dev->primary.minor, pci_pretty_name(dev->pdev)
+	    );
 	return 0;
 	return 0;
 }
 }
 
 
-static int version( drm_version_t *version )
+static int version(drm_version_t * version)
 {
 {
 	int len;
 	int len;
 
 
 	version->version_major = DRIVER_MAJOR;
 	version->version_major = DRIVER_MAJOR;
 	version->version_minor = DRIVER_MINOR;
 	version->version_minor = DRIVER_MINOR;
 	version->version_patchlevel = DRIVER_PATCHLEVEL;
 	version->version_patchlevel = DRIVER_PATCHLEVEL;
-	DRM_COPY( version->name, DRIVER_NAME );
-	DRM_COPY( version->date, DRIVER_DATE );
-	DRM_COPY( version->desc, DRIVER_DESC );
+	DRM_COPY(version->name, DRIVER_NAME);
+	DRM_COPY(version->date, DRIVER_DATE);
+	DRM_COPY(version->desc, DRIVER_DESC);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -76,11 +74,10 @@ static struct pci_device_id pciidlist[] = {
 	i810_PCI_IDS
 	i810_PCI_IDS
 };
 };
 
 
-extern drm_ioctl_desc_t i810_ioctls[];
-extern int i810_max_ioctl;
-
 static struct drm_driver driver = {
 static struct drm_driver driver = {
-	.driver_features = DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_DMA_QUEUE,
+	.driver_features =
+	    DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
+	    DRIVER_HAVE_DMA | DRIVER_DMA_QUEUE,
 	.dev_priv_size = sizeof(drm_i810_buf_priv_t),
 	.dev_priv_size = sizeof(drm_i810_buf_priv_t),
 	.pretakedown = i810_driver_pretakedown,
 	.pretakedown = i810_driver_pretakedown,
 	.prerelease = i810_driver_prerelease,
 	.prerelease = i810_driver_prerelease,
@@ -94,18 +91,20 @@ static struct drm_driver driver = {
 	.version = version,
 	.version = version,
 	.ioctls = i810_ioctls,
 	.ioctls = i810_ioctls,
 	.fops = {
 	.fops = {
-		.owner = THIS_MODULE,
-		.open = drm_open,
-		.release = drm_release,
-		.ioctl = drm_ioctl,
-		.mmap = drm_mmap,
-		.poll = drm_poll,
-		.fasync = drm_fasync,
-	},
+		 .owner = THIS_MODULE,
+		 .open = drm_open,
+		 .release = drm_release,
+		 .ioctl = drm_ioctl,
+		 .mmap = drm_mmap,
+		 .poll = drm_poll,
+		 .fasync = drm_fasync,
+		 }
+	,
 	.pci_driver = {
 	.pci_driver = {
-		.name          = DRIVER_NAME,
-		.id_table      = pciidlist,
-	},
+		       .name = DRIVER_NAME,
+		       .id_table = pciidlist,
+		       }
+	,
 };
 };
 
 
 static int __init i810_init(void)
 static int __init i810_init(void)
@@ -122,6 +121,6 @@ static void __exit i810_exit(void)
 module_init(i810_init);
 module_init(i810_init);
 module_exit(i810_exit);
 module_exit(i810_exit);
 
 
-MODULE_AUTHOR( DRIVER_AUTHOR );
-MODULE_DESCRIPTION( DRIVER_DESC );
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL and additional rights");
 MODULE_LICENSE("GPL and additional rights");

+ 21 - 20
drivers/char/drm/i810_drv.h

@@ -56,14 +56,14 @@
 #define DRIVER_PATCHLEVEL	0
 #define DRIVER_PATCHLEVEL	0
 
 
 typedef struct drm_i810_buf_priv {
 typedef struct drm_i810_buf_priv {
-   	u32 *in_use;
-   	int my_use_idx;
+	u32 *in_use;
+	int my_use_idx;
 	int currently_mapped;
 	int currently_mapped;
 	void *virtual;
 	void *virtual;
 	void *kernel_virtual;
 	void *kernel_virtual;
 } drm_i810_buf_priv_t;
 } drm_i810_buf_priv_t;
 
 
-typedef struct _drm_i810_ring_buffer{
+typedef struct _drm_i810_ring_buffer {
 	int tail_mask;
 	int tail_mask;
 	unsigned long Start;
 	unsigned long Start;
 	unsigned long End;
 	unsigned long End;
@@ -79,16 +79,15 @@ typedef struct drm_i810_private {
 	drm_map_t *mmio_map;
 	drm_map_t *mmio_map;
 
 
 	drm_i810_sarea_t *sarea_priv;
 	drm_i810_sarea_t *sarea_priv;
-   	drm_i810_ring_buffer_t ring;
+	drm_i810_ring_buffer_t ring;
 
 
-      	void *hw_status_page;
-   	unsigned long counter;
+	void *hw_status_page;
+	unsigned long counter;
 
 
 	dma_addr_t dma_status_page;
 	dma_addr_t dma_status_page;
 
 
 	drm_buf_t *mmap_buffer;
 	drm_buf_t *mmap_buffer;
 
 
-
 	u32 front_di1, back_di1, zi1;
 	u32 front_di1, back_di1, zi1;
 
 
 	int back_offset;
 	int back_offset;
@@ -97,7 +96,7 @@ typedef struct drm_i810_private {
 	int overlay_physical;
 	int overlay_physical;
 	int w, h;
 	int w, h;
 	int pitch;
 	int pitch;
-  	int back_pitch;
+	int back_pitch;
 	int depth_pitch;
 	int depth_pitch;
 
 
 	int do_boxes;
 	int do_boxes;
@@ -107,21 +106,24 @@ typedef struct drm_i810_private {
 	int page_flipping;
 	int page_flipping;
 
 
 	wait_queue_head_t irq_queue;
 	wait_queue_head_t irq_queue;
-   	atomic_t irq_received;
-   	atomic_t irq_emitted;
-  
-        int front_offset;
+	atomic_t irq_received;
+	atomic_t irq_emitted;
+
+	int front_offset;
 } drm_i810_private_t;
 } drm_i810_private_t;
 
 
 				/* i810_dma.c */
 				/* i810_dma.c */
-extern void i810_reclaim_buffers(drm_device_t *dev, struct file *filp);
+extern void i810_reclaim_buffers(drm_device_t * dev, struct file *filp);
 
 
-extern int i810_driver_dma_quiescent(drm_device_t *dev);
-extern void i810_driver_release(drm_device_t *dev, struct file *filp);
-extern void i810_driver_pretakedown(drm_device_t *dev);
-extern void i810_driver_prerelease(drm_device_t *dev, DRMFILE filp);
+extern int i810_driver_dma_quiescent(drm_device_t * dev);
+extern void i810_driver_release(drm_device_t * dev, struct file *filp);
+extern void i810_driver_pretakedown(drm_device_t * dev);
+extern void i810_driver_prerelease(drm_device_t * dev, DRMFILE filp);
 extern int i810_driver_device_is_agp(drm_device_t * dev);
 extern int i810_driver_device_is_agp(drm_device_t * dev);
 
 
+extern drm_ioctl_desc_t i810_ioctls[];
+extern int i810_max_ioctl;
+
 #define I810_BASE(reg)		((unsigned long) \
 #define I810_BASE(reg)		((unsigned long) \
 				dev_priv->mmio_map->handle)
 				dev_priv->mmio_map->handle)
 #define I810_ADDR(reg)		(I810_BASE(reg) + reg)
 #define I810_ADDR(reg)		(I810_BASE(reg) + reg)
@@ -170,7 +172,6 @@ extern int i810_driver_device_is_agp(drm_device_t * dev);
 #define INST_OP_FLUSH        0x02000000
 #define INST_OP_FLUSH        0x02000000
 #define INST_FLUSH_MAP_CACHE 0x00000001
 #define INST_FLUSH_MAP_CACHE 0x00000001
 
 
-
 #define BB1_START_ADDR_MASK   (~0x7)
 #define BB1_START_ADDR_MASK   (~0x7)
 #define BB1_PROTECTED         (1<<0)
 #define BB1_PROTECTED         (1<<0)
 #define BB1_UNPROTECTED       (0<<0)
 #define BB1_UNPROTECTED       (0<<0)
@@ -229,8 +230,8 @@ extern int i810_driver_device_is_agp(drm_device_t * dev);
 #define BR00_OP_SRC_COPY_BLT 0x10C00000
 #define BR00_OP_SRC_COPY_BLT 0x10C00000
 #define BR13_SOLID_PATTERN   0x80000000
 #define BR13_SOLID_PATTERN   0x80000000
 
 
-#define WAIT_FOR_PLANE_A_SCANLINES (1<<1) 
-#define WAIT_FOR_PLANE_A_FLIP      (1<<2) 
+#define WAIT_FOR_PLANE_A_SCANLINES (1<<1)
+#define WAIT_FOR_PLANE_A_FLIP      (1<<2)
 #define WAIT_FOR_VBLANK (1<<3)
 #define WAIT_FOR_VBLANK (1<<3)
 
 
 #endif
 #endif

+ 647 - 668
drivers/char/drm/i830_dma.c

@@ -11,11 +11,11 @@
  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  * and/or sell copies of the Software, and to permit persons to whom the
  * and/or sell copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following conditions:
  * Software is furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice (including the next
  * The above copyright notice and this permission notice (including the next
  * paragraph) shall be included in all copies or substantial portions of the
  * paragraph) shall be included in all copies or substantial portions of the
  * Software.
  * Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
@@ -47,103 +47,104 @@
 #define I830_BUF_UNMAPPED 0
 #define I830_BUF_UNMAPPED 0
 #define I830_BUF_MAPPED   1
 #define I830_BUF_MAPPED   1
 
 
-static drm_buf_t *i830_freelist_get(drm_device_t *dev)
+static drm_buf_t *i830_freelist_get(drm_device_t * dev)
 {
 {
-   	drm_device_dma_t *dma = dev->dma;
-	int		 i;
-   	int 		 used;
-   
+	drm_device_dma_t *dma = dev->dma;
+	int i;
+	int used;
+
 	/* Linear search might not be the best solution */
 	/* Linear search might not be the best solution */
 
 
-   	for (i = 0; i < dma->buf_count; i++) {
-	   	drm_buf_t *buf = dma->buflist[ i ];
-	   	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+	for (i = 0; i < dma->buf_count; i++) {
+		drm_buf_t *buf = dma->buflist[i];
+		drm_i830_buf_priv_t *buf_priv = buf->dev_private;
 		/* In use is already a pointer */
 		/* In use is already a pointer */
-	   	used = cmpxchg(buf_priv->in_use, I830_BUF_FREE, 
+		used = cmpxchg(buf_priv->in_use, I830_BUF_FREE,
 			       I830_BUF_CLIENT);
 			       I830_BUF_CLIENT);
-	   	if(used == I830_BUF_FREE) {
+		if (used == I830_BUF_FREE) {
 			return buf;
 			return buf;
 		}
 		}
 	}
 	}
-   	return NULL;
+	return NULL;
 }
 }
 
 
 /* This should only be called if the buffer is not sent to the hardware
 /* This should only be called if the buffer is not sent to the hardware
  * yet, the hardware updates in use for us once its on the ring buffer.
  * yet, the hardware updates in use for us once its on the ring buffer.
  */
  */
 
 
-static int i830_freelist_put(drm_device_t *dev, drm_buf_t *buf)
+static int i830_freelist_put(drm_device_t * dev, drm_buf_t * buf)
 {
 {
-   	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-   	int used;
-   
-   	/* In use is already a pointer */
-   	used = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT, I830_BUF_FREE);
-   	if(used != I830_BUF_CLIENT) {
-	   	DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx);
-	   	return -EINVAL;
+	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+	int used;
+
+	/* In use is already a pointer */
+	used = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT, I830_BUF_FREE);
+	if (used != I830_BUF_CLIENT) {
+		DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx);
+		return -EINVAL;
 	}
 	}
-   
-   	return 0;
+
+	return 0;
 }
 }
 
 
 static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
 static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
 {
 {
-	drm_file_t	    *priv	  = filp->private_data;
-	drm_device_t	    *dev;
-	drm_i830_private_t  *dev_priv;
-	drm_buf_t           *buf;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev;
+	drm_i830_private_t *dev_priv;
+	drm_buf_t *buf;
 	drm_i830_buf_priv_t *buf_priv;
 	drm_i830_buf_priv_t *buf_priv;
 
 
 	lock_kernel();
 	lock_kernel();
-	dev	 = priv->head->dev;
+	dev = priv->head->dev;
 	dev_priv = dev->dev_private;
 	dev_priv = dev->dev_private;
-	buf      = dev_priv->mmap_buffer;
+	buf = dev_priv->mmap_buffer;
 	buf_priv = buf->dev_private;
 	buf_priv = buf->dev_private;
-   
+
 	vma->vm_flags |= (VM_IO | VM_DONTCOPY);
 	vma->vm_flags |= (VM_IO | VM_DONTCOPY);
 	vma->vm_file = filp;
 	vma->vm_file = filp;
-   
-   	buf_priv->currently_mapped = I830_BUF_MAPPED;
+
+	buf_priv->currently_mapped = I830_BUF_MAPPED;
 	unlock_kernel();
 	unlock_kernel();
 
 
 	if (io_remap_pfn_range(vma, vma->vm_start,
 	if (io_remap_pfn_range(vma, vma->vm_start,
-			     VM_OFFSET(vma) >> PAGE_SHIFT,
-			     vma->vm_end - vma->vm_start,
-			     vma->vm_page_prot)) return -EAGAIN;
+			       VM_OFFSET(vma) >> PAGE_SHIFT,
+			       vma->vm_end - vma->vm_start, vma->vm_page_prot))
+		return -EAGAIN;
 	return 0;
 	return 0;
 }
 }
 
 
 static struct file_operations i830_buffer_fops = {
 static struct file_operations i830_buffer_fops = {
-	.open	 = drm_open,
-	.flush	 = drm_flush,
+	.open = drm_open,
+	.flush = drm_flush,
 	.release = drm_release,
 	.release = drm_release,
-	.ioctl	 = drm_ioctl,
-	.mmap	 = i830_mmap_buffers,
-	.fasync  = drm_fasync,
+	.ioctl = drm_ioctl,
+	.mmap = i830_mmap_buffers,
+	.fasync = drm_fasync,
 };
 };
 
 
-static int i830_map_buffer(drm_buf_t *buf, struct file *filp)
+static int i830_map_buffer(drm_buf_t * buf, struct file *filp)
 {
 {
-	drm_file_t	  *priv	  = filp->private_data;
-	drm_device_t	  *dev	  = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
 	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-      	drm_i830_private_t *dev_priv = dev->dev_private;
-   	struct file_operations *old_fops;
+	drm_i830_private_t *dev_priv = dev->dev_private;
+	struct file_operations *old_fops;
 	unsigned long virtual;
 	unsigned long virtual;
 	int retcode = 0;
 	int retcode = 0;
 
 
-	if(buf_priv->currently_mapped == I830_BUF_MAPPED) return -EINVAL;
+	if (buf_priv->currently_mapped == I830_BUF_MAPPED)
+		return -EINVAL;
 
 
-	down_write( &current->mm->mmap_sem );
+	down_write(&current->mm->mmap_sem);
 	old_fops = filp->f_op;
 	old_fops = filp->f_op;
 	filp->f_op = &i830_buffer_fops;
 	filp->f_op = &i830_buffer_fops;
 	dev_priv->mmap_buffer = buf;
 	dev_priv->mmap_buffer = buf;
-	virtual = do_mmap(filp, 0, buf->total, PROT_READ|PROT_WRITE,
-			    MAP_SHARED, buf->bus_address);
+	virtual = do_mmap(filp, 0, buf->total, PROT_READ | PROT_WRITE,
+			  MAP_SHARED, buf->bus_address);
 	dev_priv->mmap_buffer = NULL;
 	dev_priv->mmap_buffer = NULL;
 	filp->f_op = old_fops;
 	filp->f_op = old_fops;
-	if (IS_ERR((void *)virtual)) {		/* ugh */
+	if (IS_ERR((void *)virtual)) {	/* ugh */
 		/* Real error */
 		/* Real error */
 		DRM_ERROR("mmap error\n");
 		DRM_ERROR("mmap error\n");
 		retcode = virtual;
 		retcode = virtual;
@@ -151,17 +152,17 @@ static int i830_map_buffer(drm_buf_t *buf, struct file *filp)
 	} else {
 	} else {
 		buf_priv->virtual = (void __user *)virtual;
 		buf_priv->virtual = (void __user *)virtual;
 	}
 	}
-	up_write( &current->mm->mmap_sem );
+	up_write(&current->mm->mmap_sem);
 
 
 	return retcode;
 	return retcode;
 }
 }
 
 
-static int i830_unmap_buffer(drm_buf_t *buf)
+static int i830_unmap_buffer(drm_buf_t * buf)
 {
 {
 	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
 	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
 	int retcode = 0;
 	int retcode = 0;
 
 
-	if(buf_priv->currently_mapped != I830_BUF_MAPPED) 
+	if (buf_priv->currently_mapped != I830_BUF_MAPPED)
 		return -EINVAL;
 		return -EINVAL;
 
 
 	down_write(&current->mm->mmap_sem);
 	down_write(&current->mm->mmap_sem);
@@ -170,43 +171,43 @@ static int i830_unmap_buffer(drm_buf_t *buf)
 			    (size_t) buf->total);
 			    (size_t) buf->total);
 	up_write(&current->mm->mmap_sem);
 	up_write(&current->mm->mmap_sem);
 
 
-   	buf_priv->currently_mapped = I830_BUF_UNMAPPED;
-   	buf_priv->virtual = NULL;
+	buf_priv->currently_mapped = I830_BUF_UNMAPPED;
+	buf_priv->virtual = NULL;
 
 
 	return retcode;
 	return retcode;
 }
 }
 
 
-static int i830_dma_get_buffer(drm_device_t *dev, drm_i830_dma_t *d, 
+static int i830_dma_get_buffer(drm_device_t * dev, drm_i830_dma_t * d,
 			       struct file *filp)
 			       struct file *filp)
 {
 {
-	drm_buf_t	  *buf;
+	drm_buf_t *buf;
 	drm_i830_buf_priv_t *buf_priv;
 	drm_i830_buf_priv_t *buf_priv;
 	int retcode = 0;
 	int retcode = 0;
 
 
 	buf = i830_freelist_get(dev);
 	buf = i830_freelist_get(dev);
 	if (!buf) {
 	if (!buf) {
 		retcode = -ENOMEM;
 		retcode = -ENOMEM;
-	   	DRM_DEBUG("retcode=%d\n", retcode);
+		DRM_DEBUG("retcode=%d\n", retcode);
 		return retcode;
 		return retcode;
 	}
 	}
-   
+
 	retcode = i830_map_buffer(buf, filp);
 	retcode = i830_map_buffer(buf, filp);
-	if(retcode) {
+	if (retcode) {
 		i830_freelist_put(dev, buf);
 		i830_freelist_put(dev, buf);
-	   	DRM_ERROR("mapbuf failed, retcode %d\n", retcode);
+		DRM_ERROR("mapbuf failed, retcode %d\n", retcode);
 		return retcode;
 		return retcode;
 	}
 	}
 	buf->filp = filp;
 	buf->filp = filp;
-	buf_priv = buf->dev_private;	
+	buf_priv = buf->dev_private;
 	d->granted = 1;
 	d->granted = 1;
-   	d->request_idx = buf->idx;
-   	d->request_size = buf->total;
-   	d->virtual = buf_priv->virtual;
+	d->request_idx = buf->idx;
+	d->request_size = buf->total;
+	d->virtual = buf_priv->virtual;
 
 
 	return retcode;
 	return retcode;
 }
 }
 
 
-static int i830_dma_cleanup(drm_device_t *dev)
+static int i830_dma_cleanup(drm_device_t * dev)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
 
 
@@ -214,140 +215,144 @@ static int i830_dma_cleanup(drm_device_t *dev)
 	 * may not have been called from userspace and after dev_private
 	 * may not have been called from userspace and after dev_private
 	 * is freed, it's too late.
 	 * is freed, it's too late.
 	 */
 	 */
-	if ( dev->irq_enabled ) drm_irq_uninstall(dev);
+	if (dev->irq_enabled)
+		drm_irq_uninstall(dev);
 
 
 	if (dev->dev_private) {
 	if (dev->dev_private) {
 		int i;
 		int i;
-	   	drm_i830_private_t *dev_priv = 
-	     		(drm_i830_private_t *) dev->dev_private;
-	   
-	   	if (dev_priv->ring.virtual_start) {
-		   	drm_ioremapfree((void *) dev_priv->ring.virtual_start,
-					 dev_priv->ring.Size, dev);
+		drm_i830_private_t *dev_priv =
+		    (drm_i830_private_t *) dev->dev_private;
+
+		if (dev_priv->ring.virtual_start) {
+			drm_ioremapfree((void *)dev_priv->ring.virtual_start,
+					dev_priv->ring.Size, dev);
 		}
 		}
-	   	if (dev_priv->hw_status_page) {
+		if (dev_priv->hw_status_page) {
 			pci_free_consistent(dev->pdev, PAGE_SIZE,
 			pci_free_consistent(dev->pdev, PAGE_SIZE,
 					    dev_priv->hw_status_page,
 					    dev_priv->hw_status_page,
 					    dev_priv->dma_status_page);
 					    dev_priv->dma_status_page);
-		   	/* Need to rewrite hardware status page */
-		   	I830_WRITE(0x02080, 0x1ffff000);
+			/* Need to rewrite hardware status page */
+			I830_WRITE(0x02080, 0x1ffff000);
 		}
 		}
 
 
-	   	drm_free(dev->dev_private, sizeof(drm_i830_private_t), 
+		drm_free(dev->dev_private, sizeof(drm_i830_private_t),
 			 DRM_MEM_DRIVER);
 			 DRM_MEM_DRIVER);
-	   	dev->dev_private = NULL;
+		dev->dev_private = NULL;
 
 
 		for (i = 0; i < dma->buf_count; i++) {
 		for (i = 0; i < dma->buf_count; i++) {
-			drm_buf_t *buf = dma->buflist[ i ];
+			drm_buf_t *buf = dma->buflist[i];
 			drm_i830_buf_priv_t *buf_priv = buf->dev_private;
 			drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-			if ( buf_priv->kernel_virtual && buf->total )
-				drm_ioremapfree(buf_priv->kernel_virtual, buf->total, dev);
+			if (buf_priv->kernel_virtual && buf->total)
+				drm_ioremapfree(buf_priv->kernel_virtual,
+						buf->total, dev);
 		}
 		}
 	}
 	}
-   	return 0;
+	return 0;
 }
 }
 
 
-int i830_wait_ring(drm_device_t *dev, int n, const char *caller)
+int i830_wait_ring(drm_device_t * dev, int n, const char *caller)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
-   	drm_i830_ring_buffer_t *ring = &(dev_priv->ring);
-   	int iters = 0;
-   	unsigned long end;
+	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_ring_buffer_t *ring = &(dev_priv->ring);
+	int iters = 0;
+	unsigned long end;
 	unsigned int last_head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
 	unsigned int last_head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
 
 
-	end = jiffies + (HZ*3);
-   	while (ring->space < n) {	
-	   	ring->head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-	   	ring->space = ring->head - (ring->tail+8);
-		if (ring->space < 0) ring->space += ring->Size;
-	   
+	end = jiffies + (HZ * 3);
+	while (ring->space < n) {
+		ring->head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+		ring->space = ring->head - (ring->tail + 8);
+		if (ring->space < 0)
+			ring->space += ring->Size;
+
 		if (ring->head != last_head) {
 		if (ring->head != last_head) {
-			end = jiffies + (HZ*3);
+			end = jiffies + (HZ * 3);
 			last_head = ring->head;
 			last_head = ring->head;
 		}
 		}
-	  
-	   	iters++;
-		if(time_before(end, jiffies)) {
-		   	DRM_ERROR("space: %d wanted %d\n", ring->space, n);
-		   	DRM_ERROR("lockup\n");
-		   	goto out_wait_ring;
+
+		iters++;
+		if (time_before(end, jiffies)) {
+			DRM_ERROR("space: %d wanted %d\n", ring->space, n);
+			DRM_ERROR("lockup\n");
+			goto out_wait_ring;
 		}
 		}
 		udelay(1);
 		udelay(1);
 		dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
 		dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
 	}
 	}
 
 
-out_wait_ring:   
-   	return iters;
+      out_wait_ring:
+	return iters;
 }
 }
 
 
-static void i830_kernel_lost_context(drm_device_t *dev)
+static void i830_kernel_lost_context(drm_device_t * dev)
 {
 {
-      	drm_i830_private_t *dev_priv = dev->dev_private;
-   	drm_i830_ring_buffer_t *ring = &(dev_priv->ring);
-      
-   	ring->head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-     	ring->tail = I830_READ(LP_RING + RING_TAIL) & TAIL_ADDR;
-     	ring->space = ring->head - (ring->tail+8);
-     	if (ring->space < 0) ring->space += ring->Size;
+	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_ring_buffer_t *ring = &(dev_priv->ring);
+
+	ring->head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+	ring->tail = I830_READ(LP_RING + RING_TAIL) & TAIL_ADDR;
+	ring->space = ring->head - (ring->tail + 8);
+	if (ring->space < 0)
+		ring->space += ring->Size;
 
 
 	if (ring->head == ring->tail)
 	if (ring->head == ring->tail)
 		dev_priv->sarea_priv->perf_boxes |= I830_BOX_RING_EMPTY;
 		dev_priv->sarea_priv->perf_boxes |= I830_BOX_RING_EMPTY;
 }
 }
 
 
-static int i830_freelist_init(drm_device_t *dev, drm_i830_private_t *dev_priv)
+static int i830_freelist_init(drm_device_t * dev, drm_i830_private_t * dev_priv)
 {
 {
-      	drm_device_dma_t *dma = dev->dma;
-   	int my_idx = 36;
-   	u32 *hw_status = (u32 *)(dev_priv->hw_status_page + my_idx);
-   	int i;
-
-   	if(dma->buf_count > 1019) {
-	   	/* Not enough space in the status page for the freelist */
-	   	return -EINVAL;
+	drm_device_dma_t *dma = dev->dma;
+	int my_idx = 36;
+	u32 *hw_status = (u32 *) (dev_priv->hw_status_page + my_idx);
+	int i;
+
+	if (dma->buf_count > 1019) {
+		/* Not enough space in the status page for the freelist */
+		return -EINVAL;
 	}
 	}
 
 
-   	for (i = 0; i < dma->buf_count; i++) {
-	   	drm_buf_t *buf = dma->buflist[ i ];
-	   	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+	for (i = 0; i < dma->buf_count; i++) {
+		drm_buf_t *buf = dma->buflist[i];
+		drm_i830_buf_priv_t *buf_priv = buf->dev_private;
 
 
-	   	buf_priv->in_use = hw_status++;
-	   	buf_priv->my_use_idx = my_idx;
-	   	my_idx += 4;
+		buf_priv->in_use = hw_status++;
+		buf_priv->my_use_idx = my_idx;
+		my_idx += 4;
 
 
-	   	*buf_priv->in_use = I830_BUF_FREE;
+		*buf_priv->in_use = I830_BUF_FREE;
 
 
-		buf_priv->kernel_virtual = drm_ioremap(buf->bus_address, 
-							buf->total, dev);
+		buf_priv->kernel_virtual = drm_ioremap(buf->bus_address,
+						       buf->total, dev);
 	}
 	}
 	return 0;
 	return 0;
 }
 }
 
 
-static int i830_dma_initialize(drm_device_t *dev, 
-			       drm_i830_private_t *dev_priv,
-			       drm_i830_init_t *init)
+static int i830_dma_initialize(drm_device_t * dev,
+			       drm_i830_private_t * dev_priv,
+			       drm_i830_init_t * init)
 {
 {
 	struct list_head *list;
 	struct list_head *list;
 
 
-   	memset(dev_priv, 0, sizeof(drm_i830_private_t));
+	memset(dev_priv, 0, sizeof(drm_i830_private_t));
 
 
 	list_for_each(list, &dev->maplist->head) {
 	list_for_each(list, &dev->maplist->head) {
 		drm_map_list_t *r_list = list_entry(list, drm_map_list_t, head);
 		drm_map_list_t *r_list = list_entry(list, drm_map_list_t, head);
-		if( r_list->map &&
+		if (r_list->map &&
 		    r_list->map->type == _DRM_SHM &&
 		    r_list->map->type == _DRM_SHM &&
-		    r_list->map->flags & _DRM_CONTAINS_LOCK ) {
+		    r_list->map->flags & _DRM_CONTAINS_LOCK) {
 			dev_priv->sarea_map = r_list->map;
 			dev_priv->sarea_map = r_list->map;
- 			break;
- 		}
- 	}
+			break;
+		}
+	}
 
 
-	if(!dev_priv->sarea_map) {
+	if (!dev_priv->sarea_map) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
 		i830_dma_cleanup(dev);
 		i830_dma_cleanup(dev);
 		DRM_ERROR("can not find sarea!\n");
 		DRM_ERROR("can not find sarea!\n");
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 	dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
 	dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
-	if(!dev_priv->mmio_map) {
+	if (!dev_priv->mmio_map) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
 		i830_dma_cleanup(dev);
 		i830_dma_cleanup(dev);
 		DRM_ERROR("can not find mmio map!\n");
 		DRM_ERROR("can not find mmio map!\n");
@@ -355,7 +360,7 @@ static int i830_dma_initialize(drm_device_t *dev,
 	}
 	}
 	dev->agp_buffer_token = init->buffers_offset;
 	dev->agp_buffer_token = init->buffers_offset;
 	dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
 	dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
-	if(!dev->agp_buffer_map) {
+	if (!dev->agp_buffer_map) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
 		i830_dma_cleanup(dev);
 		i830_dma_cleanup(dev);
 		DRM_ERROR("can not find dma buffer map!\n");
 		DRM_ERROR("can not find dma buffer map!\n");
@@ -363,27 +368,26 @@ static int i830_dma_initialize(drm_device_t *dev,
 	}
 	}
 
 
 	dev_priv->sarea_priv = (drm_i830_sarea_t *)
 	dev_priv->sarea_priv = (drm_i830_sarea_t *)
-		((u8 *)dev_priv->sarea_map->handle +
-		 init->sarea_priv_offset);
+	    ((u8 *) dev_priv->sarea_map->handle + init->sarea_priv_offset);
 
 
-   	dev_priv->ring.Start = init->ring_start;
-   	dev_priv->ring.End = init->ring_end;
-   	dev_priv->ring.Size = init->ring_size;
+	dev_priv->ring.Start = init->ring_start;
+	dev_priv->ring.End = init->ring_end;
+	dev_priv->ring.Size = init->ring_size;
 
 
-   	dev_priv->ring.virtual_start = drm_ioremap(dev->agp->base + 
-						    init->ring_start, 
-						    init->ring_size, dev);
+	dev_priv->ring.virtual_start = drm_ioremap(dev->agp->base +
+						   init->ring_start,
+						   init->ring_size, dev);
 
 
-   	if (dev_priv->ring.virtual_start == NULL) {
-		dev->dev_private = (void *) dev_priv;
-	   	i830_dma_cleanup(dev);
-	   	DRM_ERROR("can not ioremap virtual address for"
+	if (dev_priv->ring.virtual_start == NULL) {
+		dev->dev_private = (void *)dev_priv;
+		i830_dma_cleanup(dev);
+		DRM_ERROR("can not ioremap virtual address for"
 			  " ring buffer\n");
 			  " ring buffer\n");
-	   	return -ENOMEM;
+		return -ENOMEM;
 	}
 	}
 
 
-   	dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
-   
+	dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
+
 	dev_priv->w = init->w;
 	dev_priv->w = init->w;
 	dev_priv->h = init->h;
 	dev_priv->h = init->h;
 	dev_priv->pitch = init->pitch;
 	dev_priv->pitch = init->pitch;
@@ -395,10 +399,10 @@ static int i830_dma_initialize(drm_device_t *dev,
 	dev_priv->back_di1 = init->back_offset | init->pitch_bits;
 	dev_priv->back_di1 = init->back_offset | init->pitch_bits;
 	dev_priv->zi1 = init->depth_offset | init->pitch_bits;
 	dev_priv->zi1 = init->depth_offset | init->pitch_bits;
 
 
-	DRM_DEBUG("front_di1 %x\n",    dev_priv->front_di1);
+	DRM_DEBUG("front_di1 %x\n", dev_priv->front_di1);
 	DRM_DEBUG("back_offset %x\n", dev_priv->back_offset);
 	DRM_DEBUG("back_offset %x\n", dev_priv->back_offset);
-	DRM_DEBUG("back_di1 %x\n",    dev_priv->back_di1);
-	DRM_DEBUG("pitch_bits %x\n",    init->pitch_bits);
+	DRM_DEBUG("back_di1 %x\n", dev_priv->back_di1);
+	DRM_DEBUG("pitch_bits %x\n", init->pitch_bits);
 
 
 	dev_priv->cpp = init->cpp;
 	dev_priv->cpp = init->cpp;
 	/* We are using separate values as placeholders for mechanisms for
 	/* We are using separate values as placeholders for mechanisms for
@@ -410,63 +414,64 @@ static int i830_dma_initialize(drm_device_t *dev,
 	dev_priv->do_boxes = 0;
 	dev_priv->do_boxes = 0;
 	dev_priv->use_mi_batchbuffer_start = 0;
 	dev_priv->use_mi_batchbuffer_start = 0;
 
 
-   	/* Program Hardware Status Page */
-   	dev_priv->hw_status_page =
-		pci_alloc_consistent(dev->pdev, PAGE_SIZE,
-						&dev_priv->dma_status_page);
-   	if (!dev_priv->hw_status_page) {
+	/* Program Hardware Status Page */
+	dev_priv->hw_status_page =
+	    pci_alloc_consistent(dev->pdev, PAGE_SIZE,
+				 &dev_priv->dma_status_page);
+	if (!dev_priv->hw_status_page) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
 		i830_dma_cleanup(dev);
 		i830_dma_cleanup(dev);
 		DRM_ERROR("Can not allocate hardware status page\n");
 		DRM_ERROR("Can not allocate hardware status page\n");
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
-   	memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
+	memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
 	DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
 	DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
-   
-   	I830_WRITE(0x02080, dev_priv->dma_status_page);
+
+	I830_WRITE(0x02080, dev_priv->dma_status_page);
 	DRM_DEBUG("Enabled hardware status page\n");
 	DRM_DEBUG("Enabled hardware status page\n");
-   
-   	/* Now we need to init our freelist */
-   	if(i830_freelist_init(dev, dev_priv) != 0) {
+
+	/* Now we need to init our freelist */
+	if (i830_freelist_init(dev, dev_priv) != 0) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
-	   	i830_dma_cleanup(dev);
-	   	DRM_ERROR("Not enough space in the status page for"
+		i830_dma_cleanup(dev);
+		DRM_ERROR("Not enough space in the status page for"
 			  " the freelist\n");
 			  " the freelist\n");
-	   	return -ENOMEM;
+		return -ENOMEM;
 	}
 	}
 	dev->dev_private = (void *)dev_priv;
 	dev->dev_private = (void *)dev_priv;
 
 
-   	return 0;
+	return 0;
 }
 }
 
 
 static int i830_dma_init(struct inode *inode, struct file *filp,
 static int i830_dma_init(struct inode *inode, struct file *filp,
-		  unsigned int cmd, unsigned long arg)
+			 unsigned int cmd, unsigned long arg)
 {
 {
-   	drm_file_t *priv = filp->private_data;
-   	drm_device_t *dev = priv->head->dev;
-   	drm_i830_private_t *dev_priv;
-   	drm_i830_init_t init;
-   	int retcode = 0;
-	
-  	if (copy_from_user(&init, (void * __user) arg, sizeof(init)))
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_i830_private_t *dev_priv;
+	drm_i830_init_t init;
+	int retcode = 0;
+
+	if (copy_from_user(&init, (void *__user)arg, sizeof(init)))
 		return -EFAULT;
 		return -EFAULT;
-	
-   	switch(init.func) {
-	 	case I830_INIT_DMA:
-			dev_priv = drm_alloc(sizeof(drm_i830_private_t), 
-					      DRM_MEM_DRIVER);
-	   		if(dev_priv == NULL) return -ENOMEM;
-	   		retcode = i830_dma_initialize(dev, dev_priv, &init);
-	   	break;
-	 	case I830_CLEANUP_DMA:
-	   		retcode = i830_dma_cleanup(dev);
-	   	break;
-	 	default:
-	   		retcode = -EINVAL;
-	   	break;
+
+	switch (init.func) {
+	case I830_INIT_DMA:
+		dev_priv = drm_alloc(sizeof(drm_i830_private_t),
+				     DRM_MEM_DRIVER);
+		if (dev_priv == NULL)
+			return -ENOMEM;
+		retcode = i830_dma_initialize(dev, dev_priv, &init);
+		break;
+	case I830_CLEANUP_DMA:
+		retcode = i830_dma_cleanup(dev);
+		break;
+	default:
+		retcode = -EINVAL;
+		break;
 	}
 	}
-   
-   	return retcode;
+
+	return retcode;
 }
 }
 
 
 #define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
 #define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
@@ -476,92 +481,89 @@ static int i830_dma_init(struct inode *inode, struct file *filp,
 /* Most efficient way to verify state for the i830 is as it is
 /* Most efficient way to verify state for the i830 is as it is
  * emitted.  Non-conformant state is silently dropped.
  * emitted.  Non-conformant state is silently dropped.
  */
  */
-static void i830EmitContextVerified( drm_device_t *dev,
-				     unsigned int *code )
+static void i830EmitContextVerified(drm_device_t * dev, unsigned int *code)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_private_t *dev_priv = dev->dev_private;
 	int i, j = 0;
 	int i, j = 0;
 	unsigned int tmp;
 	unsigned int tmp;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
-	BEGIN_LP_RING( I830_CTX_SETUP_SIZE + 4 );
+	BEGIN_LP_RING(I830_CTX_SETUP_SIZE + 4);
 
 
-	for ( i = 0 ; i < I830_CTXREG_BLENDCOLR0 ; i++ ) {
+	for (i = 0; i < I830_CTXREG_BLENDCOLR0; i++) {
 		tmp = code[i];
 		tmp = code[i];
-		if ((tmp & (7<<29)) == CMD_3D &&
-		    (tmp & (0x1f<<24)) < (0x1d<<24)) {
-			OUT_RING( tmp ); 
+		if ((tmp & (7 << 29)) == CMD_3D &&
+		    (tmp & (0x1f << 24)) < (0x1d << 24)) {
+			OUT_RING(tmp);
 			j++;
 			j++;
 		} else {
 		} else {
 			DRM_ERROR("Skipping %d\n", i);
 			DRM_ERROR("Skipping %d\n", i);
 		}
 		}
 	}
 	}
 
 
-	OUT_RING( STATE3D_CONST_BLEND_COLOR_CMD ); 
-	OUT_RING( code[I830_CTXREG_BLENDCOLR] ); 
+	OUT_RING(STATE3D_CONST_BLEND_COLOR_CMD);
+	OUT_RING(code[I830_CTXREG_BLENDCOLR]);
 	j += 2;
 	j += 2;
 
 
-	for ( i = I830_CTXREG_VF ; i < I830_CTXREG_MCSB0 ; i++ ) {
+	for (i = I830_CTXREG_VF; i < I830_CTXREG_MCSB0; i++) {
 		tmp = code[i];
 		tmp = code[i];
-		if ((tmp & (7<<29)) == CMD_3D &&
-		    (tmp & (0x1f<<24)) < (0x1d<<24)) {
-			OUT_RING( tmp ); 
+		if ((tmp & (7 << 29)) == CMD_3D &&
+		    (tmp & (0x1f << 24)) < (0x1d << 24)) {
+			OUT_RING(tmp);
 			j++;
 			j++;
 		} else {
 		} else {
 			DRM_ERROR("Skipping %d\n", i);
 			DRM_ERROR("Skipping %d\n", i);
 		}
 		}
 	}
 	}
 
 
-	OUT_RING( STATE3D_MAP_COORD_SETBIND_CMD ); 
-	OUT_RING( code[I830_CTXREG_MCSB1] ); 
+	OUT_RING(STATE3D_MAP_COORD_SETBIND_CMD);
+	OUT_RING(code[I830_CTXREG_MCSB1]);
 	j += 2;
 	j += 2;
 
 
-	if (j & 1) 
-		OUT_RING( 0 ); 
+	if (j & 1)
+		OUT_RING(0);
 
 
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 }
 }
 
 
-static void i830EmitTexVerified( drm_device_t *dev, unsigned int *code ) 
+static void i830EmitTexVerified(drm_device_t * dev, unsigned int *code)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_private_t *dev_priv = dev->dev_private;
 	int i, j = 0;
 	int i, j = 0;
 	unsigned int tmp;
 	unsigned int tmp;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
 	if (code[I830_TEXREG_MI0] == GFX_OP_MAP_INFO ||
 	if (code[I830_TEXREG_MI0] == GFX_OP_MAP_INFO ||
-	    (code[I830_TEXREG_MI0] & ~(0xf*LOAD_TEXTURE_MAP0)) == 
-	    (STATE3D_LOAD_STATE_IMMEDIATE_2|4)) {
-
-		BEGIN_LP_RING( I830_TEX_SETUP_SIZE );
-
-		OUT_RING( code[I830_TEXREG_MI0] ); /* TM0LI */
-		OUT_RING( code[I830_TEXREG_MI1] ); /* TM0S0 */
-		OUT_RING( code[I830_TEXREG_MI2] ); /* TM0S1 */
-		OUT_RING( code[I830_TEXREG_MI3] ); /* TM0S2 */
-		OUT_RING( code[I830_TEXREG_MI4] ); /* TM0S3 */
-		OUT_RING( code[I830_TEXREG_MI5] ); /* TM0S4 */
-		
-		for ( i = 6 ; i < I830_TEX_SETUP_SIZE ; i++ ) {
+	    (code[I830_TEXREG_MI0] & ~(0xf * LOAD_TEXTURE_MAP0)) ==
+	    (STATE3D_LOAD_STATE_IMMEDIATE_2 | 4)) {
+
+		BEGIN_LP_RING(I830_TEX_SETUP_SIZE);
+
+		OUT_RING(code[I830_TEXREG_MI0]);	/* TM0LI */
+		OUT_RING(code[I830_TEXREG_MI1]);	/* TM0S0 */
+		OUT_RING(code[I830_TEXREG_MI2]);	/* TM0S1 */
+		OUT_RING(code[I830_TEXREG_MI3]);	/* TM0S2 */
+		OUT_RING(code[I830_TEXREG_MI4]);	/* TM0S3 */
+		OUT_RING(code[I830_TEXREG_MI5]);	/* TM0S4 */
+
+		for (i = 6; i < I830_TEX_SETUP_SIZE; i++) {
 			tmp = code[i];
 			tmp = code[i];
-			OUT_RING( tmp ); 
+			OUT_RING(tmp);
 			j++;
 			j++;
-		} 
+		}
 
 
-		if (j & 1) 
-			OUT_RING( 0 ); 
+		if (j & 1)
+			OUT_RING(0);
 
 
 		ADVANCE_LP_RING();
 		ADVANCE_LP_RING();
-	}
-	else
+	} else
 		printk("rejected packet %x\n", code[0]);
 		printk("rejected packet %x\n", code[0]);
 }
 }
 
 
-static void i830EmitTexBlendVerified( drm_device_t *dev, 
-				      unsigned int *code,
-				      unsigned int num)
+static void i830EmitTexBlendVerified(drm_device_t * dev,
+				     unsigned int *code, unsigned int num)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_private_t *dev_priv = dev->dev_private;
 	int i, j = 0;
 	int i, j = 0;
 	unsigned int tmp;
 	unsigned int tmp;
 	RING_LOCALS;
 	RING_LOCALS;
@@ -569,59 +571,54 @@ static void i830EmitTexBlendVerified( drm_device_t *dev,
 	if (!num)
 	if (!num)
 		return;
 		return;
 
 
-	BEGIN_LP_RING( num + 1 );
+	BEGIN_LP_RING(num + 1);
 
 
-	for ( i = 0 ; i < num ; i++ ) {
+	for (i = 0; i < num; i++) {
 		tmp = code[i];
 		tmp = code[i];
-		OUT_RING( tmp );
+		OUT_RING(tmp);
 		j++;
 		j++;
 	}
 	}
 
 
-	if (j & 1) 
-		OUT_RING( 0 ); 
+	if (j & 1)
+		OUT_RING(0);
 
 
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 }
 }
 
 
-static void i830EmitTexPalette( drm_device_t *dev,
-			        unsigned int *palette,
-			        int number,
-			        int is_shared )
+static void i830EmitTexPalette(drm_device_t * dev,
+			       unsigned int *palette, int number, int is_shared)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_private_t *dev_priv = dev->dev_private;
 	int i;
 	int i;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
 	return;
 	return;
 
 
-	BEGIN_LP_RING( 258 );
+	BEGIN_LP_RING(258);
 
 
-	if(is_shared == 1) {
+	if (is_shared == 1) {
 		OUT_RING(CMD_OP_MAP_PALETTE_LOAD |
 		OUT_RING(CMD_OP_MAP_PALETTE_LOAD |
-			 MAP_PALETTE_NUM(0) |
-			 MAP_PALETTE_BOTH);
+			 MAP_PALETTE_NUM(0) | MAP_PALETTE_BOTH);
 	} else {
 	} else {
 		OUT_RING(CMD_OP_MAP_PALETTE_LOAD | MAP_PALETTE_NUM(number));
 		OUT_RING(CMD_OP_MAP_PALETTE_LOAD | MAP_PALETTE_NUM(number));
 	}
 	}
-	for(i = 0; i < 256; i++) {
+	for (i = 0; i < 256; i++) {
 		OUT_RING(palette[i]);
 		OUT_RING(palette[i]);
 	}
 	}
 	OUT_RING(0);
 	OUT_RING(0);
-	/* KW:  WHERE IS THE ADVANCE_LP_RING?  This is effectively a noop! 
+	/* KW:  WHERE IS THE ADVANCE_LP_RING?  This is effectively a noop!
 	 */
 	 */
 }
 }
 
 
 /* Need to do some additional checking when setting the dest buffer.
 /* Need to do some additional checking when setting the dest buffer.
  */
  */
-static void i830EmitDestVerified( drm_device_t *dev, 
-				  unsigned int *code ) 
-{	
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+static void i830EmitDestVerified(drm_device_t * dev, unsigned int *code)
+{
+	drm_i830_private_t *dev_priv = dev->dev_private;
 	unsigned int tmp;
 	unsigned int tmp;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
-	BEGIN_LP_RING( I830_DEST_SETUP_SIZE + 10 );
-
+	BEGIN_LP_RING(I830_DEST_SETUP_SIZE + 10);
 
 
 	tmp = code[I830_DESTREG_CBUFADDR];
 	tmp = code[I830_DESTREG_CBUFADDR];
 	if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) {
 	if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) {
@@ -630,18 +627,18 @@ static void i830EmitDestVerified( drm_device_t *dev,
 			OUT_RING(0);
 			OUT_RING(0);
 		}
 		}
 
 
-		OUT_RING( CMD_OP_DESTBUFFER_INFO );
-		OUT_RING( BUF_3D_ID_COLOR_BACK | 
-			  BUF_3D_PITCH(dev_priv->back_pitch * dev_priv->cpp) |
-			  BUF_3D_USE_FENCE);
-		OUT_RING( tmp );
-		OUT_RING( 0 );
-
-		OUT_RING( CMD_OP_DESTBUFFER_INFO );
-		OUT_RING( BUF_3D_ID_DEPTH | BUF_3D_USE_FENCE | 
-			  BUF_3D_PITCH(dev_priv->depth_pitch * dev_priv->cpp));
-		OUT_RING( dev_priv->zi1 );
-		OUT_RING( 0 );
+		OUT_RING(CMD_OP_DESTBUFFER_INFO);
+		OUT_RING(BUF_3D_ID_COLOR_BACK |
+			 BUF_3D_PITCH(dev_priv->back_pitch * dev_priv->cpp) |
+			 BUF_3D_USE_FENCE);
+		OUT_RING(tmp);
+		OUT_RING(0);
+
+		OUT_RING(CMD_OP_DESTBUFFER_INFO);
+		OUT_RING(BUF_3D_ID_DEPTH | BUF_3D_USE_FENCE |
+			 BUF_3D_PITCH(dev_priv->depth_pitch * dev_priv->cpp));
+		OUT_RING(dev_priv->zi1);
+		OUT_RING(0);
 	} else {
 	} else {
 		DRM_ERROR("bad di1 %x (allow %x or %x)\n",
 		DRM_ERROR("bad di1 %x (allow %x or %x)\n",
 			  tmp, dev_priv->front_di1, dev_priv->back_di1);
 			  tmp, dev_priv->front_di1, dev_priv->back_di1);
@@ -650,83 +647,80 @@ static void i830EmitDestVerified( drm_device_t *dev,
 	/* invarient:
 	/* invarient:
 	 */
 	 */
 
 
+	OUT_RING(GFX_OP_DESTBUFFER_VARS);
+	OUT_RING(code[I830_DESTREG_DV1]);
 
 
-	OUT_RING( GFX_OP_DESTBUFFER_VARS );
-	OUT_RING( code[I830_DESTREG_DV1] );
-
-	OUT_RING( GFX_OP_DRAWRECT_INFO );
-	OUT_RING( code[I830_DESTREG_DR1] );
-	OUT_RING( code[I830_DESTREG_DR2] );
-	OUT_RING( code[I830_DESTREG_DR3] );
-	OUT_RING( code[I830_DESTREG_DR4] );
+	OUT_RING(GFX_OP_DRAWRECT_INFO);
+	OUT_RING(code[I830_DESTREG_DR1]);
+	OUT_RING(code[I830_DESTREG_DR2]);
+	OUT_RING(code[I830_DESTREG_DR3]);
+	OUT_RING(code[I830_DESTREG_DR4]);
 
 
 	/* Need to verify this */
 	/* Need to verify this */
 	tmp = code[I830_DESTREG_SENABLE];
 	tmp = code[I830_DESTREG_SENABLE];
-	if((tmp & ~0x3) == GFX_OP_SCISSOR_ENABLE) {
-		OUT_RING( tmp );
+	if ((tmp & ~0x3) == GFX_OP_SCISSOR_ENABLE) {
+		OUT_RING(tmp);
 	} else {
 	} else {
 		DRM_ERROR("bad scissor enable\n");
 		DRM_ERROR("bad scissor enable\n");
-		OUT_RING( 0 );
+		OUT_RING(0);
 	}
 	}
 
 
-	OUT_RING( GFX_OP_SCISSOR_RECT );
-	OUT_RING( code[I830_DESTREG_SR1] );
-	OUT_RING( code[I830_DESTREG_SR2] );
-	OUT_RING( 0 );
+	OUT_RING(GFX_OP_SCISSOR_RECT);
+	OUT_RING(code[I830_DESTREG_SR1]);
+	OUT_RING(code[I830_DESTREG_SR2]);
+	OUT_RING(0);
 
 
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 }
 }
 
 
-static void i830EmitStippleVerified( drm_device_t *dev, 
-				     unsigned int *code ) 
+static void i830EmitStippleVerified(drm_device_t * dev, unsigned int *code)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_private_t *dev_priv = dev->dev_private;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
-	BEGIN_LP_RING( 2 );
-	OUT_RING( GFX_OP_STIPPLE );
-	OUT_RING( code[1] );
-	ADVANCE_LP_RING();	
+	BEGIN_LP_RING(2);
+	OUT_RING(GFX_OP_STIPPLE);
+	OUT_RING(code[1]);
+	ADVANCE_LP_RING();
 }
 }
 
 
-
-static void i830EmitState( drm_device_t *dev )
+static void i830EmitState(drm_device_t * dev)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
-      	drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
+	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
 	unsigned int dirty = sarea_priv->dirty;
 	unsigned int dirty = sarea_priv->dirty;
 
 
 	DRM_DEBUG("%s %x\n", __FUNCTION__, dirty);
 	DRM_DEBUG("%s %x\n", __FUNCTION__, dirty);
 
 
 	if (dirty & I830_UPLOAD_BUFFERS) {
 	if (dirty & I830_UPLOAD_BUFFERS) {
-		i830EmitDestVerified( dev, sarea_priv->BufferState );
+		i830EmitDestVerified(dev, sarea_priv->BufferState);
 		sarea_priv->dirty &= ~I830_UPLOAD_BUFFERS;
 		sarea_priv->dirty &= ~I830_UPLOAD_BUFFERS;
 	}
 	}
 
 
 	if (dirty & I830_UPLOAD_CTX) {
 	if (dirty & I830_UPLOAD_CTX) {
-		i830EmitContextVerified( dev, sarea_priv->ContextState );
+		i830EmitContextVerified(dev, sarea_priv->ContextState);
 		sarea_priv->dirty &= ~I830_UPLOAD_CTX;
 		sarea_priv->dirty &= ~I830_UPLOAD_CTX;
 	}
 	}
 
 
 	if (dirty & I830_UPLOAD_TEX0) {
 	if (dirty & I830_UPLOAD_TEX0) {
-		i830EmitTexVerified( dev, sarea_priv->TexState[0] );
+		i830EmitTexVerified(dev, sarea_priv->TexState[0]);
 		sarea_priv->dirty &= ~I830_UPLOAD_TEX0;
 		sarea_priv->dirty &= ~I830_UPLOAD_TEX0;
 	}
 	}
 
 
 	if (dirty & I830_UPLOAD_TEX1) {
 	if (dirty & I830_UPLOAD_TEX1) {
-		i830EmitTexVerified( dev, sarea_priv->TexState[1] );
+		i830EmitTexVerified(dev, sarea_priv->TexState[1]);
 		sarea_priv->dirty &= ~I830_UPLOAD_TEX1;
 		sarea_priv->dirty &= ~I830_UPLOAD_TEX1;
 	}
 	}
 
 
 	if (dirty & I830_UPLOAD_TEXBLEND0) {
 	if (dirty & I830_UPLOAD_TEXBLEND0) {
-		i830EmitTexBlendVerified( dev, sarea_priv->TexBlendState[0],
-				sarea_priv->TexBlendStateWordsUsed[0]);
+		i830EmitTexBlendVerified(dev, sarea_priv->TexBlendState[0],
+					 sarea_priv->TexBlendStateWordsUsed[0]);
 		sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND0;
 		sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND0;
 	}
 	}
 
 
 	if (dirty & I830_UPLOAD_TEXBLEND1) {
 	if (dirty & I830_UPLOAD_TEXBLEND1) {
-		i830EmitTexBlendVerified( dev, sarea_priv->TexBlendState[1],
-				sarea_priv->TexBlendStateWordsUsed[1]);
+		i830EmitTexBlendVerified(dev, sarea_priv->TexBlendState[1],
+					 sarea_priv->TexBlendStateWordsUsed[1]);
 		sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND1;
 		sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND1;
 	}
 	}
 
 
@@ -759,36 +753,32 @@ static void i830EmitState( drm_device_t *dev )
 	/* 1.3:
 	/* 1.3:
 	 */
 	 */
 	if (dirty & I830_UPLOAD_STIPPLE) {
 	if (dirty & I830_UPLOAD_STIPPLE) {
-		i830EmitStippleVerified( dev, 
-					 sarea_priv->StippleState);
+		i830EmitStippleVerified(dev, sarea_priv->StippleState);
 		sarea_priv->dirty &= ~I830_UPLOAD_STIPPLE;
 		sarea_priv->dirty &= ~I830_UPLOAD_STIPPLE;
 	}
 	}
 
 
 	if (dirty & I830_UPLOAD_TEX2) {
 	if (dirty & I830_UPLOAD_TEX2) {
-		i830EmitTexVerified( dev, sarea_priv->TexState2 );
+		i830EmitTexVerified(dev, sarea_priv->TexState2);
 		sarea_priv->dirty &= ~I830_UPLOAD_TEX2;
 		sarea_priv->dirty &= ~I830_UPLOAD_TEX2;
 	}
 	}
 
 
 	if (dirty & I830_UPLOAD_TEX3) {
 	if (dirty & I830_UPLOAD_TEX3) {
-		i830EmitTexVerified( dev, sarea_priv->TexState3 );
+		i830EmitTexVerified(dev, sarea_priv->TexState3);
 		sarea_priv->dirty &= ~I830_UPLOAD_TEX3;
 		sarea_priv->dirty &= ~I830_UPLOAD_TEX3;
 	}
 	}
 
 
-
 	if (dirty & I830_UPLOAD_TEXBLEND2) {
 	if (dirty & I830_UPLOAD_TEXBLEND2) {
-		i830EmitTexBlendVerified( 
-			dev, 
-			sarea_priv->TexBlendState2,
-			sarea_priv->TexBlendStateWordsUsed2);
+		i830EmitTexBlendVerified(dev,
+					 sarea_priv->TexBlendState2,
+					 sarea_priv->TexBlendStateWordsUsed2);
 
 
 		sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND2;
 		sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND2;
 	}
 	}
 
 
 	if (dirty & I830_UPLOAD_TEXBLEND3) {
 	if (dirty & I830_UPLOAD_TEXBLEND3) {
-		i830EmitTexBlendVerified( 
-			dev, 
-			sarea_priv->TexBlendState3,
-			sarea_priv->TexBlendStateWordsUsed3);
+		i830EmitTexBlendVerified(dev,
+					 sarea_priv->TexBlendState3,
+					 sarea_priv->TexBlendStateWordsUsed3);
 		sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND3;
 		sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND3;
 	}
 	}
 }
 }
@@ -797,97 +787,96 @@ static void i830EmitState( drm_device_t *dev )
  * Performance monitoring functions
  * Performance monitoring functions
  */
  */
 
 
-static void i830_fill_box( drm_device_t *dev,
-			   int x, int y, int w, int h,
-			   int r, int g, int b )
+static void i830_fill_box(drm_device_t * dev,
+			  int x, int y, int w, int h, int r, int g, int b)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_private_t *dev_priv = dev->dev_private;
 	u32 color;
 	u32 color;
 	unsigned int BR13, CMD;
 	unsigned int BR13, CMD;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
-	BR13 = (0xF0 << 16) | (dev_priv->pitch * dev_priv->cpp) | (1<<24);
+	BR13 = (0xF0 << 16) | (dev_priv->pitch * dev_priv->cpp) | (1 << 24);
 	CMD = XY_COLOR_BLT_CMD;
 	CMD = XY_COLOR_BLT_CMD;
 	x += dev_priv->sarea_priv->boxes[0].x1;
 	x += dev_priv->sarea_priv->boxes[0].x1;
 	y += dev_priv->sarea_priv->boxes[0].y1;
 	y += dev_priv->sarea_priv->boxes[0].y1;
 
 
 	if (dev_priv->cpp == 4) {
 	if (dev_priv->cpp == 4) {
-		BR13 |= (1<<25);
+		BR13 |= (1 << 25);
 		CMD |= (XY_COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB);
 		CMD |= (XY_COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB);
-		color = (((0xff) << 24) | (r << 16) | (g <<  8) | b);	
+		color = (((0xff) << 24) | (r << 16) | (g << 8) | b);
 	} else {
 	} else {
 		color = (((r & 0xf8) << 8) |
 		color = (((r & 0xf8) << 8) |
-			 ((g & 0xfc) << 3) |
-			 ((b & 0xf8) >> 3));
+			 ((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
 	}
 	}
 
 
-	BEGIN_LP_RING( 6 );	    
-	OUT_RING( CMD );
-	OUT_RING( BR13 );
-	OUT_RING( (y << 16) | x );
-	OUT_RING( ((y+h) << 16) | (x+w) );
+	BEGIN_LP_RING(6);
+	OUT_RING(CMD);
+	OUT_RING(BR13);
+	OUT_RING((y << 16) | x);
+	OUT_RING(((y + h) << 16) | (x + w));
 
 
- 	if ( dev_priv->current_page == 1 ) { 
-		OUT_RING( dev_priv->front_offset );
- 	} else {	 
-		OUT_RING( dev_priv->back_offset );
- 	} 
+	if (dev_priv->current_page == 1) {
+		OUT_RING(dev_priv->front_offset);
+	} else {
+		OUT_RING(dev_priv->back_offset);
+	}
 
 
-	OUT_RING( color );
+	OUT_RING(color);
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 }
 }
 
 
-static void i830_cp_performance_boxes( drm_device_t *dev )
+static void i830_cp_performance_boxes(drm_device_t * dev)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_private_t *dev_priv = dev->dev_private;
 
 
 	/* Purple box for page flipping
 	/* Purple box for page flipping
 	 */
 	 */
-	if ( dev_priv->sarea_priv->perf_boxes & I830_BOX_FLIP ) 
-		i830_fill_box( dev, 4, 4, 8, 8, 255, 0, 255 );
+	if (dev_priv->sarea_priv->perf_boxes & I830_BOX_FLIP)
+		i830_fill_box(dev, 4, 4, 8, 8, 255, 0, 255);
 
 
 	/* Red box if we have to wait for idle at any point
 	/* Red box if we have to wait for idle at any point
 	 */
 	 */
-	if ( dev_priv->sarea_priv->perf_boxes & I830_BOX_WAIT ) 
-		i830_fill_box( dev, 16, 4, 8, 8, 255, 0, 0 );
+	if (dev_priv->sarea_priv->perf_boxes & I830_BOX_WAIT)
+		i830_fill_box(dev, 16, 4, 8, 8, 255, 0, 0);
 
 
 	/* Blue box: lost context?
 	/* Blue box: lost context?
 	 */
 	 */
-	if ( dev_priv->sarea_priv->perf_boxes & I830_BOX_LOST_CONTEXT ) 
-		i830_fill_box( dev, 28, 4, 8, 8, 0, 0, 255 );
+	if (dev_priv->sarea_priv->perf_boxes & I830_BOX_LOST_CONTEXT)
+		i830_fill_box(dev, 28, 4, 8, 8, 0, 0, 255);
 
 
 	/* Yellow box for texture swaps
 	/* Yellow box for texture swaps
 	 */
 	 */
-	if ( dev_priv->sarea_priv->perf_boxes & I830_BOX_TEXTURE_LOAD ) 
-		i830_fill_box( dev, 40, 4, 8, 8, 255, 255, 0 );
+	if (dev_priv->sarea_priv->perf_boxes & I830_BOX_TEXTURE_LOAD)
+		i830_fill_box(dev, 40, 4, 8, 8, 255, 255, 0);
 
 
 	/* Green box if hardware never idles (as far as we can tell)
 	/* Green box if hardware never idles (as far as we can tell)
 	 */
 	 */
-	if ( !(dev_priv->sarea_priv->perf_boxes & I830_BOX_RING_EMPTY) ) 
-		i830_fill_box( dev, 64, 4, 8, 8, 0, 255, 0 );
-
+	if (!(dev_priv->sarea_priv->perf_boxes & I830_BOX_RING_EMPTY))
+		i830_fill_box(dev, 64, 4, 8, 8, 0, 255, 0);
 
 
-	/* Draw bars indicating number of buffers allocated 
+	/* Draw bars indicating number of buffers allocated
 	 * (not a great measure, easily confused)
 	 * (not a great measure, easily confused)
 	 */
 	 */
 	if (dev_priv->dma_used) {
 	if (dev_priv->dma_used) {
 		int bar = dev_priv->dma_used / 10240;
 		int bar = dev_priv->dma_used / 10240;
-		if (bar > 100) bar = 100;
-		if (bar < 1) bar = 1;
-		i830_fill_box( dev, 4, 16, bar, 4, 196, 128, 128 );
+		if (bar > 100)
+			bar = 100;
+		if (bar < 1)
+			bar = 1;
+		i830_fill_box(dev, 4, 16, bar, 4, 196, 128, 128);
 		dev_priv->dma_used = 0;
 		dev_priv->dma_used = 0;
 	}
 	}
 
 
 	dev_priv->sarea_priv->perf_boxes = 0;
 	dev_priv->sarea_priv->perf_boxes = 0;
 }
 }
 
 
-static void i830_dma_dispatch_clear( drm_device_t *dev, int flags, 
+static void i830_dma_dispatch_clear(drm_device_t * dev, int flags,
 				    unsigned int clear_color,
 				    unsigned int clear_color,
 				    unsigned int clear_zval,
 				    unsigned int clear_zval,
 				    unsigned int clear_depthmask)
 				    unsigned int clear_depthmask)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
-      	drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
+	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
 	int nbox = sarea_priv->nbox;
 	int nbox = sarea_priv->nbox;
 	drm_clip_rect_t *pbox = sarea_priv->boxes;
 	drm_clip_rect_t *pbox = sarea_priv->boxes;
 	int pitch = dev_priv->pitch;
 	int pitch = dev_priv->pitch;
@@ -896,90 +885,90 @@ static void i830_dma_dispatch_clear( drm_device_t *dev, int flags,
 	unsigned int BR13, CMD, D_CMD;
 	unsigned int BR13, CMD, D_CMD;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
-
-	if ( dev_priv->current_page == 1 ) {
+	if (dev_priv->current_page == 1) {
 		unsigned int tmp = flags;
 		unsigned int tmp = flags;
 
 
 		flags &= ~(I830_FRONT | I830_BACK);
 		flags &= ~(I830_FRONT | I830_BACK);
-		if ( tmp & I830_FRONT ) flags |= I830_BACK;
-		if ( tmp & I830_BACK )  flags |= I830_FRONT;
+		if (tmp & I830_FRONT)
+			flags |= I830_BACK;
+		if (tmp & I830_BACK)
+			flags |= I830_FRONT;
 	}
 	}
 
 
-  	i830_kernel_lost_context(dev);
+	i830_kernel_lost_context(dev);
 
 
-	switch(cpp) {
-	case 2: 
-		BR13 = (0xF0 << 16) | (pitch * cpp) | (1<<24);
+	switch (cpp) {
+	case 2:
+		BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24);
 		D_CMD = CMD = XY_COLOR_BLT_CMD;
 		D_CMD = CMD = XY_COLOR_BLT_CMD;
 		break;
 		break;
 	case 4:
 	case 4:
-		BR13 = (0xF0 << 16) | (pitch * cpp) | (1<<24) | (1<<25);
-		CMD = (XY_COLOR_BLT_CMD | XY_COLOR_BLT_WRITE_ALPHA | 
+		BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24) | (1 << 25);
+		CMD = (XY_COLOR_BLT_CMD | XY_COLOR_BLT_WRITE_ALPHA |
 		       XY_COLOR_BLT_WRITE_RGB);
 		       XY_COLOR_BLT_WRITE_RGB);
 		D_CMD = XY_COLOR_BLT_CMD;
 		D_CMD = XY_COLOR_BLT_CMD;
-		if(clear_depthmask & 0x00ffffff)
+		if (clear_depthmask & 0x00ffffff)
 			D_CMD |= XY_COLOR_BLT_WRITE_RGB;
 			D_CMD |= XY_COLOR_BLT_WRITE_RGB;
-		if(clear_depthmask & 0xff000000)
+		if (clear_depthmask & 0xff000000)
 			D_CMD |= XY_COLOR_BLT_WRITE_ALPHA;
 			D_CMD |= XY_COLOR_BLT_WRITE_ALPHA;
 		break;
 		break;
 	default:
 	default:
-		BR13 = (0xF0 << 16) | (pitch * cpp) | (1<<24);
+		BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24);
 		D_CMD = CMD = XY_COLOR_BLT_CMD;
 		D_CMD = CMD = XY_COLOR_BLT_CMD;
 		break;
 		break;
 	}
 	}
 
 
-      	if (nbox > I830_NR_SAREA_CLIPRECTS)
-     		nbox = I830_NR_SAREA_CLIPRECTS;
+	if (nbox > I830_NR_SAREA_CLIPRECTS)
+		nbox = I830_NR_SAREA_CLIPRECTS;
 
 
-	for (i = 0 ; i < nbox ; i++, pbox++) {
+	for (i = 0; i < nbox; i++, pbox++) {
 		if (pbox->x1 > pbox->x2 ||
 		if (pbox->x1 > pbox->x2 ||
 		    pbox->y1 > pbox->y2 ||
 		    pbox->y1 > pbox->y2 ||
-		    pbox->x2 > dev_priv->w ||
-		    pbox->y2 > dev_priv->h)
+		    pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
 			continue;
 			continue;
 
 
-	   	if ( flags & I830_FRONT ) {	    
-		   	DRM_DEBUG("clear front\n");
-			BEGIN_LP_RING( 6 );	    
-			OUT_RING( CMD );
-			OUT_RING( BR13 );
-			OUT_RING( (pbox->y1 << 16) | pbox->x1 );
-			OUT_RING( (pbox->y2 << 16) | pbox->x2 );
-			OUT_RING( dev_priv->front_offset );
-			OUT_RING( clear_color );
+		if (flags & I830_FRONT) {
+			DRM_DEBUG("clear front\n");
+			BEGIN_LP_RING(6);
+			OUT_RING(CMD);
+			OUT_RING(BR13);
+			OUT_RING((pbox->y1 << 16) | pbox->x1);
+			OUT_RING((pbox->y2 << 16) | pbox->x2);
+			OUT_RING(dev_priv->front_offset);
+			OUT_RING(clear_color);
 			ADVANCE_LP_RING();
 			ADVANCE_LP_RING();
 		}
 		}
 
 
-		if ( flags & I830_BACK ) {
+		if (flags & I830_BACK) {
 			DRM_DEBUG("clear back\n");
 			DRM_DEBUG("clear back\n");
-			BEGIN_LP_RING( 6 );	    
-			OUT_RING( CMD );
-			OUT_RING( BR13 );
-			OUT_RING( (pbox->y1 << 16) | pbox->x1 );
-			OUT_RING( (pbox->y2 << 16) | pbox->x2 );
-			OUT_RING( dev_priv->back_offset );
-			OUT_RING( clear_color );
+			BEGIN_LP_RING(6);
+			OUT_RING(CMD);
+			OUT_RING(BR13);
+			OUT_RING((pbox->y1 << 16) | pbox->x1);
+			OUT_RING((pbox->y2 << 16) | pbox->x2);
+			OUT_RING(dev_priv->back_offset);
+			OUT_RING(clear_color);
 			ADVANCE_LP_RING();
 			ADVANCE_LP_RING();
 		}
 		}
 
 
-		if ( flags & I830_DEPTH ) {
+		if (flags & I830_DEPTH) {
 			DRM_DEBUG("clear depth\n");
 			DRM_DEBUG("clear depth\n");
-			BEGIN_LP_RING( 6 );
-			OUT_RING( D_CMD );
-			OUT_RING( BR13 );
-			OUT_RING( (pbox->y1 << 16) | pbox->x1 );
-			OUT_RING( (pbox->y2 << 16) | pbox->x2 );
-			OUT_RING( dev_priv->depth_offset );
-			OUT_RING( clear_zval );
+			BEGIN_LP_RING(6);
+			OUT_RING(D_CMD);
+			OUT_RING(BR13);
+			OUT_RING((pbox->y1 << 16) | pbox->x1);
+			OUT_RING((pbox->y2 << 16) | pbox->x2);
+			OUT_RING(dev_priv->depth_offset);
+			OUT_RING(clear_zval);
 			ADVANCE_LP_RING();
 			ADVANCE_LP_RING();
 		}
 		}
 	}
 	}
 }
 }
 
 
-static void i830_dma_dispatch_swap( drm_device_t *dev )
+static void i830_dma_dispatch_swap(drm_device_t * dev)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
-      	drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
+	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
 	int nbox = sarea_priv->nbox;
 	int nbox = sarea_priv->nbox;
 	drm_clip_rect_t *pbox = sarea_priv->boxes;
 	drm_clip_rect_t *pbox = sarea_priv->boxes;
 	int pitch = dev_priv->pitch;
 	int pitch = dev_priv->pitch;
@@ -990,202 +979,192 @@ static void i830_dma_dispatch_swap( drm_device_t *dev )
 
 
 	DRM_DEBUG("swapbuffers\n");
 	DRM_DEBUG("swapbuffers\n");
 
 
-  	i830_kernel_lost_context(dev);
+	i830_kernel_lost_context(dev);
 
 
 	if (dev_priv->do_boxes)
 	if (dev_priv->do_boxes)
-		i830_cp_performance_boxes( dev );
+		i830_cp_performance_boxes(dev);
 
 
-	switch(cpp) {
-	case 2: 
-		BR13 = (pitch * cpp) | (0xCC << 16) | (1<<24);
+	switch (cpp) {
+	case 2:
+		BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24);
 		CMD = XY_SRC_COPY_BLT_CMD;
 		CMD = XY_SRC_COPY_BLT_CMD;
 		break;
 		break;
 	case 4:
 	case 4:
-		BR13 = (pitch * cpp) | (0xCC << 16) | (1<<24) | (1<<25);
+		BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24) | (1 << 25);
 		CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
 		CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
 		       XY_SRC_COPY_BLT_WRITE_RGB);
 		       XY_SRC_COPY_BLT_WRITE_RGB);
 		break;
 		break;
 	default:
 	default:
-		BR13 = (pitch * cpp) | (0xCC << 16) | (1<<24);
+		BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24);
 		CMD = XY_SRC_COPY_BLT_CMD;
 		CMD = XY_SRC_COPY_BLT_CMD;
 		break;
 		break;
 	}
 	}
 
 
+	if (nbox > I830_NR_SAREA_CLIPRECTS)
+		nbox = I830_NR_SAREA_CLIPRECTS;
 
 
-      	if (nbox > I830_NR_SAREA_CLIPRECTS)
-     		nbox = I830_NR_SAREA_CLIPRECTS;
-
-	for (i = 0 ; i < nbox; i++, pbox++) 
-	{
+	for (i = 0; i < nbox; i++, pbox++) {
 		if (pbox->x1 > pbox->x2 ||
 		if (pbox->x1 > pbox->x2 ||
 		    pbox->y1 > pbox->y2 ||
 		    pbox->y1 > pbox->y2 ||
-		    pbox->x2 > dev_priv->w ||
-		    pbox->y2 > dev_priv->h)
+		    pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
 			continue;
 			continue;
- 
+
 		DRM_DEBUG("dispatch swap %d,%d-%d,%d!\n",
 		DRM_DEBUG("dispatch swap %d,%d-%d,%d!\n",
-			  pbox->x1, pbox->y1,
-			  pbox->x2, pbox->y2);
+			  pbox->x1, pbox->y1, pbox->x2, pbox->y2);
 
 
-		BEGIN_LP_RING( 8 );
-		OUT_RING( CMD );
-		OUT_RING( BR13 );
-		OUT_RING( (pbox->y1 << 16) | pbox->x1 );
-		OUT_RING( (pbox->y2 << 16) | pbox->x2 );
+		BEGIN_LP_RING(8);
+		OUT_RING(CMD);
+		OUT_RING(BR13);
+		OUT_RING((pbox->y1 << 16) | pbox->x1);
+		OUT_RING((pbox->y2 << 16) | pbox->x2);
 
 
-		if (dev_priv->current_page == 0) 
-			OUT_RING( dev_priv->front_offset );
+		if (dev_priv->current_page == 0)
+			OUT_RING(dev_priv->front_offset);
 		else
 		else
-			OUT_RING( dev_priv->back_offset );			
+			OUT_RING(dev_priv->back_offset);
 
 
-		OUT_RING( (pbox->y1 << 16) | pbox->x1 );
-		OUT_RING( BR13 & 0xffff );
+		OUT_RING((pbox->y1 << 16) | pbox->x1);
+		OUT_RING(BR13 & 0xffff);
 
 
-		if (dev_priv->current_page == 0) 
-			OUT_RING( dev_priv->back_offset );			
+		if (dev_priv->current_page == 0)
+			OUT_RING(dev_priv->back_offset);
 		else
 		else
-			OUT_RING( dev_priv->front_offset );
+			OUT_RING(dev_priv->front_offset);
 
 
 		ADVANCE_LP_RING();
 		ADVANCE_LP_RING();
 	}
 	}
 }
 }
 
 
-static void i830_dma_dispatch_flip( drm_device_t *dev )
+static void i830_dma_dispatch_flip(drm_device_t * dev)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_private_t *dev_priv = dev->dev_private;
 	RING_LOCALS;
 	RING_LOCALS;
 
 
-	DRM_DEBUG( "%s: page=%d pfCurrentPage=%d\n", 
-		   __FUNCTION__, 
-		   dev_priv->current_page,
-		   dev_priv->sarea_priv->pf_current_page);
+	DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
+		  __FUNCTION__,
+		  dev_priv->current_page,
+		  dev_priv->sarea_priv->pf_current_page);
 
 
-  	i830_kernel_lost_context(dev);
+	i830_kernel_lost_context(dev);
 
 
 	if (dev_priv->do_boxes) {
 	if (dev_priv->do_boxes) {
 		dev_priv->sarea_priv->perf_boxes |= I830_BOX_FLIP;
 		dev_priv->sarea_priv->perf_boxes |= I830_BOX_FLIP;
-		i830_cp_performance_boxes( dev );
+		i830_cp_performance_boxes(dev);
 	}
 	}
 
 
-
-	BEGIN_LP_RING( 2 );
-    	OUT_RING( INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE ); 
-	OUT_RING( 0 );
+	BEGIN_LP_RING(2);
+	OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+	OUT_RING(0);
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 
 
-	BEGIN_LP_RING( 6 );
-	OUT_RING( CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP );	
-	OUT_RING( 0 );
-	if ( dev_priv->current_page == 0 ) {
-		OUT_RING( dev_priv->back_offset );
+	BEGIN_LP_RING(6);
+	OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP);
+	OUT_RING(0);
+	if (dev_priv->current_page == 0) {
+		OUT_RING(dev_priv->back_offset);
 		dev_priv->current_page = 1;
 		dev_priv->current_page = 1;
 	} else {
 	} else {
-		OUT_RING( dev_priv->front_offset );
+		OUT_RING(dev_priv->front_offset);
 		dev_priv->current_page = 0;
 		dev_priv->current_page = 0;
 	}
 	}
 	OUT_RING(0);
 	OUT_RING(0);
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
 
 
-
-	BEGIN_LP_RING( 2 );
-	OUT_RING( MI_WAIT_FOR_EVENT |
-		  MI_WAIT_FOR_PLANE_A_FLIP );
-	OUT_RING( 0 );
+	BEGIN_LP_RING(2);
+	OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP);
+	OUT_RING(0);
 	ADVANCE_LP_RING();
 	ADVANCE_LP_RING();
-	
 
 
 	dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
 	dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
 }
 }
 
 
-static void i830_dma_dispatch_vertex(drm_device_t *dev, 
-				     drm_buf_t *buf,
-				     int discard,
-				     int used)
+static void i830_dma_dispatch_vertex(drm_device_t * dev,
+				     drm_buf_t * buf, int discard, int used)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
 	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-   	drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
-   	drm_clip_rect_t *box = sarea_priv->boxes;
-   	int nbox = sarea_priv->nbox;
+	drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
+	drm_clip_rect_t *box = sarea_priv->boxes;
+	int nbox = sarea_priv->nbox;
 	unsigned long address = (unsigned long)buf->bus_address;
 	unsigned long address = (unsigned long)buf->bus_address;
-	unsigned long start = address - dev->agp->base;     
+	unsigned long start = address - dev->agp->base;
 	int i = 0, u;
 	int i = 0, u;
-   	RING_LOCALS;
+	RING_LOCALS;
 
 
-   	i830_kernel_lost_context(dev);
+	i830_kernel_lost_context(dev);
 
 
-   	if (nbox > I830_NR_SAREA_CLIPRECTS) 
+	if (nbox > I830_NR_SAREA_CLIPRECTS)
 		nbox = I830_NR_SAREA_CLIPRECTS;
 		nbox = I830_NR_SAREA_CLIPRECTS;
 
 
 	if (discard) {
 	if (discard) {
-		u = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT, 
+		u = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT,
 			    I830_BUF_HARDWARE);
 			    I830_BUF_HARDWARE);
-		if(u != I830_BUF_CLIENT) {
+		if (u != I830_BUF_CLIENT) {
 			DRM_DEBUG("xxxx 2\n");
 			DRM_DEBUG("xxxx 2\n");
 		}
 		}
 	}
 	}
 
 
-	if (used > 4*1023) 
+	if (used > 4 * 1023)
 		used = 0;
 		used = 0;
 
 
 	if (sarea_priv->dirty)
 	if (sarea_priv->dirty)
-	   i830EmitState( dev );
+		i830EmitState(dev);
 
 
-  	DRM_DEBUG("dispatch vertex addr 0x%lx, used 0x%x nbox %d\n", 
+	DRM_DEBUG("dispatch vertex addr 0x%lx, used 0x%x nbox %d\n",
 		  address, used, nbox);
 		  address, used, nbox);
 
 
-   	dev_priv->counter++;
-   	DRM_DEBUG(  "dispatch counter : %ld\n", dev_priv->counter);
-   	DRM_DEBUG(  "i830_dma_dispatch\n");
-   	DRM_DEBUG(  "start : %lx\n", start);
-	DRM_DEBUG(  "used : %d\n", used);
-   	DRM_DEBUG(  "start + used - 4 : %ld\n", start + used - 4);
+	dev_priv->counter++;
+	DRM_DEBUG("dispatch counter : %ld\n", dev_priv->counter);
+	DRM_DEBUG("i830_dma_dispatch\n");
+	DRM_DEBUG("start : %lx\n", start);
+	DRM_DEBUG("used : %d\n", used);
+	DRM_DEBUG("start + used - 4 : %ld\n", start + used - 4);
 
 
 	if (buf_priv->currently_mapped == I830_BUF_MAPPED) {
 	if (buf_priv->currently_mapped == I830_BUF_MAPPED) {
 		u32 *vp = buf_priv->kernel_virtual;
 		u32 *vp = buf_priv->kernel_virtual;
 
 
 		vp[0] = (GFX_OP_PRIMITIVE |
 		vp[0] = (GFX_OP_PRIMITIVE |
-			sarea_priv->vertex_prim |
-			((used/4)-2));
+			 sarea_priv->vertex_prim | ((used / 4) - 2));
 
 
 		if (dev_priv->use_mi_batchbuffer_start) {
 		if (dev_priv->use_mi_batchbuffer_start) {
-			vp[used/4] = MI_BATCH_BUFFER_END;
-			used += 4; 
+			vp[used / 4] = MI_BATCH_BUFFER_END;
+			used += 4;
 		}
 		}
-		
+
 		if (used & 4) {
 		if (used & 4) {
-			vp[used/4] = 0;
+			vp[used / 4] = 0;
 			used += 4;
 			used += 4;
 		}
 		}
 
 
 		i830_unmap_buffer(buf);
 		i830_unmap_buffer(buf);
 	}
 	}
-		   
+
 	if (used) {
 	if (used) {
 		do {
 		do {
 			if (i < nbox) {
 			if (i < nbox) {
 				BEGIN_LP_RING(6);
 				BEGIN_LP_RING(6);
-				OUT_RING( GFX_OP_DRAWRECT_INFO );
-				OUT_RING( sarea_priv->BufferState[I830_DESTREG_DR1] );
-				OUT_RING( box[i].x1 | (box[i].y1<<16) );
-				OUT_RING( box[i].x2 | (box[i].y2<<16) );
-				OUT_RING( sarea_priv->BufferState[I830_DESTREG_DR4] );
-				OUT_RING( 0 );
+				OUT_RING(GFX_OP_DRAWRECT_INFO);
+				OUT_RING(sarea_priv->
+					 BufferState[I830_DESTREG_DR1]);
+				OUT_RING(box[i].x1 | (box[i].y1 << 16));
+				OUT_RING(box[i].x2 | (box[i].y2 << 16));
+				OUT_RING(sarea_priv->
+					 BufferState[I830_DESTREG_DR4]);
+				OUT_RING(0);
 				ADVANCE_LP_RING();
 				ADVANCE_LP_RING();
 			}
 			}
 
 
 			if (dev_priv->use_mi_batchbuffer_start) {
 			if (dev_priv->use_mi_batchbuffer_start) {
 				BEGIN_LP_RING(2);
 				BEGIN_LP_RING(2);
-				OUT_RING( MI_BATCH_BUFFER_START | (2<<6) );
-				OUT_RING( start | MI_BATCH_NON_SECURE );
+				OUT_RING(MI_BATCH_BUFFER_START | (2 << 6));
+				OUT_RING(start | MI_BATCH_NON_SECURE);
 				ADVANCE_LP_RING();
 				ADVANCE_LP_RING();
-			} 
-			else {
+			} else {
 				BEGIN_LP_RING(4);
 				BEGIN_LP_RING(4);
-				OUT_RING( MI_BATCH_BUFFER );
-				OUT_RING( start | MI_BATCH_NON_SECURE );
-				OUT_RING( start + used - 4 );
-				OUT_RING( 0 );
+				OUT_RING(MI_BATCH_BUFFER);
+				OUT_RING(start | MI_BATCH_NON_SECURE);
+				OUT_RING(start + used - 4);
+				OUT_RING(0);
 				ADVANCE_LP_RING();
 				ADVANCE_LP_RING();
 			}
 			}
 
 
@@ -1195,61 +1174,60 @@ static void i830_dma_dispatch_vertex(drm_device_t *dev,
 	if (discard) {
 	if (discard) {
 		dev_priv->counter++;
 		dev_priv->counter++;
 
 
-		(void) cmpxchg(buf_priv->in_use, I830_BUF_CLIENT,
-			       I830_BUF_HARDWARE);
+		(void)cmpxchg(buf_priv->in_use, I830_BUF_CLIENT,
+			      I830_BUF_HARDWARE);
 
 
 		BEGIN_LP_RING(8);
 		BEGIN_LP_RING(8);
-		OUT_RING( CMD_STORE_DWORD_IDX );
-		OUT_RING( 20 );
-		OUT_RING( dev_priv->counter );
-		OUT_RING( CMD_STORE_DWORD_IDX );
-		OUT_RING( buf_priv->my_use_idx );
-		OUT_RING( I830_BUF_FREE );
-		OUT_RING( CMD_REPORT_HEAD );
-		OUT_RING( 0 );
+		OUT_RING(CMD_STORE_DWORD_IDX);
+		OUT_RING(20);
+		OUT_RING(dev_priv->counter);
+		OUT_RING(CMD_STORE_DWORD_IDX);
+		OUT_RING(buf_priv->my_use_idx);
+		OUT_RING(I830_BUF_FREE);
+		OUT_RING(CMD_REPORT_HEAD);
+		OUT_RING(0);
 		ADVANCE_LP_RING();
 		ADVANCE_LP_RING();
 	}
 	}
 }
 }
 
 
-
-static void i830_dma_quiescent(drm_device_t *dev)
+static void i830_dma_quiescent(drm_device_t * dev)
 {
 {
-      	drm_i830_private_t *dev_priv = dev->dev_private;
-   	RING_LOCALS;
+	drm_i830_private_t *dev_priv = dev->dev_private;
+	RING_LOCALS;
 
 
-  	i830_kernel_lost_context(dev);
+	i830_kernel_lost_context(dev);
 
 
-   	BEGIN_LP_RING(4);
-   	OUT_RING( INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE );
-   	OUT_RING( CMD_REPORT_HEAD );
-      	OUT_RING( 0 );
-      	OUT_RING( 0 );
-   	ADVANCE_LP_RING();
+	BEGIN_LP_RING(4);
+	OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+	OUT_RING(CMD_REPORT_HEAD);
+	OUT_RING(0);
+	OUT_RING(0);
+	ADVANCE_LP_RING();
 
 
-	i830_wait_ring( dev, dev_priv->ring.Size - 8, __FUNCTION__ );
+	i830_wait_ring(dev, dev_priv->ring.Size - 8, __FUNCTION__);
 }
 }
 
 
-static int i830_flush_queue(drm_device_t *dev)
+static int i830_flush_queue(drm_device_t * dev)
 {
 {
-   	drm_i830_private_t *dev_priv = dev->dev_private;
+	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
-   	int i, ret = 0;
-   	RING_LOCALS;
-	
-   	i830_kernel_lost_context(dev);
-
-   	BEGIN_LP_RING(2);
-      	OUT_RING( CMD_REPORT_HEAD );
-      	OUT_RING( 0 );
-      	ADVANCE_LP_RING();
-
-	i830_wait_ring( dev, dev_priv->ring.Size - 8, __FUNCTION__ );
-
-   	for (i = 0; i < dma->buf_count; i++) {
-	   	drm_buf_t *buf = dma->buflist[ i ];
-	   	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-	   
-		int used = cmpxchg(buf_priv->in_use, I830_BUF_HARDWARE, 
+	int i, ret = 0;
+	RING_LOCALS;
+
+	i830_kernel_lost_context(dev);
+
+	BEGIN_LP_RING(2);
+	OUT_RING(CMD_REPORT_HEAD);
+	OUT_RING(0);
+	ADVANCE_LP_RING();
+
+	i830_wait_ring(dev, dev_priv->ring.Size - 8, __FUNCTION__);
+
+	for (i = 0; i < dma->buf_count; i++) {
+		drm_buf_t *buf = dma->buflist[i];
+		drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+
+		int used = cmpxchg(buf_priv->in_use, I830_BUF_HARDWARE,
 				   I830_BUF_FREE);
 				   I830_BUF_FREE);
 
 
 		if (used == I830_BUF_HARDWARE)
 		if (used == I830_BUF_HARDWARE)
@@ -1258,62 +1236,66 @@ static int i830_flush_queue(drm_device_t *dev)
 			DRM_DEBUG("still on client\n");
 			DRM_DEBUG("still on client\n");
 	}
 	}
 
 
-   	return ret;
+	return ret;
 }
 }
 
 
 /* Must be called with the lock held */
 /* Must be called with the lock held */
-void i830_reclaim_buffers(drm_device_t *dev, struct file *filp)
+void i830_reclaim_buffers(drm_device_t * dev, struct file *filp)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
-	int		 i;
+	int i;
 
 
-	if (!dma) return;
-      	if (!dev->dev_private) return;
-	if (!dma->buflist) return;
+	if (!dma)
+		return;
+	if (!dev->dev_private)
+		return;
+	if (!dma->buflist)
+		return;
 
 
-        i830_flush_queue(dev);
+	i830_flush_queue(dev);
 
 
 	for (i = 0; i < dma->buf_count; i++) {
 	for (i = 0; i < dma->buf_count; i++) {
-	   	drm_buf_t *buf = dma->buflist[ i ];
-	   	drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-	   
+		drm_buf_t *buf = dma->buflist[i];
+		drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+
 		if (buf->filp == filp && buf_priv) {
 		if (buf->filp == filp && buf_priv) {
-			int used = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT, 
+			int used = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT,
 					   I830_BUF_FREE);
 					   I830_BUF_FREE);
 
 
 			if (used == I830_BUF_CLIENT)
 			if (used == I830_BUF_CLIENT)
 				DRM_DEBUG("reclaimed from client\n");
 				DRM_DEBUG("reclaimed from client\n");
-		   	if(buf_priv->currently_mapped == I830_BUF_MAPPED)
-		     		buf_priv->currently_mapped = I830_BUF_UNMAPPED;
+			if (buf_priv->currently_mapped == I830_BUF_MAPPED)
+				buf_priv->currently_mapped = I830_BUF_UNMAPPED;
 		}
 		}
 	}
 	}
 }
 }
 
 
-static int i830_flush_ioctl(struct inode *inode, struct file *filp, 
-			     unsigned int cmd, unsigned long arg)
+static int i830_flush_ioctl(struct inode *inode, struct file *filp,
+			    unsigned int cmd, unsigned long arg)
 {
 {
-   	drm_file_t	  *priv	  = filp->private_data;
-   	drm_device_t	  *dev	  = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
-   	i830_flush_queue(dev);
-   	return 0;
+	i830_flush_queue(dev);
+	return 0;
 }
 }
 
 
 static int i830_dma_vertex(struct inode *inode, struct file *filp,
 static int i830_dma_vertex(struct inode *inode, struct file *filp,
-		       unsigned int cmd, unsigned long arg)
+			   unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
-   	drm_i830_private_t *dev_priv = (drm_i830_private_t *)dev->dev_private;
-      	u32 *hw_status = dev_priv->hw_status_page;
-   	drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *) 
-     					dev_priv->sarea_priv; 
+	drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+	u32 *hw_status = dev_priv->hw_status_page;
+	drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *)
+	    dev_priv->sarea_priv;
 	drm_i830_vertex_t vertex;
 	drm_i830_vertex_t vertex;
 
 
-	if (copy_from_user(&vertex, (drm_i830_vertex_t __user *)arg, sizeof(vertex)))
+	if (copy_from_user
+	    (&vertex, (drm_i830_vertex_t __user *) arg, sizeof(vertex)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
@@ -1321,15 +1303,16 @@ static int i830_dma_vertex(struct inode *inode, struct file *filp,
 	DRM_DEBUG("i830 dma vertex, idx %d used %d discard %d\n",
 	DRM_DEBUG("i830 dma vertex, idx %d used %d discard %d\n",
 		  vertex.idx, vertex.used, vertex.discard);
 		  vertex.idx, vertex.used, vertex.discard);
 
 
-	if(vertex.idx < 0 || vertex.idx > dma->buf_count) return -EINVAL;
+	if (vertex.idx < 0 || vertex.idx > dma->buf_count)
+		return -EINVAL;
 
 
-	i830_dma_dispatch_vertex( dev, 
-				  dma->buflist[ vertex.idx ], 
-				  vertex.discard, vertex.used );
+	i830_dma_dispatch_vertex(dev,
+				 dma->buflist[vertex.idx],
+				 vertex.discard, vertex.used);
+
+	sarea_priv->last_enqueue = dev_priv->counter - 1;
+	sarea_priv->last_dispatch = (int)hw_status[5];
 
 
-	sarea_priv->last_enqueue = dev_priv->counter-1;
-   	sarea_priv->last_dispatch = (int) hw_status[5];
-   
 	return 0;
 	return 0;
 }
 }
 
 
@@ -1340,9 +1323,10 @@ static int i830_clear_bufs(struct inode *inode, struct file *filp,
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
 	drm_i830_clear_t clear;
 	drm_i830_clear_t clear;
 
 
-   	if (copy_from_user(&clear, (drm_i830_clear_t __user *)arg, sizeof(clear)))
+	if (copy_from_user
+	    (&clear, (drm_i830_clear_t __user *) arg, sizeof(clear)))
 		return -EFAULT;
 		return -EFAULT;
-   
+
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
 	/* GH: Someone's doing nasty things... */
 	/* GH: Someone's doing nasty things... */
@@ -1350,11 +1334,10 @@ static int i830_clear_bufs(struct inode *inode, struct file *filp,
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	i830_dma_dispatch_clear( dev, clear.flags, 
-				 clear.clear_color, 
-				 clear.clear_depth,
-			         clear.clear_depthmask);
-   	return 0;
+	i830_dma_dispatch_clear(dev, clear.flags,
+				clear.clear_color,
+				clear.clear_depth, clear.clear_depthmask);
+	return 0;
 }
 }
 
 
 static int i830_swap_bufs(struct inode *inode, struct file *filp,
 static int i830_swap_bufs(struct inode *inode, struct file *filp,
@@ -1362,20 +1345,18 @@ static int i830_swap_bufs(struct inode *inode, struct file *filp,
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
-   
+
 	DRM_DEBUG("i830_swap_bufs\n");
 	DRM_DEBUG("i830_swap_bufs\n");
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
-	i830_dma_dispatch_swap( dev );
-   	return 0;
+	i830_dma_dispatch_swap(dev);
+	return 0;
 }
 }
 
 
-
-
 /* Not sure why this isn't set all the time:
 /* Not sure why this isn't set all the time:
- */ 
-static void i830_do_init_pageflip( drm_device_t *dev )
+ */
+static void i830_do_init_pageflip(drm_device_t * dev)
 {
 {
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 
 
@@ -1385,20 +1366,20 @@ static void i830_do_init_pageflip( drm_device_t *dev )
 	dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
 	dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
 }
 }
 
 
-static int i830_do_cleanup_pageflip( drm_device_t *dev )
+static int i830_do_cleanup_pageflip(drm_device_t * dev)
 {
 {
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 
 
 	DRM_DEBUG("%s\n", __FUNCTION__);
 	DRM_DEBUG("%s\n", __FUNCTION__);
 	if (dev_priv->current_page != 0)
 	if (dev_priv->current_page != 0)
-		i830_dma_dispatch_flip( dev );
+		i830_dma_dispatch_flip(dev);
 
 
 	dev_priv->page_flipping = 0;
 	dev_priv->page_flipping = 0;
 	return 0;
 	return 0;
 }
 }
 
 
 static int i830_flip_bufs(struct inode *inode, struct file *filp,
 static int i830_flip_bufs(struct inode *inode, struct file *filp,
-			   unsigned int cmd, unsigned long arg)
+			  unsigned int cmd, unsigned long arg)
 {
 {
 	drm_file_t *priv = filp->private_data;
 	drm_file_t *priv = filp->private_data;
 	drm_device_t *dev = priv->head->dev;
 	drm_device_t *dev = priv->head->dev;
@@ -1408,45 +1389,45 @@ static int i830_flip_bufs(struct inode *inode, struct file *filp,
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
-	if (!dev_priv->page_flipping) 
-		i830_do_init_pageflip( dev );
+	if (!dev_priv->page_flipping)
+		i830_do_init_pageflip(dev);
 
 
-	i830_dma_dispatch_flip( dev );
-   	return 0;
+	i830_dma_dispatch_flip(dev);
+	return 0;
 }
 }
 
 
 static int i830_getage(struct inode *inode, struct file *filp, unsigned int cmd,
 static int i830_getage(struct inode *inode, struct file *filp, unsigned int cmd,
-			unsigned long arg)
+		       unsigned long arg)
 {
 {
-   	drm_file_t	  *priv	    = filp->private_data;
-	drm_device_t	  *dev	    = priv->head->dev;
-   	drm_i830_private_t *dev_priv = (drm_i830_private_t *)dev->dev_private;
-      	u32 *hw_status = dev_priv->hw_status_page;
-   	drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *) 
-     					dev_priv->sarea_priv; 
-
-      	sarea_priv->last_dispatch = (int) hw_status[5];
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+	u32 *hw_status = dev_priv->hw_status_page;
+	drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *)
+	    dev_priv->sarea_priv;
+
+	sarea_priv->last_dispatch = (int)hw_status[5];
 	return 0;
 	return 0;
 }
 }
 
 
 static int i830_getbuf(struct inode *inode, struct file *filp, unsigned int cmd,
 static int i830_getbuf(struct inode *inode, struct file *filp, unsigned int cmd,
-			unsigned long arg)
+		       unsigned long arg)
 {
 {
-	drm_file_t	  *priv	    = filp->private_data;
-	drm_device_t	  *dev	    = priv->head->dev;
-	int		  retcode   = 0;
-	drm_i830_dma_t	  d;
-   	drm_i830_private_t *dev_priv = (drm_i830_private_t *)dev->dev_private;
-   	u32 *hw_status = dev_priv->hw_status_page;
-   	drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *) 
-     					dev_priv->sarea_priv; 
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
+	int retcode = 0;
+	drm_i830_dma_t d;
+	drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+	u32 *hw_status = dev_priv->hw_status_page;
+	drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *)
+	    dev_priv->sarea_priv;
 
 
 	DRM_DEBUG("getbuf\n");
 	DRM_DEBUG("getbuf\n");
-   	if (copy_from_user(&d, (drm_i830_dma_t __user *)arg, sizeof(d)))
+	if (copy_from_user(&d, (drm_i830_dma_t __user *) arg, sizeof(d)))
 		return -EFAULT;
 		return -EFAULT;
-   
+
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
-	
+
 	d.granted = 0;
 	d.granted = 0;
 
 
 	retcode = i830_dma_get_buffer(dev, &d, filp);
 	retcode = i830_dma_get_buffer(dev, &d, filp);
@@ -1454,46 +1435,45 @@ static int i830_getbuf(struct inode *inode, struct file *filp, unsigned int cmd,
 	DRM_DEBUG("i830_dma: %d returning %d, granted = %d\n",
 	DRM_DEBUG("i830_dma: %d returning %d, granted = %d\n",
 		  current->pid, retcode, d.granted);
 		  current->pid, retcode, d.granted);
 
 
-	if (copy_to_user((drm_dma_t __user *)arg, &d, sizeof(d)))
+	if (copy_to_user((drm_dma_t __user *) arg, &d, sizeof(d)))
 		return -EFAULT;
 		return -EFAULT;
-   	sarea_priv->last_dispatch = (int) hw_status[5];
+	sarea_priv->last_dispatch = (int)hw_status[5];
 
 
 	return retcode;
 	return retcode;
 }
 }
 
 
 static int i830_copybuf(struct inode *inode,
 static int i830_copybuf(struct inode *inode,
-			 struct file *filp, unsigned int cmd, unsigned long arg)
+			struct file *filp, unsigned int cmd, unsigned long arg)
 {
 {
 	/* Never copy - 2.4.x doesn't need it */
 	/* Never copy - 2.4.x doesn't need it */
 	return 0;
 	return 0;
 }
 }
 
 
 static int i830_docopy(struct inode *inode, struct file *filp, unsigned int cmd,
 static int i830_docopy(struct inode *inode, struct file *filp, unsigned int cmd,
-			unsigned long arg)
+		       unsigned long arg)
 {
 {
 	return 0;
 	return 0;
 }
 }
 
 
-
-
-static int i830_getparam( struct inode *inode, struct file *filp, 
-			unsigned int cmd, unsigned long arg )
+static int i830_getparam(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	  *priv	    = filp->private_data;
-	drm_device_t	  *dev	    = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_getparam_t param;
 	drm_i830_getparam_t param;
 	int value;
 	int value;
 
 
-	if ( !dev_priv ) {
-		DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ );
+	if (!dev_priv) {
+		DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	if (copy_from_user(&param, (drm_i830_getparam_t __user *)arg, sizeof(param) ))
+	if (copy_from_user
+	    (&param, (drm_i830_getparam_t __user *) arg, sizeof(param)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	switch( param.param ) {
+	switch (param.param) {
 	case I830_PARAM_IRQ_ACTIVE:
 	case I830_PARAM_IRQ_ACTIVE:
 		value = dev->irq_enabled;
 		value = dev->irq_enabled;
 		break;
 		break;
@@ -1501,32 +1481,32 @@ static int i830_getparam( struct inode *inode, struct file *filp,
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	if ( copy_to_user( param.value, &value, sizeof(int) ) ) {
-		DRM_ERROR( "copy_to_user\n" );
+	if (copy_to_user(param.value, &value, sizeof(int))) {
+		DRM_ERROR("copy_to_user\n");
 		return -EFAULT;
 		return -EFAULT;
 	}
 	}
-	
+
 	return 0;
 	return 0;
 }
 }
 
 
-
-static int i830_setparam( struct inode *inode, struct file *filp,
-			unsigned int cmd, unsigned long arg )
+static int i830_setparam(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg)
 {
 {
-	drm_file_t	  *priv	    = filp->private_data;
-	drm_device_t	  *dev	    = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_setparam_t param;
 	drm_i830_setparam_t param;
 
 
-	if ( !dev_priv ) {
-		DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ );
+	if (!dev_priv) {
+		DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	if (copy_from_user(&param, (drm_i830_setparam_t __user *)arg, sizeof(param) ))
+	if (copy_from_user
+	    (&param, (drm_i830_setparam_t __user *) arg, sizeof(param)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	switch( param.param ) {
+	switch (param.param) {
 	case I830_SETPARAM_USE_MI_BATCHBUFFER_START:
 	case I830_SETPARAM_USE_MI_BATCHBUFFER_START:
 		dev_priv->use_mi_batchbuffer_start = param.value;
 		dev_priv->use_mi_batchbuffer_start = param.value;
 		break;
 		break;
@@ -1537,13 +1517,12 @@ static int i830_setparam( struct inode *inode, struct file *filp,
 	return 0;
 	return 0;
 }
 }
 
 
-
-void i830_driver_pretakedown(drm_device_t *dev)
+void i830_driver_pretakedown(drm_device_t * dev)
 {
 {
-	i830_dma_cleanup( dev );
+	i830_dma_cleanup(dev);
 }
 }
 
 
-void i830_driver_prerelease(drm_device_t *dev, DRMFILE filp)
+void i830_driver_prerelease(drm_device_t * dev, DRMFILE filp)
 {
 {
 	if (dev->dev_private) {
 	if (dev->dev_private) {
 		drm_i830_private_t *dev_priv = dev->dev_private;
 		drm_i830_private_t *dev_priv = dev->dev_private;
@@ -1553,32 +1532,32 @@ void i830_driver_prerelease(drm_device_t *dev, DRMFILE filp)
 	}
 	}
 }
 }
 
 
-void i830_driver_release(drm_device_t *dev, struct file *filp)
+void i830_driver_release(drm_device_t * dev, struct file *filp)
 {
 {
 	i830_reclaim_buffers(dev, filp);
 	i830_reclaim_buffers(dev, filp);
 }
 }
 
 
-int i830_driver_dma_quiescent(drm_device_t *dev)
+int i830_driver_dma_quiescent(drm_device_t * dev)
 {
 {
-	i830_dma_quiescent( dev );
+	i830_dma_quiescent(dev);
 	return 0;
 	return 0;
 }
 }
 
 
 drm_ioctl_desc_t i830_ioctls[] = {
 drm_ioctl_desc_t i830_ioctls[] = {
-	[DRM_IOCTL_NR(DRM_I830_INIT)]     = { i830_dma_init,    1, 1 },
-	[DRM_IOCTL_NR(DRM_I830_VERTEX)]   = { i830_dma_vertex,  1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_CLEAR)]    = { i830_clear_bufs,  1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_FLUSH)]    = { i830_flush_ioctl, 1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_GETAGE)]   = { i830_getage,      1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_GETBUF)]   = { i830_getbuf,      1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_SWAP)]     = { i830_swap_bufs,   1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_COPY)]     = { i830_copybuf,     1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_DOCOPY)]   = { i830_docopy,      1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_FLIP)]     = { i830_flip_bufs,   1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_IRQ_EMIT)] = { i830_irq_emit,    1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_IRQ_WAIT)] = { i830_irq_wait,    1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_GETPARAM)] = { i830_getparam,    1, 0 },
-	[DRM_IOCTL_NR(DRM_I830_SETPARAM)] = { i830_setparam,    1, 0 } 
+	[DRM_IOCTL_NR(DRM_I830_INIT)] = {i830_dma_init, 1, 1},
+	[DRM_IOCTL_NR(DRM_I830_VERTEX)] = {i830_dma_vertex, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_CLEAR)] = {i830_clear_bufs, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_FLUSH)] = {i830_flush_ioctl, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_GETAGE)] = {i830_getage, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_GETBUF)] = {i830_getbuf, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_SWAP)] = {i830_swap_bufs, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_COPY)] = {i830_copybuf, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_DOCOPY)] = {i830_docopy, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_FLIP)] = {i830_flip_bufs, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_IRQ_EMIT)] = {i830_irq_emit, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_IRQ_WAIT)] = {i830_irq_wait, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_GETPARAM)] = {i830_getparam, 1, 0},
+	[DRM_IOCTL_NR(DRM_I830_SETPARAM)] = {i830_setparam, 1, 0}
 };
 };
 
 
 int i830_max_ioctl = DRM_ARRAY_SIZE(i830_ioctls);
 int i830_max_ioctl = DRM_ARRAY_SIZE(i830_ioctls);

+ 41 - 49
drivers/char/drm/i830_drm.h

@@ -33,14 +33,14 @@
 #define I830_UPLOAD_CTX			0x1
 #define I830_UPLOAD_CTX			0x1
 #define I830_UPLOAD_BUFFERS		0x2
 #define I830_UPLOAD_BUFFERS		0x2
 #define I830_UPLOAD_CLIPRECTS		0x4
 #define I830_UPLOAD_CLIPRECTS		0x4
-#define I830_UPLOAD_TEX0_IMAGE		0x100 /* handled clientside */
-#define I830_UPLOAD_TEX0_CUBE		0x200 /* handled clientside */
-#define I830_UPLOAD_TEX1_IMAGE		0x400 /* handled clientside */
-#define I830_UPLOAD_TEX1_CUBE		0x800 /* handled clientside */
-#define I830_UPLOAD_TEX2_IMAGE		0x1000 /* handled clientside */
-#define I830_UPLOAD_TEX2_CUBE		0x2000 /* handled clientside */
-#define I830_UPLOAD_TEX3_IMAGE		0x4000 /* handled clientside */
-#define I830_UPLOAD_TEX3_CUBE		0x8000 /* handled clientside */
+#define I830_UPLOAD_TEX0_IMAGE		0x100	/* handled clientside */
+#define I830_UPLOAD_TEX0_CUBE		0x200	/* handled clientside */
+#define I830_UPLOAD_TEX1_IMAGE		0x400	/* handled clientside */
+#define I830_UPLOAD_TEX1_CUBE		0x800	/* handled clientside */
+#define I830_UPLOAD_TEX2_IMAGE		0x1000	/* handled clientside */
+#define I830_UPLOAD_TEX2_CUBE		0x2000	/* handled clientside */
+#define I830_UPLOAD_TEX3_IMAGE		0x4000	/* handled clientside */
+#define I830_UPLOAD_TEX3_CUBE		0x8000	/* handled clientside */
 #define I830_UPLOAD_TEX_N_IMAGE(n)	(0x100 << (n * 2))
 #define I830_UPLOAD_TEX_N_IMAGE(n)	(0x100 << (n * 2))
 #define I830_UPLOAD_TEX_N_CUBE(n)	(0x200 << (n * 2))
 #define I830_UPLOAD_TEX_N_CUBE(n)	(0x200 << (n * 2))
 #define I830_UPLOAD_TEXIMAGE_MASK	0xff00
 #define I830_UPLOAD_TEXIMAGE_MASK	0xff00
@@ -65,7 +65,7 @@
  * or in a piecewise fashion as required.
  * or in a piecewise fashion as required.
  */
  */
 
 
-/* Destbuffer state 
+/* Destbuffer state
  *    - backbuffer linear offset and pitch -- invarient in the current dri
  *    - backbuffer linear offset and pitch -- invarient in the current dri
  *    - zbuffer linear offset and pitch -- also invarient
  *    - zbuffer linear offset and pitch -- also invarient
  *    - drawing origin in back and depth buffers.
  *    - drawing origin in back and depth buffers.
@@ -103,7 +103,7 @@
 #define I830_CTXREG_AA			9
 #define I830_CTXREG_AA			9
 #define I830_CTXREG_FOGCOLOR		10
 #define I830_CTXREG_FOGCOLOR		10
 #define I830_CTXREG_BLENDCOLR0		11
 #define I830_CTXREG_BLENDCOLR0		11
-#define I830_CTXREG_BLENDCOLR		12 /* Dword 1 of 2 dword command */
+#define I830_CTXREG_BLENDCOLR		12	/* Dword 1 of 2 dword command */
 #define I830_CTXREG_VF			13
 #define I830_CTXREG_VF			13
 #define I830_CTXREG_VF2			14
 #define I830_CTXREG_VF2			14
 #define I830_CTXREG_MCSB0		15
 #define I830_CTXREG_MCSB0		15
@@ -111,12 +111,11 @@
 #define I830_CTX_SETUP_SIZE		17
 #define I830_CTX_SETUP_SIZE		17
 
 
 /* 1.3: Stipple state
 /* 1.3: Stipple state
- */ 
+ */
 #define I830_STPREG_ST0 0
 #define I830_STPREG_ST0 0
 #define I830_STPREG_ST1 1
 #define I830_STPREG_ST1 1
 #define I830_STP_SETUP_SIZE 2
 #define I830_STP_SETUP_SIZE 2
 
 
-
 /* Texture state (per tex unit)
 /* Texture state (per tex unit)
  */
  */
 
 
@@ -132,23 +131,23 @@
 #define I830_TEXREG_MCS	9	/* GFX_OP_MAP_COORD_SETS */
 #define I830_TEXREG_MCS	9	/* GFX_OP_MAP_COORD_SETS */
 #define I830_TEX_SETUP_SIZE 10
 #define I830_TEX_SETUP_SIZE 10
 
 
-#define I830_TEXREG_TM0LI      0 /* load immediate 2 texture map n */
+#define I830_TEXREG_TM0LI      0	/* load immediate 2 texture map n */
 #define I830_TEXREG_TM0S0      1
 #define I830_TEXREG_TM0S0      1
 #define I830_TEXREG_TM0S1      2
 #define I830_TEXREG_TM0S1      2
 #define I830_TEXREG_TM0S2      3
 #define I830_TEXREG_TM0S2      3
 #define I830_TEXREG_TM0S3      4
 #define I830_TEXREG_TM0S3      4
 #define I830_TEXREG_TM0S4      5
 #define I830_TEXREG_TM0S4      5
-#define I830_TEXREG_NOP0       6       /* noop */
-#define I830_TEXREG_NOP1       7       /* noop */
-#define I830_TEXREG_NOP2       8       /* noop */
-#define __I830_TEXREG_MCS      9       /* GFX_OP_MAP_COORD_SETS -- shared */
+#define I830_TEXREG_NOP0       6	/* noop */
+#define I830_TEXREG_NOP1       7	/* noop */
+#define I830_TEXREG_NOP2       8	/* noop */
+#define __I830_TEXREG_MCS      9	/* GFX_OP_MAP_COORD_SETS -- shared */
 #define __I830_TEX_SETUP_SIZE   10
 #define __I830_TEX_SETUP_SIZE   10
 
 
 #define I830_FRONT   0x1
 #define I830_FRONT   0x1
 #define I830_BACK    0x2
 #define I830_BACK    0x2
 #define I830_DEPTH   0x4
 #define I830_DEPTH   0x4
 
 
-#endif /* _I830_DEFINES_ */
+#endif				/* _I830_DEFINES_ */
 
 
 typedef struct _drm_i830_init {
 typedef struct _drm_i830_init {
 	enum {
 	enum {
@@ -177,19 +176,19 @@ typedef struct _drm_i830_init {
  * structure as well */
  * structure as well */
 
 
 typedef struct _drm_i830_tex_region {
 typedef struct _drm_i830_tex_region {
-	unsigned char next, prev; /* indices to form a circular LRU  */
+	unsigned char next, prev;	/* indices to form a circular LRU  */
 	unsigned char in_use;	/* owned by a client, or free? */
 	unsigned char in_use;	/* owned by a client, or free? */
 	int age;		/* tracked by clients to update local LRU's */
 	int age;		/* tracked by clients to update local LRU's */
 } drm_i830_tex_region_t;
 } drm_i830_tex_region_t;
 
 
 typedef struct _drm_i830_sarea {
 typedef struct _drm_i830_sarea {
 	unsigned int ContextState[I830_CTX_SETUP_SIZE];
 	unsigned int ContextState[I830_CTX_SETUP_SIZE];
-   	unsigned int BufferState[I830_DEST_SETUP_SIZE];
+	unsigned int BufferState[I830_DEST_SETUP_SIZE];
 	unsigned int TexState[I830_TEXTURE_COUNT][I830_TEX_SETUP_SIZE];
 	unsigned int TexState[I830_TEXTURE_COUNT][I830_TEX_SETUP_SIZE];
 	unsigned int TexBlendState[I830_TEXBLEND_COUNT][I830_TEXBLEND_SIZE];
 	unsigned int TexBlendState[I830_TEXBLEND_COUNT][I830_TEXBLEND_SIZE];
 	unsigned int TexBlendStateWordsUsed[I830_TEXBLEND_COUNT];
 	unsigned int TexBlendStateWordsUsed[I830_TEXBLEND_COUNT];
 	unsigned int Palette[2][256];
 	unsigned int Palette[2][256];
-   	unsigned int dirty;
+	unsigned int dirty;
 
 
 	unsigned int nbox;
 	unsigned int nbox;
 	drm_clip_rect_t boxes[I830_NR_SAREA_CLIPRECTS];
 	drm_clip_rect_t boxes[I830_NR_SAREA_CLIPRECTS];
@@ -207,26 +206,26 @@ typedef struct _drm_i830_sarea {
 	 * texture space, and can make informed decisions as to which
 	 * texture space, and can make informed decisions as to which
 	 * areas to kick out.  There is no need to choose whether to
 	 * areas to kick out.  There is no need to choose whether to
 	 * kick out your own texture or someone else's - simply eject
 	 * kick out your own texture or someone else's - simply eject
-	 * them all in LRU order.  
+	 * them all in LRU order.
 	 */
 	 */
 
 
-	drm_i830_tex_region_t texList[I830_NR_TEX_REGIONS+1]; 
-				/* Last elt is sentinal */
-        int texAge;		/* last time texture was uploaded */
-        int last_enqueue;	/* last time a buffer was enqueued */
+	drm_i830_tex_region_t texList[I830_NR_TEX_REGIONS + 1];
+	/* Last elt is sentinal */
+	int texAge;		/* last time texture was uploaded */
+	int last_enqueue;	/* last time a buffer was enqueued */
 	int last_dispatch;	/* age of the most recently dispatched buffer */
 	int last_dispatch;	/* age of the most recently dispatched buffer */
-	int last_quiescent;     /*  */
+	int last_quiescent;	/*  */
 	int ctxOwner;		/* last context to upload state */
 	int ctxOwner;		/* last context to upload state */
 
 
 	int vertex_prim;
 	int vertex_prim;
 
 
-        int pf_enabled;               /* is pageflipping allowed? */
-        int pf_active;               
-        int pf_current_page;	    /* which buffer is being displayed? */
+	int pf_enabled;		/* is pageflipping allowed? */
+	int pf_active;
+	int pf_current_page;	/* which buffer is being displayed? */
+
+	int perf_boxes;		/* performance boxes to be displayed */
 
 
-        int perf_boxes;             /* performance boxes to be displayed */
-   
-        /* Here's the state for texunits 2,3:
+	/* Here's the state for texunits 2,3:
 	 */
 	 */
 	unsigned int TexState2[I830_TEX_SETUP_SIZE];
 	unsigned int TexState2[I830_TEX_SETUP_SIZE];
 	unsigned int TexBlendState2[I830_TEXBLEND_SIZE];
 	unsigned int TexBlendState2[I830_TEXBLEND_SIZE];
@@ -241,12 +240,11 @@ typedef struct _drm_i830_sarea {
 
 
 /* Flags for perf_boxes
 /* Flags for perf_boxes
  */
  */
-#define I830_BOX_RING_EMPTY    0x1 /* populated by kernel */
-#define I830_BOX_FLIP          0x2 /* populated by kernel */
-#define I830_BOX_WAIT          0x4 /* populated by kernel & client */
-#define I830_BOX_TEXTURE_LOAD  0x8 /* populated by kernel */
-#define I830_BOX_LOST_CONTEXT  0x10 /* populated by client */
-
+#define I830_BOX_RING_EMPTY    0x1	/* populated by kernel */
+#define I830_BOX_FLIP          0x2	/* populated by kernel */
+#define I830_BOX_WAIT          0x4	/* populated by kernel & client */
+#define I830_BOX_TEXTURE_LOAD  0x8	/* populated by kernel */
+#define I830_BOX_LOST_CONTEXT  0x10	/* populated by client */
 
 
 /* I830 specific ioctls
 /* I830 specific ioctls
  * The device specific ioctl range is 0x40 to 0x79.
  * The device specific ioctl range is 0x40 to 0x79.
@@ -289,23 +287,21 @@ typedef struct _drm_i830_clear {
 	unsigned int clear_depthmask;
 	unsigned int clear_depthmask;
 } drm_i830_clear_t;
 } drm_i830_clear_t;
 
 
-
-
 /* These may be placeholders if we have more cliprects than
 /* These may be placeholders if we have more cliprects than
  * I830_NR_SAREA_CLIPRECTS.  In that case, the client sets discard to
  * I830_NR_SAREA_CLIPRECTS.  In that case, the client sets discard to
  * false, indicating that the buffer will be dispatched again with a
  * false, indicating that the buffer will be dispatched again with a
  * new set of cliprects.
  * new set of cliprects.
  */
  */
 typedef struct _drm_i830_vertex {
 typedef struct _drm_i830_vertex {
-   	int idx;		/* buffer index */
+	int idx;		/* buffer index */
 	int used;		/* nr bytes in use */
 	int used;		/* nr bytes in use */
 	int discard;		/* client is finished with the buffer? */
 	int discard;		/* client is finished with the buffer? */
 } drm_i830_vertex_t;
 } drm_i830_vertex_t;
 
 
 typedef struct _drm_i830_copy_t {
 typedef struct _drm_i830_copy_t {
-   	int idx;		/* buffer index */
+	int idx;		/* buffer index */
 	int used;		/* nr bytes in use */
 	int used;		/* nr bytes in use */
-	void __user *address;		/* Address to copy from */
+	void __user *address;	/* Address to copy from */
 } drm_i830_copy_t;
 } drm_i830_copy_t;
 
 
 typedef struct drm_i830_dma {
 typedef struct drm_i830_dma {
@@ -315,7 +311,6 @@ typedef struct drm_i830_dma {
 	int granted;
 	int granted;
 } drm_i830_dma_t;
 } drm_i830_dma_t;
 
 
-
 /* 1.3: Userspace can request & wait on irq's:
 /* 1.3: Userspace can request & wait on irq's:
  */
  */
 typedef struct drm_i830_irq_emit {
 typedef struct drm_i830_irq_emit {
@@ -326,7 +321,6 @@ typedef struct drm_i830_irq_wait {
 	int irq_seq;
 	int irq_seq;
 } drm_i830_irq_wait_t;
 } drm_i830_irq_wait_t;
 
 
-
 /* 1.3: New ioctl to query kernel params:
 /* 1.3: New ioctl to query kernel params:
  */
  */
 #define I830_PARAM_IRQ_ACTIVE            1
 #define I830_PARAM_IRQ_ACTIVE            1
@@ -336,7 +330,6 @@ typedef struct drm_i830_getparam {
 	int __user *value;
 	int __user *value;
 } drm_i830_getparam_t;
 } drm_i830_getparam_t;
 
 
-
 /* 1.3: New ioctl to set kernel params:
 /* 1.3: New ioctl to set kernel params:
  */
  */
 #define I830_SETPARAM_USE_MI_BATCHBUFFER_START            1
 #define I830_SETPARAM_USE_MI_BATCHBUFFER_START            1
@@ -346,5 +339,4 @@ typedef struct drm_i830_setparam {
 	int value;
 	int value;
 } drm_i830_setparam_t;
 } drm_i830_setparam_t;
 
 
-
-#endif /* _I830_DRM_H_ */
+#endif				/* _I830_DRM_H_ */

+ 30 - 32
drivers/char/drm/i830_drv.c

@@ -40,36 +40,34 @@
 
 
 #include "drm_pciids.h"
 #include "drm_pciids.h"
 
 
-static int postinit( struct drm_device *dev, unsigned long flags )
+static int postinit(struct drm_device *dev, unsigned long flags)
 {
 {
 	dev->counters += 4;
 	dev->counters += 4;
 	dev->types[6] = _DRM_STAT_IRQ;
 	dev->types[6] = _DRM_STAT_IRQ;
 	dev->types[7] = _DRM_STAT_PRIMARY;
 	dev->types[7] = _DRM_STAT_PRIMARY;
 	dev->types[8] = _DRM_STAT_SECONDARY;
 	dev->types[8] = _DRM_STAT_SECONDARY;
 	dev->types[9] = _DRM_STAT_DMA;
 	dev->types[9] = _DRM_STAT_DMA;
-	
-	DRM_INFO( "Initialized %s %d.%d.%d %s on minor %d: %s\n",
-		DRIVER_NAME,
-		DRIVER_MAJOR,
-		DRIVER_MINOR,
-		DRIVER_PATCHLEVEL,
-		DRIVER_DATE,
-		dev->primary.minor,
-		pci_pretty_name(dev->pdev)
-		);
+
+	DRM_INFO("Initialized %s %d.%d.%d %s on minor %d: %s\n",
+		 DRIVER_NAME,
+		 DRIVER_MAJOR,
+		 DRIVER_MINOR,
+		 DRIVER_PATCHLEVEL,
+		 DRIVER_DATE, dev->primary.minor, pci_pretty_name(dev->pdev)
+	    );
 	return 0;
 	return 0;
 }
 }
 
 
-static int version( drm_version_t *version )
+static int version(drm_version_t * version)
 {
 {
 	int len;
 	int len;
 
 
 	version->version_major = DRIVER_MAJOR;
 	version->version_major = DRIVER_MAJOR;
 	version->version_minor = DRIVER_MINOR;
 	version->version_minor = DRIVER_MINOR;
 	version->version_patchlevel = DRIVER_PATCHLEVEL;
 	version->version_patchlevel = DRIVER_PATCHLEVEL;
-	DRM_COPY( version->name, DRIVER_NAME );
-	DRM_COPY( version->date, DRIVER_DATE );
-	DRM_COPY( version->desc, DRIVER_DESC );
+	DRM_COPY(version->name, DRIVER_NAME);
+	DRM_COPY(version->date, DRIVER_DATE);
+	DRM_COPY(version->desc, DRIVER_DESC);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -77,11 +75,10 @@ static struct pci_device_id pciidlist[] = {
 	i830_PCI_IDS
 	i830_PCI_IDS
 };
 };
 
 
-extern drm_ioctl_desc_t i830_ioctls[];
-extern int i830_max_ioctl;
-
 static struct drm_driver driver = {
 static struct drm_driver driver = {
-	.driver_features = DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_DMA_QUEUE,
+	.driver_features =
+	    DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
+	    DRIVER_HAVE_DMA | DRIVER_DMA_QUEUE,
 #if USE_IRQS
 #if USE_IRQS
 	.driver_features |= DRIVER_HAVE_IRQ | DRIVER_SHARED_IRQ,
 	.driver_features |= DRIVER_HAVE_IRQ | DRIVER_SHARED_IRQ,
 #endif
 #endif
@@ -104,18 +101,19 @@ static struct drm_driver driver = {
 	.version = version,
 	.version = version,
 	.ioctls = i830_ioctls,
 	.ioctls = i830_ioctls,
 	.fops = {
 	.fops = {
-		.owner = THIS_MODULE,
-		.open = drm_open,
-		.release = drm_release,
-		.ioctl = drm_ioctl,
-		.mmap = drm_mmap,
-		.poll = drm_poll,
-		.fasync = drm_fasync,
-	},
+		 .owner = THIS_MODULE,
+		 .open = drm_open,
+		 .release = drm_release,
+		 .ioctl = drm_ioctl,
+		 .mmap = drm_mmap,
+		 .poll = drm_poll,
+		 .fasync = drm_fasync,
+		 }
+	,
 	.pci_driver = {
 	.pci_driver = {
-		.name          = DRIVER_NAME,
-		.id_table      = pciidlist,
-	}
+		       .name = DRIVER_NAME,
+		       .id_table = pciidlist,
+		       }
 
 
 };
 };
 
 
@@ -133,6 +131,6 @@ static void __exit i830_exit(void)
 module_init(i830_init);
 module_init(i830_init);
 module_exit(i830_exit);
 module_exit(i830_exit);
 
 
-MODULE_AUTHOR( DRIVER_AUTHOR );
-MODULE_DESCRIPTION( DRIVER_DESC );
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL and additional rights");
 MODULE_LICENSE("GPL and additional rights");

+ 37 - 46
drivers/char/drm/i830_drv.h

@@ -11,11 +11,11 @@
  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  * and/or sell copies of the Software, and to permit persons to whom the
  * and/or sell copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following conditions:
  * Software is furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice (including the next
  * The above copyright notice and this permission notice (including the next
  * paragraph) shall be included in all copies or substantial portions of the
  * paragraph) shall be included in all copies or substantial portions of the
  * Software.
  * Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
@@ -63,14 +63,14 @@
 #define USE_IRQS 0
 #define USE_IRQS 0
 
 
 typedef struct drm_i830_buf_priv {
 typedef struct drm_i830_buf_priv {
-   	u32 *in_use;
-   	int my_use_idx;
+	u32 *in_use;
+	int my_use_idx;
 	int currently_mapped;
 	int currently_mapped;
 	void __user *virtual;
 	void __user *virtual;
 	void *kernel_virtual;
 	void *kernel_virtual;
 } drm_i830_buf_priv_t;
 } drm_i830_buf_priv_t;
 
 
-typedef struct _drm_i830_ring_buffer{
+typedef struct _drm_i830_ring_buffer {
 	int tail_mask;
 	int tail_mask;
 	unsigned long Start;
 	unsigned long Start;
 	unsigned long End;
 	unsigned long End;
@@ -86,17 +86,17 @@ typedef struct drm_i830_private {
 	drm_map_t *mmio_map;
 	drm_map_t *mmio_map;
 
 
 	drm_i830_sarea_t *sarea_priv;
 	drm_i830_sarea_t *sarea_priv;
-   	drm_i830_ring_buffer_t ring;
+	drm_i830_ring_buffer_t ring;
 
 
-      	void * hw_status_page;
-   	unsigned long counter;
+	void *hw_status_page;
+	unsigned long counter;
 
 
 	dma_addr_t dma_status_page;
 	dma_addr_t dma_status_page;
 
 
 	drm_buf_t *mmap_buffer;
 	drm_buf_t *mmap_buffer;
-	
+
 	u32 front_di1, back_di1, zi1;
 	u32 front_di1, back_di1, zi1;
-	
+
 	int back_offset;
 	int back_offset;
 	int depth_offset;
 	int depth_offset;
 	int front_offset;
 	int front_offset;
@@ -113,43 +113,39 @@ typedef struct drm_i830_private {
 	int page_flipping;
 	int page_flipping;
 
 
 	wait_queue_head_t irq_queue;
 	wait_queue_head_t irq_queue;
-   	atomic_t irq_received;
-   	atomic_t irq_emitted;
+	atomic_t irq_received;
+	atomic_t irq_emitted;
 
 
 	int use_mi_batchbuffer_start;
 	int use_mi_batchbuffer_start;
 
 
 } drm_i830_private_t;
 } drm_i830_private_t;
 
 
+extern drm_ioctl_desc_t i830_ioctls[];
+extern int i830_max_ioctl;
+
 /* i830_dma.c */
 /* i830_dma.c */
-extern void i830_reclaim_buffers(drm_device_t *dev, struct file *filp);
+extern void i830_reclaim_buffers(drm_device_t * dev, struct file *filp);
 
 
 /* i830_irq.c */
 /* i830_irq.c */
-extern int i830_irq_emit( struct inode *inode, struct file *filp, 
-			  unsigned int cmd, unsigned long arg );
-extern int i830_irq_wait( struct inode *inode, struct file *filp,
-			  unsigned int cmd, unsigned long arg );
-
-extern irqreturn_t i830_driver_irq_handler( DRM_IRQ_ARGS );
-extern void i830_driver_irq_preinstall( drm_device_t *dev );
-extern void i830_driver_irq_postinstall( drm_device_t *dev );
-extern void i830_driver_irq_uninstall( drm_device_t *dev );
-extern void i830_driver_pretakedown(drm_device_t *dev);
-extern void i830_driver_release(drm_device_t *dev, struct file *filp);
-extern int i830_driver_dma_quiescent(drm_device_t *dev);
-extern void i830_driver_prerelease(drm_device_t *dev, DRMFILE filp);
+extern int i830_irq_emit(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg);
+extern int i830_irq_wait(struct inode *inode, struct file *filp,
+			 unsigned int cmd, unsigned long arg);
+
+extern irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS);
+extern void i830_driver_irq_preinstall(drm_device_t * dev);
+extern void i830_driver_irq_postinstall(drm_device_t * dev);
+extern void i830_driver_irq_uninstall(drm_device_t * dev);
+extern void i830_driver_pretakedown(drm_device_t * dev);
+extern void i830_driver_release(drm_device_t * dev, struct file *filp);
+extern int i830_driver_dma_quiescent(drm_device_t * dev);
+extern void i830_driver_prerelease(drm_device_t * dev, DRMFILE filp);
 extern int i830_driver_device_is_agp(drm_device_t * dev);
 extern int i830_driver_device_is_agp(drm_device_t * dev);
 
 
-#define I830_BASE(reg)		((unsigned long) \
-				dev_priv->mmio_map->handle)
-#define I830_ADDR(reg)		(I830_BASE(reg) + reg)
-#define I830_DEREF(reg)		*(__volatile__ unsigned int *)I830_ADDR(reg)
-#define I830_READ(reg)		readl((volatile u32 *)I830_ADDR(reg))
-#define I830_WRITE(reg,val) 	writel(val, (volatile u32 *)I830_ADDR(reg))
-#define I830_DEREF16(reg)	*(__volatile__ u16 *)I830_ADDR(reg)
-#define I830_READ16(reg) 	I830_DEREF16(reg)
-#define I830_WRITE16(reg,val)	do { I830_DEREF16(reg) = val; } while (0)
-
-
+#define I830_READ(reg)          DRM_READ32(dev_priv->mmio_map, reg)
+#define I830_WRITE(reg,val)     DRM_WRITE32(dev_priv->mmio_map, reg, val)
+#define I830_READ16(reg)        DRM_READ16(dev_priv->mmio_map, reg)
+#define I830_WRITE16(reg,val)   DRM_WRITE16(dev_priv->mmio_map, reg, val)
 
 
 #define I830_VERBOSE 0
 #define I830_VERBOSE 0
 
 
@@ -168,7 +164,6 @@ extern int i830_driver_device_is_agp(drm_device_t * dev);
 	virt = dev_priv->ring.virtual_start;		\
 	virt = dev_priv->ring.virtual_start;		\
 } while (0)
 } while (0)
 
 
-
 #define OUT_RING(n) do {					\
 #define OUT_RING(n) do {					\
 	if (I830_VERBOSE) printk("   OUT_RING %x\n", (int)(n));	\
 	if (I830_VERBOSE) printk("   OUT_RING %x\n", (int)(n));	\
 	*(volatile unsigned int *)(virt + outring) = n;		\
 	*(volatile unsigned int *)(virt + outring) = n;		\
@@ -184,8 +179,7 @@ extern int i830_driver_device_is_agp(drm_device_t * dev);
 	I830_WRITE(LP_RING + RING_TAIL, outring);			\
 	I830_WRITE(LP_RING + RING_TAIL, outring);			\
 } while(0)
 } while(0)
 
 
-extern int i830_wait_ring(drm_device_t *dev, int n, const char *caller);
-
+extern int i830_wait_ring(drm_device_t * dev, int n, const char *caller);
 
 
 #define GFX_OP_USER_INTERRUPT 		((0<<29)|(2<<23))
 #define GFX_OP_USER_INTERRUPT 		((0<<29)|(2<<23))
 #define GFX_OP_BREAKPOINT_INTERRUPT	((0<<29)|(1<<23))
 #define GFX_OP_BREAKPOINT_INTERRUPT	((0<<29)|(1<<23))
@@ -200,7 +194,6 @@ extern int i830_wait_ring(drm_device_t *dev, int n, const char *caller);
 #define INST_OP_FLUSH        0x02000000
 #define INST_OP_FLUSH        0x02000000
 #define INST_FLUSH_MAP_CACHE 0x00000001
 #define INST_FLUSH_MAP_CACHE 0x00000001
 
 
-
 #define BB1_START_ADDR_MASK   (~0x7)
 #define BB1_START_ADDR_MASK   (~0x7)
 #define BB1_PROTECTED         (1<<0)
 #define BB1_PROTECTED         (1<<0)
 #define BB1_UNPROTECTED       (0<<0)
 #define BB1_UNPROTECTED       (0<<0)
@@ -213,7 +206,6 @@ extern int i830_wait_ring(drm_device_t *dev, int n, const char *caller);
 
 
 #define I830_IRQ_RESERVED ((1<<13)|(3<<2))
 #define I830_IRQ_RESERVED ((1<<13)|(3<<2))
 
 
-
 #define LP_RING     		0x2030
 #define LP_RING     		0x2030
 #define HP_RING     		0x2040
 #define HP_RING     		0x2040
 #define RING_TAIL      		0x00
 #define RING_TAIL      		0x00
@@ -225,7 +217,7 @@ extern int i830_wait_ring(drm_device_t *dev, int n, const char *caller);
 #define RING_START     		0x08
 #define RING_START     		0x08
 #define START_ADDR          	0x0xFFFFF000
 #define START_ADDR          	0x0xFFFFF000
 #define RING_LEN       		0x0C
 #define RING_LEN       		0x0C
-#define RING_NR_PAGES       	0x001FF000 
+#define RING_NR_PAGES       	0x001FF000
 #define RING_REPORT_MASK    	0x00000006
 #define RING_REPORT_MASK    	0x00000006
 #define RING_REPORT_64K     	0x00000002
 #define RING_REPORT_64K     	0x00000002
 #define RING_REPORT_128K    	0x00000004
 #define RING_REPORT_128K    	0x00000004
@@ -291,10 +283,9 @@ extern int i830_wait_ring(drm_device_t *dev, int n, const char *caller);
 #define MI_BATCH_NON_SECURE	(1)
 #define MI_BATCH_NON_SECURE	(1)
 
 
 #define MI_WAIT_FOR_EVENT       ((0x3<<23))
 #define MI_WAIT_FOR_EVENT       ((0x3<<23))
-#define MI_WAIT_FOR_PLANE_A_FLIP      (1<<2) 
-#define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1) 
+#define MI_WAIT_FOR_PLANE_A_FLIP      (1<<2)
+#define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1)
 
 
 #define MI_LOAD_SCAN_LINES_INCL  ((0x12<<23))
 #define MI_LOAD_SCAN_LINES_INCL  ((0x12<<23))
 
 
 #endif
 #endif
-

+ 66 - 71
drivers/char/drm/i830_irq.c

@@ -9,11 +9,11 @@
  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  * and/or sell copies of the Software, and to permit persons to whom the
  * and/or sell copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following conditions:
  * Software is furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice (including the next
  * The above copyright notice and this permission notice (including the next
  * paragraph) shall be included in all copies or substantial portions of the
  * paragraph) shall be included in all copies or substantial portions of the
  * Software.
  * Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
@@ -33,28 +33,27 @@
 #include <linux/interrupt.h>	/* For task queue support */
 #include <linux/interrupt.h>	/* For task queue support */
 #include <linux/delay.h>
 #include <linux/delay.h>
 
 
-
-irqreturn_t i830_driver_irq_handler( DRM_IRQ_ARGS )
+irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS)
 {
 {
-	drm_device_t	 *dev = (drm_device_t *)arg;
-      	drm_i830_private_t *dev_priv = (drm_i830_private_t *)dev->dev_private;
-   	u16 temp;
+	drm_device_t *dev = (drm_device_t *) arg;
+	drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+	u16 temp;
 
 
-      	temp = I830_READ16(I830REG_INT_IDENTITY_R);
+	temp = I830_READ16(I830REG_INT_IDENTITY_R);
 	DRM_DEBUG("%x\n", temp);
 	DRM_DEBUG("%x\n", temp);
 
 
-   	if ( !( temp & 2 ) ) 
+	if (!(temp & 2))
 		return IRQ_NONE;
 		return IRQ_NONE;
 
 
-	I830_WRITE16(I830REG_INT_IDENTITY_R, temp); 
+	I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
 
 
 	atomic_inc(&dev_priv->irq_received);
 	atomic_inc(&dev_priv->irq_received);
-	wake_up_interruptible(&dev_priv->irq_queue); 
+	wake_up_interruptible(&dev_priv->irq_queue);
 
 
 	return IRQ_HANDLED;
 	return IRQ_HANDLED;
 }
 }
 
 
-static int i830_emit_irq(drm_device_t *dev)
+static int i830_emit_irq(drm_device_t * dev)
 {
 {
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	RING_LOCALS;
 	RING_LOCALS;
@@ -63,27 +62,25 @@ static int i830_emit_irq(drm_device_t *dev)
 
 
 	atomic_inc(&dev_priv->irq_emitted);
 	atomic_inc(&dev_priv->irq_emitted);
 
 
-   	BEGIN_LP_RING(2);
-      	OUT_RING( 0 );
-      	OUT_RING( GFX_OP_USER_INTERRUPT );
-      	ADVANCE_LP_RING();
+	BEGIN_LP_RING(2);
+	OUT_RING(0);
+	OUT_RING(GFX_OP_USER_INTERRUPT);
+	ADVANCE_LP_RING();
 
 
 	return atomic_read(&dev_priv->irq_emitted);
 	return atomic_read(&dev_priv->irq_emitted);
 }
 }
 
 
-
-static int i830_wait_irq(drm_device_t *dev, int irq_nr)
+static int i830_wait_irq(drm_device_t * dev, int irq_nr)
 {
 {
-  	drm_i830_private_t *dev_priv = 
-	   (drm_i830_private_t *)dev->dev_private;
+	drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
 	DECLARE_WAITQUEUE(entry, current);
 	DECLARE_WAITQUEUE(entry, current);
-	unsigned long end = jiffies + HZ*3;
+	unsigned long end = jiffies + HZ * 3;
 	int ret = 0;
 	int ret = 0;
 
 
 	DRM_DEBUG("%s\n", __FUNCTION__);
 	DRM_DEBUG("%s\n", __FUNCTION__);
 
 
- 	if (atomic_read(&dev_priv->irq_received) >= irq_nr)  
- 		return 0; 
+	if (atomic_read(&dev_priv->irq_received) >= irq_nr)
+		return 0;
 
 
 	dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
 	dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
 
 
@@ -91,21 +88,21 @@ static int i830_wait_irq(drm_device_t *dev, int irq_nr)
 
 
 	for (;;) {
 	for (;;) {
 		__set_current_state(TASK_INTERRUPTIBLE);
 		__set_current_state(TASK_INTERRUPTIBLE);
-	   	if (atomic_read(&dev_priv->irq_received) >= irq_nr) 
-		   break;
-		if((signed)(end - jiffies) <= 0) {
+		if (atomic_read(&dev_priv->irq_received) >= irq_nr)
+			break;
+		if ((signed)(end - jiffies) <= 0) {
 			DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
 			DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
-				  I830_READ16( I830REG_INT_IDENTITY_R ),
-				  I830_READ16( I830REG_INT_MASK_R ),
-				  I830_READ16( I830REG_INT_ENABLE_R ),
-				  I830_READ16( I830REG_HWSTAM ));
+				  I830_READ16(I830REG_INT_IDENTITY_R),
+				  I830_READ16(I830REG_INT_MASK_R),
+				  I830_READ16(I830REG_INT_ENABLE_R),
+				  I830_READ16(I830REG_HWSTAM));
 
 
-		   	ret = -EBUSY;	/* Lockup?  Missed irq? */
+			ret = -EBUSY;	/* Lockup?  Missed irq? */
 			break;
 			break;
 		}
 		}
-	      	schedule_timeout(HZ*3);
-	      	if (signal_pending(current)) {
-		   	ret = -EINTR;
+		schedule_timeout(HZ * 3);
+		if (signal_pending(current)) {
+			ret = -EINTR;
 			break;
 			break;
 		}
 		}
 	}
 	}
@@ -115,89 +112,87 @@ static int i830_wait_irq(drm_device_t *dev, int irq_nr)
 	return ret;
 	return ret;
 }
 }
 
 
-
 /* Needs the lock as it touches the ring.
 /* Needs the lock as it touches the ring.
  */
  */
-int i830_irq_emit( struct inode *inode, struct file *filp, unsigned int cmd,
-		   unsigned long arg )
+int i830_irq_emit(struct inode *inode, struct file *filp, unsigned int cmd,
+		  unsigned long arg)
 {
 {
-	drm_file_t	  *priv	    = filp->private_data;
-	drm_device_t	  *dev	    = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_irq_emit_t emit;
 	drm_i830_irq_emit_t emit;
 	int result;
 	int result;
 
 
 	LOCK_TEST_WITH_RETURN(dev, filp);
 	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
-	if ( !dev_priv ) {
-		DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ );
+	if (!dev_priv) {
+		DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	if (copy_from_user( &emit, (drm_i830_irq_emit_t __user *)arg, sizeof(emit) ))
+	if (copy_from_user
+	    (&emit, (drm_i830_irq_emit_t __user *) arg, sizeof(emit)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	result = i830_emit_irq( dev );
+	result = i830_emit_irq(dev);
 
 
-	if ( copy_to_user( emit.irq_seq, &result, sizeof(int) ) ) {
-		DRM_ERROR( "copy_to_user\n" );
+	if (copy_to_user(emit.irq_seq, &result, sizeof(int))) {
+		DRM_ERROR("copy_to_user\n");
 		return -EFAULT;
 		return -EFAULT;
 	}
 	}
 
 
 	return 0;
 	return 0;
 }
 }
 
 
-
 /* Doesn't need the hardware lock.
 /* Doesn't need the hardware lock.
  */
  */
-int i830_irq_wait( struct inode *inode, struct file *filp, unsigned int cmd,
-		   unsigned long arg )
+int i830_irq_wait(struct inode *inode, struct file *filp, unsigned int cmd,
+		  unsigned long arg)
 {
 {
-	drm_file_t	  *priv	    = filp->private_data;
-	drm_device_t	  *dev	    = priv->head->dev;
+	drm_file_t *priv = filp->private_data;
+	drm_device_t *dev = priv->head->dev;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_private_t *dev_priv = dev->dev_private;
 	drm_i830_irq_wait_t irqwait;
 	drm_i830_irq_wait_t irqwait;
 
 
-	if ( !dev_priv ) {
-		DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ );
+	if (!dev_priv) {
+		DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	if (copy_from_user( &irqwait, (drm_i830_irq_wait_t __user *)arg, 
-			    sizeof(irqwait) ))
+	if (copy_from_user(&irqwait, (drm_i830_irq_wait_t __user *) arg,
+			   sizeof(irqwait)))
 		return -EFAULT;
 		return -EFAULT;
 
 
-	return i830_wait_irq( dev, irqwait.irq_seq );
+	return i830_wait_irq(dev, irqwait.irq_seq);
 }
 }
 
 
-
 /* drm_dma.h hooks
 /* drm_dma.h hooks
 */
 */
-void i830_driver_irq_preinstall( drm_device_t *dev ) {
-	drm_i830_private_t *dev_priv =
-		(drm_i830_private_t *)dev->dev_private;
+void i830_driver_irq_preinstall(drm_device_t * dev)
+{
+	drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
 
 
-	I830_WRITE16( I830REG_HWSTAM, 0xffff );
-	I830_WRITE16( I830REG_INT_MASK_R, 0x0 );
-	I830_WRITE16( I830REG_INT_ENABLE_R, 0x0 );
+	I830_WRITE16(I830REG_HWSTAM, 0xffff);
+	I830_WRITE16(I830REG_INT_MASK_R, 0x0);
+	I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
 	atomic_set(&dev_priv->irq_received, 0);
 	atomic_set(&dev_priv->irq_received, 0);
 	atomic_set(&dev_priv->irq_emitted, 0);
 	atomic_set(&dev_priv->irq_emitted, 0);
 	init_waitqueue_head(&dev_priv->irq_queue);
 	init_waitqueue_head(&dev_priv->irq_queue);
 }
 }
 
 
-void i830_driver_irq_postinstall( drm_device_t *dev ) {
-	drm_i830_private_t *dev_priv =
-		(drm_i830_private_t *)dev->dev_private;
+void i830_driver_irq_postinstall(drm_device_t * dev)
+{
+	drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
 
 
-	I830_WRITE16( I830REG_INT_ENABLE_R, 0x2 );
+	I830_WRITE16(I830REG_INT_ENABLE_R, 0x2);
 }
 }
 
 
-void i830_driver_irq_uninstall( drm_device_t *dev ) {
-	drm_i830_private_t *dev_priv =
-		(drm_i830_private_t *)dev->dev_private;
+void i830_driver_irq_uninstall(drm_device_t * dev)
+{
+	drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
 	if (!dev_priv)
 	if (!dev_priv)
 		return;
 		return;
 
 
-	I830_WRITE16( I830REG_INT_MASK_R, 0xffff );
-	I830_WRITE16( I830REG_INT_ENABLE_R, 0x0 );
+	I830_WRITE16(I830REG_INT_MASK_R, 0xffff);
+	I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
 }
 }

+ 16 - 16
drivers/char/drm/i915_dma.c

@@ -85,14 +85,14 @@ static int i915_dma_cleanup(drm_device_t * dev)
 	 * is freed, it's too late.
 	 * is freed, it's too late.
 	 */
 	 */
 	if (dev->irq)
 	if (dev->irq)
-		drm_irq_uninstall (dev);
+		drm_irq_uninstall(dev);
 
 
 	if (dev->dev_private) {
 	if (dev->dev_private) {
 		drm_i915_private_t *dev_priv =
 		drm_i915_private_t *dev_priv =
 		    (drm_i915_private_t *) dev->dev_private;
 		    (drm_i915_private_t *) dev->dev_private;
 
 
 		if (dev_priv->ring.virtual_start) {
 		if (dev_priv->ring.virtual_start) {
-			drm_core_ioremapfree( &dev_priv->ring.map, dev);
+			drm_core_ioremapfree(&dev_priv->ring.map, dev);
 		}
 		}
 
 
 		if (dev_priv->status_page_dmah) {
 		if (dev_priv->status_page_dmah) {
@@ -101,8 +101,8 @@ static int i915_dma_cleanup(drm_device_t * dev)
 			I915_WRITE(0x02080, 0x1ffff000);
 			I915_WRITE(0x02080, 0x1ffff000);
 		}
 		}
 
 
-		drm_free (dev->dev_private, sizeof(drm_i915_private_t),
-			   DRM_MEM_DRIVER);
+		drm_free(dev->dev_private, sizeof(drm_i915_private_t),
+			 DRM_MEM_DRIVER);
 
 
 		dev->dev_private = NULL;
 		dev->dev_private = NULL;
 	}
 	}
@@ -146,7 +146,7 @@ static int i915_initialize(drm_device_t * dev,
 	dev_priv->ring.map.flags = 0;
 	dev_priv->ring.map.flags = 0;
 	dev_priv->ring.map.mtrr = 0;
 	dev_priv->ring.map.mtrr = 0;
 
 
-	drm_core_ioremap( &dev_priv->ring.map, dev );
+	drm_core_ioremap(&dev_priv->ring.map, dev);
 
 
 	if (dev_priv->ring.map.handle == NULL) {
 	if (dev_priv->ring.map.handle == NULL) {
 		dev->dev_private = (void *)dev_priv;
 		dev->dev_private = (void *)dev_priv;
@@ -243,8 +243,8 @@ static int i915_dma_init(DRM_IOCTL_ARGS)
 
 
 	switch (init.func) {
 	switch (init.func) {
 	case I915_INIT_DMA:
 	case I915_INIT_DMA:
-		dev_priv = drm_alloc (sizeof(drm_i915_private_t),
-				       DRM_MEM_DRIVER);
+		dev_priv = drm_alloc(sizeof(drm_i915_private_t),
+				     DRM_MEM_DRIVER);
 		if (dev_priv == NULL)
 		if (dev_priv == NULL)
 			return DRM_ERR(ENOMEM);
 			return DRM_ERR(ENOMEM);
 		retcode = i915_initialize(dev, dev_priv, &init);
 		retcode = i915_initialize(dev, dev_priv, &init);
@@ -297,7 +297,7 @@ static int do_validate_cmd(int cmd)
 		case 0x1c:
 		case 0x1c:
 			return 1;
 			return 1;
 		case 0x1d:
 		case 0x1d:
-			switch ((cmd>>16)&0xff) {
+			switch ((cmd >> 16) & 0xff) {
 			case 0x3:
 			case 0x3:
 				return (cmd & 0x1f) + 2;
 				return (cmd & 0x1f) + 2;
 			case 0x4:
 			case 0x4:
@@ -699,20 +699,20 @@ static int i915_setparam(DRM_IOCTL_ARGS)
 	return 0;
 	return 0;
 }
 }
 
 
-void i915_driver_pretakedown(drm_device_t *dev)
+void i915_driver_pretakedown(drm_device_t * dev)
 {
 {
-	if ( dev->dev_private ) {
+	if (dev->dev_private) {
 		drm_i915_private_t *dev_priv = dev->dev_private;
 		drm_i915_private_t *dev_priv = dev->dev_private;
-	        i915_mem_takedown( &(dev_priv->agp_heap) );
- 	}
-	i915_dma_cleanup( dev );
+		i915_mem_takedown(&(dev_priv->agp_heap));
+	}
+	i915_dma_cleanup(dev);
 }
 }
 
 
-void i915_driver_prerelease(drm_device_t *dev, DRMFILE filp)
+void i915_driver_prerelease(drm_device_t * dev, DRMFILE filp)
 {
 {
-	if ( dev->dev_private ) {
+	if (dev->dev_private) {
 		drm_i915_private_t *dev_priv = dev->dev_private;
 		drm_i915_private_t *dev_priv = dev->dev_private;
-                i915_mem_release( dev, filp, dev_priv->agp_heap );
+		i915_mem_release(dev, filp, dev_priv->agp_heap);
 	}
 	}
 }
 }
 
 

+ 30 - 34
drivers/char/drm/i915_drv.c

@@ -34,36 +34,34 @@
 
 
 #include "drm_pciids.h"
 #include "drm_pciids.h"
 
 
-static int postinit( struct drm_device *dev, unsigned long flags )
+static int postinit(struct drm_device *dev, unsigned long flags)
 {
 {
 	dev->counters += 4;
 	dev->counters += 4;
 	dev->types[6] = _DRM_STAT_IRQ;
 	dev->types[6] = _DRM_STAT_IRQ;
 	dev->types[7] = _DRM_STAT_PRIMARY;
 	dev->types[7] = _DRM_STAT_PRIMARY;
 	dev->types[8] = _DRM_STAT_SECONDARY;
 	dev->types[8] = _DRM_STAT_SECONDARY;
 	dev->types[9] = _DRM_STAT_DMA;
 	dev->types[9] = _DRM_STAT_DMA;
-	
-	DRM_INFO( "Initialized %s %d.%d.%d %s on minor %d: %s\n",
-		DRIVER_NAME,
-		DRIVER_MAJOR,
-		DRIVER_MINOR,
-		DRIVER_PATCHLEVEL,
-		DRIVER_DATE,
-		dev->primary.minor,
-		pci_pretty_name(dev->pdev)
-		);
+
+	DRM_INFO("Initialized %s %d.%d.%d %s on minor %d: %s\n",
+		 DRIVER_NAME,
+		 DRIVER_MAJOR,
+		 DRIVER_MINOR,
+		 DRIVER_PATCHLEVEL,
+		 DRIVER_DATE, dev->primary.minor, pci_pretty_name(dev->pdev)
+	    );
 	return 0;
 	return 0;
 }
 }
 
 
-static int version( drm_version_t *version )
+static int version(drm_version_t * version)
 {
 {
 	int len;
 	int len;
 
 
 	version->version_major = DRIVER_MAJOR;
 	version->version_major = DRIVER_MAJOR;
 	version->version_minor = DRIVER_MINOR;
 	version->version_minor = DRIVER_MINOR;
 	version->version_patchlevel = DRIVER_PATCHLEVEL;
 	version->version_patchlevel = DRIVER_PATCHLEVEL;
-	DRM_COPY( version->name, DRIVER_NAME );
-	DRM_COPY( version->date, DRIVER_DATE );
-	DRM_COPY( version->desc, DRIVER_DESC );
+	DRM_COPY(version->name, DRIVER_NAME);
+	DRM_COPY(version->date, DRIVER_DATE);
+	DRM_COPY(version->desc, DRIVER_DESC);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -71,12 +69,10 @@ static struct pci_device_id pciidlist[] = {
 	i915_PCI_IDS
 	i915_PCI_IDS
 };
 };
 
 
-extern drm_ioctl_desc_t i915_ioctls[];
-extern int i915_max_ioctl;
-
 static struct drm_driver driver = {
 static struct drm_driver driver = {
-	.driver_features = DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
-				DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED,
+	.driver_features =
+	    DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
+	    DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED,
 	.pretakedown = i915_driver_pretakedown,
 	.pretakedown = i915_driver_pretakedown,
 	.prerelease = i915_driver_prerelease,
 	.prerelease = i915_driver_prerelease,
 	.device_is_agp = i915_driver_device_is_agp,
 	.device_is_agp = i915_driver_device_is_agp,
@@ -91,21 +87,21 @@ static struct drm_driver driver = {
 	.version = version,
 	.version = version,
 	.ioctls = i915_ioctls,
 	.ioctls = i915_ioctls,
 	.fops = {
 	.fops = {
-		.owner = THIS_MODULE,
-		.open = drm_open,
-		.release = drm_release,
-		.ioctl = drm_ioctl,
-		.mmap = drm_mmap,
-		.poll = drm_poll,
-		.fasync = drm_fasync,
+		 .owner = THIS_MODULE,
+		 .open = drm_open,
+		 .release = drm_release,
+		 .ioctl = drm_ioctl,
+		 .mmap = drm_mmap,
+		 .poll = drm_poll,
+		 .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 #ifdef CONFIG_COMPAT
-		.compat_ioctl = i915_compat_ioctl,
+		 .compat_ioctl = i915_compat_ioctl,
 #endif
 #endif
-	},
+		 },
 	.pci_driver = {
 	.pci_driver = {
-		.name          = DRIVER_NAME,
-		.id_table      = pciidlist,
-	}
+		       .name = DRIVER_NAME,
+		       .id_table = pciidlist,
+		       }
 };
 };
 
 
 static int __init i915_init(void)
 static int __init i915_init(void)
@@ -122,6 +118,6 @@ static void __exit i915_exit(void)
 module_init(i915_init);
 module_init(i915_init);
 module_exit(i915_exit);
 module_exit(i915_exit);
 
 
-MODULE_AUTHOR( DRIVER_AUTHOR );
-MODULE_DESCRIPTION( DRIVER_DESC );
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL and additional rights");
 MODULE_LICENSE("GPL and additional rights");

+ 9 - 7
drivers/char/drm/i915_drv.h

@@ -99,20 +99,23 @@ typedef struct drm_i915_private {
 	struct mem_block *agp_heap;
 	struct mem_block *agp_heap;
 } drm_i915_private_t;
 } drm_i915_private_t;
 
 
+extern drm_ioctl_desc_t i915_ioctls[];
+extern int i915_max_ioctl;
+
 				/* i915_dma.c */
 				/* i915_dma.c */
 extern void i915_kernel_lost_context(drm_device_t * dev);
 extern void i915_kernel_lost_context(drm_device_t * dev);
-extern void i915_driver_pretakedown(drm_device_t *dev);
-extern void i915_driver_prerelease(drm_device_t *dev, DRMFILE filp);
-extern int i915_driver_device_is_agp(drm_device_t *dev);
+extern void i915_driver_pretakedown(drm_device_t * dev);
+extern void i915_driver_prerelease(drm_device_t * dev, DRMFILE filp);
+extern int i915_driver_device_is_agp(drm_device_t * dev);
 
 
 /* i915_irq.c */
 /* i915_irq.c */
 extern int i915_irq_emit(DRM_IOCTL_ARGS);
 extern int i915_irq_emit(DRM_IOCTL_ARGS);
 extern int i915_irq_wait(DRM_IOCTL_ARGS);
 extern int i915_irq_wait(DRM_IOCTL_ARGS);
 
 
 extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
 extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
-extern void i915_driver_irq_preinstall(drm_device_t *dev);
-extern void i915_driver_irq_postinstall(drm_device_t *dev);
-extern void i915_driver_irq_uninstall(drm_device_t *dev);
+extern void i915_driver_irq_preinstall(drm_device_t * dev);
+extern void i915_driver_irq_postinstall(drm_device_t * dev);
+extern void i915_driver_irq_uninstall(drm_device_t * dev);
 
 
 /* i915_mem.c */
 /* i915_mem.c */
 extern int i915_mem_alloc(DRM_IOCTL_ARGS);
 extern int i915_mem_alloc(DRM_IOCTL_ARGS);
@@ -125,7 +128,6 @@ extern void i915_mem_release(drm_device_t * dev,
 extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
 extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
 			      unsigned long arg);
 			      unsigned long arg);
 
 
-
 #define I915_READ(reg)          DRM_READ32(dev_priv->mmio_map, reg)
 #define I915_READ(reg)          DRM_READ32(dev_priv->mmio_map, reg)
 #define I915_WRITE(reg,val)     DRM_WRITE32(dev_priv->mmio_map, reg, val)
 #define I915_WRITE(reg,val)     DRM_WRITE32(dev_priv->mmio_map, reg, val)
 #define I915_READ16(reg) 	DRM_READ16(dev_priv->mmio_map, reg)
 #define I915_READ16(reg) 	DRM_READ16(dev_priv->mmio_map, reg)

+ 33 - 31
drivers/char/drm/i915_ioc32.c

@@ -3,7 +3,7 @@
  *
  *
  * 32-bit ioctl compatibility routines for the i915 DRM.
  * 32-bit ioctl compatibility routines for the i915 DRM.
  *
  *
- * \author Alan Hourihane <alanh@fairlite.demon.co.uk> 
+ * \author Alan Hourihane <alanh@fairlite.demon.co.uk>
  *
  *
  *
  *
  * Copyright (C) Paul Mackerras 2005
  * Copyright (C) Paul Mackerras 2005
@@ -42,51 +42,55 @@ typedef struct _drm_i915_batchbuffer32 {
 	int DR1;		/* hw flags for GFX_OP_DRAWRECT_INFO */
 	int DR1;		/* hw flags for GFX_OP_DRAWRECT_INFO */
 	int DR4;		/* window origin for GFX_OP_DRAWRECT_INFO */
 	int DR4;		/* window origin for GFX_OP_DRAWRECT_INFO */
 	int num_cliprects;	/* mulitpass with multiple cliprects? */
 	int num_cliprects;	/* mulitpass with multiple cliprects? */
-	u32 cliprects;	/* pointer to userspace cliprects */
+	u32 cliprects;		/* pointer to userspace cliprects */
 } drm_i915_batchbuffer32_t;
 } drm_i915_batchbuffer32_t;
 
 
 static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
 static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
-			   unsigned long arg)
+				   unsigned long arg)
 {
 {
 	drm_i915_batchbuffer32_t batchbuffer32;
 	drm_i915_batchbuffer32_t batchbuffer32;
 	drm_i915_batchbuffer_t __user *batchbuffer;
 	drm_i915_batchbuffer_t __user *batchbuffer;
-	
-	if (copy_from_user(&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32)))
+
+	if (copy_from_user
+	    (&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32)))
 		return -EFAULT;
 		return -EFAULT;
-	
+
 	batchbuffer = compat_alloc_user_space(sizeof(*batchbuffer));
 	batchbuffer = compat_alloc_user_space(sizeof(*batchbuffer));
 	if (!access_ok(VERIFY_WRITE, batchbuffer, sizeof(*batchbuffer))
 	if (!access_ok(VERIFY_WRITE, batchbuffer, sizeof(*batchbuffer))
 	    || __put_user(batchbuffer32.start, &batchbuffer->start)
 	    || __put_user(batchbuffer32.start, &batchbuffer->start)
 	    || __put_user(batchbuffer32.used, &batchbuffer->used)
 	    || __put_user(batchbuffer32.used, &batchbuffer->used)
 	    || __put_user(batchbuffer32.DR1, &batchbuffer->DR1)
 	    || __put_user(batchbuffer32.DR1, &batchbuffer->DR1)
 	    || __put_user(batchbuffer32.DR4, &batchbuffer->DR4)
 	    || __put_user(batchbuffer32.DR4, &batchbuffer->DR4)
-	    || __put_user(batchbuffer32.num_cliprects, &batchbuffer->num_cliprects)
+	    || __put_user(batchbuffer32.num_cliprects,
+			  &batchbuffer->num_cliprects)
 	    || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects,
 	    || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects,
 			  &batchbuffer->cliprects))
 			  &batchbuffer->cliprects))
 		return -EFAULT;
 		return -EFAULT;
-	
+
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_I915_BATCHBUFFER, (unsigned long) batchbuffer);
+			 DRM_IOCTL_I915_BATCHBUFFER,
+			 (unsigned long)batchbuffer);
 }
 }
 
 
 typedef struct _drm_i915_cmdbuffer32 {
 typedef struct _drm_i915_cmdbuffer32 {
-	u32 buf;	/* pointer to userspace command buffer */
+	u32 buf;		/* pointer to userspace command buffer */
 	int sz;			/* nr bytes in buf */
 	int sz;			/* nr bytes in buf */
 	int DR1;		/* hw flags for GFX_OP_DRAWRECT_INFO */
 	int DR1;		/* hw flags for GFX_OP_DRAWRECT_INFO */
 	int DR4;		/* window origin for GFX_OP_DRAWRECT_INFO */
 	int DR4;		/* window origin for GFX_OP_DRAWRECT_INFO */
 	int num_cliprects;	/* mulitpass with multiple cliprects? */
 	int num_cliprects;	/* mulitpass with multiple cliprects? */
-	u32 cliprects;	/* pointer to userspace cliprects */
+	u32 cliprects;		/* pointer to userspace cliprects */
 } drm_i915_cmdbuffer32_t;
 } drm_i915_cmdbuffer32_t;
 
 
 static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
 static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
-			   unsigned long arg)
+				 unsigned long arg)
 {
 {
 	drm_i915_cmdbuffer32_t cmdbuffer32;
 	drm_i915_cmdbuffer32_t cmdbuffer32;
 	drm_i915_cmdbuffer_t __user *cmdbuffer;
 	drm_i915_cmdbuffer_t __user *cmdbuffer;
-	
-	if (copy_from_user(&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32)))
+
+	if (copy_from_user
+	    (&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32)))
 		return -EFAULT;
 		return -EFAULT;
-	
+
 	cmdbuffer = compat_alloc_user_space(sizeof(*cmdbuffer));
 	cmdbuffer = compat_alloc_user_space(sizeof(*cmdbuffer));
 	if (!access_ok(VERIFY_WRITE, cmdbuffer, sizeof(*cmdbuffer))
 	if (!access_ok(VERIFY_WRITE, cmdbuffer, sizeof(*cmdbuffer))
 	    || __put_user((int __user *)(unsigned long)cmdbuffer32.buf,
 	    || __put_user((int __user *)(unsigned long)cmdbuffer32.buf,
@@ -98,9 +102,9 @@ static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
 	    || __put_user((int __user *)(unsigned long)cmdbuffer32.cliprects,
 	    || __put_user((int __user *)(unsigned long)cmdbuffer32.cliprects,
 			  &cmdbuffer->cliprects))
 			  &cmdbuffer->cliprects))
 		return -EFAULT;
 		return -EFAULT;
-	
+
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_I915_CMDBUFFER, (unsigned long) cmdbuffer);
+			 DRM_IOCTL_I915_CMDBUFFER, (unsigned long)cmdbuffer);
 }
 }
 
 
 typedef struct drm_i915_irq_emit32 {
 typedef struct drm_i915_irq_emit32 {
@@ -108,12 +112,12 @@ typedef struct drm_i915_irq_emit32 {
 } drm_i915_irq_emit32_t;
 } drm_i915_irq_emit32_t;
 
 
 static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
 static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
-				  unsigned long arg)
+				unsigned long arg)
 {
 {
 	drm_i915_irq_emit32_t req32;
 	drm_i915_irq_emit32_t req32;
 	drm_i915_irq_emit_t __user *request;
 	drm_i915_irq_emit_t __user *request;
 
 
-	if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
+	if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	request = compat_alloc_user_space(sizeof(*request));
 	request = compat_alloc_user_space(sizeof(*request));
@@ -123,7 +127,7 @@ static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_I915_IRQ_EMIT, (unsigned long) request);
+			 DRM_IOCTL_I915_IRQ_EMIT, (unsigned long)request);
 }
 }
 typedef struct drm_i915_getparam32 {
 typedef struct drm_i915_getparam32 {
 	int param;
 	int param;
@@ -131,12 +135,12 @@ typedef struct drm_i915_getparam32 {
 } drm_i915_getparam32_t;
 } drm_i915_getparam32_t;
 
 
 static int compat_i915_getparam(struct file *file, unsigned int cmd,
 static int compat_i915_getparam(struct file *file, unsigned int cmd,
-				     unsigned long arg)
+				unsigned long arg)
 {
 {
 	drm_i915_getparam32_t req32;
 	drm_i915_getparam32_t req32;
 	drm_i915_getparam_t __user *request;
 	drm_i915_getparam_t __user *request;
 
 
-	if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
+	if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	request = compat_alloc_user_space(sizeof(*request));
 	request = compat_alloc_user_space(sizeof(*request));
@@ -147,7 +151,7 @@ static int compat_i915_getparam(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_I915_GETPARAM, (unsigned long) request);
+			 DRM_IOCTL_I915_GETPARAM, (unsigned long)request);
 }
 }
 
 
 typedef struct drm_i915_mem_alloc32 {
 typedef struct drm_i915_mem_alloc32 {
@@ -158,12 +162,12 @@ typedef struct drm_i915_mem_alloc32 {
 } drm_i915_mem_alloc32_t;
 } drm_i915_mem_alloc32_t;
 
 
 static int compat_i915_alloc(struct file *file, unsigned int cmd,
 static int compat_i915_alloc(struct file *file, unsigned int cmd,
-				     unsigned long arg)
+			     unsigned long arg)
 {
 {
 	drm_i915_mem_alloc32_t req32;
 	drm_i915_mem_alloc32_t req32;
 	drm_i915_mem_alloc_t __user *request;
 	drm_i915_mem_alloc_t __user *request;
 
 
-	if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
+	if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
 		return -EFAULT;
 		return -EFAULT;
 
 
 	request = compat_alloc_user_space(sizeof(*request));
 	request = compat_alloc_user_space(sizeof(*request));
@@ -176,10 +180,9 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
 		return -EFAULT;
 		return -EFAULT;
 
 
 	return drm_ioctl(file->f_dentry->d_inode, file,
 	return drm_ioctl(file->f_dentry->d_inode, file,
-			 DRM_IOCTL_I915_ALLOC, (unsigned long) request);
+			 DRM_IOCTL_I915_ALLOC, (unsigned long)request);
 }
 }
 
 
-
 drm_ioctl_compat_t *i915_compat_ioctls[] = {
 drm_ioctl_compat_t *i915_compat_ioctls[] = {
 	[DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
 	[DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
 	[DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
 	[DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
@@ -197,8 +200,7 @@ drm_ioctl_compat_t *i915_compat_ioctls[] = {
  * \param arg user argument.
  * \param arg user argument.
  * \return zero on success or negative number on failure.
  * \return zero on success or negative number on failure.
  */
  */
-long i915_compat_ioctl(struct file *filp, unsigned int cmd,
-			 unsigned long arg)
+long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 {
 	unsigned int nr = DRM_IOCTL_NR(cmd);
 	unsigned int nr = DRM_IOCTL_NR(cmd);
 	drm_ioctl_compat_t *fn = NULL;
 	drm_ioctl_compat_t *fn = NULL;
@@ -206,13 +208,13 @@ long i915_compat_ioctl(struct file *filp, unsigned int cmd,
 
 
 	if (nr < DRM_COMMAND_BASE)
 	if (nr < DRM_COMMAND_BASE)
 		return drm_compat_ioctl(filp, cmd, arg);
 		return drm_compat_ioctl(filp, cmd, arg);
-	
+
 	if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
 	if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
 		fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
 		fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
 
 
 	lock_kernel();		/* XXX for now */
 	lock_kernel();		/* XXX for now */
 	if (fn != NULL)
 	if (fn != NULL)
-		ret = (*fn)(filp, cmd, arg);
+		ret = (*fn) (filp, cmd, arg);
 	else
 	else
 		ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
 		ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
 	unlock_kernel();
 	unlock_kernel();

+ 5 - 3
drivers/char/drm/i915_mem.c

@@ -86,7 +86,7 @@ static void mark_block(drm_device_t * dev, struct mem_block *p, int in_use)
 }
 }
 
 
 /* Very simple allocator for agp memory, working on a static range
 /* Very simple allocator for agp memory, working on a static range
- * already mapped into each client's address space.  
+ * already mapped into each client's address space.
  */
  */
 
 
 static struct mem_block *split_block(struct mem_block *p, int start, int size,
 static struct mem_block *split_block(struct mem_block *p, int start, int size,
@@ -94,7 +94,8 @@ static struct mem_block *split_block(struct mem_block *p, int start, int size,
 {
 {
 	/* Maybe cut off the start of an existing block */
 	/* Maybe cut off the start of an existing block */
 	if (start > p->start) {
 	if (start > p->start) {
-		struct mem_block *newblock = drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS);
+		struct mem_block *newblock =
+		    drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS);
 		if (!newblock)
 		if (!newblock)
 			goto out;
 			goto out;
 		newblock->start = start;
 		newblock->start = start;
@@ -110,7 +111,8 @@ static struct mem_block *split_block(struct mem_block *p, int start, int size,
 
 
 	/* Maybe cut off the end of an existing block */
 	/* Maybe cut off the end of an existing block */
 	if (size < p->size) {
 	if (size < p->size) {
-		struct mem_block *newblock = drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS);
+		struct mem_block *newblock =
+		    drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS);
 		if (!newblock)
 		if (!newblock)
 			goto out;
 			goto out;
 		newblock->start = start + size;
 		newblock->start = start + size;

+ 244 - 267
drivers/char/drm/mga_dma.c

@@ -28,7 +28,7 @@
 /**
 /**
  * \file mga_dma.c
  * \file mga_dma.c
  * DMA support for MGA G200 / G400.
  * DMA support for MGA G200 / G400.
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Jeff Hartmann <jhartmann@valinux.com>
  * \author Jeff Hartmann <jhartmann@valinux.com>
  * \author Keith Whitwell <keith@tungstengraphics.com>
  * \author Keith Whitwell <keith@tungstengraphics.com>
@@ -44,40 +44,40 @@
 #define MGA_DEFAULT_USEC_TIMEOUT	10000
 #define MGA_DEFAULT_USEC_TIMEOUT	10000
 #define MGA_FREELIST_DEBUG		0
 #define MGA_FREELIST_DEBUG		0
 
 
-static int mga_do_cleanup_dma( drm_device_t *dev );
+static int mga_do_cleanup_dma(drm_device_t * dev);
 
 
 /* ================================================================
 /* ================================================================
  * Engine control
  * Engine control
  */
  */
 
 
-int mga_do_wait_for_idle( drm_mga_private_t *dev_priv )
+int mga_do_wait_for_idle(drm_mga_private_t * dev_priv)
 {
 {
 	u32 status = 0;
 	u32 status = 0;
 	int i;
 	int i;
-	DRM_DEBUG( "\n" );
+	DRM_DEBUG("\n");
 
 
-	for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) {
-		status = MGA_READ( MGA_STATUS ) & MGA_ENGINE_IDLE_MASK;
-		if ( status == MGA_ENDPRDMASTS ) {
-			MGA_WRITE8( MGA_CRTC_INDEX, 0 );
+	for (i = 0; i < dev_priv->usec_timeout; i++) {
+		status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
+		if (status == MGA_ENDPRDMASTS) {
+			MGA_WRITE8(MGA_CRTC_INDEX, 0);
 			return 0;
 			return 0;
 		}
 		}
-		DRM_UDELAY( 1 );
+		DRM_UDELAY(1);
 	}
 	}
 
 
 #if MGA_DMA_DEBUG
 #if MGA_DMA_DEBUG
-	DRM_ERROR( "failed!\n" );
-	DRM_INFO( "   status=0x%08x\n", status );
+	DRM_ERROR("failed!\n");
+	DRM_INFO("   status=0x%08x\n", status);
 #endif
 #endif
 	return DRM_ERR(EBUSY);
 	return DRM_ERR(EBUSY);
 }
 }
 
 
-static int mga_do_dma_reset( drm_mga_private_t *dev_priv )
+static int mga_do_dma_reset(drm_mga_private_t * dev_priv)
 {
 {
 	drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
 	drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
 	drm_mga_primary_buffer_t *primary = &dev_priv->prim;
 	drm_mga_primary_buffer_t *primary = &dev_priv->prim;
 
 
-	DRM_DEBUG( "\n" );
+	DRM_DEBUG("\n");
 
 
 	/* The primary DMA stream should look like new right about now.
 	/* The primary DMA stream should look like new right about now.
 	 */
 	 */
@@ -100,24 +100,25 @@ static int mga_do_dma_reset( drm_mga_private_t *dev_priv )
  * Primary DMA stream
  * Primary DMA stream
  */
  */
 
 
-void mga_do_dma_flush( drm_mga_private_t *dev_priv )
+void mga_do_dma_flush(drm_mga_private_t * dev_priv)
 {
 {
 	drm_mga_primary_buffer_t *primary = &dev_priv->prim;
 	drm_mga_primary_buffer_t *primary = &dev_priv->prim;
 	u32 head, tail;
 	u32 head, tail;
 	u32 status = 0;
 	u32 status = 0;
 	int i;
 	int i;
- 	DMA_LOCALS;
-	DRM_DEBUG( "\n" );
-
-        /* We need to wait so that we can do an safe flush */
-	for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) {
-		status = MGA_READ( MGA_STATUS ) & MGA_ENGINE_IDLE_MASK;
-		if ( status == MGA_ENDPRDMASTS ) break;
-		DRM_UDELAY( 1 );
+	DMA_LOCALS;
+	DRM_DEBUG("\n");
+
+	/* We need to wait so that we can do an safe flush */
+	for (i = 0; i < dev_priv->usec_timeout; i++) {
+		status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
+		if (status == MGA_ENDPRDMASTS)
+			break;
+		DRM_UDELAY(1);
 	}
 	}
 
 
-	if ( primary->tail == primary->last_flush ) {
-		DRM_DEBUG( "   bailing out...\n" );
+	if (primary->tail == primary->last_flush) {
+		DRM_DEBUG("   bailing out...\n");
 		return;
 		return;
 	}
 	}
 
 
@@ -127,48 +128,46 @@ void mga_do_dma_flush( drm_mga_private_t *dev_priv )
 	 * actually (partially?) reads the first of these commands.
 	 * actually (partially?) reads the first of these commands.
 	 * See page 4-16 in the G400 manual, middle of the page or so.
 	 * See page 4-16 in the G400 manual, middle of the page or so.
 	 */
 	 */
-	BEGIN_DMA( 1 );
+	BEGIN_DMA(1);
 
 
-	DMA_BLOCK( MGA_DMAPAD,  0x00000000,
-		   MGA_DMAPAD,  0x00000000,
-		   MGA_DMAPAD,  0x00000000,
-		   MGA_DMAPAD,	0x00000000 );
+	DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+		  MGA_DMAPAD, 0x00000000,
+		  MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
 
 
 	ADVANCE_DMA();
 	ADVANCE_DMA();
 
 
 	primary->last_flush = primary->tail;
 	primary->last_flush = primary->tail;
 
 
-	head = MGA_READ( MGA_PRIMADDRESS );
+	head = MGA_READ(MGA_PRIMADDRESS);
 
 
-	if ( head <= tail ) {
+	if (head <= tail) {
 		primary->space = primary->size - primary->tail;
 		primary->space = primary->size - primary->tail;
 	} else {
 	} else {
 		primary->space = head - tail;
 		primary->space = head - tail;
 	}
 	}
 
 
-	DRM_DEBUG( "   head = 0x%06lx\n", head - dev_priv->primary->offset );
-	DRM_DEBUG( "   tail = 0x%06lx\n", tail - dev_priv->primary->offset );
-	DRM_DEBUG( "  space = 0x%06x\n", primary->space );
+	DRM_DEBUG("   head = 0x%06lx\n", head - dev_priv->primary->offset);
+	DRM_DEBUG("   tail = 0x%06lx\n", tail - dev_priv->primary->offset);
+	DRM_DEBUG("  space = 0x%06x\n", primary->space);
 
 
 	mga_flush_write_combine();
 	mga_flush_write_combine();
 	MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access);
 	MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access);
 
 
-	DRM_DEBUG( "done.\n" );
+	DRM_DEBUG("done.\n");
 }
 }
 
 
-void mga_do_dma_wrap_start( drm_mga_private_t *dev_priv )
+void mga_do_dma_wrap_start(drm_mga_private_t * dev_priv)
 {
 {
 	drm_mga_primary_buffer_t *primary = &dev_priv->prim;
 	drm_mga_primary_buffer_t *primary = &dev_priv->prim;
 	u32 head, tail;
 	u32 head, tail;
 	DMA_LOCALS;
 	DMA_LOCALS;
-	DRM_DEBUG( "\n" );
+	DRM_DEBUG("\n");
 
 
 	BEGIN_DMA_WRAP();
 	BEGIN_DMA_WRAP();
 
 
-	DMA_BLOCK( MGA_DMAPAD,	0x00000000,
-		   MGA_DMAPAD,	0x00000000,
-		   MGA_DMAPAD,	0x00000000,
-		   MGA_DMAPAD,	0x00000000 );
+	DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+		  MGA_DMAPAD, 0x00000000,
+		  MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
 
 
 	ADVANCE_DMA();
 	ADVANCE_DMA();
 
 
@@ -178,45 +177,43 @@ void mga_do_dma_wrap_start( drm_mga_private_t *dev_priv )
 	primary->last_flush = 0;
 	primary->last_flush = 0;
 	primary->last_wrap++;
 	primary->last_wrap++;
 
 
-	head = MGA_READ( MGA_PRIMADDRESS );
+	head = MGA_READ(MGA_PRIMADDRESS);
 
 
-	if ( head == dev_priv->primary->offset ) {
+	if (head == dev_priv->primary->offset) {
 		primary->space = primary->size;
 		primary->space = primary->size;
 	} else {
 	} else {
 		primary->space = head - dev_priv->primary->offset;
 		primary->space = head - dev_priv->primary->offset;
 	}
 	}
 
 
-	DRM_DEBUG( "   head = 0x%06lx\n",
-		  head - dev_priv->primary->offset );
-	DRM_DEBUG( "   tail = 0x%06x\n", primary->tail );
-	DRM_DEBUG( "   wrap = %d\n", primary->last_wrap );
-	DRM_DEBUG( "  space = 0x%06x\n", primary->space );
+	DRM_DEBUG("   head = 0x%06lx\n", head - dev_priv->primary->offset);
+	DRM_DEBUG("   tail = 0x%06x\n", primary->tail);
+	DRM_DEBUG("   wrap = %d\n", primary->last_wrap);
+	DRM_DEBUG("  space = 0x%06x\n", primary->space);
 
 
 	mga_flush_write_combine();
 	mga_flush_write_combine();
 	MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access);
 	MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access);
 
 
-	set_bit( 0, &primary->wrapped );
-	DRM_DEBUG( "done.\n" );
+	set_bit(0, &primary->wrapped);
+	DRM_DEBUG("done.\n");
 }
 }
 
 
-void mga_do_dma_wrap_end( drm_mga_private_t *dev_priv )
+void mga_do_dma_wrap_end(drm_mga_private_t * dev_priv)
 {
 {
 	drm_mga_primary_buffer_t *primary = &dev_priv->prim;
 	drm_mga_primary_buffer_t *primary = &dev_priv->prim;
 	drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
 	drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
 	u32 head = dev_priv->primary->offset;
 	u32 head = dev_priv->primary->offset;
-	DRM_DEBUG( "\n" );
+	DRM_DEBUG("\n");
 
 
 	sarea_priv->last_wrap++;
 	sarea_priv->last_wrap++;
-	DRM_DEBUG( "   wrap = %d\n", sarea_priv->last_wrap );
+	DRM_DEBUG("   wrap = %d\n", sarea_priv->last_wrap);
 
 
 	mga_flush_write_combine();
 	mga_flush_write_combine();
-	MGA_WRITE( MGA_PRIMADDRESS, head | MGA_DMA_GENERAL );
+	MGA_WRITE(MGA_PRIMADDRESS, head | MGA_DMA_GENERAL);
 
 
-	clear_bit( 0, &primary->wrapped );
-	DRM_DEBUG( "done.\n" );
+	clear_bit(0, &primary->wrapped);
+	DRM_DEBUG("done.\n");
 }
 }
 
 
-
 /* ================================================================
 /* ================================================================
  * Freelist management
  * Freelist management
  */
  */
@@ -225,63 +222,61 @@ void mga_do_dma_wrap_end( drm_mga_private_t *dev_priv )
 #define MGA_BUFFER_FREE		0
 #define MGA_BUFFER_FREE		0
 
 
 #if MGA_FREELIST_DEBUG
 #if MGA_FREELIST_DEBUG
-static void mga_freelist_print( drm_device_t *dev )
+static void mga_freelist_print(drm_device_t * dev)
 {
 {
 	drm_mga_private_t *dev_priv = dev->dev_private;
 	drm_mga_private_t *dev_priv = dev->dev_private;
 	drm_mga_freelist_t *entry;
 	drm_mga_freelist_t *entry;
 
 
-	DRM_INFO( "\n" );
-	DRM_INFO( "current dispatch: last=0x%x done=0x%x\n",
-		  dev_priv->sarea_priv->last_dispatch,
-		  (unsigned int)(MGA_READ( MGA_PRIMADDRESS ) -
-				 dev_priv->primary->offset) );
-	DRM_INFO( "current freelist:\n" );
-
-	for ( entry = dev_priv->head->next ; entry ; entry = entry->next ) {
-		DRM_INFO( "   %p   idx=%2d  age=0x%x 0x%06lx\n",
-			  entry, entry->buf->idx, entry->age.head,
-			  entry->age.head - dev_priv->primary->offset );
+	DRM_INFO("\n");
+	DRM_INFO("current dispatch: last=0x%x done=0x%x\n",
+		 dev_priv->sarea_priv->last_dispatch,
+		 (unsigned int)(MGA_READ(MGA_PRIMADDRESS) -
+				dev_priv->primary->offset));
+	DRM_INFO("current freelist:\n");
+
+	for (entry = dev_priv->head->next; entry; entry = entry->next) {
+		DRM_INFO("   %p   idx=%2d  age=0x%x 0x%06lx\n",
+			 entry, entry->buf->idx, entry->age.head,
+			 entry->age.head - dev_priv->primary->offset);
 	}
 	}
-	DRM_INFO( "\n" );
+	DRM_INFO("\n");
 }
 }
 #endif
 #endif
 
 
-static int mga_freelist_init( drm_device_t *dev, drm_mga_private_t *dev_priv )
+static int mga_freelist_init(drm_device_t * dev, drm_mga_private_t * dev_priv)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
 	drm_buf_t *buf;
 	drm_buf_t *buf;
 	drm_mga_buf_priv_t *buf_priv;
 	drm_mga_buf_priv_t *buf_priv;
 	drm_mga_freelist_t *entry;
 	drm_mga_freelist_t *entry;
 	int i;
 	int i;
-	DRM_DEBUG( "count=%d\n", dma->buf_count );
+	DRM_DEBUG("count=%d\n", dma->buf_count);
 
 
-	dev_priv->head = drm_alloc( sizeof(drm_mga_freelist_t),
-				     DRM_MEM_DRIVER );
-	if ( dev_priv->head == NULL )
+	dev_priv->head = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
+	if (dev_priv->head == NULL)
 		return DRM_ERR(ENOMEM);
 		return DRM_ERR(ENOMEM);
 
 
-	memset( dev_priv->head, 0, sizeof(drm_mga_freelist_t) );
-	SET_AGE( &dev_priv->head->age, MGA_BUFFER_USED, 0 );
+	memset(dev_priv->head, 0, sizeof(drm_mga_freelist_t));
+	SET_AGE(&dev_priv->head->age, MGA_BUFFER_USED, 0);
 
 
-	for ( i = 0 ; i < dma->buf_count ; i++ ) {
+	for (i = 0; i < dma->buf_count; i++) {
 		buf = dma->buflist[i];
 		buf = dma->buflist[i];
-	        buf_priv = buf->dev_private;
+		buf_priv = buf->dev_private;
 
 
-		entry = drm_alloc( sizeof(drm_mga_freelist_t),
-				    DRM_MEM_DRIVER );
-		if ( entry == NULL )
+		entry = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
+		if (entry == NULL)
 			return DRM_ERR(ENOMEM);
 			return DRM_ERR(ENOMEM);
 
 
-		memset( entry, 0, sizeof(drm_mga_freelist_t) );
+		memset(entry, 0, sizeof(drm_mga_freelist_t));
 
 
 		entry->next = dev_priv->head->next;
 		entry->next = dev_priv->head->next;
 		entry->prev = dev_priv->head;
 		entry->prev = dev_priv->head;
-		SET_AGE( &entry->age, MGA_BUFFER_FREE, 0 );
+		SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
 		entry->buf = buf;
 		entry->buf = buf;
 
 
-		if ( dev_priv->head->next != NULL )
+		if (dev_priv->head->next != NULL)
 			dev_priv->head->next->prev = entry;
 			dev_priv->head->next->prev = entry;
-		if ( entry->next == NULL )
+		if (entry->next == NULL)
 			dev_priv->tail = entry;
 			dev_priv->tail = entry;
 
 
 		buf_priv->list_entry = entry;
 		buf_priv->list_entry = entry;
@@ -294,17 +289,17 @@ static int mga_freelist_init( drm_device_t *dev, drm_mga_private_t *dev_priv )
 	return 0;
 	return 0;
 }
 }
 
 
-static void mga_freelist_cleanup( drm_device_t *dev )
+static void mga_freelist_cleanup(drm_device_t * dev)
 {
 {
 	drm_mga_private_t *dev_priv = dev->dev_private;
 	drm_mga_private_t *dev_priv = dev->dev_private;
 	drm_mga_freelist_t *entry;
 	drm_mga_freelist_t *entry;
 	drm_mga_freelist_t *next;
 	drm_mga_freelist_t *next;
-	DRM_DEBUG( "\n" );
+	DRM_DEBUG("\n");
 
 
 	entry = dev_priv->head;
 	entry = dev_priv->head;
-	while ( entry ) {
+	while (entry) {
 		next = entry->next;
 		next = entry->next;
-		drm_free( entry, sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER );
+		drm_free(entry, sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
 		entry = next;
 		entry = next;
 	}
 	}
 
 
@@ -314,71 +309,69 @@ static void mga_freelist_cleanup( drm_device_t *dev )
 #if 0
 #if 0
 /* FIXME: Still needed?
 /* FIXME: Still needed?
  */
  */
-static void mga_freelist_reset( drm_device_t *dev )
+static void mga_freelist_reset(drm_device_t * dev)
 {
 {
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
 	drm_buf_t *buf;
 	drm_buf_t *buf;
 	drm_mga_buf_priv_t *buf_priv;
 	drm_mga_buf_priv_t *buf_priv;
 	int i;
 	int i;
 
 
-	for ( i = 0 ; i < dma->buf_count ; i++ ) {
+	for (i = 0; i < dma->buf_count; i++) {
 		buf = dma->buflist[i];
 		buf = dma->buflist[i];
-	        buf_priv = buf->dev_private;
-		SET_AGE( &buf_priv->list_entry->age,
-			 MGA_BUFFER_FREE, 0 );
+		buf_priv = buf->dev_private;
+		SET_AGE(&buf_priv->list_entry->age, MGA_BUFFER_FREE, 0);
 	}
 	}
 }
 }
 #endif
 #endif
 
 
-static drm_buf_t *mga_freelist_get( drm_device_t *dev )
+static drm_buf_t *mga_freelist_get(drm_device_t * dev)
 {
 {
 	drm_mga_private_t *dev_priv = dev->dev_private;
 	drm_mga_private_t *dev_priv = dev->dev_private;
 	drm_mga_freelist_t *next;
 	drm_mga_freelist_t *next;
 	drm_mga_freelist_t *prev;
 	drm_mga_freelist_t *prev;
 	drm_mga_freelist_t *tail = dev_priv->tail;
 	drm_mga_freelist_t *tail = dev_priv->tail;
 	u32 head, wrap;
 	u32 head, wrap;
-	DRM_DEBUG( "\n" );
+	DRM_DEBUG("\n");
 
 
-	head = MGA_READ( MGA_PRIMADDRESS );
+	head = MGA_READ(MGA_PRIMADDRESS);
 	wrap = dev_priv->sarea_priv->last_wrap;
 	wrap = dev_priv->sarea_priv->last_wrap;
 
 
-	DRM_DEBUG( "   tail=0x%06lx %d\n",
-		   tail->age.head ?
-		   tail->age.head - dev_priv->primary->offset : 0,
-		   tail->age.wrap );
-	DRM_DEBUG( "   head=0x%06lx %d\n",
-		   head - dev_priv->primary->offset, wrap );
+	DRM_DEBUG("   tail=0x%06lx %d\n",
+		  tail->age.head ?
+		  tail->age.head - dev_priv->primary->offset : 0,
+		  tail->age.wrap);
+	DRM_DEBUG("   head=0x%06lx %d\n",
+		  head - dev_priv->primary->offset, wrap);
 
 
-	if ( TEST_AGE( &tail->age, head, wrap ) ) {
+	if (TEST_AGE(&tail->age, head, wrap)) {
 		prev = dev_priv->tail->prev;
 		prev = dev_priv->tail->prev;
 		next = dev_priv->tail;
 		next = dev_priv->tail;
 		prev->next = NULL;
 		prev->next = NULL;
 		next->prev = next->next = NULL;
 		next->prev = next->next = NULL;
 		dev_priv->tail = prev;
 		dev_priv->tail = prev;
-		SET_AGE( &next->age, MGA_BUFFER_USED, 0 );
+		SET_AGE(&next->age, MGA_BUFFER_USED, 0);
 		return next->buf;
 		return next->buf;
 	}
 	}
 
 
-	DRM_DEBUG( "returning NULL!\n" );
+	DRM_DEBUG("returning NULL!\n");
 	return NULL;
 	return NULL;
 }
 }
 
 
-int mga_freelist_put( drm_device_t *dev, drm_buf_t *buf )
+int mga_freelist_put(drm_device_t * dev, drm_buf_t * buf)
 {
 {
 	drm_mga_private_t *dev_priv = dev->dev_private;
 	drm_mga_private_t *dev_priv = dev->dev_private;
 	drm_mga_buf_priv_t *buf_priv = buf->dev_private;
 	drm_mga_buf_priv_t *buf_priv = buf->dev_private;
 	drm_mga_freelist_t *head, *entry, *prev;
 	drm_mga_freelist_t *head, *entry, *prev;
 
 
-	DRM_DEBUG( "age=0x%06lx wrap=%d\n",
-		   buf_priv->list_entry->age.head -
-		   dev_priv->primary->offset,
-		   buf_priv->list_entry->age.wrap );
+	DRM_DEBUG("age=0x%06lx wrap=%d\n",
+		  buf_priv->list_entry->age.head -
+		  dev_priv->primary->offset, buf_priv->list_entry->age.wrap);
 
 
 	entry = buf_priv->list_entry;
 	entry = buf_priv->list_entry;
 	head = dev_priv->head;
 	head = dev_priv->head;
 
 
-	if ( buf_priv->list_entry->age.head == MGA_BUFFER_USED ) {
-		SET_AGE( &entry->age, MGA_BUFFER_FREE, 0 );
+	if (buf_priv->list_entry->age.head == MGA_BUFFER_USED) {
+		SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
 		prev = dev_priv->tail;
 		prev = dev_priv->tail;
 		prev->next = entry;
 		prev->next = entry;
 		entry->prev = prev;
 		entry->prev = prev;
@@ -394,15 +387,13 @@ int mga_freelist_put( drm_device_t *dev, drm_buf_t *buf )
 	return 0;
 	return 0;
 }
 }
 
 
-
 /* ================================================================
 /* ================================================================
  * DMA initialization, cleanup
  * DMA initialization, cleanup
  */
  */
 
 
-
-int mga_driver_preinit(drm_device_t *dev, unsigned long flags)
+int mga_driver_preinit(drm_device_t * dev, unsigned long flags)
 {
 {
-	drm_mga_private_t * dev_priv;
+	drm_mga_private_t *dev_priv;
 
 
 	dev_priv = drm_alloc(sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
 	dev_priv = drm_alloc(sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
 	if (!dev_priv)
 	if (!dev_priv)
@@ -420,7 +411,7 @@ int mga_driver_preinit(drm_device_t *dev, unsigned long flags)
 #if __OS_HAS_AGP
 #if __OS_HAS_AGP
 /**
 /**
  * Bootstrap the driver for AGP DMA.
  * Bootstrap the driver for AGP DMA.
- * 
+ *
  * \todo
  * \todo
  * Investigate whether there is any benifit to storing the WARP microcode in
  * Investigate whether there is any benifit to storing the WARP microcode in
  * AGP memory.  If not, the microcode may as well always be put in PCI
  * AGP memory.  If not, the microcode may as well always be put in PCI
@@ -436,18 +427,18 @@ int mga_driver_preinit(drm_device_t *dev, unsigned long flags)
 static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
 static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
 				    drm_mga_dma_bootstrap_t * dma_bs)
 				    drm_mga_dma_bootstrap_t * dma_bs)
 {
 {
-	drm_mga_private_t * const dev_priv = (drm_mga_private_t *) dev->dev_private;
+	drm_mga_private_t *const dev_priv =
+	    (drm_mga_private_t *) dev->dev_private;
 	unsigned int warp_size = mga_warp_microcode_size(dev_priv);
 	unsigned int warp_size = mga_warp_microcode_size(dev_priv);
 	int err;
 	int err;
-	unsigned  offset;
+	unsigned offset;
 	const unsigned secondary_size = dma_bs->secondary_bin_count
 	const unsigned secondary_size = dma_bs->secondary_bin_count
-		* dma_bs->secondary_bin_size;
+	    * dma_bs->secondary_bin_size;
 	const unsigned agp_size = (dma_bs->agp_size << 20);
 	const unsigned agp_size = (dma_bs->agp_size << 20);
 	drm_buf_desc_t req;
 	drm_buf_desc_t req;
 	drm_agp_mode_t mode;
 	drm_agp_mode_t mode;
 	drm_agp_info_t info;
 	drm_agp_info_t info;
 
 
-	
 	/* Acquire AGP. */
 	/* Acquire AGP. */
 	err = drm_agp_acquire(dev);
 	err = drm_agp_acquire(dev);
 	if (err) {
 	if (err) {
@@ -468,7 +459,6 @@ static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
 		return err;
 		return err;
 	}
 	}
 
 
-
 	/* In addition to the usual AGP mode configuration, the G200 AGP cards
 	/* In addition to the usual AGP mode configuration, the G200 AGP cards
 	 * need to have the AGP mode "manually" set.
 	 * need to have the AGP mode "manually" set.
 	 */
 	 */
@@ -476,24 +466,22 @@ static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
 	if (dev_priv->chipset == MGA_CARD_TYPE_G200) {
 	if (dev_priv->chipset == MGA_CARD_TYPE_G200) {
 		if (mode.mode & 0x02) {
 		if (mode.mode & 0x02) {
 			MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_ENABLE);
 			MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_ENABLE);
-		}
-		else {
+		} else {
 			MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_DISABLE);
 			MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_DISABLE);
 		}
 		}
 	}
 	}
 
 
-
 	/* Allocate and bind AGP memory. */
 	/* Allocate and bind AGP memory. */
 	dev_priv->agp_pages = agp_size / PAGE_SIZE;
 	dev_priv->agp_pages = agp_size / PAGE_SIZE;
-	dev_priv->agp_mem = drm_alloc_agp( dev, dev_priv->agp_pages, 0 );
+	dev_priv->agp_mem = drm_alloc_agp(dev, dev_priv->agp_pages, 0);
 	if (dev_priv->agp_mem == NULL) {
 	if (dev_priv->agp_mem == NULL) {
 		dev_priv->agp_pages = 0;
 		dev_priv->agp_pages = 0;
 		DRM_ERROR("Unable to allocate %uMB AGP memory\n",
 		DRM_ERROR("Unable to allocate %uMB AGP memory\n",
 			  dma_bs->agp_size);
 			  dma_bs->agp_size);
 		return DRM_ERR(ENOMEM);
 		return DRM_ERR(ENOMEM);
 	}
 	}
-		
-	err = drm_bind_agp( dev_priv->agp_mem, 0 );
+
+	err = drm_bind_agp(dev_priv->agp_mem, 0);
 	if (err) {
 	if (err) {
 		DRM_ERROR("Unable to bind AGP memory\n");
 		DRM_ERROR("Unable to bind AGP memory\n");
 		return err;
 		return err;
@@ -506,44 +494,44 @@ static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
 		warp_size = PAGE_SIZE;
 		warp_size = PAGE_SIZE;
 
 
 	offset = 0;
 	offset = 0;
-	err = drm_addmap( dev, offset, warp_size,
-			  _DRM_AGP, _DRM_READ_ONLY, & dev_priv->warp );
+	err = drm_addmap(dev, offset, warp_size,
+			 _DRM_AGP, _DRM_READ_ONLY, &dev_priv->warp);
 	if (err) {
 	if (err) {
 		DRM_ERROR("Unable to map WARP microcode\n");
 		DRM_ERROR("Unable to map WARP microcode\n");
 		return err;
 		return err;
 	}
 	}
 
 
 	offset += warp_size;
 	offset += warp_size;
-	err = drm_addmap( dev, offset, dma_bs->primary_size,
-			  _DRM_AGP, _DRM_READ_ONLY, & dev_priv->primary );
+	err = drm_addmap(dev, offset, dma_bs->primary_size,
+			 _DRM_AGP, _DRM_READ_ONLY, &dev_priv->primary);
 	if (err) {
 	if (err) {
 		DRM_ERROR("Unable to map primary DMA region\n");
 		DRM_ERROR("Unable to map primary DMA region\n");
 		return err;
 		return err;
 	}
 	}
 
 
 	offset += dma_bs->primary_size;
 	offset += dma_bs->primary_size;
-	err = drm_addmap( dev, offset, secondary_size,
-			  _DRM_AGP, 0, & dev->agp_buffer_map );
+	err = drm_addmap(dev, offset, secondary_size,
+			 _DRM_AGP, 0, &dev->agp_buffer_map);
 	if (err) {
 	if (err) {
 		DRM_ERROR("Unable to map secondary DMA region\n");
 		DRM_ERROR("Unable to map secondary DMA region\n");
 		return err;
 		return err;
 	}
 	}
 
 
-	(void) memset( &req, 0, sizeof(req) );
+	(void)memset(&req, 0, sizeof(req));
 	req.count = dma_bs->secondary_bin_count;
 	req.count = dma_bs->secondary_bin_count;
 	req.size = dma_bs->secondary_bin_size;
 	req.size = dma_bs->secondary_bin_size;
 	req.flags = _DRM_AGP_BUFFER;
 	req.flags = _DRM_AGP_BUFFER;
 	req.agp_start = offset;
 	req.agp_start = offset;
 
 
-	err = drm_addbufs_agp( dev, & req );
+	err = drm_addbufs_agp(dev, &req);
 	if (err) {
 	if (err) {
 		DRM_ERROR("Unable to add secondary DMA buffers\n");
 		DRM_ERROR("Unable to add secondary DMA buffers\n");
 		return err;
 		return err;
 	}
 	}
 
 
 	offset += secondary_size;
 	offset += secondary_size;
-	err = drm_addmap( dev, offset, agp_size - offset,
-			  _DRM_AGP, 0, & dev_priv->agp_textures );
+	err = drm_addmap(dev, offset, agp_size - offset,
+			 _DRM_AGP, 0, &dev_priv->agp_textures);
 	if (err) {
 	if (err) {
 		DRM_ERROR("Unable to map AGP texture region\n");
 		DRM_ERROR("Unable to map AGP texture region\n");
 		return err;
 		return err;
@@ -577,7 +565,7 @@ static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
 
 
 /**
 /**
  * Bootstrap the driver for PCI DMA.
  * Bootstrap the driver for PCI DMA.
- * 
+ *
  * \todo
  * \todo
  * The algorithm for decreasing the size of the primary DMA buffer could be
  * The algorithm for decreasing the size of the primary DMA buffer could be
  * better.  The size should be rounded up to the nearest page size, then
  * better.  The size should be rounded up to the nearest page size, then
@@ -586,20 +574,20 @@ static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
  * \todo
  * \todo
  * Determine whether the maximum address passed to drm_pci_alloc is correct.
  * Determine whether the maximum address passed to drm_pci_alloc is correct.
  * The same goes for drm_addbufs_pci.
  * The same goes for drm_addbufs_pci.
- * 
+ *
  * \sa mga_do_dma_bootstrap, mga_do_agp_dma_bootstrap
  * \sa mga_do_dma_bootstrap, mga_do_agp_dma_bootstrap
  */
  */
 static int mga_do_pci_dma_bootstrap(drm_device_t * dev,
 static int mga_do_pci_dma_bootstrap(drm_device_t * dev,
 				    drm_mga_dma_bootstrap_t * dma_bs)
 				    drm_mga_dma_bootstrap_t * dma_bs)
 {
 {
-	drm_mga_private_t * const dev_priv = (drm_mga_private_t *) dev->dev_private;
+	drm_mga_private_t *const dev_priv =
+	    (drm_mga_private_t *) dev->dev_private;
 	unsigned int warp_size = mga_warp_microcode_size(dev_priv);
 	unsigned int warp_size = mga_warp_microcode_size(dev_priv);
 	unsigned int primary_size;
 	unsigned int primary_size;
 	unsigned int bin_count;
 	unsigned int bin_count;
 	int err;
 	int err;
 	drm_buf_desc_t req;
 	drm_buf_desc_t req;
 
 
-	
 	if (dev->dma == NULL) {
 	if (dev->dma == NULL) {
 		DRM_ERROR("dev->dma is NULL\n");
 		DRM_ERROR("dev->dma is NULL\n");
 		return DRM_ERR(EFAULT);
 		return DRM_ERR(EFAULT);
@@ -624,9 +612,8 @@ static int mga_do_pci_dma_bootstrap(drm_device_t * dev,
 	 * alignment of the primary or secondary DMA buffers.
 	 * alignment of the primary or secondary DMA buffers.
 	 */
 	 */
 
 
-	for ( primary_size = dma_bs->primary_size
-	      ; primary_size != 0
-	      ; primary_size >>= 1 ) {
+	for (primary_size = dma_bs->primary_size; primary_size != 0;
+	     primary_size >>= 1) {
 		/* The proper alignment for this mapping is 0x04 */
 		/* The proper alignment for this mapping is 0x04 */
 		err = drm_addmap(dev, 0, primary_size, _DRM_CONSISTENT,
 		err = drm_addmap(dev, 0, primary_size, _DRM_CONSISTENT,
 				 _DRM_READ_ONLY, &dev_priv->primary);
 				 _DRM_READ_ONLY, &dev_priv->primary);
@@ -641,24 +628,23 @@ static int mga_do_pci_dma_bootstrap(drm_device_t * dev,
 
 
 	if (dev_priv->primary->size != dma_bs->primary_size) {
 	if (dev_priv->primary->size != dma_bs->primary_size) {
 		DRM_INFO("Primary DMA buffer size reduced from %u to %u.\n",
 		DRM_INFO("Primary DMA buffer size reduced from %u to %u.\n",
-			 dma_bs->primary_size, 
-			 (unsigned) dev_priv->primary->size);
+			 dma_bs->primary_size,
+			 (unsigned)dev_priv->primary->size);
 		dma_bs->primary_size = dev_priv->primary->size;
 		dma_bs->primary_size = dev_priv->primary->size;
 	}
 	}
 
 
-	for ( bin_count = dma_bs->secondary_bin_count
-	      ; bin_count > 0 
-	      ; bin_count-- ) {
-		(void) memset( &req, 0, sizeof(req) );
+	for (bin_count = dma_bs->secondary_bin_count; bin_count > 0;
+	     bin_count--) {
+		(void)memset(&req, 0, sizeof(req));
 		req.count = bin_count;
 		req.count = bin_count;
 		req.size = dma_bs->secondary_bin_size;
 		req.size = dma_bs->secondary_bin_size;
 
 
-		err = drm_addbufs_pci( dev, & req );
+		err = drm_addbufs_pci(dev, &req);
 		if (!err) {
 		if (!err) {
 			break;
 			break;
 		}
 		}
 	}
 	}
-	
+
 	if (bin_count == 0) {
 	if (bin_count == 0) {
 		DRM_ERROR("Unable to add secondary DMA buffers\n");
 		DRM_ERROR("Unable to add secondary DMA buffers\n");
 		return err;
 		return err;
@@ -680,38 +666,34 @@ static int mga_do_pci_dma_bootstrap(drm_device_t * dev,
 	return 0;
 	return 0;
 }
 }
 
 
-
 static int mga_do_dma_bootstrap(drm_device_t * dev,
 static int mga_do_dma_bootstrap(drm_device_t * dev,
 				drm_mga_dma_bootstrap_t * dma_bs)
 				drm_mga_dma_bootstrap_t * dma_bs)
 {
 {
 	const int is_agp = (dma_bs->agp_mode != 0) && drm_device_is_agp(dev);
 	const int is_agp = (dma_bs->agp_mode != 0) && drm_device_is_agp(dev);
 	int err;
 	int err;
-	drm_mga_private_t * const dev_priv =
-		(drm_mga_private_t *) dev->dev_private;
-
+	drm_mga_private_t *const dev_priv =
+	    (drm_mga_private_t *) dev->dev_private;
 
 
 	dev_priv->used_new_dma_init = 1;
 	dev_priv->used_new_dma_init = 1;
 
 
 	/* The first steps are the same for both PCI and AGP based DMA.  Map
 	/* The first steps are the same for both PCI and AGP based DMA.  Map
 	 * the cards MMIO registers and map a status page.
 	 * the cards MMIO registers and map a status page.
 	 */
 	 */
-	err = drm_addmap( dev, dev_priv->mmio_base, dev_priv->mmio_size,
-			  _DRM_REGISTERS, _DRM_READ_ONLY, & dev_priv->mmio );
+	err = drm_addmap(dev, dev_priv->mmio_base, dev_priv->mmio_size,
+			 _DRM_REGISTERS, _DRM_READ_ONLY, &dev_priv->mmio);
 	if (err) {
 	if (err) {
 		DRM_ERROR("Unable to map MMIO region\n");
 		DRM_ERROR("Unable to map MMIO region\n");
 		return err;
 		return err;
 	}
 	}
 
 
-
-	err = drm_addmap( dev, 0, SAREA_MAX, _DRM_SHM,
-			  _DRM_READ_ONLY | _DRM_LOCKED | _DRM_KERNEL,
-			  & dev_priv->status );
+	err = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM,
+			 _DRM_READ_ONLY | _DRM_LOCKED | _DRM_KERNEL,
+			 &dev_priv->status);
 	if (err) {
 	if (err) {
 		DRM_ERROR("Unable to map status region\n");
 		DRM_ERROR("Unable to map status region\n");
 		return err;
 		return err;
 	}
 	}
 
 
-
 	/* The DMA initialization procedure is slightly different for PCI and
 	/* The DMA initialization procedure is slightly different for PCI and
 	 * AGP cards.  AGP cards just allocate a large block of AGP memory and
 	 * AGP cards.  AGP cards just allocate a large block of AGP memory and
 	 * carve off portions of it for internal uses.  The remaining memory
 	 * carve off portions of it for internal uses.  The remaining memory
@@ -720,7 +702,7 @@ static int mga_do_dma_bootstrap(drm_device_t * dev,
 	if (is_agp) {
 	if (is_agp) {
 		err = mga_do_agp_dma_bootstrap(dev, dma_bs);
 		err = mga_do_agp_dma_bootstrap(dev, dma_bs);
 	}
 	}
-	
+
 	/* If we attempted to initialize the card for AGP DMA but failed,
 	/* If we attempted to initialize the card for AGP DMA but failed,
 	 * clean-up any mess that may have been created.
 	 * clean-up any mess that may have been created.
 	 */
 	 */
@@ -729,7 +711,6 @@ static int mga_do_dma_bootstrap(drm_device_t * dev,
 		mga_do_cleanup_dma(dev);
 		mga_do_cleanup_dma(dev);
 	}
 	}
 
 
-
 	/* Not only do we want to try and initialized PCI cards for PCI DMA,
 	/* Not only do we want to try and initialized PCI cards for PCI DMA,
 	 * but we also try to initialized AGP cards that could not be
 	 * but we also try to initialized AGP cards that could not be
 	 * initialized for AGP DMA.  This covers the case where we have an AGP
 	 * initialized for AGP DMA.  This covers the case where we have an AGP
@@ -742,7 +723,6 @@ static int mga_do_dma_bootstrap(drm_device_t * dev,
 		err = mga_do_pci_dma_bootstrap(dev, dma_bs);
 		err = mga_do_pci_dma_bootstrap(dev, dma_bs);
 	}
 	}
 
 
-
 	return err;
 	return err;
 }
 }
 
 
@@ -752,45 +732,42 @@ int mga_dma_bootstrap(DRM_IOCTL_ARGS)
 	drm_mga_dma_bootstrap_t bootstrap;
 	drm_mga_dma_bootstrap_t bootstrap;
 	int err;
 	int err;
 
 
-
 	DRM_COPY_FROM_USER_IOCTL(bootstrap,
 	DRM_COPY_FROM_USER_IOCTL(bootstrap,
 				 (drm_mga_dma_bootstrap_t __user *) data,
 				 (drm_mga_dma_bootstrap_t __user *) data,
 				 sizeof(bootstrap));
 				 sizeof(bootstrap));
 
 
-	err = mga_do_dma_bootstrap(dev, & bootstrap);
-	if (! err) {
+	err = mga_do_dma_bootstrap(dev, &bootstrap);
+	if (!err) {
 		static const int modes[] = { 0, 1, 2, 2, 4, 4, 4, 4 };
 		static const int modes[] = { 0, 1, 2, 2, 4, 4, 4, 4 };
-		const drm_mga_private_t * const dev_priv = 
-			(drm_mga_private_t *) dev->dev_private;
+		const drm_mga_private_t *const dev_priv =
+		    (drm_mga_private_t *) dev->dev_private;
 
 
 		if (dev_priv->agp_textures != NULL) {
 		if (dev_priv->agp_textures != NULL) {
-			bootstrap.texture_handle = dev_priv->agp_textures->offset;
+			bootstrap.texture_handle =
+			    dev_priv->agp_textures->offset;
 			bootstrap.texture_size = dev_priv->agp_textures->size;
 			bootstrap.texture_size = dev_priv->agp_textures->size;
-		}
-		else {
+		} else {
 			bootstrap.texture_handle = 0;
 			bootstrap.texture_handle = 0;
 			bootstrap.texture_size = 0;
 			bootstrap.texture_size = 0;
 		}
 		}
 
 
-		bootstrap.agp_mode = modes[ bootstrap.agp_mode & 0x07 ];
-		if (DRM_COPY_TO_USER( (void __user *) data, & bootstrap,
+		bootstrap.agp_mode = modes[bootstrap.agp_mode & 0x07];
+		if (DRM_COPY_TO_USER((void __user *)data, &bootstrap,
 				     sizeof(bootstrap))) {
 				     sizeof(bootstrap))) {
 			err = DRM_ERR(EFAULT);
 			err = DRM_ERR(EFAULT);
 		}
 		}
-	}
-	else {
+	} else {
 		mga_do_cleanup_dma(dev);
 		mga_do_cleanup_dma(dev);
 	}
 	}
 
 
 	return err;
 	return err;
 }
 }
 
 
-static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
+static int mga_do_init_dma(drm_device_t * dev, drm_mga_init_t * init)
 {
 {
 	drm_mga_private_t *dev_priv;
 	drm_mga_private_t *dev_priv;
 	int ret;
 	int ret;
-	DRM_DEBUG( "\n" );
-
+	DRM_DEBUG("\n");
 
 
 	dev_priv = dev->dev_private;
 	dev_priv = dev->dev_private;
 
 
@@ -799,17 +776,17 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
 	} else {
 	} else {
 		dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_RSTR;
 		dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_RSTR;
 	}
 	}
-	dev_priv->maccess	= init->maccess;
+	dev_priv->maccess = init->maccess;
 
 
-	dev_priv->fb_cpp	= init->fb_cpp;
-	dev_priv->front_offset	= init->front_offset;
-	dev_priv->front_pitch	= init->front_pitch;
-	dev_priv->back_offset	= init->back_offset;
-	dev_priv->back_pitch	= init->back_pitch;
+	dev_priv->fb_cpp = init->fb_cpp;
+	dev_priv->front_offset = init->front_offset;
+	dev_priv->front_pitch = init->front_pitch;
+	dev_priv->back_offset = init->back_offset;
+	dev_priv->back_pitch = init->back_pitch;
 
 
-	dev_priv->depth_cpp	= init->depth_cpp;
-	dev_priv->depth_offset	= init->depth_offset;
-	dev_priv->depth_pitch	= init->depth_pitch;
+	dev_priv->depth_cpp = init->depth_cpp;
+	dev_priv->depth_offset = init->depth_offset;
+	dev_priv->depth_pitch = init->depth_pitch;
 
 
 	/* FIXME: Need to support AGP textures...
 	/* FIXME: Need to support AGP textures...
 	 */
 	 */
@@ -823,7 +800,7 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
 		return DRM_ERR(EINVAL);
 		return DRM_ERR(EINVAL);
 	}
 	}
 
 
-	if (! dev_priv->used_new_dma_init) {
+	if (!dev_priv->used_new_dma_init) {
 
 
 		dev_priv->dma_access = MGA_PAGPXFER;
 		dev_priv->dma_access = MGA_PAGPXFER;
 		dev_priv->wagp_enable = MGA_WAGP_ENABLE;
 		dev_priv->wagp_enable = MGA_WAGP_ENABLE;
@@ -849,7 +826,8 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
 			return DRM_ERR(EINVAL);
 			return DRM_ERR(EINVAL);
 		}
 		}
 		dev->agp_buffer_token = init->buffers_offset;
 		dev->agp_buffer_token = init->buffers_offset;
-		dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
+		dev->agp_buffer_map =
+		    drm_core_findmap(dev, init->buffers_offset);
 		if (!dev->agp_buffer_map) {
 		if (!dev->agp_buffer_map) {
 			DRM_ERROR("failed to find dma buffer region!\n");
 			DRM_ERROR("failed to find dma buffer region!\n");
 			return DRM_ERR(EINVAL);
 			return DRM_ERR(EINVAL);
@@ -861,8 +839,8 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
 	}
 	}
 
 
 	dev_priv->sarea_priv =
 	dev_priv->sarea_priv =
-		(drm_mga_sarea_t *)((u8 *)dev_priv->sarea->handle +
-				    init->sarea_priv_offset);
+	    (drm_mga_sarea_t *) ((u8 *) dev_priv->sarea->handle +
+				 init->sarea_priv_offset);
 
 
 	if (!dev_priv->warp->handle ||
 	if (!dev_priv->warp->handle ||
 	    !dev_priv->primary->handle ||
 	    !dev_priv->primary->handle ||
@@ -885,23 +863,20 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
 		return ret;
 		return ret;
 	}
 	}
 
 
-	dev_priv->prim.status = (u32 *)dev_priv->status->handle;
+	dev_priv->prim.status = (u32 *) dev_priv->status->handle;
 
 
-	mga_do_wait_for_idle( dev_priv );
+	mga_do_wait_for_idle(dev_priv);
 
 
 	/* Init the primary DMA registers.
 	/* Init the primary DMA registers.
 	 */
 	 */
-	MGA_WRITE( MGA_PRIMADDRESS,
-		   dev_priv->primary->offset | MGA_DMA_GENERAL );
+	MGA_WRITE(MGA_PRIMADDRESS, dev_priv->primary->offset | MGA_DMA_GENERAL);
 #if 0
 #if 0
-	MGA_WRITE( MGA_PRIMPTR,
-		   virt_to_bus((void *)dev_priv->prim.status) |
-		   MGA_PRIMPTREN0 |	/* Soft trap, SECEND, SETUPEND */
-		   MGA_PRIMPTREN1 );	/* DWGSYNC */
+	MGA_WRITE(MGA_PRIMPTR, virt_to_bus((void *)dev_priv->prim.status) | MGA_PRIMPTREN0 |	/* Soft trap, SECEND, SETUPEND */
+		  MGA_PRIMPTREN1);	/* DWGSYNC */
 #endif
 #endif
 
 
-	dev_priv->prim.start = (u8 *)dev_priv->primary->handle;
-	dev_priv->prim.end = ((u8 *)dev_priv->primary->handle
+	dev_priv->prim.start = (u8 *) dev_priv->primary->handle;
+	dev_priv->prim.end = ((u8 *) dev_priv->primary->handle
 			      + dev_priv->primary->size);
 			      + dev_priv->primary->size);
 	dev_priv->prim.size = dev_priv->primary->size;
 	dev_priv->prim.size = dev_priv->primary->size;
 
 
@@ -929,7 +904,7 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
 	return 0;
 	return 0;
 }
 }
 
 
-static int mga_do_cleanup_dma( drm_device_t *dev )
+static int mga_do_cleanup_dma(drm_device_t * dev)
 {
 {
 	int err = 0;
 	int err = 0;
 	DRM_DEBUG("\n");
 	DRM_DEBUG("\n");
@@ -938,16 +913,17 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
 	 * may not have been called from userspace and after dev_private
 	 * may not have been called from userspace and after dev_private
 	 * is freed, it's too late.
 	 * is freed, it's too late.
 	 */
 	 */
-	if ( dev->irq_enabled ) drm_irq_uninstall(dev);
+	if (dev->irq_enabled)
+		drm_irq_uninstall(dev);
 
 
-	if ( dev->dev_private ) {
+	if (dev->dev_private) {
 		drm_mga_private_t *dev_priv = dev->dev_private;
 		drm_mga_private_t *dev_priv = dev->dev_private;
 
 
-		if ((dev_priv->warp != NULL) 
+		if ((dev_priv->warp != NULL)
 		    && (dev_priv->warp->type != _DRM_CONSISTENT))
 		    && (dev_priv->warp->type != _DRM_CONSISTENT))
 			drm_core_ioremapfree(dev_priv->warp, dev);
 			drm_core_ioremapfree(dev_priv->warp, dev);
 
 
-		if ((dev_priv->primary != NULL) 
+		if ((dev_priv->primary != NULL)
 		    && (dev_priv->primary->type != _DRM_CONSISTENT))
 		    && (dev_priv->primary->type != _DRM_CONSISTENT))
 			drm_core_ioremapfree(dev_priv->primary, dev);
 			drm_core_ioremapfree(dev_priv->primary, dev);
 
 
@@ -960,7 +936,8 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
 				dev_priv->agp_textures = NULL;
 				dev_priv->agp_textures = NULL;
 				drm_unbind_agp(dev_priv->agp_mem);
 				drm_unbind_agp(dev_priv->agp_mem);
 
 
-				drm_free_agp(dev_priv->agp_mem, dev_priv->agp_pages);
+				drm_free_agp(dev_priv->agp_mem,
+					     dev_priv->agp_pages);
 				dev_priv->agp_pages = 0;
 				dev_priv->agp_pages = 0;
 				dev_priv->agp_mem = NULL;
 				dev_priv->agp_mem = NULL;
 			}
 			}
@@ -982,7 +959,8 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
 
 
 		memset(&dev_priv->prim, 0, sizeof(dev_priv->prim));
 		memset(&dev_priv->prim, 0, sizeof(dev_priv->prim));
 		dev_priv->warp_pipe = 0;
 		dev_priv->warp_pipe = 0;
-		memset(dev_priv->warp_pipe_phys, 0, sizeof(dev_priv->warp_pipe_phys));
+		memset(dev_priv->warp_pipe_phys, 0,
+		       sizeof(dev_priv->warp_pipe_phys));
 
 
 		if (dev_priv->head != NULL) {
 		if (dev_priv->head != NULL) {
 			mga_freelist_cleanup(dev);
 			mga_freelist_cleanup(dev);
@@ -992,103 +970,102 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
 	return err;
 	return err;
 }
 }
 
 
-int mga_dma_init( DRM_IOCTL_ARGS )
+int mga_dma_init(DRM_IOCTL_ARGS)
 {
 {
 	DRM_DEVICE;
 	DRM_DEVICE;
 	drm_mga_init_t init;
 	drm_mga_init_t init;
 	int err;
 	int err;
 
 
-	LOCK_TEST_WITH_RETURN( dev, filp );
+	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
 	DRM_COPY_FROM_USER_IOCTL(init, (drm_mga_init_t __user *) data,
 	DRM_COPY_FROM_USER_IOCTL(init, (drm_mga_init_t __user *) data,
 				 sizeof(init));
 				 sizeof(init));
 
 
-	switch ( init.func ) {
+	switch (init.func) {
 	case MGA_INIT_DMA:
 	case MGA_INIT_DMA:
 		err = mga_do_init_dma(dev, &init);
 		err = mga_do_init_dma(dev, &init);
 		if (err) {
 		if (err) {
-			(void) mga_do_cleanup_dma(dev);
+			(void)mga_do_cleanup_dma(dev);
 		}
 		}
 		return err;
 		return err;
 	case MGA_CLEANUP_DMA:
 	case MGA_CLEANUP_DMA:
-		return mga_do_cleanup_dma( dev );
+		return mga_do_cleanup_dma(dev);
 	}
 	}
 
 
 	return DRM_ERR(EINVAL);
 	return DRM_ERR(EINVAL);
 }
 }
 
 
-
 /* ================================================================
 /* ================================================================
  * Primary DMA stream management
  * Primary DMA stream management
  */
  */
 
 
-int mga_dma_flush( DRM_IOCTL_ARGS )
+int mga_dma_flush(DRM_IOCTL_ARGS)
 {
 {
 	DRM_DEVICE;
 	DRM_DEVICE;
-	drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
+	drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
 	drm_lock_t lock;
 	drm_lock_t lock;
 
 
-	LOCK_TEST_WITH_RETURN( dev, filp );
+	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
-	DRM_COPY_FROM_USER_IOCTL( lock, (drm_lock_t __user *)data, sizeof(lock) );
+	DRM_COPY_FROM_USER_IOCTL(lock, (drm_lock_t __user *) data,
+				 sizeof(lock));
 
 
-	DRM_DEBUG( "%s%s%s\n",
-		   (lock.flags & _DRM_LOCK_FLUSH) ?	"flush, " : "",
-		   (lock.flags & _DRM_LOCK_FLUSH_ALL) ?	"flush all, " : "",
-		   (lock.flags & _DRM_LOCK_QUIESCENT) ?	"idle, " : "" );
+	DRM_DEBUG("%s%s%s\n",
+		  (lock.flags & _DRM_LOCK_FLUSH) ? "flush, " : "",
+		  (lock.flags & _DRM_LOCK_FLUSH_ALL) ? "flush all, " : "",
+		  (lock.flags & _DRM_LOCK_QUIESCENT) ? "idle, " : "");
 
 
-	WRAP_WAIT_WITH_RETURN( dev_priv );
+	WRAP_WAIT_WITH_RETURN(dev_priv);
 
 
-	if ( lock.flags & (_DRM_LOCK_FLUSH | _DRM_LOCK_FLUSH_ALL) ) {
-		mga_do_dma_flush( dev_priv );
+	if (lock.flags & (_DRM_LOCK_FLUSH | _DRM_LOCK_FLUSH_ALL)) {
+		mga_do_dma_flush(dev_priv);
 	}
 	}
 
 
-	if ( lock.flags & _DRM_LOCK_QUIESCENT ) {
+	if (lock.flags & _DRM_LOCK_QUIESCENT) {
 #if MGA_DMA_DEBUG
 #if MGA_DMA_DEBUG
-		int ret = mga_do_wait_for_idle( dev_priv );
-		if ( ret < 0 )
-			DRM_INFO( "%s: -EBUSY\n", __FUNCTION__ );
+		int ret = mga_do_wait_for_idle(dev_priv);
+		if (ret < 0)
+			DRM_INFO("%s: -EBUSY\n", __FUNCTION__);
 		return ret;
 		return ret;
 #else
 #else
-		return mga_do_wait_for_idle( dev_priv );
+		return mga_do_wait_for_idle(dev_priv);
 #endif
 #endif
 	} else {
 	} else {
 		return 0;
 		return 0;
 	}
 	}
 }
 }
 
 
-int mga_dma_reset( DRM_IOCTL_ARGS )
+int mga_dma_reset(DRM_IOCTL_ARGS)
 {
 {
 	DRM_DEVICE;
 	DRM_DEVICE;
-	drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
+	drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
 
 
-	LOCK_TEST_WITH_RETURN( dev, filp );
+	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
-	return mga_do_dma_reset( dev_priv );
+	return mga_do_dma_reset(dev_priv);
 }
 }
 
 
-
 /* ================================================================
 /* ================================================================
  * DMA buffer management
  * DMA buffer management
  */
  */
 
 
-static int mga_dma_get_buffers( DRMFILE filp,
-				drm_device_t *dev, drm_dma_t *d )
+static int mga_dma_get_buffers(DRMFILE filp, drm_device_t * dev, drm_dma_t * d)
 {
 {
 	drm_buf_t *buf;
 	drm_buf_t *buf;
 	int i;
 	int i;
 
 
-	for ( i = d->granted_count ; i < d->request_count ; i++ ) {
-		buf = mga_freelist_get( dev );
-		if ( !buf ) return DRM_ERR(EAGAIN);
+	for (i = d->granted_count; i < d->request_count; i++) {
+		buf = mga_freelist_get(dev);
+		if (!buf)
+			return DRM_ERR(EAGAIN);
 
 
 		buf->filp = filp;
 		buf->filp = filp;
 
 
-		if ( DRM_COPY_TO_USER( &d->request_indices[i],
-				   &buf->idx, sizeof(buf->idx) ) )
+		if (DRM_COPY_TO_USER(&d->request_indices[i],
+				     &buf->idx, sizeof(buf->idx)))
 			return DRM_ERR(EFAULT);
 			return DRM_ERR(EFAULT);
-		if ( DRM_COPY_TO_USER( &d->request_sizes[i],
-				   &buf->total, sizeof(buf->total) ) )
+		if (DRM_COPY_TO_USER(&d->request_sizes[i],
+				     &buf->total, sizeof(buf->total)))
 			return DRM_ERR(EFAULT);
 			return DRM_ERR(EFAULT);
 
 
 		d->granted_count++;
 		d->granted_count++;
@@ -1096,44 +1073,44 @@ static int mga_dma_get_buffers( DRMFILE filp,
 	return 0;
 	return 0;
 }
 }
 
 
-int mga_dma_buffers( DRM_IOCTL_ARGS )
+int mga_dma_buffers(DRM_IOCTL_ARGS)
 {
 {
 	DRM_DEVICE;
 	DRM_DEVICE;
 	drm_device_dma_t *dma = dev->dma;
 	drm_device_dma_t *dma = dev->dma;
-	drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
+	drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
 	drm_dma_t __user *argp = (void __user *)data;
 	drm_dma_t __user *argp = (void __user *)data;
 	drm_dma_t d;
 	drm_dma_t d;
 	int ret = 0;
 	int ret = 0;
 
 
-	LOCK_TEST_WITH_RETURN( dev, filp );
+	LOCK_TEST_WITH_RETURN(dev, filp);
 
 
-	DRM_COPY_FROM_USER_IOCTL( d, argp, sizeof(d) );
+	DRM_COPY_FROM_USER_IOCTL(d, argp, sizeof(d));
 
 
 	/* Please don't send us buffers.
 	/* Please don't send us buffers.
 	 */
 	 */
-	if ( d.send_count != 0 ) {
-		DRM_ERROR( "Process %d trying to send %d buffers via drmDMA\n",
-			   DRM_CURRENTPID, d.send_count );
+	if (d.send_count != 0) {
+		DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
+			  DRM_CURRENTPID, d.send_count);
 		return DRM_ERR(EINVAL);
 		return DRM_ERR(EINVAL);
 	}
 	}
 
 
 	/* We'll send you buffers.
 	/* We'll send you buffers.
 	 */
 	 */
-	if ( d.request_count < 0 || d.request_count > dma->buf_count ) {
-		DRM_ERROR( "Process %d trying to get %d buffers (of %d max)\n",
-			   DRM_CURRENTPID, d.request_count, dma->buf_count );
+	if (d.request_count < 0 || d.request_count > dma->buf_count) {
+		DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
+			  DRM_CURRENTPID, d.request_count, dma->buf_count);
 		return DRM_ERR(EINVAL);
 		return DRM_ERR(EINVAL);
 	}
 	}
 
 
-	WRAP_TEST_WITH_RETURN( dev_priv );
+	WRAP_TEST_WITH_RETURN(dev_priv);
 
 
 	d.granted_count = 0;
 	d.granted_count = 0;
 
 
-	if ( d.request_count ) {
-		ret = mga_dma_get_buffers( filp, dev, &d );
+	if (d.request_count) {
+		ret = mga_dma_get_buffers(filp, dev, &d);
 	}
 	}
 
 
-	DRM_COPY_TO_USER_IOCTL( argp, d, sizeof(d) );
+	DRM_COPY_TO_USER_IOCTL(argp, d, sizeof(d));
 
 
 	return ret;
 	return ret;
 }
 }
@@ -1154,11 +1131,11 @@ int mga_driver_postcleanup(drm_device_t * dev)
  */
  */
 void mga_driver_pretakedown(drm_device_t * dev)
 void mga_driver_pretakedown(drm_device_t * dev)
 {
 {
-	mga_do_cleanup_dma( dev );
+	mga_do_cleanup_dma(dev);
 }
 }
 
 
-int mga_driver_dma_quiescent(drm_device_t *dev)
+int mga_driver_dma_quiescent(drm_device_t * dev)
 {
 {
 	drm_mga_private_t *dev_priv = dev->dev_private;
 	drm_mga_private_t *dev_priv = dev->dev_private;
-	return mga_do_wait_for_idle( dev_priv );
+	return mga_do_wait_for_idle(dev_priv);
 }
 }

+ 67 - 75
drivers/char/drm/mga_drm.h

@@ -44,10 +44,10 @@
 
 
 /* WARP pipe flags
 /* WARP pipe flags
  */
  */
-#define MGA_F			0x1		/* fog */
-#define MGA_A			0x2		/* alpha */
-#define MGA_S			0x4		/* specular */
-#define MGA_T2			0x8		/* multitexture */
+#define MGA_F			0x1	/* fog */
+#define MGA_A			0x2	/* alpha */
+#define MGA_S			0x4	/* specular */
+#define MGA_T2			0x8	/* multitexture */
 
 
 #define MGA_WARP_TGZ		0
 #define MGA_WARP_TGZ		0
 #define MGA_WARP_TGZF		(MGA_F)
 #define MGA_WARP_TGZF		(MGA_F)
@@ -66,14 +66,14 @@
 #define MGA_WARP_T2GZSA		(MGA_T2|MGA_S|MGA_A)
 #define MGA_WARP_T2GZSA		(MGA_T2|MGA_S|MGA_A)
 #define MGA_WARP_T2GZSAF	(MGA_T2|MGA_S|MGA_F|MGA_A)
 #define MGA_WARP_T2GZSAF	(MGA_T2|MGA_S|MGA_F|MGA_A)
 
 
-#define MGA_MAX_G200_PIPES	8		/* no multitex */
+#define MGA_MAX_G200_PIPES	8	/* no multitex */
 #define MGA_MAX_G400_PIPES	16
 #define MGA_MAX_G400_PIPES	16
 #define MGA_MAX_WARP_PIPES	MGA_MAX_G400_PIPES
 #define MGA_MAX_WARP_PIPES	MGA_MAX_G400_PIPES
-#define MGA_WARP_UCODE_SIZE	32768		/* in bytes */
+#define MGA_WARP_UCODE_SIZE	32768	/* in bytes */
 
 
 #define MGA_CARD_TYPE_G200	1
 #define MGA_CARD_TYPE_G200	1
 #define MGA_CARD_TYPE_G400	2
 #define MGA_CARD_TYPE_G400	2
-#define MGA_CARD_TYPE_G450	3       /* not currently used */
+#define MGA_CARD_TYPE_G450	3	/* not currently used */
 #define MGA_CARD_TYPE_G550	4
 #define MGA_CARD_TYPE_G550	4
 
 
 #define MGA_FRONT		0x1
 #define MGA_FRONT		0x1
@@ -86,14 +86,14 @@
 #define MGA_UPLOAD_TEX0		0x2
 #define MGA_UPLOAD_TEX0		0x2
 #define MGA_UPLOAD_TEX1		0x4
 #define MGA_UPLOAD_TEX1		0x4
 #define MGA_UPLOAD_PIPE		0x8
 #define MGA_UPLOAD_PIPE		0x8
-#define MGA_UPLOAD_TEX0IMAGE	0x10 /* handled client-side */
-#define MGA_UPLOAD_TEX1IMAGE	0x20 /* handled client-side */
+#define MGA_UPLOAD_TEX0IMAGE	0x10	/* handled client-side */
+#define MGA_UPLOAD_TEX1IMAGE	0x20	/* handled client-side */
 #define MGA_UPLOAD_2D		0x40
 #define MGA_UPLOAD_2D		0x40
-#define MGA_WAIT_AGE		0x80 /* handled client-side */
-#define MGA_UPLOAD_CLIPRECTS	0x100 /* handled client-side */
+#define MGA_WAIT_AGE		0x80	/* handled client-side */
+#define MGA_UPLOAD_CLIPRECTS	0x100	/* handled client-side */
 #if 0
 #if 0
-#define MGA_DMA_FLUSH		0x200 /* set when someone gets the lock
-					 quiescent */
+#define MGA_DMA_FLUSH		0x200	/* set when someone gets the lock
+					   quiescent */
 #endif
 #endif
 
 
 /* 32 buffers of 64k each, total 2 meg.
 /* 32 buffers of 64k each, total 2 meg.
@@ -120,8 +120,7 @@
 
 
 #define  DRM_MGA_IDLE_RETRY          2048
 #define  DRM_MGA_IDLE_RETRY          2048
 
 
-#endif /* __MGA_SAREA_DEFINES__ */
-
+#endif				/* __MGA_SAREA_DEFINES__ */
 
 
 /* Setup registers for 3D context
 /* Setup registers for 3D context
  */
  */
@@ -165,25 +164,25 @@ typedef struct {
 /* General aging mechanism
 /* General aging mechanism
  */
  */
 typedef struct {
 typedef struct {
-	unsigned int head;		/* Position of head pointer          */
-	unsigned int wrap;		/* Primary DMA wrap count            */
+	unsigned int head;	/* Position of head pointer          */
+	unsigned int wrap;	/* Primary DMA wrap count            */
 } drm_mga_age_t;
 } drm_mga_age_t;
 
 
 typedef struct _drm_mga_sarea {
 typedef struct _drm_mga_sarea {
 	/* The channel for communication of state information to the kernel
 	/* The channel for communication of state information to the kernel
 	 * on firing a vertex dma buffer.
 	 * on firing a vertex dma buffer.
 	 */
 	 */
-   	drm_mga_context_regs_t context_state;
-   	drm_mga_server_regs_t server_state;
-   	drm_mga_texture_regs_t tex_state[2];
-   	unsigned int warp_pipe;
-   	unsigned int dirty;
-   	unsigned int vertsize;
+	drm_mga_context_regs_t context_state;
+	drm_mga_server_regs_t server_state;
+	drm_mga_texture_regs_t tex_state[2];
+	unsigned int warp_pipe;
+	unsigned int dirty;
+	unsigned int vertsize;
 
 
 	/* The current cliprects, or a subset thereof.
 	/* The current cliprects, or a subset thereof.
 	 */
 	 */
-   	drm_clip_rect_t boxes[MGA_NR_SAREA_CLIPRECTS];
-   	unsigned int nbox;
+	drm_clip_rect_t boxes[MGA_NR_SAREA_CLIPRECTS];
+	unsigned int nbox;
 
 
 	/* Information about the most recently used 3d drawable.  The
 	/* Information about the most recently used 3d drawable.  The
 	 * client fills in the req_* fields, the server fills in the
 	 * client fills in the req_* fields, the server fills in the
@@ -192,18 +191,18 @@ typedef struct _drm_mga_sarea {
 	 * The client clears the exported_drawable field before
 	 * The client clears the exported_drawable field before
 	 * clobbering the boxes data.
 	 * clobbering the boxes data.
 	 */
 	 */
-        unsigned int req_drawable;	 /* the X drawable id */
-	unsigned int req_draw_buffer;	 /* MGA_FRONT or MGA_BACK */
+	unsigned int req_drawable;	/* the X drawable id */
+	unsigned int req_draw_buffer;	/* MGA_FRONT or MGA_BACK */
 
 
-        unsigned int exported_drawable;
+	unsigned int exported_drawable;
 	unsigned int exported_index;
 	unsigned int exported_index;
-        unsigned int exported_stamp;
-        unsigned int exported_buffers;
-        unsigned int exported_nfront;
-        unsigned int exported_nback;
+	unsigned int exported_stamp;
+	unsigned int exported_buffers;
+	unsigned int exported_nfront;
+	unsigned int exported_nback;
 	int exported_back_x, exported_front_x, exported_w;
 	int exported_back_x, exported_front_x, exported_w;
 	int exported_back_y, exported_front_y, exported_h;
 	int exported_back_y, exported_front_y, exported_h;
-   	drm_clip_rect_t exported_boxes[MGA_NR_SAREA_CLIPRECTS];
+	drm_clip_rect_t exported_boxes[MGA_NR_SAREA_CLIPRECTS];
 
 
 	/* Counters for aging textures and for client-side throttling.
 	/* Counters for aging textures and for client-side throttling.
 	 */
 	 */
@@ -211,21 +210,20 @@ typedef struct _drm_mga_sarea {
 	unsigned int last_wrap;
 	unsigned int last_wrap;
 
 
 	drm_mga_age_t last_frame;
 	drm_mga_age_t last_frame;
-        unsigned int last_enqueue;	/* last time a buffer was enqueued */
+	unsigned int last_enqueue;	/* last time a buffer was enqueued */
 	unsigned int last_dispatch;	/* age of the most recently dispatched buffer */
 	unsigned int last_dispatch;	/* age of the most recently dispatched buffer */
-	unsigned int last_quiescent;     /*  */
+	unsigned int last_quiescent;	/*  */
 
 
 	/* LRU lists for texture memory in agp space and on the card.
 	/* LRU lists for texture memory in agp space and on the card.
 	 */
 	 */
-	drm_tex_region_t texList[MGA_NR_TEX_HEAPS][MGA_NR_TEX_REGIONS+1];
+	drm_tex_region_t texList[MGA_NR_TEX_HEAPS][MGA_NR_TEX_REGIONS + 1];
 	unsigned int texAge[MGA_NR_TEX_HEAPS];
 	unsigned int texAge[MGA_NR_TEX_HEAPS];
 
 
 	/* Mechanism to validate card state.
 	/* Mechanism to validate card state.
 	 */
 	 */
-   	int ctxOwner;
+	int ctxOwner;
 } drm_mga_sarea_t;
 } drm_mga_sarea_t;
 
 
-
 /* MGA specific ioctls
 /* MGA specific ioctls
  * The device specific ioctl range is 0x40 to 0x79.
  * The device specific ioctl range is 0x40 to 0x79.
  */
  */
@@ -247,7 +245,6 @@ typedef struct _drm_mga_sarea {
 #define DRM_MGA_WAIT_FENCE     0x0b
 #define DRM_MGA_WAIT_FENCE     0x0b
 #define DRM_MGA_DMA_BOOTSTRAP  0x0c
 #define DRM_MGA_DMA_BOOTSTRAP  0x0c
 
 
-
 #define DRM_IOCTL_MGA_INIT     DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_INIT, drm_mga_init_t)
 #define DRM_IOCTL_MGA_INIT     DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_INIT, drm_mga_init_t)
 #define DRM_IOCTL_MGA_FLUSH    DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_FLUSH, drm_lock_t)
 #define DRM_IOCTL_MGA_FLUSH    DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_FLUSH, drm_lock_t)
 #define DRM_IOCTL_MGA_RESET    DRM_IO(  DRM_COMMAND_BASE + DRM_MGA_RESET)
 #define DRM_IOCTL_MGA_RESET    DRM_IO(  DRM_COMMAND_BASE + DRM_MGA_RESET)
@@ -263,33 +260,33 @@ typedef struct _drm_mga_sarea {
 #define DRM_IOCTL_MGA_DMA_BOOTSTRAP DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_DMA_BOOTSTRAP, drm_mga_dma_bootstrap_t)
 #define DRM_IOCTL_MGA_DMA_BOOTSTRAP DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_DMA_BOOTSTRAP, drm_mga_dma_bootstrap_t)
 
 
 typedef struct _drm_mga_warp_index {
 typedef struct _drm_mga_warp_index {
-   	int installed;
-   	unsigned long phys_addr;
-   	int size;
+	int installed;
+	unsigned long phys_addr;
+	int size;
 } drm_mga_warp_index_t;
 } drm_mga_warp_index_t;
 
 
 typedef struct drm_mga_init {
 typedef struct drm_mga_init {
-   	enum {
-	   	MGA_INIT_DMA    = 0x01,
-	       	MGA_CLEANUP_DMA = 0x02
+	enum {
+		MGA_INIT_DMA = 0x01,
+		MGA_CLEANUP_DMA = 0x02
 	} func;
 	} func;
 
 
-   	unsigned long sarea_priv_offset;
+	unsigned long sarea_priv_offset;
 
 
 	int chipset;
 	int chipset;
-   	int sgram;
+	int sgram;
 
 
 	unsigned int maccess;
 	unsigned int maccess;
 
 
-   	unsigned int fb_cpp;
+	unsigned int fb_cpp;
 	unsigned int front_offset, front_pitch;
 	unsigned int front_offset, front_pitch;
-   	unsigned int back_offset, back_pitch;
+	unsigned int back_offset, back_pitch;
 
 
-   	unsigned int depth_cpp;
-   	unsigned int depth_offset, depth_pitch;
+	unsigned int depth_cpp;
+	unsigned int depth_offset, depth_pitch;
 
 
-   	unsigned int texture_offset[MGA_NR_TEX_HEAPS];
-   	unsigned int texture_size[MGA_NR_TEX_HEAPS];
+	unsigned int texture_offset[MGA_NR_TEX_HEAPS];
+	unsigned int texture_size[MGA_NR_TEX_HEAPS];
 
 
 	unsigned long fb_offset;
 	unsigned long fb_offset;
 	unsigned long mmio_offset;
 	unsigned long mmio_offset;
@@ -302,64 +299,59 @@ typedef struct drm_mga_init {
 typedef struct drm_mga_dma_bootstrap {
 typedef struct drm_mga_dma_bootstrap {
 	/**
 	/**
 	 * \name AGP texture region
 	 * \name AGP texture region
-	 * 
+	 *
 	 * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, these fields will
 	 * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, these fields will
 	 * be filled in with the actual AGP texture settings.
 	 * be filled in with the actual AGP texture settings.
-	 * 
+	 *
 	 * \warning
 	 * \warning
 	 * If these fields are non-zero, but dma_mga_dma_bootstrap::agp_mode
 	 * If these fields are non-zero, but dma_mga_dma_bootstrap::agp_mode
 	 * is zero, it means that PCI memory (most likely through the use of
 	 * is zero, it means that PCI memory (most likely through the use of
 	 * an IOMMU) is being used for "AGP" textures.
 	 * an IOMMU) is being used for "AGP" textures.
 	 */
 	 */
-	/*@{*/
+	/*@{ */
 	unsigned long texture_handle; /**< Handle used to map AGP textures. */
 	unsigned long texture_handle; /**< Handle used to map AGP textures. */
-	uint32_t     texture_size;    /**< Size of the AGP texture region. */
-	/*@}*/
-
+	uint32_t texture_size;	      /**< Size of the AGP texture region. */
+	/*@} */
 
 
 	/**
 	/**
 	 * Requested size of the primary DMA region.
 	 * Requested size of the primary DMA region.
-	 * 
+	 *
 	 * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
 	 * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
 	 * filled in with the actual AGP mode.  If AGP was not available
 	 * filled in with the actual AGP mode.  If AGP was not available
 	 */
 	 */
 	uint32_t primary_size;
 	uint32_t primary_size;
 
 
-
 	/**
 	/**
 	 * Requested number of secondary DMA buffers.
 	 * Requested number of secondary DMA buffers.
-	 * 
+	 *
 	 * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
 	 * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
 	 * filled in with the actual number of secondary DMA buffers
 	 * filled in with the actual number of secondary DMA buffers
 	 * allocated.  Particularly when PCI DMA is used, this may be
 	 * allocated.  Particularly when PCI DMA is used, this may be
 	 * (subtantially) less than the number requested.
 	 * (subtantially) less than the number requested.
 	 */
 	 */
 	uint32_t secondary_bin_count;
 	uint32_t secondary_bin_count;
-	
-	
+
 	/**
 	/**
 	 * Requested size of each secondary DMA buffer.
 	 * Requested size of each secondary DMA buffer.
-	 * 
+	 *
 	 * While the kernel \b is free to reduce
 	 * While the kernel \b is free to reduce
 	 * dma_mga_dma_bootstrap::secondary_bin_count, it is \b not allowed
 	 * dma_mga_dma_bootstrap::secondary_bin_count, it is \b not allowed
 	 * to reduce dma_mga_dma_bootstrap::secondary_bin_size.
 	 * to reduce dma_mga_dma_bootstrap::secondary_bin_size.
 	 */
 	 */
 	uint32_t secondary_bin_size;
 	uint32_t secondary_bin_size;
 
 
-
 	/**
 	/**
 	 * Bit-wise mask of AGPSTAT2_* values.  Currently only \c AGPSTAT2_1X,
 	 * Bit-wise mask of AGPSTAT2_* values.  Currently only \c AGPSTAT2_1X,
 	 * \c AGPSTAT2_2X, and \c AGPSTAT2_4X are supported.  If this value is
 	 * \c AGPSTAT2_2X, and \c AGPSTAT2_4X are supported.  If this value is
 	 * zero, it means that PCI DMA should be used, even if AGP is
 	 * zero, it means that PCI DMA should be used, even if AGP is
 	 * possible.
 	 * possible.
-	 * 
+	 *
 	 * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
 	 * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
 	 * filled in with the actual AGP mode.  If AGP was not available
 	 * filled in with the actual AGP mode.  If AGP was not available
 	 * (i.e., PCI DMA was used), this value will be zero.
 	 * (i.e., PCI DMA was used), this value will be zero.
 	 */
 	 */
 	uint32_t agp_mode;
 	uint32_t agp_mode;
 
 
-
 	/**
 	/**
 	 * Desired AGP GART size, measured in megabytes.
 	 * Desired AGP GART size, measured in megabytes.
 	 */
 	 */
@@ -375,16 +367,16 @@ typedef struct drm_mga_clear {
 } drm_mga_clear_t;
 } drm_mga_clear_t;
 
 
 typedef struct drm_mga_vertex {
 typedef struct drm_mga_vertex {
-   	int idx;			/* buffer to queue */
-	int used;			/* bytes in use */
-	int discard;			/* client finished with buffer?  */
+	int idx;		/* buffer to queue */
+	int used;		/* bytes in use */
+	int discard;		/* client finished with buffer?  */
 } drm_mga_vertex_t;
 } drm_mga_vertex_t;
 
 
 typedef struct drm_mga_indices {
 typedef struct drm_mga_indices {
-   	int idx;			/* buffer to queue */
+	int idx;		/* buffer to queue */
 	unsigned int start;
 	unsigned int start;
 	unsigned int end;
 	unsigned int end;
-	int discard;			/* client finished with buffer?  */
+	int discard;		/* client finished with buffer?  */
 } drm_mga_indices_t;
 } drm_mga_indices_t;
 
 
 typedef struct drm_mga_iload {
 typedef struct drm_mga_iload {
@@ -400,12 +392,12 @@ typedef struct _drm_mga_blit {
 	int src_pitch, dst_pitch;
 	int src_pitch, dst_pitch;
 	int delta_sx, delta_sy;
 	int delta_sx, delta_sy;
 	int delta_dx, delta_dy;
 	int delta_dx, delta_dy;
-	int height, ydir;		/* flip image vertically */
+	int height, ydir;	/* flip image vertically */
 	int source_pitch, dest_pitch;
 	int source_pitch, dest_pitch;
 } drm_mga_blit_t;
 } drm_mga_blit_t;
 
 
 /* 3.1: An ioctl to get parameters that aren't available to the 3d
 /* 3.1: An ioctl to get parameters that aren't available to the 3d
- * client any other way.  
+ * client any other way.
  */
  */
 #define MGA_PARAM_IRQ_NR            1
 #define MGA_PARAM_IRQ_NR            1
 
 

+ 38 - 42
drivers/char/drm/mga_drv.c

@@ -35,14 +35,13 @@
 #include "mga_drm.h"
 #include "mga_drm.h"
 #include "mga_drv.h"
 #include "mga_drv.h"
 
 
-  
 #include "drm_pciids.h"
 #include "drm_pciids.h"
 
 
 static int mga_driver_device_is_agp(drm_device_t * dev);
 static int mga_driver_device_is_agp(drm_device_t * dev);
-static int postinit( struct drm_device *dev, unsigned long flags )
+static int postinit(struct drm_device *dev, unsigned long flags)
 {
 {
-	drm_mga_private_t * const dev_priv =
-		(drm_mga_private_t *) dev->dev_private;
+	drm_mga_private_t *const dev_priv =
+	    (drm_mga_private_t *) dev->dev_private;
 
 
 	dev_priv->mmio_base = pci_resource_start(dev->pdev, 1);
 	dev_priv->mmio_base = pci_resource_start(dev->pdev, 1);
 	dev_priv->mmio_size = pci_resource_len(dev->pdev, 1);
 	dev_priv->mmio_size = pci_resource_len(dev->pdev, 1);
@@ -52,28 +51,26 @@ static int postinit( struct drm_device *dev, unsigned long flags )
 	dev->types[7] = _DRM_STAT_PRIMARY;
 	dev->types[7] = _DRM_STAT_PRIMARY;
 	dev->types[8] = _DRM_STAT_SECONDARY;
 	dev->types[8] = _DRM_STAT_SECONDARY;
 
 
-	DRM_INFO( "Initialized %s %d.%d.%d %s on minor %d: %s\n",
-		DRIVER_NAME,
-		DRIVER_MAJOR,
-		DRIVER_MINOR,
-		DRIVER_PATCHLEVEL,
-		DRIVER_DATE,
-		dev->primary.minor,
-		pci_pretty_name(dev->pdev)
-		);
+	DRM_INFO("Initialized %s %d.%d.%d %s on minor %d: %s\n",
+		 DRIVER_NAME,
+		 DRIVER_MAJOR,
+		 DRIVER_MINOR,
+		 DRIVER_PATCHLEVEL,
+		 DRIVER_DATE, dev->primary.minor, pci_pretty_name(dev->pdev)
+	    );
 	return 0;
 	return 0;
 }
 }
 
 
-static int version( drm_version_t *version )
+static int version(drm_version_t * version)
 {
 {
 	int len;
 	int len;
 
 
 	version->version_major = DRIVER_MAJOR;
 	version->version_major = DRIVER_MAJOR;
 	version->version_minor = DRIVER_MINOR;
 	version->version_minor = DRIVER_MINOR;
 	version->version_patchlevel = DRIVER_PATCHLEVEL;
 	version->version_patchlevel = DRIVER_PATCHLEVEL;
-	DRM_COPY( version->name, DRIVER_NAME );
-	DRM_COPY( version->date, DRIVER_DATE );
-	DRM_COPY( version->desc, DRIVER_DESC );
+	DRM_COPY(version->name, DRIVER_NAME);
+	DRM_COPY(version->date, DRIVER_DATE);
+	DRM_COPY(version->desc, DRIVER_DESC);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -81,11 +78,11 @@ static struct pci_device_id pciidlist[] = {
 	mga_PCI_IDS
 	mga_PCI_IDS
 };
 };
 
 
-extern drm_ioctl_desc_t mga_ioctls[];
-extern int mga_max_ioctl;
-
 static struct drm_driver driver = {
 static struct drm_driver driver = {
-	.driver_features = DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL,
+	.driver_features =
+	    DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
+	    DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
+	    DRIVER_IRQ_VBL,
 	.preinit = mga_driver_preinit,
 	.preinit = mga_driver_preinit,
 	.postcleanup = mga_driver_postcleanup,
 	.postcleanup = mga_driver_postcleanup,
 	.pretakedown = mga_driver_pretakedown,
 	.pretakedown = mga_driver_pretakedown,
@@ -104,21 +101,21 @@ static struct drm_driver driver = {
 	.ioctls = mga_ioctls,
 	.ioctls = mga_ioctls,
 	.dma_ioctl = mga_dma_buffers,
 	.dma_ioctl = mga_dma_buffers,
 	.fops = {
 	.fops = {
-		.owner = THIS_MODULE,
-		.open = drm_open,
-		.release = drm_release,
-		.ioctl = drm_ioctl,
-		.mmap = drm_mmap,
-		.poll = drm_poll,
-		.fasync = drm_fasync,
+		 .owner = THIS_MODULE,
+		 .open = drm_open,
+		 .release = drm_release,
+		 .ioctl = drm_ioctl,
+		 .mmap = drm_mmap,
+		 .poll = drm_poll,
+		 .fasync = drm_fasync,
 #ifdef CONFIG_COMPAT
 #ifdef CONFIG_COMPAT
-		.compat_ioctl = mga_compat_ioctl,
+		 .compat_ioctl = mga_compat_ioctl,
 #endif
 #endif
-	},
+		 },
 	.pci_driver = {
 	.pci_driver = {
-		.name = DRIVER_NAME,
-		.id_table = pciidlist,
-	}
+		       .name = DRIVER_NAME,
+		       .id_table = pciidlist,
+		       }
 };
 };
 
 
 static int __init mga_init(void)
 static int __init mga_init(void)
@@ -135,8 +132,8 @@ static void __exit mga_exit(void)
 module_init(mga_init);
 module_init(mga_init);
 module_exit(mga_exit);
 module_exit(mga_exit);
 
 
-MODULE_AUTHOR( DRIVER_AUTHOR );
-MODULE_DESCRIPTION( DRIVER_DESC );
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL and additional rights");
 MODULE_LICENSE("GPL and additional rights");
 
 
 /**
 /**
@@ -151,10 +148,9 @@ MODULE_LICENSE("GPL and additional rights");
  * \returns
  * \returns
  * If the device is a PCI G450, zero is returned.  Otherwise 2 is returned.
  * If the device is a PCI G450, zero is returned.  Otherwise 2 is returned.
  */
  */
-int mga_driver_device_is_agp(drm_device_t * dev)
+static int mga_driver_device_is_agp(drm_device_t * dev)
 {
 {
-	const struct pci_dev * const pdev = dev->pdev;
-
+	const struct pci_dev *const pdev = dev->pdev;
 
 
 	/* There are PCI versions of the G450.  These cards have the
 	/* There are PCI versions of the G450.  These cards have the
 	 * same PCI ID as the AGP G450, but have an additional PCI-to-PCI
 	 * same PCI ID as the AGP G450, but have an additional PCI-to-PCI
@@ -164,10 +160,10 @@ int mga_driver_device_is_agp(drm_device_t * dev)
 	 * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the
 	 * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the
 	 * device.
 	 * device.
 	 */
 	 */
-	
-	if ( (pdev->device == 0x0525)
-	     && (pdev->bus->self->vendor == 0x3388)
-	     && (pdev->bus->self->device == 0x0021) ) {
+
+	if ((pdev->device == 0x0525)
+	    && (pdev->bus->self->vendor == 0x3388)
+	    && (pdev->bus->self->device == 0x0021)) {
 		return 0;
 		return 0;
 	}
 	}
 
 

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно