Преглед на файлове

[nvs] Allow for non-volatile storage devices without block boundaries

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown преди 14 години
родител
ревизия
8f8b55f187
променени са 2 файла, в които са добавени 32 реда и са изтрити 17 реда
  1. 32
    16
      src/drivers/nvs/nvs.c
  2. 0
    1
      src/drivers/nvs/nvsvpd.c

+ 32
- 16
src/drivers/nvs/nvs.c Целия файл

@@ -30,6 +30,34 @@ FILE_LICENCE ( GPL2_OR_LATER );
30 30
  *
31 31
  */
32 32
 
33
+/**
34
+ * Calculate length up to next block boundary
35
+ *
36
+ * @v nvs		NVS device
37
+ * @v address		Starting address
38
+ * @v max_len		Maximum length
39
+ * @ret len		Length to use, stopping at block boundaries
40
+ */
41
+static size_t nvs_frag_len ( struct nvs_device *nvs, unsigned int address,
42
+			     size_t max_len ) {
43
+	size_t frag_len;
44
+
45
+	/* If there are no block boundaries, return the maximum length */
46
+	if ( ! nvs->block_size )
47
+		return max_len;
48
+
49
+	/* Calculate space remaining up to next block boundary */
50
+	frag_len = ( ( nvs->block_size -
51
+		       ( address & ( nvs->block_size - 1 ) ) )
52
+		     << nvs->word_len_log2 );
53
+
54
+	/* Limit to maximum length */
55
+	if ( max_len < frag_len )
56
+		return max_len;
57
+
58
+	return frag_len;
59
+}
60
+
33 61
 /**
34 62
  * Read from non-volatile storage device
35 63
  *
@@ -51,14 +79,8 @@ int nvs_read ( struct nvs_device *nvs, unsigned int address,
51 79
 
52 80
 	while ( len ) {
53 81
 
54
-		/* Calculate space remaining up to next block boundary */
55
-		frag_len = ( ( nvs->block_size -
56
-			       ( address & ( nvs->block_size - 1 ) ) )
57
-			     << nvs->word_len_log2 );
58
-
59
-		/* Limit to space remaining in buffer */
60
-		if ( frag_len > len )
61
-			frag_len = len;
82
+		/* Calculate length to read, stopping at block boundaries */
83
+		frag_len = nvs_frag_len ( nvs, address, len );
62 84
 
63 85
 		/* Read this portion of the buffer from the device */
64 86
 		if ( ( rc = nvs->read ( nvs, address, data, frag_len ) ) != 0 )
@@ -122,14 +144,8 @@ int nvs_write ( struct nvs_device *nvs, unsigned int address,
122 144
 
123 145
 	while ( len ) {
124 146
 
125
-		/* Calculate space remaining up to next block boundary */
126
-		frag_len = ( ( nvs->block_size -
127
-			       ( address & ( nvs->block_size - 1 ) ) )
128
-			     << nvs->word_len_log2 );
129
-
130
-		/* Limit to space remaining in buffer */
131
-		if ( frag_len > len )
132
-			frag_len = len;
147
+		/* Calculate length to write, stopping at block boundaries */
148
+		frag_len = nvs_frag_len ( nvs, address, len );
133 149
 
134 150
 		/* Write this portion of the buffer to the device */
135 151
 		if ( ( rc = nvs->write ( nvs, address, data, frag_len ) ) != 0)

+ 0
- 1
src/drivers/nvs/nvsvpd.c Целия файл

@@ -111,7 +111,6 @@ int nvs_vpd_init ( struct nvs_vpd_device *nvsvpd, struct pci_device *pci,
111 111
 	}
112 112
 
113 113
 	/* Initialise NVS device */
114
-	nvsvpd->nvs.block_size = 1;
115 114
 	nvsvpd->nvs.size = len;
116 115
 	nvsvpd->nvs.read = nvs_vpd_read;
117 116
 	nvsvpd->nvs.write = nvs_vpd_write;

Loading…
Отказ
Запис