title: when Linux calls PCI driver's probe function?
body: <p>Before registering a PCI driver, we have to initialize <code>struct pci_driver</code> and pass it to  <code>pci_register_driver</code>. One of fields of the structure is a pointer to driver's <code>probe</code> function.</p>
  
  <p>My question is - when the kernel calls driver's probe routine. Is it guaranteed to be right after the call to <code>pci_register_driver</code> or may happen any other time? What is determining this behaviour?</p>
  
  <p><strong>UPDATE</strong>
  <code>pci_register_driver</code> is a macro expanded into <code>__pci_register_driver</code>, which in turn calls <code>driver_register</code>, and <code>driver_register</code> calls <code>bus_add_driver</code>.</p>
  
  <p>There's a following code in <code>bus_add_driver</code>:</p>
  
  <pre><code>if (drv-&gt;bus-&gt;p-&gt;drivers_autoprobe) {
          error = driver_attach(drv);
          if (error)
              goto out_unregister;
  }
  </code></pre>
  
  <p><code>driver_attach</code> will call <code>bus_for_each_dev</code> with argument <code>__driver_attach</code>, which will invoke <code>driver_probe_device</code></p>
  
  <p>And <code>driver_probe_device</code> ultimately calls <code>really_probe</code>:</p>
  
  <pre><code>if (dev-&gt;bus-&gt;probe) {
      ret = dev-&gt;bus-&gt;probe(dev);
  </code></pre>
  
  <p>The one thing I'm not sure about, is if the flag <code>drivers_autoprobe</code> gets set for pci_bus.</p>