Browse Source

Added the generic block-splitting code to nvs.c

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
2d8d21fe74
4 changed files with 49 additions and 25 deletions
  1. 1
    21
      src/drivers/net/rtl8139.c
  2. 40
    1
      src/drivers/nvs/nvs.c
  3. 7
    2
      src/include/gpxe/nvs.h
  4. 1
    1
      src/include/gpxe/threewire.h

+ 1
- 21
src/drivers/net/rtl8139.c View File

@@ -265,26 +265,6 @@ static struct bit_basher_operations rtl_basher_ops = {
265 265
 	rtl->eeprom.bus = &rtl->spibit.bus;
266 266
 }
267 267
 
268
-/**
269
- * Read the MAC address
270
- *
271
- * @v rtl		RTL8139 NIC
272
- * @v mac_addr		Buffer to contain MAC address (ETH_ALEN bytes)
273
- */
274
-static void rtl_read_mac ( struct rtl8139_nic *rtl, uint8_t *mac_addr ) {
275
-
276
-	struct nvs_device *nvs = &rtl->eeprom.nvs;
277
-	int i;
278
-	
279
-	DBG ( "MAC address is " );
280
-	for ( i = EE_MAC ; i < ( EE_MAC + ( ETH_ALEN / 2 ) ) ; i++ ) {
281
-		nvs_read ( nvs, i, mac_addr, 2 );
282
-		DBG ( "%02x%02x", mac_addr[0], mac_addr[1] );
283
-		mac_addr += 2;
284
-	}
285
-	DBG ( "\n" );
286
-}
287
-
288 268
 /**
289 269
  * Reset NIC
290 270
  *
@@ -531,7 +511,7 @@ static int rtl_probe ( struct pci_device *pci,
531 511
 	/* Reset the NIC, set up EEPROM access and read MAC address */
532 512
 	rtl_reset ( rtl );
533 513
 	rtl_init_eeprom ( rtl );
534
-	rtl_read_mac ( rtl, netdev->ll_addr );
514
+	nvs_read ( &rtl->eeprom.nvs, EE_MAC, netdev->ll_addr, ETH_ALEN );
535 515
 	
536 516
 	/* Point to NIC specific routines */
537 517
 	//	netdev->open	 = rtl_open;

+ 40
- 1
src/drivers/nvs/nvs.c View File

@@ -17,6 +17,7 @@
17 17
  */
18 18
 
19 19
 #include <stdint.h>
20
+#include <assert.h>
20 21
 #include <gpxe/nvs.h>
21 22
 
22 23
 /** @file
@@ -25,7 +26,45 @@
25 26
  *
26 27
  */
27 28
 
29
+/**
30
+ * Read from non-volatile storage device
31
+ *
32
+ * @v nvs		NVS device
33
+ * @v address		Address from which to read
34
+ * @v data		Data buffer
35
+ * @v len		Length of data buffer
36
+ * @ret rc		Return status code
37
+ */
28 38
 int nvs_read ( struct nvs_device *nvs, unsigned int address,
29 39
 	       void *data, size_t len ) {
30
-	return nvs->read ( nvs, address, data, len );
40
+	size_t frag_len;
41
+	int rc;
42
+
43
+	/* We don't even attempt to handle buffer lengths that aren't
44
+	 * an integral number of words.
45
+	 */
46
+	assert ( ( len & ( ( 1 << nvs->word_len_log2 ) - 1 ) ) == 0 );
47
+
48
+	while ( len ) {
49
+
50
+		/* Calculate space remaining up to next block boundary */
51
+		frag_len = ( ( nvs->block_size -
52
+			       ( address & ( nvs->block_size - 1 ) ) )
53
+			     << nvs->word_len_log2 );
54
+
55
+		/* Limit to space remaining in buffer */
56
+		if ( frag_len > len )
57
+			frag_len = len;
58
+
59
+		/* Read this portion of the buffer from the device */
60
+		if ( ( rc = nvs->read ( nvs, address, data, frag_len ) ) != 0 )
61
+			return rc;
62
+
63
+		/* Update parameters */
64
+		data += frag_len;
65
+		address += ( frag_len >> nvs->word_len_log2 );
66
+		len -= frag_len;
67
+	}
68
+
69
+	return 0;
31 70
 }

+ 7
- 2
src/include/gpxe/nvs.h View File

@@ -11,8 +11,13 @@
11 11
 
12 12
 /** A non-volatile storage device */
13 13
 struct nvs_device {
14
-	/** Word length, in bits */
15
-	unsigned int word_len;
14
+	/** Word length
15
+	 *
16
+	 * This is expressed as the base-2 logarithm of the word
17
+	 * length in bytes.  A value of 0 therefore translates as
18
+	 * 8-bit words, and a value of 1 translates as 16-bit words.
19
+	 */
20
+	unsigned int word_len_log2;
16 21
 	/** Device size (in words) */
17 22
 	unsigned int size;
18 23
 	/** Data block size (in words)

+ 1
- 1
src/include/gpxe/threewire.h View File

@@ -32,7 +32,7 @@ extern int threewire_read ( struct nvs_device *nvs, unsigned int address,
32 32
 
33 33
 static inline __attribute__ (( always_inline )) void
34 34
 init_at93cx6 ( struct spi_device *device, unsigned int organisation ) {
35
-	device->nvs.word_len = organisation;
35
+	device->nvs.word_len_log2 = ( ( organisation == 8 ) ? 0 : 1 );
36 36
 	device->nvs.block_size = 1;
37 37
 	device->command_len = 3,
38 38
 	device->nvs.read = threewire_read;

Loading…
Cancel
Save