ld_sdmmc.c revision 1.14.2.5 1 1.14.2.5 skrll /* $NetBSD: ld_sdmmc.c,v 1.14.2.5 2017/08/28 17:52:27 skrll Exp $ */
2 1.1 nonaka
3 1.1 nonaka /*
4 1.1 nonaka * Copyright (c) 2008 KIYOHARA Takashi
5 1.1 nonaka * All rights reserved.
6 1.1 nonaka *
7 1.1 nonaka * Redistribution and use in source and binary forms, with or without
8 1.1 nonaka * modification, are permitted provided that the following conditions
9 1.1 nonaka * are met:
10 1.1 nonaka * 1. Redistributions of source code must retain the above copyright
11 1.1 nonaka * notice, this list of conditions and the following disclaimer.
12 1.1 nonaka * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 nonaka * notice, this list of conditions and the following disclaimer in the
14 1.1 nonaka * documentation and/or other materials provided with the distribution.
15 1.1 nonaka *
16 1.1 nonaka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 nonaka * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 1.1 nonaka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 1.1 nonaka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 1.1 nonaka * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.1 nonaka * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.1 nonaka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 nonaka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 1.1 nonaka * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 1.1 nonaka * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 nonaka * POSSIBILITY OF SUCH DAMAGE.
27 1.1 nonaka *
28 1.1 nonaka */
29 1.1 nonaka
30 1.1 nonaka #include <sys/cdefs.h>
31 1.14.2.5 skrll __KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.14.2.5 2017/08/28 17:52:27 skrll Exp $");
32 1.1 nonaka
33 1.9 matt #ifdef _KERNEL_OPT
34 1.9 matt #include "opt_sdmmc.h"
35 1.9 matt #endif
36 1.1 nonaka
37 1.1 nonaka #include <sys/param.h>
38 1.1 nonaka #include <sys/systm.h>
39 1.1 nonaka #include <sys/kernel.h>
40 1.1 nonaka #include <sys/device.h>
41 1.1 nonaka #include <sys/buf.h>
42 1.1 nonaka #include <sys/bufq.h>
43 1.1 nonaka #include <sys/bus.h>
44 1.1 nonaka #include <sys/endian.h>
45 1.1 nonaka #include <sys/dkio.h>
46 1.1 nonaka #include <sys/disk.h>
47 1.14.2.4 skrll #include <sys/disklabel.h>
48 1.3 nonaka #include <sys/kthread.h>
49 1.14.2.4 skrll #include <sys/syslog.h>
50 1.14.2.3 skrll #include <sys/module.h>
51 1.14.2.5 skrll #include <sys/pcq.h>
52 1.1 nonaka
53 1.1 nonaka #include <dev/ldvar.h>
54 1.1 nonaka
55 1.1 nonaka #include <dev/sdmmc/sdmmcvar.h>
56 1.1 nonaka
57 1.14.2.3 skrll #include "ioconf.h"
58 1.14.2.3 skrll
59 1.14 jmcneill #ifdef LD_SDMMC_DEBUG
60 1.1 nonaka #define DPRINTF(s) printf s
61 1.1 nonaka #else
62 1.1 nonaka #define DPRINTF(s) /**/
63 1.1 nonaka #endif
64 1.1 nonaka
65 1.14.2.4 skrll #define LD_SDMMC_IORETRIES 5 /* number of retries before giving up */
66 1.14.2.4 skrll #define RECOVERYTIME hz/2 /* time to wait before retrying a cmd */
67 1.14.2.4 skrll
68 1.14.2.5 skrll #define LD_SDMMC_MAXQUEUECNT 4 /* number of queued bio requests */
69 1.14.2.5 skrll #define LD_SDMMC_MAXTASKCNT 8 /* number of tasks in task pool */
70 1.14.2.5 skrll
71 1.1 nonaka struct ld_sdmmc_softc;
72 1.1 nonaka
73 1.1 nonaka struct ld_sdmmc_task {
74 1.1 nonaka struct sdmmc_task task;
75 1.1 nonaka
76 1.1 nonaka struct ld_sdmmc_softc *task_sc;
77 1.14.2.5 skrll
78 1.1 nonaka struct buf *task_bp;
79 1.14.2.4 skrll int task_retries; /* number of xfer retry */
80 1.14.2.4 skrll struct callout task_restart_ch;
81 1.1 nonaka };
82 1.1 nonaka
83 1.1 nonaka struct ld_sdmmc_softc {
84 1.1 nonaka struct ld_softc sc_ld;
85 1.1 nonaka int sc_hwunit;
86 1.1 nonaka
87 1.1 nonaka struct sdmmc_function *sc_sf;
88 1.14.2.5 skrll struct ld_sdmmc_task sc_task[LD_SDMMC_MAXTASKCNT];
89 1.14.2.5 skrll pcq_t *sc_freeq;
90 1.14.2.5 skrll
91 1.14.2.5 skrll struct evcnt sc_ev_discard; /* discard counter */
92 1.14.2.5 skrll struct evcnt sc_ev_discarderr; /* discard error counter */
93 1.14.2.5 skrll struct evcnt sc_ev_discardbusy; /* discard busy counter */
94 1.1 nonaka };
95 1.1 nonaka
96 1.2 cegger static int ld_sdmmc_match(device_t, cfdata_t, void *);
97 1.1 nonaka static void ld_sdmmc_attach(device_t, device_t, void *);
98 1.1 nonaka static int ld_sdmmc_detach(device_t, int);
99 1.1 nonaka
100 1.1 nonaka static int ld_sdmmc_dump(struct ld_softc *, void *, int, int);
101 1.1 nonaka static int ld_sdmmc_start(struct ld_softc *, struct buf *);
102 1.14.2.4 skrll static void ld_sdmmc_restart(void *);
103 1.14.2.5 skrll static int ld_sdmmc_discard(struct ld_softc *, struct buf *);
104 1.14.2.5 skrll static int ld_sdmmc_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
105 1.1 nonaka
106 1.3 nonaka static void ld_sdmmc_doattach(void *);
107 1.1 nonaka static void ld_sdmmc_dobio(void *);
108 1.14.2.5 skrll static void ld_sdmmc_dodiscard(void *);
109 1.1 nonaka
110 1.1 nonaka CFATTACH_DECL_NEW(ld_sdmmc, sizeof(struct ld_sdmmc_softc),
111 1.1 nonaka ld_sdmmc_match, ld_sdmmc_attach, ld_sdmmc_detach, NULL);
112 1.1 nonaka
113 1.1 nonaka
114 1.1 nonaka /* ARGSUSED */
115 1.1 nonaka static int
116 1.2 cegger ld_sdmmc_match(device_t parent, cfdata_t match, void *aux)
117 1.1 nonaka {
118 1.1 nonaka struct sdmmc_softc *sdmsc = device_private(parent);
119 1.1 nonaka
120 1.1 nonaka if (ISSET(sdmsc->sc_flags, SMF_MEM_MODE))
121 1.1 nonaka return 1;
122 1.1 nonaka return 0;
123 1.1 nonaka }
124 1.1 nonaka
125 1.1 nonaka /* ARGSUSED */
126 1.1 nonaka static void
127 1.1 nonaka ld_sdmmc_attach(device_t parent, device_t self, void *aux)
128 1.1 nonaka {
129 1.1 nonaka struct ld_sdmmc_softc *sc = device_private(self);
130 1.1 nonaka struct sdmmc_attach_args *sa = aux;
131 1.1 nonaka struct ld_softc *ld = &sc->sc_ld;
132 1.14.2.4 skrll struct ld_sdmmc_task *task;
133 1.3 nonaka struct lwp *lwp;
134 1.14.2.4 skrll int i;
135 1.1 nonaka
136 1.1 nonaka ld->sc_dv = self;
137 1.1 nonaka
138 1.11 jakllsch aprint_normal(": <0x%02x:0x%04x:%s:0x%02x:0x%08x:0x%03x>\n",
139 1.11 jakllsch sa->sf->cid.mid, sa->sf->cid.oid, sa->sf->cid.pnm,
140 1.11 jakllsch sa->sf->cid.rev, sa->sf->cid.psn, sa->sf->cid.mdt);
141 1.1 nonaka aprint_naive("\n");
142 1.1 nonaka
143 1.14.2.5 skrll evcnt_attach_dynamic(&sc->sc_ev_discard, EVCNT_TYPE_MISC,
144 1.14.2.5 skrll NULL, device_xname(self), "sdmmc discard count");
145 1.14.2.5 skrll evcnt_attach_dynamic(&sc->sc_ev_discarderr, EVCNT_TYPE_MISC,
146 1.14.2.5 skrll NULL, device_xname(self), "sdmmc discard errors");
147 1.14.2.5 skrll evcnt_attach_dynamic(&sc->sc_ev_discardbusy, EVCNT_TYPE_MISC,
148 1.14.2.5 skrll NULL, device_xname(self), "sdmmc discard busy");
149 1.14.2.5 skrll
150 1.14.2.5 skrll const int ntask = __arraycount(sc->sc_task);
151 1.14.2.5 skrll sc->sc_freeq = pcq_create(ntask, KM_SLEEP);
152 1.14.2.5 skrll for (i = 0; i < ntask; i++) {
153 1.14.2.4 skrll task = &sc->sc_task[i];
154 1.14.2.4 skrll task->task_sc = sc;
155 1.14.2.5 skrll callout_init(&task->task_restart_ch, CALLOUT_MPSAFE);
156 1.14.2.5 skrll pcq_put(sc->sc_freeq, task);
157 1.14.2.4 skrll }
158 1.1 nonaka
159 1.1 nonaka sc->sc_hwunit = 0; /* always 0? */
160 1.1 nonaka sc->sc_sf = sa->sf;
161 1.1 nonaka
162 1.14.2.5 skrll ld->sc_flags = LDF_ENABLED | LDF_MPSAFE;
163 1.1 nonaka ld->sc_secperunit = sc->sc_sf->csd.capacity;
164 1.4 nonaka ld->sc_secsize = SDMMC_SECTOR_SIZE;
165 1.1 nonaka ld->sc_maxxfer = MAXPHYS;
166 1.14.2.2 skrll ld->sc_maxqueuecnt = LD_SDMMC_MAXQUEUECNT;
167 1.1 nonaka ld->sc_dump = ld_sdmmc_dump;
168 1.1 nonaka ld->sc_start = ld_sdmmc_start;
169 1.14.2.5 skrll ld->sc_discard = ld_sdmmc_discard;
170 1.14.2.5 skrll ld->sc_ioctl = ld_sdmmc_ioctl;
171 1.1 nonaka
172 1.3 nonaka /*
173 1.14.2.5 skrll * Defer attachment of ld + disk subsystem to a thread.
174 1.14.2.5 skrll *
175 1.14.2.5 skrll * This is necessary because wedge autodiscover needs to
176 1.14.2.5 skrll * open and call into the ld driver, which could deadlock
177 1.14.2.5 skrll * when the sdmmc driver isn't ready in early bootstrap.
178 1.14.2.5 skrll *
179 1.14.2.5 skrll * Don't mark thread as MPSAFE to keep aprint output sane.
180 1.3 nonaka */
181 1.12 christos config_pending_incr(self);
182 1.14.2.5 skrll if (kthread_create(PRI_NONE, 0, NULL,
183 1.3 nonaka ld_sdmmc_doattach, sc, &lwp, "%sattach", device_xname(self))) {
184 1.3 nonaka aprint_error_dev(self, "couldn't create thread\n");
185 1.3 nonaka }
186 1.3 nonaka }
187 1.3 nonaka
188 1.3 nonaka static void
189 1.3 nonaka ld_sdmmc_doattach(void *arg)
190 1.3 nonaka {
191 1.3 nonaka struct ld_sdmmc_softc *sc = (struct ld_sdmmc_softc *)arg;
192 1.3 nonaka struct ld_softc *ld = &sc->sc_ld;
193 1.6 kiyohara struct sdmmc_softc *ssc = device_private(device_parent(ld->sc_dv));
194 1.14.2.5 skrll const u_int cache_size = sc->sc_sf->ext_csd.cache_size;
195 1.14.2.5 skrll char buf[sizeof("9999 KB")];
196 1.3 nonaka
197 1.14.2.3 skrll ldattach(ld, BUFQ_DISK_DEFAULT_STRAT);
198 1.14.2.2 skrll aprint_normal_dev(ld->sc_dv, "%d-bit width,", sc->sc_sf->width);
199 1.14.2.2 skrll if (ssc->sc_transfer_mode != NULL)
200 1.14.2.2 skrll aprint_normal(" %s,", ssc->sc_transfer_mode);
201 1.14.2.5 skrll if (cache_size > 0) {
202 1.14.2.5 skrll format_bytes(buf, sizeof(buf), cache_size);
203 1.14.2.5 skrll aprint_normal(" %s cache%s,", buf,
204 1.14.2.5 skrll ISSET(sc->sc_sf->flags, SFF_CACHE_ENABLED) ? "" :
205 1.14.2.5 skrll " (disabled)");
206 1.14.2.5 skrll }
207 1.6 kiyohara if ((ssc->sc_busclk / 1000) != 0)
208 1.6 kiyohara aprint_normal(" %u.%03u MHz\n",
209 1.6 kiyohara ssc->sc_busclk / 1000, ssc->sc_busclk % 1000);
210 1.6 kiyohara else
211 1.6 kiyohara aprint_normal(" %u KHz\n", ssc->sc_busclk % 1000);
212 1.12 christos config_pending_decr(ld->sc_dv);
213 1.3 nonaka kthread_exit(0);
214 1.1 nonaka }
215 1.1 nonaka
216 1.1 nonaka static int
217 1.1 nonaka ld_sdmmc_detach(device_t dev, int flags)
218 1.1 nonaka {
219 1.1 nonaka struct ld_sdmmc_softc *sc = device_private(dev);
220 1.1 nonaka struct ld_softc *ld = &sc->sc_ld;
221 1.14.2.4 skrll int rv, i;
222 1.1 nonaka
223 1.1 nonaka if ((rv = ldbegindetach(ld, flags)) != 0)
224 1.1 nonaka return rv;
225 1.1 nonaka ldenddetach(ld);
226 1.1 nonaka
227 1.14.2.4 skrll for (i = 0; i < __arraycount(sc->sc_task); i++)
228 1.14.2.4 skrll callout_destroy(&sc->sc_task[i].task_restart_ch);
229 1.14.2.4 skrll
230 1.14.2.5 skrll pcq_destroy(sc->sc_freeq);
231 1.14.2.5 skrll evcnt_detach(&sc->sc_ev_discard);
232 1.14.2.5 skrll evcnt_detach(&sc->sc_ev_discarderr);
233 1.14.2.5 skrll evcnt_detach(&sc->sc_ev_discardbusy);
234 1.14.2.5 skrll
235 1.1 nonaka return 0;
236 1.1 nonaka }
237 1.1 nonaka
238 1.1 nonaka static int
239 1.1 nonaka ld_sdmmc_start(struct ld_softc *ld, struct buf *bp)
240 1.1 nonaka {
241 1.1 nonaka struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
242 1.14.2.5 skrll struct ld_sdmmc_task *task = pcq_get(sc->sc_freeq);
243 1.14.2.2 skrll
244 1.14.2.5 skrll if (task == NULL)
245 1.14.2.5 skrll return EAGAIN;
246 1.1 nonaka
247 1.1 nonaka task->task_bp = bp;
248 1.14.2.4 skrll task->task_retries = 0;
249 1.1 nonaka sdmmc_init_task(&task->task, ld_sdmmc_dobio, task);
250 1.1 nonaka
251 1.1 nonaka sdmmc_add_task(sc->sc_sf->sc, &task->task);
252 1.1 nonaka
253 1.1 nonaka return 0;
254 1.1 nonaka }
255 1.1 nonaka
256 1.1 nonaka static void
257 1.14.2.4 skrll ld_sdmmc_restart(void *arg)
258 1.14.2.4 skrll {
259 1.14.2.4 skrll struct ld_sdmmc_task *task = (struct ld_sdmmc_task *)arg;
260 1.14.2.4 skrll struct ld_sdmmc_softc *sc = task->task_sc;
261 1.14.2.4 skrll struct buf *bp = task->task_bp;
262 1.14.2.4 skrll
263 1.14.2.4 skrll bp->b_resid = bp->b_bcount;
264 1.14.2.4 skrll
265 1.14.2.4 skrll sdmmc_add_task(sc->sc_sf->sc, &task->task);
266 1.14.2.4 skrll }
267 1.14.2.4 skrll
268 1.14.2.4 skrll static void
269 1.1 nonaka ld_sdmmc_dobio(void *arg)
270 1.1 nonaka {
271 1.1 nonaka struct ld_sdmmc_task *task = (struct ld_sdmmc_task *)arg;
272 1.1 nonaka struct ld_sdmmc_softc *sc = task->task_sc;
273 1.1 nonaka struct buf *bp = task->task_bp;
274 1.14.2.2 skrll int error;
275 1.1 nonaka
276 1.1 nonaka /*
277 1.1 nonaka * I/O operation
278 1.1 nonaka */
279 1.1 nonaka DPRINTF(("%s: I/O operation (dir=%s, blkno=0x%jx, bcnt=0x%x)\n",
280 1.1 nonaka device_xname(sc->sc_ld.sc_dv), bp->b_flags & B_READ ? "IN" : "OUT",
281 1.1 nonaka bp->b_rawblkno, bp->b_bcount));
282 1.1 nonaka
283 1.1 nonaka /* is everything done in terms of blocks? */
284 1.1 nonaka if (bp->b_rawblkno >= sc->sc_sf->csd.capacity) {
285 1.1 nonaka /* trying to read or write past end of device */
286 1.13 mlelstv aprint_error_dev(sc->sc_ld.sc_dv,
287 1.13 mlelstv "blkno 0x%" PRIu64 " exceeds capacity %d\n",
288 1.13 mlelstv bp->b_rawblkno, sc->sc_sf->csd.capacity);
289 1.13 mlelstv bp->b_error = EINVAL;
290 1.1 nonaka bp->b_resid = bp->b_bcount;
291 1.14.2.5 skrll
292 1.14.2.5 skrll goto done;
293 1.1 nonaka }
294 1.1 nonaka
295 1.1 nonaka if (bp->b_flags & B_READ)
296 1.1 nonaka error = sdmmc_mem_read_block(sc->sc_sf, bp->b_rawblkno,
297 1.1 nonaka bp->b_data, bp->b_bcount);
298 1.1 nonaka else
299 1.1 nonaka error = sdmmc_mem_write_block(sc->sc_sf, bp->b_rawblkno,
300 1.1 nonaka bp->b_data, bp->b_bcount);
301 1.1 nonaka if (error) {
302 1.14.2.4 skrll if (task->task_retries < LD_SDMMC_IORETRIES) {
303 1.14.2.4 skrll struct dk_softc *dksc = &sc->sc_ld.sc_dksc;
304 1.14.2.4 skrll struct cfdriver *cd = device_cfdriver(dksc->sc_dev);
305 1.14.2.4 skrll
306 1.14.2.4 skrll diskerr(bp, cd->cd_name, "error", LOG_PRINTF, 0,
307 1.14.2.4 skrll dksc->sc_dkdev.dk_label);
308 1.14.2.4 skrll printf(", retrying\n");
309 1.14.2.4 skrll task->task_retries++;
310 1.14.2.4 skrll callout_reset(&task->task_restart_ch, RECOVERYTIME,
311 1.14.2.4 skrll ld_sdmmc_restart, task);
312 1.14.2.4 skrll return;
313 1.14.2.4 skrll }
314 1.13 mlelstv bp->b_error = error;
315 1.1 nonaka bp->b_resid = bp->b_bcount;
316 1.1 nonaka } else {
317 1.1 nonaka bp->b_resid = 0;
318 1.1 nonaka }
319 1.1 nonaka
320 1.14.2.5 skrll done:
321 1.14.2.5 skrll pcq_put(sc->sc_freeq, task);
322 1.14.2.4 skrll
323 1.1 nonaka lddone(&sc->sc_ld, bp);
324 1.1 nonaka }
325 1.1 nonaka
326 1.1 nonaka static int
327 1.1 nonaka ld_sdmmc_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
328 1.1 nonaka {
329 1.1 nonaka struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
330 1.1 nonaka
331 1.1 nonaka return sdmmc_mem_write_block(sc->sc_sf, blkno, data,
332 1.1 nonaka blkcnt * ld->sc_secsize);
333 1.1 nonaka }
334 1.14.2.3 skrll
335 1.14.2.5 skrll static void
336 1.14.2.5 skrll ld_sdmmc_dodiscard(void *arg)
337 1.14.2.5 skrll {
338 1.14.2.5 skrll struct ld_sdmmc_task *task = arg;
339 1.14.2.5 skrll struct ld_sdmmc_softc *sc = task->task_sc;
340 1.14.2.5 skrll struct buf *bp = task->task_bp;
341 1.14.2.5 skrll uint32_t sblkno, nblks;
342 1.14.2.5 skrll int error;
343 1.14.2.5 skrll
344 1.14.2.5 skrll /* first and last block to erase */
345 1.14.2.5 skrll sblkno = bp->b_rawblkno;
346 1.14.2.5 skrll nblks = howmany(bp->b_bcount, sc->sc_ld.sc_secsize);
347 1.14.2.5 skrll
348 1.14.2.5 skrll /* An error from discard is non-fatal */
349 1.14.2.5 skrll error = sdmmc_mem_discard(sc->sc_sf, sblkno, sblkno + nblks - 1);
350 1.14.2.5 skrll if (error != 0)
351 1.14.2.5 skrll sc->sc_ev_discarderr.ev_count++;
352 1.14.2.5 skrll else
353 1.14.2.5 skrll sc->sc_ev_discard.ev_count++;
354 1.14.2.5 skrll pcq_put(sc->sc_freeq, task);
355 1.14.2.5 skrll
356 1.14.2.5 skrll if (error)
357 1.14.2.5 skrll bp->b_error = error;
358 1.14.2.5 skrll
359 1.14.2.5 skrll lddiscardend(&sc->sc_ld, bp);
360 1.14.2.5 skrll }
361 1.14.2.5 skrll
362 1.14.2.5 skrll static int
363 1.14.2.5 skrll ld_sdmmc_discard(struct ld_softc *ld, struct buf *bp)
364 1.14.2.5 skrll {
365 1.14.2.5 skrll struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
366 1.14.2.5 skrll struct ld_sdmmc_task *task = pcq_get(sc->sc_freeq);
367 1.14.2.5 skrll
368 1.14.2.5 skrll if (task == NULL) {
369 1.14.2.5 skrll sc->sc_ev_discardbusy.ev_count++;
370 1.14.2.5 skrll return 0;
371 1.14.2.5 skrll }
372 1.14.2.5 skrll
373 1.14.2.5 skrll task->task_bp = bp;
374 1.14.2.5 skrll
375 1.14.2.5 skrll sdmmc_init_task(&task->task, ld_sdmmc_dodiscard, task);
376 1.14.2.5 skrll
377 1.14.2.5 skrll sdmmc_add_task(sc->sc_sf->sc, &task->task);
378 1.14.2.5 skrll
379 1.14.2.5 skrll return 0;
380 1.14.2.5 skrll }
381 1.14.2.5 skrll
382 1.14.2.5 skrll static int
383 1.14.2.5 skrll ld_sdmmc_ioctl(struct ld_softc *ld, u_long cmd, void *addr, int32_t flag,
384 1.14.2.5 skrll bool poll)
385 1.14.2.5 skrll {
386 1.14.2.5 skrll struct ld_sdmmc_softc *sc = device_private(ld->sc_dv);
387 1.14.2.5 skrll
388 1.14.2.5 skrll switch (cmd) {
389 1.14.2.5 skrll case DIOCCACHESYNC:
390 1.14.2.5 skrll return sdmmc_mem_flush_cache(sc->sc_sf, poll);
391 1.14.2.5 skrll default:
392 1.14.2.5 skrll return EPASSTHROUGH;
393 1.14.2.5 skrll }
394 1.14.2.5 skrll }
395 1.14.2.5 skrll
396 1.14.2.3 skrll MODULE(MODULE_CLASS_DRIVER, ld_sdmmc, "ld");
397 1.14.2.3 skrll
398 1.14.2.3 skrll #ifdef _MODULE
399 1.14.2.3 skrll /*
400 1.14.2.3 skrll * XXX Don't allow ioconf.c to redefine the "struct cfdriver ld_cd"
401 1.14.2.3 skrll * XXX it will be defined in the common-code module
402 1.14.2.3 skrll */
403 1.14.2.3 skrll #undef CFDRIVER_DECL
404 1.14.2.3 skrll #define CFDRIVER_DECL(name, class, attr)
405 1.14.2.3 skrll #include "ioconf.c"
406 1.14.2.3 skrll #endif
407 1.14.2.3 skrll
408 1.14.2.3 skrll static int
409 1.14.2.3 skrll ld_sdmmc_modcmd(modcmd_t cmd, void *opaque)
410 1.14.2.3 skrll {
411 1.14.2.3 skrll #ifdef _MODULE
412 1.14.2.3 skrll /*
413 1.14.2.3 skrll * We ignore the cfdriver_vec[] that ioconf provides, since
414 1.14.2.3 skrll * the cfdrivers are attached already.
415 1.14.2.3 skrll */
416 1.14.2.3 skrll static struct cfdriver * const no_cfdriver_vec[] = { NULL };
417 1.14.2.3 skrll #endif
418 1.14.2.3 skrll int error = 0;
419 1.14.2.3 skrll
420 1.14.2.3 skrll #ifdef _MODULE
421 1.14.2.3 skrll switch (cmd) {
422 1.14.2.3 skrll case MODULE_CMD_INIT:
423 1.14.2.3 skrll error = config_init_component(no_cfdriver_vec,
424 1.14.2.3 skrll cfattach_ioconf_ld_sdmmc, cfdata_ioconf_ld_sdmmc);
425 1.14.2.3 skrll break;
426 1.14.2.3 skrll case MODULE_CMD_FINI:
427 1.14.2.3 skrll error = config_fini_component(no_cfdriver_vec,
428 1.14.2.3 skrll cfattach_ioconf_ld_sdmmc, cfdata_ioconf_ld_sdmmc);
429 1.14.2.3 skrll break;
430 1.14.2.3 skrll default:
431 1.14.2.3 skrll error = ENOTTY;
432 1.14.2.3 skrll break;
433 1.14.2.3 skrll }
434 1.14.2.3 skrll #endif
435 1.14.2.3 skrll
436 1.14.2.3 skrll return error;
437 1.14.2.3 skrll }
438