| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ld_virtio.c,v 1.17 2018/06/03 02:13:09 jakllsch Exp $ */ | | 1 | /* $NetBSD: ld_virtio.c,v 1.18 2018/06/03 19:47:35 jakllsch 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.17 2018/06/03 02:13:09 jakllsch Exp $"); | | 29 | __KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.18 2018/06/03 19:47:35 jakllsch Exp $"); |
30 | | | 30 | |
31 | #include <sys/param.h> | | 31 | #include <sys/param.h> |
32 | #include <sys/systm.h> | | 32 | #include <sys/systm.h> |
33 | #include <sys/kernel.h> | | 33 | #include <sys/kernel.h> |
34 | #include <sys/buf.h> | | 34 | #include <sys/buf.h> |
35 | #include <sys/bufq.h> | | 35 | #include <sys/bufq.h> |
36 | #include <sys/bus.h> | | 36 | #include <sys/bus.h> |
37 | #include <sys/device.h> | | 37 | #include <sys/device.h> |
38 | #include <sys/disk.h> | | 38 | #include <sys/disk.h> |
39 | #include <sys/mutex.h> | | 39 | #include <sys/mutex.h> |
40 | #include <sys/module.h> | | 40 | #include <sys/module.h> |
41 | | | 41 | |
42 | #include <dev/pci/pcidevs.h> | | 42 | #include <dev/pci/pcidevs.h> |
| @@ -50,62 +50,69 @@ __KERNEL_RCSID(0, "$NetBSD: ld_virtio.c, | | | @@ -50,62 +50,69 @@ __KERNEL_RCSID(0, "$NetBSD: ld_virtio.c, |
50 | #include "ioconf.h" | | 50 | #include "ioconf.h" |
51 | | | 51 | |
52 | /* | | 52 | /* |
53 | * ld_virtioreg: | | 53 | * ld_virtioreg: |
54 | */ | | 54 | */ |
55 | /* Configuration registers */ | | 55 | /* Configuration registers */ |
56 | #define VIRTIO_BLK_CONFIG_CAPACITY 0 /* 64bit */ | | 56 | #define VIRTIO_BLK_CONFIG_CAPACITY 0 /* 64bit */ |
57 | #define VIRTIO_BLK_CONFIG_SIZE_MAX 8 /* 32bit */ | | 57 | #define VIRTIO_BLK_CONFIG_SIZE_MAX 8 /* 32bit */ |
58 | #define VIRTIO_BLK_CONFIG_SEG_MAX 12 /* 32bit */ | | 58 | #define VIRTIO_BLK_CONFIG_SEG_MAX 12 /* 32bit */ |
59 | #define VIRTIO_BLK_CONFIG_GEOMETRY_C 16 /* 16bit */ | | 59 | #define VIRTIO_BLK_CONFIG_GEOMETRY_C 16 /* 16bit */ |
60 | #define VIRTIO_BLK_CONFIG_GEOMETRY_H 18 /* 8bit */ | | 60 | #define VIRTIO_BLK_CONFIG_GEOMETRY_H 18 /* 8bit */ |
61 | #define VIRTIO_BLK_CONFIG_GEOMETRY_S 19 /* 8bit */ | | 61 | #define VIRTIO_BLK_CONFIG_GEOMETRY_S 19 /* 8bit */ |
62 | #define VIRTIO_BLK_CONFIG_BLK_SIZE 20 /* 32bit */ | | 62 | #define VIRTIO_BLK_CONFIG_BLK_SIZE 20 /* 32bit */ |
| | | 63 | #define VIRTIO_BLK_CONFIG_WRITEBACK 32 /* 8bit */ |
63 | | | 64 | |
64 | /* Feature bits */ | | 65 | /* Feature bits */ |
65 | #define VIRTIO_BLK_F_BARRIER (1<<0) | | 66 | #define VIRTIO_BLK_F_BARRIER (1<<0) |
66 | #define VIRTIO_BLK_F_SIZE_MAX (1<<1) | | 67 | #define VIRTIO_BLK_F_SIZE_MAX (1<<1) |
67 | #define VIRTIO_BLK_F_SEG_MAX (1<<2) | | 68 | #define VIRTIO_BLK_F_SEG_MAX (1<<2) |
68 | #define VIRTIO_BLK_F_GEOMETRY (1<<4) | | 69 | #define VIRTIO_BLK_F_GEOMETRY (1<<4) |
69 | #define VIRTIO_BLK_F_RO (1<<5) | | 70 | #define VIRTIO_BLK_F_RO (1<<5) |
70 | #define VIRTIO_BLK_F_BLK_SIZE (1<<6) | | 71 | #define VIRTIO_BLK_F_BLK_SIZE (1<<6) |
71 | #define VIRTIO_BLK_F_SCSI (1<<7) | | 72 | #define VIRTIO_BLK_F_SCSI (1<<7) |
72 | #define VIRTIO_BLK_F_FLUSH (1<<9) | | 73 | #define VIRTIO_BLK_F_FLUSH (1<<9) |
| | | 74 | #define VIRTIO_BLK_F_TOPOLOGY (1<<10) |
| | | 75 | #define VIRTIO_BLK_F_CONFIG_WCE (1<<11) |
73 | | | 76 | |
74 | /* | | 77 | /* |
75 | * Each block request uses at least two segments - one for the header | | 78 | * Each block request uses at least two segments - one for the header |
76 | * and one for the status. | | 79 | * and one for the status. |
77 | */ | | 80 | */ |
78 | #define VIRTIO_BLK_MIN_SEGMENTS 2 | | 81 | #define VIRTIO_BLK_MIN_SEGMENTS 2 |
79 | | | 82 | |
80 | #define VIRTIO_BLK_FLAG_BITS \ | | 83 | #define VIRTIO_BLK_FLAG_BITS \ |
81 | VIRTIO_COMMON_FLAG_BITS \ | | 84 | VIRTIO_COMMON_FLAG_BITS \ |
| | | 85 | "\x0c""CONFIG_WCE" \ |
| | | 86 | "\x0b""TOPOLOGY" \ |
82 | "\x0a""FLUSH" \ | | 87 | "\x0a""FLUSH" \ |
83 | "\x08""SCSI" \ | | 88 | "\x08""SCSI" \ |
84 | "\x07""BLK_SIZE" \ | | 89 | "\x07""BLK_SIZE" \ |
85 | "\x06""RO" \ | | 90 | "\x06""RO" \ |
86 | "\x05""GEOMETRY" \ | | 91 | "\x05""GEOMETRY" \ |
87 | "\x03""SEG_MAX" \ | | 92 | "\x03""SEG_MAX" \ |
88 | "\x02""SIZE_MAX" \ | | 93 | "\x02""SIZE_MAX" \ |
89 | "\x01""BARRIER" | | 94 | "\x01""BARRIER" |
90 | | | 95 | |
91 | /* Command */ | | 96 | /* Command */ |
92 | #define VIRTIO_BLK_T_IN 0 | | 97 | #define VIRTIO_BLK_T_IN 0 |
93 | #define VIRTIO_BLK_T_OUT 1 | | 98 | #define VIRTIO_BLK_T_OUT 1 |
| | | 99 | #define VIRTIO_BLK_T_FLUSH 4 |
94 | #define VIRTIO_BLK_T_BARRIER 0x80000000 | | 100 | #define VIRTIO_BLK_T_BARRIER 0x80000000 |
95 | | | 101 | |
96 | /* Status */ | | 102 | /* Status */ |
97 | #define VIRTIO_BLK_S_OK 0 | | 103 | #define VIRTIO_BLK_S_OK 0 |
98 | #define VIRTIO_BLK_S_IOERR 1 | | 104 | #define VIRTIO_BLK_S_IOERR 1 |
| | | 105 | #define VIRTIO_BLK_S_UNSUPP 2 |
99 | | | 106 | |
100 | /* Request header structure */ | | 107 | /* Request header structure */ |
101 | struct virtio_blk_req_hdr { | | 108 | struct virtio_blk_req_hdr { |
102 | uint32_t type; /* VIRTIO_BLK_T_* */ | | 109 | uint32_t type; /* VIRTIO_BLK_T_* */ |
103 | uint32_t ioprio; | | 110 | uint32_t ioprio; |
104 | uint64_t sector; | | 111 | uint64_t sector; |
105 | } __packed; | | 112 | } __packed; |
106 | /* 512*virtio_blk_req_hdr.sector byte payload and 1 byte status follows */ | | 113 | /* 512*virtio_blk_req_hdr.sector byte payload and 1 byte status follows */ |
107 | | | 114 | |
108 | | | 115 | |
109 | /* | | 116 | /* |
110 | * ld_virtiovar: | | 117 | * ld_virtiovar: |
111 | */ | | 118 | */ |