23 #include <linux/slab.h>
25 #include <linux/module.h>
31 #define DEVICE_NAME "ps3flash"
33 #define FLASH_BLOCK_SIZE (256*1024)
53 dev_err(&dev->
sbd.core,
"%s:%u: %s failed 0x%llx\n", __func__,
54 __LINE__, write ?
"write" :
"read", res);
68 res = ps3flash_read_write_sectors(dev, priv->
tag, 1);
81 if (start_sector == priv->
tag)
84 res = ps3flash_writeback(dev);
90 res = ps3flash_read_write_sectors(dev, start_sector, 0);
108 offset += file->
f_pos;
129 static ssize_t ps3flash_read(
char __user *userbuf,
void *kernelbuf,
140 "%s:%u: Reading %zu bytes at position %lld to U0x%p/K0x%p\n",
141 __func__, __LINE__, count, *pos, userbuf, kernelbuf);
144 if (*pos >= size || !count)
147 if (*pos + count > size) {
149 "%s:%u Truncating count from %zu to %llu\n", __func__,
150 __LINE__, count, size - *pos);
164 res = ps3flash_fetch(dev, sector);
169 "%s:%u: copy %lu bytes from 0x%p to U0x%p/K0x%p\n",
170 __func__, __LINE__, n, src, userbuf, kernelbuf);
179 memcpy(kernelbuf, src, n);
189 }
while (remaining > 0);
198 static ssize_t ps3flash_write(
const char __user *userbuf,
199 const void *kernelbuf,
size_t count, loff_t *pos)
209 "%s:%u: Writing %zu bytes at position %lld from U0x%p/K0x%p\n",
210 __func__, __LINE__, count, *pos, userbuf, kernelbuf);
213 if (*pos >= size || !count)
216 if (*pos + count > size) {
218 "%s:%u Truncating count from %zu to %llu\n", __func__,
219 __LINE__, count, size - *pos);
234 res = ps3flash_fetch(dev, sector);
235 else if (sector != priv->
tag)
236 res = ps3flash_writeback(dev);
241 "%s:%u: copy %lu bytes from U0x%p/K0x%p to 0x%p\n",
242 __func__, __LINE__, n, userbuf, kernelbuf, dst);
251 memcpy(dst, kernelbuf, n);
264 }
while (remaining > 0);
273 static ssize_t ps3flash_user_read(
struct file *file,
char __user *
buf,
274 size_t count, loff_t *pos)
276 return ps3flash_read(buf,
NULL, count, pos);
279 static ssize_t ps3flash_user_write(
struct file *file,
const char __user *
buf,
280 size_t count, loff_t *pos)
282 return ps3flash_write(buf,
NULL, count, pos);
285 static ssize_t ps3flash_kernel_read(
void *
buf,
size_t count, loff_t pos)
287 return ps3flash_read(
NULL, buf, count, &pos);
290 static ssize_t ps3flash_kernel_write(
const void *
buf,
size_t count,
296 res = ps3flash_write(
NULL, buf, count, &pos);
301 wb = ps3flash_writeback(ps3flash_dev);
308 static int ps3flash_flush(
struct file *file,
fl_owner_t id)
310 return ps3flash_writeback(ps3flash_dev);
313 static int ps3flash_fsync(
struct file *file, loff_t
start, loff_t
end,
int datasync)
318 err = ps3flash_writeback(ps3flash_dev);
329 res = lv1_storage_get_async_status(dev->
sbd.dev_id, &tag, &status);
333 "%s:%u: tag mismatch, got %llx, expected %llx\n",
334 __func__, __LINE__, tag, dev->
tag);
337 dev_err(&dev->
sbd.core,
"%s:%u: res=%d status=0x%llx\n",
338 __func__, __LINE__, res, status);
348 .llseek = ps3flash_llseek,
349 .read = ps3flash_user_read,
350 .write = ps3flash_user_write,
351 .flush = ps3flash_flush,
352 .fsync = ps3flash_fsync,
356 .read = ps3flash_kernel_read,
357 .write = ps3flash_kernel_write,
363 .fops = &ps3flash_fops,
376 "%s:%u region start %lu is not aligned\n", __func__,
381 if (tmp % FLASH_BLOCK_SIZE) {
383 "%s:%u region size %lu is not aligned\n", __func__,
394 "Only one FLASH device is supported\n");
406 ps3_system_bus_set_drvdata(&dev->
sbd, priv);
421 dev_err(&dev->
sbd.core,
"%s:%u: misc_register failed %d\n",
422 __func__, __LINE__, error);
426 dev_info(&dev->
sbd.core,
"%s:%u: registered misc device %d\n",
427 __func__, __LINE__, ps3flash_misc.
minor);
436 ps3_system_bus_set_drvdata(&dev->
sbd,
NULL);
449 kfree(ps3_system_bus_get_drvdata(&dev->
sbd));
450 ps3_system_bus_set_drvdata(&dev->
sbd,
NULL);
460 .probe = ps3flash_probe,
461 .remove = ps3flash_remove,
462 .shutdown = ps3flash_remove,
466 static int __init ps3flash_init(
void)
471 static void __exit ps3flash_exit(
void)