/* IPC rights table. Copyright 1999, 2000, 2001 Johan Rydberg, jrydberg@opencores.org. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "ipc-table.h" #include "ipc-port.h" #include "ipc-object.h" #include "trace.h" /* Intialize IPC table object TBL. Marks all slots as unused. */ void ipc_table_object_init (struct ipc_table *tbl) { int cnt; for (cnt = 0; cnt < MTABLERIGHTS; cnt++) tbl->it_tbl [cnt] = 0; } /* Try to reserve entry named by NAME in TBL. Return true if we succeed with pointer to entry structure in ENTRYP. False is retuned if we fail to reserve slot in tbale. */ bool ipc_table_reserve_name (struct ipc_table *tbl, struct ipc_entry **entryp, rtmk_port_t name) { struct ipc_entry *ie; if (tbl->it_tbl [name - 1]) return false; ie = (struct ipc_entry *) kmem_cache_alloc (ipc_entry_cache); *entryp = ie; tbl->it_tbl [name - 1] = ie; return true; } /* This function tries to reserve an entry within TBL. It returns true if it succeed to reserve an entry, with name of entry in NAMEP and pointer to entry in ENTRYP. */ bool ipc_table_reserve (struct ipc_table *tbl, struct ipc_entry **entryp, rtmk_port_t *namep) { struct ipc_entry *ie; int cnt; for (cnt = 0; cnt < MTABLERIGHTS; cnt++) { if (tbl->it_tbl [cnt]) continue; ie = (struct ipc_entry *) kmem_cache_alloc (ipc_entry_cache); *namep = (rtmk_port_t) (cnt + 1); *entryp = ie; tbl->it_tbl [cnt] = ie; return true; } return false; } /* Lookup NAME in TBL. If slot was not empty, we return true and pointer to entry structure in ENTRYP. */ bool ipc_table_lookup (struct ipc_table *tbl, rtmk_port_t name, struct ipc_entry **entryp) { struct ipc_entry *entry; assert (name < MTABLERIGHTS && name != 0); entry = tbl->it_tbl [name - 1]; if (entry && (IE_BITS_STATUS (entry->ie_bits) & IE_BITS_VALID) == IE_BITS_VALID) { *entryp = entry; return true; } return false; } /* Remove entry named NAME from TBL. Return true if we removed the entry (and it was valid). */ bool ipc_table_remove (struct ipc_table *tbl, rtmk_port_t name) { struct ipc_entry *entry; assert (name < MTABLERIGHTS && name != 0); entry = tbl->it_tbl [name - 1]; if (entry && (IE_BITS_STATUS (entry->ie_bits) & IE_BITS_VALID) == IE_BITS_VALID) { entry->ie_bits &= ~IE_BITS_VALID; tbl->it_tbl [name - 1] = (ipc_entry) 0; return true; } return false; }