|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Intel Corporation. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/device.h> |
| 8 | +#include <zephyr/kernel.h> |
| 9 | +#include <zephyr/drivers/pcie/pcie.h> |
| 10 | +#include <zephyr/drivers/ethernet/eth_intel_plat.h> |
| 11 | + |
| 12 | +#include <zephyr/logging/log.h> |
| 13 | +LOG_MODULE_REGISTER(intel_eth_plat, CONFIG_ETHERNET_LOG_LEVEL); |
| 14 | + |
| 15 | +#define DT_DRV_COMPAT intel_eth_plat |
| 16 | + |
| 17 | +struct intel_eth_plat_cfg { |
| 18 | + struct pcie_dev *pcie; |
| 19 | +}; |
| 20 | + |
| 21 | +struct intel_eth_plat_data { |
| 22 | + DEVICE_MMIO_RAM; |
| 23 | +}; |
| 24 | + |
| 25 | +uint32_t eth_intel_get_pcie_bdf(const struct device *dev) |
| 26 | +{ |
| 27 | + const struct intel_eth_plat_cfg *cfg = dev->config; |
| 28 | + |
| 29 | + return cfg->pcie->bdf; |
| 30 | +} |
| 31 | + |
| 32 | +uint32_t eth_intel_get_pcie_id(const struct device *dev) |
| 33 | +{ |
| 34 | + const struct intel_eth_plat_cfg *cfg = dev->config; |
| 35 | + |
| 36 | + return cfg->pcie->id; |
| 37 | +} |
| 38 | + |
| 39 | +static int intel_eth_plat_init(const struct device *dev) |
| 40 | +{ |
| 41 | + const struct intel_eth_plat_cfg *cfg = dev->config; |
| 42 | + struct pcie_bar mbar; |
| 43 | + |
| 44 | + if (cfg->pcie->bdf == PCIE_BDF_NONE || |
| 45 | + !pcie_probe_mbar(cfg->pcie->bdf, 0, &mbar)) { |
| 46 | + LOG_ERR("Cannot get mbar"); |
| 47 | + return -ENOENT; |
| 48 | + } |
| 49 | + |
| 50 | + pcie_set_cmd(cfg->pcie->bdf, |
| 51 | + PCIE_CONF_CMDSTAT_MEM | PCIE_CONF_CMDSTAT_MASTER, true); |
| 52 | + |
| 53 | + device_map(DEVICE_MMIO_RAM_PTR(dev), |
| 54 | + mbar.phys_addr, mbar.size, K_MEM_CACHE_NONE); |
| 55 | + |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +#define INTEL_ETH_PLAT_CONFIG(n) \ |
| 60 | + static const struct intel_eth_plat_cfg plat_cfg_##n = { \ |
| 61 | + DEVICE_PCIE_INST_INIT(n, pcie), \ |
| 62 | + }; |
| 63 | + |
| 64 | +#define INTEL_ETH_PLAT_INIT(n) \ |
| 65 | + DEVICE_PCIE_INST_DECLARE(n); \ |
| 66 | + INTEL_ETH_PLAT_CONFIG(n); \ |
| 67 | + static struct intel_eth_plat_data plat_data_##n; \ |
| 68 | + \ |
| 69 | + DEVICE_DT_INST_DEFINE(n, intel_eth_plat_init, NULL, \ |
| 70 | + &plat_data_##n, &plat_cfg_##n, POST_KERNEL, \ |
| 71 | + CONFIG_PCIE_INIT_PRIORITY, NULL); |
| 72 | + |
| 73 | +DT_INST_FOREACH_STATUS_OKAY(INTEL_ETH_PLAT_INIT) |
0 commit comments