2 * Copyright (C) 2011 glevand <geoffrey.levand@mail.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/param.h>
29 #include <sys/endian.h>
30 #include <machine/stdarg.h>
33 #include "bootstrap.h"
35 #include "ps3devdesc.h"
38 #define dev_printf(dev, fmt, args...) \
39 printf("%s%d: " fmt "\n", dev->d_dev->dv_name, dev->d_unit, ##args)
42 #define DEBUG(fmt, args...) printf("%s:%d: " fmt "\n", __func__, __LINE__, ##args)
44 #define DEBUG(fmt, args...)
47 static int ps3cdrom_init(void);
48 static int ps3cdrom_strategy(void *devdata, int flag, daddr_t dblk,
49 size_t offset, size_t size, char *buf, size_t *rsize);
50 static int ps3cdrom_open(struct open_file *f, ...);
51 static int ps3cdrom_close(struct open_file *f);
52 static void ps3cdrom_print(int verbose);
54 struct devsw ps3cdrom = {
65 static struct ps3_stordev stor_dev;
67 static int ps3cdrom_init(void)
71 err = ps3stor_setup(&stor_dev, PS3_DEV_TYPE_STOR_CDROM);
78 static int ps3cdrom_strategy(void *devdata, int flag, daddr_t dblk,
79 size_t offset, size_t size, char *buf, size_t *rsize)
81 struct ps3_devdesc *dev = (struct ps3_devdesc *) devdata;
84 DEBUG("d_unit=%u dblk=%llu size=%u", dev->d_unit, dblk, size);
87 dev_printf(dev, "write operation is not supported!");
91 if (dblk % (stor_dev.sd_blksize / DEV_BSIZE) != 0)
94 dblk /= (stor_dev.sd_blksize / DEV_BSIZE);
96 if (size % stor_dev.sd_blksize) {
98 "size=%u is not multiple of device block size=%llu", size,
106 err = ps3stor_read_sectors(&stor_dev, dev->d_unit, dblk,
107 size / stor_dev.sd_blksize, 0, buf);
114 "read operation failed dblk=%llu size=%d err=%d", dblk,
120 static int ps3cdrom_open(struct open_file *f, ...)
124 struct ps3_devdesc *dev;
128 dev = va_arg(ap, struct ps3_devdesc *);
131 if (dev->d_unit > 0) {
132 dev_printf(dev, "attempt to open nonexistent disk");
136 err = ps3stor_read_sectors(&stor_dev, dev->d_unit, 16, 1, 0, buf);
140 /* Do not attach if not ISO9660 (workaround for buggy firmware) */
141 if (memcmp(buf, "\001CD001", 6) != 0)
147 static int ps3cdrom_close(struct open_file *f)
152 static void ps3cdrom_print(int verbose)