Correcting debconf field name for extlinux installation (Closes: #746785).
[syslinux-debian/hramrach.git] / efi / diskio.c
blob01ab2a0e5cb7b89d9fe97d1ffda582e076b04f7e
1 #include <fs.h>
2 #include <ilog2.h>
3 #include <disk.h>
4 #include <dprintf.h>
5 #include "efi.h"
7 static inline EFI_STATUS read_blocks(EFI_BLOCK_IO *bio, uint32_t id,
8 sector_t lba, UINTN bytes, void *buf)
10 return uefi_call_wrapper(bio->ReadBlocks, 5, bio, id, lba, bytes, buf);
13 static inline EFI_STATUS write_blocks(EFI_BLOCK_IO *bio, uint32_t id,
14 sector_t lba, UINTN bytes, void *buf)
16 return uefi_call_wrapper(bio->WriteBlocks, 5, bio, id, lba, bytes, buf);
19 static int efi_rdwr_sectors(struct disk *disk, void *buf,
20 sector_t lba, size_t count, bool is_write)
22 struct efi_disk_private *priv = (struct efi_disk_private *)disk->private;
23 EFI_BLOCK_IO *bio = priv->bio;
24 EFI_STATUS status;
25 UINTN bytes = count * disk->sector_size;
27 if (is_write)
28 status = write_blocks(bio, disk->disk_number, lba, bytes, buf);
29 else
30 status = read_blocks(bio, disk->disk_number, lba, bytes, buf);
32 if (status != EFI_SUCCESS)
33 Print(L"Failed to %s blocks: 0x%x\n",
34 is_write ? L"write" : L"read",
35 status);
37 return count << disk->sector_shift;
40 struct disk *efi_disk_init(void *private)
42 static struct disk disk;
43 struct efi_disk_private *priv = (struct efi_disk_private *)private;
44 EFI_HANDLE handle = priv->dev_handle;
45 EFI_BLOCK_IO *bio;
46 EFI_DISK_IO *dio;
47 EFI_STATUS status;
49 status = uefi_call_wrapper(BS->HandleProtocol, 3, handle,
50 &DiskIoProtocol, (void **)&dio);
51 if (status != EFI_SUCCESS)
52 return NULL;
54 status = uefi_call_wrapper(BS->HandleProtocol, 3, handle,
55 &BlockIoProtocol, (void **)&bio);
56 if (status != EFI_SUCCESS)
57 return NULL;
60 * XXX Do we need to map this to a BIOS disk number?
62 disk.disk_number = bio->Media->MediaId;
64 disk.sector_size = bio->Media->BlockSize;
65 disk.rdwr_sectors = efi_rdwr_sectors;
66 disk.sector_shift = ilog2(disk.sector_size);
68 dprintf("sector_size=%d, disk_number=%d\n", disk.sector_size,
69 disk.disk_number);
71 priv->bio = bio;
72 priv->dio = dio;
73 disk.private = private;
74 #if 0
76 disk.part_start = part_start;
77 disk.secpercyl = disk.h * disk.s;
80 disk.maxtransfer = MaxTransfer;
82 dprintf("disk %02x cdrom %d type %d sector %u/%u offset %llu limit %u\n",
83 media_id, cdrom, ebios, sector_size, disk.sector_shift,
84 part_start, disk.maxtransfer);
85 #endif
87 return &disk;