1292555Sian/*- 2292555Sian * Copyright (c) 2015 Ian Lepore <ian@freebsd.org> 3292555Sian * All rights reserved. 4292555Sian * 5292555Sian * Redistribution and use in source and binary forms, with or without 6292555Sian * modification, are permitted provided that the following conditions 7292555Sian * are met: 8292555Sian * 1. Redistributions of source code must retain the above copyright 9292555Sian * notice, this list of conditions and the following disclaimer. 10292555Sian * 2. Redistributions in binary form must reproduce the above copyright 11292555Sian * notice, this list of conditions and the following disclaimer in the 12292555Sian * documentation and/or other materials provided with the distribution. 13292555Sian * 14292555Sian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15292555Sian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16292555Sian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17292555Sian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18292555Sian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19292555Sian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20292555Sian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21292555Sian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22292555Sian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23292555Sian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24292555Sian * SUCH DAMAGE. 25292555Sian */ 26292555Sian 27292555Sian#include <sys/cdefs.h> 28292555Sian__FBSDID("$FreeBSD$"); 29292555Sian 30292555Sian#include <sys/param.h> 31292555Sian#include <sys/bus.h> 32292555Sian 33292555Sian#include <machine/bus.h> 34292555Sian#include <machine/fdt.h> 35292555Sian 36292555Sian#include <dev/ofw/openfirm.h> 37292555Sian#include <dev/ofw/ofw_subr.h> 38292555Sian 39292555Sianint 40292555SianOF_decode_addr(phandle_t dev, int regno, bus_space_tag_t *tag, 41295662Sandrew bus_space_handle_t *handle, bus_size_t *sz) 42292555Sian{ 43292555Sian bus_addr_t addr; 44292555Sian bus_size_t size; 45292555Sian pcell_t pci_hi; 46292555Sian int flags, res; 47292555Sian 48292555Sian res = ofw_reg_to_paddr(dev, regno, &addr, &size, &pci_hi); 49292555Sian if (res < 0) 50292555Sian return (res); 51292555Sian 52292555Sian /* 53292555Sian * Nothing special to do for PCI busses right now. 54292555Sian * This may need to be handled per-platform when it does come up. 55292555Sian */ 56292555Sian#ifdef notyet 57292555Sian if (pci_hi == OFW_PADDR_NOT_PCI) { 58292555Sian *tag = fdtbus_bs_tag; 59292555Sian flags = 0; 60292555Sian } else { 61292555Sian *tag = fdtbus_bs_tag; 62292555Sian flags = (pci_hi & OFW_PCI_PHYS_HI_PREFETCHABLE) ? 63292555Sian BUS_SPACE_MAP_PREFETCHABLE: 0; 64292555Sian } 65292555Sian#else 66292555Sian *tag = fdtbus_bs_tag; 67292555Sian flags = 0; 68292555Sian#endif 69295662Sandrew 70295662Sandrew if (sz != NULL) 71295662Sandrew *sz = size; 72295662Sandrew 73292555Sian return (bus_space_map(*tag, addr, size, flags, handle)); 74292555Sian} 75292555Sian 76