2 * Copyright (c) 2007, Benedikt Sauter <sauter@ixbat.de>
5 * Short descripton of file:
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of the FH Augsburg nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 void usb_storage_probe();
38 void usb_storage_check();
40 /* CSW Status Definitions */
41 #define CSW_CMD_PASSED 0x00
42 #define CSW_CMD_FAILED 0x01
43 #define CSW_PHASE_ERROR 0x02
47 #define SCSI_TEST_UNIT_READY 0x00
48 #define SCSI_REQUEST_SENSE 0x03
49 #define SCSI_FORMAT_UNIT 0x04
50 #define SCSI_INQUIRY 0x12
51 #define SCSI_MODE_SELECT6 0x15
52 #define SCSI_MODE_SENSE6 0x1A
53 #define SCSI_START_STOP_UNIT 0x1B
54 #define SCSI_MEDIA_REMOVAL 0x1E
55 #define SCSI_READ_FORMAT_CAPACITIES 0x23
56 #define SCSI_READ_CAPACITY 0x25
57 #define SCSI_READ10 0x28
58 #define SCSI_WRITE10 0x2A
59 #define SCSI_VERIFY10 0x2F
60 #define SCSI_MODE_SELECT10 0x55
61 #define SCSI_MODE_SENSE10 0x5A
64 typedef struct usb_storage_cbw_t usb_storage_cbw;
65 struct usb_storage_cbw_t {
68 u32 dCBWDataTransferLength;
75 typedef struct usb_storage_csw_t usb_storage_csw;
76 struct usb_storage_csw_t {
84 void usb_storage_init();
86 u8 usb_storage_open(u8 device);
88 u8 usb_storage_read_capacity(u8 device);
89 u8 usb_storage_inquiry(u8 device);
90 u8 usb_storage_read_sector(u8 device, u32 sector, char * buf);
91 u8 usb_storage_write_sector(u8 device, u32 sector, char * buf);
93 #define USBSTORAGE_OK 0
94 #define USBSTORAGE_ENOINTERFACE -10000
95 #define USBSTORAGE_ESENSE -10001
96 #define USBSTORAGE_ESHORTWRITE -10002
97 #define USBSTORAGE_ESHORTREAD -10003
98 #define USBSTORAGE_ESIGNATURE -10004
99 #define USBSTORAGE_ETAG -10005
100 #define USBSTORAGE_ESTATUS -10006
101 #define USBSTORAGE_EDATARESIDUE -10007
102 #define USBSTORAGE_ETIMEDOUT -10008
103 #define USBSTORAGE_EINIT -10009
104 #define USBSTORAGE_PROCESSING -10010
128 s32 USBStorage_Initialize();
130 s32 USBStorage_Open(usbstorage_handle *dev, const char *bus, u16 vid, u16 pid);
131 s32 USBStorage_Close(usbstorage_handle *dev);
132 s32 USBStorage_Reset(usbstorage_handle *dev);
134 s32 USBStorage_GetMaxLUN(usbstorage_handle *dev);
135 s32 USBStorage_MountLUN(usbstorage_handle *dev, u8 lun);
136 s32 USBStorage_Suspend(usbstorage_handle *dev);
138 s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors);
139 s32 USBStorage_Read(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, u8 *buffer);
140 s32 USBStorage_Write(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, const u8 *buffer);
143 #define DEVICE_TYPE_WII_USB (('W'<<24)|('U'<<16)|('S'<<8)|'B')
145 extern const DISC_INTERFACE __io_usbstorage;
147 #define __stwbrx(base,index,value) \
148 __asm__ volatile ("stwbrx %0,%1,%2" : : "r"(value), "b%"(index), "r"(base) : "memory")
150 #define __lwbrx(base,index) \
151 ({ register u32 res; \
152 __asm__ volatile ("lwbrx %0,%1,%2" : "=r"(res) : "b%"(index), "r"(base) : "memory"); \
155 #endif /* __STORAGE_H */