@@ -687,6 +687,47 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
687687 }
688688 desc = (u32 )((page_address >> 12 ) & 0x00FFFFFFULL );
689689 caps [cur_cap ++ ] = (u32 )((desc << 8 ) | (0x007F ));
690+ } else if (!strcmp (type_str , "map_region" )) {
691+ if (cur_cap + 1 > 0x20 ) {
692+ fprintf (stderr , "Error: Too many capabilities!\n" );
693+ status = 0 ;
694+ goto NPDM_BUILD_END ;
695+ }
696+ if (!cJSON_IsArray (value )) {
697+ fprintf (stderr , "Map Region capability value must be array!\n" );
698+ status = 0 ;
699+ goto NPDM_BUILD_END ;
700+ }
701+ u8 regions [3 ] = {0 };
702+ int is_ro [3 ] = {0 };
703+ const cJSON * cur_region = NULL ;
704+ int index = 0 ;
705+ cJSON_ArrayForEach (cur_region , value ) {
706+ if (index >= 3 ) {
707+ fprintf (stderr , "Too many region descriptors!\n" );
708+ status = 0 ;
709+ goto NPDM_BUILD_END ;
710+ }
711+ if (!cJSON_IsObject (cur_region )) {
712+ fprintf (stderr , "Region descriptor value must be object!\n" );
713+ status = 0 ;
714+ goto NPDM_BUILD_END ;
715+ }
716+
717+ if (!cJSON_GetU8 (cur_region , "region_type" , & regions [index ]) ||
718+ !cJSON_GetBoolean (cur_region , "is_ro" , & is_ro [index ])) {
719+ status = 0 ;
720+ goto NPDM_BUILD_END ;
721+ }
722+
723+ index ++ ;
724+ }
725+
726+ u32 capability = 0x3FF ;
727+ for (int i = 0 ; i < 3 ; ++ i ) {
728+ capability |= ((regions [i ] & 0x3F ) | ((is_ro [i ] & 1 ) << 6 )) << (11 + 7 * i );
729+ }
730+ caps [cur_cap ++ ] = capability ;
690731 } else if (!strcmp (type_str , "irq_pair" )) {
691732 if (!cJSON_IsArray (value ) || cJSON_GetArraySize (value ) != 2 ) {
692733 fprintf (stderr , "Error: IRQ Pairs must have size 2 array value.\n" );
0 commit comments