ソースを参照

qcacld-3.0: Allocate global_mac_context dynamically

Allocate global_mac_context dynamically to reduce build size.

Change-Id: I67e9f20f55d2289d9b97756adaea0666f64d6afc
CRs-Fixed: 2290537
Qiwei Cai 6 年 前
コミット
c778c0853c
1 ファイル変更41 行追加2 行削除
  1. 41 2
      core/mac/src/sys/legacy/src/system/src/mac_init_api.c

+ 41 - 2
core/mac/src/sys/legacy/src/system/src/mac_init_api.c

@@ -39,8 +39,34 @@
 #include "mac_trace.h"
 #endif
 
+#ifdef WLAN_ALLOCATE_GLOBAL_BUFFERS_DYNAMICALLY
+static tAniSirGlobal *global_mac_context;
+
+static inline tpAniSirGlobal mac_allocate_context_buffer(void)
+{
+	global_mac_context = qdf_mem_malloc(sizeof(tAniSirGlobal));
+
+	return global_mac_context;
+}
+
+static inline void mac_free_context_buffer(void)
+{
+	qdf_mem_free(global_mac_context);
+	global_mac_context = NULL;
+}
+#else /* WLAN_ALLOCATE_GLOBAL_BUFFERS_DYNAMICALLY */
 static tAniSirGlobal global_mac_context;
 
+static inline tpAniSirGlobal mac_allocate_context_buffer(void)
+{
+	return &global_mac_context;
+}
+
+static inline void mac_free_context_buffer(void)
+{
+}
+#endif /* WLAN_ALLOCATE_GLOBAL_BUFFERS_DYNAMICALLY */
+
 QDF_STATUS mac_start(mac_handle_t mac_handle,
 		     struct mac_start_params *params)
 {
@@ -84,12 +110,20 @@ QDF_STATUS mac_stop(mac_handle_t mac_handle)
 QDF_STATUS mac_open(struct wlan_objmgr_psoc *psoc, tHalHandle *pHalHandle,
 		    hdd_handle_t hdd_handle, struct cds_config_info *cds_cfg)
 {
-	tpAniSirGlobal p_mac = &global_mac_context;
+	tpAniSirGlobal p_mac;
 	QDF_STATUS status;
 
 	if (pHalHandle == NULL)
 		return QDF_STATUS_E_FAILURE;
 
+	p_mac = mac_allocate_context_buffer();
+
+	if (!p_mac) {
+		pe_err("%s: Failed to allocate %zu bytes for global_mac_context",
+		       __func__, sizeof(tAniSirGlobal));
+		return QDF_STATUS_E_NOMEM;
+	}
+
 	/*
 	 * Set various global fields of p_mac here
 	 * (Could be platform dependent as some variables in p_mac are platform
@@ -100,6 +134,7 @@ QDF_STATUS mac_open(struct wlan_objmgr_psoc *psoc, tHalHandle *pHalHandle,
 	status = wlan_objmgr_psoc_try_get_ref(psoc, WLAN_LEGACY_MAC_ID);
 	if (QDF_IS_STATUS_ERROR(status)) {
 		pe_err("PSOC get ref failure");
+		mac_free_context_buffer();
 		return QDF_STATUS_E_FAILURE;
 	}
 
@@ -114,8 +149,10 @@ QDF_STATUS mac_open(struct wlan_objmgr_psoc *psoc, tHalHandle *pHalHandle,
 			p_mac->gDriverType = QDF_DRIVER_TYPE_MFG;
 
 		/* Call routine to initialize CFG data structures */
-		if (QDF_STATUS_SUCCESS != cfg_init(p_mac))
+		if (QDF_STATUS_SUCCESS != cfg_init(p_mac)) {
+			mac_free_context_buffer();
 			return QDF_STATUS_E_FAILURE;
+		}
 
 		sys_init_globals(p_mac);
 	}
@@ -129,6 +166,7 @@ QDF_STATUS mac_open(struct wlan_objmgr_psoc *psoc, tHalHandle *pHalHandle,
 	status =  pe_open(p_mac, cds_cfg);
 	if (QDF_STATUS_SUCCESS != status) {
 		pe_err("pe_open() failure");
+		mac_free_context_buffer();
 		cfg_de_init(p_mac);
 	}
 
@@ -162,6 +200,7 @@ QDF_STATUS mac_close(tHalHandle hHal)
 	}
 	wlan_objmgr_psoc_release_ref(pMac->psoc, WLAN_LEGACY_MAC_ID);
 	pMac->psoc = NULL;
+	mac_free_context_buffer();
 
 	return QDF_STATUS_SUCCESS;
 }