1 /*
2 * Copyright (c) 2024 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 /**
8 * @brief File containing SoC specific definitions for the
9 * HAL Layer of the Wi-Fi driver.
10 */
11
12 #include "common/pal.h"
13
pal_check_rpu_mcu_regions(enum RPU_PROC_TYPE proc,unsigned int addr_val)14 bool pal_check_rpu_mcu_regions(enum RPU_PROC_TYPE proc, unsigned int addr_val)
15 {
16 const struct rpu_addr_map *map = &RPU_ADDR_MAP_MCU[proc];
17 enum RPU_MCU_ADDR_REGIONS region_type;
18
19 if (proc >= RPU_PROC_TYPE_MAX) {
20 return false;
21 }
22
23 for (region_type = 0; region_type < RPU_MCU_ADDR_REGION_MAX; region_type++) {
24 const struct rpu_addr_region *region = &map->regions[region_type];
25
26 if ((addr_val >= region->start) && (addr_val <= region->end)) {
27 return true;
28 }
29 }
30
31 return false;
32 }
33
pal_rpu_addr_offset_get(unsigned int rpu_addr,unsigned long * addr,enum RPU_PROC_TYPE proc)34 enum nrf_wifi_status pal_rpu_addr_offset_get(unsigned int rpu_addr,
35 unsigned long *addr,
36 enum RPU_PROC_TYPE proc)
37 {
38 enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
39 unsigned int addr_base = (rpu_addr & RPU_ADDR_MASK_BASE);
40 unsigned long region_offset = 0;
41
42 if (addr_base == RPU_ADDR_SBUS_START) {
43 region_offset = SOC_MMAP_ADDR_OFFSET_SYSBUS;
44 } else if ((rpu_addr >= RPU_ADDR_GRAM_START) &&
45 (rpu_addr <= RPU_ADDR_GRAM_END)) {
46 region_offset = SOC_MMAP_ADDR_OFFSET_GRAM_PKD;
47 } else if (addr_base == RPU_ADDR_PBUS_START) {
48 region_offset = SOC_MMAP_ADDR_OFFSET_PBUS;
49 } else if (addr_base == RPU_ADDR_PKTRAM_START) {
50 region_offset = SOC_MMAP_ADDR_OFFSET_PKTRAM_HOST_VIEW;
51 } else if (pal_check_rpu_mcu_regions(proc, rpu_addr)) {
52 region_offset = SOC_MMAP_ADDR_OFFSETS_MCU[proc];
53 } else {
54 nrf_wifi_osal_log_err("%s: Invalid rpu_addr 0x%X",
55 __func__,
56 rpu_addr);
57 goto out;
58 }
59
60 *addr = region_offset + (rpu_addr & RPU_ADDR_MASK_OFFSET);
61
62 status = NRF_WIFI_STATUS_SUCCESS;
63 out:
64 return status;
65 }
66
67
68
69 #ifdef NRF_WIFI_LOW_POWER
pal_rpu_ps_ctrl_reg_addr_get(void)70 unsigned long pal_rpu_ps_ctrl_reg_addr_get(void)
71 {
72 return SOC_MMAP_ADDR_RPU_PS_CTRL;
73 }
74 #endif /* NRF_WIFI_LOW_POWER */
75
pal_ops_get_fw_loc(enum nrf_wifi_fw_type fw_type,enum nrf_wifi_fw_subtype fw_subtype)76 char *pal_ops_get_fw_loc(enum nrf_wifi_fw_type fw_type,
77 enum nrf_wifi_fw_subtype fw_subtype)
78 {
79 char *fw_loc = NULL;
80
81 switch (fw_type) {
82 case NRF_WIFI_FW_TYPE_LMAC_PATCH:
83 if (fw_subtype == NRF_WIFI_FW_SUBTYPE_PRI) {
84 fw_loc = NRF_WIFI_FW_LMAC_PATCH_LOC_PRI;
85 } else if (fw_subtype == NRF_WIFI_FW_SUBTYPE_SEC) {
86 fw_loc = NRF_WIFI_FW_LMAC_PATCH_LOC_SEC;
87 } else {
88 nrf_wifi_osal_log_err("%s: Invalid LMAC FW sub-type = %d",
89 __func__,
90 fw_subtype);
91 goto out;
92 }
93 break;
94 case NRF_WIFI_FW_TYPE_UMAC_PATCH:
95 if (fw_subtype == NRF_WIFI_FW_SUBTYPE_PRI) {
96 fw_loc = NRF_WIFI_FW_UMAC_PATCH_LOC_PRI;
97 } else if (fw_subtype == NRF_WIFI_FW_SUBTYPE_SEC) {
98 fw_loc = NRF_WIFI_FW_UMAC_PATCH_LOC_SEC;
99 } else {
100 nrf_wifi_osal_log_err("%s: Invalid UMAC FW sub-type = %d",
101 __func__,
102 fw_subtype);
103 goto out;
104 }
105 break;
106 default:
107 nrf_wifi_osal_log_err("%s: Invalid FW type = %d",
108 __func__,
109 fw_type);
110 goto out;
111 }
112
113 out:
114 return fw_loc;
115 }
116