summaryrefslogtreecommitdiff
path: root/target/linux
diff options
context:
space:
mode:
Diffstat (limited to 'target/linux')
-rw-r--r--target/linux/ps3/patches-2.6.28/0002-powerpc-ps3-Replace-the-flip_ctl-logic-in-ps3av-and.patch182
-rw-r--r--target/linux/ps3/patches-2.6.28/0003-powerpc-ps3-Add-sub-match-id-modalias-support.patch176
-rw-r--r--target/linux/ps3/patches-2.6.28/0005-mtd-ps3vram-Add-ps3vram-driver-for-accessing-video.patch29
-rw-r--r--target/linux/ps3/patches-2.6.28/0006-mtd-ps3vram-Add-modalias-support-to-the-ps3vram-dri.patch25
-rw-r--r--target/linux/ps3/patches-2.6.28/0010-ps3vram-ng.patch957
5 files changed, 1369 insertions, 0 deletions
diff --git a/target/linux/ps3/patches-2.6.28/0002-powerpc-ps3-Replace-the-flip_ctl-logic-in-ps3av-and.patch b/target/linux/ps3/patches-2.6.28/0002-powerpc-ps3-Replace-the-flip_ctl-logic-in-ps3av-and.patch
new file mode 100644
index 0000000..40cf93d
--- /dev/null
+++ b/target/linux/ps3/patches-2.6.28/0002-powerpc-ps3-Replace-the-flip_ctl-logic-in-ps3av-and.patch
@@ -0,0 +1,182 @@
+From 9b82f3e61758ed897200f0244b63a77c1791bcba Mon Sep 17 00:00:00 2001
+From: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
+Date: Thu, 30 Oct 2008 08:12:58 +0000
+Subject: powerpc/ps3: Replace the flip_ctl logic in ps3av and ps3fb by a mutex
+
+Introduce ps3_gpu_mutex to synchronizes GPU-related operations, like:
+ - invoking the L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT command using the
+ lv1_gpu_context_attribute() hypervisor call,
+ - handling the PS3AV_CID_AVB_PARAM packet in the PS3 A/V Settings driver.
+
+Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
+Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
+Signed-off-by: Paul Mackerras <paulus@samba.org>
+---
+ arch/powerpc/include/asm/ps3.h | 3 +++
+ arch/powerpc/include/asm/ps3av.h | 4 ----
+ arch/powerpc/platforms/ps3/setup.c | 4 ++++
+ drivers/ps3/ps3av.c | 20 --------------------
+ drivers/ps3/ps3av_cmd.c | 4 ++--
+ drivers/video/ps3fb.c | 17 +++++------------
+ 6 files changed, 14 insertions(+), 38 deletions(-)
+
+diff --git a/arch/powerpc/include/asm/ps3.h b/arch/powerpc/include/asm/ps3.h
+index f9e34c4..4299365 100644
+--- a/arch/powerpc/include/asm/ps3.h
++++ b/arch/powerpc/include/asm/ps3.h
+@@ -516,4 +516,7 @@ void ps3_sync_irq(int node);
+ u32 ps3_get_hw_thread_id(int cpu);
+ u64 ps3_get_spe_id(void *arg);
+
++/* mutex synchronizing GPU accesses and video mode changes */
++extern struct mutex ps3_gpu_mutex;
++
+ #endif
+diff --git a/arch/powerpc/include/asm/ps3av.h b/arch/powerpc/include/asm/ps3av.h
+index 5aa22cf..cd24ac1 100644
+--- a/arch/powerpc/include/asm/ps3av.h
++++ b/arch/powerpc/include/asm/ps3av.h
+@@ -740,8 +740,4 @@ extern int ps3av_audio_mute(int);
+ extern int ps3av_audio_mute_analog(int);
+ extern int ps3av_dev_open(void);
+ extern int ps3av_dev_close(void);
+-extern void ps3av_register_flip_ctl(void (*flip_ctl)(int on, void *data),
+- void *flip_data);
+-extern void ps3av_flip_ctl(int on);
+-
+ #endif /* _ASM_POWERPC_PS3AV_H_ */
+diff --git a/arch/powerpc/platforms/ps3/setup.c b/arch/powerpc/platforms/ps3/setup.c
+index 77bc330..bfc33fb 100644
+--- a/arch/powerpc/platforms/ps3/setup.c
++++ b/arch/powerpc/platforms/ps3/setup.c
+@@ -42,6 +42,10 @@
+ #define DBG pr_debug
+ #endif
+
++/* mutex synchronizing GPU accesses and video mode changes */
++DEFINE_MUTEX(ps3_gpu_mutex);
++EXPORT_SYMBOL_GPL(ps3_gpu_mutex);
++
+ #if !defined(CONFIG_SMP)
+ static void smp_send_stop(void) {}
+ #endif
+diff --git a/drivers/ps3/ps3av.c b/drivers/ps3/ps3av.c
+index 06848b2..5324978 100644
+--- a/drivers/ps3/ps3av.c
++++ b/drivers/ps3/ps3av.c
+@@ -59,8 +59,6 @@ static struct ps3av {
+ struct ps3av_reply_hdr reply_hdr;
+ u8 raw[PS3AV_BUF_SIZE];
+ } recv_buf;
+- void (*flip_ctl)(int on, void *data);
+- void *flip_data;
+ } *ps3av;
+
+ /* color space */
+@@ -939,24 +937,6 @@ int ps3av_audio_mute(int mute)
+
+ EXPORT_SYMBOL_GPL(ps3av_audio_mute);
+
+-void ps3av_register_flip_ctl(void (*flip_ctl)(int on, void *data),
+- void *flip_data)
+-{
+- mutex_lock(&ps3av->mutex);
+- ps3av->flip_ctl = flip_ctl;
+- ps3av->flip_data = flip_data;
+- mutex_unlock(&ps3av->mutex);
+-}
+-EXPORT_SYMBOL_GPL(ps3av_register_flip_ctl);
+-
+-void ps3av_flip_ctl(int on)
+-{
+- mutex_lock(&ps3av->mutex);
+- if (ps3av->flip_ctl)
+- ps3av->flip_ctl(on, ps3av->flip_data);
+- mutex_unlock(&ps3av->mutex);
+-}
+-
+ static int ps3av_probe(struct ps3_system_bus_device *dev)
+ {
+ int res;
+diff --git a/drivers/ps3/ps3av_cmd.c b/drivers/ps3/ps3av_cmd.c
+index 11eb503..716596e 100644
+--- a/drivers/ps3/ps3av_cmd.c
++++ b/drivers/ps3/ps3av_cmd.c
+@@ -864,7 +864,7 @@ int ps3av_cmd_avb_param(struct ps3av_pkt_avb_param *avb, u32 send_len)
+ {
+ int res;
+
+- ps3av_flip_ctl(0); /* flip off */
++ mutex_lock(&ps3_gpu_mutex);
+
+ /* avb packet */
+ res = ps3av_do_pkt(PS3AV_CID_AVB_PARAM, send_len, sizeof(*avb),
+@@ -878,7 +878,7 @@ int ps3av_cmd_avb_param(struct ps3av_pkt_avb_param *avb, u32 send_len)
+ res);
+
+ out:
+- ps3av_flip_ctl(1); /* flip on */
++ mutex_unlock(&ps3_gpu_mutex);
+ return res;
+ }
+
+diff --git a/drivers/video/ps3fb.c b/drivers/video/ps3fb.c
+index 4b5d807..bd3e39b 100644
+--- a/drivers/video/ps3fb.c
++++ b/drivers/video/ps3fb.c
+@@ -460,12 +460,16 @@ static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
+ line_length |= (u64)src_line_length << 32;
+
+ src_offset += GPU_FB_START;
++
++ mutex_lock(&ps3_gpu_mutex);
+ status = lv1_gpu_context_attribute(ps3fb.context_handle,
+ L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
+ dst_offset, GPU_IOIF + src_offset,
+ L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
+ (width << 16) | height,
+ line_length);
++ mutex_unlock(&ps3_gpu_mutex);
++
+ if (status)
+ dev_err(dev,
+ "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
+@@ -784,15 +788,6 @@ static int ps3fb_wait_for_vsync(u32 crtc)
+ return 0;
+ }
+
+-static void ps3fb_flip_ctl(int on, void *data)
+-{
+- struct ps3fb_priv *priv = data;
+- if (on)
+- atomic_dec_if_positive(&priv->ext_flip);
+- else
+- atomic_inc(&priv->ext_flip);
+-}
+-
+
+ /*
+ * ioctl
+@@ -1228,7 +1223,6 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
+ }
+
+ ps3fb.task = task;
+- ps3av_register_flip_ctl(ps3fb_flip_ctl, &ps3fb);
+
+ return 0;
+
+@@ -1258,10 +1252,9 @@ static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
+
+ dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__);
+
+- ps3fb_flip_ctl(0, &ps3fb); /* flip off */
++ atomic_inc(&ps3fb.ext_flip); /* flip off */
+ ps3fb.dinfo->irq.mask = 0;
+
+- ps3av_register_flip_ctl(NULL, NULL);
+ if (ps3fb.task) {
+ struct task_struct *task = ps3fb.task;
+ ps3fb.task = NULL;
+--
+1.6.0.4
+
diff --git a/target/linux/ps3/patches-2.6.28/0003-powerpc-ps3-Add-sub-match-id-modalias-support.patch b/target/linux/ps3/patches-2.6.28/0003-powerpc-ps3-Add-sub-match-id-modalias-support.patch
new file mode 100644
index 0000000..5f42184
--- /dev/null
+++ b/target/linux/ps3/patches-2.6.28/0003-powerpc-ps3-Add-sub-match-id-modalias-support.patch
@@ -0,0 +1,176 @@
+From 46d01492b2c50791b9b66f9b9154ac8d25acaeb9 Mon Sep 17 00:00:00 2001
+From: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
+Date: Wed, 3 Dec 2008 13:52:21 +0000
+Subject: powerpc/ps3: Add sub-match id modalias support
+
+commit 059e4938f8b060b10c4352e6c45739473bc73267 ("powerpc/ps3: Add a sub-match
+id to ps3_system_bus") forgot to update the module alias support:
+ - Add the sub-match ids to the module aliases, so udev can distinguish
+ between different types of sub-devices.
+ - Rename PS3_MODULE_ALIAS_GRAPHICS to PS3_MODULE_ALIAS_GPU_FB, as ps3fb
+ binds to the "FB" sub-device.
+
+Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
+Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
+Signed-off-by: Paul Mackerras <paulus@samba.org>
+---
+ arch/powerpc/include/asm/ps3.h | 53 ++++++++++++++---------------
+ arch/powerpc/platforms/ps3/device-init.c | 4 +-
+ arch/powerpc/platforms/ps3/system-bus.c | 10 +++--
+ drivers/video/ps3fb.c | 6 ++--
+ 4 files changed, 37 insertions(+), 36 deletions(-)
+
+diff --git a/arch/powerpc/include/asm/ps3.h b/arch/powerpc/include/asm/ps3.h
+index 4299365..cff30c0 100644
+--- a/arch/powerpc/include/asm/ps3.h
++++ b/arch/powerpc/include/asm/ps3.h
+@@ -305,30 +305,34 @@ static inline const char* ps3_result(int result)
+ /* system bus routines */
+
+ enum ps3_match_id {
+- PS3_MATCH_ID_EHCI = 1,
+- PS3_MATCH_ID_OHCI = 2,
+- PS3_MATCH_ID_GELIC = 3,
+- PS3_MATCH_ID_AV_SETTINGS = 4,
+- PS3_MATCH_ID_SYSTEM_MANAGER = 5,
+- PS3_MATCH_ID_STOR_DISK = 6,
+- PS3_MATCH_ID_STOR_ROM = 7,
+- PS3_MATCH_ID_STOR_FLASH = 8,
+- PS3_MATCH_ID_SOUND = 9,
+- PS3_MATCH_ID_GRAPHICS = 10,
+- PS3_MATCH_ID_LPM = 11,
++ PS3_MATCH_ID_EHCI = 1,
++ PS3_MATCH_ID_OHCI = 2,
++ PS3_MATCH_ID_GELIC = 3,
++ PS3_MATCH_ID_AV_SETTINGS = 4,
++ PS3_MATCH_ID_SYSTEM_MANAGER = 5,
++ PS3_MATCH_ID_STOR_DISK = 6,
++ PS3_MATCH_ID_STOR_ROM = 7,
++ PS3_MATCH_ID_STOR_FLASH = 8,
++ PS3_MATCH_ID_SOUND = 9,
++ PS3_MATCH_ID_GPU = 10,
++ PS3_MATCH_ID_LPM = 11,
+ };
+
+-#define PS3_MODULE_ALIAS_EHCI "ps3:1"
+-#define PS3_MODULE_ALIAS_OHCI "ps3:2"
+-#define PS3_MODULE_ALIAS_GELIC "ps3:3"
+-#define PS3_MODULE_ALIAS_AV_SETTINGS "ps3:4"
+-#define PS3_MODULE_ALIAS_SYSTEM_MANAGER "ps3:5"
+-#define PS3_MODULE_ALIAS_STOR_DISK "ps3:6"
+-#define PS3_MODULE_ALIAS_STOR_ROM "ps3:7"
+-#define PS3_MODULE_ALIAS_STOR_FLASH "ps3:8"
+-#define PS3_MODULE_ALIAS_SOUND "ps3:9"
+-#define PS3_MODULE_ALIAS_GRAPHICS "ps3:10"
+-#define PS3_MODULE_ALIAS_LPM "ps3:11"
++enum ps3_match_sub_id {
++ PS3_MATCH_SUB_ID_GPU_FB = 1,
++};
++
++#define PS3_MODULE_ALIAS_EHCI "ps3:1:0"
++#define PS3_MODULE_ALIAS_OHCI "ps3:2:0"
++#define PS3_MODULE_ALIAS_GELIC "ps3:3:0"
++#define PS3_MODULE_ALIAS_AV_SETTINGS "ps3:4:0"
++#define PS3_MODULE_ALIAS_SYSTEM_MANAGER "ps3:5:0"
++#define PS3_MODULE_ALIAS_STOR_DISK "ps3:6:0"
++#define PS3_MODULE_ALIAS_STOR_ROM "ps3:7:0"
++#define PS3_MODULE_ALIAS_STOR_FLASH "ps3:8:0"
++#define PS3_MODULE_ALIAS_SOUND "ps3:9:0"
++#define PS3_MODULE_ALIAS_GPU_FB "ps3:10:1"
++#define PS3_MODULE_ALIAS_LPM "ps3:11:0"
+
+ enum ps3_system_bus_device_type {
+ PS3_DEVICE_TYPE_IOC0 = 1,
+@@ -337,11 +341,6 @@ enum ps3_system_bus_device_type {
+ PS3_DEVICE_TYPE_LPM,
+ };
+
+-enum ps3_match_sub_id {
+- /* for PS3_MATCH_ID_GRAPHICS */
+- PS3_MATCH_SUB_ID_FB = 1,
+-};
+-
+ /**
+ * struct ps3_system_bus_device - a device on the system bus
+ */
+diff --git a/arch/powerpc/platforms/ps3/device-init.c b/arch/powerpc/platforms/ps3/device-init.c
+index 43816da..dbc124e 100644
+--- a/arch/powerpc/platforms/ps3/device-init.c
++++ b/arch/powerpc/platforms/ps3/device-init.c
+@@ -497,8 +497,8 @@ static int __init ps3_register_graphics_devices(void)
+ if (!p)
+ return -ENOMEM;
+
+- p->dev.match_id = PS3_MATCH_ID_GRAPHICS;
+- p->dev.match_sub_id = PS3_MATCH_SUB_ID_FB;
++ p->dev.match_id = PS3_MATCH_ID_GPU;
++ p->dev.match_sub_id = PS3_MATCH_SUB_ID_GPU_FB;
+ p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;
+
+ result = ps3_system_bus_device_register(&p->dev);
+diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platforms/ps3/system-bus.c
+index 661e9f7..d3da1e6 100644
+--- a/arch/powerpc/platforms/ps3/system-bus.c
++++ b/arch/powerpc/platforms/ps3/system-bus.c
+@@ -175,7 +175,7 @@ int ps3_open_hv_device(struct ps3_system_bus_device *dev)
+ return ps3_open_hv_device_sb(dev);
+
+ case PS3_MATCH_ID_SOUND:
+- case PS3_MATCH_ID_GRAPHICS:
++ case PS3_MATCH_ID_GPU:
+ return ps3_open_hv_device_gpu(dev);
+
+ case PS3_MATCH_ID_AV_SETTINGS:
+@@ -213,7 +213,7 @@ int ps3_close_hv_device(struct ps3_system_bus_device *dev)
+ return ps3_close_hv_device_sb(dev);
+
+ case PS3_MATCH_ID_SOUND:
+- case PS3_MATCH_ID_GRAPHICS:
++ case PS3_MATCH_ID_GPU:
+ return ps3_close_hv_device_gpu(dev);
+
+ case PS3_MATCH_ID_AV_SETTINGS:
+@@ -453,7 +453,8 @@ static int ps3_system_bus_uevent(struct device *_dev, struct kobj_uevent_env *en
+ {
+ struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
+
+- if (add_uevent_var(env, "MODALIAS=ps3:%d", dev->match_id))
++ if (add_uevent_var(env, "MODALIAS=ps3:%d:%d", dev->match_id,
++ dev->match_sub_id))
+ return -ENOMEM;
+ return 0;
+ }
+@@ -462,7 +463,8 @@ static ssize_t modalias_show(struct device *_dev, struct device_attribute *a,
+ char *buf)
+ {
+ struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
+- int len = snprintf(buf, PAGE_SIZE, "ps3:%d\n", dev->match_id);
++ int len = snprintf(buf, PAGE_SIZE, "ps3:%d:%d\n", dev->match_id,
++ dev->match_sub_id);
+
+ return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
+ }
+diff --git a/drivers/video/ps3fb.c b/drivers/video/ps3fb.c
+index bd3e39b..38ac805 100644
+--- a/drivers/video/ps3fb.c
++++ b/drivers/video/ps3fb.c
+@@ -1289,8 +1289,8 @@ static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
+ }
+
+ static struct ps3_system_bus_driver ps3fb_driver = {
+- .match_id = PS3_MATCH_ID_GRAPHICS,
+- .match_sub_id = PS3_MATCH_SUB_ID_FB,
++ .match_id = PS3_MATCH_ID_GPU,
++ .match_sub_id = PS3_MATCH_SUB_ID_GPU_FB,
+ .core.name = DEVICE_NAME,
+ .core.owner = THIS_MODULE,
+ .probe = ps3fb_probe,
+@@ -1348,4 +1348,4 @@ module_exit(ps3fb_exit);
+ MODULE_LICENSE("GPL");
+ MODULE_DESCRIPTION("PS3 GPU Frame Buffer Driver");
+ MODULE_AUTHOR("Sony Computer Entertainment Inc.");
+-MODULE_ALIAS(PS3_MODULE_ALIAS_GRAPHICS);
++MODULE_ALIAS(PS3_MODULE_ALIAS_GPU_FB);
+--
+1.6.0.4
+
diff --git a/target/linux/ps3/patches-2.6.28/0005-mtd-ps3vram-Add-ps3vram-driver-for-accessing-video.patch b/target/linux/ps3/patches-2.6.28/0005-mtd-ps3vram-Add-ps3vram-driver-for-accessing-video.patch
new file mode 100644
index 0000000..3c5efa6
--- /dev/null
+++ b/target/linux/ps3/patches-2.6.28/0005-mtd-ps3vram-Add-ps3vram-driver-for-accessing-video.patch
@@ -0,0 +1,29 @@
+From cffb4add03b1fc83026b06dc3664279cfbf70155 Mon Sep 17 00:00:00 2001
+From: Jim Paris <jim@jtan.com>
+Date: Tue, 6 Jan 2009 11:32:10 +0000
+Subject: [PATCH] mtd/ps3vram: Add ps3vram driver for accessing video RAM as MTD
+
+Add ps3vram driver, which exposes unused video RAM on the PS3 as a MTD
+device suitable for storage or swap. Fast data transfer is achieved
+using a local cache in system RAM and DMA transfers via the GPU.
+
+Signed-off-by: Vivien Chappelier <vivien.chappelier@free.fr>
+Signed-off-by: Jim Paris <jim@jtan.com>
+Acked-by: Geoff Levand <geoffrey.levand@am.sony.com>
+Acked-by: David Woodhouse <David.Woodhouse@intel.com>
+Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
+---
+ arch/powerpc/include/asm/ps3.h | 1 +
+
+diff --git a/arch/powerpc/include/asm/ps3.h b/arch/powerpc/include/asm/ps3.h
+index cff30c0..66b6505 100644
+--- a/arch/powerpc/include/asm/ps3.h
++++ b/arch/powerpc/include/asm/ps3.h
+@@ -320,6 +320,7 @@ enum ps3_match_id {
+
+ enum ps3_match_sub_id {
+ PS3_MATCH_SUB_ID_GPU_FB = 1,
++ PS3_MATCH_SUB_ID_GPU_RAMDISK = 2,
+ };
+
+ #define PS3_MODULE_ALIAS_EHCI "ps3:1:0"
diff --git a/target/linux/ps3/patches-2.6.28/0006-mtd-ps3vram-Add-modalias-support-to-the-ps3vram-dri.patch b/target/linux/ps3/patches-2.6.28/0006-mtd-ps3vram-Add-modalias-support-to-the-ps3vram-dri.patch
new file mode 100644
index 0000000..243c186
--- /dev/null
+++ b/target/linux/ps3/patches-2.6.28/0006-mtd-ps3vram-Add-modalias-support-to-the-ps3vram-dri.patch
@@ -0,0 +1,25 @@
+From 0a2d15b928e0b1673d4ed5f48d95af211b6fcc06 Mon Sep 17 00:00:00 2001
+From: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
+Date: Tue, 6 Jan 2009 11:32:03 +0000
+Subject: [PATCH] mtd/ps3vram: Add modalias support to the ps3vram driver
+
+Update ps3vram driver to use the new ps3 three id modalias support.
+
+Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
+Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
+Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
+---
+ arch/powerpc/include/asm/ps3.h | 1 +
+
+diff --git a/arch/powerpc/include/asm/ps3.h b/arch/powerpc/include/asm/ps3.h
+index 66b6505..eead5c6 100644
+--- a/arch/powerpc/include/asm/ps3.h
++++ b/arch/powerpc/include/asm/ps3.h
+@@ -333,6 +333,7 @@ enum ps3_match_sub_id {
+ #define PS3_MODULE_ALIAS_STOR_FLASH "ps3:8:0"
+ #define PS3_MODULE_ALIAS_SOUND "ps3:9:0"
+ #define PS3_MODULE_ALIAS_GPU_FB "ps3:10:1"
++#define PS3_MODULE_ALIAS_GPU_RAMDISK "ps3:10:2"
+ #define PS3_MODULE_ALIAS_LPM "ps3:11:0"
+
+ enum ps3_system_bus_device_type {
diff --git a/target/linux/ps3/patches-2.6.28/0010-ps3vram-ng.patch b/target/linux/ps3/patches-2.6.28/0010-ps3vram-ng.patch
new file mode 100644
index 0000000..8c29d80
--- /dev/null
+++ b/target/linux/ps3/patches-2.6.28/0010-ps3vram-ng.patch
@@ -0,0 +1,957 @@
+From d7ddc1aaee1ff6dd6a73bd3663b6c390800e0500 Mon Sep 17 00:00:00 2001
+From: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
+Date: Wed, 25 Feb 2009 18:32:10 +0100
+Subject: [PATCH] ps3/block: Replace mtd/ps3vram by block/ps3vram
+
+Convert the PS3 Video RAM Storage Driver from a MTD driver to a plain block
+device driver, as requested by Arnd Bergmann.
+
+The ps3vram driver exposes unused video RAM on the PS3 as a block device
+suitable for storage or swap. Fast data transfer is achieved using a local
+cache in system RAM and DMA transfers via the GPU.
+
+The new driver is ca. 50% faster for reading, and ca. 10% for writing.
+
+Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
+Acked-by: Jens Axboe <axboe@kernel.dk>
+Acked-by: Geoff Levand <geoffrey.levand@am.sony.com>
+Cc: Arnd Bergmann <arnd@arndb.de>
+Cc: David Woodhouse <David.Woodhouse@intel.com>
+Cc: Vivien Chappelier <vivien.chappelier@free.fr>
+Cc: Jim Paris <jim@jtan.com>
+
+Notes:
+
+The MTD-based PS3 Video RAM Storage Driver was integrated into the mainline
+kernel in 2.6.29-rc1.
+
+Ideally, we think it would be best if the existing MTD-based ps3vram driver
+would be replaced by the new block-based ps3vram driver before 2.6.29 is
+released. This would relieve the burden of supporting two different swap space
+schemes on PS3 (swap on /dev/mtdblock0 vs. /dev/ps3vram) from the distro
+maintainer's shoulders, as in that case there would never have been a stable
+kernel version containing the MTD-based ps3vram driver.
+
+Changes since previous submission (Wed, 4 Mar 2009 14:57:20 +0100 (CET)):
+ - Use blk_queue_make_request() to get rid of the thread
+ - Add a mutex (cfr. the old driver), as ps3vram_make_request() may be called
+ concurrently
+ TO DO (after 2.6.29): use a spinlock and a list to queue requests while the
+ driver is busy
+ - Remove the old MTD-based ps3vram driver and rename ps3vram-ng to ps3vram
+ - Make PS3_VRAM depend on FB_PS3=y and m for now
+ ps3vram relies on ps3fb being initialized first. The easiest way to do this
+ is by making ps3vram modular, and ps3fb builtin
+ - Remove the dependency on ps3fb_videomemory.size
+ The loop to reduce ddr_size until it succeeds does the right thing anyway,
+ and a few MiB of DDR RAM are reserved by the hypervisor
+ - lv1 return codes can be int
+ - Correct a few debug annotations
+---
+ arch/powerpc/platforms/ps3/Kconfig | 7 +
+ drivers/block/Makefile | 1 +
+ drivers/block/ps3vram.c | 865 ++++++++++++++++++++++++++++++++++++
+ create mode 100644 drivers/block/ps3vram.c
+ delete mode 100644 drivers/mtd/devices/ps3vram.c
+
+diff --git a/arch/powerpc/platforms/ps3/Kconfig b/arch/powerpc/platforms/ps3/Kconfig
+index 920cf7a..740ef56 100644
+--- a/arch/powerpc/platforms/ps3/Kconfig
++++ b/arch/powerpc/platforms/ps3/Kconfig
+@@ -128,6 +128,13 @@ config PS3_FLASH
+ be disabled on the kernel command line using "ps3flash=off", to
+ not allocate this fixed buffer.
+
++config PS3_VRAM
++ tristate "PS3 Video RAM Storage Driver"
++ depends on FB_PS3=y && BLOCK && m
++ help
++ This driver allows you to use excess PS3 video RAM as volatile
++ storage or system swap.
++
+ config PS3_LPM
+ tristate "PS3 Logical Performance Monitor support"
+ depends on PPC_PS3
+diff --git a/drivers/block/Makefile b/drivers/block/Makefile
+index 204332b..87e120e 100644
+--- a/drivers/block/Makefile
++++ b/drivers/block/Makefile
+@@ -9,6 +9,7 @@ obj-$(CONFIG_MAC_FLOPPY) += swim3.o
+ obj-$(CONFIG_BLK_DEV_FD) += floppy.o
+ obj-$(CONFIG_AMIGA_FLOPPY) += amiflop.o
+ obj-$(CONFIG_PS3_DISK) += ps3disk.o
++obj-$(CONFIG_PS3_VRAM) += ps3vram.o
+ obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o
+ obj-$(CONFIG_AMIGA_Z2RAM) += z2ram.o
+ obj-$(CONFIG_BLK_DEV_RAM) += brd.o
+diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c
+new file mode 100644
+index 0000000..393ed67
+--- /dev/null
++++ b/drivers/block/ps3vram.c
+@@ -0,0 +1,865 @@
++/*
++ * ps3vram - Use extra PS3 video ram as MTD block device.
++ *
++ * Copyright 2009 Sony Corporation
++ *
++ * Based on the MTD ps3vram driver, which is
++ * Copyright (c) 2007-2008 Jim Paris <jim@jtan.com>
++ * Added support RSX DMA Vivien Chappelier <vivien.chappelier@free.fr>
++ */
++
++#include <linux/blkdev.h>
++#include <linux/delay.h>
++#include <linux/proc_fs.h>
++#include <linux/seq_file.h>
++
++#include <asm/firmware.h>
++#include <asm/lv1call.h>
++#include <asm/ps3.h>
++
++
++#define DEVICE_NAME "ps3vram"
++
++
++#define XDR_BUF_SIZE (2 * 1024 * 1024) /* XDR buffer (must be 1MiB aligned) */
++#define XDR_IOIF 0x0c000000
++
++#define FIFO_BASE XDR_IOIF
++#define FIFO_SIZE (64 * 1024)
++
++#define DMA_PAGE_SIZE (4 * 1024)
++
++#define CACHE_PAGE_SIZE (256 * 1024)
++#define CACHE_PAGE_COUNT ((XDR_BUF_SIZE - FIFO_SIZE) / CACHE_PAGE_SIZE)
++
++#define CACHE_OFFSET CACHE_PAGE_SIZE
++#define FIFO_OFFSET 0
++
++#define CTRL_PUT 0x10
++#define CTRL_GET 0x11
++#define CTRL_TOP 0x15
++
++#define UPLOAD_SUBCH 1
++#define DOWNLOAD_SUBCH 2
++
++#define NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN 0x0000030c
++#define NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY 0x00000104
++
++#define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT 0x601
++
++#define CACHE_PAGE_PRESENT 1
++#define CACHE_PAGE_DIRTY 2
++
++struct ps3vram_tag {
++ unsigned int address;
++ unsigned int flags;
++};
++
++struct ps3vram_cache {
++ unsigned int page_count;
++ unsigned int page_size;
++ struct ps3vram_tag *tags;
++ unsigned int hit;
++ unsigned int miss;
++};
++
++struct ps3vram_priv {
++ struct request_queue *queue;
++ struct gendisk *gendisk;
++
++ u64 size;
++
++ u64 memory_handle;
++ u64 context_handle;
++ u32 *ctrl;
++ u32 *reports;
++ u8 __iomem *ddr_base;
++ u8 *xdr_buf;
++
++ u32 *fifo_base;
++ u32 *fifo_ptr;
++
++ struct ps3vram_cache cache;
++
++ /* Used to serialize cache/DMA operations */
++ struct mutex lock;
++};
++
++
++static int ps3vram_major;
++
++
++static struct block_device_operations ps3vram_fops = {
++ .owner = THIS_MODULE,
++};
++
++
++#define DMA_NOTIFIER_HANDLE_BASE 0x66604200 /* first DMA notifier handle */
++#define DMA_NOTIFIER_OFFSET_BASE 0x1000 /* first DMA notifier offset */
++#define DMA_NOTIFIER_SIZE 0x40
++#define NOTIFIER 7 /* notifier used for completion report */
++
++static char *size = "256M";
++module_param(size, charp, 0);
++MODULE_PARM_DESC(size, "memory size");
++
++static u32 *ps3vram_get_notifier(u32 *reports, int notifier)
++{
++ return (void *)reports + DMA_NOTIFIER_OFFSET_BASE +
++ DMA_NOTIFIER_SIZE * notifier;
++}
++
++static void ps3vram_notifier_reset(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER);
++ int i;
++
++ for (i = 0; i < 4; i++)
++ notify[i] = 0xffffffff;
++}
++
++static int ps3vram_notifier_wait(struct ps3_system_bus_device *dev,
++ unsigned int timeout_ms)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER);
++ unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
++
++ do {
++ if (!notify[3])
++ return 0;
++ msleep(1);
++ } while (time_before(jiffies, timeout));
++
++ return -ETIMEDOUT;
++}
++
++static void ps3vram_init_ring(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++
++ priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET;
++ priv->ctrl[CTRL_GET] = FIFO_BASE + FIFO_OFFSET;
++}
++
++static int ps3vram_wait_ring(struct ps3_system_bus_device *dev,
++ unsigned int timeout_ms)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
++
++ do {
++ if (priv->ctrl[CTRL_PUT] == priv->ctrl[CTRL_GET])
++ return 0;
++ msleep(1);
++ } while (time_before(jiffies, timeout));
++
++ dev_warn(&dev->core, "FIFO timeout (%08x/%08x/%08x)\n",
++ priv->ctrl[CTRL_PUT], priv->ctrl[CTRL_GET],
++ priv->ctrl[CTRL_TOP]);
++
++ return -ETIMEDOUT;
++}
++
++static void ps3vram_out_ring(struct ps3vram_priv *priv, u32 data)
++{
++ *(priv->fifo_ptr)++ = data;
++}
++
++static void ps3vram_begin_ring(struct ps3vram_priv *priv, u32 chan, u32 tag,
++ u32 size)
++{
++ ps3vram_out_ring(priv, (size << 18) | (chan << 13) | tag);
++}
++
++static void ps3vram_rewind_ring(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ int status;
++
++ ps3vram_out_ring(priv, 0x20000000 | (FIFO_BASE + FIFO_OFFSET));
++
++ priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET;
++
++ /* asking the HV for a blit will kick the FIFO */
++ status = lv1_gpu_context_attribute(priv->context_handle,
++ L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT, 0,
++ 0, 0, 0);
++ if (status)
++ dev_err(&dev->core,
++ "%s: lv1_gpu_context_attribute failed %d\n", __func__,
++ status);
++
++ priv->fifo_ptr = priv->fifo_base;
++}
++
++static void ps3vram_fire_ring(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ int status;
++
++ mutex_lock(&ps3_gpu_mutex);
++
++ priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET +
++ (priv->fifo_ptr - priv->fifo_base) * sizeof(u32);
++
++ /* asking the HV for a blit will kick the FIFO */
++ status = lv1_gpu_context_attribute(priv->context_handle,
++ L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT, 0,
++ 0, 0, 0);
++ if (status)
++ dev_err(&dev->core,
++ "%s: lv1_gpu_context_attribute failed %d\n", __func__,
++ status);
++
++ if ((priv->fifo_ptr - priv->fifo_base) * sizeof(u32) >
++ FIFO_SIZE - 1024) {
++ dev_dbg(&dev->core, "FIFO full, rewinding\n");
++ ps3vram_wait_ring(dev, 200);
++ ps3vram_rewind_ring(dev);
++ }
++
++ mutex_unlock(&ps3_gpu_mutex);
++}
++
++static void ps3vram_bind(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++
++ ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0, 1);
++ ps3vram_out_ring(priv, 0x31337303);
++ ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0x180, 3);
++ ps3vram_out_ring(priv, DMA_NOTIFIER_HANDLE_BASE + NOTIFIER);
++ ps3vram_out_ring(priv, 0xfeed0001); /* DMA system RAM instance */
++ ps3vram_out_ring(priv, 0xfeed0000); /* DMA video RAM instance */
++
++ ps3vram_begin_ring(priv, DOWNLOAD_SUBCH, 0, 1);
++ ps3vram_out_ring(priv, 0x3137c0de);
++ ps3vram_begin_ring(priv, DOWNLOAD_SUBCH, 0x180, 3);
++ ps3vram_out_ring(priv, DMA_NOTIFIER_HANDLE_BASE + NOTIFIER);
++ ps3vram_out_ring(priv, 0xfeed0000); /* DMA video RAM instance */
++ ps3vram_out_ring(priv, 0xfeed0001); /* DMA system RAM instance */
++
++ ps3vram_fire_ring(dev);
++}
++
++static int ps3vram_upload(struct ps3_system_bus_device *dev,
++ unsigned int src_offset, unsigned int dst_offset,
++ int len, int count)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++
++ ps3vram_begin_ring(priv, UPLOAD_SUBCH,
++ NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
++ ps3vram_out_ring(priv, XDR_IOIF + src_offset);
++ ps3vram_out_ring(priv, dst_offset);
++ ps3vram_out_ring(priv, len);
++ ps3vram_out_ring(priv, len);
++ ps3vram_out_ring(priv, len);
++ ps3vram_out_ring(priv, count);
++ ps3vram_out_ring(priv, (1 << 8) | 1);
++ ps3vram_out_ring(priv, 0);
++
++ ps3vram_notifier_reset(dev);
++ ps3vram_begin_ring(priv, UPLOAD_SUBCH,
++ NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY, 1);
++ ps3vram_out_ring(priv, 0);
++ ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0x100, 1);
++ ps3vram_out_ring(priv, 0);
++ ps3vram_fire_ring(dev);
++ if (ps3vram_notifier_wait(dev, 200) < 0) {
++ dev_warn(&dev->core, "%s: Notifier timeout\n", __func__);
++ return -1;
++ }
++
++ return 0;
++}
++
++static int ps3vram_download(struct ps3_system_bus_device *dev,
++ unsigned int src_offset, unsigned int dst_offset,
++ int len, int count)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++
++ ps3vram_begin_ring(priv, DOWNLOAD_SUBCH,
++ NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
++ ps3vram_out_ring(priv, src_offset);
++ ps3vram_out_ring(priv, XDR_IOIF + dst_offset);
++ ps3vram_out_ring(priv, len);
++ ps3vram_out_ring(priv, len);
++ ps3vram_out_ring(priv, len);
++ ps3vram_out_ring(priv, count);
++ ps3vram_out_ring(priv, (1 << 8) | 1);
++ ps3vram_out_ring(priv, 0);
++
++ ps3vram_notifier_reset(dev);
++ ps3vram_begin_ring(priv, DOWNLOAD_SUBCH,
++ NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY, 1);
++ ps3vram_out_ring(priv, 0);
++ ps3vram_begin_ring(priv, DOWNLOAD_SUBCH, 0x100, 1);
++ ps3vram_out_ring(priv, 0);
++ ps3vram_fire_ring(dev);
++ if (ps3vram_notifier_wait(dev, 200) < 0) {
++ dev_warn(&dev->core, "%s: Notifier timeout\n", __func__);
++ return -1;
++ }
++
++ return 0;
++}
++
++static void ps3vram_cache_evict(struct ps3_system_bus_device *dev, int entry)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ struct ps3vram_cache *cache = &priv->cache;
++
++ if (!(cache->tags[entry].flags & CACHE_PAGE_DIRTY))
++ return;
++
++ dev_dbg(&dev->core, "Flushing %d: 0x%08x\n", entry,
++ cache->tags[entry].address);
++ if (ps3vram_upload(dev, CACHE_OFFSET + entry * cache->page_size,
++ cache->tags[entry].address, DMA_PAGE_SIZE,
++ cache->page_size / DMA_PAGE_SIZE) < 0) {
++ dev_err(&dev->core,
++ "Failed to upload from 0x%x to " "0x%x size 0x%x\n",
++ entry * cache->page_size, cache->tags[entry].address,
++ cache->page_size);
++ }
++ cache->tags[entry].flags &= ~CACHE_PAGE_DIRTY;
++}
++
++static void ps3vram_cache_load(struct ps3_system_bus_device *dev, int entry,
++ unsigned int address)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ struct ps3vram_cache *cache = &priv->cache;
++
++ dev_dbg(&dev->core, "Fetching %d: 0x%08x\n", entry, address);
++ if (ps3vram_download(dev, address,
++ CACHE_OFFSET + entry * cache->page_size,
++ DMA_PAGE_SIZE,
++ cache->page_size / DMA_PAGE_SIZE) < 0) {
++ dev_err(&dev->core,
++ "Failed to download from 0x%x to 0x%x size 0x%x\n",
++ address, entry * cache->page_size, cache->page_size);
++ }
++
++ cache->tags[entry].address = address;
++ cache->tags[entry].flags |= CACHE_PAGE_PRESENT;
++}
++
++
++static void ps3vram_cache_flush(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ struct ps3vram_cache *cache = &priv->cache;
++ int i;
++
++ dev_dbg(&dev->core, "FLUSH\n");
++ for (i = 0; i < cache->page_count; i++) {
++ ps3vram_cache_evict(dev, i);
++ cache->tags[i].flags = 0;
++ }
++}
++
++static unsigned int ps3vram_cache_match(struct ps3_system_bus_device *dev,
++ loff_t address)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ struct ps3vram_cache *cache = &priv->cache;
++ unsigned int base;
++ unsigned int offset;
++ int i;
++ static int counter;
++
++ offset = (unsigned int) (address & (cache->page_size - 1));
++ base = (unsigned int) (address - offset);
++
++ /* fully associative check */
++ for (i = 0; i < cache->page_count; i++) {
++ if ((cache->tags[i].flags & CACHE_PAGE_PRESENT) &&
++ cache->tags[i].address == base) {
++ cache->hit++;
++ dev_dbg(&dev->core, "Found entry %d: 0x%08x\n", i,
++ cache->tags[i].address);
++ return i;
++ }
++ }
++
++ /* choose a random entry */
++ i = (jiffies + (counter++)) % cache->page_count;
++ dev_dbg(&dev->core, "Using entry %d\n", i);
++
++ ps3vram_cache_evict(dev, i);
++ ps3vram_cache_load(dev, i, base);
++
++ cache->miss++;
++ return i;
++}
++
++static int ps3vram_cache_init(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++
++ priv->cache.page_count = CACHE_PAGE_COUNT;
++ priv->cache.page_size = CACHE_PAGE_SIZE;
++ priv->cache.tags = kzalloc(sizeof(struct ps3vram_tag) *
++ CACHE_PAGE_COUNT, GFP_KERNEL);
++ if (priv->cache.tags == NULL) {
++ dev_err(&dev->core, "Could not allocate cache tags\n");
++ return -ENOMEM;
++ }
++
++ dev_info(&dev->core, "Created ram cache: %d entries, %d KiB each\n",
++ CACHE_PAGE_COUNT, CACHE_PAGE_SIZE / 1024);
++
++ return 0;
++}
++
++static void ps3vram_cache_cleanup(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++
++ ps3vram_cache_flush(dev);
++ kfree(priv->cache.tags);
++}
++
++static int ps3vram_read(struct ps3_system_bus_device *dev, loff_t from,
++ size_t len, size_t *retlen, u_char *buf)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ unsigned int cached, count;
++
++ dev_dbg(&dev->core, "%s: from=0x%08x len=0x%zx\n", __func__,
++ (unsigned int)from, len);
++
++ if (from >= priv->size)
++ return -EIO;
++
++ if (len > priv->size - from)
++ len = priv->size - from;
++
++ /* Copy from vram to buf */
++ count = len;
++ while (count) {
++ unsigned int offset, avail;
++ unsigned int entry;
++
++ offset = (unsigned int) (from & (priv->cache.page_size - 1));
++ avail = priv->cache.page_size - offset;
++
++ mutex_lock(&priv->lock);
++
++ entry = ps3vram_cache_match(dev, from);
++ cached = CACHE_OFFSET + entry * priv->cache.page_size + offset;
++
++ dev_dbg(&dev->core, "%s: from=%08x cached=%08x offset=%08x "
++ "avail=%08x count=%08x\n", __func__,
++ (unsigned int)from, cached, offset, avail, count);
++
++ if (avail > count)
++ avail = count;
++ memcpy(buf, priv->xdr_buf + cached, avail);
++
++ mutex_unlock(&priv->lock);
++
++ buf += avail;
++ count -= avail;
++ from += avail;
++ }
++
++ *retlen = len;
++ return 0;
++}
++
++static int ps3vram_write(struct ps3_system_bus_device *dev, loff_t to,
++ size_t len, size_t *retlen, const u_char *buf)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ unsigned int cached, count;
++
++ if (to >= priv->size)
++ return -EIO;
++
++ if (len > priv->size - to)
++ len = priv->size - to;
++
++ /* Copy from buf to vram */
++ count = len;
++ while (count) {
++ unsigned int offset, avail;
++ unsigned int entry;
++
++ offset = (unsigned int) (to & (priv->cache.page_size - 1));
++ avail = priv->cache.page_size - offset;
++
++ mutex_lock(&priv->lock);
++
++ entry = ps3vram_cache_match(dev, to);
++ cached = CACHE_OFFSET + entry * priv->cache.page_size + offset;
++
++ dev_dbg(&dev->core, "%s: to=%08x cached=%08x offset=%08x "
++ "avail=%08x count=%08x\n", __func__, (unsigned int)to,
++ cached, offset, avail, count);
++
++ if (avail > count)
++ avail = count;
++ memcpy(priv->xdr_buf + cached, buf, avail);
++
++ priv->cache.tags[entry].flags |= CACHE_PAGE_DIRTY;
++
++ mutex_unlock(&priv->lock);
++
++ buf += avail;
++ count -= avail;
++ to += avail;
++ }
++
++ *retlen = len;
++ return 0;
++}
++
++static int ps3vram_proc_show(struct seq_file *m, void *v)
++{
++ struct ps3vram_priv *priv = m->private;
++
++ seq_printf(m, "hit:%u\nmiss:%u\n", priv->cache.hit, priv->cache.miss);
++ return 0;
++}
++
++static int ps3vram_proc_open(struct inode *inode, struct file *file)
++{
++ return single_open(file, ps3vram_proc_show, PDE(inode)->data);
++}
++
++static const struct file_operations ps3vram_proc_fops = {
++ .owner = THIS_MODULE,
++ .open = ps3vram_proc_open,
++ .read = seq_read,
++ .llseek = seq_lseek,
++ .release = single_release,
++};
++
++static void __devinit ps3vram_proc_init(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++ struct proc_dir_entry *pde;
++
++ pde = proc_create(DEVICE_NAME, 0444, NULL, &ps3vram_proc_fops);
++ if (!pde) {
++ dev_warn(&dev->core, "failed to create /proc entry\n");
++ return;
++ }
++
++ pde->owner = THIS_MODULE;
++ pde->data = priv;
++}
++
++static int ps3vram_make_request(struct request_queue *q, struct bio *bio)
++{
++ struct ps3_system_bus_device *dev = q->queuedata;
++ int write = bio_data_dir(bio) == WRITE;
++ const char *op = write ? "write" : "read";
++ loff_t offset = bio->bi_sector << 9;
++ int error = 0;
++ struct bio_vec *bvec;
++ unsigned int i;
++
++ dev_dbg(&dev->core, "%s\n", __func__);
++
++ bio_for_each_segment(bvec, bio, i) {
++ /* PS3 is ppc64, so we don't handle highmem */
++ char *ptr = page_address(bvec->bv_page) + bvec->bv_offset;
++ size_t len = bvec->bv_len, retlen;
++
++ dev_dbg(&dev->core, " %s %zu bytes at offset %llu\n", op,
++ len, offset);
++ if (write)
++ error = ps3vram_write(dev, offset, len, &retlen, ptr);
++ else
++ error = ps3vram_read(dev, offset, len, &retlen, ptr);
++
++ if (error) {
++ dev_err(&dev->core, "%s failed\n", op);
++ goto out;
++ }
++
++ if (retlen != len) {
++ dev_err(&dev->core, "Short %s\n", op);
++ goto out;
++ }
++
++ offset += len;
++ }
++
++ dev_dbg(&dev->core, "%s completed\n", op);
++
++out:
++ bio_endio(bio, error);
++ return 0;
++}
++
++static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv;
++ int error, status;
++ struct request_queue *queue;
++ struct gendisk *gendisk;
++ u64 ddr_lpar, ctrl_lpar, info_lpar, reports_lpar, ddr_size,
++ reports_size;
++ char *rest;
++
++ priv = kzalloc(sizeof(*priv), GFP_KERNEL);
++ if (!priv) {
++ error = -ENOMEM;
++ goto fail;
++ }
++
++ mutex_init(&priv->lock);
++ dev->core.driver_data = priv;
++
++ priv = dev->core.driver_data;
++
++ /* Allocate XDR buffer (1MiB aligned) */
++ priv->xdr_buf = (void *)__get_free_pages(GFP_KERNEL,
++ get_order(XDR_BUF_SIZE));
++ if (priv->xdr_buf == NULL) {
++ dev_err(&dev->core, "Could not allocate XDR buffer\n");
++ error = -ENOMEM;
++ goto fail_free_priv;
++ }
++
++ /* Put FIFO at begginning of XDR buffer */
++ priv->fifo_base = (u32 *) (priv->xdr_buf + FIFO_OFFSET);
++ priv->fifo_ptr = priv->fifo_base;
++
++ /* XXX: Need to open GPU, in case ps3fb or snd_ps3 aren't loaded */
++ if (ps3_open_hv_device(dev)) {
++ dev_err(&dev->core, "ps3_open_hv_device failed\n");
++ error = -EAGAIN;
++ goto out_close_gpu;
++ }
++
++ /* Request memory */
++ status = -1;
++ ddr_size = ALIGN(memparse(size, &rest), 1024*1024);
++ if (!ddr_size) {
++ dev_err(&dev->core, "Specified size is too small\n");
++ error = -EINVAL;
++ goto out_close_gpu;
++ }
++
++ while (ddr_size > 0) {
++ status = lv1_gpu_memory_allocate(ddr_size, 0, 0, 0, 0,
++ &priv->memory_handle,
++ &ddr_lpar);
++ if (!status)
++ break;
++ ddr_size -= 1024*1024;
++ }
++ if (status) {
++ dev_err(&dev->core, "lv1_gpu_memory_allocate failed %d\n",
++ status);
++ error = -ENOMEM;
++ goto out_free_xdr_buf;
++ }
++
++ /* Request context */
++ status = lv1_gpu_context_allocate(priv->memory_handle, 0,
++ &priv->context_handle, &ctrl_lpar,
++ &info_lpar, &reports_lpar,
++ &reports_size);
++ if (status) {
++ dev_err(&dev->core, "lv1_gpu_context_allocate failed %d\n",
++ status);
++ error = -ENOMEM;
++ goto out_free_memory;
++ }
++
++ /* Map XDR buffer to RSX */
++ status = lv1_gpu_context_iomap(priv->context_handle, XDR_IOIF,
++ ps3_mm_phys_to_lpar(__pa(priv->xdr_buf)),
++ XDR_BUF_SIZE, 0);
++ if (status) {
++ dev_err(&dev->core, "lv1_gpu_context_iomap failed %d\n",
++ status);
++ error = -ENOMEM;
++ goto out_free_context;
++ }
++
++ priv->ddr_base = ioremap_flags(ddr_lpar, ddr_size, _PAGE_NO_CACHE);
++
++ if (!priv->ddr_base) {
++ dev_err(&dev->core, "ioremap DDR failed\n");
++ error = -ENOMEM;
++ goto out_free_context;
++ }
++
++ priv->ctrl = ioremap(ctrl_lpar, 64 * 1024);
++ if (!priv->ctrl) {
++ dev_err(&dev->core, "ioremap CTRL failed\n");
++ error = -ENOMEM;
++ goto out_unmap_vram;
++ }
++
++ priv->reports = ioremap(reports_lpar, reports_size);
++ if (!priv->reports) {
++ dev_err(&dev->core, "ioremap REPORTS failed\n");
++ error = -ENOMEM;
++ goto out_unmap_ctrl;
++ }
++
++ mutex_lock(&ps3_gpu_mutex);
++ ps3vram_init_ring(dev);
++ mutex_unlock(&ps3_gpu_mutex);
++
++ priv->size = ddr_size;
++
++ ps3vram_bind(dev);
++
++ mutex_lock(&ps3_gpu_mutex);
++ error = ps3vram_wait_ring(dev, 100);
++ mutex_unlock(&ps3_gpu_mutex);
++ if (error < 0) {
++ dev_err(&dev->core, "Failed to initialize channels\n");
++ error = -ETIMEDOUT;
++ goto out_unmap_reports;
++ }
++
++ ps3vram_cache_init(dev);
++ ps3vram_proc_init(dev);
++
++ queue = blk_alloc_queue(GFP_KERNEL);
++ if (!queue) {
++ dev_err(&dev->core, "blk_alloc_queue failed\n");
++ error = -ENOMEM;
++ goto out_cache_cleanup;
++ }
++
++ priv->queue = queue;
++ queue->queuedata = dev;
++ blk_queue_make_request(queue, ps3vram_make_request);
++ blk_queue_max_phys_segments(queue, MAX_PHYS_SEGMENTS);
++ blk_queue_max_hw_segments(queue, MAX_HW_SEGMENTS);
++ blk_queue_max_segment_size(queue, MAX_SEGMENT_SIZE);
++ blk_queue_max_sectors(queue, SAFE_MAX_SECTORS);
++
++ gendisk = alloc_disk(1);
++ if (!gendisk) {
++ dev_err(&dev->core, "alloc_disk failed\n");
++ error = -ENOMEM;
++ goto fail_cleanup_queue;
++ }
++
++ priv->gendisk = gendisk;
++ gendisk->major = ps3vram_major;
++ gendisk->first_minor = 0;
++ gendisk->fops = &ps3vram_fops;
++ gendisk->queue = queue;
++ gendisk->private_data = dev;
++ gendisk->driverfs_dev = &dev->core;
++ strlcpy(gendisk->disk_name, DEVICE_NAME, sizeof(gendisk->disk_name));
++ set_capacity(gendisk, priv->size >> 9);
++
++ dev_info(&dev->core, "%s: Using %lu MiB of GPU memory\n",
++ gendisk->disk_name, get_capacity(gendisk) >> 11);
++
++ add_disk(gendisk);
++ return 0;
++
++fail_cleanup_queue:
++ blk_cleanup_queue(queue);
++out_cache_cleanup:
++ remove_proc_entry(DEVICE_NAME, NULL);
++ ps3vram_cache_cleanup(dev);
++out_unmap_reports:
++ iounmap(priv->reports);
++out_unmap_ctrl:
++ iounmap(priv->ctrl);
++out_unmap_vram:
++ iounmap(priv->ddr_base);
++out_free_context:
++ lv1_gpu_context_free(priv->context_handle);
++out_free_memory:
++ lv1_gpu_memory_free(priv->memory_handle);
++out_close_gpu:
++ ps3_close_hv_device(dev);
++out_free_xdr_buf:
++ free_pages((unsigned long) priv->xdr_buf, get_order(XDR_BUF_SIZE));
++fail_free_priv:
++ kfree(priv);
++ dev->core.driver_data = NULL;
++fail:
++ return error;
++}
++
++static int ps3vram_remove(struct ps3_system_bus_device *dev)
++{
++ struct ps3vram_priv *priv = dev->core.driver_data;
++
++ del_gendisk(priv->gendisk);
++ put_disk(priv->gendisk);
++ blk_cleanup_queue(priv->queue);
++ remove_proc_entry(DEVICE_NAME, NULL);
++ ps3vram_cache_cleanup(dev);
++ iounmap(priv->reports);
++ iounmap(priv->ctrl);
++ iounmap(priv->ddr_base);
++ lv1_gpu_context_free(priv->context_handle);
++ lv1_gpu_memory_free(priv->memory_handle);
++ ps3_close_hv_device(dev);
++ free_pages((unsigned long) priv->xdr_buf, get_order(XDR_BUF_SIZE));
++ kfree(priv);
++ dev->core.driver_data = NULL;
++ return 0;
++}
++
++static struct ps3_system_bus_driver ps3vram = {
++ .match_id = PS3_MATCH_ID_GPU,
++ .match_sub_id = PS3_MATCH_SUB_ID_GPU_RAMDISK,
++ .core.name = DEVICE_NAME,
++ .core.owner = THIS_MODULE,
++ .probe = ps3vram_probe,
++ .remove = ps3vram_remove,
++ .shutdown = ps3vram_remove,
++};
++
++
++static int __init ps3vram_init(void)
++{
++ int error;
++
++ if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
++ return -ENODEV;
++
++ error = register_blkdev(0, DEVICE_NAME);
++ if (error <= 0) {
++ pr_err("%s: register_blkdev failed %d\n", DEVICE_NAME, error);
++ return error;
++ }
++ ps3vram_major = error;
++
++ pr_info("%s: registered block device major %d\n", DEVICE_NAME,
++ ps3vram_major);
++
++ error = ps3_system_bus_driver_register(&ps3vram);
++ if (error)
++ unregister_blkdev(ps3vram_major, DEVICE_NAME);
++
++ return error;
++}
++
++static void __exit ps3vram_exit(void)
++{
++ ps3_system_bus_driver_unregister(&ps3vram);
++ unregister_blkdev(ps3vram_major, DEVICE_NAME);
++}
++
++module_init(ps3vram_init);
++module_exit(ps3vram_exit);
++
++MODULE_LICENSE("GPL");
++MODULE_DESCRIPTION("PS3 Video RAM Storage Driver");
++MODULE_AUTHOR("Sony Corporation");
++MODULE_ALIAS(PS3_MODULE_ALIAS_GPU_RAMDISK);