Failing that: I'd suggest to create a variable for the serial port iobase, defaulting to CONFIG_DEBUG_SERIAL_PORT. Add a serial_debuf_pci_init(int bdf) helper function to read the iobase from pci config space and set that variable.
That helper can then be hooked into pci scan, or called with a hardcoded bdf for early debug output, or both.
Thank you for your suggestion. So where should the argument "bdf" come from for the helper? serial_debug_pci_init(int bdf) In the case of hooking into pci scan, get the bdf by filtering the first pci serial device(class code)? In the case of called with hardcoded bdf for early debug output, we still need a config option to hard code the "bdf", right?
The simplest way is probably to make serial_debug_pci_init() work only once, i.e. if the variable is already set to something != CONFIG_DEBUG_SERIAL_PORT just return without doing anything. That way the hardcoded bdf will be used if available, otherwise the first device (in pci scan order) will win.