@@ -282,7 +282,7 @@ ACPI_EXPORT_SYMBOL(acpi_get_table_header)
282282
283283/*******************************************************************************
284284 *
285- * FUNCTION: acpi_get_table_with_size
285+ * FUNCTION: acpi_get_table
286286 *
287287 * PARAMETERS: signature - ACPI signature of needed table
288288 * instance - Which instance (for SSDTs)
@@ -292,74 +292,110 @@ ACPI_EXPORT_SYMBOL(acpi_get_table_header)
292292 *
293293 * DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
294294 * RSDT/XSDT.
295+ * Note that an early stage acpi_get_table() call must be paired
296+ * with an early stage acpi_put_table() call. otherwise the table
297+ * pointer mapped by the early stage mapping implementation may be
298+ * erroneously unmapped by the late stage unmapping implementation
299+ * in an acpi_put_table() invoked during the late stage.
295300 *
296301 ******************************************************************************/
297302acpi_status
298- acpi_get_table_with_size (char * signature ,
299- u32 instance , struct acpi_table_header * * out_table ,
300- acpi_size * tbl_size )
303+ acpi_get_table (char * signature ,
304+ u32 instance , struct acpi_table_header * * out_table )
301305{
302306 u32 i ;
303307 u32 j ;
304- acpi_status status ;
308+ acpi_status status = AE_NOT_FOUND ;
309+ struct acpi_table_desc * table_desc ;
305310
306311 /* Parameter validation */
307312
308313 if (!signature || !out_table ) {
309314 return (AE_BAD_PARAMETER );
310315 }
311316
317+ /*
318+ * Note that the following line is required by some OSPMs, they only
319+ * check if the returned table is NULL instead of the returned status
320+ * to determined if this function is succeeded.
321+ */
322+ * out_table = NULL ;
323+
324+ (void )acpi_ut_acquire_mutex (ACPI_MTX_TABLES );
325+
312326 /* Walk the root table list */
313327
314328 for (i = 0 , j = 0 ; i < acpi_gbl_root_table_list .current_table_count ;
315329 i ++ ) {
316- if (! ACPI_COMPARE_NAME
317- ( & ( acpi_gbl_root_table_list . tables [ i ]. signature ),
318- signature )) {
330+ table_desc = & acpi_gbl_root_table_list . tables [ i ];
331+
332+ if (! ACPI_COMPARE_NAME ( & table_desc -> signature , signature )) {
319333 continue ;
320334 }
321335
322336 if (++ j < instance ) {
323337 continue ;
324338 }
325339
326- status =
327- acpi_tb_validate_table (& acpi_gbl_root_table_list .tables [i ]);
328- if (ACPI_SUCCESS (status )) {
329- * out_table = acpi_gbl_root_table_list .tables [i ].pointer ;
330- * tbl_size = acpi_gbl_root_table_list .tables [i ].length ;
331- }
332-
333- if (!acpi_gbl_permanent_mmap ) {
334- acpi_gbl_root_table_list .tables [i ].pointer = NULL ;
335- }
336-
337- return (status );
340+ status = acpi_tb_get_table (table_desc , out_table );
341+ break ;
338342 }
339343
340- return (AE_NOT_FOUND );
344+ (void )acpi_ut_release_mutex (ACPI_MTX_TABLES );
345+ return (status );
341346}
342347
343- ACPI_EXPORT_SYMBOL (acpi_get_table_with_size )
348+ ACPI_EXPORT_SYMBOL (acpi_get_table )
344349
345- acpi_status
346- acpi_get_table (char * signature ,
347- u32 instance , struct acpi_table_header * * out_table )
350+ /*******************************************************************************
351+ *
352+ * FUNCTION: acpi_put_table
353+ *
354+ * PARAMETERS: table - The pointer to the table
355+ *
356+ * RETURN: None
357+ *
358+ * DESCRIPTION: Release a table returned by acpi_get_table() and its clones.
359+ * Note that it is not safe if this function was invoked after an
360+ * uninstallation happened to the original table descriptor.
361+ * Currently there is no OSPMs' requirement to handle such
362+ * situations.
363+ *
364+ ******************************************************************************/
365+ void acpi_put_table (struct acpi_table_header * table )
348366{
349- acpi_size tbl_size ;
367+ u32 i ;
368+ struct acpi_table_desc * table_desc ;
369+
370+ ACPI_FUNCTION_TRACE (acpi_put_table );
371+
372+ (void )acpi_ut_acquire_mutex (ACPI_MTX_TABLES );
373+
374+ /* Walk the root table list */
375+
376+ for (i = 0 ; i < acpi_gbl_root_table_list .current_table_count ; i ++ ) {
377+ table_desc = & acpi_gbl_root_table_list .tables [i ];
350378
351- return acpi_get_table_with_size (signature ,
352- instance , out_table , & tbl_size );
379+ if (table_desc -> pointer != table ) {
380+ continue ;
381+ }
382+
383+ acpi_tb_put_table (table_desc );
384+ break ;
385+ }
386+
387+ (void )acpi_ut_release_mutex (ACPI_MTX_TABLES );
388+ return_VOID ;
353389}
354390
355- ACPI_EXPORT_SYMBOL (acpi_get_table )
391+ ACPI_EXPORT_SYMBOL (acpi_put_table )
356392
357393/*******************************************************************************
358394 *
359395 * FUNCTION: acpi_get_table_by_index
360396 *
361397 * PARAMETERS: table_index - Table index
362- * table - Where the pointer to the table is returned
398+ * out_table - Where the pointer to the table is returned
363399 *
364400 * RETURN: Status and pointer to the requested table
365401 *
@@ -368,43 +404,41 @@ ACPI_EXPORT_SYMBOL(acpi_get_table)
368404 *
369405 ******************************************************************************/
370406acpi_status
371- acpi_get_table_by_index (u32 table_index , struct acpi_table_header * * table )
407+ acpi_get_table_by_index (u32 table_index , struct acpi_table_header * * out_table )
372408{
373409 acpi_status status ;
374410
375411 ACPI_FUNCTION_TRACE (acpi_get_table_by_index );
376412
377413 /* Parameter validation */
378414
379- if (!table ) {
415+ if (!out_table ) {
380416 return_ACPI_STATUS (AE_BAD_PARAMETER );
381417 }
382418
419+ /*
420+ * Note that the following line is required by some OSPMs, they only
421+ * check if the returned table is NULL instead of the returned status
422+ * to determined if this function is succeeded.
423+ */
424+ * out_table = NULL ;
425+
383426 (void )acpi_ut_acquire_mutex (ACPI_MTX_TABLES );
384427
385428 /* Validate index */
386429
387430 if (table_index >= acpi_gbl_root_table_list .current_table_count ) {
388- ( void ) acpi_ut_release_mutex ( ACPI_MTX_TABLES ) ;
389- return_ACPI_STATUS ( AE_BAD_PARAMETER ) ;
431+ status = AE_BAD_PARAMETER ;
432+ goto unlock_and_exit ;
390433 }
391434
392- if (! acpi_gbl_root_table_list . tables [ table_index ]. pointer ) {
393-
394- /* Table is not mapped, map it */
435+ status =
436+ acpi_tb_get_table ( & acpi_gbl_root_table_list . tables [ table_index ],
437+ out_table );
395438
396- status =
397- acpi_tb_validate_table (& acpi_gbl_root_table_list .
398- tables [table_index ]);
399- if (ACPI_FAILURE (status )) {
400- (void )acpi_ut_release_mutex (ACPI_MTX_TABLES );
401- return_ACPI_STATUS (status );
402- }
403- }
404-
405- * table = acpi_gbl_root_table_list .tables [table_index ].pointer ;
439+ unlock_and_exit :
406440 (void )acpi_ut_release_mutex (ACPI_MTX_TABLES );
407- return_ACPI_STATUS (AE_OK );
441+ return_ACPI_STATUS (status );
408442}
409443
410444ACPI_EXPORT_SYMBOL (acpi_get_table_by_index )
0 commit comments