@@ -182,6 +182,13 @@ static struct {
182182 },
183183};
184184
185+ struct acpi_cedt_cfmws * mock_cfmws [4 ] = {
186+ [0 ] = & mock_cedt .cfmws0 .cfmws ,
187+ [1 ] = & mock_cedt .cfmws1 .cfmws ,
188+ [2 ] = & mock_cedt .cfmws2 .cfmws ,
189+ [3 ] = & mock_cedt .cfmws3 .cfmws ,
190+ };
191+
185192struct cxl_mock_res {
186193 struct list_head list ;
187194 struct range range ;
@@ -232,12 +239,6 @@ static struct cxl_mock_res *alloc_mock_res(resource_size_t size)
232239
233240static int populate_cedt (void )
234241{
235- struct acpi_cedt_cfmws * cfmws [4 ] = {
236- [0 ] = & mock_cedt .cfmws0 .cfmws ,
237- [1 ] = & mock_cedt .cfmws1 .cfmws ,
238- [2 ] = & mock_cedt .cfmws2 .cfmws ,
239- [3 ] = & mock_cedt .cfmws3 .cfmws ,
240- };
241242 struct cxl_mock_res * res ;
242243 int i ;
243244
@@ -257,8 +258,8 @@ static int populate_cedt(void)
257258 chbs -> length = size ;
258259 }
259260
260- for (i = 0 ; i < ARRAY_SIZE (cfmws ); i ++ ) {
261- struct acpi_cedt_cfmws * window = cfmws [i ];
261+ for (i = 0 ; i < ARRAY_SIZE (mock_cfmws ); i ++ ) {
262+ struct acpi_cedt_cfmws * window = mock_cfmws [i ];
262263
263264 res = alloc_mock_res (window -> window_size );
264265 if (!res )
@@ -269,21 +270,44 @@ static int populate_cedt(void)
269270 return 0 ;
270271}
271272
272- static acpi_status mock_acpi_get_table (char * signature , u32 instance ,
273- struct acpi_table_header * * out_table )
273+ /*
274+ * WARNING, this hack assumes the format of 'struct
275+ * cxl_cfmws_context' and 'struct cxl_chbs_context' share the property that
276+ * the first struct member is the device being probed by the cxl_acpi
277+ * driver.
278+ */
279+ struct cxl_cedt_context {
280+ struct device * dev ;
281+ };
282+
283+ static int mock_acpi_table_parse_cedt (enum acpi_cedt_type id ,
284+ acpi_tbl_entry_handler_arg handler_arg ,
285+ void * arg )
274286{
275- if (instance < U32_MAX || strcmp (signature , ACPI_SIG_CEDT ) != 0 )
276- return acpi_get_table (signature , instance , out_table );
287+ struct cxl_cedt_context * ctx = arg ;
288+ struct device * dev = ctx -> dev ;
289+ union acpi_subtable_headers * h ;
290+ unsigned long end ;
291+ int i ;
277292
278- * out_table = (struct acpi_table_header * ) & mock_cedt ;
279- return AE_OK ;
280- }
293+ if (dev != & cxl_acpi -> dev )
294+ return acpi_table_parse_cedt (id , handler_arg , arg );
281295
282- static void mock_acpi_put_table (struct acpi_table_header * table )
283- {
284- if (table == (struct acpi_table_header * ) & mock_cedt )
285- return ;
286- acpi_put_table (table );
296+ if (id == ACPI_CEDT_TYPE_CHBS )
297+ for (i = 0 ; i < ARRAY_SIZE (mock_cedt .chbs ); i ++ ) {
298+ h = (union acpi_subtable_headers * )& mock_cedt .chbs [i ];
299+ end = (unsigned long )& mock_cedt .chbs [i + 1 ];
300+ handler_arg (h , arg , end );
301+ }
302+
303+ if (id == ACPI_CEDT_TYPE_CFMWS )
304+ for (i = 0 ; i < ARRAY_SIZE (mock_cfmws ); i ++ ) {
305+ h = (union acpi_subtable_headers * ) mock_cfmws [i ];
306+ end = (unsigned long ) h + mock_cfmws [i ]-> header .length ;
307+ handler_arg (h , arg , end );
308+ }
309+
310+ return 0 ;
287311}
288312
289313static bool is_mock_bridge (struct device * dev )
@@ -388,8 +412,7 @@ static struct cxl_mock_ops cxl_mock_ops = {
388412 .is_mock_port = is_mock_port ,
389413 .is_mock_dev = is_mock_dev ,
390414 .mock_port = mock_cxl_root_port ,
391- .acpi_get_table = mock_acpi_get_table ,
392- .acpi_put_table = mock_acpi_put_table ,
415+ .acpi_table_parse_cedt = mock_acpi_table_parse_cedt ,
393416 .acpi_evaluate_integer = mock_acpi_evaluate_integer ,
394417 .acpi_pci_find_root = mock_acpi_pci_find_root ,
395418 .list = LIST_HEAD_INIT (cxl_mock_ops .list ),
@@ -574,3 +597,4 @@ static __exit void cxl_test_exit(void)
574597module_init (cxl_test_init );
575598module_exit (cxl_test_exit );
576599MODULE_LICENSE ("GPL v2" );
600+ MODULE_IMPORT_NS (ACPI );
0 commit comments