Open charm and charmonium production at relativistic energies