106a1103fSBjoern A. Zeeb /*-
206a1103fSBjoern A. Zeeb * SPDX-License-Identifier: BSD-2-Clause
306a1103fSBjoern A. Zeeb *
406a1103fSBjoern A. Zeeb * Copyright (c) 2022 Bjoern A. Zeeb
506a1103fSBjoern A. Zeeb *
606a1103fSBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without
706a1103fSBjoern A. Zeeb * modification, are permitted provided that the following conditions
806a1103fSBjoern A. Zeeb * are met:
906a1103fSBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright
1006a1103fSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer.
1106a1103fSBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright
1206a1103fSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the
1306a1103fSBjoern A. Zeeb * documentation and/or other materials provided with the distribution.
1406a1103fSBjoern A. Zeeb *
1506a1103fSBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1606a1103fSBjoern A. Zeeb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1706a1103fSBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1806a1103fSBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1906a1103fSBjoern A. Zeeb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2006a1103fSBjoern A. Zeeb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2106a1103fSBjoern A. Zeeb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2206a1103fSBjoern A. Zeeb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2306a1103fSBjoern A. Zeeb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2406a1103fSBjoern A. Zeeb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2506a1103fSBjoern A. Zeeb * SUCH DAMAGE.
2606a1103fSBjoern A. Zeeb */
2706a1103fSBjoern A. Zeeb
2806a1103fSBjoern A. Zeeb #include <sys/param.h>
2906a1103fSBjoern A. Zeeb #include <sys/types.h>
3006a1103fSBjoern A. Zeeb #include <sys/kernel.h>
3106a1103fSBjoern A. Zeeb #include <sys/malloc.h>
3206a1103fSBjoern A. Zeeb
3306a1103fSBjoern A. Zeeb #include <linux/kernel.h> /* pr_debug */
3406a1103fSBjoern A. Zeeb #include <linux/mhi.h>
3506a1103fSBjoern A. Zeeb
3606a1103fSBjoern A. Zeeb static MALLOC_DEFINE(M_LKPIMHI, "lkpimhi", "LinuxKPI MHI compat");
3706a1103fSBjoern A. Zeeb
3806a1103fSBjoern A. Zeeb struct mhi_controller *
linuxkpi_mhi_alloc_controller(void)3906a1103fSBjoern A. Zeeb linuxkpi_mhi_alloc_controller(void)
4006a1103fSBjoern A. Zeeb {
4106a1103fSBjoern A. Zeeb struct mhi_controller *mhi_ctrl;
4206a1103fSBjoern A. Zeeb
4306a1103fSBjoern A. Zeeb mhi_ctrl = malloc(sizeof(*mhi_ctrl), M_LKPIMHI, M_NOWAIT | M_ZERO);
4406a1103fSBjoern A. Zeeb
4506a1103fSBjoern A. Zeeb return (mhi_ctrl);
4606a1103fSBjoern A. Zeeb }
4706a1103fSBjoern A. Zeeb
4806a1103fSBjoern A. Zeeb void
linuxkpi_mhi_free_controller(struct mhi_controller * mhi_ctrl)4906a1103fSBjoern A. Zeeb linuxkpi_mhi_free_controller(struct mhi_controller *mhi_ctrl)
5006a1103fSBjoern A. Zeeb {
5106a1103fSBjoern A. Zeeb
5206a1103fSBjoern A. Zeeb /* What else do we need to check that it is gone? */
5306a1103fSBjoern A. Zeeb free(mhi_ctrl, M_LKPIMHI);
5406a1103fSBjoern A. Zeeb }
5506a1103fSBjoern A. Zeeb
5606a1103fSBjoern A. Zeeb int
linuxkpi_mhi_register_controller(struct mhi_controller * mhi_ctrl,const struct mhi_controller_config * cfg)5706a1103fSBjoern A. Zeeb linuxkpi_mhi_register_controller(struct mhi_controller *mhi_ctrl,
58*bee50f89SBjoern A. Zeeb const struct mhi_controller_config *cfg)
5906a1103fSBjoern A. Zeeb {
6006a1103fSBjoern A. Zeeb
6106a1103fSBjoern A. Zeeb if (mhi_ctrl == NULL || cfg == NULL)
6206a1103fSBjoern A. Zeeb return (-EINVAL);
6306a1103fSBjoern A. Zeeb
6406a1103fSBjoern A. Zeeb #define CHECK_FIELD(_f) \
6506a1103fSBjoern A. Zeeb if (!mhi_ctrl->_f) \
6606a1103fSBjoern A. Zeeb return (-ENXIO);
6706a1103fSBjoern A. Zeeb CHECK_FIELD(cntrl_dev);
6806a1103fSBjoern A. Zeeb CHECK_FIELD(regs);
6906a1103fSBjoern A. Zeeb CHECK_FIELD(irq);
7006a1103fSBjoern A. Zeeb CHECK_FIELD(reg_len);
7106a1103fSBjoern A. Zeeb CHECK_FIELD(nr_irqs);
7206a1103fSBjoern A. Zeeb
7306a1103fSBjoern A. Zeeb CHECK_FIELD(runtime_get);
7406a1103fSBjoern A. Zeeb CHECK_FIELD(runtime_put);
7506a1103fSBjoern A. Zeeb CHECK_FIELD(status_cb);
7606a1103fSBjoern A. Zeeb CHECK_FIELD(read_reg);
7706a1103fSBjoern A. Zeeb CHECK_FIELD(write_reg);
7806a1103fSBjoern A. Zeeb #undef CHECK_FIELD
7906a1103fSBjoern A. Zeeb
8006a1103fSBjoern A. Zeeb printf("%s: XXX-BZ TODO\n", __func__);
8106a1103fSBjoern A. Zeeb return (0);
8206a1103fSBjoern A. Zeeb }
8306a1103fSBjoern A. Zeeb
8406a1103fSBjoern A. Zeeb void
linuxkpi_mhi_unregister_controller(struct mhi_controller * mhi_ctrl)8506a1103fSBjoern A. Zeeb linuxkpi_mhi_unregister_controller(struct mhi_controller *mhi_ctrl)
8606a1103fSBjoern A. Zeeb {
8706a1103fSBjoern A. Zeeb
8806a1103fSBjoern A. Zeeb pr_debug("%s: TODO\n", __func__);
8906a1103fSBjoern A. Zeeb }
90