| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ld_virtio.c,v 1.3 2011/11/23 19:40:42 hannken Exp $ */ | | 1 | /* $NetBSD: ld_virtio.c,v 1.4 2011/12/03 10:53:09 hannken Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2010 Minoura Makoto. | | 4 | * Copyright (c) 2010 Minoura Makoto. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -16,27 +16,27 @@ | | | @@ -16,27 +16,27 @@ |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/cdefs.h> | | 28 | #include <sys/cdefs.h> |
29 | __KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.3 2011/11/23 19:40:42 hannken Exp $"); | | 29 | __KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.4 2011/12/03 10:53:09 hannken Exp $"); |
30 | | | 30 | |
31 | #include "rnd.h" | | 31 | #include "rnd.h" |
32 | | | 32 | |
33 | #include <sys/param.h> | | 33 | #include <sys/param.h> |
34 | #include <sys/systm.h> | | 34 | #include <sys/systm.h> |
35 | #include <sys/kernel.h> | | 35 | #include <sys/kernel.h> |
36 | #include <sys/buf.h> | | 36 | #include <sys/buf.h> |
37 | #include <sys/bus.h> | | 37 | #include <sys/bus.h> |
38 | #include <sys/device.h> | | 38 | #include <sys/device.h> |
39 | #include <sys/disk.h> | | 39 | #include <sys/disk.h> |
40 | #include <sys/mutex.h> | | 40 | #include <sys/mutex.h> |
41 | #if NRND > 0 | | 41 | #if NRND > 0 |
42 | #include <sys/rnd.h> | | 42 | #include <sys/rnd.h> |
| @@ -262,33 +262,35 @@ ld_virtio_attach(device_t parent, device | | | @@ -262,33 +262,35 @@ ld_virtio_attach(device_t parent, device |
262 | VIRTIO_BLK_F_RO | | | 262 | VIRTIO_BLK_F_RO | |
263 | VIRTIO_BLK_F_BLK_SIZE)); | | 263 | VIRTIO_BLK_F_BLK_SIZE)); |
264 | if (features & VIRTIO_BLK_F_RO) | | 264 | if (features & VIRTIO_BLK_F_RO) |
265 | sc->sc_readonly = 1; | | 265 | sc->sc_readonly = 1; |
266 | else | | 266 | else |
267 | sc->sc_readonly = 0; | | 267 | sc->sc_readonly = 0; |
268 | | | 268 | |
269 | ld->sc_secsize = 512; | | 269 | ld->sc_secsize = 512; |
270 | if (features & VIRTIO_BLK_F_BLK_SIZE) { | | 270 | if (features & VIRTIO_BLK_F_BLK_SIZE) { |
271 | ld->sc_secsize = virtio_read_device_config_4(vsc, | | 271 | ld->sc_secsize = virtio_read_device_config_4(vsc, |
272 | VIRTIO_BLK_CONFIG_BLK_SIZE); | | 272 | VIRTIO_BLK_CONFIG_BLK_SIZE); |
273 | } | | 273 | } |
274 | maxxfersize = MAXPHYS; | | 274 | maxxfersize = MAXPHYS; |
| | | 275 | #if 0 /* At least genfs_io assumes maxxfer == MAXPHYS. */ |
275 | if (features & VIRTIO_BLK_F_SEG_MAX) { | | 276 | if (features & VIRTIO_BLK_F_SEG_MAX) { |
276 | maxxfersize = virtio_read_device_config_4(vsc, | | 277 | maxxfersize = virtio_read_device_config_4(vsc, |
277 | VIRTIO_BLK_CONFIG_SEG_MAX) | | 278 | VIRTIO_BLK_CONFIG_SEG_MAX) |
278 | * ld->sc_secsize; | | 279 | * ld->sc_secsize; |
279 | if (maxxfersize > MAXPHYS) | | 280 | if (maxxfersize > MAXPHYS) |
280 | maxxfersize = MAXPHYS; | | 281 | maxxfersize = MAXPHYS; |
281 | } | | 282 | } |
| | | 283 | #endif |
282 | | | 284 | |
283 | if (virtio_alloc_vq(vsc, &sc->sc_vq[0], 0, | | 285 | if (virtio_alloc_vq(vsc, &sc->sc_vq[0], 0, |
284 | maxxfersize, maxxfersize / NBPG + 2, | | 286 | maxxfersize, maxxfersize / NBPG + 2, |
285 | "I/O request") != 0) { | | 287 | "I/O request") != 0) { |
286 | goto err; | | 288 | goto err; |
287 | } | | 289 | } |
288 | qsize = sc->sc_vq[0].vq_num; | | 290 | qsize = sc->sc_vq[0].vq_num; |
289 | sc->sc_vq[0].vq_done = ld_virtio_vq_done; | | 291 | sc->sc_vq[0].vq_done = ld_virtio_vq_done; |
290 | | | 292 | |
291 | ld->sc_dv = self; | | 293 | ld->sc_dv = self; |
292 | ld->sc_secperunit = virtio_read_device_config_8(vsc, | | 294 | ld->sc_secperunit = virtio_read_device_config_8(vsc, |
293 | VIRTIO_BLK_CONFIG_CAPACITY); | | 295 | VIRTIO_BLK_CONFIG_CAPACITY); |
294 | ld->sc_maxxfer = maxxfersize; | | 296 | ld->sc_maxxfer = maxxfersize; |