1
/* bonito.c - PCI bonito interface. */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2009 Free Software Foundation, Inc.
6
* GRUB is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* GRUB is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21
#include <grub/misc.h>
23
static grub_uint32_t base_win[GRUB_MACHINE_PCI_NUM_WIN];
24
static const grub_size_t sizes_win[GRUB_MACHINE_PCI_NUM_WIN] =
25
{GRUB_MACHINE_PCI_WIN1_SIZE, GRUB_MACHINE_PCI_WIN_SIZE,
26
GRUB_MACHINE_PCI_WIN_SIZE};
28
static int usage_win[GRUB_MACHINE_PCI_NUM_WIN];
29
static grub_addr_t addr_win[GRUB_MACHINE_PCI_NUM_WIN] =
30
{GRUB_MACHINE_PCI_WIN1_ADDR, GRUB_MACHINE_PCI_WIN2_ADDR,
31
GRUB_MACHINE_PCI_WIN3_ADDR};
37
grub_uint32_t reg = 0;
38
for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
39
reg |= (((base_win[i] >> GRUB_MACHINE_PCI_WIN_SHIFT)
40
& GRUB_MACHINE_PCI_WIN_MASK)
41
>> (i * GRUB_MACHINE_PCI_WIN_MASK_SIZE));
42
GRUB_MACHINE_PCI_IO_CTRL_REG = reg;
46
grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)),
47
grub_addr_t base, grub_size_t size)
52
/* First try already used registers. */
53
for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
54
if (usage_win[i] && base_win[i] <= base
55
&& base_win[i] + sizes_win[i] > base + size)
59
(addr_win[i] | (base & GRUB_MACHINE_PCI_WIN_OFFSET_MASK));
61
/* Map new register. */
62
newbase = base & ~GRUB_MACHINE_PCI_WIN_OFFSET_MASK;
63
for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
64
if (!usage_win[i] && newbase <= base
65
&& newbase + sizes_win[i] > base + size)
68
base_win[i] = newbase;
71
(addr_win[i] | (base & GRUB_MACHINE_PCI_WIN_OFFSET_MASK));
73
grub_fatal ("Out of PCI windows.");
77
grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)),
78
volatile void *mem __attribute__ ((unused)),
79
grub_size_t size __attribute__ ((unused)))
82
for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
83
if (usage_win[i] && addr_win[i]
84
== (((grub_addr_t) mem) & ~GRUB_MACHINE_PCI_WIN_OFFSET_MASK))
89
grub_fatal ("Tried to unmap not mapped region");