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
;
25 UINTN bytes
= count
* disk
->sector_size
;
28 status
= write_blocks(bio
, disk
->disk_number
, lba
, bytes
, buf
);
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",
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
;
49 status
= uefi_call_wrapper(BS
->HandleProtocol
, 3, handle
,
50 &DiskIoProtocol
, (void **)&dio
);
51 if (status
!= EFI_SUCCESS
)
54 status
= uefi_call_wrapper(BS
->HandleProtocol
, 3, handle
,
55 &BlockIoProtocol
, (void **)&bio
);
56 if (status
!= EFI_SUCCESS
)
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
,
73 disk
.private = private;
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
);