1292556Sian/*- 2292556Sian * Copyright (c) 2015 Ian Lepore <ian@freebsd.org> 3297682Sian * All rights reserved. 4292556Sian * 5292556Sian * Redistribution and use in source and binary forms, with or without 6292556Sian * modification, are permitted provided that the following conditions 7292556Sian * are met: 8292556Sian * 1. Redistributions of source code must retain the above copyright 9292556Sian * notice, this list of conditions and the following disclaimer. 10292556Sian * 2. Redistributions in binary form must reproduce the above copyright 11292556Sian * notice, this list of conditions and the following disclaimer in the 12292556Sian * documentation and/or other materials provided with the distribution. 13292556Sian * 14292556Sian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15292556Sian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16292556Sian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17292556Sian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18292556Sian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19292556Sian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20292556Sian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21292556Sian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22292556Sian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23292556Sian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24292556Sian * SUCH DAMAGE. 25292556Sian */ 26292556Sian 27292556Sian#include <sys/cdefs.h> 28292556Sian__FBSDID("$FreeBSD$"); 29292556Sian 30292556Sian#include <sys/param.h> 31292556Sian#include <sys/bus.h> 32292556Sian 33292556Sian#include <machine/bus.h> 34292556Sian#include <machine/fdt.h> 35292556Sian 36292556Sian#include <dev/ofw/openfirm.h> 37292556Sian#include <dev/ofw/ofw_subr.h> 38292556Sian 39292556Sianint 40292556SianOF_decode_addr(phandle_t dev, int regno, bus_space_tag_t *tag, 41295662Sandrew bus_space_handle_t *handle, bus_size_t *sz) 42292556Sian{ 43292556Sian bus_addr_t addr; 44292556Sian bus_size_t size; 45292556Sian pcell_t pci_hi; 46292556Sian int flags, res; 47292556Sian 48292556Sian res = ofw_reg_to_paddr(dev, regno, &addr, &size, &pci_hi); 49292556Sian if (res < 0) 50292556Sian return (res); 51292556Sian 52292556Sian /* 53292556Sian * Nothing special to do for PCI busses right now. 54292556Sian * This may need to be handled per-platform when it does come up. 55292556Sian */ 56292556Sian#ifdef notyet 57292556Sian if (pci_hi == OFW_PADDR_NOT_PCI) { 58292556Sian *tag = fdtbus_bs_tag; 59292556Sian flags = 0; 60292556Sian } else { 61292556Sian *tag = fdtbus_bs_tag; 62292556Sian flags = (pci_hi & OFW_PCI_PHYS_HI_PREFETCHABLE) ? 63292556Sian BUS_SPACE_MAP_PREFETCHABLE: 0; 64292556Sian } 65292556Sian#else 66292556Sian *tag = fdtbus_bs_tag; 67292556Sian flags = 0; 68292556Sian#endif 69295662Sandrew 70295662Sandrew if (sz != NULL) 71295662Sandrew *sz = size; 72295662Sandrew 73292556Sian return (bus_space_map(*tag, addr, size, flags, handle)); 74292556Sian} 75