Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 *  Copyright 2007-2010 Red Hat, Inc.
  4 *  by Peter Jones <pjones@redhat.com>
  5 *  Copyright 2007 IBM, Inc.
  6 *  by Konrad Rzeszutek <konradr@linux.vnet.ibm.com>
  7 *  Copyright 2008
  8 *  by Konrad Rzeszutek <ketuzsezr@darnok.org>
  9 *
 10 * This code finds the iSCSI Boot Format Table.
 
 
 
 
 
 
 
 
 
 11 */
 12
 13#include <linux/memblock.h>
 14#include <linux/blkdev.h>
 15#include <linux/ctype.h>
 16#include <linux/device.h>
 17#include <linux/efi.h>
 18#include <linux/err.h>
 19#include <linux/init.h>
 20#include <linux/limits.h>
 21#include <linux/module.h>
 22#include <linux/pci.h>
 23#include <linux/stat.h>
 24#include <linux/string.h>
 25#include <linux/types.h>
 26#include <linux/acpi.h>
 27#include <linux/iscsi_ibft.h>
 28
 29#include <asm/mmzone.h>
 30
 31/*
 32 * Physical location of iSCSI Boot Format Table.
 33 */
 34phys_addr_t ibft_phys_addr;
 35EXPORT_SYMBOL_GPL(ibft_phys_addr);
 36
 37static const struct {
 38	char *sign;
 39} ibft_signs[] = {
 40	{ "iBFT" },
 41	{ "BIFT" },	/* Broadcom iSCSI Offload */
 42};
 43
 44#define IBFT_SIGN_LEN 4
 
 
 45#define VGA_MEM 0xA0000 /* VGA buffer */
 46#define VGA_SIZE 0x20000 /* 128kB */
 47
 48/*
 49 * Routine used to find and reserve the iSCSI Boot Format Table
 50 */
 51void __init reserve_ibft_region(void)
 52{
 53	unsigned long pos, virt_pos = 0;
 54	unsigned int len = 0;
 55	void *virt = NULL;
 56	int i;
 57
 58	ibft_phys_addr = 0;
 59
 60	/* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will
 61	 * only use ACPI for this
 62	 */
 63	if (efi_enabled(EFI_BOOT))
 64		return;
 65
 66	for (pos = IBFT_START; pos < IBFT_END; pos += 16) {
 67		/* The table can't be inside the VGA BIOS reserved space,
 68		 * so skip that area */
 69		if (pos == VGA_MEM)
 70			pos += VGA_SIZE;
 71
 72		/* Map page by page */
 73		if (offset_in_page(pos) == 0) {
 74			if (virt)
 75				early_memunmap(virt, PAGE_SIZE);
 76			virt = early_memremap_ro(pos, PAGE_SIZE);
 77			virt_pos = pos;
 78		}
 79
 80		for (i = 0; i < ARRAY_SIZE(ibft_signs); i++) {
 81			if (memcmp(virt + (pos - virt_pos), ibft_signs[i].sign,
 82				   IBFT_SIGN_LEN) == 0) {
 83				unsigned long *addr =
 84				    (unsigned long *)(virt + pos - virt_pos + 4);
 85				len = *addr;
 86				/* if the length of the table extends past 1M,
 87				 * the table cannot be valid. */
 88				if (pos + len <= (IBFT_END-1)) {
 89					ibft_phys_addr = pos;
 90					memblock_reserve(ibft_phys_addr, PAGE_ALIGN(len));
 91					pr_info("iBFT found at %pa.\n", &ibft_phys_addr);
 92					goto out;
 93				}
 94			}
 95		}
 96	}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 97
 98out:
 99	early_memunmap(virt, PAGE_SIZE);
100}
v3.15
 
  1/*
  2 *  Copyright 2007-2010 Red Hat, Inc.
  3 *  by Peter Jones <pjones@redhat.com>
  4 *  Copyright 2007 IBM, Inc.
  5 *  by Konrad Rzeszutek <konradr@linux.vnet.ibm.com>
  6 *  Copyright 2008
  7 *  by Konrad Rzeszutek <ketuzsezr@darnok.org>
  8 *
  9 * This code finds the iSCSI Boot Format Table.
 10 *
 11 * This program is free software; you can redistribute it and/or modify
 12 * it under the terms of the GNU General Public License v2.0 as published by
 13 * the Free Software Foundation
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 */
 20
 21#include <linux/bootmem.h>
 22#include <linux/blkdev.h>
 23#include <linux/ctype.h>
 24#include <linux/device.h>
 25#include <linux/efi.h>
 26#include <linux/err.h>
 27#include <linux/init.h>
 28#include <linux/limits.h>
 29#include <linux/module.h>
 30#include <linux/pci.h>
 31#include <linux/stat.h>
 32#include <linux/string.h>
 33#include <linux/types.h>
 34#include <linux/acpi.h>
 35#include <linux/iscsi_ibft.h>
 36
 37#include <asm/mmzone.h>
 38
 39/*
 40 * Physical location of iSCSI Boot Format Table.
 41 */
 42struct acpi_table_ibft *ibft_addr;
 43EXPORT_SYMBOL_GPL(ibft_addr);
 44
 45static const struct {
 46	char *sign;
 47} ibft_signs[] = {
 48	{ "iBFT" },
 49	{ "BIFT" },	/* Broadcom iSCSI Offload */
 50};
 51
 52#define IBFT_SIGN_LEN 4
 53#define IBFT_START 0x80000 /* 512kB */
 54#define IBFT_END 0x100000 /* 1MB */
 55#define VGA_MEM 0xA0000 /* VGA buffer */
 56#define VGA_SIZE 0x20000 /* 128kB */
 57
 58static int __init find_ibft_in_mem(void)
 
 
 
 59{
 60	unsigned long pos;
 61	unsigned int len = 0;
 62	void *virt;
 63	int i;
 64
 
 
 
 
 
 
 
 
 65	for (pos = IBFT_START; pos < IBFT_END; pos += 16) {
 66		/* The table can't be inside the VGA BIOS reserved space,
 67		 * so skip that area */
 68		if (pos == VGA_MEM)
 69			pos += VGA_SIZE;
 70		virt = isa_bus_to_virt(pos);
 
 
 
 
 
 
 
 71
 72		for (i = 0; i < ARRAY_SIZE(ibft_signs); i++) {
 73			if (memcmp(virt, ibft_signs[i].sign, IBFT_SIGN_LEN) ==
 74			    0) {
 75				unsigned long *addr =
 76				    (unsigned long *)isa_bus_to_virt(pos + 4);
 77				len = *addr;
 78				/* if the length of the table extends past 1M,
 79				 * the table cannot be valid. */
 80				if (pos + len <= (IBFT_END-1)) {
 81					ibft_addr = (struct acpi_table_ibft *)virt;
 82					pr_info("iBFT found at 0x%lx.\n", pos);
 83					goto done;
 
 84				}
 85			}
 86		}
 87	}
 88done:
 89	return len;
 90}
 91/*
 92 * Routine used to find the iSCSI Boot Format Table. The logical
 93 * kernel address is set in the ibft_addr global variable.
 94 */
 95unsigned long __init find_ibft_region(unsigned long *sizep)
 96{
 97	ibft_addr = NULL;
 98
 99	/* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will
100	 * only use ACPI for this */
101
102	if (!efi_enabled(EFI_BOOT))
103		find_ibft_in_mem();
104
105	if (ibft_addr) {
106		*sizep = PAGE_ALIGN(ibft_addr->header.length);
107		return (u64)isa_virt_to_bus(ibft_addr);
108	}
109
110	*sizep = 0;
111	return 0;
112}