ps3stor.c (224106) | ps3stor.c (224857) |
---|---|
1/*- 2 * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru) 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 8 unchanged lines hidden (view full) --- 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. 24 * | 1/*- 2 * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru) 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 8 unchanged lines hidden (view full) --- 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. 24 * |
25 * $FreeBSD: head/sys/boot/powerpc/ps3/ps3stor.c 224106 2011-07-16 19:01:09Z nwhitehorn $ | 25 * $FreeBSD: head/sys/boot/powerpc/ps3/ps3stor.c 224857 2011-08-14 00:20:37Z nwhitehorn $ |
26 */ 27 28#include <stand.h> 29 30#include "bootstrap.h" 31#include "lv1call.h" 32#include "ps3bus.h" 33#include "ps3repo.h" --- 13 unchanged lines hidden (view full) --- 47 err = ps3repo_read_bus_id(sd->sd_busidx, &sd->sd_busid); 48 if (err) 49 goto out; 50 51 err = ps3repo_find_bus_dev_by_type(sd->sd_busidx, type, &sd->sd_devidx); 52 if (err) 53 goto out; 54 | 26 */ 27 28#include <stand.h> 29 30#include "bootstrap.h" 31#include "lv1call.h" 32#include "ps3bus.h" 33#include "ps3repo.h" --- 13 unchanged lines hidden (view full) --- 47 err = ps3repo_read_bus_id(sd->sd_busidx, &sd->sd_busid); 48 if (err) 49 goto out; 50 51 err = ps3repo_find_bus_dev_by_type(sd->sd_busidx, type, &sd->sd_devidx); 52 if (err) 53 goto out; 54 |
55 err = ps3repo_read_bus_dev_id(sd->sd_busidx, sd->sd_devidx, &sd->sd_devid); | 55 err = ps3repo_read_bus_dev_id(sd->sd_busidx, sd->sd_devidx, 56 &sd->sd_devid); |
56 if (err) 57 goto out; 58 | 57 if (err) 58 goto out; 59 |
59 err = ps3repo_read_bus_dev_blk_size(sd->sd_busidx, sd->sd_devidx, &sd->sd_blksize); | 60 err = ps3repo_read_bus_dev_blk_size(sd->sd_busidx, sd->sd_devidx, 61 &sd->sd_blksize); |
60 if (err) 61 goto out; 62 | 62 if (err) 63 goto out; 64 |
63 err = ps3repo_read_bus_dev_nblocks(sd->sd_busidx, sd->sd_devidx, &sd->sd_nblocks); | 65 err = ps3repo_read_bus_dev_nblocks(sd->sd_busidx, sd->sd_devidx, 66 &sd->sd_nblocks); |
64 if (err) 65 goto out; 66 | 67 if (err) 68 goto out; 69 |
67 err = ps3repo_read_bus_dev_nregs(sd->sd_busidx, sd->sd_devidx, &sd->sd_nregs); | 70 err = ps3repo_read_bus_dev_nregs(sd->sd_busidx, sd->sd_devidx, 71 &sd->sd_nregs); |
68 if (err) 69 goto out; 70 71 for (i = 0; i < sd->sd_nregs; i++) { | 72 if (err) 73 goto out; 74 75 for (i = 0; i < sd->sd_nregs; i++) { |
72 err = ps3repo_read_bus_dev_reg_id(sd->sd_busidx, sd->sd_devidx, i, 73 &sd->sd_regs[i].sr_id); | 76 err = ps3repo_read_bus_dev_reg_id(sd->sd_busidx, sd->sd_devidx, 77 i, &sd->sd_regs[i].sr_id); |
74 if (err) 75 goto out; 76 | 78 if (err) 79 goto out; 80 |
77 err = ps3repo_read_bus_dev_reg_start(sd->sd_busidx, sd->sd_devidx, i, 78 &sd->sd_regs[i].sr_start); | 81 err = ps3repo_read_bus_dev_reg_start(sd->sd_busidx, 82 sd->sd_devidx, i, &sd->sd_regs[i].sr_start); |
79 if (err) 80 goto out; 81 | 83 if (err) 84 goto out; 85 |
82 err = ps3repo_read_bus_dev_reg_size(sd->sd_busidx, sd->sd_devidx, i, 83 &sd->sd_regs[i].sr_size); | 86 err = ps3repo_read_bus_dev_reg_size(sd->sd_busidx, 87 sd->sd_devidx, i, &sd->sd_regs[i].sr_size); |
84 if (err) 85 goto out; 86 } 87 88 if (!sd->sd_nregs) { 89 err = ENODEV; 90 goto out; 91 } --- 12 unchanged lines hidden (view full) --- 104 105 lv1_close_device(sd->sd_busid, sd->sd_devid); 106 107out: 108 109 return err; 110} 111 | 88 if (err) 89 goto out; 90 } 91 92 if (!sd->sd_nregs) { 93 err = ENODEV; 94 goto out; 95 } --- 12 unchanged lines hidden (view full) --- 108 109 lv1_close_device(sd->sd_busid, sd->sd_devid); 110 111out: 112 113 return err; 114} 115 |
116static char dma_buf[2048] __aligned(2048); 117 |
|
112int ps3stor_read_sectors(struct ps3_stordev *sd, int regidx, 113 uint64_t start_sector, uint64_t sector_count, uint64_t flags, char *buf) 114{ 115#define MIN(a, b) ((a) <= (b) ? (a) : (b)) | 118int ps3stor_read_sectors(struct ps3_stordev *sd, int regidx, 119 uint64_t start_sector, uint64_t sector_count, uint64_t flags, char *buf) 120{ 121#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
116#define BOUNCE_SECTORS 4 | 122#define BOUNCE_SECTORS (sizeof(dma_buf) / sd->sd_blksize) |
117#define ASYNC_STATUS_POLL_PERIOD 100 /* microseconds */ 118 119 struct ps3_storreg *reg = &sd->sd_regs[regidx]; | 123#define ASYNC_STATUS_POLL_PERIOD 100 /* microseconds */ 124 125 struct ps3_storreg *reg = &sd->sd_regs[regidx]; |
120 char dma_buf[sd->sd_blksize * BOUNCE_SECTORS]; | |
121 uint64_t nleft, nread, nsectors; 122 uint64_t tag, status; 123 unsigned int timeout; | 126 uint64_t nleft, nread, nsectors; 127 uint64_t tag, status; 128 unsigned int timeout; |
124 int err; | 129 int err = 0; |
125 126 nleft = sector_count; 127 nread = 0; 128 129 while (nleft) { 130 nsectors = MIN(nleft, BOUNCE_SECTORS); 131 | 130 131 nleft = sector_count; 132 nread = 0; 133 134 while (nleft) { 135 nsectors = MIN(nleft, BOUNCE_SECTORS); 136 |
132 err = lv1_storage_read(sd->sd_devid, reg->sr_id, start_sector + nread, nsectors, 133 flags, (uint32_t) dma_buf, &tag); | 137 err = lv1_storage_read(sd->sd_devid, reg->sr_id, 138 start_sector + nread, nsectors, flags, (uint32_t)dma_buf, 139 &tag); |
134 if (err) 135 return err; 136 137 timeout = 5000000; /* microseconds */ 138 139 while (1) { 140 if (timeout < ASYNC_STATUS_POLL_PERIOD) 141 return ETIMEDOUT; 142 | 140 if (err) 141 return err; 142 143 timeout = 5000000; /* microseconds */ 144 145 while (1) { 146 if (timeout < ASYNC_STATUS_POLL_PERIOD) 147 return ETIMEDOUT; 148 |
143 err = lv1_storage_check_async_status(sd->sd_devid, tag, &status); | 149 err = lv1_storage_check_async_status(sd->sd_devid, tag, 150 &status); |
144 if (!err && !status) 145 break; 146 147 delay(ASYNC_STATUS_POLL_PERIOD); 148 timeout -= ASYNC_STATUS_POLL_PERIOD; 149 } 150 | 151 if (!err && !status) 152 break; 153 154 delay(ASYNC_STATUS_POLL_PERIOD); 155 timeout -= ASYNC_STATUS_POLL_PERIOD; 156 } 157 |
151 memcpy(buf + nread * sd->sd_blksize, (u_char *) dma_buf, nsectors * sd->sd_blksize); | 158 if (status != 0) 159 return EIO; 160 161 memcpy(buf + nread * sd->sd_blksize, (u_char *)dma_buf, 162 nsectors * sd->sd_blksize); |
152 nread += nsectors; 153 nleft -= nsectors; 154 } 155 | 163 nread += nsectors; 164 nleft -= nsectors; 165 } 166 |
156 return 0; | 167 return err; |
157 158#undef MIN 159#undef BOUNCE_SECTORS 160#undef ASYNC_STATUS_POLL_PERIOD 161} 162 163void ps3stor_print(struct ps3_stordev *sd) 164{ 165} | 168 169#undef MIN 170#undef BOUNCE_SECTORS 171#undef ASYNC_STATUS_POLL_PERIOD 172} 173 174void ps3stor_print(struct ps3_stordev *sd) 175{ 176} |