xref: /openbmc/openpower-proc-control/procedures/p9/cleanup_pcie.cpp (revision 1a9a5a6a144e81d8b61e6f999d8de7cba731ae6e)
1f0d958dfSAnthony Wilson /**
2e84b4ddbSPatrick Venture  * Copyright (C) 2018 IBM Corporation
3f0d958dfSAnthony Wilson  *
4f0d958dfSAnthony Wilson  * Licensed under the Apache License, Version 2.0 (the "License");
5f0d958dfSAnthony Wilson  * you may not use this file except in compliance with the License.
6f0d958dfSAnthony Wilson  * You may obtain a copy of the License at
7f0d958dfSAnthony Wilson  *
8f0d958dfSAnthony Wilson  *     http://www.apache.org/licenses/LICENSE-2.0
9f0d958dfSAnthony Wilson  *
10f0d958dfSAnthony Wilson  * Unless required by applicable law or agreed to in writing, software
11f0d958dfSAnthony Wilson  * distributed under the License is distributed on an "AS IS" BASIS,
12f0d958dfSAnthony Wilson  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f0d958dfSAnthony Wilson  * See the License for the specific language governing permissions and
14f0d958dfSAnthony Wilson  * limitations under the License.
15f0d958dfSAnthony Wilson  */
16f0d958dfSAnthony Wilson #include "cfam_access.hpp"
17f0d958dfSAnthony Wilson #include "p9_cfam.hpp"
18f0d958dfSAnthony Wilson #include "registration.hpp"
19f0d958dfSAnthony Wilson #include "targeting.hpp"
20f0d958dfSAnthony Wilson 
21f78d9042SPatrick Venture #include <phosphor-logging/log.hpp>
22aa2030c2SAnthony Wilson #include <xyz/openbmc_project/Common/File/error.hpp>
23f78d9042SPatrick Venture 
24f0d958dfSAnthony Wilson namespace openpower
25f0d958dfSAnthony Wilson {
26f0d958dfSAnthony Wilson namespace p9
27f0d958dfSAnthony Wilson {
28f0d958dfSAnthony Wilson 
29f0d958dfSAnthony Wilson using namespace phosphor::logging;
30f0d958dfSAnthony Wilson using namespace openpower::cfam::access;
31f0d958dfSAnthony Wilson using namespace openpower::cfam::p9;
32f0d958dfSAnthony Wilson using namespace openpower::targeting;
33aa2030c2SAnthony Wilson namespace file_error = sdbusplus::xyz::openbmc_project::Common::File::Error;
34f0d958dfSAnthony Wilson 
35f0d958dfSAnthony Wilson /**
36f0d958dfSAnthony Wilson  * @brief Disables PCIE drivers and receiver in the PCIE root ctrl 1 register
37f0d958dfSAnthony Wilson  * @return void
38f0d958dfSAnthony Wilson  */
cleanupPcie()39f0d958dfSAnthony Wilson void cleanupPcie()
40f0d958dfSAnthony Wilson {
41aa2030c2SAnthony Wilson     try
42aa2030c2SAnthony Wilson     {
43f0d958dfSAnthony Wilson         Targeting targets;
44f0d958dfSAnthony Wilson 
45f0d958dfSAnthony Wilson         log<level::INFO>("Running P9 procedure cleanupPcie");
46f0d958dfSAnthony Wilson 
4759704841SAnthony Wilson         // Disable the PCIE drivers and receiver on all CPUs
4859704841SAnthony Wilson         for (const auto& target : targets)
4959704841SAnthony Wilson         {
50a27263d4SMatt Spinler             try
51a27263d4SMatt Spinler             {
5259704841SAnthony Wilson                 writeReg(target, P9_ROOT_CTRL1_CLEAR, 0x00001C00);
5359704841SAnthony Wilson             }
54*1a9a5a6aSPatrick Williams             catch (const std::exception& e)
55a27263d4SMatt Spinler             {
56a27263d4SMatt Spinler                 // Don't need an error log coming from the power off
57a27263d4SMatt Spinler                 // path, just keep trying on the other processors.
58a27263d4SMatt Spinler                 continue;
59a27263d4SMatt Spinler             }
60a27263d4SMatt Spinler         }
61f0d958dfSAnthony Wilson     }
62*1a9a5a6aSPatrick Williams     catch (const file_error::Open& e)
63aa2030c2SAnthony Wilson     {
64aa2030c2SAnthony Wilson         // For this procedure we can ignore the ::Open error
65aa2030c2SAnthony Wilson     }
66aa2030c2SAnthony Wilson }
67f0d958dfSAnthony Wilson 
6863508a73SBrad Bishop REGISTER_PROCEDURE("cleanupPcie", cleanupPcie)
69f0d958dfSAnthony Wilson 
70f78d9042SPatrick Venture } // namespace p9
71f78d9042SPatrick Venture } // namespace openpower
72