This patch unifies the use of config options in v2 to all start with CONFIG_
[coreboot.git] / src / stream / ide_stream.c
1 #include <console/console.h>
2 #include <stdlib.h>
3 #include <stddef.h>
4 #include <stream/read_bytes.h>
5 #include <delay.h>
6 #include <string.h>
7 #include <pc80/ide.h>
8
9 #ifndef CONFIG_IDE_BOOT_DRIVE
10 #define CONFIG_IDE_BOOT_DRIVE 0
11 #endif
12
13 static unsigned long offset;
14
15 int stream_init(void)
16 {
17         int i,res;
18
19         printk_debug ("Trying polled ide\n");
20         printk_debug ("Waiting for ide disks to spin up\n");
21         printk_notice ("This is a hard coded delay and longer than necessary.\n");
22         for (i = 0; i < 2; i++) {
23                 printk_notice (".");
24                 delay(1);
25         }
26         printk_info ("\n");
27
28 #ifdef ONE_TRACK
29         offset = (ONE_TRACK*512);
30 #elif defined(CONFIG_IDE_OFFSET)
31         offset = CONFIG_IDE_OFFSET;
32 #else
33         offset = 0x7e00;
34 #endif
35         res = ide_probe(CONFIG_IDE_BOOT_DRIVE);
36         delay(1);
37         return res;
38 }
39
40 void stream_fini(void)
41 {
42         return;
43 }
44
45 static unsigned char buffer[512];
46 static unsigned int block_num = 0;
47 static unsigned int first_fill = 1;
48
49 static byte_offset_t stream_ide_read(void *vdest, byte_offset_t offs, byte_offset_t count)
50 {
51         byte_offset_t bytes = 0;
52         unsigned char *dest = vdest;
53
54         //printk_debug("stream_ide_read count = %x\n", count);
55         while (bytes < count) {
56                 unsigned int byte_offset, len;
57
58                 /* The block is not cached in memory or frist time called */
59                 if (block_num != offs / 512 || first_fill) {
60                         block_num  = offs / 512;
61                         printk_notice (".");
62                         ide_read(CONFIG_IDE_BOOT_DRIVE, block_num, buffer);
63                         first_fill = 0;
64                 }
65
66                 byte_offset = offs % 512;
67                 len = 512 - byte_offset;
68                 if (len > (count - bytes)) {
69                         len = (count - bytes);
70                 }
71
72                 memcpy(dest, buffer + byte_offset, len);
73
74                 offs += len;
75                 bytes += len;
76                 dest += len;
77
78         }
79         return bytes;
80 }
81
82 byte_offset_t stream_read(void *vdest, byte_offset_t count)
83 {
84         byte_offset_t len;
85
86         len = stream_ide_read(vdest, offset, count);
87         if (len > 0) {
88                 offset += len;
89         }
90
91         return len;
92 }
93
94 byte_offset_t stream_skip(byte_offset_t count)
95 {
96         offset += count;
97         return count;
98 }