aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorGeert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>2007-06-21 10:14:21 -0400
committerPaul Mackerras <paulus@samba.org>2007-06-28 05:19:20 -0400
commit80071802cb9c622dbd44bc6ba292f0683891ef44 (patch)
tree2ca8bfaee1212a5a62d059ee842394e14b068bae /drivers
parent32d7331852a07d1f94c6d1b817c7c45648aa0fe7 (diff)
[POWERPC] PS3: Storage Driver Core
Add storage driver core support for the PS3. PS3 storage devices are a special kind of PS3 system bus device. Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ps3/Makefile1
-rw-r--r--drivers/ps3/ps3stor_lib.c302
2 files changed, 303 insertions, 0 deletions
diff --git a/drivers/ps3/Makefile b/drivers/ps3/Makefile
index b8c5547adbde..746031de2195 100644
--- a/drivers/ps3/Makefile
+++ b/drivers/ps3/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_PS3_PS3AV) += ps3av_mod.o
3ps3av_mod-objs += ps3av.o ps3av_cmd.o 3ps3av_mod-objs += ps3av.o ps3av_cmd.o
4obj-$(CONFIG_PPC_PS3) += sys-manager-core.o 4obj-$(CONFIG_PPC_PS3) += sys-manager-core.o
5obj-$(CONFIG_PS3_SYS_MANAGER) += sys-manager.o 5obj-$(CONFIG_PS3_SYS_MANAGER) += sys-manager.o
6obj-$(CONFIG_PS3_STORAGE) += ps3stor_lib.o
diff --git a/drivers/ps3/ps3stor_lib.c b/drivers/ps3/ps3stor_lib.c
new file mode 100644
index 000000000000..3a9824e3b251
--- /dev/null
+++ b/drivers/ps3/ps3stor_lib.c
@@ -0,0 +1,302 @@
1/*
2 * PS3 Storage Library
3 *
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <linux/dma-mapping.h>
22
23#include <asm/lv1call.h>
24#include <asm/ps3stor.h>
25
26
27static int ps3stor_probe_access(struct ps3_storage_device *dev)
28{
29 int res, error;
30 unsigned int i;
31 unsigned long n;
32
33 if (dev->sbd.match_id == PS3_MATCH_ID_STOR_ROM) {
34 /* special case: CD-ROM is assumed always accessible */
35 dev->accessible_regions = 1;
36 return 0;
37 }
38
39 error = -EPERM;
40 for (i = 0; i < dev->num_regions; i++) {
41 dev_dbg(&dev->sbd.core,
42 "%s:%u: checking accessibility of region %u\n",
43 __func__, __LINE__, i);
44
45 dev->region_idx = i;
46 res = ps3stor_read_write_sectors(dev, dev->bounce_lpar, 0, 1,
47 0);
48 if (res) {
49 dev_dbg(&dev->sbd.core, "%s:%u: read failed, "
50 "region %u is not accessible\n", __func__,
51 __LINE__, i);
52 continue;
53 }
54
55 dev_dbg(&dev->sbd.core, "%s:%u: region %u is accessible\n",
56 __func__, __LINE__, i);
57 set_bit(i, &dev->accessible_regions);
58
59 /* We can access at least one region */
60 error = 0;
61 }
62 if (error)
63 return error;
64
65 n = hweight_long(dev->accessible_regions);
66 if (n > 1)
67 dev_info(&dev->sbd.core,
68 "%s:%u: %lu accessible regions found. Only the first "
69 "one will be used",
70 __func__, __LINE__, n);
71 dev->region_idx = __ffs(dev->accessible_regions);
72 dev_info(&dev->sbd.core,
73 "First accessible region has index %u start %lu size %lu\n",
74 dev->region_idx, dev->regions[dev->region_idx].start,
75 dev->regions[dev->region_idx].size);
76
77 return 0;
78}
79
80
81/**
82 * ps3stor_setup - Setup a storage device before use
83 * @dev: Pointer to a struct ps3_storage_device
84 * @handler: Pointer to an interrupt handler
85 *
86 * Returns 0 for success, or an error code
87 */
88int ps3stor_setup(struct ps3_storage_device *dev, irq_handler_t handler)
89{
90 int error, res, alignment;
91 enum ps3_dma_page_size page_size;
92
93 error = ps3_open_hv_device(&dev->sbd);
94 if (error) {
95 dev_err(&dev->sbd.core,
96 "%s:%u: ps3_open_hv_device failed %d\n", __func__,
97 __LINE__, error);
98 goto fail;
99 }
100
101 error = ps3_sb_event_receive_port_setup(&dev->sbd, PS3_BINDING_CPU_ANY,
102 &dev->irq);
103 if (error) {
104 dev_err(&dev->sbd.core,
105 "%s:%u: ps3_sb_event_receive_port_setup failed %d\n",
106 __func__, __LINE__, error);
107 goto fail_close_device;
108 }
109
110 error = request_irq(dev->irq, handler, IRQF_DISABLED,
111 dev->sbd.core.driver->name, dev);
112 if (error) {
113 dev_err(&dev->sbd.core, "%s:%u: request_irq failed %d\n",
114 __func__, __LINE__, error);
115 goto fail_sb_event_receive_port_destroy;
116 }
117
118 alignment = min(__ffs(dev->bounce_size),
119 __ffs((unsigned long)dev->bounce_buf));
120 if (alignment < 12) {
121 dev_err(&dev->sbd.core,
122 "%s:%u: bounce buffer not aligned (%lx at 0x%p)\n",
123 __func__, __LINE__, dev->bounce_size, dev->bounce_buf);
124 error = -EINVAL;
125 goto fail_free_irq;
126 } else if (alignment < 16)
127 page_size = PS3_DMA_4K;
128 else
129 page_size = PS3_DMA_64K;
130 dev->sbd.d_region = &dev->dma_region;
131 ps3_dma_region_init(&dev->sbd, &dev->dma_region, page_size,
132 PS3_DMA_OTHER, dev->bounce_buf, dev->bounce_size);
133 res = ps3_dma_region_create(&dev->dma_region);
134 if (res) {
135 dev_err(&dev->sbd.core, "%s:%u: cannot create DMA region\n",
136 __func__, __LINE__);
137 error = -ENOMEM;
138 goto fail_free_irq;
139 }
140
141 dev->bounce_lpar = ps3_mm_phys_to_lpar(__pa(dev->bounce_buf));
142 dev->bounce_dma = dma_map_single(&dev->sbd.core, dev->bounce_buf,
143 dev->bounce_size, DMA_BIDIRECTIONAL);
144 if (!dev->bounce_dma) {
145 dev_err(&dev->sbd.core, "%s:%u: map DMA region failed\n",
146 __func__, __LINE__);
147 error = -ENODEV;
148 goto fail_free_dma;
149 }
150
151 error = ps3stor_probe_access(dev);
152 if (error) {
153 dev_err(&dev->sbd.core, "%s:%u: No accessible regions found\n",
154 __func__, __LINE__);
155 goto fail_unmap_dma;
156 }
157 return 0;
158
159fail_unmap_dma:
160 dma_unmap_single(&dev->sbd.core, dev->bounce_dma, dev->bounce_size,
161 DMA_BIDIRECTIONAL);
162fail_free_dma:
163 ps3_dma_region_free(&dev->dma_region);
164fail_free_irq:
165 free_irq(dev->irq, dev);
166fail_sb_event_receive_port_destroy:
167 ps3_sb_event_receive_port_destroy(&dev->sbd, dev->irq);
168fail_close_device:
169 ps3_close_hv_device(&dev->sbd);
170fail:
171 return error;
172}
173EXPORT_SYMBOL_GPL(ps3stor_setup);
174
175
176/**
177 * ps3stor_teardown - Tear down a storage device after use
178 * @dev: Pointer to a struct ps3_storage_device
179 */
180void ps3stor_teardown(struct ps3_storage_device *dev)
181{
182 int error;
183