@@ -485,22 +485,14 @@ static ssize_t interleave_ways_show(struct device *dev,
485485
486486static const struct attribute_group * get_cxl_region_target_group (void );
487487
488- static ssize_t interleave_ways_store (struct device * dev ,
489- struct device_attribute * attr ,
490- const char * buf , size_t len )
488+ static int set_interleave_ways (struct cxl_region * cxlr , int val )
491489{
492- struct cxl_region * cxlr = to_cxl_region (dev );
493490 struct cxl_root_decoder * cxlrd = cxlr -> cxlrd ;
494491 struct cxl_decoder * cxld = & cxlrd -> cxlsd .cxld ;
495492 struct cxl_region_params * p = & cxlr -> params ;
496- unsigned int val , save ;
497- int rc ;
493+ int save , rc ;
498494 u8 iw ;
499495
500- rc = kstrtouint (buf , 0 , & val );
501- if (rc )
502- return rc ;
503-
504496 rc = ways_to_eiw (val , & iw );
505497 if (rc )
506498 return rc ;
@@ -515,20 +507,39 @@ static ssize_t interleave_ways_store(struct device *dev,
515507 return - EINVAL ;
516508 }
517509
518- ACQUIRE (rwsem_write_kill , rwsem )(& cxl_rwsem .region );
519- if ((rc = ACQUIRE_ERR (rwsem_write_kill , & rwsem )))
520- return rc ;
510+ lockdep_assert_held_write (& cxl_rwsem .region );
521511
522512 if (p -> state >= CXL_CONFIG_INTERLEAVE_ACTIVE )
523513 return - EBUSY ;
524514
525515 save = p -> interleave_ways ;
526516 p -> interleave_ways = val ;
527517 rc = sysfs_update_group (& cxlr -> dev .kobj , get_cxl_region_target_group ());
528- if (rc ) {
518+ if (rc )
529519 p -> interleave_ways = save ;
520+
521+ return rc ;
522+ }
523+
524+ static ssize_t interleave_ways_store (struct device * dev ,
525+ struct device_attribute * attr ,
526+ const char * buf , size_t len )
527+ {
528+ struct cxl_region * cxlr = to_cxl_region (dev );
529+ int val ;
530+ int rc ;
531+
532+ rc = kstrtoint (buf , 0 , & val );
533+ if (rc )
534+ return rc ;
535+
536+ ACQUIRE (rwsem_write_kill , rwsem )(& cxl_rwsem .region );
537+ if ((rc = ACQUIRE_ERR (rwsem_write_kill , & rwsem )))
538+ return rc ;
539+
540+ rc = set_interleave_ways (cxlr , val );
541+ if (rc )
530542 return rc ;
531- }
532543
533544 return len ;
534545}
@@ -548,21 +559,14 @@ static ssize_t interleave_granularity_show(struct device *dev,
548559 return sysfs_emit (buf , "%d\n" , p -> interleave_granularity );
549560}
550561
551- static ssize_t interleave_granularity_store (struct device * dev ,
552- struct device_attribute * attr ,
553- const char * buf , size_t len )
562+ static int set_interleave_granularity (struct cxl_region * cxlr , int val )
554563{
555- struct cxl_region * cxlr = to_cxl_region (dev );
556564 struct cxl_root_decoder * cxlrd = cxlr -> cxlrd ;
557565 struct cxl_decoder * cxld = & cxlrd -> cxlsd .cxld ;
558566 struct cxl_region_params * p = & cxlr -> params ;
559- int rc , val ;
567+ int rc ;
560568 u16 ig ;
561569
562- rc = kstrtoint (buf , 0 , & val );
563- if (rc )
564- return rc ;
565-
566570 rc = granularity_to_eig (val , & ig );
567571 if (rc )
568572 return rc ;
@@ -578,14 +582,33 @@ static ssize_t interleave_granularity_store(struct device *dev,
578582 if (cxld -> interleave_ways > 1 && val != cxld -> interleave_granularity )
579583 return - EINVAL ;
580584
581- ACQUIRE (rwsem_write_kill , rwsem )(& cxl_rwsem .region );
582- if ((rc = ACQUIRE_ERR (rwsem_write_kill , & rwsem )))
583- return rc ;
585+ lockdep_assert_held_write (& cxl_rwsem .region );
584586
585587 if (p -> state >= CXL_CONFIG_INTERLEAVE_ACTIVE )
586588 return - EBUSY ;
587589
588590 p -> interleave_granularity = val ;
591+ return 0 ;
592+ }
593+
594+ static ssize_t interleave_granularity_store (struct device * dev ,
595+ struct device_attribute * attr ,
596+ const char * buf , size_t len )
597+ {
598+ struct cxl_region * cxlr = to_cxl_region (dev );
599+ int rc , val ;
600+
601+ rc = kstrtoint (buf , 0 , & val );
602+ if (rc )
603+ return rc ;
604+
605+ ACQUIRE (rwsem_write_kill , rwsem )(& cxl_rwsem .region );
606+ if ((rc = ACQUIRE_ERR (rwsem_write_kill , & rwsem )))
607+ return rc ;
608+
609+ rc = set_interleave_granularity (cxlr , val );
610+ if (rc )
611+ return rc ;
589612
590613 return len ;
591614}
@@ -2667,7 +2690,8 @@ static ssize_t create_ram_region_show(struct device *dev,
26672690}
26682691
26692692static struct cxl_region * __create_region (struct cxl_root_decoder * cxlrd ,
2670- enum cxl_partition_mode mode , int id )
2693+ enum cxl_partition_mode mode , int id ,
2694+ enum cxl_decoder_type target_type )
26712695{
26722696 int rc ;
26732697
@@ -2689,7 +2713,7 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
26892713 return ERR_PTR (- EBUSY );
26902714 }
26912715
2692- return devm_cxl_add_region (cxlrd , id , mode , CXL_DECODER_HOSTONLYMEM );
2716+ return devm_cxl_add_region (cxlrd , id , mode , target_type );
26932717}
26942718
26952719static ssize_t create_region_store (struct device * dev , const char * buf ,
@@ -2703,7 +2727,7 @@ static ssize_t create_region_store(struct device *dev, const char *buf,
27032727 if (rc != 1 )
27042728 return - EINVAL ;
27052729
2706- cxlr = __create_region (cxlrd , mode , id );
2730+ cxlr = __create_region (cxlrd , mode , id , CXL_DECODER_HOSTONLYMEM );
27072731 if (IS_ERR (cxlr ))
27082732 return PTR_ERR (cxlr );
27092733
@@ -3921,7 +3945,8 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,
39213945
39223946 do {
39233947 cxlr = __create_region (cxlrd , cxlds -> part [part ].mode ,
3924- atomic_read (& cxlrd -> region_id ));
3948+ atomic_read (& cxlrd -> region_id ),
3949+ cxled -> cxld .target_type );
39253950 } while (IS_ERR (cxlr ) && PTR_ERR (cxlr ) == - EBUSY );
39263951
39273952 if (IS_ERR (cxlr )) {
0 commit comments