Fix a few whitespace and coding style issues.
[coreboot.git] / src / northbridge / intel / sch / acpi.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007-2009 coresystems GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 #include <types.h>
21 #include <string.h>
22 #include <console/console.h>
23 #include <arch/acpi.h>
24 #include <arch/acpigen.h>
25 #include <device/device.h>
26 #include <device/pci.h>
27 #include <device/pci_ids.h>
28
29 unsigned long acpi_fill_mcfg(unsigned long current)
30 {
31         device_t dev;
32         u32 pciexbar = 0;
33         u32 pciexbar_reg;
34         int max_buses;
35
36         dev = dev_find_device(0x8086, 0x27a0, 0);
37         if (!dev)
38                 return current;
39
40         pciexbar_reg = pci_read_config32(dev, 0x48);
41
42         /* MMCFG not supported or not enabled. */
43         if (!(pciexbar_reg & (1 << 0)))
44                 return current;
45
46         switch ((pciexbar_reg >> 1) & 3) {
47         case 0: /* 256MB */
48                 pciexbar = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
49                                            (1 << 28));
50                 max_buses = 256;
51                 break;
52         case 1: /* 128M */
53                 pciexbar = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
54                                            (1 << 28) | (1 << 27));
55                 max_buses = 128;
56                 break;
57         case 2: /* 64M */
58                 pciexbar = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
59                                            (1 << 28) | (1 << 27) | (1 << 26));
60                 max_buses = 64;
61                 break;
62         default: /* RSVD */
63                 return current;
64         }
65
66         if (!pciexbar)
67                 return current;
68
69 #if CONFIG_GENERATE_ACPI_TABLES
70         current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
71                                              pciexbar, 0x0, 0x0, max_buses - 1);
72 #endif
73         return current;
74 }