[U-Boot] [PATCH 07/25] dm: serial: Convert ns16550 driver to use driver model PCI API
Bin Meng
bmeng.cn at gmail.com
Wed Nov 18 05:27:14 CET 2015
On Tue, Nov 17, 2015 at 11:53 AM, Simon Glass <sjg at chromium.org> wrote:
> Use the driver model version of the function to find the BAR. This updates
> the fdtdec function, of which ns16550 is the only user.
>
> The fdtdec_get_pci_bdf() function is dropped for several reasons:
> - with driver model we should use 'struct udevice *' rather than passing the
> device tree offset explicitly
> - there are no other users in the tree
> - the function parses for information which is already available in the PCI
> device structure (specifically struct pci_child_platdata which is available
> at dev_get_parent_platdata(dev)
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> drivers/serial/ns16550.c | 3 +--
> include/fdtdec.h | 23 +++-----------------
> lib/fdtdec.c | 55 ++++--------------------------------------------
> 3 files changed, 8 insertions(+), 73 deletions(-)
>
> diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
> index 6433844..364531e 100644
> --- a/drivers/serial/ns16550.c
> +++ b/drivers/serial/ns16550.c
> @@ -386,8 +386,7 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
> return ret;
> }
>
> - ret = fdtdec_get_pci_bar32(gd->fdt_blob, dev->of_offset,
> - &pci_addr, &bar);
> + ret = fdtdec_get_pci_bar32(dev, &pci_addr, &bar);
> if (ret)
> return ret;
>
> diff --git a/include/fdtdec.h b/include/fdtdec.h
> index 8e0f592..6afd53d 100644
> --- a/include/fdtdec.h
> +++ b/include/fdtdec.h
> @@ -445,32 +445,15 @@ int fdtdec_get_pci_vendev(const void *blob, int node,
>
> /**
> * Look at the pci address of a device node that represents a PCI device
> - * and parse the bus, device and function number from it. For some cases
> - * like the bus number encoded in reg property is not correct after pci
> - * enumeration, this function looks through the node's compatible strings
> - * to get these numbers extracted instead.
> - *
> - * @param blob FDT blob
> - * @param node node to examine
> - * @param addr pci address in the form of fdt_pci_addr
> - * @param bdf returns bus, device, function triplet
> - * @return 0 if ok, negative on error
> - */
> -int fdtdec_get_pci_bdf(const void *blob, int node,
> - struct fdt_pci_addr *addr, pci_dev_t *bdf);
> -
> -/**
> - * Look at the pci address of a device node that represents a PCI device
> * and return base address of the pci device's registers.
> *
> - * @param blob FDT blob
> - * @param node node to examine
> + * @param dev device to examine
> * @param addr pci address in the form of fdt_pci_addr
> * @param bar returns base address of the pci device's registers
> * @return 0 if ok, negative on error
> */
> -int fdtdec_get_pci_bar32(const void *blob, int node,
> - struct fdt_pci_addr *addr, u32 *bar);
> +int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr,
> + u32 *bar);
>
> /**
> * Look up a 32-bit integer property in a node and return it. The property
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index 4534177..4b9f196 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -5,6 +5,7 @@
>
> #ifndef USE_HOSTCC
> #include <common.h>
> +#include <dm.h>
> #include <errno.h>
> #include <serial.h>
> #include <libfdt.h>
> @@ -283,58 +284,10 @@ int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device)
> return -ENOENT;
> }
>
> -int fdtdec_get_pci_bdf(const void *blob, int node,
> - struct fdt_pci_addr *addr, pci_dev_t *bdf)
> +int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr,
> + u32 *bar)
> {
> - u16 dt_vendor, dt_device, vendor, device;
> - int ret;
> -
> - /* get vendor id & device id from the compatible string */
> - ret = fdtdec_get_pci_vendev(blob, node, &dt_vendor, &dt_device);
> - if (ret)
> - return ret;
> -
> - /* extract the bdf from fdt_pci_addr */
> - *bdf = addr->phys_hi & 0xffff00;
> -
> - /* read vendor id & device id based on bdf */
> - pci_read_config_word(*bdf, PCI_VENDOR_ID, &vendor);
> - pci_read_config_word(*bdf, PCI_DEVICE_ID, &device);
> -
> - /*
> - * Note there are two places in the device tree to fully describe
> - * a pci device: one is via compatible string with a format of
> - * "pciVVVV,DDDD" and the other one is the bdf numbers encoded in
> - * the device node's reg address property. We read the vendor id
> - * and device id based on bdf and compare the values with the
> - * "VVVV,DDDD". If they are the same, then we are good to use bdf
> - * to read device's bar. But if they are different, we have to rely
> - * on the vendor id and device id extracted from the compatible
> - * string and locate the real bdf by pci_find_device(). This is
> - * because normally we may only know device's device number and
> - * function number when writing device tree. The bus number is
> - * dynamically assigned during the pci enumeration process.
> - */
> - if ((dt_vendor != vendor) || (dt_device != device)) {
> - *bdf = pci_find_device(dt_vendor, dt_device, 0);
> - if (*bdf == -1)
> - return -ENODEV;
> - }
> -
> - return 0;
> -}
> -
> -int fdtdec_get_pci_bar32(const void *blob, int node,
> - struct fdt_pci_addr *addr, u32 *bar)
> -{
> - pci_dev_t bdf;
> int barnum;
> - int ret;
> -
> - /* get pci devices's bdf */
> - ret = fdtdec_get_pci_bdf(blob, node, addr, &bdf);
> - if (ret)
> - return ret;
>
> /* extract the bar number from fdt_pci_addr */
> barnum = addr->phys_hi & 0xff;
> @@ -342,7 +295,7 @@ int fdtdec_get_pci_bar32(const void *blob, int node,
> return -EINVAL;
>
> barnum = (barnum - PCI_BASE_ADDRESS_0) / 4;
> - *bar = pci_read_bar32(pci_bus_to_hose(PCI_BUS(bdf)), bdf, barnum);
> + *bar = dm_pci_read_bar32(dev, barnum);
>
> return 0;
> }
> --
Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
More information about the U-Boot
mailing list