1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
9 * ----------------------------------------------------------------------- */
12 * arch/i386/boot/edd.c
14 * Get EDD BIOS disk information
18 #include <linux/edd.h>
20 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
23 * Read the MBR (first sector) from a specific device.
25 static int read_mbr(u8 devno, void *buf)
29 ax = 0x0201; /* Legacy Read, one sector */
30 cx = 0x0001; /* Sector 0-0-1 */
33 asm volatile("pushfl; stc; int $0x13; setc %%al; popfl"
34 : "+a" (ax), "+c" (cx), "+d" (dx), "+b" (bx)
35 : : "esi", "edi", "memory");
37 return -(u8)ax; /* 0 or -1 */
40 static u32 read_mbr_sig(u8 devno, struct edd_info *ei, u32 *mbrsig)
43 char *mbrbuf_ptr, *mbrbuf_end;
44 u32 buf_base, mbr_base;
47 sector_size = ei->params.bytes_per_sector;
49 sector_size = 512; /* Best available guess */
51 /* Produce a naturally aligned buffer on the heap */
52 buf_base = (ds() << 4) + (u32)&_end;
53 mbr_base = (buf_base+sector_size-1) & ~(sector_size-1);
54 mbrbuf_ptr = _end + (mbr_base-buf_base);
55 mbrbuf_end = mbrbuf_ptr + sector_size;
57 /* Make sure we actually have space on the heap... */
58 if (!(boot_params.hdr.loadflags & CAN_USE_HEAP))
60 if (mbrbuf_end > (char *)(size_t)boot_params.hdr.heap_end_ptr)
63 if (read_mbr(devno, mbrbuf_ptr))
66 *mbrsig = *(u32 *)&mbrbuf_ptr[EDD_MBR_SIG_OFFSET];
70 static int get_edd_info(u8 devno, struct edd_info *ei)
72 u16 ax, bx, cx, dx, di;
74 memset(ei, 0, sizeof *ei);
76 /* Check Extensions Present */
81 asm("pushfl; stc; int $0x13; setc %%al; popfl"
82 : "+a" (ax), "+b" (bx), "=c" (cx), "+d" (dx)
86 return -1; /* No extended information */
92 ei->version = ax >> 8; /* EDD version number */
93 ei->interface_support = cx; /* EDD functionality subsets */
95 /* Extended Get Device Parameters */
97 ei->params.length = sizeof(ei->params);
100 asm("pushfl; int $0x13; popfl"
101 : "+a" (ax), "+d" (dx), "=m" (ei->params)
103 : "ebx", "ecx", "edi");
105 /* Get legacy CHS parameters */
107 /* Ralf Brown recommends setting ES:DI to 0:0 */
113 "pushfl; stc; int $0x13; setc %%al; popfl; "
115 : "+a" (ax), "=b" (bx), "=c" (cx), "+d" (dx), "+D" (di)
119 ei->legacy_max_cylinder = (cx >> 8) + ((cx & 0xc0) << 2);
120 ei->legacy_max_head = dx >> 8;
121 ei->legacy_sectors_per_track = cx & 0x3f;
134 struct edd_info ei, *edp;
137 if (cmdline_find_option("edd", eddarg, sizeof eddarg) > 0) {
138 if (!strcmp(eddarg, "skipmbr") || !strcmp(eddarg, "skip"))
140 else if (!strcmp(eddarg, "off"))
144 be_quiet = cmdline_find_option_bool("quiet");
146 edp = boot_params.eddbuf;
147 mbrptr = boot_params.edd_mbr_sig_buffer;
152 /* Bugs in OnBoard or AddOnCards Bios may hang the EDD probe,
153 * so give a hint if this happens.
157 printf("Probing EDD (edd=off to disable)... ");
159 for (devno = 0x80; devno < 0x80+EDD_MBR_SIG_MAX; devno++) {
161 * Scan the BIOS-supported hard disks and query EDD
164 get_edd_info(devno, &ei);
166 if (boot_params.eddbuf_entries < EDDMAXNR) {
167 memcpy(edp, &ei, sizeof ei);
169 boot_params.eddbuf_entries++;
172 if (do_mbr && !read_mbr_sig(devno, &ei, mbrptr++))
173 boot_params.edd_mbr_sig_buf_entries = devno-0x80+1;