1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/*-
* Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <stand.h>
#include "bootstrap.h"
#include "lv1call.h"
#include "ps3bus.h"
#include "ps3repo.h"
#include "ps3stor.h"
int ps3stor_setup(struct ps3_stordev *sd, int type)
{
unsigned int i;
int err;
sd->sd_type = type;
err = ps3repo_find_bus_by_type(PS3_BUS_TYPE_STOR, &sd->sd_busidx);
if (err)
goto out;
err = ps3repo_read_bus_id(sd->sd_busidx, &sd->sd_busid);
if (err)
goto out;
err = ps3repo_find_bus_dev_by_type(sd->sd_busidx, type, &sd->sd_devidx);
if (err)
goto out;
err = ps3repo_read_bus_dev_id(sd->sd_busidx, sd->sd_devidx,
&sd->sd_devid);
if (err)
goto out;
err = ps3repo_read_bus_dev_blk_size(sd->sd_busidx, sd->sd_devidx,
&sd->sd_blksize);
if (err)
goto out;
err = ps3repo_read_bus_dev_nblocks(sd->sd_busidx, sd->sd_devidx,
&sd->sd_nblocks);
if (err)
goto out;
err = ps3repo_read_bus_dev_nregs(sd->sd_busidx, sd->sd_devidx,
&sd->sd_nregs);
if (err)
goto out;
for (i = 0; i < sd->sd_nregs; i++) {
err = ps3repo_read_bus_dev_reg_id(sd->sd_busidx, sd->sd_devidx,
i, &sd->sd_regs[i].sr_id);
if (err)
goto out;
err = ps3repo_read_bus_dev_reg_start(sd->sd_busidx,
sd->sd_devidx, i, &sd->sd_regs[i].sr_start);
if (err)
goto out;
err = ps3repo_read_bus_dev_reg_size(sd->sd_busidx,
sd->sd_devidx, i, &sd->sd_regs[i].sr_size);
if (err)
goto out;
}
if (!sd->sd_nregs) {
err = ENODEV;
goto out;
}
err = lv1_open_device(sd->sd_busid, sd->sd_devid, 0);
if (err)
goto out;
err = lv1_setup_dma(sd->sd_busid, sd->sd_devid, &sd->sd_dmabase);
if (err)
goto close_dev;
return 0;
close_dev:
lv1_close_device(sd->sd_busid, sd->sd_devid);
out:
return err;
}
static char dma_buf[2048] __aligned(2048);
int ps3stor_read_sectors(struct ps3_stordev *sd, int regidx,
uint64_t start_sector, uint64_t sector_count, uint64_t flags, char *buf)
{
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
#define BOUNCE_SECTORS (sizeof(dma_buf) / sd->sd_blksize)
#define ASYNC_STATUS_POLL_PERIOD 100 /* microseconds */
struct ps3_storreg *reg = &sd->sd_regs[regidx];
uint64_t nleft, nread, nsectors;
uint64_t tag, status;
unsigned int timeout;
int err = 0;
nleft = sector_count;
nread = 0;
while (nleft) {
nsectors = MIN(nleft, BOUNCE_SECTORS);
err = lv1_storage_read(sd->sd_devid, reg->sr_id,
start_sector + nread, nsectors, flags, (uint32_t)dma_buf,
&tag);
if (err)
return err;
timeout = 5000000; /* microseconds */
while (1) {
if (timeout < ASYNC_STATUS_POLL_PERIOD)
return ETIMEDOUT;
err = lv1_storage_check_async_status(sd->sd_devid, tag,
&status);
if (!err && !status)
break;
delay(ASYNC_STATUS_POLL_PERIOD);
timeout -= ASYNC_STATUS_POLL_PERIOD;
}
if (status != 0)
return EIO;
memcpy(buf + nread * sd->sd_blksize, (u_char *)dma_buf,
nsectors * sd->sd_blksize);
nread += nsectors;
nleft -= nsectors;
}
return err;
#undef MIN
#undef BOUNCE_SECTORS
#undef ASYNC_STATUS_POLL_PERIOD
}
void ps3stor_print(struct ps3_stordev *sd)
{
}
|