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 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 int 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 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);
88 dev_printf(dev, "write operation is not supported!");
92 if (dblk % (stor_dev.sd_blksize / DEV_BSIZE) != 0)
95 dblk /= (stor_dev.sd_blksize / DEV_BSIZE);
97 if (size % stor_dev.sd_blksize) {
99 "size=%u is not multiple of device block size=%llu", size,
100 stor_dev.sd_blksize);
107 err = ps3stor_read_sectors(&stor_dev, dev->d_unit, dblk,
108 size / stor_dev.sd_blksize, 0, buf);
115 "read operation failed dblk=%llu size=%d err=%d", dblk,
121 static int ps3cdrom_open(struct open_file *f, ...)
125 struct ps3_devdesc *dev;
129 dev = va_arg(ap, struct ps3_devdesc *);
132 if (dev->d_unit > 0) {
133 dev_printf(dev, "attempt to open nonexistent disk");
137 err = ps3stor_read_sectors(&stor_dev, dev->d_unit, 16, 1, 0, buf);
141 /* Do not attach if not ISO9660 (workaround for buggy firmware) */
142 if (memcmp(buf, "\001CD001", 6) != 0)
148 static int ps3cdrom_close(struct open_file *f)
153 static int ps3cdrom_print(int verbose)