@@ -191,6 +191,92 @@ void __iomem *pci_ioremap_wc_bar(struct pci_dev *pdev, int bar)
191191EXPORT_SYMBOL_GPL (pci_ioremap_wc_bar );
192192#endif
193193
194+ /**
195+ * pci_dev_str_match - test if a string matches a device
196+ * @dev: the PCI device to test
197+ * @p: string to match the device against
198+ * @endptr: pointer to the string after the match
199+ *
200+ * Test if a string (typically from a kernel parameter) matches a specified
201+ * PCI device. The string may be of one of the following formats:
202+ *
203+ * [<domain>:]<bus>:<device>.<func>
204+ * pci:<vendor>:<device>[:<subvendor>:<subdevice>]
205+ *
206+ * The first format specifies a PCI bus/device/function address which
207+ * may change if new hardware is inserted, if motherboard firmware changes,
208+ * or due to changes caused in kernel parameters. If the domain is
209+ * left unspecified, it is taken to be 0.
210+ *
211+ * The second format matches devices using IDs in the configuration
212+ * space which may match multiple devices in the system. A value of 0
213+ * for any field will match all devices. (Note: this differs from
214+ * in-kernel code that uses PCI_ANY_ID which is ~0; this is for
215+ * legacy reasons and convenience so users don't have to specify
216+ * FFFFFFFFs on the command line.)
217+ *
218+ * Returns 1 if the string matches the device, 0 if it does not and
219+ * a negative error code if the string cannot be parsed.
220+ */
221+ static int pci_dev_str_match (struct pci_dev * dev , const char * p ,
222+ const char * * endptr )
223+ {
224+ int ret ;
225+ int seg , bus , slot , func , count ;
226+ unsigned short vendor , device , subsystem_vendor , subsystem_device ;
227+
228+ if (strncmp (p , "pci:" , 4 ) == 0 ) {
229+ /* PCI vendor/device (subvendor/subdevice) IDs are specified */
230+ p += 4 ;
231+ ret = sscanf (p , "%hx:%hx:%hx:%hx%n" , & vendor , & device ,
232+ & subsystem_vendor , & subsystem_device , & count );
233+ if (ret != 4 ) {
234+ ret = sscanf (p , "%hx:%hx%n" , & vendor , & device , & count );
235+ if (ret != 2 )
236+ return - EINVAL ;
237+
238+ subsystem_vendor = 0 ;
239+ subsystem_device = 0 ;
240+ }
241+
242+ p += count ;
243+
244+ if ((!vendor || vendor == dev -> vendor ) &&
245+ (!device || device == dev -> device ) &&
246+ (!subsystem_vendor ||
247+ subsystem_vendor == dev -> subsystem_vendor ) &&
248+ (!subsystem_device ||
249+ subsystem_device == dev -> subsystem_device ))
250+ goto found ;
251+
252+ } else {
253+ /* PCI Bus, Device, Function IDs are specified */
254+ ret = sscanf (p , "%x:%x:%x.%x%n" , & seg , & bus , & slot ,
255+ & func , & count );
256+ if (ret != 4 ) {
257+ seg = 0 ;
258+ ret = sscanf (p , "%x:%x.%x%n" , & bus , & slot ,
259+ & func , & count );
260+ if (ret != 3 )
261+ return - EINVAL ;
262+ }
263+
264+ p += count ;
265+
266+ if (seg == pci_domain_nr (dev -> bus ) &&
267+ bus == dev -> bus -> number &&
268+ slot == PCI_SLOT (dev -> devfn ) &&
269+ func == PCI_FUNC (dev -> devfn ))
270+ goto found ;
271+ }
272+
273+ * endptr = p ;
274+ return 0 ;
275+
276+ found :
277+ * endptr = p ;
278+ return 1 ;
279+ }
194280
195281static int __pci_find_next_cap_ttl (struct pci_bus * bus , unsigned int devfn ,
196282 u8 pos , int cap , int * ttl )
@@ -5454,10 +5540,10 @@ static DEFINE_SPINLOCK(resource_alignment_lock);
54545540static resource_size_t pci_specified_resource_alignment (struct pci_dev * dev ,
54555541 bool * resize )
54565542{
5457- int seg , bus , slot , func , align_order , count ;
5458- unsigned short vendor , device , subsystem_vendor , subsystem_device ;
5543+ int align_order , count ;
54595544 resource_size_t align = pcibios_default_alignment ();
5460- char * p ;
5545+ const char * p ;
5546+ int ret ;
54615547
54625548 spin_lock (& resource_alignment_lock );
54635549 p = resource_alignment_param ;
@@ -5477,58 +5563,21 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev,
54775563 } else {
54785564 align_order = -1 ;
54795565 }
5480- if (strncmp (p , "pci:" , 4 ) == 0 ) {
5481- /* PCI vendor/device (subvendor/subdevice) ids are specified */
5482- p += 4 ;
5483- if (sscanf (p , "%hx:%hx:%hx:%hx%n" ,
5484- & vendor , & device , & subsystem_vendor , & subsystem_device , & count ) != 4 ) {
5485- if (sscanf (p , "%hx:%hx%n" , & vendor , & device , & count ) != 2 ) {
5486- printk (KERN_ERR "PCI: Can't parse resource_alignment parameter: pci:%s\n" ,
5487- p );
5488- break ;
5489- }
5490- subsystem_vendor = subsystem_device = 0 ;
5491- }
5492- p += count ;
5493- if ((!vendor || (vendor == dev -> vendor )) &&
5494- (!device || (device == dev -> device )) &&
5495- (!subsystem_vendor || (subsystem_vendor == dev -> subsystem_vendor )) &&
5496- (!subsystem_device || (subsystem_device == dev -> subsystem_device ))) {
5497- * resize = true;
5498- if (align_order == -1 )
5499- align = PAGE_SIZE ;
5500- else
5501- align = 1 << align_order ;
5502- /* Found */
5503- break ;
5504- }
5505- }
5506- else {
5507- if (sscanf (p , "%x:%x:%x.%x%n" ,
5508- & seg , & bus , & slot , & func , & count ) != 4 ) {
5509- seg = 0 ;
5510- if (sscanf (p , "%x:%x.%x%n" ,
5511- & bus , & slot , & func , & count ) != 3 ) {
5512- /* Invalid format */
5513- printk (KERN_ERR "PCI: Can't parse resource_alignment parameter: %s\n" ,
5514- p );
5515- break ;
5516- }
5517- }
5518- p += count ;
5519- if (seg == pci_domain_nr (dev -> bus ) &&
5520- bus == dev -> bus -> number &&
5521- slot == PCI_SLOT (dev -> devfn ) &&
5522- func == PCI_FUNC (dev -> devfn )) {
5523- * resize = true;
5524- if (align_order == -1 )
5525- align = PAGE_SIZE ;
5526- else
5527- align = 1 << align_order ;
5528- /* Found */
5529- break ;
5530- }
5566+
5567+ ret = pci_dev_str_match (dev , p , & p );
5568+ if (ret == 1 ) {
5569+ * resize = true;
5570+ if (align_order == -1 )
5571+ align = PAGE_SIZE ;
5572+ else
5573+ align = 1 << align_order ;
5574+ break ;
5575+ } else if (ret < 0 ) {
5576+ pr_err ("PCI: Can't parse resource_alignment parameter: %s\n" ,
5577+ p );
5578+ break ;
55315579 }
5580+
55325581 if (* p != ';' && * p != ',' ) {
55335582 /* End of param or invalid format */
55345583 break ;
0 commit comments