We compute the luminosity function (LF) and the formation rate of long gamma-ray bursts (GRBs) by fitting the observed differential peak flux distribution obtained by BATSE in three different scenarios: (1) GRBs follow the cosmic star formation, and their LF is constant in time; (2) GRBs follow the cosmic star formation, but the LF varies with redshift; and (3) GRBs form preferentially in low-metallicity environments. We find that the differential peak flux number counts obtained by BATSE and by Swift can be reproduced using the same LF and GRB formation rate, indicating that the two satellites are observing the same GRB population. We then check the resulting redshift distributions in light of Swift 2 year data, focusing in particular on the relatively large sample of GRBs detected at z>2.5. We show that models in which GRBs trace the cosmic star formation and are described by a constant LF are ruled out by the number of high-z Swift detections. This conclusion does not depend on the redshift distribution of bursts that lack optical identification, nor on the existence of a decline in star formation rate at z>2, nor on the adopted faint end of the GRB LF. Swift observations can be explained by assuming that the LF varies with redshift and/or that GRB formation is limited to low-metallicity environments.