1 From f507cd22035fdadd5dbb476dd05e9e7ee21c3b84 Mon Sep 17 00:00:00 2001
2 From: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
3 Date: Fri, 6 Mar 2009 02:54:09 +0000
4 Subject: [PATCH] ps3/block: Replace mtd/ps3vram by block/ps3vram
6 Convert the PS3 Video RAM Storage Driver from an MTD driver to a plain block
9 The ps3vram driver exposes unused video RAM on the PS3 as a block device
10 suitable for storage or swap. Fast data transfer is achieved using a local
11 cache in system RAM and DMA transfers via the GPU.
13 The new driver is ca. 50% faster for reading, and ca. 10% for writing.
15 Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
16 Acked-by: Geoff Levand <geoffrey.levand@am.sony.com>
17 Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
19 arch/powerpc/platforms/ps3/Kconfig | 7 +
20 drivers/block/Makefile | 1 +
21 drivers/block/ps3vram.c | 865 ++++++++++++++++++++++++++++++++++++
22 drivers/mtd/devices/Kconfig | 7 -
23 drivers/mtd/devices/Makefile | 1 -
24 drivers/mtd/devices/ps3vram.c | 768 --------------------------------
25 6 files changed, 873 insertions(+), 776 deletions(-)
26 create mode 100644 drivers/block/ps3vram.c
27 delete mode 100644 drivers/mtd/devices/ps3vram.c
29 diff --git a/arch/powerpc/platforms/ps3/Kconfig b/arch/powerpc/platforms/ps3/Kconfig
30 index 920cf7a..740ef56 100644
31 --- a/arch/powerpc/platforms/ps3/Kconfig
32 +++ b/arch/powerpc/platforms/ps3/Kconfig
33 @@ -128,6 +128,13 @@ config PS3_FLASH
34 be disabled on the kernel command line using "ps3flash=off", to
35 not allocate this fixed buffer.
38 + tristate "PS3 Video RAM Storage Driver"
39 + depends on FB_PS3=y && BLOCK && m
41 + This driver allows you to use excess PS3 video RAM as volatile
42 + storage or system swap.
45 tristate "PS3 Logical Performance Monitor support"
47 diff --git a/drivers/block/Makefile b/drivers/block/Makefile
48 index 204332b..87e120e 100644
49 --- a/drivers/block/Makefile
50 +++ b/drivers/block/Makefile
51 @@ -9,6 +9,7 @@ obj-$(CONFIG_MAC_FLOPPY) += swim3.o
52 obj-$(CONFIG_BLK_DEV_FD) += floppy.o
53 obj-$(CONFIG_AMIGA_FLOPPY) += amiflop.o
54 obj-$(CONFIG_PS3_DISK) += ps3disk.o
55 +obj-$(CONFIG_PS3_VRAM) += ps3vram.o
56 obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o
57 obj-$(CONFIG_AMIGA_Z2RAM) += z2ram.o
58 obj-$(CONFIG_BLK_DEV_RAM) += brd.o
59 diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c
61 index 0000000..393ed67
63 +++ b/drivers/block/ps3vram.c
66 + * ps3vram - Use extra PS3 video ram as MTD block device.
68 + * Copyright 2009 Sony Corporation
70 + * Based on the MTD ps3vram driver, which is
71 + * Copyright (c) 2007-2008 Jim Paris <jim@jtan.com>
72 + * Added support RSX DMA Vivien Chappelier <vivien.chappelier@free.fr>
75 +#include <linux/blkdev.h>
76 +#include <linux/delay.h>
77 +#include <linux/proc_fs.h>
78 +#include <linux/seq_file.h>
80 +#include <asm/firmware.h>
81 +#include <asm/lv1call.h>
85 +#define DEVICE_NAME "ps3vram"
88 +#define XDR_BUF_SIZE (2 * 1024 * 1024) /* XDR buffer (must be 1MiB aligned) */
89 +#define XDR_IOIF 0x0c000000
91 +#define FIFO_BASE XDR_IOIF
92 +#define FIFO_SIZE (64 * 1024)
94 +#define DMA_PAGE_SIZE (4 * 1024)
96 +#define CACHE_PAGE_SIZE (256 * 1024)
97 +#define CACHE_PAGE_COUNT ((XDR_BUF_SIZE - FIFO_SIZE) / CACHE_PAGE_SIZE)
99 +#define CACHE_OFFSET CACHE_PAGE_SIZE
100 +#define FIFO_OFFSET 0
102 +#define CTRL_PUT 0x10
103 +#define CTRL_GET 0x11
104 +#define CTRL_TOP 0x15
106 +#define UPLOAD_SUBCH 1
107 +#define DOWNLOAD_SUBCH 2
109 +#define NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN 0x0000030c
110 +#define NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY 0x00000104
112 +#define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT 0x601
114 +#define CACHE_PAGE_PRESENT 1
115 +#define CACHE_PAGE_DIRTY 2
117 +struct ps3vram_tag {
118 + unsigned int address;
119 + unsigned int flags;
122 +struct ps3vram_cache {
123 + unsigned int page_count;
124 + unsigned int page_size;
125 + struct ps3vram_tag *tags;
130 +struct ps3vram_priv {
131 + struct request_queue *queue;
132 + struct gendisk *gendisk;
137 + u64 context_handle;
140 + u8 __iomem *ddr_base;
146 + struct ps3vram_cache cache;
148 + /* Used to serialize cache/DMA operations */
153 +static int ps3vram_major;
156 +static struct block_device_operations ps3vram_fops = {
157 + .owner = THIS_MODULE,
161 +#define DMA_NOTIFIER_HANDLE_BASE 0x66604200 /* first DMA notifier handle */
162 +#define DMA_NOTIFIER_OFFSET_BASE 0x1000 /* first DMA notifier offset */
163 +#define DMA_NOTIFIER_SIZE 0x40
164 +#define NOTIFIER 7 /* notifier used for completion report */
166 +static char *size = "256M";
167 +module_param(size, charp, 0);
168 +MODULE_PARM_DESC(size, "memory size");
170 +static u32 *ps3vram_get_notifier(u32 *reports, int notifier)
172 + return (void *)reports + DMA_NOTIFIER_OFFSET_BASE +
173 + DMA_NOTIFIER_SIZE * notifier;
176 +static void ps3vram_notifier_reset(struct ps3_system_bus_device *dev)
178 + struct ps3vram_priv *priv = dev->core.driver_data;
179 + u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER);
182 + for (i = 0; i < 4; i++)
183 + notify[i] = 0xffffffff;
186 +static int ps3vram_notifier_wait(struct ps3_system_bus_device *dev,
187 + unsigned int timeout_ms)
189 + struct ps3vram_priv *priv = dev->core.driver_data;
190 + u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER);
191 + unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
197 + } while (time_before(jiffies, timeout));
202 +static void ps3vram_init_ring(struct ps3_system_bus_device *dev)
204 + struct ps3vram_priv *priv = dev->core.driver_data;
206 + priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET;
207 + priv->ctrl[CTRL_GET] = FIFO_BASE + FIFO_OFFSET;
210 +static int ps3vram_wait_ring(struct ps3_system_bus_device *dev,
211 + unsigned int timeout_ms)
213 + struct ps3vram_priv *priv = dev->core.driver_data;
214 + unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
217 + if (priv->ctrl[CTRL_PUT] == priv->ctrl[CTRL_GET])
220 + } while (time_before(jiffies, timeout));
222 + dev_warn(&dev->core, "FIFO timeout (%08x/%08x/%08x)\n",
223 + priv->ctrl[CTRL_PUT], priv->ctrl[CTRL_GET],
224 + priv->ctrl[CTRL_TOP]);
229 +static void ps3vram_out_ring(struct ps3vram_priv *priv, u32 data)
231 + *(priv->fifo_ptr)++ = data;
234 +static void ps3vram_begin_ring(struct ps3vram_priv *priv, u32 chan, u32 tag,
237 + ps3vram_out_ring(priv, (size << 18) | (chan << 13) | tag);
240 +static void ps3vram_rewind_ring(struct ps3_system_bus_device *dev)
242 + struct ps3vram_priv *priv = dev->core.driver_data;
245 + ps3vram_out_ring(priv, 0x20000000 | (FIFO_BASE + FIFO_OFFSET));
247 + priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET;
249 + /* asking the HV for a blit will kick the FIFO */
250 + status = lv1_gpu_context_attribute(priv->context_handle,
251 + L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT, 0,
254 + dev_err(&dev->core,
255 + "%s: lv1_gpu_context_attribute failed %d\n", __func__,
258 + priv->fifo_ptr = priv->fifo_base;
261 +static void ps3vram_fire_ring(struct ps3_system_bus_device *dev)
263 + struct ps3vram_priv *priv = dev->core.driver_data;
266 + mutex_lock(&ps3_gpu_mutex);
268 + priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET +
269 + (priv->fifo_ptr - priv->fifo_base) * sizeof(u32);
271 + /* asking the HV for a blit will kick the FIFO */
272 + status = lv1_gpu_context_attribute(priv->context_handle,
273 + L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT, 0,
276 + dev_err(&dev->core,
277 + "%s: lv1_gpu_context_attribute failed %d\n", __func__,
280 + if ((priv->fifo_ptr - priv->fifo_base) * sizeof(u32) >
281 + FIFO_SIZE - 1024) {
282 + dev_dbg(&dev->core, "FIFO full, rewinding\n");
283 + ps3vram_wait_ring(dev, 200);
284 + ps3vram_rewind_ring(dev);
287 + mutex_unlock(&ps3_gpu_mutex);
290 +static void ps3vram_bind(struct ps3_system_bus_device *dev)
292 + struct ps3vram_priv *priv = dev->core.driver_data;
294 + ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0, 1);
295 + ps3vram_out_ring(priv, 0x31337303);
296 + ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0x180, 3);
297 + ps3vram_out_ring(priv, DMA_NOTIFIER_HANDLE_BASE + NOTIFIER);
298 + ps3vram_out_ring(priv, 0xfeed0001); /* DMA system RAM instance */
299 + ps3vram_out_ring(priv, 0xfeed0000); /* DMA video RAM instance */
301 + ps3vram_begin_ring(priv, DOWNLOAD_SUBCH, 0, 1);
302 + ps3vram_out_ring(priv, 0x3137c0de);
303 + ps3vram_begin_ring(priv, DOWNLOAD_SUBCH, 0x180, 3);
304 + ps3vram_out_ring(priv, DMA_NOTIFIER_HANDLE_BASE + NOTIFIER);
305 + ps3vram_out_ring(priv, 0xfeed0000); /* DMA video RAM instance */
306 + ps3vram_out_ring(priv, 0xfeed0001); /* DMA system RAM instance */
308 + ps3vram_fire_ring(dev);
311 +static int ps3vram_upload(struct ps3_system_bus_device *dev,
312 + unsigned int src_offset, unsigned int dst_offset,
313 + int len, int count)
315 + struct ps3vram_priv *priv = dev->core.driver_data;
317 + ps3vram_begin_ring(priv, UPLOAD_SUBCH,
318 + NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
319 + ps3vram_out_ring(priv, XDR_IOIF + src_offset);
320 + ps3vram_out_ring(priv, dst_offset);
321 + ps3vram_out_ring(priv, len);
322 + ps3vram_out_ring(priv, len);
323 + ps3vram_out_ring(priv, len);
324 + ps3vram_out_ring(priv, count);
325 + ps3vram_out_ring(priv, (1 << 8) | 1);
326 + ps3vram_out_ring(priv, 0);
328 + ps3vram_notifier_reset(dev);
329 + ps3vram_begin_ring(priv, UPLOAD_SUBCH,
330 + NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY, 1);
331 + ps3vram_out_ring(priv, 0);
332 + ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0x100, 1);
333 + ps3vram_out_ring(priv, 0);
334 + ps3vram_fire_ring(dev);
335 + if (ps3vram_notifier_wait(dev, 200) < 0) {
336 + dev_warn(&dev->core, "%s: Notifier timeout\n", __func__);
343 +static int ps3vram_download(struct ps3_system_bus_device *dev,
344 + unsigned int src_offset, unsigned int dst_offset,
345 + int len, int count)
347 + struct ps3vram_priv *priv = dev->core.driver_data;
349 + ps3vram_begin_ring(priv, DOWNLOAD_SUBCH,
350 + NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
351 + ps3vram_out_ring(priv, src_offset);
352 + ps3vram_out_ring(priv, XDR_IOIF + dst_offset);
353 + ps3vram_out_ring(priv, len);
354 + ps3vram_out_ring(priv, len);
355 + ps3vram_out_ring(priv, len);
356 + ps3vram_out_ring(priv, count);
357 + ps3vram_out_ring(priv, (1 << 8) | 1);
358 + ps3vram_out_ring(priv, 0);
360 + ps3vram_notifier_reset(dev);
361 + ps3vram_begin_ring(priv, DOWNLOAD_SUBCH,
362 + NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY, 1);
363 + ps3vram_out_ring(priv, 0);
364 + ps3vram_begin_ring(priv, DOWNLOAD_SUBCH, 0x100, 1);
365 + ps3vram_out_ring(priv, 0);
366 + ps3vram_fire_ring(dev);
367 + if (ps3vram_notifier_wait(dev, 200) < 0) {
368 + dev_warn(&dev->core, "%s: Notifier timeout\n", __func__);
375 +static void ps3vram_cache_evict(struct ps3_system_bus_device *dev, int entry)
377 + struct ps3vram_priv *priv = dev->core.driver_data;
378 + struct ps3vram_cache *cache = &priv->cache;
380 + if (!(cache->tags[entry].flags & CACHE_PAGE_DIRTY))
383 + dev_dbg(&dev->core, "Flushing %d: 0x%08x\n", entry,
384 + cache->tags[entry].address);
385 + if (ps3vram_upload(dev, CACHE_OFFSET + entry * cache->page_size,
386 + cache->tags[entry].address, DMA_PAGE_SIZE,
387 + cache->page_size / DMA_PAGE_SIZE) < 0) {
388 + dev_err(&dev->core,
389 + "Failed to upload from 0x%x to " "0x%x size 0x%x\n",
390 + entry * cache->page_size, cache->tags[entry].address,
393 + cache->tags[entry].flags &= ~CACHE_PAGE_DIRTY;
396 +static void ps3vram_cache_load(struct ps3_system_bus_device *dev, int entry,
397 + unsigned int address)
399 + struct ps3vram_priv *priv = dev->core.driver_data;
400 + struct ps3vram_cache *cache = &priv->cache;
402 + dev_dbg(&dev->core, "Fetching %d: 0x%08x\n", entry, address);
403 + if (ps3vram_download(dev, address,
404 + CACHE_OFFSET + entry * cache->page_size,
406 + cache->page_size / DMA_PAGE_SIZE) < 0) {
407 + dev_err(&dev->core,
408 + "Failed to download from 0x%x to 0x%x size 0x%x\n",
409 + address, entry * cache->page_size, cache->page_size);
412 + cache->tags[entry].address = address;
413 + cache->tags[entry].flags |= CACHE_PAGE_PRESENT;
417 +static void ps3vram_cache_flush(struct ps3_system_bus_device *dev)
419 + struct ps3vram_priv *priv = dev->core.driver_data;
420 + struct ps3vram_cache *cache = &priv->cache;
423 + dev_dbg(&dev->core, "FLUSH\n");
424 + for (i = 0; i < cache->page_count; i++) {
425 + ps3vram_cache_evict(dev, i);
426 + cache->tags[i].flags = 0;
430 +static unsigned int ps3vram_cache_match(struct ps3_system_bus_device *dev,
433 + struct ps3vram_priv *priv = dev->core.driver_data;
434 + struct ps3vram_cache *cache = &priv->cache;
436 + unsigned int offset;
438 + static int counter;
440 + offset = (unsigned int) (address & (cache->page_size - 1));
441 + base = (unsigned int) (address - offset);
443 + /* fully associative check */
444 + for (i = 0; i < cache->page_count; i++) {
445 + if ((cache->tags[i].flags & CACHE_PAGE_PRESENT) &&
446 + cache->tags[i].address == base) {
448 + dev_dbg(&dev->core, "Found entry %d: 0x%08x\n", i,
449 + cache->tags[i].address);
454 + /* choose a random entry */
455 + i = (jiffies + (counter++)) % cache->page_count;
456 + dev_dbg(&dev->core, "Using entry %d\n", i);
458 + ps3vram_cache_evict(dev, i);
459 + ps3vram_cache_load(dev, i, base);
465 +static int ps3vram_cache_init(struct ps3_system_bus_device *dev)
467 + struct ps3vram_priv *priv = dev->core.driver_data;
469 + priv->cache.page_count = CACHE_PAGE_COUNT;
470 + priv->cache.page_size = CACHE_PAGE_SIZE;
471 + priv->cache.tags = kzalloc(sizeof(struct ps3vram_tag) *
472 + CACHE_PAGE_COUNT, GFP_KERNEL);
473 + if (priv->cache.tags == NULL) {
474 + dev_err(&dev->core, "Could not allocate cache tags\n");
478 + dev_info(&dev->core, "Created ram cache: %d entries, %d KiB each\n",
479 + CACHE_PAGE_COUNT, CACHE_PAGE_SIZE / 1024);
484 +static void ps3vram_cache_cleanup(struct ps3_system_bus_device *dev)
486 + struct ps3vram_priv *priv = dev->core.driver_data;
488 + ps3vram_cache_flush(dev);
489 + kfree(priv->cache.tags);
492 +static int ps3vram_read(struct ps3_system_bus_device *dev, loff_t from,
493 + size_t len, size_t *retlen, u_char *buf)
495 + struct ps3vram_priv *priv = dev->core.driver_data;
496 + unsigned int cached, count;
498 + dev_dbg(&dev->core, "%s: from=0x%08x len=0x%zx\n", __func__,
499 + (unsigned int)from, len);
501 + if (from >= priv->size)
504 + if (len > priv->size - from)
505 + len = priv->size - from;
507 + /* Copy from vram to buf */
510 + unsigned int offset, avail;
511 + unsigned int entry;
513 + offset = (unsigned int) (from & (priv->cache.page_size - 1));
514 + avail = priv->cache.page_size - offset;
516 + mutex_lock(&priv->lock);
518 + entry = ps3vram_cache_match(dev, from);
519 + cached = CACHE_OFFSET + entry * priv->cache.page_size + offset;
521 + dev_dbg(&dev->core, "%s: from=%08x cached=%08x offset=%08x "
522 + "avail=%08x count=%08x\n", __func__,
523 + (unsigned int)from, cached, offset, avail, count);
527 + memcpy(buf, priv->xdr_buf + cached, avail);
529 + mutex_unlock(&priv->lock);
540 +static int ps3vram_write(struct ps3_system_bus_device *dev, loff_t to,
541 + size_t len, size_t *retlen, const u_char *buf)
543 + struct ps3vram_priv *priv = dev->core.driver_data;
544 + unsigned int cached, count;
546 + if (to >= priv->size)
549 + if (len > priv->size - to)
550 + len = priv->size - to;
552 + /* Copy from buf to vram */
555 + unsigned int offset, avail;
556 + unsigned int entry;
558 + offset = (unsigned int) (to & (priv->cache.page_size - 1));
559 + avail = priv->cache.page_size - offset;
561 + mutex_lock(&priv->lock);
563 + entry = ps3vram_cache_match(dev, to);
564 + cached = CACHE_OFFSET + entry * priv->cache.page_size + offset;
566 + dev_dbg(&dev->core, "%s: to=%08x cached=%08x offset=%08x "
567 + "avail=%08x count=%08x\n", __func__, (unsigned int)to,
568 + cached, offset, avail, count);
572 + memcpy(priv->xdr_buf + cached, buf, avail);
574 + priv->cache.tags[entry].flags |= CACHE_PAGE_DIRTY;
576 + mutex_unlock(&priv->lock);
587 +static int ps3vram_proc_show(struct seq_file *m, void *v)
589 + struct ps3vram_priv *priv = m->private;
591 + seq_printf(m, "hit:%u\nmiss:%u\n", priv->cache.hit, priv->cache.miss);
595 +static int ps3vram_proc_open(struct inode *inode, struct file *file)
597 + return single_open(file, ps3vram_proc_show, PDE(inode)->data);
600 +static const struct file_operations ps3vram_proc_fops = {
601 + .owner = THIS_MODULE,
602 + .open = ps3vram_proc_open,
604 + .llseek = seq_lseek,
605 + .release = single_release,
608 +static void __devinit ps3vram_proc_init(struct ps3_system_bus_device *dev)
610 + struct ps3vram_priv *priv = dev->core.driver_data;
611 + struct proc_dir_entry *pde;
613 + pde = proc_create(DEVICE_NAME, 0444, NULL, &ps3vram_proc_fops);
615 + dev_warn(&dev->core, "failed to create /proc entry\n");
619 + pde->owner = THIS_MODULE;
623 +static int ps3vram_make_request(struct request_queue *q, struct bio *bio)
625 + struct ps3_system_bus_device *dev = q->queuedata;
626 + int write = bio_data_dir(bio) == WRITE;
627 + const char *op = write ? "write" : "read";
628 + loff_t offset = bio->bi_sector << 9;
630 + struct bio_vec *bvec;
633 + dev_dbg(&dev->core, "%s\n", __func__);
635 + bio_for_each_segment(bvec, bio, i) {
636 + /* PS3 is ppc64, so we don't handle highmem */
637 + char *ptr = page_address(bvec->bv_page) + bvec->bv_offset;
638 + size_t len = bvec->bv_len, retlen;
640 + dev_dbg(&dev->core, " %s %zu bytes at offset %llu\n", op,
643 + error = ps3vram_write(dev, offset, len, &retlen, ptr);
645 + error = ps3vram_read(dev, offset, len, &retlen, ptr);
648 + dev_err(&dev->core, "%s failed\n", op);
652 + if (retlen != len) {
653 + dev_err(&dev->core, "Short %s\n", op);
660 + dev_dbg(&dev->core, "%s completed\n", op);
663 + bio_endio(bio, error);
667 +static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev)
669 + struct ps3vram_priv *priv;
671 + struct request_queue *queue;
672 + struct gendisk *gendisk;
673 + u64 ddr_lpar, ctrl_lpar, info_lpar, reports_lpar, ddr_size,
677 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
683 + mutex_init(&priv->lock);
684 + dev->core.driver_data = priv;
686 + priv = dev->core.driver_data;
688 + /* Allocate XDR buffer (1MiB aligned) */
689 + priv->xdr_buf = (void *)__get_free_pages(GFP_KERNEL,
690 + get_order(XDR_BUF_SIZE));
691 + if (priv->xdr_buf == NULL) {
692 + dev_err(&dev->core, "Could not allocate XDR buffer\n");
694 + goto fail_free_priv;
697 + /* Put FIFO at begginning of XDR buffer */
698 + priv->fifo_base = (u32 *) (priv->xdr_buf + FIFO_OFFSET);
699 + priv->fifo_ptr = priv->fifo_base;
701 + /* XXX: Need to open GPU, in case ps3fb or snd_ps3 aren't loaded */
702 + if (ps3_open_hv_device(dev)) {
703 + dev_err(&dev->core, "ps3_open_hv_device failed\n");
705 + goto out_close_gpu;
708 + /* Request memory */
710 + ddr_size = ALIGN(memparse(size, &rest), 1024*1024);
712 + dev_err(&dev->core, "Specified size is too small\n");
714 + goto out_close_gpu;
717 + while (ddr_size > 0) {
718 + status = lv1_gpu_memory_allocate(ddr_size, 0, 0, 0, 0,
719 + &priv->memory_handle,
723 + ddr_size -= 1024*1024;
726 + dev_err(&dev->core, "lv1_gpu_memory_allocate failed %d\n",
729 + goto out_free_xdr_buf;
732 + /* Request context */
733 + status = lv1_gpu_context_allocate(priv->memory_handle, 0,
734 + &priv->context_handle, &ctrl_lpar,
735 + &info_lpar, &reports_lpar,
738 + dev_err(&dev->core, "lv1_gpu_context_allocate failed %d\n",
741 + goto out_free_memory;
744 + /* Map XDR buffer to RSX */
745 + status = lv1_gpu_context_iomap(priv->context_handle, XDR_IOIF,
746 + ps3_mm_phys_to_lpar(__pa(priv->xdr_buf)),
749 + dev_err(&dev->core, "lv1_gpu_context_iomap failed %d\n",
752 + goto out_free_context;
755 + priv->ddr_base = ioremap_flags(ddr_lpar, ddr_size, _PAGE_NO_CACHE);
757 + if (!priv->ddr_base) {
758 + dev_err(&dev->core, "ioremap DDR failed\n");
760 + goto out_free_context;
763 + priv->ctrl = ioremap(ctrl_lpar, 64 * 1024);
765 + dev_err(&dev->core, "ioremap CTRL failed\n");
767 + goto out_unmap_vram;
770 + priv->reports = ioremap(reports_lpar, reports_size);
771 + if (!priv->reports) {
772 + dev_err(&dev->core, "ioremap REPORTS failed\n");
774 + goto out_unmap_ctrl;
777 + mutex_lock(&ps3_gpu_mutex);
778 + ps3vram_init_ring(dev);
779 + mutex_unlock(&ps3_gpu_mutex);
781 + priv->size = ddr_size;
785 + mutex_lock(&ps3_gpu_mutex);
786 + error = ps3vram_wait_ring(dev, 100);
787 + mutex_unlock(&ps3_gpu_mutex);
789 + dev_err(&dev->core, "Failed to initialize channels\n");
790 + error = -ETIMEDOUT;
791 + goto out_unmap_reports;
794 + ps3vram_cache_init(dev);
795 + ps3vram_proc_init(dev);
797 + queue = blk_alloc_queue(GFP_KERNEL);
799 + dev_err(&dev->core, "blk_alloc_queue failed\n");
801 + goto out_cache_cleanup;
804 + priv->queue = queue;
805 + queue->queuedata = dev;
806 + blk_queue_make_request(queue, ps3vram_make_request);
807 + blk_queue_max_phys_segments(queue, MAX_PHYS_SEGMENTS);
808 + blk_queue_max_hw_segments(queue, MAX_HW_SEGMENTS);
809 + blk_queue_max_segment_size(queue, MAX_SEGMENT_SIZE);
810 + blk_queue_max_sectors(queue, SAFE_MAX_SECTORS);
812 + gendisk = alloc_disk(1);
814 + dev_err(&dev->core, "alloc_disk failed\n");
816 + goto fail_cleanup_queue;
819 + priv->gendisk = gendisk;
820 + gendisk->major = ps3vram_major;
821 + gendisk->first_minor = 0;
822 + gendisk->fops = &ps3vram_fops;
823 + gendisk->queue = queue;
824 + gendisk->private_data = dev;
825 + gendisk->driverfs_dev = &dev->core;
826 + strlcpy(gendisk->disk_name, DEVICE_NAME, sizeof(gendisk->disk_name));
827 + set_capacity(gendisk, priv->size >> 9);
829 + dev_info(&dev->core, "%s: Using %lu MiB of GPU memory\n",
830 + gendisk->disk_name, get_capacity(gendisk) >> 11);
836 + blk_cleanup_queue(queue);
838 + remove_proc_entry(DEVICE_NAME, NULL);
839 + ps3vram_cache_cleanup(dev);
841 + iounmap(priv->reports);
843 + iounmap(priv->ctrl);
845 + iounmap(priv->ddr_base);
847 + lv1_gpu_context_free(priv->context_handle);
849 + lv1_gpu_memory_free(priv->memory_handle);
851 + ps3_close_hv_device(dev);
853 + free_pages((unsigned long) priv->xdr_buf, get_order(XDR_BUF_SIZE));
856 + dev->core.driver_data = NULL;
861 +static int ps3vram_remove(struct ps3_system_bus_device *dev)
863 + struct ps3vram_priv *priv = dev->core.driver_data;
865 + del_gendisk(priv->gendisk);
866 + put_disk(priv->gendisk);
867 + blk_cleanup_queue(priv->queue);
868 + remove_proc_entry(DEVICE_NAME, NULL);
869 + ps3vram_cache_cleanup(dev);
870 + iounmap(priv->reports);
871 + iounmap(priv->ctrl);
872 + iounmap(priv->ddr_base);
873 + lv1_gpu_context_free(priv->context_handle);
874 + lv1_gpu_memory_free(priv->memory_handle);
875 + ps3_close_hv_device(dev);
876 + free_pages((unsigned long) priv->xdr_buf, get_order(XDR_BUF_SIZE));
878 + dev->core.driver_data = NULL;
882 +static struct ps3_system_bus_driver ps3vram = {
883 + .match_id = PS3_MATCH_ID_GPU,
884 + .match_sub_id = PS3_MATCH_SUB_ID_GPU_RAMDISK,
885 + .core.name = DEVICE_NAME,
886 + .core.owner = THIS_MODULE,
887 + .probe = ps3vram_probe,
888 + .remove = ps3vram_remove,
889 + .shutdown = ps3vram_remove,
893 +static int __init ps3vram_init(void)
897 + if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
900 + error = register_blkdev(0, DEVICE_NAME);
902 + pr_err("%s: register_blkdev failed %d\n", DEVICE_NAME, error);
905 + ps3vram_major = error;
907 + pr_info("%s: registered block device major %d\n", DEVICE_NAME,
910 + error = ps3_system_bus_driver_register(&ps3vram);
912 + unregister_blkdev(ps3vram_major, DEVICE_NAME);
917 +static void __exit ps3vram_exit(void)
919 + ps3_system_bus_driver_unregister(&ps3vram);
920 + unregister_blkdev(ps3vram_major, DEVICE_NAME);
923 +module_init(ps3vram_init);
924 +module_exit(ps3vram_exit);
926 +MODULE_LICENSE("GPL");
927 +MODULE_DESCRIPTION("PS3 Video RAM Storage Driver");
928 +MODULE_AUTHOR("Sony Corporation");
929 +MODULE_ALIAS(PS3_MODULE_ALIAS_GPU_RAMDISK);
930 diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
931 index bc33200..6fde0a2 100644
932 --- a/drivers/mtd/devices/Kconfig
933 +++ b/drivers/mtd/devices/Kconfig
934 @@ -120,13 +120,6 @@ config MTD_PHRAM
935 doesn't have access to, memory beyond the mem=xxx limit, nvram,
936 memory on the video card, etc...
939 - tristate "PS3 video RAM"
942 - This driver allows you to use excess PS3 video RAM as volatile
943 - storage or system swap.
946 tristate "28F160xx flash driver for LART"
947 depends on SA1100_LART
948 diff --git a/drivers/mtd/devices/Makefile b/drivers/mtd/devices/Makefile
949 index e51521d..0993d5c 100644
950 --- a/drivers/mtd/devices/Makefile
951 +++ b/drivers/mtd/devices/Makefile
952 @@ -16,4 +16,3 @@ obj-$(CONFIG_MTD_LART) += lart.o
953 obj-$(CONFIG_MTD_BLOCK2MTD) += block2mtd.o
954 obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o
955 obj-$(CONFIG_MTD_M25P80) += m25p80.o
956 -obj-$(CONFIG_MTD_PS3VRAM) += ps3vram.o
957 diff --git a/drivers/mtd/devices/ps3vram.c b/drivers/mtd/devices/ps3vram.c
958 deleted file mode 100644
959 index d21e9be..0000000
960 --- a/drivers/mtd/devices/ps3vram.c
964 - * ps3vram - Use extra PS3 video ram as MTD block device.
966 - * Copyright (c) 2007-2008 Jim Paris <jim@jtan.com>
967 - * Added support RSX DMA Vivien Chappelier <vivien.chappelier@free.fr>
970 -#include <linux/io.h>
971 -#include <linux/mm.h>
972 -#include <linux/init.h>
973 -#include <linux/kernel.h>
974 -#include <linux/list.h>
975 -#include <linux/module.h>
976 -#include <linux/moduleparam.h>
977 -#include <linux/slab.h>
978 -#include <linux/version.h>
979 -#include <linux/gfp.h>
980 -#include <linux/delay.h>
981 -#include <linux/mtd/mtd.h>
983 -#include <asm/lv1call.h>
984 -#include <asm/ps3.h>
986 -#define DEVICE_NAME "ps3vram"
988 -#define XDR_BUF_SIZE (2 * 1024 * 1024) /* XDR buffer (must be 1MiB aligned) */
989 -#define XDR_IOIF 0x0c000000
991 -#define FIFO_BASE XDR_IOIF
992 -#define FIFO_SIZE (64 * 1024)
994 -#define DMA_PAGE_SIZE (4 * 1024)
996 -#define CACHE_PAGE_SIZE (256 * 1024)
997 -#define CACHE_PAGE_COUNT ((XDR_BUF_SIZE - FIFO_SIZE) / CACHE_PAGE_SIZE)
999 -#define CACHE_OFFSET CACHE_PAGE_SIZE
1000 -#define FIFO_OFFSET 0
1002 -#define CTRL_PUT 0x10
1003 -#define CTRL_GET 0x11
1004 -#define CTRL_TOP 0x15
1006 -#define UPLOAD_SUBCH 1
1007 -#define DOWNLOAD_SUBCH 2
1009 -#define NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN 0x0000030c
1010 -#define NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY 0x00000104
1012 -#define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT 0x601
1014 -struct mtd_info ps3vram_mtd;
1016 -#define CACHE_PAGE_PRESENT 1
1017 -#define CACHE_PAGE_DIRTY 2
1019 -struct ps3vram_tag {
1020 - unsigned int address;
1021 - unsigned int flags;
1024 -struct ps3vram_cache {
1025 - unsigned int page_count;
1026 - unsigned int page_size;
1027 - struct ps3vram_tag *tags;
1030 -struct ps3vram_priv {
1031 - u64 memory_handle;
1032 - u64 context_handle;
1035 - u8 __iomem *ddr_base;
1041 - struct device *dev;
1042 - struct ps3vram_cache cache;
1044 - /* Used to serialize cache/DMA operations */
1045 - struct mutex lock;
1048 -#define DMA_NOTIFIER_HANDLE_BASE 0x66604200 /* first DMA notifier handle */
1049 -#define DMA_NOTIFIER_OFFSET_BASE 0x1000 /* first DMA notifier offset */
1050 -#define DMA_NOTIFIER_SIZE 0x40
1051 -#define NOTIFIER 7 /* notifier used for completion report */
1053 -/* A trailing '-' means to subtract off ps3fb_videomemory.size */
1054 -char *size = "256M-";
1055 -module_param(size, charp, 0);
1056 -MODULE_PARM_DESC(size, "memory size");
1058 -static u32 *ps3vram_get_notifier(u32 *reports, int notifier)
1060 - return (void *) reports +
1061 - DMA_NOTIFIER_OFFSET_BASE +
1062 - DMA_NOTIFIER_SIZE * notifier;
1065 -static void ps3vram_notifier_reset(struct mtd_info *mtd)
1069 - struct ps3vram_priv *priv = mtd->priv;
1070 - u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER);
1071 - for (i = 0; i < 4; i++)
1072 - notify[i] = 0xffffffff;
1075 -static int ps3vram_notifier_wait(struct mtd_info *mtd, unsigned int timeout_ms)
1077 - struct ps3vram_priv *priv = mtd->priv;
1078 - u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER);
1079 - unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
1085 - } while (time_before(jiffies, timeout));
1087 - return -ETIMEDOUT;
1090 -static void ps3vram_init_ring(struct mtd_info *mtd)
1092 - struct ps3vram_priv *priv = mtd->priv;
1094 - priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET;
1095 - priv->ctrl[CTRL_GET] = FIFO_BASE + FIFO_OFFSET;
1098 -static int ps3vram_wait_ring(struct mtd_info *mtd, unsigned int timeout_ms)
1100 - struct ps3vram_priv *priv = mtd->priv;
1101 - unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
1104 - if (priv->ctrl[CTRL_PUT] == priv->ctrl[CTRL_GET])
1107 - } while (time_before(jiffies, timeout));
1109 - dev_dbg(priv->dev, "%s:%d: FIFO timeout (%08x/%08x/%08x)\n", __func__,
1110 - __LINE__, priv->ctrl[CTRL_PUT], priv->ctrl[CTRL_GET],
1111 - priv->ctrl[CTRL_TOP]);
1113 - return -ETIMEDOUT;
1116 -static void ps3vram_out_ring(struct ps3vram_priv *priv, u32 data)
1118 - *(priv->fifo_ptr)++ = data;
1121 -static void ps3vram_begin_ring(struct ps3vram_priv *priv, u32 chan,
1122 - u32 tag, u32 size)
1124 - ps3vram_out_ring(priv, (size << 18) | (chan << 13) | tag);
1127 -static void ps3vram_rewind_ring(struct mtd_info *mtd)
1129 - struct ps3vram_priv *priv = mtd->priv;
1132 - ps3vram_out_ring(priv, 0x20000000 | (FIFO_BASE + FIFO_OFFSET));
1134 - priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET;
1136 - /* asking the HV for a blit will kick the fifo */
1137 - status = lv1_gpu_context_attribute(priv->context_handle,
1138 - L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
1141 - dev_err(priv->dev, "%s:%d: lv1_gpu_context_attribute failed\n",
1142 - __func__, __LINE__);
1144 - priv->fifo_ptr = priv->fifo_base;
1147 -static void ps3vram_fire_ring(struct mtd_info *mtd)
1149 - struct ps3vram_priv *priv = mtd->priv;
1152 - mutex_lock(&ps3_gpu_mutex);
1154 - priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET +
1155 - (priv->fifo_ptr - priv->fifo_base) * sizeof(u32);
1157 - /* asking the HV for a blit will kick the fifo */
1158 - status = lv1_gpu_context_attribute(priv->context_handle,
1159 - L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
1162 - dev_err(priv->dev, "%s:%d: lv1_gpu_context_attribute failed\n",
1163 - __func__, __LINE__);
1165 - if ((priv->fifo_ptr - priv->fifo_base) * sizeof(u32) >
1166 - FIFO_SIZE - 1024) {
1167 - dev_dbg(priv->dev, "%s:%d: fifo full, rewinding\n", __func__,
1169 - ps3vram_wait_ring(mtd, 200);
1170 - ps3vram_rewind_ring(mtd);
1173 - mutex_unlock(&ps3_gpu_mutex);
1176 -static void ps3vram_bind(struct mtd_info *mtd)
1178 - struct ps3vram_priv *priv = mtd->priv;
1180 - ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0, 1);
1181 - ps3vram_out_ring(priv, 0x31337303);
1182 - ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0x180, 3);
1183 - ps3vram_out_ring(priv, DMA_NOTIFIER_HANDLE_BASE + NOTIFIER);
1184 - ps3vram_out_ring(priv, 0xfeed0001); /* DMA system RAM instance */
1185 - ps3vram_out_ring(priv, 0xfeed0000); /* DMA video RAM instance */
1187 - ps3vram_begin_ring(priv, DOWNLOAD_SUBCH, 0, 1);
1188 - ps3vram_out_ring(priv, 0x3137c0de);
1189 - ps3vram_begin_ring(priv, DOWNLOAD_SUBCH, 0x180, 3);
1190 - ps3vram_out_ring(priv, DMA_NOTIFIER_HANDLE_BASE + NOTIFIER);
1191 - ps3vram_out_ring(priv, 0xfeed0000); /* DMA video RAM instance */
1192 - ps3vram_out_ring(priv, 0xfeed0001); /* DMA system RAM instance */
1194 - ps3vram_fire_ring(mtd);
1197 -static int ps3vram_upload(struct mtd_info *mtd, unsigned int src_offset,
1198 - unsigned int dst_offset, int len, int count)
1200 - struct ps3vram_priv *priv = mtd->priv;
1202 - ps3vram_begin_ring(priv, UPLOAD_SUBCH,
1203 - NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
1204 - ps3vram_out_ring(priv, XDR_IOIF + src_offset);
1205 - ps3vram_out_ring(priv, dst_offset);
1206 - ps3vram_out_ring(priv, len);
1207 - ps3vram_out_ring(priv, len);
1208 - ps3vram_out_ring(priv, len);
1209 - ps3vram_out_ring(priv, count);
1210 - ps3vram_out_ring(priv, (1 << 8) | 1);
1211 - ps3vram_out_ring(priv, 0);
1213 - ps3vram_notifier_reset(mtd);
1214 - ps3vram_begin_ring(priv, UPLOAD_SUBCH,
1215 - NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY, 1);
1216 - ps3vram_out_ring(priv, 0);
1217 - ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0x100, 1);
1218 - ps3vram_out_ring(priv, 0);
1219 - ps3vram_fire_ring(mtd);
1220 - if (ps3vram_notifier_wait(mtd, 200) < 0) {
1221 - dev_dbg(priv->dev, "%s:%d: notifier timeout\n", __func__,
1229 -static int ps3vram_download(struct mtd_info *mtd, unsigned int src_offset,
1230 - unsigned int dst_offset, int len, int count)
1232 - struct ps3vram_priv *priv = mtd->priv;
1234 - ps3vram_begin_ring(priv, DOWNLOAD_SUBCH,
1235 - NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
1236 - ps3vram_out_ring(priv, src_offset);
1237 - ps3vram_out_ring(priv, XDR_IOIF + dst_offset);
1238 - ps3vram_out_ring(priv, len);
1239 - ps3vram_out_ring(priv, len);
1240 - ps3vram_out_ring(priv, len);
1241 - ps3vram_out_ring(priv, count);
1242 - ps3vram_out_ring(priv, (1 << 8) | 1);
1243 - ps3vram_out_ring(priv, 0);
1245 - ps3vram_notifier_reset(mtd);
1246 - ps3vram_begin_ring(priv, DOWNLOAD_SUBCH,
1247 - NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY, 1);
1248 - ps3vram_out_ring(priv, 0);
1249 - ps3vram_begin_ring(priv, DOWNLOAD_SUBCH, 0x100, 1);
1250 - ps3vram_out_ring(priv, 0);
1251 - ps3vram_fire_ring(mtd);
1252 - if (ps3vram_notifier_wait(mtd, 200) < 0) {
1253 - dev_dbg(priv->dev, "%s:%d: notifier timeout\n", __func__,
1261 -static void ps3vram_cache_evict(struct mtd_info *mtd, int entry)
1263 - struct ps3vram_priv *priv = mtd->priv;
1264 - struct ps3vram_cache *cache = &priv->cache;
1266 - if (cache->tags[entry].flags & CACHE_PAGE_DIRTY) {
1267 - dev_dbg(priv->dev, "%s:%d: flushing %d : 0x%08x\n", __func__,
1268 - __LINE__, entry, cache->tags[entry].address);
1269 - if (ps3vram_upload(mtd,
1270 - CACHE_OFFSET + entry * cache->page_size,
1271 - cache->tags[entry].address,
1273 - cache->page_size / DMA_PAGE_SIZE) < 0) {
1274 - dev_dbg(priv->dev, "%s:%d: failed to upload from "
1275 - "0x%x to 0x%x size 0x%x\n", __func__, __LINE__,
1276 - entry * cache->page_size,
1277 - cache->tags[entry].address, cache->page_size);
1279 - cache->tags[entry].flags &= ~CACHE_PAGE_DIRTY;
1283 -static void ps3vram_cache_load(struct mtd_info *mtd, int entry,
1284 - unsigned int address)
1286 - struct ps3vram_priv *priv = mtd->priv;
1287 - struct ps3vram_cache *cache = &priv->cache;
1289 - dev_dbg(priv->dev, "%s:%d: fetching %d : 0x%08x\n", __func__, __LINE__,
1291 - if (ps3vram_download(mtd,
1293 - CACHE_OFFSET + entry * cache->page_size,
1295 - cache->page_size / DMA_PAGE_SIZE) < 0) {
1296 - dev_err(priv->dev, "%s:%d: failed to download from "
1297 - "0x%x to 0x%x size 0x%x\n", __func__, __LINE__, address,
1298 - entry * cache->page_size, cache->page_size);
1301 - cache->tags[entry].address = address;
1302 - cache->tags[entry].flags |= CACHE_PAGE_PRESENT;
1306 -static void ps3vram_cache_flush(struct mtd_info *mtd)
1308 - struct ps3vram_priv *priv = mtd->priv;
1309 - struct ps3vram_cache *cache = &priv->cache;
1312 - dev_dbg(priv->dev, "%s:%d: FLUSH\n", __func__, __LINE__);
1313 - for (i = 0; i < cache->page_count; i++) {
1314 - ps3vram_cache_evict(mtd, i);
1315 - cache->tags[i].flags = 0;
1319 -static unsigned int ps3vram_cache_match(struct mtd_info *mtd, loff_t address)
1321 - struct ps3vram_priv *priv = mtd->priv;
1322 - struct ps3vram_cache *cache = &priv->cache;
1323 - unsigned int base;
1324 - unsigned int offset;
1326 - static int counter;
1328 - offset = (unsigned int) (address & (cache->page_size - 1));
1329 - base = (unsigned int) (address - offset);
1331 - /* fully associative check */
1332 - for (i = 0; i < cache->page_count; i++) {
1333 - if ((cache->tags[i].flags & CACHE_PAGE_PRESENT) &&
1334 - cache->tags[i].address == base) {
1335 - dev_dbg(priv->dev, "%s:%d: found entry %d : 0x%08x\n",
1336 - __func__, __LINE__, i, cache->tags[i].address);
1341 - /* choose a random entry */
1342 - i = (jiffies + (counter++)) % cache->page_count;
1343 - dev_dbg(priv->dev, "%s:%d: using entry %d\n", __func__, __LINE__, i);
1345 - ps3vram_cache_evict(mtd, i);
1346 - ps3vram_cache_load(mtd, i, base);
1351 -static int ps3vram_cache_init(struct mtd_info *mtd)
1353 - struct ps3vram_priv *priv = mtd->priv;
1355 - priv->cache.page_count = CACHE_PAGE_COUNT;
1356 - priv->cache.page_size = CACHE_PAGE_SIZE;
1357 - priv->cache.tags = kzalloc(sizeof(struct ps3vram_tag) *
1358 - CACHE_PAGE_COUNT, GFP_KERNEL);
1359 - if (priv->cache.tags == NULL) {
1360 - dev_err(priv->dev, "%s:%d: could not allocate cache tags\n",
1361 - __func__, __LINE__);
1365 - dev_info(priv->dev, "created ram cache: %d entries, %d KiB each\n",
1366 - CACHE_PAGE_COUNT, CACHE_PAGE_SIZE / 1024);
1371 -static void ps3vram_cache_cleanup(struct mtd_info *mtd)
1373 - struct ps3vram_priv *priv = mtd->priv;
1375 - ps3vram_cache_flush(mtd);
1376 - kfree(priv->cache.tags);
1379 -static int ps3vram_erase(struct mtd_info *mtd, struct erase_info *instr)
1381 - struct ps3vram_priv *priv = mtd->priv;
1383 - if (instr->addr + instr->len > mtd->size)
1386 - mutex_lock(&priv->lock);
1388 - ps3vram_cache_flush(mtd);
1390 - /* Set bytes to 0xFF */
1391 - memset_io(priv->ddr_base + instr->addr, 0xFF, instr->len);
1393 - mutex_unlock(&priv->lock);
1395 - instr->state = MTD_ERASE_DONE;
1396 - mtd_erase_callback(instr);
1401 -static int ps3vram_read(struct mtd_info *mtd, loff_t from, size_t len,
1402 - size_t *retlen, u_char *buf)
1404 - struct ps3vram_priv *priv = mtd->priv;
1405 - unsigned int cached, count;
1407 - dev_dbg(priv->dev, "%s:%d: from=0x%08x len=0x%zx\n", __func__, __LINE__,
1408 - (unsigned int)from, len);
1410 - if (from >= mtd->size)
1413 - if (len > mtd->size - from)
1414 - len = mtd->size - from;
1416 - /* Copy from vram to buf */
1419 - unsigned int offset, avail;
1420 - unsigned int entry;
1422 - offset = (unsigned int) (from & (priv->cache.page_size - 1));
1423 - avail = priv->cache.page_size - offset;
1425 - mutex_lock(&priv->lock);
1427 - entry = ps3vram_cache_match(mtd, from);
1428 - cached = CACHE_OFFSET + entry * priv->cache.page_size + offset;
1430 - dev_dbg(priv->dev, "%s:%d: from=%08x cached=%08x offset=%08x "
1431 - "avail=%08x count=%08x\n", __func__, __LINE__,
1432 - (unsigned int)from, cached, offset, avail, count);
1434 - if (avail > count)
1436 - memcpy(buf, priv->xdr_buf + cached, avail);
1438 - mutex_unlock(&priv->lock);
1449 -static int ps3vram_write(struct mtd_info *mtd, loff_t to, size_t len,
1450 - size_t *retlen, const u_char *buf)
1452 - struct ps3vram_priv *priv = mtd->priv;
1453 - unsigned int cached, count;
1455 - if (to >= mtd->size)
1458 - if (len > mtd->size - to)
1459 - len = mtd->size - to;
1461 - /* Copy from buf to vram */
1464 - unsigned int offset, avail;
1465 - unsigned int entry;
1467 - offset = (unsigned int) (to & (priv->cache.page_size - 1));
1468 - avail = priv->cache.page_size - offset;
1470 - mutex_lock(&priv->lock);
1472 - entry = ps3vram_cache_match(mtd, to);
1473 - cached = CACHE_OFFSET + entry * priv->cache.page_size + offset;
1475 - dev_dbg(priv->dev, "%s:%d: to=%08x cached=%08x offset=%08x "
1476 - "avail=%08x count=%08x\n", __func__, __LINE__,
1477 - (unsigned int)to, cached, offset, avail, count);
1479 - if (avail > count)
1481 - memcpy(priv->xdr_buf + cached, buf, avail);
1483 - priv->cache.tags[entry].flags |= CACHE_PAGE_DIRTY;
1485 - mutex_unlock(&priv->lock);
1496 -static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev)
1498 - struct ps3vram_priv *priv;
1506 - int ret = -ENOMEM;
1510 - ps3vram_mtd.priv = kzalloc(sizeof(struct ps3vram_priv), GFP_KERNEL);
1511 - if (!ps3vram_mtd.priv)
1513 - priv = ps3vram_mtd.priv;
1515 - mutex_init(&priv->lock);
1516 - priv->dev = &dev->core;
1518 - /* Allocate XDR buffer (1MiB aligned) */
1519 - priv->xdr_buf = (void *)__get_free_pages(GFP_KERNEL,
1520 - get_order(XDR_BUF_SIZE));
1521 - if (priv->xdr_buf == NULL) {
1522 - dev_dbg(&dev->core, "%s:%d: could not allocate XDR buffer\n",
1523 - __func__, __LINE__);
1525 - goto out_free_priv;
1528 - /* Put FIFO at begginning of XDR buffer */
1529 - priv->fifo_base = (u32 *) (priv->xdr_buf + FIFO_OFFSET);
1530 - priv->fifo_ptr = priv->fifo_base;
1532 - /* XXX: Need to open GPU, in case ps3fb or snd_ps3 aren't loaded */
1533 - if (ps3_open_hv_device(dev)) {
1534 - dev_err(&dev->core, "%s:%d: ps3_open_hv_device failed\n",
1535 - __func__, __LINE__);
1537 - goto out_close_gpu;
1540 - /* Request memory */
1542 - ddr_size = memparse(size, &rest);
1544 - ddr_size -= ps3fb_videomemory.size;
1545 - ddr_size = ALIGN(ddr_size, 1024*1024);
1546 - if (ddr_size <= 0) {
1547 - dev_err(&dev->core, "%s:%d: specified size is too small\n",
1548 - __func__, __LINE__);
1550 - goto out_close_gpu;
1553 - while (ddr_size > 0) {
1554 - status = lv1_gpu_memory_allocate(ddr_size, 0, 0, 0, 0,
1555 - &priv->memory_handle,
1559 - ddr_size -= 1024*1024;
1561 - if (status || ddr_size <= 0) {
1562 - dev_err(&dev->core, "%s:%d: lv1_gpu_memory_allocate failed\n",
1563 - __func__, __LINE__);
1565 - goto out_free_xdr_buf;
1568 - /* Request context */
1569 - status = lv1_gpu_context_allocate(priv->memory_handle,
1571 - &priv->context_handle,
1577 - dev_err(&dev->core, "%s:%d: lv1_gpu_context_allocate failed\n",
1578 - __func__, __LINE__);
1580 - goto out_free_memory;
1583 - /* Map XDR buffer to RSX */
1584 - status = lv1_gpu_context_iomap(priv->context_handle, XDR_IOIF,
1585 - ps3_mm_phys_to_lpar(__pa(priv->xdr_buf)),
1588 - dev_err(&dev->core, "%s:%d: lv1_gpu_context_iomap failed\n",
1589 - __func__, __LINE__);
1591 - goto out_free_context;
1594 - priv->ddr_base = ioremap_flags(ddr_lpar, ddr_size, _PAGE_NO_CACHE);
1596 - if (!priv->ddr_base) {
1597 - dev_err(&dev->core, "%s:%d: ioremap failed\n", __func__,
1600 - goto out_free_context;
1603 - priv->ctrl = ioremap(ctrl_lpar, 64 * 1024);
1604 - if (!priv->ctrl) {
1605 - dev_err(&dev->core, "%s:%d: ioremap failed\n", __func__,
1608 - goto out_unmap_vram;
1611 - priv->reports = ioremap(reports_lpar, reports_size);
1612 - if (!priv->reports) {
1613 - dev_err(&dev->core, "%s:%d: ioremap failed\n", __func__,
1616 - goto out_unmap_ctrl;
1619 - mutex_lock(&ps3_gpu_mutex);
1620 - ps3vram_init_ring(&ps3vram_mtd);
1621 - mutex_unlock(&ps3_gpu_mutex);
1623 - ps3vram_mtd.name = "ps3vram";
1624 - ps3vram_mtd.size = ddr_size;
1625 - ps3vram_mtd.flags = MTD_CAP_RAM;
1626 - ps3vram_mtd.erase = ps3vram_erase;
1627 - ps3vram_mtd.point = NULL;
1628 - ps3vram_mtd.unpoint = NULL;
1629 - ps3vram_mtd.read = ps3vram_read;
1630 - ps3vram_mtd.write = ps3vram_write;
1631 - ps3vram_mtd.owner = THIS_MODULE;
1632 - ps3vram_mtd.type = MTD_RAM;
1633 - ps3vram_mtd.erasesize = CACHE_PAGE_SIZE;
1634 - ps3vram_mtd.writesize = 1;
1636 - ps3vram_bind(&ps3vram_mtd);
1638 - mutex_lock(&ps3_gpu_mutex);
1639 - ret = ps3vram_wait_ring(&ps3vram_mtd, 100);
1640 - mutex_unlock(&ps3_gpu_mutex);
1642 - dev_err(&dev->core, "%s:%d: failed to initialize channels\n",
1643 - __func__, __LINE__);
1645 - goto out_unmap_reports;
1648 - ps3vram_cache_init(&ps3vram_mtd);
1650 - if (add_mtd_device(&ps3vram_mtd)) {
1651 - dev_err(&dev->core, "%s:%d: add_mtd_device failed\n",
1652 - __func__, __LINE__);
1654 - goto out_cache_cleanup;
1657 - dev_info(&dev->core, "reserved %u MiB of gpu memory\n",
1658 - (unsigned int)(ddr_size / 1024 / 1024));
1663 - ps3vram_cache_cleanup(&ps3vram_mtd);
1665 - iounmap(priv->reports);
1667 - iounmap(priv->ctrl);
1669 - iounmap(priv->ddr_base);
1671 - lv1_gpu_context_free(priv->context_handle);
1673 - lv1_gpu_memory_free(priv->memory_handle);
1675 - ps3_close_hv_device(dev);
1677 - free_pages((unsigned long) priv->xdr_buf, get_order(XDR_BUF_SIZE));
1679 - kfree(ps3vram_mtd.priv);
1680 - ps3vram_mtd.priv = NULL;
1685 -static int ps3vram_shutdown(struct ps3_system_bus_device *dev)
1687 - struct ps3vram_priv *priv;
1689 - priv = ps3vram_mtd.priv;
1691 - del_mtd_device(&ps3vram_mtd);
1692 - ps3vram_cache_cleanup(&ps3vram_mtd);
1693 - iounmap(priv->reports);
1694 - iounmap(priv->ctrl);
1695 - iounmap(priv->ddr_base);
1696 - lv1_gpu_context_free(priv->context_handle);
1697 - lv1_gpu_memory_free(priv->memory_handle);
1698 - ps3_close_hv_device(dev);
1699 - free_pages((unsigned long) priv->xdr_buf, get_order(XDR_BUF_SIZE));
1704 -static struct ps3_system_bus_driver ps3vram_driver = {
1705 - .match_id = PS3_MATCH_ID_GPU,
1706 - .match_sub_id = PS3_MATCH_SUB_ID_GPU_RAMDISK,
1707 - .core.name = DEVICE_NAME,
1708 - .core.owner = THIS_MODULE,
1709 - .probe = ps3vram_probe,
1710 - .remove = ps3vram_shutdown,
1711 - .shutdown = ps3vram_shutdown,
1714 -static int __init ps3vram_init(void)
1716 - return ps3_system_bus_driver_register(&ps3vram_driver);
1719 -static void __exit ps3vram_exit(void)
1721 - ps3_system_bus_driver_unregister(&ps3vram_driver);
1724 -module_init(ps3vram_init);
1725 -module_exit(ps3vram_exit);
1727 -MODULE_LICENSE("GPL");
1728 -MODULE_AUTHOR("Jim Paris <jim@jtan.com>");
1729 -MODULE_DESCRIPTION("MTD driver for PS3 video RAM");
1730 -MODULE_ALIAS(PS3_MODULE_ALIAS_GPU_RAMDISK);