removal of eficall.h files.
2) Allow booting from 4k-byte sector devices.
3) Don't leak memory after successfull i/o.
The end result is that riscv64 efidev.c and efipxe.c are identical to the
arm64/armv7 versions, efirng.c is identical to the amd64/arm64 versions and
efiboot.c has only the arm64 -> riscv64 changes.
ok kettenis@
-/* $OpenBSD: efiboot.c,v 1.1 2021/04/28 19:01:00 drahn Exp $ */
+/* $OpenBSD: efiboot.c,v 1.2 2021/06/25 17:49:49 krw Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
#include "efidev.h"
#include "efiboot.h"
-#include "eficall.h"
#include "fdt.h"
EFI_SYSTEM_TABLE *ST;
IH = image;
/* disable reset by watchdog after 5 minutes */
- EFI_CALL(BS->SetWatchdogTimer, 0, 0, 0, NULL);
+ BS->SetWatchdogTimer(0, 0, 0, NULL);
- status = EFI_CALL(BS->HandleProtocol, image, &imgp_guid,
+ status = BS->HandleProtocol(image, &imgp_guid,
(void **)&imgp);
if (status == EFI_SUCCESS)
- status = EFI_CALL(BS->HandleProtocol, imgp->DeviceHandle,
- &devp_guid, (void **)&dp);
+ status = BS->HandleProtocol(imgp->DeviceHandle, &devp_guid,
+ (void **)&dp);
if (status == EFI_SUCCESS)
efi_bootdp = dp;
{
EFI_STATUS status;
- status = EFI_CALL(BS->AllocatePages, AllocateAnyPages, EfiLoaderData,
+ status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
EFI_SIZE_TO_PAGES(heapsiz), &heap);
if (status != EFI_SUCCESS)
panic("BS->AllocatePages()");
TAILQ_INIT(&disklist);
sz = 0;
- status = EFI_CALL(BS->LocateHandle, ByProtocol, &blkio_guid, 0, &sz, 0);
+ status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz, 0);
if (status == EFI_BUFFER_TOO_SMALL) {
handles = alloc(sz);
- status = EFI_CALL(BS->LocateHandle, ByProtocol, &blkio_guid,
- 0, &sz, handles);
+ status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz,
+ handles);
}
if (handles == NULL || EFI_ERROR(status))
return;
depth = 1;
for (i = 0; i < sz / sizeof(EFI_HANDLE); i++) {
- status = EFI_CALL(BS->HandleProtocol, handles[i], &blkio_guid,
+ status = BS->HandleProtocol(handles[i], &blkio_guid,
(void **)&blkio);
if (EFI_ERROR(status))
panic("BS->HandleProtocol() returns %d", status);
if (efi_bootdp == NULL || depth == -1 || bootdev != 0)
goto next;
- status = EFI_CALL(BS->HandleProtocol, handles[i], &devp_guid,
+ status = BS->HandleProtocol(handles[i], &devp_guid,
(void **)&dp);
if (EFI_ERROR(status))
goto next;
}
}
- status = EFI_CALL(BS->LocateProtocol, &gop_guid, NULL, (void **)&gop);
+ status = BS->LocateProtocol(&gop_guid, NULL, (void **)&gop);
if (status != EFI_SUCCESS)
return;
for (retry = 1; retry >= 0; retry--) {
efi_memprobe_internal(); /* sync the current map */
efi_updatefdt();
- status = EFI_CALL(BS->ExitBootServices, IH, mmap_key);
+ status = BS->ExitBootServices(IH, mmap_key);
if (status == EFI_SUCCESS)
break;
if (retry == 0)
free(mmap, mmap_ndesc * mmap_descsiz);
siz = 0;
- status = EFI_CALL(BS->GetMemoryMap, &siz, NULL, &mapkey, &mmsiz,
- &mmver);
+ status = BS->GetMemoryMap(&siz, NULL, &mapkey, &mmsiz, &mmver);
if (status != EFI_BUFFER_TOO_SMALL)
panic("cannot get the size of memory map");
mm = alloc(siz);
- status = EFI_CALL(BS->GetMemoryMap, &siz, mm, &mapkey, &mmsiz, &mmver);
+ status = BS->GetMemoryMap(&siz, mm, &mapkey, &mmsiz, &mmver);
if (status != EFI_SUCCESS)
panic("cannot get the memory map");
n = siz / mmsiz;
if (paddr & (align - 1))
continue;
- if (EFI_CALL(BS->AllocatePages, AllocateAddress,
- EfiLoaderData, pages, &paddr) == EFI_SUCCESS) {
+ if (BS->AllocatePages(AllocateAddress, EfiLoaderData,
+ pages, &paddr) == EFI_SUCCESS) {
*addr = paddr;
return EFI_SUCCESS;
}
int
Xexit_efi(void)
{
- EFI_CALL(BS->Exit, IH, 0, 0, NULL);
+ BS->Exit(IH, 0, 0, NULL);
for (;;)
continue;
return (0);
int
Xpoweroff_efi(void)
{
- EFI_CALL(RS->ResetSystem, EfiResetShutdown, EFI_SUCCESS, 0, NULL);
+ RS->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
return (0);
}
-/* $OpenBSD: efidev.c,v 1.2 2021/06/02 22:44:27 krw Exp $ */
+/* $OpenBSD: efidev.c,v 1.3 2021/06/25 17:49:49 krw Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
#include "libsa.h"
#include <efi.h>
-#include "eficall.h"
extern EFI_BOOT_SERVICES *BS;
static EFI_STATUS
efid_io(int rw, efi_diskinfo_t ed, u_int off, int nsect, void *buf)
{
- EFI_STATUS status = EFI_SUCCESS;
+ u_int blks, start, end;
EFI_PHYSICAL_ADDRESS addr;
+ EFI_STATUS status;
caddr_t data;
+ size_t size;
- if (ed->blkio->Media->BlockSize != DEV_BSIZE)
+ /* block count of the intrinsic block size in DEV_BSIZE */
+ blks = EFI_BLKSPERSEC(ed);
+ if (blks == 0)
+ /* block size < 512. HP Stream 13 actually has such a disk. */
return (EFI_UNSUPPORTED);
+ start = off / blks;
+ end = (off + nsect + blks - 1) / blks;
+ size = (end - start) * ed->blkio->Media->BlockSize;
+
status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
- EFI_SIZE_TO_PAGES(nsect * DEV_BSIZE), &addr);
+ EFI_SIZE_TO_PAGES(size), &addr);
if (EFI_ERROR(status))
goto on_eio;
data = (caddr_t)(uintptr_t)addr;
switch (rw) {
case F_READ:
- status = EFI_CALL(ed->blkio->ReadBlocks,
- ed->blkio, ed->mediaid, off,
- nsect * DEV_BSIZE, data);
+ status = ed->blkio->ReadBlocks(ed->blkio, ed->mediaid, start,
+ size, data);
if (EFI_ERROR(status))
goto on_eio;
- memcpy(buf, data, nsect * DEV_BSIZE);
+ memcpy(buf, data + DEV_BSIZE * (off - start * blks),
+ DEV_BSIZE * nsect);
break;
case F_WRITE:
if (ed->blkio->Media->ReadOnly)
goto on_eio;
- memcpy(data, buf, nsect * DEV_BSIZE);
- status = EFI_CALL(ed->blkio->WriteBlocks,
- ed->blkio, ed->mediaid, off,
- nsect * DEV_BSIZE, data);
+ if (off % blks != 0 || nsect % blks != 0) {
+ status = ed->blkio->ReadBlocks(ed->blkio, ed->mediaid,
+ start, size, data);
+ if (EFI_ERROR(status))
+ goto on_eio;
+ }
+ memcpy(data + DEV_BSIZE * (off - start * blks), buf,
+ DEV_BSIZE * nsect);
+ status = ed->blkio->WriteBlocks(ed->blkio, ed->mediaid, start,
+ size, data);
if (EFI_ERROR(status))
goto on_eio;
break;
}
- return (EFI_SUCCESS);
on_eio:
- BS->FreePages(addr, EFI_SIZE_TO_PAGES(nsect * DEV_BSIZE));
+ BS->FreePages(addr, EFI_SIZE_TO_PAGES(size));
return (status);
}
-/* $OpenBSD: efipxe.c,v 1.1 2021/04/28 19:01:00 drahn Exp $ */
+/* $OpenBSD: efipxe.c,v 1.2 2021/06/25 17:49:49 krw Exp $ */
/*
* Copyright (c) 2017 Patrick Wildt <patrick@blueri.se>
*
#include <efi.h>
#include <efiapi.h>
-#include "eficall.h"
#include "efiboot.h"
#include "disk.h"
if (efi_bootdp == NULL)
return;
- status = EFI_CALL(BS->LocateHandleBuffer, ByProtocol, &pxe_guid, NULL,
+ status = BS->LocateHandleBuffer(ByProtocol, &pxe_guid, NULL,
&nhandles, &handles);
if (status != EFI_SUCCESS)
return;
for (i = 0; i < nhandles; i++) {
EFI_PXE_BASE_CODE_DHCPV4_PACKET *dhcp;
- status = EFI_CALL(BS->HandleProtocol, handles[i],
- &devp_guid, (void **)&dp0);
+ status = BS->HandleProtocol(handles[i], &devp_guid,
+ (void **)&dp0);
if (status != EFI_SUCCESS)
continue;
if (depth == -1 || efi_device_path_ncmp(efi_bootdp, dp0, depth))
continue;
- status = EFI_CALL(BS->HandleProtocol, handles[i], &net_guid,
+ status = BS->HandleProtocol(handles[i], &net_guid,
(void **)&net);
if (status != EFI_SUCCESS)
continue;
- status = EFI_CALL(BS->HandleProtocol, handles[i], &pxe_guid,
+ status = BS->HandleProtocol(handles[i], &pxe_guid,
(void **)&pxe);
if (status != EFI_SUCCESS)
continue;
continue;
if (pxe->Mtftp != NULL) {
- status = EFI_CALL(pxe->Mtftp, NULL, 0, NULL,
- FALSE, NULL, NULL, NULL, NULL, NULL, FALSE);
+ status = pxe->Mtftp(NULL, 0, NULL, FALSE, NULL, NULL,
+ NULL, NULL, NULL, FALSE);
if (status != EFI_UNSUPPORTED)
use_mtftp = 1;
}
memset(tftpfile, 0, sizeof(*tftpfile));
memcpy(&dstip, &servip, sizeof(servip));
- status = EFI_CALL(PXE->Mtftp, PXE, EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,
- NULL, FALSE, &size, NULL, &dstip, path, NULL, FALSE);
+ status = PXE->Mtftp(PXE, EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE, NULL,
+ FALSE, &size, NULL, &dstip, path, NULL, FALSE);
if (status != EFI_SUCCESS) {
free(tftpfile, sizeof(*tftpfile));
return ENOENT;
if (tftpfile->inbufsize == 0)
goto out;
- status = EFI_CALL(BS->AllocatePages, AllocateAnyPages, EfiLoaderData,
+ status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
EFI_SIZE_TO_PAGES(tftpfile->inbufsize), &addr);
if (status != EFI_SUCCESS) {
free(tftpfile, sizeof(*tftpfile));
}
tftpfile->inbuf = (unsigned char *)((paddr_t)addr);
- status = EFI_CALL(PXE->Mtftp, PXE, EFI_PXE_BASE_CODE_TFTP_READ_FILE,
+ status = PXE->Mtftp(PXE, EFI_PXE_BASE_CODE_TFTP_READ_FILE,
tftpfile->inbuf, FALSE, &size, NULL, &dstip, path, NULL, FALSE);
if (status != EFI_SUCCESS) {
free(tftpfile, sizeof(*tftpfile));
struct mtftp_handle *tftpfile = f->f_fsdata;
if (tftpfile->inbuf != NULL)
- EFI_CALL(BS->FreePages, (paddr_t)tftpfile->inbuf,
+ BS->FreePages((paddr_t)tftpfile->inbuf,
EFI_SIZE_TO_PAGES(tftpfile->inbufsize));
free(tftpfile, sizeof(*tftpfile));
return 0;
return 1;
if (!use_mtftp) {
- status = EFI_CALL(BS->AllocatePages, AllocateAnyPages,
- EfiLoaderData, EFI_SIZE_TO_PAGES(RECV_SIZE), &txbuf);
+ status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
+ EFI_SIZE_TO_PAGES(RECV_SIZE), &txbuf);
if (status != EFI_SUCCESS)
return ENOMEM;
if ((tftpdev_sock = netif_open("efinet")) < 0) {
- EFI_CALL(BS->FreePages, txbuf,
- EFI_SIZE_TO_PAGES(RECV_SIZE));
+ BS->FreePages(txbuf, EFI_SIZE_TO_PAGES(RECV_SIZE));
return ENXIO;
}
if (!use_mtftp) {
ret = netif_close(*(int *)f->f_devdata);
- EFI_CALL(BS->FreePages, txbuf, EFI_SIZE_TO_PAGES(RECV_SIZE));
+ BS->FreePages(txbuf, EFI_SIZE_TO_PAGES(RECV_SIZE));
txbuf = 0;
}
return;
if (net->Mode->State == EfiSimpleNetworkStopped) {
- status = EFI_CALL(net->Start, net);
+ status = net->Start(net);
if (status != EFI_SUCCESS)
return;
}
if (net->Mode->State != EfiSimpleNetworkInitialized) {
- status = EFI_CALL(net->Initialize, net, 0, 0);
+ status = net->Initialize(net, 0, 0);
if (status != EFI_SUCCESS)
return;
}
- EFI_CALL(net->ReceiveFilters, net,
- EFI_SIMPLE_NETWORK_RECEIVE_UNICAST |
+ net->ReceiveFilters(net, EFI_SIMPLE_NETWORK_RECEIVE_UNICAST |
EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST,
0, FALSE, 0, NULL);
status = EFI_NOT_READY;
while ((getsecs() - t) < tmo) {
pktsz = bufsz;
- status = EFI_CALL(net->Receive, net, NULL, &pktsz, ptr,
- NULL, NULL, NULL);
+ status = net->Receive(net, NULL, &pktsz, ptr, NULL, NULL, NULL);
if (status == EFI_SUCCESS)
break;
if (status != EFI_NOT_READY)
goto out;
memcpy((void *)txbuf, pkt, len);
- status = EFI_CALL(net->Transmit, net, 0, len, (void *)txbuf,
- NULL, NULL, NULL);
+ status = net->Transmit(net, 0, len, (void *)txbuf, NULL, NULL, NULL);
if (status != EFI_SUCCESS)
goto out;
buf = NULL;
while (status == EFI_SUCCESS) {
- status = EFI_CALL(net->GetStatus, net, NULL, &buf);
+ status = net->GetStatus(net, NULL, &buf);
if (buf)
break;
}
if (net == NULL)
return;
- EFI_CALL(net->Shutdown, net);
+ net->Shutdown(net);
}
-/* $OpenBSD: efirng.c,v 1.1 2021/04/28 19:01:00 drahn Exp $ */
+/* $OpenBSD: efirng.c,v 1.2 2021/06/25 17:49:49 krw Exp $ */
/*
* Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org>
#include <efi.h>
#include <efiapi.h>
-#include "eficall.h"
#include "libsa.h"
extern EFI_BOOT_SERVICES *BS;
size_t i;
int ret = 0;
- status = EFI_CALL(BS->LocateProtocol, &rng_guid, NULL, (void **)&rng);
+ status = BS->LocateProtocol(&rng_guid, NULL, (void **)&rng);
if (rng == NULL || EFI_ERROR(status))
return -1;
random = alloc(buflen);
- status = EFI_CALL(rng->GetRNG, rng, NULL, buflen, random);
+ status = rng->GetRNG(rng, NULL, buflen, random);
if (EFI_ERROR(status)) {
printf("RNG GetRNG() failed (%d)\n", status);
ret = -1;