@@ -6199,6 +6199,24 @@ static u64 spr_upi_pci_offsets[SPR_UNCORE_UPI_NUM_BOXES] = {
61996199 0 , 0x8000 , 0x10000 , 0x18000
62006200};
62016201
6202+ static void spr_extra_boxes_cleanup (struct intel_uncore_type * type )
6203+ {
6204+ struct intel_uncore_discovery_unit * pos ;
6205+ struct rb_node * node ;
6206+
6207+ if (!type -> boxes )
6208+ return ;
6209+
6210+ while (!RB_EMPTY_ROOT (type -> boxes )) {
6211+ node = rb_first (type -> boxes );
6212+ pos = rb_entry (node , struct intel_uncore_discovery_unit , node );
6213+ rb_erase (node , type -> boxes );
6214+ kfree (pos );
6215+ }
6216+ kfree (type -> boxes );
6217+ type -> boxes = NULL ;
6218+ }
6219+
62026220static struct intel_uncore_type spr_uncore_upi = {
62036221 .event_mask = SNBEP_PMON_RAW_EVENT_MASK ,
62046222 .event_mask_ext = SPR_RAW_EVENT_MASK_EXT ,
@@ -6213,10 +6231,11 @@ static struct intel_uncore_type spr_uncore_upi = {
62136231 .num_counters = 4 ,
62146232 .num_boxes = SPR_UNCORE_UPI_NUM_BOXES ,
62156233 .perf_ctr_bits = 48 ,
6216- .perf_ctr = ICX_UPI_PCI_PMON_CTR0 ,
6217- .event_ctl = ICX_UPI_PCI_PMON_CTL0 ,
6234+ .perf_ctr = ICX_UPI_PCI_PMON_CTR0 - ICX_UPI_PCI_PMON_BOX_CTL ,
6235+ .event_ctl = ICX_UPI_PCI_PMON_CTL0 - ICX_UPI_PCI_PMON_BOX_CTL ,
62186236 .box_ctl = ICX_UPI_PCI_PMON_BOX_CTL ,
62196237 .pci_offsets = spr_upi_pci_offsets ,
6238+ .cleanup_extra_boxes = spr_extra_boxes_cleanup ,
62206239};
62216240
62226241static struct intel_uncore_type spr_uncore_m3upi = {
@@ -6226,11 +6245,12 @@ static struct intel_uncore_type spr_uncore_m3upi = {
62266245 .num_counters = 4 ,
62276246 .num_boxes = SPR_UNCORE_UPI_NUM_BOXES ,
62286247 .perf_ctr_bits = 48 ,
6229- .perf_ctr = ICX_M3UPI_PCI_PMON_CTR0 ,
6230- .event_ctl = ICX_M3UPI_PCI_PMON_CTL0 ,
6248+ .perf_ctr = ICX_M3UPI_PCI_PMON_CTR0 - ICX_M3UPI_PCI_PMON_BOX_CTL ,
6249+ .event_ctl = ICX_M3UPI_PCI_PMON_CTL0 - ICX_M3UPI_PCI_PMON_BOX_CTL ,
62316250 .box_ctl = ICX_M3UPI_PCI_PMON_BOX_CTL ,
62326251 .pci_offsets = spr_upi_pci_offsets ,
62336252 .constraints = icx_uncore_m3upi_constraints ,
6253+ .cleanup_extra_boxes = spr_extra_boxes_cleanup ,
62346254};
62356255
62366256enum perf_uncore_spr_iio_freerunning_type_id {
@@ -6517,10 +6537,11 @@ void spr_uncore_cpu_init(void)
65176537
65186538static void spr_update_device_location (int type_id )
65196539{
6540+ struct intel_uncore_discovery_unit * unit ;
65206541 struct intel_uncore_type * type ;
65216542 struct pci_dev * dev = NULL ;
6543+ struct rb_root * root ;
65226544 u32 device , devfn ;
6523- u64 * ctls ;
65246545 int die ;
65256546
65266547 if (type_id == UNCORE_SPR_UPI ) {
@@ -6534,27 +6555,35 @@ static void spr_update_device_location(int type_id)
65346555 } else
65356556 return ;
65366557
6537- ctls = kcalloc ( __uncore_max_dies , sizeof (u64 ), GFP_KERNEL );
6538- if (!ctls ) {
6558+ root = kzalloc ( sizeof (struct rb_root ), GFP_KERNEL );
6559+ if (!root ) {
65396560 type -> num_boxes = 0 ;
65406561 return ;
65416562 }
6563+ * root = RB_ROOT ;
65426564
65436565 while ((dev = pci_get_device (PCI_VENDOR_ID_INTEL , device , dev )) != NULL ) {
6544- if (devfn != dev -> devfn )
6545- continue ;
65466566
65476567 die = uncore_device_to_die (dev );
65486568 if (die < 0 )
65496569 continue ;
65506570
6551- ctls [die ] = pci_domain_nr (dev -> bus ) << UNCORE_DISCOVERY_PCI_DOMAIN_OFFSET |
6552- dev -> bus -> number << UNCORE_DISCOVERY_PCI_BUS_OFFSET |
6553- devfn << UNCORE_DISCOVERY_PCI_DEVFN_OFFSET |
6554- type -> box_ctl ;
6571+ unit = kzalloc (sizeof (* unit ), GFP_KERNEL );
6572+ if (!unit )
6573+ continue ;
6574+ unit -> die = die ;
6575+ unit -> id = PCI_SLOT (dev -> devfn ) - PCI_SLOT (devfn );
6576+ unit -> addr = pci_domain_nr (dev -> bus ) << UNCORE_DISCOVERY_PCI_DOMAIN_OFFSET |
6577+ dev -> bus -> number << UNCORE_DISCOVERY_PCI_BUS_OFFSET |
6578+ devfn << UNCORE_DISCOVERY_PCI_DEVFN_OFFSET |
6579+ type -> box_ctl ;
6580+
6581+ unit -> pmu_idx = unit -> id ;
6582+
6583+ uncore_find_add_unit (unit , root , NULL );
65556584 }
65566585
6557- type -> box_ctls = ctls ;
6586+ type -> boxes = root ;
65586587}
65596588
65606589int spr_uncore_pci_init (void )
0 commit comments