Explorar el Código

Added the generic block-splitting code to nvs.c

tags/v0.9.3
Michael Brown hace 17 años
padre
commit
2d8d21fe74
Se han modificado 4 ficheros con 49 adiciones y 25 borrados
  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 Ver fichero

265
 	rtl->eeprom.bus = &rtl->spibit.bus;
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
  * Reset NIC
269
  * Reset NIC
290
  *
270
  *
531
 	/* Reset the NIC, set up EEPROM access and read MAC address */
511
 	/* Reset the NIC, set up EEPROM access and read MAC address */
532
 	rtl_reset ( rtl );
512
 	rtl_reset ( rtl );
533
 	rtl_init_eeprom ( rtl );
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
 	/* Point to NIC specific routines */
516
 	/* Point to NIC specific routines */
537
 	//	netdev->open	 = rtl_open;
517
 	//	netdev->open	 = rtl_open;

+ 40
- 1
src/drivers/nvs/nvs.c Ver fichero

17
  */
17
  */
18
 
18
 
19
 #include <stdint.h>
19
 #include <stdint.h>
20
+#include <assert.h>
20
 #include <gpxe/nvs.h>
21
 #include <gpxe/nvs.h>
21
 
22
 
22
 /** @file
23
 /** @file
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
 int nvs_read ( struct nvs_device *nvs, unsigned int address,
38
 int nvs_read ( struct nvs_device *nvs, unsigned int address,
29
 	       void *data, size_t len ) {
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 Ver fichero

11
 
11
 
12
 /** A non-volatile storage device */
12
 /** A non-volatile storage device */
13
 struct nvs_device {
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
 	/** Device size (in words) */
21
 	/** Device size (in words) */
17
 	unsigned int size;
22
 	unsigned int size;
18
 	/** Data block size (in words)
23
 	/** Data block size (in words)

+ 1
- 1
src/include/gpxe/threewire.h Ver fichero

32
 
32
 
33
 static inline __attribute__ (( always_inline )) void
33
 static inline __attribute__ (( always_inline )) void
34
 init_at93cx6 ( struct spi_device *device, unsigned int organisation ) {
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
 	device->nvs.block_size = 1;
36
 	device->nvs.block_size = 1;
37
 	device->command_len = 3,
37
 	device->command_len = 3,
38
 	device->nvs.read = threewire_read;
38
 	device->nvs.read = threewire_read;

Loading…
Cancelar
Guardar