Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program 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; 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. |
Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 14 | */ |
| 15 | |
Kyösti Mälkki | 526c2fb | 2014-07-10 22:16:58 +0300 | [diff] [blame] | 16 | #include "AGESA.h" |
Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 17 | #include "amdlib.h" |
Kyösti Mälkki | 6e74b2c | 2014-12-16 07:34:58 +0200 | [diff] [blame] | 18 | #include <northbridge/amd/agesa/agesawrapper.h> |
Kyösti Mälkki | 26f297e | 2014-05-26 11:27:54 +0300 | [diff] [blame] | 19 | #include <northbridge/amd/agesa/BiosCallOuts.h> |
Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 20 | #include "Ids.h" |
Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 21 | #include "heapManager.h" |
Kimarie Hoot | b37ec54 | 2013-03-08 15:31:49 -0700 | [diff] [blame] | 22 | #include <arch/io.h> |
Kyösti Mälkki | 6025efa | 2014-05-05 13:20:56 +0300 | [diff] [blame] | 23 | #include <stdlib.h> |
Kimarie Hoot | b37ec54 | 2013-03-08 15:31:49 -0700 | [diff] [blame] | 24 | |
| 25 | #ifdef __PRE_RAM__ |
| 26 | /* These defines are used to select the appropriate socket for the SPD read |
| 27 | * because this is a multi-socket design. |
| 28 | */ |
| 29 | #define PCI_REG_GPIO_48_47_46_37_CNTRL (0xA6) |
| 30 | #define PCI_REG_GPIO_52_to_49_CNTRL (0x50) |
| 31 | #define GPIO_OUT_BIT_GPIO48 (BIT3) |
| 32 | #define GPIO_OUT_BIT_GPIO49 (BIT0) |
| 33 | #define GPIO_OUT_ENABLE_BIT_GPIO48 (BIT7) |
| 34 | #define GPIO_OUT_ENABLE_BIT_GPIO49 (BIT4) |
| 35 | |
| 36 | static UINT8 select_socket(UINT8 socket_id) |
| 37 | { |
| 38 | device_t sm_dev = PCI_DEV(0, 0x14, 0); //SMBUS |
| 39 | UINT8 value = 0; |
| 40 | UINT8 gpio52_to_49 = 0; |
| 41 | |
| 42 | /* Configure GPIO49,48 to select the desired socket |
| 43 | * GPIO49,48 control the IDTQS3253 S1,S0 |
| 44 | * S1 S0 true table |
| 45 | * 0 0 channel 0 |
| 46 | * 0 1 channel 1 |
| 47 | * 1 0 channel 2 - Socket 0 |
| 48 | * 1 1 channel 3 - Socket 1 |
| 49 | * Note: Above is abstracted from Schematic. But actually it seems to be other way. |
| 50 | * 1 0 channel 2 - Socket 1 |
| 51 | * 1 1 channel 3 - Socket 0 |
| 52 | * Note: The DIMMs need to be plugged in from the farthest slot for each channel. |
| 53 | */ |
| 54 | gpio52_to_49 = pci_read_config8(sm_dev, PCI_REG_GPIO_52_to_49_CNTRL); |
| 55 | value = gpio52_to_49 | GPIO_OUT_BIT_GPIO49; // Output of GPIO49 is always forced to "1" |
| 56 | value &= ~(GPIO_OUT_ENABLE_BIT_GPIO49); // 0=Output Enabled, 1=Tristate |
| 57 | pci_write_config8(sm_dev, PCI_REG_GPIO_52_to_49_CNTRL, value); |
| 58 | |
| 59 | value = pci_read_config8(sm_dev, PCI_REG_GPIO_48_47_46_37_CNTRL); |
| 60 | value &= ~(GPIO_OUT_BIT_GPIO48); |
| 61 | value |= (~(socket_id & 1)) << 3; // Output of GPIO48 is inverse of SocketId |
| 62 | value &= ~(GPIO_OUT_ENABLE_BIT_GPIO48); // 0=Output Enabled, 1=Tristate |
| 63 | pci_write_config8(sm_dev, PCI_REG_GPIO_48_47_46_37_CNTRL, value); |
| 64 | |
| 65 | return gpio52_to_49; |
| 66 | } |
| 67 | |
| 68 | static void restore_socket(UINT8 original_value) |
| 69 | { |
| 70 | device_t sm_dev = PCI_DEV(0, 0x14, 0); //SMBUS |
| 71 | pci_write_config8(sm_dev, PCI_REG_GPIO_52_to_49_CNTRL, original_value); |
| 72 | |
| 73 | // TODO: Restore previous GPIO48 configurations? |
| 74 | //pci_write_config8(sm_dev, PCI_REG_GPIO_48_47_46_37_CNTRL, gpio48_47_46_37_save); |
| 75 | } |
| 76 | #endif |
Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 77 | |
Stefan Reinauer | dd132a5 | 2015-07-30 11:16:37 -0700 | [diff] [blame] | 78 | static AGESA_STATUS board_ReadSpd (UINT32 Func, UINTN Data, VOID *ConfigPtr); |
Kyösti Mälkki | c009601 | 2014-05-05 18:56:33 +0300 | [diff] [blame] | 79 | |
Kyösti Mälkki | 6025efa | 2014-05-05 13:20:56 +0300 | [diff] [blame] | 80 | const BIOS_CALLOUT_STRUCT BiosCallouts[] = |
Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 81 | { |
Kyösti Mälkki | 5e19fa4 | 2014-05-04 23:13:54 +0300 | [diff] [blame] | 82 | {AGESA_DO_RESET, agesa_Reset }, |
Kyösti Mälkki | c009601 | 2014-05-05 18:56:33 +0300 | [diff] [blame] | 83 | {AGESA_READ_SPD, board_ReadSpd }, |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 84 | {AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported }, |
Kyösti Mälkki | 6b4b151 | 2014-05-05 12:05:53 +0300 | [diff] [blame] | 85 | {AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp }, |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 86 | {AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData }, |
| 87 | {AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopSuccess }, |
| 88 | {AGESA_HOOKBEFORE_DRAM_INIT, agesa_NoopSuccess }, |
| 89 | {AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopSuccess }, |
Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 90 | }; |
Kyösti Mälkki | 6025efa | 2014-05-05 13:20:56 +0300 | [diff] [blame] | 91 | const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts); |
Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 92 | |
Stefan Reinauer | dd132a5 | 2015-07-30 11:16:37 -0700 | [diff] [blame] | 93 | static AGESA_STATUS board_ReadSpd (UINT32 Func, UINTN Data, VOID *ConfigPtr) |
Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 94 | { |
| 95 | AGESA_STATUS Status; |
Kimarie Hoot | b37ec54 | 2013-03-08 15:31:49 -0700 | [diff] [blame] | 96 | #ifdef __PRE_RAM__ |
| 97 | UINT8 original_value = 0; |
| 98 | |
| 99 | if (ConfigPtr == NULL) |
| 100 | return AGESA_ERROR; |
| 101 | |
| 102 | original_value = select_socket(((AGESA_READ_SPD_PARAMS *)ConfigPtr)->SocketId); |
| 103 | |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 104 | Status = agesa_ReadSpd (Func, Data, ConfigPtr); |
Kimarie Hoot | b37ec54 | 2013-03-08 15:31:49 -0700 | [diff] [blame] | 105 | |
| 106 | restore_socket(original_value); |
| 107 | #else |
| 108 | Status = AGESA_UNSUPPORTED; |
| 109 | #endif |
Siyuan Wang | 1ee8b45 | 2012-09-07 19:20:02 +0800 | [diff] [blame] | 110 | |
| 111 | return Status; |
| 112 | } |