blob: c997a12faa95fbe8830e32e4f1e33b2b5409793a [file] [log] [blame]
/*
<:copyright-BRCM:2016:DUAL/GPL:standard
Broadcom Proprietary and Confidential.(c) 2016 Broadcom
All Rights Reserved
Unless you and Broadcom execute a separate written software license
agreement governing use of this software, this software is licensed
to you under the terms of the GNU General Public License version 2
(the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
with the following added to such license:
As a special exception, the copyright holders of this software give
you permission to link this software with independent modules, and
to copy and distribute the resulting executable under terms of your
choice, provided that you also meet, for each linked independent
module, the terms and conditions of the license of that module.
An independent module is a module which is not derived from this
software. The special exception does not apply to any modifications
of the software.
Not withstanding the above, under no circumstances may you combine
this software in any way with any other Broadcom software provided
under a license other than the GPL, without Broadcom's express prior
written consent.
:>
*/
/*
* bcmolt_board_selector.c
*/
#include <linux/fs.h>
#include "bcmolt_board_selector.h"
static bus_devfn_devid bus_devfn_devid_table_svk4[] = {
{ 5, 0, 0},
{ 3, 0, 1},
{-1,-1,-1},
};
static bus_devfn_devid bus_devfn_devid_table_svk1_3[] = {
{ 3, 0, 0},
{-1,-1,-1},
};
#define SVK4_IDENT_FILE "/etc/svk4"
#define PCIE_DEVICE_RESCAN_FILE_SVK4 "/sys/bus/pci/devices/0000:02:00.0/rescan"
#define PCIE_DEVICE_RESCAN_FILE_SVK1_3 "/sys/bus/pci/devices/0000:02:01.0/rescan"
/* Minimum required FPGA version for standalone mode (host / embedded processors running disconnected). */
#define FPGA_VER_FOR_STANDALONE 7
static struct file *file_open(const char *path, int flags)
{
struct file *fd = NULL;
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
fd = filp_open(path, flags, mode);
if(IS_ERR(fd))
return NULL;
return fd;
}
static void file_close(struct file *file)
{
filp_close(file, NULL);
}
static bcmos_bool can_read_file(const char *path)
{
struct file *fd = file_open(path, O_RDONLY);
if ((fd == NULL) || (fd == (void *)-ENOENT)) /* -ENOENT; No such file or directory */
{
return BCMOS_FALSE;
}
file_close(fd);
return BCMOS_TRUE;
}
static bcmos_bool board_is_svk4(void)
{
return can_read_file(SVK4_IDENT_FILE);
}
/* Get PCI rescan string. It is used in linux to rescan PCIe bus */
const char *bcmolt_board_pci_rescan_string_get(void)
{
return board_is_svk4() ? PCIE_DEVICE_RESCAN_FILE_SVK4 : PCIE_DEVICE_RESCAN_FILE_SVK1_3;
}
/* Get bus, devfn --> dev_id mapping table.
* The table is terminated by row with bus=-1,devfn=-1
*/
const bus_devfn_devid *bcmolt_board_pci_map_table_get(void)
{
return board_is_svk4() ? bus_devfn_devid_table_svk4 : bus_devfn_devid_table_svk1_3;
}
/* Return TRUE if board supports Maple-standalone mode */
bcmos_bool bcmolt_board_supports_standalone(uint32_t version)
{
return board_is_svk4() || version >= FPGA_VER_FOR_STANDALONE;
}
/* Returns number of maple devices on the board */
uint8_t bcmolt_board_num_maple_devices(void)
{
return board_is_svk4() ? 2 : 1;
}